@webpros/mui-theme 0.4.2 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/package.json
CHANGED
|
@@ -2,12 +2,14 @@ import { ReactNode } from 'react';
|
|
|
2
2
|
type ToggleButtonGroupProps = {
|
|
3
3
|
children: ReactNode;
|
|
4
4
|
multiple?: boolean;
|
|
5
|
+
value?: string | string[];
|
|
6
|
+
onToggle?: (value: string | string[]) => void;
|
|
5
7
|
};
|
|
6
8
|
export type ToggleContextType = {
|
|
7
9
|
value: string | Array<string>;
|
|
8
10
|
handleToggle: React.MouseEventHandler;
|
|
9
11
|
};
|
|
10
12
|
export declare const ToggleContext: import("react").Context<ToggleContextType>;
|
|
11
|
-
export declare const ToggleButtonGroup: ({ children, multiple }: ToggleButtonGroupProps) => import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export declare const ToggleButtonGroup: ({ children, multiple, value: controlledValue, onToggle, }: ToggleButtonGroupProps) => import("react/jsx-runtime").JSX.Element;
|
|
12
14
|
export type ToggleButtonGroupComponentType = typeof ToggleButtonGroup;
|
|
13
15
|
export {};
|
|
@@ -13,19 +13,24 @@ const toggleGroupSX = {
|
|
|
13
13
|
gap: 0.25,
|
|
14
14
|
width: 'fit-content',
|
|
15
15
|
};
|
|
16
|
-
export const ToggleButtonGroup = ({ children, multiple = false }) => {
|
|
17
|
-
const [
|
|
16
|
+
export const ToggleButtonGroup = ({ children, multiple = false, value: controlledValue, onToggle, }) => {
|
|
17
|
+
const [internalValue, setInternalValue] = useState(multiple ? [] : '');
|
|
18
|
+
const value = controlledValue !== null && controlledValue !== void 0 ? controlledValue : internalValue;
|
|
18
19
|
const handleToggle = (e) => {
|
|
19
20
|
const clickedValue = e.currentTarget.value;
|
|
21
|
+
let newValue;
|
|
20
22
|
if (Array.isArray(value)) {
|
|
21
|
-
|
|
23
|
+
newValue = value.includes(clickedValue)
|
|
22
24
|
? value.filter((item) => item !== clickedValue)
|
|
23
25
|
: [...value, clickedValue];
|
|
24
|
-
setValue(newValue);
|
|
25
26
|
}
|
|
26
27
|
else {
|
|
27
|
-
|
|
28
|
+
newValue = clickedValue;
|
|
28
29
|
}
|
|
30
|
+
if (controlledValue === undefined) {
|
|
31
|
+
setInternalValue(newValue);
|
|
32
|
+
}
|
|
33
|
+
onToggle === null || onToggle === void 0 ? void 0 : onToggle(newValue);
|
|
29
34
|
e.currentTarget.blur();
|
|
30
35
|
};
|
|
31
36
|
const toggleContextValue = { value, handleToggle };
|