@babylonjs/shared-ui-components 9.31.3 → 9.32.0
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.
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { type FunctionComponent } from "react";
|
|
2
2
|
import { type PrimitiveProps } from "./primitive.js";
|
|
3
3
|
export type SwitchProps = PrimitiveProps<boolean> & {
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* Accessible name for switches whose visible label is rendered separately.
|
|
6
|
+
*/
|
|
7
|
+
ariaLabel?: string;
|
|
8
|
+
/**
|
|
9
|
+
* When true, value controls the checked state without optimistic local updates. Defaults to false.
|
|
10
|
+
*/
|
|
5
11
|
controlled?: boolean;
|
|
6
12
|
};
|
|
7
13
|
/**
|
|
@@ -35,6 +35,6 @@ export const Switch = (props) => {
|
|
|
35
35
|
setChecked(event.target.checked);
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
-
return (_jsx(FluentSwitch, { className: mergeClasses(classes.switch, size === "small" && classes.switchSmall), indicator: { className: classes.indicator }, checked: props.controlled ? props.value : checked, disabled: props.disabled, onChange: onChange }));
|
|
38
|
+
return (_jsx(FluentSwitch, { className: mergeClasses(classes.switch, size === "small" && classes.switchSmall), indicator: { className: classes.indicator }, checked: props.controlled ? (props.value ?? false) : checked, "aria-label": props.ariaLabel, disabled: props.disabled, onChange: onChange }));
|
|
39
39
|
};
|
|
40
40
|
//# sourceMappingURL=switch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"switch.js","sourceRoot":"","sources":["../../../../../dev/sharedUiComponents/src/fluent/primitives/switch.tsx"],"names":[],"mappings":";AAAA,OAAO,EAA2B,UAAU,EAAE,MAAM,IAAI,YAAY,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AACvH,OAAO,EAA4C,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGlG,OAAO,EAAE,W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;QACX,IAAI,KAAK,CAAC,KAAK,IAAI,SAAS,EAAE,CAAC;YAC3B,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,gDAAgD;QAC7E,CAAC;IACL,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;IAElB,MAAM,QAAQ,GAAG,CAAC,KAAoC,EAAE,CAAqB,EAAE,EAAE;QAC7E,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACvD,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC;YACpB,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACrC,CAAC;IACL,CAAC,CAAC;IAEF,OAAO,CACH,KAAC,YAAY,IACT,SAAS,EAAE,YAAY,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,KAAK,OAAO,IAAI,OAAO,CAAC,WAAW,CAAC,EAChF,SAAS,EAAE,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,EAC3C,OAAO,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,gBAChD,KAAK,CAAC,SAAS,EAC3B,QAAQ,EAAE,KAAK,CAAC,QAAQ,EACxB,QAAQ,EAAE,QAAQ,GACpB,CACL,CAAC;AACN,CAAC,CAAC","sourcesContent":["import { type SwitchOnChangeData, makeStyles, Switch as FluentSwitch, mergeClasses } from \"@fluentui/react-components\";\r\nimport { type ChangeEvent, type FunctionComponent, useContext, useEffect, useState } from \"react\";\r\nimport { type PrimitiveProps } from \"./primitive\";\r\n\r\nimport { ToolContext } from \"../hoc/fluentToolWrapper\";\r\n\r\nconst useSwitchStyles = makeStyles({\r\n switch: {\r\n marginLeft: \"auto\",\r\n },\r\n switchSmall: {\r\n transform: `scale(.85)`, // workaround since we cannot resize fluent switch\r\n transformOrigin: \"right\",\r\n },\r\n indicator: {\r\n margin: 0, // Remove the default right margin so the switch aligns well on the right side inside panels like the properties pane.\r\n },\r\n});\r\n\r\nexport type SwitchProps = PrimitiveProps<boolean> & {\r\n /**\r\n * Accessible name for switches whose visible label is rendered separately.\r\n */\r\n ariaLabel?: string;\r\n /**\r\n * When true, value controls the checked state without optimistic local updates. Defaults to false.\r\n */\r\n controlled?: boolean;\r\n};\r\n\r\n/**\r\n * This is a primitive fluent boolean switch component whose only knowledge is the shared styling across all tools\r\n * @param props\r\n * @returns Switch component\r\n */\r\nexport const Switch: FunctionComponent<SwitchProps> = (props) => {\r\n Switch.displayName = \"Switch\";\r\n const { size } = useContext(ToolContext);\r\n const classes = useSwitchStyles();\r\n const [checked, setChecked] = useState(() => props.value ?? false);\r\n\r\n useEffect(() => {\r\n if (props.value != undefined) {\r\n setChecked(props.value); // Update local state when props.checked changes\r\n }\r\n }, [props.value]);\r\n\r\n const onChange = (event: ChangeEvent<HTMLInputElement>, _: SwitchOnChangeData) => {\r\n props.onChange && props.onChange(event.target.checked);\r\n if (!props.controlled) {\r\n setChecked(event.target.checked);\r\n }\r\n };\r\n\r\n return (\r\n <FluentSwitch\r\n className={mergeClasses(classes.switch, size === \"small\" && classes.switchSmall)}\r\n indicator={{ className: classes.indicator }}\r\n checked={props.controlled ? (props.value ?? false) : checked}\r\n aria-label={props.ariaLabel}\r\n disabled={props.disabled}\r\n onChange={onChange}\r\n />\r\n );\r\n};\r\n"]}
|