@khanacademy/wonder-blocks-switch 3.4.17 → 4.0.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.
- package/.turbo/turbo-build$colon$css.log +1 -1
- package/CHANGELOG.md +76 -0
- package/dist/es/index.css +196 -0
- package/dist/es/index.css.map +1 -0
- package/dist/es/index.js +4 -7
- package/dist/index.css +196 -0
- package/dist/index.css.map +1 -0
- package/dist/index.js +4 -7
- package/package.json +15 -8
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @khanacademy/wonder-blocks-switch@
|
|
2
|
+
> @khanacademy/wonder-blocks-switch@4.0.0 build:css /home/runner/work/wonder-blocks/wonder-blocks/packages/wonder-blocks-switch
|
|
3
3
|
> pnpm exec wonder-blocks-tokens .
|
|
4
4
|
|
|
5
5
|
CSS variables generated successfully in: /home/runner/work/wonder-blocks/wonder-blocks/packages/wonder-blocks-switch/dist/css
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,81 @@
|
|
|
1
1
|
# @khanacademy/wonder-blocks-switch
|
|
2
2
|
|
|
3
|
+
## 4.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- 647e025: **Breaking:** this package now styles its components with CSS Modules instead
|
|
8
|
+
of Aphrodite (WB-2120), and its components render unstyled unless its CSS is
|
|
9
|
+
loaded. To set it up:
|
|
10
|
+
|
|
11
|
+
- **Load the CSS.** The JS entry imports `dist/index.css` as a side effect, and
|
|
12
|
+
`"sideEffects": ["**/*.css"]` keeps bundlers from dropping it, so standard
|
|
13
|
+
webpack, Vite and Next.js setups need no change. Builds that can't process
|
|
14
|
+
CSS imports (some SSR or Jest setups) need a CSS loader or mock. The
|
|
15
|
+
stylesheet is also exported as `./css` for apps that load it explicitly.
|
|
16
|
+
- **Declare the cascade layer order** before any Wonder Blocks CSS:
|
|
17
|
+
`@layer reset, shared, shared.base, shared.reset, legacy;`. The component
|
|
18
|
+
rules live in `@layer shared`, so unlayered app CSS now beats them
|
|
19
|
+
regardless of specificity. Overrides passed through `style` / `styles`
|
|
20
|
+
props still go through Aphrodite and keep winning.
|
|
21
|
+
|
|
22
|
+
`filters`, `icon` and `tabs` also gain an `exports` map, so deep imports such
|
|
23
|
+
as `@khanacademy/wonder-blocks-icon/dist/...` no longer resolve. Import from
|
|
24
|
+
the package root or `./css` instead.
|
|
25
|
+
|
|
26
|
+
See the package's other changesets for the precedence edge cases that change
|
|
27
|
+
behavior, and the "Get Started / CSS setup" guide in Storybook.
|
|
28
|
+
|
|
29
|
+
### Minor Changes
|
|
30
|
+
|
|
31
|
+
- 6ee3145: Migrate `Switch` from Aphrodite to CSS Modules (WB-2332, CSS Modules Phase 5 /
|
|
32
|
+
Wave D). The public component API is unchanged — same props and DOM structure —
|
|
33
|
+
so this is an internal styling refactor.
|
|
34
|
+
|
|
35
|
+
- Styling now lives in `switch.module.css`. Theming (default / thunderblocks /
|
|
36
|
+
syl-dark) is unchanged: the module reads the same `--wb-c-switch-*` variables
|
|
37
|
+
that `build:css` already emits from `src/theme/*`, switched on
|
|
38
|
+
`[data-wb-theme]`.
|
|
39
|
+
- The per-state `StyleSheet.create` cache (`_generateStyles`) is gone. The
|
|
40
|
+
`checked`, `clickable` (an `onChange` was passed) and `disabled` axes are
|
|
41
|
+
conditional class names composed through the `style` prop.
|
|
42
|
+
- Every rule is nested inside a `root` marker class on the track, so the track's
|
|
43
|
+
`display` beats `View`'s defaults (and the icon's position beats
|
|
44
|
+
`PhosphorIcon`'s) on specificity rather than stylesheet load order.
|
|
45
|
+
- The package now ships `dist/index.css` (auto side-effect import) and exposes
|
|
46
|
+
it via the new `@khanacademy/wonder-blocks-switch/css` subpath. `aphrodite` is
|
|
47
|
+
dropped from `peerDependencies` (the package no longer imports it).
|
|
48
|
+
|
|
49
|
+
### Patch Changes
|
|
50
|
+
|
|
51
|
+
- 9652f57: Load each package's CSS after the CSS of the Wonder Blocks packages it depends
|
|
52
|
+
on. The published JS imported its own `index.css` before its dependencies, so
|
|
53
|
+
bundlers emitted, for example, Button's CSS before Typography's. Both sit in
|
|
54
|
+
`@layer shared` with single-class selectors, so the later `BodyText` rule won and
|
|
55
|
+
Button labels lost their own `font-weight`, `line-height` and `font-size`. The CSS
|
|
56
|
+
import now comes after the dependency imports, matching the source order that
|
|
57
|
+
Storybook already uses.
|
|
58
|
+
- f52e4cd: List the `types` condition first in the `.` export of the package.json (where it wasn't already), so TypeScript picks it before `import`/`require`. Make the `./css` export conditional: `import` now resolves to `dist/es/index.css`, the copy the ESM entry already loads, so importing `./css` alongside the components no longer loads the CSS twice. `require` still resolves to `dist/index.css`.
|
|
59
|
+
- Updated dependencies [0c6d97d]
|
|
60
|
+
- Updated dependencies [185dbbc]
|
|
61
|
+
- Updated dependencies [0b6c478]
|
|
62
|
+
- Updated dependencies [9652f57]
|
|
63
|
+
- Updated dependencies [aa5a8e1]
|
|
64
|
+
- Updated dependencies [f52e4cd]
|
|
65
|
+
- Updated dependencies [f52e4cd]
|
|
66
|
+
- Updated dependencies [647e025]
|
|
67
|
+
- Updated dependencies [b66b7b7]
|
|
68
|
+
- Updated dependencies [dbb8f0f]
|
|
69
|
+
- Updated dependencies [82ae405]
|
|
70
|
+
- Updated dependencies [ad52f4b]
|
|
71
|
+
- Updated dependencies [e4f0a12]
|
|
72
|
+
- Updated dependencies [415b002]
|
|
73
|
+
- Updated dependencies [44dac93]
|
|
74
|
+
- @khanacademy/wonder-blocks-tokens@18.3.0
|
|
75
|
+
- @khanacademy/wonder-blocks-core@13.0.0
|
|
76
|
+
- @khanacademy/wonder-blocks-icon@7.0.0
|
|
77
|
+
- @khanacademy/wonder-blocks-styles@1.0.0
|
|
78
|
+
|
|
3
79
|
## 3.4.17
|
|
4
80
|
|
|
5
81
|
### Patch Changes
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
@layer shared {/**
|
|
2
|
+
* Switch styles
|
|
3
|
+
*
|
|
4
|
+
* Every value that differs between the default and thunderblocks themes is a
|
|
5
|
+
* codegen'd `--wb-c-switch-*` token (switched on `[data-wb-theme]`), so the
|
|
6
|
+
* rules below read those directly. Values that never varied by theme are
|
|
7
|
+
* written as the plain `--wb-*` token.
|
|
8
|
+
*
|
|
9
|
+
* Every rule is nested inside `.root` — the marker class on the outermost
|
|
10
|
+
* element, which carries no declarations of its own — for two reasons:
|
|
11
|
+
*
|
|
12
|
+
* 1. The track is a `View`, and `PhosphorIcon` renders the optional icon; both
|
|
13
|
+
* ship single-class rules in the same `@layer shared`, and this component
|
|
14
|
+
* overrides properties they set (`display` on the track). At equal
|
|
15
|
+
* specificity stylesheet load order would decide the winner, so the
|
|
16
|
+
* compound selector makes it depend on specificity instead.
|
|
17
|
+
* 2. It keeps every rule in a group at the same specificity, so source order
|
|
18
|
+
* alone decides precedence between them, as it did when Aphrodite merged
|
|
19
|
+
* the style array into a single class: base track → `checked` →
|
|
20
|
+
* `clickable` → `disabled`, then the `:focus-within` → `:active` →
|
|
21
|
+
* `:hover` states, with the disabled resets last. That order is
|
|
22
|
+
* load-bearing.
|
|
23
|
+
*
|
|
24
|
+
* Nesting is native CSS: every `&` is explicit and resolves to the flat
|
|
25
|
+
* selector it replaces (`.root.switch`, `.root .slider`, …).
|
|
26
|
+
*
|
|
27
|
+
* `checked`, `clickable` (an `onChange` handler was passed) and `disabled` are
|
|
28
|
+
* conditional classes composed through the `style` prop (`processStyleList`
|
|
29
|
+
* routes class-name strings to `className`). The hidden `input` is the
|
|
30
|
+
* element that takes focus, so the track shows the focus ring with
|
|
31
|
+
* `:focus-within`. The build wraps every rule in `@layer shared { … }`.
|
|
32
|
+
*//*
|
|
33
|
+
* Cross-package focus-visible mixin.
|
|
34
|
+
*
|
|
35
|
+
* Authors include the mixin via:
|
|
36
|
+
*
|
|
37
|
+
* @import "@khanacademy/wonder-blocks-styles/focus-styles.css";
|
|
38
|
+
*
|
|
39
|
+
* .my-component:focus-visible {
|
|
40
|
+
* @apply --wb-focus-visible;
|
|
41
|
+
* }
|
|
42
|
+
*
|
|
43
|
+
* postcss-import resolves the @import through the workspace and
|
|
44
|
+
* @csstools/postcss-mixins expands the @apply at build time
|
|
45
|
+
* (CSS Mixins Level 1 syntax — note the leading `--` on the name).
|
|
46
|
+
*/.wb-switch-root-e6326c9d {
|
|
47
|
+
/* The track. */
|
|
48
|
+
&.wb-switch-switch-e6326c9d {
|
|
49
|
+
display: inline-flex;
|
|
50
|
+
block-size: var(--wb-c-switch-root-sizing-height);
|
|
51
|
+
inline-size: var(--wb-c-switch-root-sizing-width);
|
|
52
|
+
border-radius: var(--wb-c-switch-root-border-radius-default);
|
|
53
|
+
flex-shrink: 0;
|
|
54
|
+
background-color: var(--wb-semanticColor-core-border-neutral-default);
|
|
55
|
+
cursor: auto;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
&.wb-switch-checked-e6326c9d {
|
|
59
|
+
background-color: var(
|
|
60
|
+
--wb-semanticColor-core-background-instructive-default
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
&.wb-switch-clickable-e6326c9d {
|
|
65
|
+
cursor: pointer;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/* Checked and unchecked share the same disabled track colour. */
|
|
69
|
+
&.wb-switch-disabled-e6326c9d {
|
|
70
|
+
background-color: var(
|
|
71
|
+
--wb-semanticColor-core-background-disabled-strong
|
|
72
|
+
);
|
|
73
|
+
cursor: not-allowed;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/* The hidden `input` takes focus, so the track shows the ring while
|
|
77
|
+
* anything inside it is focused. */
|
|
78
|
+
&.wb-switch-switch-e6326c9d:focus-within {
|
|
79
|
+
box-shadow: 0 0 0 var(--wb-border-width-medium)
|
|
80
|
+
var(--wb-semanticColor-focus-inner);
|
|
81
|
+
outline: var(--wb-border-width-medium) solid
|
|
82
|
+
var(--wb-semanticColor-focus-outer);
|
|
83
|
+
outline-offset: var(--wb-border-width-medium);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/* Hover and press keep the ring's inner `box-shadow` but only show its
|
|
87
|
+
* outline when the switch can be toggled. */
|
|
88
|
+
&.wb-switch-switch-e6326c9d:active,
|
|
89
|
+
&.wb-switch-switch-e6326c9d:hover {
|
|
90
|
+
box-shadow: 0 0 0 var(--wb-border-width-medium)
|
|
91
|
+
var(--wb-semanticColor-focus-inner);
|
|
92
|
+
outline: var(--wb-border-width-medium) solid
|
|
93
|
+
var(--wb-semanticColor-focus-outer);
|
|
94
|
+
outline-offset: var(--wb-border-width-medium);
|
|
95
|
+
|
|
96
|
+
outline: none;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
&.wb-switch-clickable-e6326c9d:active,
|
|
100
|
+
&.wb-switch-clickable-e6326c9d:hover {
|
|
101
|
+
outline: var(--wb-border-width-medium) solid
|
|
102
|
+
var(--wb-semanticColor-focus-outer);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
&.wb-switch-clickable-e6326c9d:active {
|
|
106
|
+
background-color: var(--wb-semanticColor-core-border-neutral-strong);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
&.wb-switch-clickable-e6326c9d:active:where(.wb-switch-checked-e6326c9d) {
|
|
110
|
+
background-color: var(
|
|
111
|
+
--wb-semanticColor-core-background-instructive-strong
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/* Disabled resets the hover and press states, including the press
|
|
116
|
+
* colour, so the disabled track colour stays. Declared last — see the
|
|
117
|
+
* specificity note above. */
|
|
118
|
+
&.wb-switch-disabled-e6326c9d:active,
|
|
119
|
+
&.wb-switch-disabled-e6326c9d:hover {
|
|
120
|
+
background-color: var(
|
|
121
|
+
--wb-semanticColor-core-background-disabled-strong
|
|
122
|
+
);
|
|
123
|
+
box-shadow: none;
|
|
124
|
+
outline: none;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/* A focused disabled switch keeps the focus ring while hovered or
|
|
128
|
+
* pressed: declared after the disabled resets so it overrides them. */
|
|
129
|
+
&.wb-switch-disabled-e6326c9d:focus-within {
|
|
130
|
+
box-shadow: 0 0 0 var(--wb-border-width-medium)
|
|
131
|
+
var(--wb-semanticColor-focus-inner);
|
|
132
|
+
outline: var(--wb-border-width-medium) solid
|
|
133
|
+
var(--wb-semanticColor-focus-outer);
|
|
134
|
+
outline-offset: var(--wb-border-width-medium);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/* The input is visually hidden: the track and slider render the switch,
|
|
138
|
+
* and the input is used for accessibility. */
|
|
139
|
+
& .wb-switch-hidden-e6326c9d {
|
|
140
|
+
opacity: 0;
|
|
141
|
+
block-size: 0;
|
|
142
|
+
inline-size: 0;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
& .wb-switch-slider-e6326c9d {
|
|
146
|
+
position: absolute;
|
|
147
|
+
inset-block-start: var(--wb-c-switch-slider-position-top);
|
|
148
|
+
inset-inline-start: var(--wb-c-switch-slider-position-left);
|
|
149
|
+
block-size: var(--wb-c-switch-slider-sizing-height);
|
|
150
|
+
inline-size: var(--wb-c-switch-slider-sizing-width);
|
|
151
|
+
border-radius: var(--wb-c-switch-root-border-radius-default);
|
|
152
|
+
background-color: var(
|
|
153
|
+
--wb-semanticColor-action-primary-progressive-default-foreground
|
|
154
|
+
);
|
|
155
|
+
transition: inset-inline-start 0.15s ease-in-out;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
& .wb-switch-icon-e6326c9d {
|
|
159
|
+
position: absolute;
|
|
160
|
+
inset-block-start: var(--wb-c-switch-icon-position-top);
|
|
161
|
+
inset-inline-start: var(--wb-c-switch-icon-position-left);
|
|
162
|
+
z-index: 1;
|
|
163
|
+
color: var(--wb-semanticColor-core-border-neutral-default);
|
|
164
|
+
transition: inset-inline-start 0.15s ease-in-out;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/* Checked moves the slider and icon to the far end of the track. */
|
|
168
|
+
&.wb-switch-checked-e6326c9d .wb-switch-slider-e6326c9d {
|
|
169
|
+
/* track width - slider width - edge offset */
|
|
170
|
+
inset-inline-start: calc(
|
|
171
|
+
100% - var(--wb-sizing-size_200) - var(--wb-sizing-size_020)
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
&.wb-switch-checked-e6326c9d .wb-switch-icon-e6326c9d {
|
|
176
|
+
color: var(--wb-semanticColor-core-foreground-instructive-default);
|
|
177
|
+
|
|
178
|
+
/* track width - icon width (small = size_160) - edge offset */
|
|
179
|
+
inset-inline-start: calc(
|
|
180
|
+
100% - var(--wb-sizing-size_160) - var(--wb-sizing-size_040)
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/* Checked and unchecked share the same disabled slider and icon colours.
|
|
185
|
+
* Declared after `checked` so it overrides it. */
|
|
186
|
+
&.wb-switch-disabled-e6326c9d .wb-switch-slider-e6326c9d {
|
|
187
|
+
background-color: var(--wb-semanticColor-core-foreground-disabled-default);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
&.wb-switch-disabled-e6326c9d .wb-switch-icon-e6326c9d {
|
|
191
|
+
color: var(--wb-semanticColor-core-foreground-disabled-subtle);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/*# sourceMappingURL=index.css.map */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["<no source>","../../src/components/switch.module.css","../../../wonder-blocks-styles/src/styles/focus-styles.css"],"names":[],"mappings":"AAAA,eCAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+BE,CC/BF;;;;;;;;;;;;;;EAcE,CDqBF;IACI,eAAe;IACf;QACI,oBAAoB;QACpB,iDAAiD;QACjD,iDAAiD;QACjD,4DAA4D;QAC5D,cAAc;QACd,qEAAqE;QACrE,YAAY;IAChB;;IAEA;QACI;;SAEC;IACL;;IAEA;QACI,eAAe;IACnB;;IAEA,gEAAgE;IAChE;QACI;;SAEC;QACD,mBAAmB;IACvB;;IAEA;uCACmC;IACnC;ICnDA;2CACuC;IACvC;2CACuC;IACvC,6CAA6C;IDiD7C;;IAEA;gDAC4C;IAC5C;;ICzDA;2CACuC;IACvC;2CACuC;IACvC,6CAA6C;;QDyDzC,aAAa;IACjB;;IAEA;;QAEI;+CACuC;IAC3C;;IAEA;QACI,oEAAoE;IACxE;;IAEA;QACI;;SAEC;IACL;;IAEA;;gCAE4B;IAC5B;;QAEI;;SAEC;QACD,gBAAgB;QAChB,aAAa;IACjB;;IAEA;0EACsE;IACtE;IC9FA;2CACuC;IACvC;2CACuC;IACvC,6CAA6C;ID4F7C;;IAEA;iDAC6C;IAC7C;QACI,UAAU;QACV,aAAa;QACb,cAAc;IAClB;;IAEA;QACI,kBAAkB;QAClB,yDAAyD;QACzD,2DAA2D;QAC3D,mDAAmD;QACnD,mDAAmD;QACnD,4DAA4D;QAC5D;;SAEC;QACD,gDAAgD;IACpD;;IAEA;QACI,kBAAkB;QAClB,uDAAuD;QACvD,yDAAyD;QACzD,UAAU;QACV,0DAA0D;QAC1D,gDAAgD;IACpD;;IAEA,mEAAmE;IACnE;QACI,6CAA6C;QAC7C;;SAEC;IACL;;IAEA;QACI,kEAAkE;;QAElE,8DAA8D;QAC9D;;SAEC;IACL;;IAEA;qDACiD;IACjD;QACI,0EAA0E;IAC9E;;IAEA;QACI,8DAA8D;IAClE;AACJ;CD1KA","file":"index.css","sourcesContent":[null,"/**\n * Switch styles\n *\n * Every value that differs between the default and thunderblocks themes is a\n * codegen'd `--wb-c-switch-*` token (switched on `[data-wb-theme]`), so the\n * rules below read those directly. Values that never varied by theme are\n * written as the plain `--wb-*` token.\n *\n * Every rule is nested inside `.root` — the marker class on the outermost\n * element, which carries no declarations of its own — for two reasons:\n *\n * 1. The track is a `View`, and `PhosphorIcon` renders the optional icon; both\n * ship single-class rules in the same `@layer shared`, and this component\n * overrides properties they set (`display` on the track). At equal\n * specificity stylesheet load order would decide the winner, so the\n * compound selector makes it depend on specificity instead.\n * 2. It keeps every rule in a group at the same specificity, so source order\n * alone decides precedence between them, as it did when Aphrodite merged\n * the style array into a single class: base track → `checked` →\n * `clickable` → `disabled`, then the `:focus-within` → `:active` →\n * `:hover` states, with the disabled resets last. That order is\n * load-bearing.\n *\n * Nesting is native CSS: every `&` is explicit and resolves to the flat\n * selector it replaces (`.root.switch`, `.root .slider`, …).\n *\n * `checked`, `clickable` (an `onChange` handler was passed) and `disabled` are\n * conditional classes composed through the `style` prop (`processStyleList`\n * routes class-name strings to `className`). The hidden `input` is the\n * element that takes focus, so the track shows the focus ring with\n * `:focus-within`. The build wraps every rule in `@layer shared { … }`.\n */\n\n@import \"@khanacademy/wonder-blocks-styles/focus-styles.css\";\n\n.root {\n /* The track. */\n &.switch {\n display: inline-flex;\n block-size: var(--wb-c-switch-root-sizing-height);\n inline-size: var(--wb-c-switch-root-sizing-width);\n border-radius: var(--wb-c-switch-root-border-radius-default);\n flex-shrink: 0;\n background-color: var(--wb-semanticColor-core-border-neutral-default);\n cursor: auto;\n }\n\n &.checked {\n background-color: var(\n --wb-semanticColor-core-background-instructive-default\n );\n }\n\n &.clickable {\n cursor: pointer;\n }\n\n /* Checked and unchecked share the same disabled track colour. */\n &.disabled {\n background-color: var(\n --wb-semanticColor-core-background-disabled-strong\n );\n cursor: not-allowed;\n }\n\n /* The hidden `input` takes focus, so the track shows the ring while\n * anything inside it is focused. */\n &.switch:focus-within {\n @apply --wb-focus-visible;\n }\n\n /* Hover and press keep the ring's inner `box-shadow` but only show its\n * outline when the switch can be toggled. */\n &.switch:active,\n &.switch:hover {\n @apply --wb-focus-visible;\n\n outline: none;\n }\n\n &.clickable:active,\n &.clickable:hover {\n outline: var(--wb-border-width-medium) solid\n var(--wb-semanticColor-focus-outer);\n }\n\n &.clickable:active {\n background-color: var(--wb-semanticColor-core-border-neutral-strong);\n }\n\n &.clickable:active:where(.checked) {\n background-color: var(\n --wb-semanticColor-core-background-instructive-strong\n );\n }\n\n /* Disabled resets the hover and press states, including the press\n * colour, so the disabled track colour stays. Declared last — see the\n * specificity note above. */\n &.disabled:active,\n &.disabled:hover {\n background-color: var(\n --wb-semanticColor-core-background-disabled-strong\n );\n box-shadow: none;\n outline: none;\n }\n\n /* A focused disabled switch keeps the focus ring while hovered or\n * pressed: declared after the disabled resets so it overrides them. */\n &.disabled:focus-within {\n @apply --wb-focus-visible;\n }\n\n /* The input is visually hidden: the track and slider render the switch,\n * and the input is used for accessibility. */\n & .hidden {\n opacity: 0;\n block-size: 0;\n inline-size: 0;\n }\n\n & .slider {\n position: absolute;\n inset-block-start: var(--wb-c-switch-slider-position-top);\n inset-inline-start: var(--wb-c-switch-slider-position-left);\n block-size: var(--wb-c-switch-slider-sizing-height);\n inline-size: var(--wb-c-switch-slider-sizing-width);\n border-radius: var(--wb-c-switch-root-border-radius-default);\n background-color: var(\n --wb-semanticColor-action-primary-progressive-default-foreground\n );\n transition: inset-inline-start 0.15s ease-in-out;\n }\n\n & .icon {\n position: absolute;\n inset-block-start: var(--wb-c-switch-icon-position-top);\n inset-inline-start: var(--wb-c-switch-icon-position-left);\n z-index: 1;\n color: var(--wb-semanticColor-core-border-neutral-default);\n transition: inset-inline-start 0.15s ease-in-out;\n }\n\n /* Checked moves the slider and icon to the far end of the track. */\n &.checked .slider {\n /* track width - slider width - edge offset */\n inset-inline-start: calc(\n 100% - var(--wb-sizing-size_200) - var(--wb-sizing-size_020)\n );\n }\n\n &.checked .icon {\n color: var(--wb-semanticColor-core-foreground-instructive-default);\n\n /* track width - icon width (small = size_160) - edge offset */\n inset-inline-start: calc(\n 100% - var(--wb-sizing-size_160) - var(--wb-sizing-size_040)\n );\n }\n\n /* Checked and unchecked share the same disabled slider and icon colours.\n * Declared after `checked` so it overrides it. */\n &.disabled .slider {\n background-color: var(--wb-semanticColor-core-foreground-disabled-default);\n }\n\n &.disabled .icon {\n color: var(--wb-semanticColor-core-foreground-disabled-subtle);\n }\n}\n","/*\n * Cross-package focus-visible mixin.\n *\n * Authors include the mixin via:\n *\n * @import \"@khanacademy/wonder-blocks-styles/focus-styles.css\";\n *\n * .my-component:focus-visible {\n * @apply --wb-focus-visible;\n * }\n *\n * postcss-import resolves the @import through the workspace and\n * @csstools/postcss-mixins expands the @apply at build time\n * (CSS Mixins Level 1 syntax — note the leading `--` on the name).\n */\n@mixin --wb-focus-visible() {\n box-shadow: 0 0 0 var(--wb-border-width-medium)\n var(--wb-semanticColor-focus-inner);\n outline: var(--wb-border-width-medium) solid\n var(--wb-semanticColor-focus-outer);\n outline-offset: var(--wb-border-width-medium);\n}\n"]}
|
package/dist/es/index.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { useId } from 'react';
|
|
4
|
-
import { StyleSheet } from 'aphrodite';
|
|
5
4
|
import { addStyle, View } from '@khanacademy/wonder-blocks-core';
|
|
6
|
-
import { border, sizing, mapValuesToCssVars, semanticColor } from '@khanacademy/wonder-blocks-tokens';
|
|
7
|
-
import { focusStyles } from '@khanacademy/wonder-blocks-styles';
|
|
8
5
|
|
|
9
|
-
var
|
|
6
|
+
var modules_eb089f86={"root":"wb-switch-root-e6326c9d","switch":"wb-switch-switch-e6326c9d","checked":"wb-switch-checked-e6326c9d","clickable":"wb-switch-clickable-e6326c9d","disabled":"wb-switch-disabled-e6326c9d","hidden":"wb-switch-hidden-e6326c9d","slider":"wb-switch-slider-e6326c9d","icon":"wb-switch-icon-e6326c9d"};
|
|
10
7
|
|
|
11
|
-
|
|
8
|
+
const StyledSpan=addStyle("span");const StyledInput=addStyle("input");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 combinedStyles=[modules_eb089f86.root,modules_eb089f86.switch,checked&&modules_eb089f86.checked,onChange!==undefined&&modules_eb089f86.clickable,disabled&&modules_eb089f86.disabled];let styledIcon;if(icon){styledIcon=React.cloneElement(icon,{size:"small",style:modules_eb089f86.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:modules_eb089f86.hidden,type:"checkbox"}),icon&&styledIcon,jsx(StyledSpan,{style:modules_eb089f86.slider})]})});var Switch$1 = Switch;
|
|
12
9
|
|
|
13
|
-
|
|
10
|
+
export { Switch$1 as default };
|
|
14
11
|
|
|
15
|
-
|
|
12
|
+
import "./index.css";
|
package/dist/index.css
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
@layer shared {/**
|
|
2
|
+
* Switch styles
|
|
3
|
+
*
|
|
4
|
+
* Every value that differs between the default and thunderblocks themes is a
|
|
5
|
+
* codegen'd `--wb-c-switch-*` token (switched on `[data-wb-theme]`), so the
|
|
6
|
+
* rules below read those directly. Values that never varied by theme are
|
|
7
|
+
* written as the plain `--wb-*` token.
|
|
8
|
+
*
|
|
9
|
+
* Every rule is nested inside `.root` — the marker class on the outermost
|
|
10
|
+
* element, which carries no declarations of its own — for two reasons:
|
|
11
|
+
*
|
|
12
|
+
* 1. The track is a `View`, and `PhosphorIcon` renders the optional icon; both
|
|
13
|
+
* ship single-class rules in the same `@layer shared`, and this component
|
|
14
|
+
* overrides properties they set (`display` on the track). At equal
|
|
15
|
+
* specificity stylesheet load order would decide the winner, so the
|
|
16
|
+
* compound selector makes it depend on specificity instead.
|
|
17
|
+
* 2. It keeps every rule in a group at the same specificity, so source order
|
|
18
|
+
* alone decides precedence between them, as it did when Aphrodite merged
|
|
19
|
+
* the style array into a single class: base track → `checked` →
|
|
20
|
+
* `clickable` → `disabled`, then the `:focus-within` → `:active` →
|
|
21
|
+
* `:hover` states, with the disabled resets last. That order is
|
|
22
|
+
* load-bearing.
|
|
23
|
+
*
|
|
24
|
+
* Nesting is native CSS: every `&` is explicit and resolves to the flat
|
|
25
|
+
* selector it replaces (`.root.switch`, `.root .slider`, …).
|
|
26
|
+
*
|
|
27
|
+
* `checked`, `clickable` (an `onChange` handler was passed) and `disabled` are
|
|
28
|
+
* conditional classes composed through the `style` prop (`processStyleList`
|
|
29
|
+
* routes class-name strings to `className`). The hidden `input` is the
|
|
30
|
+
* element that takes focus, so the track shows the focus ring with
|
|
31
|
+
* `:focus-within`. The build wraps every rule in `@layer shared { … }`.
|
|
32
|
+
*//*
|
|
33
|
+
* Cross-package focus-visible mixin.
|
|
34
|
+
*
|
|
35
|
+
* Authors include the mixin via:
|
|
36
|
+
*
|
|
37
|
+
* @import "@khanacademy/wonder-blocks-styles/focus-styles.css";
|
|
38
|
+
*
|
|
39
|
+
* .my-component:focus-visible {
|
|
40
|
+
* @apply --wb-focus-visible;
|
|
41
|
+
* }
|
|
42
|
+
*
|
|
43
|
+
* postcss-import resolves the @import through the workspace and
|
|
44
|
+
* @csstools/postcss-mixins expands the @apply at build time
|
|
45
|
+
* (CSS Mixins Level 1 syntax — note the leading `--` on the name).
|
|
46
|
+
*/.wb-switch-root-e6326c9d {
|
|
47
|
+
/* The track. */
|
|
48
|
+
&.wb-switch-switch-e6326c9d {
|
|
49
|
+
display: inline-flex;
|
|
50
|
+
block-size: var(--wb-c-switch-root-sizing-height);
|
|
51
|
+
inline-size: var(--wb-c-switch-root-sizing-width);
|
|
52
|
+
border-radius: var(--wb-c-switch-root-border-radius-default);
|
|
53
|
+
flex-shrink: 0;
|
|
54
|
+
background-color: var(--wb-semanticColor-core-border-neutral-default);
|
|
55
|
+
cursor: auto;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
&.wb-switch-checked-e6326c9d {
|
|
59
|
+
background-color: var(
|
|
60
|
+
--wb-semanticColor-core-background-instructive-default
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
&.wb-switch-clickable-e6326c9d {
|
|
65
|
+
cursor: pointer;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/* Checked and unchecked share the same disabled track colour. */
|
|
69
|
+
&.wb-switch-disabled-e6326c9d {
|
|
70
|
+
background-color: var(
|
|
71
|
+
--wb-semanticColor-core-background-disabled-strong
|
|
72
|
+
);
|
|
73
|
+
cursor: not-allowed;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/* The hidden `input` takes focus, so the track shows the ring while
|
|
77
|
+
* anything inside it is focused. */
|
|
78
|
+
&.wb-switch-switch-e6326c9d:focus-within {
|
|
79
|
+
box-shadow: 0 0 0 var(--wb-border-width-medium)
|
|
80
|
+
var(--wb-semanticColor-focus-inner);
|
|
81
|
+
outline: var(--wb-border-width-medium) solid
|
|
82
|
+
var(--wb-semanticColor-focus-outer);
|
|
83
|
+
outline-offset: var(--wb-border-width-medium);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/* Hover and press keep the ring's inner `box-shadow` but only show its
|
|
87
|
+
* outline when the switch can be toggled. */
|
|
88
|
+
&.wb-switch-switch-e6326c9d:active,
|
|
89
|
+
&.wb-switch-switch-e6326c9d:hover {
|
|
90
|
+
box-shadow: 0 0 0 var(--wb-border-width-medium)
|
|
91
|
+
var(--wb-semanticColor-focus-inner);
|
|
92
|
+
outline: var(--wb-border-width-medium) solid
|
|
93
|
+
var(--wb-semanticColor-focus-outer);
|
|
94
|
+
outline-offset: var(--wb-border-width-medium);
|
|
95
|
+
|
|
96
|
+
outline: none;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
&.wb-switch-clickable-e6326c9d:active,
|
|
100
|
+
&.wb-switch-clickable-e6326c9d:hover {
|
|
101
|
+
outline: var(--wb-border-width-medium) solid
|
|
102
|
+
var(--wb-semanticColor-focus-outer);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
&.wb-switch-clickable-e6326c9d:active {
|
|
106
|
+
background-color: var(--wb-semanticColor-core-border-neutral-strong);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
&.wb-switch-clickable-e6326c9d:active:where(.wb-switch-checked-e6326c9d) {
|
|
110
|
+
background-color: var(
|
|
111
|
+
--wb-semanticColor-core-background-instructive-strong
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/* Disabled resets the hover and press states, including the press
|
|
116
|
+
* colour, so the disabled track colour stays. Declared last — see the
|
|
117
|
+
* specificity note above. */
|
|
118
|
+
&.wb-switch-disabled-e6326c9d:active,
|
|
119
|
+
&.wb-switch-disabled-e6326c9d:hover {
|
|
120
|
+
background-color: var(
|
|
121
|
+
--wb-semanticColor-core-background-disabled-strong
|
|
122
|
+
);
|
|
123
|
+
box-shadow: none;
|
|
124
|
+
outline: none;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/* A focused disabled switch keeps the focus ring while hovered or
|
|
128
|
+
* pressed: declared after the disabled resets so it overrides them. */
|
|
129
|
+
&.wb-switch-disabled-e6326c9d:focus-within {
|
|
130
|
+
box-shadow: 0 0 0 var(--wb-border-width-medium)
|
|
131
|
+
var(--wb-semanticColor-focus-inner);
|
|
132
|
+
outline: var(--wb-border-width-medium) solid
|
|
133
|
+
var(--wb-semanticColor-focus-outer);
|
|
134
|
+
outline-offset: var(--wb-border-width-medium);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/* The input is visually hidden: the track and slider render the switch,
|
|
138
|
+
* and the input is used for accessibility. */
|
|
139
|
+
& .wb-switch-hidden-e6326c9d {
|
|
140
|
+
opacity: 0;
|
|
141
|
+
block-size: 0;
|
|
142
|
+
inline-size: 0;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
& .wb-switch-slider-e6326c9d {
|
|
146
|
+
position: absolute;
|
|
147
|
+
inset-block-start: var(--wb-c-switch-slider-position-top);
|
|
148
|
+
inset-inline-start: var(--wb-c-switch-slider-position-left);
|
|
149
|
+
block-size: var(--wb-c-switch-slider-sizing-height);
|
|
150
|
+
inline-size: var(--wb-c-switch-slider-sizing-width);
|
|
151
|
+
border-radius: var(--wb-c-switch-root-border-radius-default);
|
|
152
|
+
background-color: var(
|
|
153
|
+
--wb-semanticColor-action-primary-progressive-default-foreground
|
|
154
|
+
);
|
|
155
|
+
transition: inset-inline-start 0.15s ease-in-out;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
& .wb-switch-icon-e6326c9d {
|
|
159
|
+
position: absolute;
|
|
160
|
+
inset-block-start: var(--wb-c-switch-icon-position-top);
|
|
161
|
+
inset-inline-start: var(--wb-c-switch-icon-position-left);
|
|
162
|
+
z-index: 1;
|
|
163
|
+
color: var(--wb-semanticColor-core-border-neutral-default);
|
|
164
|
+
transition: inset-inline-start 0.15s ease-in-out;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/* Checked moves the slider and icon to the far end of the track. */
|
|
168
|
+
&.wb-switch-checked-e6326c9d .wb-switch-slider-e6326c9d {
|
|
169
|
+
/* track width - slider width - edge offset */
|
|
170
|
+
inset-inline-start: calc(
|
|
171
|
+
100% - var(--wb-sizing-size_200) - var(--wb-sizing-size_020)
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
&.wb-switch-checked-e6326c9d .wb-switch-icon-e6326c9d {
|
|
176
|
+
color: var(--wb-semanticColor-core-foreground-instructive-default);
|
|
177
|
+
|
|
178
|
+
/* track width - icon width (small = size_160) - edge offset */
|
|
179
|
+
inset-inline-start: calc(
|
|
180
|
+
100% - var(--wb-sizing-size_160) - var(--wb-sizing-size_040)
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/* Checked and unchecked share the same disabled slider and icon colours.
|
|
185
|
+
* Declared after `checked` so it overrides it. */
|
|
186
|
+
&.wb-switch-disabled-e6326c9d .wb-switch-slider-e6326c9d {
|
|
187
|
+
background-color: var(--wb-semanticColor-core-foreground-disabled-default);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
&.wb-switch-disabled-e6326c9d .wb-switch-icon-e6326c9d {
|
|
191
|
+
color: var(--wb-semanticColor-core-foreground-disabled-subtle);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/*# sourceMappingURL=index.css.map */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["<no source>","../src/components/switch.module.css","../../wonder-blocks-styles/src/styles/focus-styles.css"],"names":[],"mappings":"AAAA,eCAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+BE,CC/BF;;;;;;;;;;;;;;EAcE,CDqBF;IACI,eAAe;IACf;QACI,oBAAoB;QACpB,iDAAiD;QACjD,iDAAiD;QACjD,4DAA4D;QAC5D,cAAc;QACd,qEAAqE;QACrE,YAAY;IAChB;;IAEA;QACI;;SAEC;IACL;;IAEA;QACI,eAAe;IACnB;;IAEA,gEAAgE;IAChE;QACI;;SAEC;QACD,mBAAmB;IACvB;;IAEA;uCACmC;IACnC;ICnDA;2CACuC;IACvC;2CACuC;IACvC,6CAA6C;IDiD7C;;IAEA;gDAC4C;IAC5C;;ICzDA;2CACuC;IACvC;2CACuC;IACvC,6CAA6C;;QDyDzC,aAAa;IACjB;;IAEA;;QAEI;+CACuC;IAC3C;;IAEA;QACI,oEAAoE;IACxE;;IAEA;QACI;;SAEC;IACL;;IAEA;;gCAE4B;IAC5B;;QAEI;;SAEC;QACD,gBAAgB;QAChB,aAAa;IACjB;;IAEA;0EACsE;IACtE;IC9FA;2CACuC;IACvC;2CACuC;IACvC,6CAA6C;ID4F7C;;IAEA;iDAC6C;IAC7C;QACI,UAAU;QACV,aAAa;QACb,cAAc;IAClB;;IAEA;QACI,kBAAkB;QAClB,yDAAyD;QACzD,2DAA2D;QAC3D,mDAAmD;QACnD,mDAAmD;QACnD,4DAA4D;QAC5D;;SAEC;QACD,gDAAgD;IACpD;;IAEA;QACI,kBAAkB;QAClB,uDAAuD;QACvD,yDAAyD;QACzD,UAAU;QACV,0DAA0D;QAC1D,gDAAgD;IACpD;;IAEA,mEAAmE;IACnE;QACI,6CAA6C;QAC7C;;SAEC;IACL;;IAEA;QACI,kEAAkE;;QAElE,8DAA8D;QAC9D;;SAEC;IACL;;IAEA;qDACiD;IACjD;QACI,0EAA0E;IAC9E;;IAEA;QACI,8DAA8D;IAClE;AACJ;CD1KA","file":"index.css","sourcesContent":[null,"/**\n * Switch styles\n *\n * Every value that differs between the default and thunderblocks themes is a\n * codegen'd `--wb-c-switch-*` token (switched on `[data-wb-theme]`), so the\n * rules below read those directly. Values that never varied by theme are\n * written as the plain `--wb-*` token.\n *\n * Every rule is nested inside `.root` — the marker class on the outermost\n * element, which carries no declarations of its own — for two reasons:\n *\n * 1. The track is a `View`, and `PhosphorIcon` renders the optional icon; both\n * ship single-class rules in the same `@layer shared`, and this component\n * overrides properties they set (`display` on the track). At equal\n * specificity stylesheet load order would decide the winner, so the\n * compound selector makes it depend on specificity instead.\n * 2. It keeps every rule in a group at the same specificity, so source order\n * alone decides precedence between them, as it did when Aphrodite merged\n * the style array into a single class: base track → `checked` →\n * `clickable` → `disabled`, then the `:focus-within` → `:active` →\n * `:hover` states, with the disabled resets last. That order is\n * load-bearing.\n *\n * Nesting is native CSS: every `&` is explicit and resolves to the flat\n * selector it replaces (`.root.switch`, `.root .slider`, …).\n *\n * `checked`, `clickable` (an `onChange` handler was passed) and `disabled` are\n * conditional classes composed through the `style` prop (`processStyleList`\n * routes class-name strings to `className`). The hidden `input` is the\n * element that takes focus, so the track shows the focus ring with\n * `:focus-within`. The build wraps every rule in `@layer shared { … }`.\n */\n\n@import \"@khanacademy/wonder-blocks-styles/focus-styles.css\";\n\n.root {\n /* The track. */\n &.switch {\n display: inline-flex;\n block-size: var(--wb-c-switch-root-sizing-height);\n inline-size: var(--wb-c-switch-root-sizing-width);\n border-radius: var(--wb-c-switch-root-border-radius-default);\n flex-shrink: 0;\n background-color: var(--wb-semanticColor-core-border-neutral-default);\n cursor: auto;\n }\n\n &.checked {\n background-color: var(\n --wb-semanticColor-core-background-instructive-default\n );\n }\n\n &.clickable {\n cursor: pointer;\n }\n\n /* Checked and unchecked share the same disabled track colour. */\n &.disabled {\n background-color: var(\n --wb-semanticColor-core-background-disabled-strong\n );\n cursor: not-allowed;\n }\n\n /* The hidden `input` takes focus, so the track shows the ring while\n * anything inside it is focused. */\n &.switch:focus-within {\n @apply --wb-focus-visible;\n }\n\n /* Hover and press keep the ring's inner `box-shadow` but only show its\n * outline when the switch can be toggled. */\n &.switch:active,\n &.switch:hover {\n @apply --wb-focus-visible;\n\n outline: none;\n }\n\n &.clickable:active,\n &.clickable:hover {\n outline: var(--wb-border-width-medium) solid\n var(--wb-semanticColor-focus-outer);\n }\n\n &.clickable:active {\n background-color: var(--wb-semanticColor-core-border-neutral-strong);\n }\n\n &.clickable:active:where(.checked) {\n background-color: var(\n --wb-semanticColor-core-background-instructive-strong\n );\n }\n\n /* Disabled resets the hover and press states, including the press\n * colour, so the disabled track colour stays. Declared last — see the\n * specificity note above. */\n &.disabled:active,\n &.disabled:hover {\n background-color: var(\n --wb-semanticColor-core-background-disabled-strong\n );\n box-shadow: none;\n outline: none;\n }\n\n /* A focused disabled switch keeps the focus ring while hovered or\n * pressed: declared after the disabled resets so it overrides them. */\n &.disabled:focus-within {\n @apply --wb-focus-visible;\n }\n\n /* The input is visually hidden: the track and slider render the switch,\n * and the input is used for accessibility. */\n & .hidden {\n opacity: 0;\n block-size: 0;\n inline-size: 0;\n }\n\n & .slider {\n position: absolute;\n inset-block-start: var(--wb-c-switch-slider-position-top);\n inset-inline-start: var(--wb-c-switch-slider-position-left);\n block-size: var(--wb-c-switch-slider-sizing-height);\n inline-size: var(--wb-c-switch-slider-sizing-width);\n border-radius: var(--wb-c-switch-root-border-radius-default);\n background-color: var(\n --wb-semanticColor-action-primary-progressive-default-foreground\n );\n transition: inset-inline-start 0.15s ease-in-out;\n }\n\n & .icon {\n position: absolute;\n inset-block-start: var(--wb-c-switch-icon-position-top);\n inset-inline-start: var(--wb-c-switch-icon-position-left);\n z-index: 1;\n color: var(--wb-semanticColor-core-border-neutral-default);\n transition: inset-inline-start 0.15s ease-in-out;\n }\n\n /* Checked moves the slider and icon to the far end of the track. */\n &.checked .slider {\n /* track width - slider width - edge offset */\n inset-inline-start: calc(\n 100% - var(--wb-sizing-size_200) - var(--wb-sizing-size_020)\n );\n }\n\n &.checked .icon {\n color: var(--wb-semanticColor-core-foreground-instructive-default);\n\n /* track width - icon width (small = size_160) - edge offset */\n inset-inline-start: calc(\n 100% - var(--wb-sizing-size_160) - var(--wb-sizing-size_040)\n );\n }\n\n /* Checked and unchecked share the same disabled slider and icon colours.\n * Declared after `checked` so it overrides it. */\n &.disabled .slider {\n background-color: var(--wb-semanticColor-core-foreground-disabled-default);\n }\n\n &.disabled .icon {\n color: var(--wb-semanticColor-core-foreground-disabled-subtle);\n }\n}\n","/*\n * Cross-package focus-visible mixin.\n *\n * Authors include the mixin via:\n *\n * @import \"@khanacademy/wonder-blocks-styles/focus-styles.css\";\n *\n * .my-component:focus-visible {\n * @apply --wb-focus-visible;\n * }\n *\n * postcss-import resolves the @import through the workspace and\n * @csstools/postcss-mixins expands the @apply at build time\n * (CSS Mixins Level 1 syntax — note the leading `--` on the name).\n */\n@mixin --wb-focus-visible() {\n box-shadow: 0 0 0 var(--wb-border-width-medium)\n var(--wb-semanticColor-focus-inner);\n outline: var(--wb-border-width-medium) solid\n var(--wb-semanticColor-focus-outer);\n outline-offset: var(--wb-border-width-medium);\n}\n"]}
|
package/dist/index.js
CHANGED
|
@@ -2,10 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
4
|
var React = require('react');
|
|
5
|
-
var aphrodite = require('aphrodite');
|
|
6
5
|
var wonderBlocksCore = require('@khanacademy/wonder-blocks-core');
|
|
7
|
-
var wonderBlocksTokens = require('@khanacademy/wonder-blocks-tokens');
|
|
8
|
-
var wonderBlocksStyles = require('@khanacademy/wonder-blocks-styles');
|
|
9
6
|
|
|
10
7
|
function _interopNamespace(e) {
|
|
11
8
|
if (e && e.__esModule) return e;
|
|
@@ -27,10 +24,10 @@ function _interopNamespace(e) {
|
|
|
27
24
|
|
|
28
25
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
29
26
|
|
|
30
|
-
var
|
|
27
|
+
var modules_eb089f86={"root":"wb-switch-root-e6326c9d","switch":"wb-switch-switch-e6326c9d","checked":"wb-switch-checked-e6326c9d","clickable":"wb-switch-clickable-e6326c9d","disabled":"wb-switch-disabled-e6326c9d","hidden":"wb-switch-hidden-e6326c9d","slider":"wb-switch-slider-e6326c9d","icon":"wb-switch-icon-e6326c9d"};
|
|
31
28
|
|
|
32
|
-
|
|
29
|
+
const StyledSpan=wonderBlocksCore.addStyle("span");const StyledInput=wonderBlocksCore.addStyle("input");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 combinedStyles=[modules_eb089f86.root,modules_eb089f86.switch,checked&&modules_eb089f86.checked,onChange!==undefined&&modules_eb089f86.clickable,disabled&&modules_eb089f86.disabled];let styledIcon;if(icon){styledIcon=React__namespace.cloneElement(icon,{size:"small",style:modules_eb089f86.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:modules_eb089f86.hidden,type:"checkbox"}),icon&&styledIcon,jsxRuntime.jsx(StyledSpan,{style:modules_eb089f86.slider})]})});var Switch$1 = Switch;
|
|
33
30
|
|
|
34
|
-
|
|
31
|
+
module.exports = Switch$1;
|
|
35
32
|
|
|
36
|
-
|
|
33
|
+
require("./index.css");
|
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": "
|
|
6
|
+
"version": "4.0.0",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
@@ -19,23 +19,30 @@
|
|
|
19
19
|
"main": "dist/index.js",
|
|
20
20
|
"module": "dist/es/index.js",
|
|
21
21
|
"types": "dist/index.d.ts",
|
|
22
|
+
"sideEffects": [
|
|
23
|
+
"**/*.css"
|
|
24
|
+
],
|
|
22
25
|
"exports": {
|
|
23
26
|
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
24
28
|
"import": "./dist/es/index.js",
|
|
25
|
-
"require": "./dist/index.js"
|
|
26
|
-
|
|
29
|
+
"require": "./dist/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./css": {
|
|
32
|
+
"import": "./dist/es/index.css",
|
|
33
|
+
"require": "./dist/index.css",
|
|
34
|
+
"default": "./dist/index.css"
|
|
27
35
|
},
|
|
28
36
|
"./styles.css": "./dist/css/vars.css"
|
|
29
37
|
},
|
|
30
38
|
"dependencies": {
|
|
31
|
-
"@khanacademy/wonder-blocks-core": "
|
|
32
|
-
"@khanacademy/wonder-blocks-icon": "
|
|
33
|
-
"@khanacademy/wonder-blocks-styles": "0.
|
|
39
|
+
"@khanacademy/wonder-blocks-core": "13.0.0",
|
|
40
|
+
"@khanacademy/wonder-blocks-icon": "7.0.0",
|
|
41
|
+
"@khanacademy/wonder-blocks-styles": "1.0.0",
|
|
34
42
|
"@khanacademy/wonder-blocks-theming": "4.1.0",
|
|
35
|
-
"@khanacademy/wonder-blocks-tokens": "18.
|
|
43
|
+
"@khanacademy/wonder-blocks-tokens": "18.3.0"
|
|
36
44
|
},
|
|
37
45
|
"peerDependencies": {
|
|
38
|
-
"aphrodite": "^1.2.5",
|
|
39
46
|
"react": "18.2.0"
|
|
40
47
|
},
|
|
41
48
|
"devDependencies": {
|