@khanacademy/wonder-blocks-switch 0.0.0-PR2904-20260109172033 → 0.0.0-PR2921-20260109172217
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/CHANGELOG.md +10 -7
- package/dist/css/vars.css +16 -0
- package/dist/es/index.js +1 -1
- package/dist/index.js +1 -1
- package/dist/theme/syl-dark.d.ts +40 -0
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
# @khanacademy/wonder-blocks-switch
|
|
2
2
|
|
|
3
|
-
## 0.0.0-
|
|
3
|
+
## 0.0.0-PR2921-20260109172217
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 8a3ee1f: Support SYL Dark
|
|
4
8
|
|
|
5
9
|
### Patch Changes
|
|
6
10
|
|
|
7
|
-
- Updated dependencies [
|
|
8
|
-
- @khanacademy/wonder-blocks-
|
|
9
|
-
- @khanacademy/wonder-blocks-
|
|
10
|
-
- @khanacademy/wonder-blocks-
|
|
11
|
-
- @khanacademy/wonder-blocks-
|
|
12
|
-
- @khanacademy/wonder-blocks-tokens@14.1.3
|
|
11
|
+
- Updated dependencies [8a3ee1f]
|
|
12
|
+
- @khanacademy/wonder-blocks-theming@0.0.0-PR2921-20260109172217
|
|
13
|
+
- @khanacademy/wonder-blocks-tokens@0.0.0-PR2921-20260109172217
|
|
14
|
+
- @khanacademy/wonder-blocks-icon@0.0.0-PR2921-20260109172217
|
|
15
|
+
- @khanacademy/wonder-blocks-styles@0.0.0-PR2921-20260109172217
|
|
13
16
|
|
|
14
17
|
## 3.3.25
|
|
15
18
|
|
package/dist/css/vars.css
CHANGED
|
@@ -14,6 +14,22 @@
|
|
|
14
14
|
--wb-c-switch-icon-transform-default: translateX(var(--wb-sizing-size_160));
|
|
15
15
|
--wb-c-switch-icon-transform-transition: transform 0.15s ease-in-out;}
|
|
16
16
|
|
|
17
|
+
[data-wb-theme='syl-dark'] {--wb-c-switch-root-border-radius-default: var(--wb-border-radius-radius_240);
|
|
18
|
+
--wb-c-switch-root-border-radius-hover: var(--wb-border-radius-radius_120);
|
|
19
|
+
--wb-c-switch-root-border-radius-press: var(--wb-border-radius-radius_120);
|
|
20
|
+
--wb-c-switch-root-sizing-height: var(--wb-sizing-size_240);
|
|
21
|
+
--wb-c-switch-root-sizing-width: var(--wb-sizing-size_440);
|
|
22
|
+
--wb-c-switch-slider-sizing-height: var(--wb-sizing-size_200);
|
|
23
|
+
--wb-c-switch-slider-sizing-width: var(--wb-sizing-size_200);
|
|
24
|
+
--wb-c-switch-slider-position-top: var(--wb-sizing-size_020);
|
|
25
|
+
--wb-c-switch-slider-position-left: var(--wb-sizing-size_020);
|
|
26
|
+
--wb-c-switch-slider-transform-default: translateX(var(--wb-sizing-size_200));
|
|
27
|
+
--wb-c-switch-slider-transform-transition: transform 0.15s ease-in-out;
|
|
28
|
+
--wb-c-switch-icon-position-top: var(--wb-sizing-size_040);
|
|
29
|
+
--wb-c-switch-icon-position-left: var(--wb-sizing-size_040);
|
|
30
|
+
--wb-c-switch-icon-transform-default: translateX(var(--wb-sizing-size_200));
|
|
31
|
+
--wb-c-switch-icon-transform-transition: transform 0.15s ease-in-out;}
|
|
32
|
+
|
|
17
33
|
[data-wb-theme='thunderblocks'] {--wb-c-switch-root-border-radius-default: var(--wb-border-radius-radius_240);
|
|
18
34
|
--wb-c-switch-root-border-radius-hover: var(--wb-border-radius-radius_120);
|
|
19
35
|
--wb-c-switch-root-border-radius-press: var(--wb-border-radius-radius_120);
|
package/dist/es/index.js
CHANGED
|
@@ -10,6 +10,6 @@ var themeDefault = {root:{border:{radius:{default:border.radius.radius_120,hover
|
|
|
10
10
|
|
|
11
11
|
var theme = mapValuesToCssVars(themeDefault,"--wb-c-switch-");
|
|
12
12
|
|
|
13
|
-
const StyledSpan=addStyle("span");const StyledInput=addStyle("input");const focusStylesObject=focusStyles.focus[":focus-visible"];const baseStyles={color:{bg:{switch:{off:semanticColor.core.border.neutral.default,disabledOff:semanticColor.core.border.disabled.strong,activeOff:semanticColor.core.border.neutral.strong,on:semanticColor.core.background.instructive.default,disabledOn:semanticColor.core.border.
|
|
13
|
+
const StyledSpan=addStyle("span");const StyledInput=addStyle("input");const focusStylesObject=focusStyles.focus[":focus-visible"];const baseStyles={color:{bg:{switch:{off:semanticColor.core.border.neutral.default,disabledOff:semanticColor.core.border.disabled.strong,activeOff:semanticColor.core.border.neutral.strong,on:semanticColor.core.background.instructive.default,disabledOn:semanticColor.core.border.disabled.strong,activeOn:semanticColor.core.background.instructive.strong},slider:{on:semanticColor.core.foreground.knockout.default,off:semanticColor.core.foreground.knockout.default},icon:{on:semanticColor.core.foreground.instructive.subtle,disabledOn:semanticColor.core.foreground.disabled.default,off:semanticColor.core.border.neutral.default,disabledOff:semanticColor.core.foreground.disabled.default}}}};const sharedStyles=StyleSheet.create({hidden:{opacity:0,height:0,width:0},switch:{display:"inline-flex",height:theme.root.sizing.height,width:theme.root.sizing.width,borderRadius:theme.root.border.radius.default,flexShrink:0},switchFocus:{":focus-within":focusStylesObject},disabled:{cursor:"not-allowed",":hover":{outline:"none"},":active":{outline:"none"}},disabledFocus:{":focus-within":focusStylesObject},slider:{position:"absolute",top:theme.slider.position.top,left:theme.slider.position.left,height:theme.slider.sizing.height,width:theme.slider.sizing.width,borderRadius:theme.root.border.radius.default,backgroundColor:baseStyles.color.bg.slider.on,transition:theme.slider.transform.transition},icon:{position:"absolute",top:theme.icon.position.top,left:theme.icon.position.left,zIndex:1,transition:theme.icon.transform.transition}});const Switch=React.forwardRef(function Switch(props,ref){const{"aria-label":ariaLabel,"aria-labelledby":ariaLabelledBy,"aria-describedby":ariaDescribedBy,checked,className,disabled=false,icon,id,onChange,testId}=props;const generatedUniqueId=useId();const uniqueId=id??generatedUniqueId;const handleClick=()=>{if(!disabled&&onChange){onChange(!checked);}};const handleChange=()=>{};const stateStyles=_generateStyles(checked,onChange!==undefined,disabled);const combinedStyles=[sharedStyles.switch,sharedStyles.switchFocus,stateStyles.switch,disabled&&sharedStyles.disabled,disabled&&sharedStyles.disabledFocus];let styledIcon;if(icon){styledIcon=React.cloneElement(icon,{size:"small",style:[sharedStyles.icon,stateStyles.icon],"aria-hidden":true});}return jsxs(View,{onClick:handleClick,style:combinedStyles,className:className,testId:testId,children:[jsx(StyledInput,{"aria-describedby":ariaDescribedBy,"aria-label":ariaLabel,"aria-labelledby":ariaLabelledBy,checked:checked,"aria-disabled":disabled,id:uniqueId,onChange:handleChange,ref:ref,role:"switch",style:sharedStyles.hidden,type:"checkbox"}),icon&&styledIcon,jsx(StyledSpan,{style:[sharedStyles.slider,stateStyles.slider]})]})});const styles={};const _generateStyles=(checked,clickable,disabled)=>{const checkedStyle=`${checked}-${clickable}-${disabled}`;if(styles[checkedStyle]){return styles[checkedStyle]}let newStyles={};const sharedSwitchStyles={cursor:clickable?"pointer":"auto",":hover":{...focusStylesObject,outline:clickable?focusStylesObject.outline:"none"}};if(checked){newStyles={switch:{backgroundColor:disabled?baseStyles.color.bg.switch.disabledOn:baseStyles.color.bg.switch.on,":active":{backgroundColor:!disabled&&clickable?baseStyles.color.bg.switch.activeOn:undefined,...focusStylesObject,outline:clickable?focusStylesObject.outline:"none"},...sharedSwitchStyles},slider:{transform:theme.slider.transform.default},icon:{color:disabled?baseStyles.color.bg.icon.disabledOn:baseStyles.color.bg.icon.on,transform:theme.icon.transform.default}};}else {newStyles={switch:{backgroundColor:disabled?baseStyles.color.bg.switch.disabledOff:baseStyles.color.bg.switch.off,":active":{backgroundColor:!disabled&&clickable?baseStyles.color.bg.switch.activeOff:undefined,...focusStylesObject,outline:clickable?focusStylesObject.outline:"none"},...sharedSwitchStyles},slider:{backgroundColor:baseStyles.color.bg.slider.off},icon:{color:disabled?baseStyles.color.bg.icon.disabledOff:baseStyles.color.bg.icon.off}};}styles[checkedStyle]=StyleSheet.create(newStyles);return styles[checkedStyle]};
|
|
14
14
|
|
|
15
15
|
export { Switch as default };
|
package/dist/index.js
CHANGED
|
@@ -31,6 +31,6 @@ var themeDefault = {root:{border:{radius:{default:wonderBlocksTokens.border.radi
|
|
|
31
31
|
|
|
32
32
|
var theme = wonderBlocksTokens.mapValuesToCssVars(themeDefault,"--wb-c-switch-");
|
|
33
33
|
|
|
34
|
-
const StyledSpan=wonderBlocksCore.addStyle("span");const StyledInput=wonderBlocksCore.addStyle("input");const focusStylesObject=wonderBlocksStyles.focusStyles.focus[":focus-visible"];const baseStyles={color:{bg:{switch:{off:wonderBlocksTokens.semanticColor.core.border.neutral.default,disabledOff:wonderBlocksTokens.semanticColor.core.border.disabled.strong,activeOff:wonderBlocksTokens.semanticColor.core.border.neutral.strong,on:wonderBlocksTokens.semanticColor.core.background.instructive.default,disabledOn:wonderBlocksTokens.semanticColor.core.border.
|
|
34
|
+
const StyledSpan=wonderBlocksCore.addStyle("span");const StyledInput=wonderBlocksCore.addStyle("input");const focusStylesObject=wonderBlocksStyles.focusStyles.focus[":focus-visible"];const baseStyles={color:{bg:{switch:{off:wonderBlocksTokens.semanticColor.core.border.neutral.default,disabledOff:wonderBlocksTokens.semanticColor.core.border.disabled.strong,activeOff:wonderBlocksTokens.semanticColor.core.border.neutral.strong,on:wonderBlocksTokens.semanticColor.core.background.instructive.default,disabledOn:wonderBlocksTokens.semanticColor.core.border.disabled.strong,activeOn:wonderBlocksTokens.semanticColor.core.background.instructive.strong},slider:{on:wonderBlocksTokens.semanticColor.core.foreground.knockout.default,off:wonderBlocksTokens.semanticColor.core.foreground.knockout.default},icon:{on:wonderBlocksTokens.semanticColor.core.foreground.instructive.subtle,disabledOn:wonderBlocksTokens.semanticColor.core.foreground.disabled.default,off:wonderBlocksTokens.semanticColor.core.border.neutral.default,disabledOff:wonderBlocksTokens.semanticColor.core.foreground.disabled.default}}}};const sharedStyles=aphrodite.StyleSheet.create({hidden:{opacity:0,height:0,width:0},switch:{display:"inline-flex",height:theme.root.sizing.height,width:theme.root.sizing.width,borderRadius:theme.root.border.radius.default,flexShrink:0},switchFocus:{":focus-within":focusStylesObject},disabled:{cursor:"not-allowed",":hover":{outline:"none"},":active":{outline:"none"}},disabledFocus:{":focus-within":focusStylesObject},slider:{position:"absolute",top:theme.slider.position.top,left:theme.slider.position.left,height:theme.slider.sizing.height,width:theme.slider.sizing.width,borderRadius:theme.root.border.radius.default,backgroundColor:baseStyles.color.bg.slider.on,transition:theme.slider.transform.transition},icon:{position:"absolute",top:theme.icon.position.top,left:theme.icon.position.left,zIndex:1,transition:theme.icon.transform.transition}});const Switch=React__namespace.forwardRef(function Switch(props,ref){const{"aria-label":ariaLabel,"aria-labelledby":ariaLabelledBy,"aria-describedby":ariaDescribedBy,checked,className,disabled=false,icon,id,onChange,testId}=props;const generatedUniqueId=React.useId();const uniqueId=id??generatedUniqueId;const handleClick=()=>{if(!disabled&&onChange){onChange(!checked);}};const handleChange=()=>{};const stateStyles=_generateStyles(checked,onChange!==undefined,disabled);const combinedStyles=[sharedStyles.switch,sharedStyles.switchFocus,stateStyles.switch,disabled&&sharedStyles.disabled,disabled&&sharedStyles.disabledFocus];let styledIcon;if(icon){styledIcon=React__namespace.cloneElement(icon,{size:"small",style:[sharedStyles.icon,stateStyles.icon],"aria-hidden":true});}return jsxRuntime.jsxs(wonderBlocksCore.View,{onClick:handleClick,style:combinedStyles,className:className,testId:testId,children:[jsxRuntime.jsx(StyledInput,{"aria-describedby":ariaDescribedBy,"aria-label":ariaLabel,"aria-labelledby":ariaLabelledBy,checked:checked,"aria-disabled":disabled,id:uniqueId,onChange:handleChange,ref:ref,role:"switch",style:sharedStyles.hidden,type:"checkbox"}),icon&&styledIcon,jsxRuntime.jsx(StyledSpan,{style:[sharedStyles.slider,stateStyles.slider]})]})});const styles={};const _generateStyles=(checked,clickable,disabled)=>{const checkedStyle=`${checked}-${clickable}-${disabled}`;if(styles[checkedStyle]){return styles[checkedStyle]}let newStyles={};const sharedSwitchStyles={cursor:clickable?"pointer":"auto",":hover":{...focusStylesObject,outline:clickable?focusStylesObject.outline:"none"}};if(checked){newStyles={switch:{backgroundColor:disabled?baseStyles.color.bg.switch.disabledOn:baseStyles.color.bg.switch.on,":active":{backgroundColor:!disabled&&clickable?baseStyles.color.bg.switch.activeOn:undefined,...focusStylesObject,outline:clickable?focusStylesObject.outline:"none"},...sharedSwitchStyles},slider:{transform:theme.slider.transform.default},icon:{color:disabled?baseStyles.color.bg.icon.disabledOn:baseStyles.color.bg.icon.on,transform:theme.icon.transform.default}};}else {newStyles={switch:{backgroundColor:disabled?baseStyles.color.bg.switch.disabledOff:baseStyles.color.bg.switch.off,":active":{backgroundColor:!disabled&&clickable?baseStyles.color.bg.switch.activeOff:undefined,...focusStylesObject,outline:clickable?focusStylesObject.outline:"none"},...sharedSwitchStyles},slider:{backgroundColor:baseStyles.color.bg.slider.off},icon:{color:disabled?baseStyles.color.bg.icon.disabledOff:baseStyles.color.bg.icon.off}};}styles[checkedStyle]=aphrodite.StyleSheet.create(newStyles);return styles[checkedStyle]};
|
|
35
35
|
|
|
36
36
|
module.exports = Switch;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
root: {
|
|
3
|
+
border: {
|
|
4
|
+
radius: {
|
|
5
|
+
default: string;
|
|
6
|
+
hover: string;
|
|
7
|
+
press: string;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
sizing: {
|
|
11
|
+
height: string;
|
|
12
|
+
width: string;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
slider: {
|
|
16
|
+
sizing: {
|
|
17
|
+
height: string;
|
|
18
|
+
width: string;
|
|
19
|
+
};
|
|
20
|
+
position: {
|
|
21
|
+
top: string;
|
|
22
|
+
left: string;
|
|
23
|
+
};
|
|
24
|
+
transform: {
|
|
25
|
+
default: string;
|
|
26
|
+
transition: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
icon: {
|
|
30
|
+
position: {
|
|
31
|
+
top: string;
|
|
32
|
+
left: string;
|
|
33
|
+
};
|
|
34
|
+
transform: {
|
|
35
|
+
default: string;
|
|
36
|
+
transition: string;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export default _default;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Switch components for Wonder Blocks.",
|
|
4
4
|
"author": "Khan Academy",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "0.0.0-
|
|
6
|
+
"version": "0.0.0-PR2921-20260109172217",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
@@ -28,18 +28,18 @@
|
|
|
28
28
|
"./styles.css": "./dist/css/vars.css"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@khanacademy/wonder-blocks-core": "
|
|
32
|
-
"@khanacademy/wonder-blocks-icon": "0.0.0-
|
|
33
|
-
"@khanacademy/wonder-blocks-styles": "0.
|
|
34
|
-
"@khanacademy/wonder-blocks-theming": "
|
|
35
|
-
"@khanacademy/wonder-blocks-tokens": "
|
|
31
|
+
"@khanacademy/wonder-blocks-core": "12.4.2",
|
|
32
|
+
"@khanacademy/wonder-blocks-icon": "0.0.0-PR2921-20260109172217",
|
|
33
|
+
"@khanacademy/wonder-blocks-styles": "0.0.0-PR2921-20260109172217",
|
|
34
|
+
"@khanacademy/wonder-blocks-theming": "0.0.0-PR2921-20260109172217",
|
|
35
|
+
"@khanacademy/wonder-blocks-tokens": "0.0.0-PR2921-20260109172217"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"aphrodite": "^1.2.5",
|
|
39
39
|
"react": "18.2.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@khanacademy/wb-dev-build-settings": "
|
|
42
|
+
"@khanacademy/wb-dev-build-settings": "3.2.0"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"build:css": "pnpm exec wonder-blocks-tokens .",
|