@rio-m3e/styles 0.0.0-stage → 0.2.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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,6 @@
1
+ Rio
2
+ Copyright 2026 LegenLee
3
+
4
+ This product bundles material-color-utilities
5
+ (https://github.com/material-foundation/material-color-utilities),
6
+ Copyright 2021 Google LLC, licensed under the Apache License, Version 2.0.
package/README.md CHANGED
@@ -1,3 +1,12 @@
1
- # Temporary Holding Version
1
+ # @rio-m3e/styles
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Plain CSS for the components of [Rio](https://github.com/LegenLee/rio), a Material 3 Expressive implementation. It reads the `--rio-*` CSS variables that [`@rio-m3e/tokens`](https://www.npmjs.com/package/@rio-m3e/tokens) sets.
4
+
5
+ Framework adapters such as [`@rio-m3e/vue`](https://www.npmjs.com/package/@rio-m3e/vue) import these files for you. To use them directly, import them one by one:
6
+
7
+ ```ts
8
+ import '@rio-m3e/styles/button.css';
9
+ import '@rio-m3e/styles/base/ripple.css';
10
+ ```
11
+
12
+ Licensed under the Apache License 2.0.
package/css.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ // Empty declaration so side-effect imports like `import '@rio-m3e/styles/*.css'` pass type checking.
2
+ // TypeScript 6 turns on noUncheckedSideEffectImports by default.
3
+ export {};
package/package.json CHANGED
@@ -1,6 +1,31 @@
1
1
  {
2
2
  "name": "@rio-m3e/styles",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.0",
4
+ "description": "Framework-agnostic component styles for Rio",
5
+ "license": "Apache-2.0",
6
+ "author": "LegenLee",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/LegenLee/rio.git",
10
+ "directory": "packages/styles"
11
+ },
12
+ "files": [
13
+ "src",
14
+ "css.d.ts",
15
+ "NOTICE"
16
+ ],
17
+ "type": "module",
18
+ "sideEffects": [
19
+ "**/*.css"
20
+ ],
21
+ "exports": {
22
+ "./*.css": {
23
+ "types": "./css.d.ts",
24
+ "default": "./src/*.css"
25
+ },
26
+ "./package.json": "./package.json"
27
+ },
28
+ "publishConfig": {
29
+ "access": "public"
30
+ }
6
31
  }
@@ -0,0 +1,18 @@
1
+ /*
2
+ * Keyboard focus indicator: a ring around the element, shown only for keyboard-style focus
3
+ * (:focus-visible), so mouse and touch users don't see it.
4
+ *
5
+ * Every M3 component token so far uses `secondary` for the ring. A component that needs another
6
+ * color sets `--rio-focus-ring-color`. The ring follows the element's border radius.
7
+ */
8
+
9
+ .rio-focus-ring:focus-visible {
10
+ outline: var(--rio-state-focus-indicator-thickness) solid
11
+ var(--rio-focus-ring-color, var(--rio-color-secondary));
12
+ outline-offset: var(--rio-state-focus-indicator-outer-offset);
13
+ }
14
+
15
+ /* Draws the ring inside the element, for places where an outer ring would be clipped. */
16
+ .rio-focus-ring[data-focus-ring='inner']:focus-visible {
17
+ outline-offset: var(--rio-state-focus-indicator-inner-offset);
18
+ }
@@ -0,0 +1,21 @@
1
+ /*
2
+ * Reduced motion: when the user asks the OS to reduce motion, spatial motion (position, size,
3
+ * rotation, corner radius) becomes instant. Effects motion (color, opacity) keeps its short fades,
4
+ * which don't cause the discomfort reduced motion is meant to prevent. This is a Rio decision; the
5
+ * M3 pages Rio has read don't define reduced-motion behavior.
6
+ *
7
+ * Every element gets the override, with !important, so it beats the theme variables `applyTheme`
8
+ * sets inline on the root, and any subtree that swaps motion schemes. Components that use the
9
+ * motion tokens import this file. The ripple follows the same rule in JavaScript.
10
+ */
11
+
12
+ @media (prefers-reduced-motion: reduce) {
13
+ * {
14
+ --rio-motion-fast-spatial: 0ms !important;
15
+ --rio-motion-fast-spatial-duration: 0ms !important;
16
+ --rio-motion-default-spatial: 0ms !important;
17
+ --rio-motion-default-spatial-duration: 0ms !important;
18
+ --rio-motion-slow-spatial: 0ms !important;
19
+ --rio-motion-slow-spatial-duration: 0ms !important;
20
+ }
21
+ }
@@ -0,0 +1,63 @@
1
+ /*
2
+ * Press ripple, driven by `attachRipple` from `@rio-m3e/core`. It styles every element the
3
+ * primitive marks with `data-ripple`, so no class is needed. A class would also be fragile: Vue
4
+ * rewrites `class` when a `:class` binding changes, but leaves attributes it doesn't own alone.
5
+ *
6
+ * While pressed, the element has `data-pressed`, and the primitive animates the three registered
7
+ * properties below on `::after`. The ripple is a radial gradient in the content color
8
+ * (currentColor), so it stays inside the element's rounded corners without `overflow: hidden`. It
9
+ * sits under the content, above the state layer on `::before`. Fade timings follow Material Web's
10
+ * ripple.
11
+ */
12
+
13
+ @property --rio-ripple-x {
14
+ syntax: '<length>';
15
+ inherits: false;
16
+ initial-value: 0px;
17
+ }
18
+
19
+ @property --rio-ripple-y {
20
+ syntax: '<length>';
21
+ inherits: false;
22
+ initial-value: 0px;
23
+ }
24
+
25
+ @property --rio-ripple-radius {
26
+ syntax: '<length>';
27
+ inherits: false;
28
+ initial-value: 0px;
29
+ }
30
+
31
+ [data-ripple] {
32
+ position: relative;
33
+ isolation: isolate;
34
+ -webkit-tap-highlight-color: transparent;
35
+ }
36
+
37
+ [data-ripple]::after {
38
+ content: '';
39
+ position: absolute;
40
+ inset: 0;
41
+ z-index: -1;
42
+ border-radius: inherit;
43
+ background: radial-gradient(
44
+ circle var(--rio-ripple-radius) at var(--rio-ripple-x) var(--rio-ripple-y),
45
+ currentColor max(calc(100% - 70px), 65%),
46
+ transparent 100%
47
+ );
48
+ opacity: 0;
49
+ pointer-events: none;
50
+ transition: opacity 375ms linear;
51
+ }
52
+
53
+ [data-ripple][data-pressed]::after {
54
+ opacity: var(--rio-state-pressed-state-layer-opacity);
55
+ transition-duration: 105ms;
56
+ }
57
+
58
+ /* Forced colors replace backgrounds, so the ripple would only get in the way. */
59
+ @media (forced-colors: active) {
60
+ [data-ripple]::after {
61
+ display: none;
62
+ }
63
+ }
@@ -0,0 +1,37 @@
1
+ /*
2
+ * Shape morphing, driven by `attachShapeMorph` from `@rio-m3e/core`. A component sets
3
+ * `--rio-shape-morph-target` to the corner radius it wants in each state. The primitive reads
4
+ * the targets in px, which needs the registrations below, and springs the inline radii toward
5
+ * them. It marks the element with `data-shape-morph`.
6
+ *
7
+ * Shapes whose sides differ set `--rio-shape-morph-start-target` and `--rio-shape-morph-end-target`
8
+ * (the corners at the start and end of the line, in the writing direction) with any class or
9
+ * attribute selector; otherwise both follow `--rio-shape-morph-target`.
10
+ *
11
+ * The component also draws its corners from the per-side targets, so it still works without
12
+ * JavaScript, and lists both targets in its `transition` as `1ms step-end`, so the springs see
13
+ * them change (see "Primitives" in docs/conventions.md, and button.css).
14
+ */
15
+
16
+ @property --rio-shape-morph-target {
17
+ syntax: '<length>';
18
+ inherits: false;
19
+ initial-value: 0px;
20
+ }
21
+
22
+ @property --rio-shape-morph-start-target {
23
+ syntax: '<length>';
24
+ inherits: false;
25
+ initial-value: 0px;
26
+ }
27
+
28
+ @property --rio-shape-morph-end-target {
29
+ syntax: '<length>';
30
+ inherits: false;
31
+ initial-value: 0px;
32
+ }
33
+
34
+ :where([data-shape-morph]) {
35
+ --rio-shape-morph-start-target: var(--rio-shape-morph-target);
36
+ --rio-shape-morph-end-target: var(--rio-shape-morph-target);
37
+ }
@@ -0,0 +1,59 @@
1
+ /*
2
+ * State layer: a semi-transparent overlay in the content color at a fixed opacity per state.
3
+ *
4
+ * Put `rio-state-layer` on the interactive element and set its content color with `color`. The
5
+ * overlay uses `currentColor`, sits between the container background and the content, and shows
6
+ * one state at a time: later rules win, so pressed beats focus, and focus beats hover.
7
+ *
8
+ * Pressed is a flat overlay unless the element has a ripple (`attachRipple` from `@rio-m3e/core`
9
+ * marks it with `data-ripple`). Then the ripple on `::after` shows the press instead.
10
+ */
11
+
12
+ .rio-state-layer {
13
+ position: relative;
14
+ isolation: isolate;
15
+ }
16
+
17
+ .rio-state-layer::before {
18
+ content: '';
19
+ position: absolute;
20
+ inset: 0;
21
+ z-index: -1;
22
+ border-radius: inherit;
23
+ background-color: currentColor;
24
+ opacity: 0;
25
+ pointer-events: none;
26
+ transition: opacity var(--rio-motion-fast-effects);
27
+ }
28
+
29
+ /* Touch screens keep :hover after a tap, so only devices that can hover get a hover state. */
30
+ @media (hover: hover) {
31
+ .rio-state-layer:hover::before {
32
+ opacity: var(--rio-state-hover-state-layer-opacity);
33
+ }
34
+ }
35
+
36
+ .rio-state-layer:focus-visible::before {
37
+ opacity: var(--rio-state-focus-state-layer-opacity);
38
+ }
39
+
40
+ .rio-state-layer:not([data-ripple]):is(:active, [data-pressed])::before {
41
+ opacity: var(--rio-state-pressed-state-layer-opacity);
42
+ }
43
+
44
+ /* `attachDrag` from `@rio-m3e/core` marks an element with `data-dragging` while it moves. */
45
+ .rio-state-layer[data-dragging]::before {
46
+ opacity: var(--rio-state-dragged-state-layer-opacity);
47
+ }
48
+
49
+ /* Disabled elements don't change state, so they get no state layer at all. */
50
+ .rio-state-layer:is(:disabled, [aria-disabled='true'])::before {
51
+ opacity: 0;
52
+ }
53
+
54
+ /* Forced colors replace backgrounds, so the overlay would only get in the way. */
55
+ @media (forced-colors: active) {
56
+ .rio-state-layer::before {
57
+ display: none;
58
+ }
59
+ }
@@ -0,0 +1,98 @@
1
+ /*
2
+ * M3E button group: a row of buttons and icon buttons (`button.css`, `icon-button.css`). The group
3
+ * has no color of its own. It carries `data-variant`, `data-size`, and `data-shape`, which
4
+ * `createButtonGroup` from `@rio-m3e/core` sets; the size and shape reach the buttons through the
5
+ * framework adapter, so these rules read the buttons' own `data-size` and `data-shape`.
6
+ *
7
+ * Values come from Material Web's component tokens (`_md-comp-button-group-standard-*.scss` and
8
+ * `_md-comp-button-group-connected-*.scss`, Material 3 v34.0.21). The pressed button's width
9
+ * change in standard groups is JavaScript (`attachButtonGroup` from `@rio-m3e/core`).
10
+ */
11
+
12
+ .rio-button-group {
13
+ /* Standard, small */
14
+ --_between: 12px;
15
+
16
+ display: inline-flex;
17
+ align-items: center;
18
+ gap: var(--_between);
19
+ vertical-align: middle;
20
+ }
21
+
22
+ /* Standard: the space keeps every button's 48px target clear of its neighbors' */
23
+
24
+ .rio-button-group:where([data-size='xsmall']) {
25
+ --_between: 18px;
26
+ }
27
+
28
+ .rio-button-group:where([data-size='medium'], [data-size='large'], [data-size='xlarge']) {
29
+ --_between: 8px;
30
+ }
31
+
32
+ /*
33
+ * Connected: 2px apart, and as wide as the space it's given, shared equally by its buttons. The
34
+ * ends of the row keep the group's shape; the facing corners are smaller, tighten when pressed,
35
+ * and open up fully when the button is selected. Each button springs its two sides separately
36
+ * (see base/shape-morph.css).
37
+ */
38
+
39
+ .rio-button-group:where([data-variant='connected']) {
40
+ --_between: 2px;
41
+
42
+ display: flex;
43
+ }
44
+
45
+ .rio-button-group[data-variant='connected'] > .rio-button {
46
+ /* Small, medium, and extra small */
47
+ --_inner: var(--rio-shape-corner-small);
48
+ --_inner-pressed: var(--rio-shape-corner-extra-small);
49
+ /* Corners that face another button, and corners at the ends of the row */
50
+ --_inner-now: var(--_inner);
51
+ --_outer: var(--_round);
52
+ --_start: var(--_inner-now);
53
+ --_end: var(--_inner-now);
54
+
55
+ flex: 1 1 0;
56
+ /* The corners show these targets (button.css). */
57
+ --rio-shape-morph-start-target: var(--_start);
58
+ --rio-shape-morph-end-target: var(--_end);
59
+ }
60
+
61
+ .rio-button-group[data-variant='connected'] > .rio-button:where([data-size='large']) {
62
+ --_inner: var(--rio-shape-corner-large);
63
+ --_inner-pressed: var(--rio-shape-corner-medium);
64
+ }
65
+
66
+ .rio-button-group[data-variant='connected'] > .rio-button:where([data-size='xlarge']) {
67
+ --_inner: var(--rio-shape-corner-large-increased);
68
+ --_inner-pressed: var(--rio-shape-corner-large);
69
+ }
70
+
71
+ /* A square group's ends use the same radius as its facing corners. */
72
+ .rio-button-group[data-variant='connected'] > .rio-button[data-shape='square'] {
73
+ --_outer: var(--_inner);
74
+ }
75
+
76
+ .rio-button-group[data-variant='connected'] > .rio-button:first-child {
77
+ --_start: var(--_outer);
78
+ }
79
+
80
+ .rio-button-group[data-variant='connected'] > .rio-button:last-child {
81
+ --_end: var(--_outer);
82
+ }
83
+
84
+ .rio-button-group[data-variant='connected'] > .rio-button[data-selected='true'] {
85
+ --_inner-now: var(--_round);
86
+ --_outer: var(--_round);
87
+ }
88
+
89
+ /* After selected, so a pressed selected button still tightens its facing corners */
90
+ .rio-button-group[data-variant='connected'] > .rio-button[data-pressed] {
91
+ --_inner-now: var(--_inner-pressed);
92
+ }
93
+
94
+ /* Extra small and small icon buttons keep a 48px minimum width, matching their target. */
95
+ .rio-button-group[data-variant='connected']
96
+ > .rio-icon-button:where([data-size='xsmall'], [data-size='small']) {
97
+ min-inline-size: 48px;
98
+ }
package/src/button.css ADDED
@@ -0,0 +1,278 @@
1
+ /*
2
+ * M3E common button.
3
+ *
4
+ * Values come from Material Web's component tokens (`_md-comp-button-*.scss`, Material 3
5
+ * v34.0.21). Label type styles per size come from Compose's `ButtonDefaults.textStyleFor`. The
6
+ * element carries `data-variant`, `data-size`, `data-shape`, and, for toggle buttons,
7
+ * `data-selected`, which `createButton` from `@rio-m3e/core` sets.
8
+ *
9
+ * Variant, size, shape, and toggle rules sit inside `:where()`, so they add no specificity. The
10
+ * disabled and pressed rules always win, and apps can override any of them with a single class.
11
+ */
12
+
13
+ .rio-button {
14
+ /* Size: small, the default */
15
+ --_height: 40px;
16
+ --_padding: 16px;
17
+ --_icon-size: 20px;
18
+ --_gap: 8px;
19
+ --_outline-width: 1px;
20
+ --_square: var(--rio-shape-corner-medium);
21
+ --_pressed: var(--rio-shape-corner-small);
22
+ --_selected-round: var(--rio-shape-corner-medium);
23
+ --_font: var(--rio-typescale-label-large);
24
+ --_tracking: var(--rio-typescale-label-large-tracking);
25
+
26
+ /* Round is half the height rather than corner-full (9999px), so it animates into other shapes. */
27
+ --_round: calc(var(--_height) / 2);
28
+ --_radius: var(--_round);
29
+
30
+ /* Color: filled, the default */
31
+ --_container: var(--rio-color-primary);
32
+ --_content: var(--rio-color-on-primary);
33
+ --_outline: transparent;
34
+ --_elevation: var(--rio-elevation-level0);
35
+ --_hover-elevation: var(--rio-elevation-level1);
36
+
37
+ display: inline-flex;
38
+ align-items: center;
39
+ justify-content: center;
40
+ gap: var(--_gap);
41
+ box-sizing: border-box;
42
+ block-size: var(--_height);
43
+ padding-inline: var(--_padding);
44
+ border: var(--_outline-width) solid var(--_outline);
45
+ /*
46
+ * The shape-morph primitive springs the inline radii toward these targets. The corners show the
47
+ * targets, not `--_radius`: when the state changes, a target holds its old value until the
48
+ * spring takes over (see `transition` below), so the new shape doesn't flash first. Button
49
+ * groups and split buttons set the per-side targets.
50
+ */
51
+ --rio-shape-morph-target: var(--_radius);
52
+ --rio-shape-morph-start-target: var(--rio-shape-morph-target);
53
+ --rio-shape-morph-end-target: var(--rio-shape-morph-target);
54
+ border-start-start-radius: var(--rio-shape-morph-start-target);
55
+ border-end-start-radius: var(--rio-shape-morph-start-target);
56
+ border-start-end-radius: var(--rio-shape-morph-end-target);
57
+ border-end-end-radius: var(--rio-shape-morph-end-target);
58
+ background-color: var(--_container);
59
+ box-shadow: var(--_elevation);
60
+ color: var(--_content);
61
+ font: var(--_font);
62
+ letter-spacing: var(--_tracking);
63
+ white-space: nowrap;
64
+ vertical-align: middle;
65
+ cursor: pointer;
66
+ user-select: none;
67
+ /*
68
+ * No border-radius transition: corners move with the fast-spatial spring (see
69
+ * base/shape-morph.css). The spring targets get an instant transition instead, which is how the
70
+ * spring sees them change (core's spring-property). `--rio-spring-targets` is public: an app
71
+ * that sets its own `transition` on a button keeps the morphing by including it, and
72
+ * stylesheets that spring more targets on a button extend it.
73
+ */
74
+ --rio-spring-targets:
75
+ --rio-shape-morph-start-target 1ms step-end, --rio-shape-morph-end-target 1ms step-end;
76
+ transition:
77
+ background-color var(--rio-motion-fast-effects),
78
+ color var(--rio-motion-fast-effects),
79
+ box-shadow var(--rio-motion-fast-effects),
80
+ var(--rio-spring-targets);
81
+ }
82
+
83
+ /* Sizes */
84
+
85
+ .rio-button:where([data-size='xsmall']) {
86
+ --_height: 32px;
87
+ --_padding: 12px;
88
+ }
89
+
90
+ .rio-button:where([data-size='medium']) {
91
+ --_height: 56px;
92
+ --_padding: 24px;
93
+ --_icon-size: 24px;
94
+ --_square: var(--rio-shape-corner-large);
95
+ --_pressed: var(--rio-shape-corner-medium);
96
+ --_selected-round: var(--rio-shape-corner-large);
97
+ --_font: var(--rio-typescale-title-medium);
98
+ --_tracking: var(--rio-typescale-title-medium-tracking);
99
+ }
100
+
101
+ .rio-button:where([data-size='large']) {
102
+ --_height: 96px;
103
+ --_padding: 48px;
104
+ --_icon-size: 32px;
105
+ --_gap: 12px;
106
+ --_outline-width: 2px;
107
+ --_square: var(--rio-shape-corner-extra-large);
108
+ --_pressed: var(--rio-shape-corner-large);
109
+ --_selected-round: var(--rio-shape-corner-extra-large);
110
+ --_font: var(--rio-typescale-headline-small);
111
+ --_tracking: var(--rio-typescale-headline-small-tracking);
112
+ }
113
+
114
+ .rio-button:where([data-size='xlarge']) {
115
+ --_height: 136px;
116
+ --_padding: 64px;
117
+ --_icon-size: 40px;
118
+ --_gap: 16px;
119
+ --_outline-width: 3px;
120
+ --_square: var(--rio-shape-corner-extra-large);
121
+ --_pressed: var(--rio-shape-corner-large);
122
+ --_selected-round: var(--rio-shape-corner-extra-large);
123
+ --_font: var(--rio-typescale-headline-large);
124
+ --_tracking: var(--rio-typescale-headline-large-tracking);
125
+ }
126
+
127
+ /* Shapes. A selected toggle swaps them: round turns square-ish, square turns round. */
128
+
129
+ .rio-button:where([data-shape='square']) {
130
+ --_radius: var(--_square);
131
+ }
132
+
133
+ .rio-button:where([data-selected='true']) {
134
+ --_radius: var(--_selected-round);
135
+ }
136
+
137
+ .rio-button:where([data-shape='square'][data-selected='true']) {
138
+ --_radius: var(--_round);
139
+ }
140
+
141
+ /* Variants */
142
+
143
+ .rio-button:where([data-variant='tonal']) {
144
+ --_container: var(--rio-color-secondary-container);
145
+ --_content: var(--rio-color-on-secondary-container);
146
+ }
147
+
148
+ .rio-button:where([data-variant='outlined']) {
149
+ --_container: transparent;
150
+ --_content: var(--rio-color-on-surface-variant);
151
+ --_outline: var(--rio-color-outline-variant);
152
+ --_hover-elevation: var(--rio-elevation-level0);
153
+ }
154
+
155
+ .rio-button:where([data-variant='elevated']) {
156
+ --_container: var(--rio-color-surface-container-low);
157
+ --_content: var(--rio-color-primary);
158
+ --_elevation: var(--rio-elevation-level1);
159
+ --_hover-elevation: var(--rio-elevation-level2);
160
+ }
161
+
162
+ .rio-button:where([data-variant='text']) {
163
+ --_container: transparent;
164
+ --_content: var(--rio-color-primary);
165
+ --_hover-elevation: var(--rio-elevation-level0);
166
+ }
167
+
168
+ /* Icon buttons only (see icon-button.css): no container, like text, but it can toggle */
169
+ .rio-button:where([data-variant='standard']) {
170
+ --_container: transparent;
171
+ --_content: var(--rio-color-on-surface-variant);
172
+ }
173
+
174
+ /* Toggle buttons: unselected and selected colors, where they differ from the defaults above */
175
+
176
+ .rio-button:where([data-variant='filled'][data-selected='false']) {
177
+ --_container: var(--rio-color-surface-container);
178
+ --_content: var(--rio-color-on-surface-variant);
179
+ }
180
+
181
+ .rio-button:where([data-variant='tonal'][data-selected='true']) {
182
+ --_container: var(--rio-color-secondary);
183
+ --_content: var(--rio-color-on-secondary);
184
+ }
185
+
186
+ .rio-button:where([data-variant='outlined'][data-selected='true']) {
187
+ --_container: var(--rio-color-inverse-surface);
188
+ --_content: var(--rio-color-inverse-on-surface);
189
+ --_outline: transparent;
190
+ }
191
+
192
+ .rio-button:where([data-variant='elevated'][data-selected='true']) {
193
+ --_container: var(--rio-color-primary);
194
+ --_content: var(--rio-color-on-primary);
195
+ }
196
+
197
+ .rio-button:where([data-variant='standard'][data-selected='true']) {
198
+ --_content: var(--rio-color-primary);
199
+ }
200
+
201
+ /* Interaction: hover lifts one level, pressing returns to rest and morphs the corners */
202
+
203
+ @media (hover: hover) {
204
+ .rio-button:hover {
205
+ box-shadow: var(--_hover-elevation);
206
+ }
207
+ }
208
+
209
+ .rio-button[data-pressed] {
210
+ --rio-shape-morph-target: var(--_pressed);
211
+ box-shadow: var(--_elevation);
212
+ }
213
+
214
+ /* Disabled, native or soft */
215
+
216
+ .rio-button:is(:disabled, [aria-disabled='true']) {
217
+ --_container: color-mix(in srgb, var(--rio-color-on-surface) 10%, transparent);
218
+ --_content: color-mix(
219
+ in srgb,
220
+ var(--rio-color-on-surface) calc(var(--rio-state-disabled-state-layer-opacity) * 100%),
221
+ transparent
222
+ );
223
+ --_elevation: none;
224
+ --_hover-elevation: none;
225
+ cursor: default;
226
+ }
227
+
228
+ .rio-button:is(:disabled, [aria-disabled='true']):where(
229
+ [data-variant='outlined'],
230
+ [data-variant='text'],
231
+ [data-variant='standard']
232
+ ) {
233
+ --_container: transparent;
234
+ }
235
+
236
+ .rio-button:is(:disabled, [aria-disabled='true']):where(
237
+ [data-variant='outlined'][data-selected='true']
238
+ ) {
239
+ --_container: color-mix(in srgb, var(--rio-color-on-surface) 10%, transparent);
240
+ }
241
+
242
+ /*
243
+ * The state layer (::before) and the ripple (::after) cover the border too. With `inset: 0` they
244
+ * would stop at the padding box, inside the border, and look slightly smaller than the container.
245
+ * Every variant keeps a border, transparent unless outlined, because forced-colors mode paints
246
+ * transparent borders in a system color and keeps the button's edge visible.
247
+ */
248
+ .rio-button[data-variant]::before,
249
+ .rio-button[data-variant]::after {
250
+ inset: calc(-1 * var(--_outline-width));
251
+ }
252
+
253
+ /* Parts */
254
+
255
+ /* Extra small and small buttons are shorter than the spec's 48px minimum target. */
256
+ .rio-button__touch {
257
+ position: absolute;
258
+ /* Physical, like `translate`: a logical start would flip in right-to-left layouts and push the
259
+ target off the button. */
260
+ top: 50%;
261
+ left: 50%;
262
+ inline-size: max(100%, 48px);
263
+ block-size: max(100%, 48px);
264
+ translate: -50% -50%;
265
+ }
266
+
267
+ .rio-button__icon {
268
+ display: inline-flex;
269
+ flex: none;
270
+ inline-size: var(--_icon-size);
271
+ block-size: var(--_icon-size);
272
+ font-size: var(--_icon-size);
273
+ }
274
+
275
+ .rio-button__icon > :is(svg, img) {
276
+ inline-size: 100%;
277
+ block-size: 100%;
278
+ }
@@ -0,0 +1,84 @@
1
+ /*
2
+ * M3E icon button, layered on top of `button.css`. The root carries both `rio-button` and
3
+ * `rio-icon-button`, so it inherits the button's shapes (round, square, pressed, selected), shape
4
+ * morphing, colors (the `standard` variant lives in `button.css` with the others), disabled rules,
5
+ * state layer, ripple, and touch target. This file holds only what differs: the three widths, the
6
+ * icon sizes, and no elevation.
7
+ *
8
+ * Values come from Material Web's component tokens (`_md-comp-icon-button-*.scss`, Material 3
9
+ * v34.0.21). Every rule is `.rio-button.rio-icon-button`, so it beats `button.css` in any load
10
+ * order. None of them touch what the disabled and pressed rules set, so those still apply.
11
+ */
12
+
13
+ .rio-button.rio-icon-button {
14
+ /* Small, default width */
15
+ --_icon-size: 24px;
16
+ --_padding: 8px;
17
+ --_elevation: none;
18
+ --_hover-elevation: none;
19
+
20
+ inline-size: calc(var(--_icon-size) + 2 * var(--_padding));
21
+ padding: 0;
22
+ }
23
+
24
+ /* Sizes: icon size and the padding beside it for each width */
25
+
26
+ .rio-button.rio-icon-button:where([data-size='xsmall']) {
27
+ --_icon-size: 20px;
28
+ --_padding: 6px;
29
+ }
30
+
31
+ .rio-button.rio-icon-button:where([data-size='xsmall'][data-width='narrow']) {
32
+ --_padding: 4px;
33
+ }
34
+
35
+ .rio-button.rio-icon-button:where([data-size='xsmall'][data-width='wide']) {
36
+ --_padding: 10px;
37
+ }
38
+
39
+ .rio-button.rio-icon-button:where([data-size='small'][data-width='narrow']) {
40
+ --_padding: 4px;
41
+ }
42
+
43
+ .rio-button.rio-icon-button:where([data-size='small'][data-width='wide']) {
44
+ --_padding: 14px;
45
+ }
46
+
47
+ .rio-button.rio-icon-button:where([data-size='medium']) {
48
+ --_icon-size: 24px;
49
+ --_padding: 16px;
50
+ }
51
+
52
+ .rio-button.rio-icon-button:where([data-size='medium'][data-width='narrow']) {
53
+ --_padding: 12px;
54
+ }
55
+
56
+ .rio-button.rio-icon-button:where([data-size='medium'][data-width='wide']) {
57
+ --_padding: 24px;
58
+ }
59
+
60
+ .rio-button.rio-icon-button:where([data-size='large']) {
61
+ --_icon-size: 32px;
62
+ --_padding: 32px;
63
+ }
64
+
65
+ .rio-button.rio-icon-button:where([data-size='large'][data-width='narrow']) {
66
+ --_padding: 16px;
67
+ }
68
+
69
+ .rio-button.rio-icon-button:where([data-size='large'][data-width='wide']) {
70
+ --_padding: 48px;
71
+ }
72
+
73
+ .rio-button.rio-icon-button:where([data-size='xlarge']) {
74
+ --_icon-size: 40px;
75
+ --_padding: 48px;
76
+ }
77
+
78
+ .rio-button.rio-icon-button:where([data-size='xlarge'][data-width='narrow']) {
79
+ --_padding: 32px;
80
+ }
81
+
82
+ .rio-button.rio-icon-button:where([data-size='xlarge'][data-width='wide']) {
83
+ --_padding: 72px;
84
+ }
@@ -0,0 +1,185 @@
1
+ /*
2
+ * M3E split button: a leading button and a trailing menu button, 2px apart. Both are buttons
3
+ * (`button.css`), so they keep the button's sizes, colors, elevation, disabled rules, state layer,
4
+ * ripple, and touch target. This file adds what differs: the paddings, the trailing button's
5
+ * width, the corners, and the menu icon. `createSplitButton` from `@rio-m3e/core` sets the
6
+ * attributes, and the buttons carry `data-size`, `data-variant`, and, on the trailing button,
7
+ * `data-open`.
8
+ *
9
+ * Values come from Material Web's component tokens (`_md-comp-split-button-*.scss`, Material 3
10
+ * v34.0.21). The menu icon's offset comes from the spec page's measurements, and its direction
11
+ * (toward the start) from the M3 Design Kit.
12
+ */
13
+
14
+ @property --rio-split-button-menu-turn-target {
15
+ syntax: '<angle>';
16
+ inherits: false;
17
+ initial-value: 0deg;
18
+ }
19
+
20
+ @property --rio-split-button-menu-shift-target {
21
+ syntax: '<length>';
22
+ inherits: false;
23
+ initial-value: 0px;
24
+ }
25
+
26
+ .rio-split-button {
27
+ display: inline-flex;
28
+ align-items: center;
29
+ gap: 2px;
30
+ vertical-align: middle;
31
+ }
32
+
33
+ /*
34
+ * Both buttons: the corners at the ends of the split button are round, and the facing ones are
35
+ * small. Hovering, focusing, or pressing a button rounds its facing corners more, and opening the
36
+ * menu rounds the trailing button fully. Each side springs on its own (see base/shape-morph.css).
37
+ */
38
+ .rio-split-button > .rio-button {
39
+ /* Small */
40
+ --_lead-start: 16px;
41
+ --_lead-end: 12px;
42
+ --_menu-size: 22px;
43
+ --_menu-padding: 13px;
44
+ --_menu-offset: 1px;
45
+ --_inner: var(--rio-shape-corner-extra-small);
46
+ --_inner-active: var(--rio-shape-corner-medium);
47
+
48
+ --_inner-now: var(--_inner);
49
+ }
50
+
51
+ /*
52
+ * `[data-variant]` is always there; it lifts this above button.css's per-side defaults in any
53
+ * order. The corners show these targets (button.css).
54
+ */
55
+ .rio-split-button > .rio-button[data-variant] {
56
+ --rio-shape-morph-start-target: var(--_start);
57
+ --rio-shape-morph-end-target: var(--_end);
58
+ }
59
+
60
+ .rio-split-button > .rio-button:where([data-size='xsmall']) {
61
+ --_lead-start: 12px;
62
+ --_lead-end: 10px;
63
+ --_inner-active: var(--rio-shape-corner-small);
64
+ }
65
+
66
+ .rio-split-button > .rio-button:where([data-size='medium']) {
67
+ --_lead-start: 24px;
68
+ --_lead-end: 24px;
69
+ --_menu-size: 26px;
70
+ --_menu-padding: 15px;
71
+ --_menu-offset: 2px;
72
+ }
73
+
74
+ .rio-split-button > .rio-button:where([data-size='large']) {
75
+ --_lead-start: 48px;
76
+ --_lead-end: 48px;
77
+ --_menu-size: 38px;
78
+ --_menu-padding: 29px;
79
+ --_menu-offset: 3px;
80
+ --_inner: var(--rio-shape-corner-small);
81
+ --_inner-active: var(--rio-shape-corner-large-increased);
82
+ }
83
+
84
+ .rio-split-button > .rio-button:where([data-size='xlarge']) {
85
+ --_lead-start: 64px;
86
+ --_lead-end: 64px;
87
+ --_menu-size: 50px;
88
+ --_menu-padding: 43px;
89
+ --_menu-offset: 6px;
90
+ --_inner: var(--rio-shape-corner-medium);
91
+ --_inner-active: var(--rio-shape-corner-large-increased);
92
+ }
93
+
94
+ @media (hover: hover) {
95
+ .rio-split-button > .rio-button:hover {
96
+ --_inner-now: var(--_inner-active);
97
+ }
98
+ }
99
+
100
+ .rio-split-button > .rio-button:is(:focus-visible, [data-pressed]) {
101
+ --_inner-now: var(--_inner-active);
102
+ }
103
+
104
+ /*
105
+ * Disabled buttons don't react, so their corners stay put. Being open still shows (that rule comes
106
+ * later): a disabled toggle button keeps its selected shape too.
107
+ */
108
+ .rio-split-button > .rio-button:is(:disabled, [aria-disabled='true']) {
109
+ --_inner-now: var(--_inner);
110
+ }
111
+
112
+ /* Leading button */
113
+
114
+ .rio-split-button > .rio-split-button__leading {
115
+ --_start: var(--_round);
116
+ --_end: var(--_inner-now);
117
+
118
+ padding-inline: var(--_lead-start) var(--_lead-end);
119
+ }
120
+
121
+ /* Trailing button: a square, or 48px wide when shorter, with the menu icon in it */
122
+
123
+ .rio-split-button > .rio-split-button__trailing {
124
+ --_start: var(--_inner-now);
125
+ --_end: var(--_round);
126
+ --rio-split-button-menu-shift-target: var(--_menu-offset);
127
+ /* Toward the start: left, or right in right-to-left layouts */
128
+ --_start-sign: -1;
129
+
130
+ inline-size: calc(var(--_menu-size) + 2 * var(--_menu-padding));
131
+ padding: 0;
132
+ }
133
+
134
+ .rio-split-button > .rio-split-button__trailing:dir(rtl) {
135
+ --_start-sign: 1;
136
+ }
137
+
138
+ /*
139
+ * Open: fully round, with the icon centered and turned half a circle, its point swinging through
140
+ * the start side, toward the leading button. The color doesn't change; a state layer shows
141
+ * instead, at the pressed opacity.
142
+ */
143
+ .rio-split-button > .rio-split-button__trailing[data-open] {
144
+ --_inner-now: var(--_round);
145
+ --rio-split-button-menu-turn-target: 180deg;
146
+ --rio-split-button-menu-shift-target: 0px;
147
+ }
148
+
149
+ .rio-split-button > .rio-split-button__trailing[data-open]:dir(rtl) {
150
+ --rio-split-button-menu-turn-target: -180deg;
151
+ }
152
+
153
+ .rio-split-button
154
+ > .rio-split-button__trailing[data-open]:not(:disabled, [aria-disabled='true'])::before {
155
+ opacity: var(--rio-state-pressed-state-layer-opacity);
156
+ }
157
+
158
+ /*
159
+ * The springs in `attachSplitButtonMenuIcon` write `--_menu-turn` and `--_menu-shift` while they
160
+ * move; at rest the targets apply. The targets are registered and don't inherit, so they are
161
+ * passed down through these.
162
+ */
163
+ .rio-split-button > .rio-split-button__trailing {
164
+ --_menu-turn-rest: var(--rio-split-button-menu-turn-target);
165
+ --_menu-shift-rest: var(--rio-split-button-menu-shift-target);
166
+ /* The button's spring targets (button.css), and the menu icon's. */
167
+ --rio-spring-targets:
168
+ --rio-shape-morph-start-target 1ms step-end, --rio-shape-morph-end-target 1ms step-end,
169
+ --rio-split-button-menu-turn-target 1ms step-end,
170
+ --rio-split-button-menu-shift-target 1ms step-end;
171
+ }
172
+
173
+ .rio-split-button__menu-icon {
174
+ display: inline-flex;
175
+ flex: none;
176
+ inline-size: var(--_menu-size);
177
+ block-size: var(--_menu-size);
178
+ rotate: var(--_menu-turn, var(--_menu-turn-rest));
179
+ translate: calc(var(--_menu-shift, var(--_menu-shift-rest)) * var(--_start-sign)) 0;
180
+ }
181
+
182
+ .rio-split-button__menu-icon > :is(svg, img) {
183
+ inline-size: 100%;
184
+ block-size: 100%;
185
+ }
package/src/switch.css ADDED
@@ -0,0 +1,218 @@
1
+ /*
2
+ * M3 switch.
3
+ *
4
+ * Values come from Material Web's component tokens (`_md-comp-switch.scss`, Material 3 v34.0.21),
5
+ * which match the spec's measurements table. The handle's center and size are declared as targets
6
+ * for each state; `attachSwitchHandle` from `@rio-m3e/core` springs `--_handle-x` and
7
+ * `--_handle-size` toward them, which show the targets at rest. The targets get an instant
8
+ * transition so the springs see them change. Without JavaScript the handle simply jumps.
9
+ *
10
+ * The root carries `data-selected`, plus `data-pressed` (from the ripple), `data-dragging` (from
11
+ * the drag), and `data-icon` when the handle shows an icon. State rules sit inside `:where()` so
12
+ * the disabled rules always win.
13
+ */
14
+
15
+ @property --rio-switch-handle-x-target {
16
+ syntax: '<length>';
17
+ inherits: false;
18
+ initial-value: 0px;
19
+ }
20
+
21
+ @property --rio-switch-handle-size-target {
22
+ syntax: '<length>';
23
+ inherits: false;
24
+ initial-value: 0px;
25
+ }
26
+
27
+ @property --rio-switch-handle-x-off {
28
+ syntax: '<length>';
29
+ inherits: false;
30
+ initial-value: 0px;
31
+ }
32
+
33
+ @property --rio-switch-handle-x-on {
34
+ syntax: '<length>';
35
+ inherits: false;
36
+ initial-value: 0px;
37
+ }
38
+
39
+ .rio-switch {
40
+ --_track-width: 52px;
41
+ --_track-height: 32px;
42
+ --_outline-width: 2px;
43
+
44
+ /* The handle's center, measured from the track's starting edge */
45
+ --rio-switch-handle-x-off: calc(var(--_track-height) / 2);
46
+ --rio-switch-handle-x-on: calc(var(--_track-width) - var(--_track-height) / 2);
47
+ --rio-switch-handle-x-target: var(--rio-switch-handle-x-off);
48
+ --rio-switch-handle-size-target: 16px;
49
+ --_handle-x: var(--rio-switch-handle-x-target);
50
+ --_handle-size: var(--rio-switch-handle-size-target);
51
+
52
+ /* Colors: unselected */
53
+ --_track: var(--rio-color-surface-container-highest);
54
+ --_outline: var(--rio-color-outline);
55
+ --_handle: var(--rio-color-outline);
56
+ --_handle-active: var(--rio-color-on-surface-variant);
57
+ --_icon: var(--rio-color-surface-container-highest);
58
+ --_state-layer: var(--rio-color-on-surface);
59
+
60
+ position: relative;
61
+ display: inline-flex;
62
+ flex: none;
63
+ box-sizing: border-box;
64
+ inline-size: var(--_track-width);
65
+ block-size: var(--_track-height);
66
+ margin: 0;
67
+ padding: 0;
68
+ border: var(--_outline-width) solid var(--_outline);
69
+ border-radius: var(--rio-shape-corner-full);
70
+ background-color: var(--_track);
71
+ vertical-align: middle;
72
+ cursor: pointer;
73
+ /* Horizontal drags belong to the handle; vertical ones still scroll the page. */
74
+ touch-action: pan-y;
75
+ -webkit-tap-highlight-color: transparent;
76
+ /* The handle's spring targets get an instant transition, which is how the springs see them
77
+ change (core's spring-property). Public, as on the button (button.css). */
78
+ --rio-spring-targets:
79
+ --rio-switch-handle-x-target 1ms step-end, --rio-switch-handle-size-target 1ms step-end;
80
+ transition:
81
+ background-color var(--rio-motion-fast-effects),
82
+ border-color var(--rio-motion-fast-effects),
83
+ var(--rio-spring-targets);
84
+ }
85
+
86
+ /* States */
87
+
88
+ .rio-switch:where([data-selected='true']) {
89
+ --rio-switch-handle-x-target: var(--rio-switch-handle-x-on);
90
+ --rio-switch-handle-size-target: 24px;
91
+ --_track: var(--rio-color-primary);
92
+ --_outline: var(--rio-color-primary);
93
+ --_handle: var(--rio-color-on-primary);
94
+ --_handle-active: var(--rio-color-primary-container);
95
+ --_icon: var(--rio-color-primary);
96
+ --_state-layer: var(--rio-color-primary);
97
+ }
98
+
99
+ .rio-switch:where([data-icon]) {
100
+ --rio-switch-handle-size-target: 24px;
101
+ }
102
+
103
+ /* Pressing or dragging grows the handle */
104
+ .rio-switch:is([data-pressed], [data-dragging]) {
105
+ --rio-switch-handle-size-target: 28px;
106
+ }
107
+
108
+ /* Hovering, focusing, or pressing changes the handle's color */
109
+
110
+ @media (hover: hover) {
111
+ .rio-switch:hover .rio-switch__handle {
112
+ background-color: var(--_handle-active);
113
+ }
114
+
115
+ .rio-switch:hover .rio-switch__state::before {
116
+ opacity: var(--rio-state-hover-state-layer-opacity);
117
+ }
118
+ }
119
+
120
+ .rio-switch:is(:focus-visible, [data-pressed], [data-dragging]) .rio-switch__handle {
121
+ background-color: var(--_handle-active);
122
+ }
123
+
124
+ .rio-switch:focus-visible .rio-switch__state::before {
125
+ opacity: var(--rio-state-focus-state-layer-opacity);
126
+ }
127
+
128
+ /* Disabled, native or soft: the track at 12%, the unselected handle and the icons at 38% */
129
+
130
+ .rio-switch:is(:disabled, [aria-disabled='true']) {
131
+ --_track: color-mix(in srgb, var(--rio-color-surface-container-highest) 12%, transparent);
132
+ --_outline: color-mix(in srgb, var(--rio-color-on-surface) 12%, transparent);
133
+ --_handle: color-mix(in srgb, var(--rio-color-on-surface) 38%, transparent);
134
+ --_handle-active: var(--_handle);
135
+ --_icon: color-mix(in srgb, var(--rio-color-surface-container-highest) 38%, transparent);
136
+ cursor: default;
137
+ }
138
+
139
+ .rio-switch:is(:disabled, [aria-disabled='true']):where([data-selected='true']) {
140
+ --_track: color-mix(in srgb, var(--rio-color-on-surface) 12%, transparent);
141
+ --_outline: transparent;
142
+ --_handle: var(--rio-color-surface);
143
+ --_handle-active: var(--rio-color-surface);
144
+ --_icon: color-mix(in srgb, var(--rio-color-on-surface) 38%, transparent);
145
+ }
146
+
147
+ .rio-switch:is(:disabled, [aria-disabled='true']) .rio-switch__state::before {
148
+ opacity: 0;
149
+ }
150
+
151
+ /* Parts */
152
+
153
+ /* The 40px circle around the handle: the state layer on ::before, the ripple on ::after */
154
+ .rio-switch .rio-switch__state {
155
+ position: absolute;
156
+ inset-inline-start: calc(var(--_handle-x) - 20px - var(--_outline-width));
157
+ inset-block-start: calc(50% - 20px);
158
+ inline-size: 40px;
159
+ block-size: 40px;
160
+ border-radius: var(--rio-shape-corner-full);
161
+ color: var(--_state-layer);
162
+ pointer-events: none;
163
+ }
164
+
165
+ .rio-switch__state::before {
166
+ content: '';
167
+ position: absolute;
168
+ inset: 0;
169
+ border-radius: inherit;
170
+ background-color: currentColor;
171
+ opacity: 0;
172
+ pointer-events: none;
173
+ transition: opacity var(--rio-motion-fast-effects);
174
+ }
175
+
176
+ .rio-switch__handle {
177
+ position: absolute;
178
+ display: grid;
179
+ place-items: center;
180
+ inset-inline-start: calc(var(--_handle-x) - var(--_handle-size) / 2 - var(--_outline-width));
181
+ inset-block-start: calc(50% - var(--_handle-size) / 2);
182
+ inline-size: var(--_handle-size);
183
+ block-size: var(--_handle-size);
184
+ border-radius: var(--rio-shape-corner-full);
185
+ background-color: var(--_handle);
186
+ color: var(--_icon);
187
+ pointer-events: none;
188
+ transition: background-color var(--rio-motion-fast-effects);
189
+ }
190
+
191
+ .rio-switch__icon {
192
+ display: inline-flex;
193
+ inline-size: 16px;
194
+ block-size: 16px;
195
+ }
196
+
197
+ .rio-switch__icon > :is(svg, img) {
198
+ inline-size: 100%;
199
+ block-size: 100%;
200
+ }
201
+
202
+ /* The track is 32px tall, below the spec's 48px minimum target. */
203
+ .rio-switch__touch {
204
+ position: absolute;
205
+ /* Physical, like `translate`: a logical start would flip in right-to-left layouts and push the
206
+ target off the switch. */
207
+ top: 50%;
208
+ left: 50%;
209
+ inline-size: max(100%, 48px);
210
+ block-size: max(100%, 48px);
211
+ translate: -50% -50%;
212
+ }
213
+
214
+ @media (forced-colors: active) {
215
+ .rio-switch__state::before {
216
+ display: none;
217
+ }
218
+ }