@m3e/switch 1.0.0-rc.1
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 +22 -0
- package/README.md +174 -0
- package/cem.config.mjs +16 -0
- package/demo/index.html +65 -0
- package/dist/css-custom-data.json +352 -0
- package/dist/custom-elements.json +633 -0
- package/dist/html-custom-data.json +38 -0
- package/dist/index.js +774 -0
- package/dist/index.js.map +1 -0
- package/dist/index.min.js +399 -0
- package/dist/index.min.js.map +1 -0
- package/dist/src/SwitchElement.d.ts +147 -0
- package/dist/src/SwitchElement.d.ts.map +1 -0
- package/dist/src/SwitchIcons.d.ts +3 -0
- package/dist/src/SwitchIcons.d.ts.map +1 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/styles/SwitchHandleStyle.d.ts +6 -0
- package/dist/src/styles/SwitchHandleStyle.d.ts.map +1 -0
- package/dist/src/styles/SwitchIconStyle.d.ts +6 -0
- package/dist/src/styles/SwitchIconStyle.d.ts.map +1 -0
- package/dist/src/styles/SwitchStateLayerStyle.d.ts +6 -0
- package/dist/src/styles/SwitchStateLayerStyle.d.ts.map +1 -0
- package/dist/src/styles/SwitchStyle.d.ts +6 -0
- package/dist/src/styles/SwitchStyle.d.ts.map +1 -0
- package/dist/src/styles/SwitchToken.d.ts +76 -0
- package/dist/src/styles/SwitchToken.d.ts.map +1 -0
- package/dist/src/styles/SwitchTrackStyle.d.ts +6 -0
- package/dist/src/styles/SwitchTrackStyle.d.ts.map +1 -0
- package/dist/src/styles/index.d.ts +6 -0
- package/dist/src/styles/index.d.ts.map +1 -0
- package/eslint.config.mjs +13 -0
- package/package.json +48 -0
- package/rollup.config.js +32 -0
- package/src/SwitchElement.ts +268 -0
- package/src/SwitchIcons.ts +2 -0
- package/src/index.ts +2 -0
- package/src/styles/SwitchHandleStyle.ts +140 -0
- package/src/styles/SwitchIconStyle.ts +89 -0
- package/src/styles/SwitchStateLayerStyle.ts +43 -0
- package/src/styles/SwitchStyle.ts +30 -0
- package/src/styles/SwitchToken.ts +145 -0
- package/src/styles/SwitchTrackStyle.ts +104 -0
- package/src/styles/index.ts +5 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { unsafeCSS } from "lit";
|
|
2
|
+
|
|
3
|
+
import { DesignToken } from "@m3e/core";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Component design tokens that control `M3eSwitchElement`.
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export const SwitchToken = {
|
|
10
|
+
selectedIconColor: unsafeCSS(`var(--m3e-switch-selected-icon-color, ${DesignToken.color.onPrimaryContainer})`),
|
|
11
|
+
selectedIconSize: unsafeCSS("var(--m3e-switch-selected-icon-size, 1rem)"),
|
|
12
|
+
unselectedIconColor: unsafeCSS(
|
|
13
|
+
`var(--m3e-switch-unselected-icon-color, ${DesignToken.color.surfaceContainerHighest})`
|
|
14
|
+
),
|
|
15
|
+
unselectedIconSize: unsafeCSS("var(--m3e-switch-unselected-icon-size, 1rem)"),
|
|
16
|
+
trackHeight: unsafeCSS("var(--m3e-switch-track-height, 2rem)"),
|
|
17
|
+
trackWidth: unsafeCSS("var(--m3e-switch-track-width, 3.25rem)"),
|
|
18
|
+
trackOutlineColor: unsafeCSS(`var(--m3e-switch-track-outline-color, ${DesignToken.color.outline})`),
|
|
19
|
+
trackOutlineWidth: unsafeCSS("var(--m3e-switch-track-outline-width, 0.125rem)"),
|
|
20
|
+
trackShape: unsafeCSS(`var(--m3e-switch-track-shape, ${DesignToken.shape.corner.full})`),
|
|
21
|
+
selectedTrackColor: unsafeCSS(`var(--m3e-switch-selected-track-color, ${DesignToken.color.primary})`),
|
|
22
|
+
unselectedTrackColor: unsafeCSS(
|
|
23
|
+
`var(--m3e-switch-unselected-track-color, ${DesignToken.color.surfaceContainerHighest})`
|
|
24
|
+
),
|
|
25
|
+
unselectedHandleHeight: unsafeCSS("var(--m3e-switch-unselected-handle-height, 1rem)"),
|
|
26
|
+
unselectedHandleWidth: unsafeCSS("var(--m3e-switch-unselected-handle-width, 1rem)"),
|
|
27
|
+
withIconHandleHeight: unsafeCSS("var(--m3e-switch-with-icon-handle-height, 1.5rem)"),
|
|
28
|
+
withIconHandleWidth: unsafeCSS("var(--m3e-switch-with-icon-handle-width, 1.5rem)"),
|
|
29
|
+
selectedHandleHeight: unsafeCSS("var(--m3e-switch-selected-handle-height, 1.5rem)"),
|
|
30
|
+
selectedHandleWidth: unsafeCSS("var(--m3e-switch-selected-handle-width, 1.5rem)"),
|
|
31
|
+
pressedHandleHeight: unsafeCSS("var(--m3e-switch-pressed-handle-height, 1.75rem)"),
|
|
32
|
+
pressedHandleWidth: unsafeCSS("var(--m3e-switch-pressed-handle-width, 1.75rem)"),
|
|
33
|
+
handleShape: unsafeCSS(`var(--m3e-switch-handle-shape, ${DesignToken.shape.corner.full})`),
|
|
34
|
+
selectedHandleColor: unsafeCSS(`var(--m3e-switch-selected-handle-color, ${DesignToken.color.onPrimary})`),
|
|
35
|
+
unselectedHandleColor: unsafeCSS(`var(--m3e-switch-unselected-handle-color, ${DesignToken.color.outline})`),
|
|
36
|
+
stateLayerSize: unsafeCSS("var(--m3e-switch-state-layer-size, 2.5rem)"),
|
|
37
|
+
stateLayerShape: unsafeCSS(`var(--m3e-switch-state-layer-shape, ${DesignToken.shape.corner.full})`),
|
|
38
|
+
disabledSelectedIconColor: unsafeCSS(
|
|
39
|
+
`var(--m3e-switch-disabled-selected-icon-color, ${DesignToken.color.onSurface})`
|
|
40
|
+
),
|
|
41
|
+
disabledSelectedIconOpacity: unsafeCSS("var(--m3e-switch-disabled-selected-icon-opacity, 38%)"),
|
|
42
|
+
disabledUnselectedIconColor: unsafeCSS(
|
|
43
|
+
`var(--m3e-switch-disabled-unselected-icon-color, ${DesignToken.color.surfaceContainerHighest})`
|
|
44
|
+
),
|
|
45
|
+
disabledUnselectedIconOpacity: unsafeCSS("var(--m3e-switch-disabled-unselected-icon-opacity, 38%)"),
|
|
46
|
+
disabledTrackOpacity: unsafeCSS("var(--m3e-switch-disabled-track-opacity, 12%)"),
|
|
47
|
+
disabledSelectedTrackColor: unsafeCSS(
|
|
48
|
+
`var(--m3e-switch-disabled-selected-track-color, ${DesignToken.color.onSurface})`
|
|
49
|
+
),
|
|
50
|
+
disabledUnselectedTrackColor: unsafeCSS(
|
|
51
|
+
`var(--m3e-switch-disabled-unselected-track-color, ${DesignToken.color.surfaceContainerHighest})`
|
|
52
|
+
),
|
|
53
|
+
disabledUnselectedTrackOutlineColor: unsafeCSS(
|
|
54
|
+
`var(--m3e-switch-disabled-unselected-track-outline-color, ${DesignToken.color.onSurface})`
|
|
55
|
+
),
|
|
56
|
+
disabledUnselectedHandleOpacity: unsafeCSS("var(--m3e-switch-disabled-unselected-handle-opacity, 38%)"),
|
|
57
|
+
disabledSelectedHandleOpacity: unsafeCSS("var(--m3e-switch-disabled-selected-handle-opacity, 100%)"),
|
|
58
|
+
disabledSelectedHandleColor: unsafeCSS(
|
|
59
|
+
`var(--m3e-switch-disabled-selected-handle-color, ${DesignToken.color.surface})`
|
|
60
|
+
),
|
|
61
|
+
disabledUnselectedHandleColor: unsafeCSS(
|
|
62
|
+
`var(--m3e-switch-disabled-unselected-handle-color, ${DesignToken.color.onSurface})`
|
|
63
|
+
),
|
|
64
|
+
selectedHoverIconColor: unsafeCSS(
|
|
65
|
+
`var(--m3e-switch-selected-hover-icon-color, ${DesignToken.color.onPrimaryContainer})`
|
|
66
|
+
),
|
|
67
|
+
unselectedHoverIconColor: unsafeCSS(
|
|
68
|
+
`var(--m3e-switch-unselected-hover-icon-color, ${DesignToken.color.surfaceContainerHighest})`
|
|
69
|
+
),
|
|
70
|
+
selectedHoverTrackColor: unsafeCSS(`var(--m3e-switch-selected-hover-track-color, ${DesignToken.color.primary})`),
|
|
71
|
+
selectedHoverStateLayerColor: unsafeCSS(
|
|
72
|
+
`var(--m3e-switch-selected-hover-state-layer-color, ${DesignToken.color.primary})`
|
|
73
|
+
),
|
|
74
|
+
selectedHoverStateLayerOpacity: unsafeCSS("var(--m3e-switch-selected-hover-state-layer-opacity, 8%)"),
|
|
75
|
+
unselectedHoverTrackColor: unsafeCSS(
|
|
76
|
+
`var(--m3e-switch-unselected-hover-track-color, ${DesignToken.color.surfaceContainerHighest})`
|
|
77
|
+
),
|
|
78
|
+
unselectedHoverTrackOutlineColor: unsafeCSS(
|
|
79
|
+
`var(--m3e-switch-unselected-hover-track-outline-color, ${DesignToken.color.outline})`
|
|
80
|
+
),
|
|
81
|
+
unselectedHoverStateLayerColor: unsafeCSS(
|
|
82
|
+
`var(--m3e-switch-unselected-hover-state-layer-color, ${DesignToken.color.onSurface})`
|
|
83
|
+
),
|
|
84
|
+
unselectedHoverStateLayerOpacity: unsafeCSS("var(--m3e-switch-unselected-hover-state-layer-opacity, 8%)"),
|
|
85
|
+
selectedHoverHandleColor: unsafeCSS(
|
|
86
|
+
`var(--m3e-switch-selected-hover-handle-color, ${DesignToken.color.surfaceContainerHighest})`
|
|
87
|
+
),
|
|
88
|
+
unselectedHoverHandleColor: unsafeCSS(
|
|
89
|
+
`var(--m3e-switch-unselected-hover-handle-color, ${DesignToken.color.onSurfaceVariant})`
|
|
90
|
+
),
|
|
91
|
+
selectedFocusIconColor: unsafeCSS(
|
|
92
|
+
`var(--m3e-switch-selected-focus-icon-color, ${DesignToken.color.onPrimaryContainer})`
|
|
93
|
+
),
|
|
94
|
+
unselectedFocusIconColor: unsafeCSS(
|
|
95
|
+
`var(--m3e-switch-unselected-focus-icon-color, ${DesignToken.color.surfaceContainerHighest})`
|
|
96
|
+
),
|
|
97
|
+
selectedFocusTrackColor: unsafeCSS(`var(--m3e-switch-selected-focus-track-color, ${DesignToken.color.primary})`),
|
|
98
|
+
selectedFocusStateLayerColor: unsafeCSS(
|
|
99
|
+
`var(--m3e-switch-selected-focus-state-layer-color, ${DesignToken.color.primary})`
|
|
100
|
+
),
|
|
101
|
+
selectedFocusStateLayerOpacity: unsafeCSS("var(--m3e-switch-selected-focus-state-layer-opacity, 10%)"),
|
|
102
|
+
unselectedFocusTrackColor: unsafeCSS(
|
|
103
|
+
`var(--m3e-switch-unselected-focus-track-color, ${DesignToken.color.surfaceContainerHighest})`
|
|
104
|
+
),
|
|
105
|
+
unselectedFocusTrackOutlineColor: unsafeCSS(
|
|
106
|
+
`var(--m3e-switch-unselected-focus-track-outline-color, ${DesignToken.color.outline})`
|
|
107
|
+
),
|
|
108
|
+
unselectedFocusStateLayerColor: unsafeCSS(
|
|
109
|
+
`var(--m3e-switch-unselected-focus-state-layer-color, ${DesignToken.color.onSurface})`
|
|
110
|
+
),
|
|
111
|
+
unselectedFocusStateLayerOpacity: unsafeCSS("var(--m3e-switch-unselected-focus-state-layer-opacity, 10%)"),
|
|
112
|
+
selectedFocusHandleColor: unsafeCSS(
|
|
113
|
+
`var(--m3e-switch-selected-focus-handle-color, ${DesignToken.color.primaryContainer})`
|
|
114
|
+
),
|
|
115
|
+
unselectedFocusHandleColor: unsafeCSS(
|
|
116
|
+
`var(--m3e-switch-unselected-focus-handle-color, ${DesignToken.color.onSurfaceVariant})`
|
|
117
|
+
),
|
|
118
|
+
selectedPressedIconColor: unsafeCSS(
|
|
119
|
+
`var(--m3e-switch-selected-pressed-icon-color, ${DesignToken.color.onPrimaryContainer})`
|
|
120
|
+
),
|
|
121
|
+
unselectedPressedIconColor: unsafeCSS(
|
|
122
|
+
`var(--m3e-switch-unselected-pressed-icon-color, ${DesignToken.color.surfaceContainerHighest})`
|
|
123
|
+
),
|
|
124
|
+
selectedPressedTrackColor: unsafeCSS(`var(--m3e-switch-selected-pressed-track-color, ${DesignToken.color.primary})`),
|
|
125
|
+
selectedPressedStateLayerColor: unsafeCSS(
|
|
126
|
+
`var(--m3e-switch-selected-pressed-state-layer-color, ${DesignToken.color.primary})`
|
|
127
|
+
),
|
|
128
|
+
selectedPressedStateLayerOpacity: unsafeCSS("var(--m3e-switch-selected-pressed-state-layer-opacity, 10%)"),
|
|
129
|
+
unselectedPressedTrackColor: unsafeCSS(
|
|
130
|
+
`var(--m3e-switch-unselected-pressed-track-color, ${DesignToken.color.surfaceContainerHighest})`
|
|
131
|
+
),
|
|
132
|
+
unselectedPressedTrackOutlineColor: unsafeCSS(
|
|
133
|
+
`var(--m3e-switch-unselected-pressed-track-outline-color, ${DesignToken.color.outline})`
|
|
134
|
+
),
|
|
135
|
+
unselectedPressedStateLayerColor: unsafeCSS(
|
|
136
|
+
`var(--m3e-switch-unselected-pressed-state-layer-color, ${DesignToken.color.onSurface})`
|
|
137
|
+
),
|
|
138
|
+
unselectedPressedStateLayerOpacity: unsafeCSS("var(--m3e-switch-unselected-pressed-state-layer-opacity, 10%)"),
|
|
139
|
+
selectedPressedHandleColor: unsafeCSS(
|
|
140
|
+
`var(--m3e-switch-selected-pressed-handle-color, ${DesignToken.color.primaryContainer})`
|
|
141
|
+
),
|
|
142
|
+
unselectedPressedHandleColor: unsafeCSS(
|
|
143
|
+
`var(--m3e-switch-unselected-pressed-handle-color, ${DesignToken.color.onSurfaceVariant})`
|
|
144
|
+
),
|
|
145
|
+
} as const;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { css, unsafeCSS } from "lit";
|
|
2
|
+
import { DesignToken } from "@m3e/core";
|
|
3
|
+
|
|
4
|
+
import { SwitchToken } from "./SwitchToken";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Track styles for `M3eSwitchElement`.
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export const SwitchTrackStyle = css`
|
|
11
|
+
.track {
|
|
12
|
+
display: flex;
|
|
13
|
+
align-items: center;
|
|
14
|
+
position: relative;
|
|
15
|
+
box-sizing: border-box;
|
|
16
|
+
border-radius: ${SwitchToken.trackShape};
|
|
17
|
+
width: ${SwitchToken.trackWidth};
|
|
18
|
+
height: ${SwitchToken.trackHeight};
|
|
19
|
+
transition: ${unsafeCSS(
|
|
20
|
+
`background-color ${DesignToken.motion.duration.short4} ${DesignToken.motion.easing.standard}`
|
|
21
|
+
)};
|
|
22
|
+
}
|
|
23
|
+
:host(:not([checked])) .track {
|
|
24
|
+
border-width: ${SwitchToken.trackOutlineWidth};
|
|
25
|
+
border-style: solid;
|
|
26
|
+
}
|
|
27
|
+
:host(:not([aria-disabled="true"]):not([checked]):not(:focus):not(:hover)) .track:not(.pressed) {
|
|
28
|
+
border-color: ${SwitchToken.trackOutlineColor};
|
|
29
|
+
background-color: ${SwitchToken.unselectedTrackColor};
|
|
30
|
+
}
|
|
31
|
+
:host(:not([aria-disabled="true"]):not([checked]):not(:focus):hover) .track:not(.pressed) {
|
|
32
|
+
border-color: ${SwitchToken.unselectedHoverTrackOutlineColor};
|
|
33
|
+
background-color: ${SwitchToken.unselectedHoverTrackColor};
|
|
34
|
+
}
|
|
35
|
+
:host(:not([aria-disabled="true"]):not([checked]):focus) .track:not(.pressed) {
|
|
36
|
+
border-color: ${SwitchToken.unselectedFocusTrackOutlineColor};
|
|
37
|
+
background-color: ${SwitchToken.unselectedFocusTrackColor};
|
|
38
|
+
}
|
|
39
|
+
:host(:not([aria-disabled="true"]):not([checked])) .track.pressed {
|
|
40
|
+
border-color: ${SwitchToken.unselectedPressedTrackOutlineColor};
|
|
41
|
+
background-color: ${SwitchToken.unselectedPressedTrackColor};
|
|
42
|
+
}
|
|
43
|
+
:host([aria-disabled="true"]:not([checked])) .track {
|
|
44
|
+
border-color: color-mix(
|
|
45
|
+
in srgb,
|
|
46
|
+
${SwitchToken.disabledUnselectedTrackOutlineColor} ${SwitchToken.disabledTrackOpacity},
|
|
47
|
+
transparent
|
|
48
|
+
);
|
|
49
|
+
background-color: color-mix(
|
|
50
|
+
in srgb,
|
|
51
|
+
${SwitchToken.disabledUnselectedTrackColor} ${SwitchToken.disabledTrackOpacity},
|
|
52
|
+
transparent
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
:host(:not([aria-disabled="true"])[checked]:not(:focus):not(:hover)) .track:not(.pressed) {
|
|
56
|
+
background-color: ${SwitchToken.selectedTrackColor};
|
|
57
|
+
}
|
|
58
|
+
:host(:not([aria-disabled="true"])[checked]:not(:focus):hover) .track:not(.pressed) {
|
|
59
|
+
background-color: ${SwitchToken.selectedHoverTrackColor};
|
|
60
|
+
}
|
|
61
|
+
:host(:not([aria-disabled="true"])[checked]:focus) .track:not(.pressed) {
|
|
62
|
+
background-color: ${SwitchToken.selectedFocusTrackColor};
|
|
63
|
+
}
|
|
64
|
+
:host(:not([aria-disabled="true"])[checked]) .track.pressed {
|
|
65
|
+
background-color: ${SwitchToken.selectedPressedTrackColor};
|
|
66
|
+
}
|
|
67
|
+
:host([aria-disabled="true"][checked]) .track {
|
|
68
|
+
background-color: color-mix(
|
|
69
|
+
in srgb,
|
|
70
|
+
${SwitchToken.disabledSelectedTrackColor} ${SwitchToken.disabledTrackOpacity},
|
|
71
|
+
transparent
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
@media (forced-colors: active) {
|
|
75
|
+
.track {
|
|
76
|
+
transition: none;
|
|
77
|
+
}
|
|
78
|
+
:host(:not([aria-disabled="true"]):not([checked]):not(:focus):not(:hover)) .track:not(.pressed),
|
|
79
|
+
:host(:not([aria-disabled="true"]):not([checked]):not(:focus):hover) .track:not(.pressed),
|
|
80
|
+
:host(:not([aria-disabled="true"]):not([checked]):focus) .track:not(.pressed),
|
|
81
|
+
:host(:not([aria-disabled="true"]):not([checked])) .track.pressed {
|
|
82
|
+
border-color: ButtonText;
|
|
83
|
+
background-color: Canvas;
|
|
84
|
+
}
|
|
85
|
+
:host([aria-disabled="true"]:not([checked])) .track {
|
|
86
|
+
border-color: GrayText;
|
|
87
|
+
background-color: Canvas;
|
|
88
|
+
}
|
|
89
|
+
:host(:not([aria-disabled="true"])[checked]:not(:focus):not(:hover)) .track:not(.pressed),
|
|
90
|
+
:host(:not([aria-disabled="true"])[checked]:not(:focus):hover) .track:not(.pressed),
|
|
91
|
+
:host(:not([aria-disabled="true"])[checked]:focus) .track:not(.pressed),
|
|
92
|
+
:host(:not([aria-disabled="true"])[checked]) .track.pressed {
|
|
93
|
+
background-color: ButtonText;
|
|
94
|
+
}
|
|
95
|
+
:host([aria-disabled="true"][checked]) .track {
|
|
96
|
+
background-color: GrayText;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
@media (prefers-reduced-motion) {
|
|
100
|
+
.track {
|
|
101
|
+
transition: none;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
`;
|