@material/web 2.4.2-nightly.593705e.0 → 2.4.2-nightly.69624cd.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/button/internal/button.d.ts +0 -4
- package/button/internal/button.js.map +1 -1
- package/checkbox/internal/checkbox.d.ts +2 -2
- package/checkbox/internal/checkbox.js.map +1 -1
- package/chips/internal/chip.d.ts +2 -0
- package/icon/internal/icon.d.ts +1 -1
- package/icon/internal/icon.js +1 -1
- package/icon/internal/icon.js.map +1 -1
- package/iconbutton/internal/icon-button.d.ts +0 -4
- package/iconbutton/internal/icon-button.js.map +1 -1
- package/internal/aria/aria.d.ts +1 -1
- package/internal/events/dispatch-hooks.js +31 -35
- package/internal/events/dispatch-hooks.js.map +1 -1
- package/labs/behaviors/form-associated.d.ts +0 -22
- package/labs/behaviors/form-associated.js +0 -11
- package/labs/behaviors/form-associated.js.map +1 -1
- package/labs/gb/components/button/_button-tokens.scss +30 -30
- package/labs/gb/components/button/button.css +1 -1
- package/labs/gb/components/button/button.css.map +1 -1
- package/labs/gb/components/button/button.cssresult.js +1 -1
- package/labs/gb/components/button/button.cssresult.js.map +1 -1
- package/labs/gb/components/button/button.d.ts +1 -16
- package/labs/gb/components/button/button.js +10 -33
- package/labs/gb/components/button/button.js.map +1 -1
- package/labs/gb/components/button/button.scss +25 -25
- package/labs/gb/components/button/md-button.d.ts +1 -1
- package/labs/gb/components/button/md-button.js +9 -9
- package/labs/gb/components/button/md-button.js.map +1 -1
- package/labs/gb/components/card/card.d.ts +1 -11
- package/labs/gb/components/card/card.js +6 -13
- package/labs/gb/components/card/card.js.map +1 -1
- package/labs/gb/components/card/md-card.js +6 -6
- package/labs/gb/components/card/md-card.js.map +1 -1
- package/labs/gb/components/checkbox/checkbox.css +1 -1
- package/labs/gb/components/checkbox/checkbox.css.map +1 -1
- package/labs/gb/components/checkbox/checkbox.cssresult.js +1 -1
- package/labs/gb/components/checkbox/checkbox.cssresult.js.map +1 -1
- package/labs/gb/components/checkbox/checkbox.d.ts +1 -16
- package/labs/gb/components/checkbox/checkbox.js +8 -31
- package/labs/gb/components/checkbox/checkbox.js.map +1 -1
- package/labs/gb/components/checkbox/checkbox.scss +13 -13
- package/labs/gb/components/checkbox/md-checkbox.d.ts +4 -4
- package/labs/gb/components/checkbox/md-checkbox.js +10 -10
- package/labs/gb/components/checkbox/md-checkbox.js.map +1 -1
- package/labs/gb/components/divider/divider.d.ts +1 -11
- package/labs/gb/components/divider/divider.js +4 -11
- package/labs/gb/components/divider/divider.js.map +1 -1
- package/labs/gb/components/fab/fab.d.ts +1 -16
- package/labs/gb/components/fab/fab.js +8 -31
- package/labs/gb/components/fab/fab.js.map +1 -1
- package/labs/gb/components/fab/md-fab.js +4 -4
- package/labs/gb/components/fab/md-fab.js.map +1 -1
- package/labs/gb/components/focus/focus-ring.js +1 -1
- package/labs/gb/components/focus/focus-ring.js.map +1 -1
- package/labs/gb/components/iconbutton/_icon-button-tokens.scss +202 -0
- package/labs/gb/components/iconbutton/icon-button.css +4 -0
- package/labs/gb/components/iconbutton/icon-button.css.map +1 -0
- package/labs/gb/components/iconbutton/icon-button.cssresult.d.ts +3 -0
- package/labs/gb/components/iconbutton/icon-button.cssresult.js +14 -0
- package/labs/gb/components/iconbutton/icon-button.cssresult.js.map +1 -0
- package/labs/gb/components/iconbutton/icon-button.d.ts +97 -0
- package/labs/gb/components/iconbutton/icon-button.js +122 -0
- package/labs/gb/components/iconbutton/icon-button.js.map +1 -0
- package/labs/gb/components/iconbutton/icon-button.scss +153 -0
- package/labs/gb/components/iconbutton/md-icon-button.d.ts +73 -0
- package/labs/gb/components/iconbutton/md-icon-button.js +176 -0
- package/labs/gb/components/iconbutton/md-icon-button.js.map +1 -0
- package/labs/gb/components/list/_list-tokens.scss +102 -0
- package/labs/gb/components/list/list.css +4 -0
- package/labs/gb/components/list/list.css.map +1 -0
- package/labs/gb/components/list/list.cssresult.d.ts +3 -0
- package/labs/gb/components/list/list.cssresult.js +14 -0
- package/labs/gb/components/list/list.cssresult.js.map +1 -0
- package/labs/gb/components/list/list.d.ts +103 -0
- package/labs/gb/components/list/list.js +109 -0
- package/labs/gb/components/list/list.js.map +1 -0
- package/labs/gb/components/list/list.scss +212 -0
- package/labs/gb/components/list/md-list-item.d.ts +44 -0
- package/labs/gb/components/list/md-list-item.js +122 -0
- package/labs/gb/components/list/md-list-item.js.map +1 -0
- package/labs/gb/components/list/md-list.d.ts +26 -0
- package/labs/gb/components/list/md-list.js +51 -0
- package/labs/gb/components/list/md-list.js.map +1 -0
- package/labs/gb/components/menu/_menu-tokens.scss +128 -0
- package/labs/gb/components/menu/md-menu-group.d.ts +26 -0
- package/labs/gb/components/menu/md-menu-group.js +65 -0
- package/labs/gb/components/menu/md-menu-group.js.map +1 -0
- package/labs/gb/components/menu/md-menu-item.d.ts +30 -0
- package/labs/gb/components/menu/md-menu-item.js +165 -0
- package/labs/gb/components/menu/md-menu-item.js.map +1 -0
- package/labs/gb/components/menu/md-menu.d.ts +28 -0
- package/labs/gb/components/menu/md-menu.js +141 -0
- package/labs/gb/components/menu/md-menu.js.map +1 -0
- package/labs/gb/components/menu/menu.css +4 -0
- package/labs/gb/components/menu/menu.css.map +1 -0
- package/labs/gb/components/menu/menu.cssresult.d.ts +3 -0
- package/labs/gb/components/menu/menu.cssresult.js +14 -0
- package/labs/gb/components/menu/menu.cssresult.js.map +1 -0
- package/labs/gb/components/menu/menu.d.ts +117 -0
- package/labs/gb/components/menu/menu.js +107 -0
- package/labs/gb/components/menu/menu.js.map +1 -0
- package/labs/gb/components/menu/menu.scss +171 -0
- package/labs/gb/components/radio/md-radio.d.ts +4 -4
- package/labs/gb/components/radio/md-radio.js +11 -11
- package/labs/gb/components/radio/md-radio.js.map +1 -1
- package/labs/gb/components/radio/radio.css +1 -1
- package/labs/gb/components/radio/radio.css.map +1 -1
- package/labs/gb/components/radio/radio.cssresult.js +1 -1
- package/labs/gb/components/radio/radio.cssresult.js.map +1 -1
- package/labs/gb/components/radio/radio.d.ts +1 -14
- package/labs/gb/components/radio/radio.js +8 -23
- package/labs/gb/components/radio/radio.js.map +1 -1
- package/labs/gb/components/radio/radio.scss +4 -5
- package/labs/gb/components/ripple/ripple.d.ts +1 -10
- package/labs/gb/components/ripple/ripple.js +28 -32
- package/labs/gb/components/ripple/ripple.js.map +1 -1
- package/labs/gb/components/shared/directives.d.ts +93 -0
- package/labs/gb/components/shared/directives.js +111 -0
- package/labs/gb/components/shared/directives.js.map +1 -0
- package/labs/gb/components/shared/has-slotted.d.ts +10 -0
- package/labs/gb/components/shared/has-slotted.js +19 -0
- package/labs/gb/components/shared/has-slotted.js.map +1 -0
- package/labs/gb/components/shared/pseudo-classes.d.ts +7 -0
- package/labs/gb/components/shared/pseudo-classes.js +9 -0
- package/labs/gb/components/shared/pseudo-classes.js.map +1 -1
- package/labs/gb/components/switch/_switch-tokens.scss +56 -0
- package/labs/gb/components/switch/md-switch.d.ts +66 -0
- package/labs/gb/components/switch/md-switch.js +162 -0
- package/labs/gb/components/switch/md-switch.js.map +1 -0
- package/labs/gb/components/switch/switch.css +4 -0
- package/labs/gb/components/switch/switch.css.map +1 -0
- package/labs/gb/components/switch/switch.cssresult.d.ts +3 -0
- package/labs/gb/components/switch/switch.cssresult.js +14 -0
- package/labs/gb/components/switch/switch.cssresult.js.map +1 -0
- package/labs/gb/components/switch/switch.d.ts +54 -0
- package/labs/gb/components/switch/switch.js +85 -0
- package/labs/gb/components/switch/switch.js.map +1 -0
- package/labs/gb/components/switch/switch.scss +109 -0
- package/labs/gb/styles/icon/md-icon.css +1 -1
- package/labs/gb/styles/icon/md-icon.css.map +1 -1
- package/labs/gb/styles/icon/md-icon.cssresult.js +1 -1
- package/labs/gb/styles/icon/md-icon.cssresult.js.map +1 -1
- package/labs/gb/styles/icon/md-icon.d.ts +20 -0
- package/labs/gb/styles/icon/md-icon.js +24 -0
- package/labs/gb/styles/icon/md-icon.js.map +1 -0
- package/labs/gb/styles/icon/md-icon.scss +2 -1
- package/labs/gb/styles/m3.css +5 -2
- package/labs/gb/styles/m3.css.map +1 -1
- package/labs/gb/styles/m3.cssresult.js +5 -2
- package/labs/gb/styles/m3.cssresult.js.map +1 -1
- package/labs/gb/styles/m3.scss +1 -0
- package/labs/gb/styles/space/md-space-tokens.css +4 -0
- package/labs/gb/styles/space/md-space-tokens.css.map +1 -0
- package/labs/gb/styles/space/md-space-tokens.cssresult.d.ts +3 -0
- package/labs/gb/styles/space/md-space-tokens.cssresult.js +14 -0
- package/labs/gb/styles/space/md-space-tokens.cssresult.js.map +1 -0
- package/labs/gb/styles/space/md-space-tokens.scss +28 -0
- package/labs/gb/styles/tailwind.css +4 -0
- package/labs/gb/styles/tailwind.css.map +1 -0
- package/labs/gb/styles/tailwind.cssresult.d.ts +3 -0
- package/labs/gb/styles/tailwind.cssresult.js +14 -0
- package/labs/gb/styles/tailwind.cssresult.js.map +1 -0
- package/labs/gb/styles/tailwind.scss +244 -0
- package/labs/gb/styles/typography/internal/_typography-tokens.scss +85 -16
- package/labs/gb/styles/typography/md-typography-tokens.css +1 -1
- package/labs/gb/styles/typography/md-typography-tokens.css.map +1 -1
- package/labs/gb/styles/typography/md-typography-tokens.cssresult.js +1 -1
- package/labs/gb/styles/typography/md-typography-tokens.cssresult.js.map +1 -1
- package/list/internal/listitem/list-item.d.ts +2 -0
- package/menu/internal/menuitem/menu-item.d.ts +2 -0
- package/package.json +7 -3
- package/radio/internal/radio.d.ts +0 -2
- package/radio/internal/radio.js.map +1 -1
- package/select/internal/select.d.ts +2 -2
- package/select/internal/select.js.map +1 -1
- package/select/internal/selectoption/select-option.d.ts +2 -0
- package/slider/internal/slider.d.ts +0 -2
- package/slider/internal/slider.js.map +1 -1
- package/switch/internal/_switch.scss +1 -0
- package/switch/internal/switch-styles.css +1 -1
- package/switch/internal/switch-styles.css.map +1 -1
- package/switch/internal/switch-styles.cssresult.js +1 -1
- package/switch/internal/switch-styles.cssresult.js.map +1 -1
- package/switch/internal/switch.d.ts +0 -2
- package/switch/internal/switch.js.map +1 -1
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { noChange } from 'lit';
|
|
7
|
+
import { AsyncDirective, directive, } from 'lit/async-directive.js';
|
|
8
|
+
import { classMap } from 'lit/directives/class-map.js';
|
|
9
|
+
/**
|
|
10
|
+
* Creates a Lit directive that behaves like `classMap()`, but also provides
|
|
11
|
+
* element setup and cleanup logic.
|
|
12
|
+
*
|
|
13
|
+
* These directives bind to `class="${componentDirectiveName()}"`.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const toggleButton = createClassMapDirective({
|
|
18
|
+
* getClasses: (state: ToggleButtonState) => ({
|
|
19
|
+
* 'toggle-button': true,
|
|
20
|
+
* 'toggle-button-selected': state.selected,
|
|
21
|
+
* }),
|
|
22
|
+
* setupElement: (element, opts) => {
|
|
23
|
+
* element.addEventListener('click', () => {
|
|
24
|
+
* state.selected = !state.selected;
|
|
25
|
+
* }, opts);
|
|
26
|
+
* },
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* html`
|
|
30
|
+
* <button class="${toggleButton()}">Unselected</button>
|
|
31
|
+
* <button class="${toggleButton({selected: true})}">Selected</button>
|
|
32
|
+
* <button class="${toggleButton({classes: {'visible': isVisible}})}">
|
|
33
|
+
* With additional classes
|
|
34
|
+
* </button>
|
|
35
|
+
* `;
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @param options Options for creating the class map directive.
|
|
39
|
+
* @return A Lit `directive()` that binds to the class attribute.
|
|
40
|
+
*/
|
|
41
|
+
export function createClassMapDirective(options) {
|
|
42
|
+
return directive(class ComponentClassMapDirective extends SetupElementDirective {
|
|
43
|
+
constructor() {
|
|
44
|
+
super(...arguments);
|
|
45
|
+
this.setupElement = options.setupElement;
|
|
46
|
+
}
|
|
47
|
+
render(params) {
|
|
48
|
+
return classMap({
|
|
49
|
+
...(params?.classes || {}),
|
|
50
|
+
...options.getClasses(params),
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Creates a Lit directive that can be used to add setup and cleanup logic to
|
|
57
|
+
* an element.
|
|
58
|
+
*
|
|
59
|
+
* These directives bind as element parts.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* const logClick = createElementDirective((element, opts) => {
|
|
64
|
+
* element.addEventListener('click', (event) => {
|
|
65
|
+
* console.log('click', event);
|
|
66
|
+
* }, opts);
|
|
67
|
+
* });
|
|
68
|
+
*
|
|
69
|
+
* html`<button ${logClick()}>Click me</button>`;
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* @param setupElement The function to set up logic for the directive's element.
|
|
73
|
+
* @return A Lit `directive()` that binds as an element part.
|
|
74
|
+
*/
|
|
75
|
+
export function createElementDirective(setupElement) {
|
|
76
|
+
return directive(class ElementDirective extends SetupElementDirective {
|
|
77
|
+
constructor() {
|
|
78
|
+
super(...arguments);
|
|
79
|
+
this.setupElement = setupElement;
|
|
80
|
+
}
|
|
81
|
+
render() {
|
|
82
|
+
return noChange;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* A base class for Lit element and attribute directives that provides a setup
|
|
88
|
+
* method for initializing logic when a directive's element is connected.
|
|
89
|
+
*/
|
|
90
|
+
class SetupElementDirective extends AsyncDirective {
|
|
91
|
+
update({ element }, params) {
|
|
92
|
+
if (element !== this.element) {
|
|
93
|
+
this.element = element;
|
|
94
|
+
this.disconnected();
|
|
95
|
+
if (this.isConnected) {
|
|
96
|
+
this.reconnected();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return this.render(...params);
|
|
100
|
+
}
|
|
101
|
+
disconnected() {
|
|
102
|
+
this.cleanup?.abort();
|
|
103
|
+
}
|
|
104
|
+
reconnected() {
|
|
105
|
+
if (this.element && this.setupElement) {
|
|
106
|
+
this.cleanup = new AbortController();
|
|
107
|
+
this.setupElement(this.element, { signal: this.cleanup.signal });
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=directives.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"directives.js","sourceRoot":"","sources":["directives.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAC,QAAQ,EAAC,MAAM,KAAK,CAAC;AAC7B,OAAO,EACL,cAAc,EAEd,SAAS,GAGV,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAC,QAAQ,EAAiB,MAAM,6BAA6B,CAAC;AAsCrE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,UAAU,uBAAuB,CACrC,OAAwC;IAExC,OAAO,SAAS,CACd,MAAM,0BAA2B,SAAQ,qBAAqB;QAA9D;;YAQqB,iBAAY,GAAG,OAAO,CAAC,YAAY,CAAC;QACzD,CAAC;QARC,MAAM,CAAC,MAAkC;YACvC,OAAO,QAAQ,CAAC;gBACd,GAAG,CAAC,MAAM,EAAE,OAAO,IAAI,EAAE,CAAC;gBAC1B,GAAG,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC;aAC9B,CAAC,CAAC;QACL,CAAC;KAGF,CACF,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,sBAAsB,CACpC,YAAkC;IAElC,OAAO,SAAS,CACd,MAAM,gBAAiB,SAAQ,qBAAqB;QAApD;;YAKqB,iBAAY,GAAG,YAAY,CAAC;QACjD,CAAC;QALC,MAAM;YACJ,OAAO,QAAQ,CAAC;QAClB,CAAC;KAGF,CACF,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAe,qBAAsB,SAAQ,cAAc;IAmBhD,MAAM,CAAC,EAAC,OAAO,EAA8B,EAAE,MAAiB;QACvE,IAAI,OAAO,KAAK,IAAI,CAAC,OAAO,EAAE,CAAC;YAC7B,IAAI,CAAC,OAAO,GAAG,OAAsB,CAAC;YACtC,IAAI,CAAC,YAAY,EAAE,CAAC;YACpB,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;gBACrB,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC;IAChC,CAAC;IAEkB,YAAY;QAC7B,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;IACxB,CAAC;IAEkB,WAAW;QAC5B,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACtC,IAAI,CAAC,OAAO,GAAG,IAAI,eAAe,EAAE,CAAC;YACrC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,EAAE,EAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,EAAC,CAAC,CAAC;QACjE,CAAC;IACH,CAAC;CACF","sourcesContent":["/**\n * @license\n * Copyright 2026 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {noChange} from 'lit';\nimport {\n AsyncDirective,\n AttributePart,\n directive,\n DirectiveResult,\n ElementPart,\n} from 'lit/async-directive.js';\nimport {classMap, type ClassInfo} from 'lit/directives/class-map.js';\n\n/**\n * A function that sets up logic for a directive's element.\n *\n * @param element The element attached to the directive.\n * @param opts Options for setting up the element, including an AbortSignal for\n * cleanup.\n */\nexport type SetupElementFunction = (\n element: HTMLElement,\n opts: {signal: AbortSignal},\n) => void;\n\n/**\n * All class map directives include AdditionalClasses to allow adding dynamic\n * classes to the element using `classMap()`.\n */\nexport interface AdditionalClasses {\n /**\n * Additional classes to apply to the element.\n */\n classes?: ClassInfo;\n}\n\n/**\n * Options for creating a class map directive.\n *\n * @param getClasses A function that returns the class names and truthy values\n * if they apply.\n * @param setupElement An optional function to set up logic for the directive's\n * element.\n */\nexport interface ClassMapDirectiveOptions<State> {\n getClasses: (state?: State) => ClassInfo;\n setupElement?: SetupElementFunction;\n}\n\n/**\n * Creates a Lit directive that behaves like `classMap()`, but also provides\n * element setup and cleanup logic.\n *\n * These directives bind to `class=\"${componentDirectiveName()}\"`.\n *\n * @example\n * ```ts\n * const toggleButton = createClassMapDirective({\n * getClasses: (state: ToggleButtonState) => ({\n * 'toggle-button': true,\n * 'toggle-button-selected': state.selected,\n * }),\n * setupElement: (element, opts) => {\n * element.addEventListener('click', () => {\n * state.selected = !state.selected;\n * }, opts);\n * },\n * });\n *\n * html`\n * <button class=\"${toggleButton()}\">Unselected</button>\n * <button class=\"${toggleButton({selected: true})}\">Selected</button>\n * <button class=\"${toggleButton({classes: {'visible': isVisible}})}\">\n * With additional classes\n * </button>\n * `;\n * ```\n *\n * @param options Options for creating the class map directive.\n * @return A Lit `directive()` that binds to the class attribute.\n */\nexport function createClassMapDirective<State = {}>(\n options: ClassMapDirectiveOptions<State>,\n): (state?: State & AdditionalClasses) => DirectiveResult {\n return directive(\n class ComponentClassMapDirective extends SetupElementDirective {\n render(params?: State & AdditionalClasses) {\n return classMap({\n ...(params?.classes || {}),\n ...options.getClasses(params),\n });\n }\n\n protected override setupElement = options.setupElement;\n },\n );\n}\n\n/**\n * Creates a Lit directive that can be used to add setup and cleanup logic to\n * an element.\n *\n * These directives bind as element parts.\n *\n * @example\n * ```ts\n * const logClick = createElementDirective((element, opts) => {\n * element.addEventListener('click', (event) => {\n * console.log('click', event);\n * }, opts);\n * });\n *\n * html`<button ${logClick()}>Click me</button>`;\n * ```\n *\n * @param setupElement The function to set up logic for the directive's element.\n * @return A Lit `directive()` that binds as an element part.\n */\nexport function createElementDirective(\n setupElement: SetupElementFunction,\n): () => DirectiveResult {\n return directive(\n class ElementDirective extends SetupElementDirective {\n render() {\n return noChange;\n }\n\n protected override setupElement = setupElement;\n },\n );\n}\n\n/**\n * A base class for Lit element and attribute directives that provides a setup\n * method for initializing logic when a directive's element is connected.\n */\nabstract class SetupElementDirective extends AsyncDirective {\n /**\n * Called when the directive's element changes. Use this method to add\n * event listeners or perform other setup logic.\n *\n * The `signal` option is used to clean up setup logic when the element is\n * disconnected.\n *\n * @param element The element attached to the directive.\n * @param signal An AbortSignal to clean up event listeners and other logic.\n */\n protected setupElement?: (\n element: HTMLElement,\n opts: {signal: AbortSignal},\n ) => void;\n\n private element?: HTMLElement;\n private cleanup?: AbortController;\n\n override update({element}: ElementPart | AttributePart, params: unknown[]) {\n if (element !== this.element) {\n this.element = element as HTMLElement;\n this.disconnected();\n if (this.isConnected) {\n this.reconnected();\n }\n }\n\n return this.render(...params);\n }\n\n protected override disconnected() {\n this.cleanup?.abort();\n }\n\n protected override reconnected() {\n if (this.element && this.setupElement) {\n this.cleanup = new AbortController();\n this.setupElement(this.element, {signal: this.cleanup.signal});\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Emulates the `:has-slotted` CSS pseudo class by adding a `.has-slotted` class
|
|
8
|
+
* to `<slot>` elements when they have assigned nodes.
|
|
9
|
+
*/
|
|
10
|
+
export declare const hasSlotted: () => import("lit-html/directive.js").DirectiveResult;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { createElementDirective } from './directives.js';
|
|
7
|
+
/**
|
|
8
|
+
* Emulates the `:has-slotted` CSS pseudo class by adding a `.has-slotted` class
|
|
9
|
+
* to `<slot>` elements when they have assigned nodes.
|
|
10
|
+
*/
|
|
11
|
+
export const hasSlotted = createElementDirective((element, opts) => {
|
|
12
|
+
if (!element.matches('slot')) {
|
|
13
|
+
throw new Error('hasSlotted() must be used on a <slot> element.');
|
|
14
|
+
}
|
|
15
|
+
element.addEventListener('slotchange', (event) => {
|
|
16
|
+
element.classList.toggle('has-slotted', element.assignedNodes().length > 0);
|
|
17
|
+
}, opts);
|
|
18
|
+
});
|
|
19
|
+
//# sourceMappingURL=has-slotted.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"has-slotted.js","sourceRoot":"","sources":["has-slotted.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAC,sBAAsB,EAAC,MAAM,iBAAiB,CAAC;AAEvD;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,sBAAsB,CAAC,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE;IACjE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACpE,CAAC;IAED,OAAO,CAAC,gBAAgB,CACtB,YAAY,EACZ,CAAC,KAAK,EAAE,EAAE;QACR,OAAO,CAAC,SAAS,CAAC,MAAM,CACtB,aAAa,EACZ,OAA2B,CAAC,aAAa,EAAE,CAAC,MAAM,GAAG,CAAC,CACxD,CAAC;IACJ,CAAC,EACD,IAAI,CACL,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["/**\n * @license\n * Copyright 2026 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {createElementDirective} from './directives.js';\n\n/**\n * Emulates the `:has-slotted` CSS pseudo class by adding a `.has-slotted` class\n * to `<slot>` elements when they have assigned nodes.\n */\nexport const hasSlotted = createElementDirective((element, opts) => {\n if (!element.matches('slot')) {\n throw new Error('hasSlotted() must be used on a <slot> element.');\n }\n\n element.addEventListener(\n 'slotchange',\n (event) => {\n element.classList.toggle(\n 'has-slotted',\n (element as HTMLSlotElement).assignedNodes().length > 0,\n );\n },\n opts,\n );\n});\n"]}
|
|
@@ -24,3 +24,10 @@ export declare const PSEUDO_CLASSES: {
|
|
|
24
24
|
indeterminate: string;
|
|
25
25
|
invalid: string;
|
|
26
26
|
};
|
|
27
|
+
/**
|
|
28
|
+
* Returns whether the element is disabled.
|
|
29
|
+
*
|
|
30
|
+
* @param element The element to check.
|
|
31
|
+
* @return true if the element is disabled.
|
|
32
|
+
*/
|
|
33
|
+
export declare function isDisabled(element: Element): boolean;
|
|
@@ -24,4 +24,13 @@ export const PSEUDO_CLASSES = {
|
|
|
24
24
|
indeterminate: 'indeterminate',
|
|
25
25
|
invalid: 'invalid',
|
|
26
26
|
};
|
|
27
|
+
/**
|
|
28
|
+
* Returns whether the element is disabled.
|
|
29
|
+
*
|
|
30
|
+
* @param element The element to check.
|
|
31
|
+
* @return true if the element is disabled.
|
|
32
|
+
*/
|
|
33
|
+
export function isDisabled(element) {
|
|
34
|
+
return element.matches('.disabled,:disabled,[disabled],[aria-disabled=true]');
|
|
35
|
+
}
|
|
27
36
|
//# sourceMappingURL=pseudo-classes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pseudo-classes.js","sourceRoot":"","sources":["pseudo-classes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;IAClB,QAAQ,EAAE,UAAU;IACpB,KAAK,EAAE,OAAO;IACd,YAAY,EAAE,eAAe;IAC7B,KAAK,EAAE,OAAO;IACd,aAAa,EAAE,eAAe;IAC9B,OAAO,EAAE,SAAS;CACnB,CAAC","sourcesContent":["/**\n * @license\n * Copyright 2026 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * Cross-component classes for emulating pseudo-classes.\n *\n * All components that style with psuedo-classes for their DOM structure also\n * support emulating these states.\n *\n * @example\n * ```html\n * <button class=\"ripple active\">Pressed ripple</button>\n * ```\n */\nexport const PSEUDO_CLASSES = {\n active: 'active',\n checked: 'checked',\n disabled: 'disabled',\n focus: 'focus',\n focusVisible: 'focus-visible',\n hover: 'hover',\n indeterminate: 'indeterminate',\n invalid: 'invalid',\n};\n"]}
|
|
1
|
+
{"version":3,"file":"pseudo-classes.js","sourceRoot":"","sources":["pseudo-classes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;IAClB,QAAQ,EAAE,UAAU;IACpB,KAAK,EAAE,OAAO;IACd,YAAY,EAAE,eAAe;IAC7B,KAAK,EAAE,OAAO;IACd,aAAa,EAAE,eAAe;IAC9B,OAAO,EAAE,SAAS;CACnB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,OAAgB;IACzC,OAAO,OAAO,CAAC,OAAO,CAAC,qDAAqD,CAAC,CAAC;AAChF,CAAC","sourcesContent":["/**\n * @license\n * Copyright 2026 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * Cross-component classes for emulating pseudo-classes.\n *\n * All components that style with psuedo-classes for their DOM structure also\n * support emulating these states.\n *\n * @example\n * ```html\n * <button class=\"ripple active\">Pressed ripple</button>\n * ```\n */\nexport const PSEUDO_CLASSES = {\n active: 'active',\n checked: 'checked',\n disabled: 'disabled',\n focus: 'focus',\n focusVisible: 'focus-visible',\n hover: 'hover',\n indeterminate: 'indeterminate',\n invalid: 'invalid',\n};\n\n/**\n * Returns whether the element is disabled.\n *\n * @param element The element to check.\n * @return true if the element is disabled.\n */\nexport function isDisabled(element: Element): boolean {\n return element.matches('.disabled,:disabled,[disabled],[aria-disabled=true]');\n}\n"]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 Google LLC
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
//
|
|
5
|
+
|
|
6
|
+
@mixin root {
|
|
7
|
+
--handle-color: var(--md-sys-color-outline);
|
|
8
|
+
--handle-size: 16px;
|
|
9
|
+
--with-icon-handle-size: 24px;
|
|
10
|
+
--icon-color: var(--md-sys-color-surface-container-highest);
|
|
11
|
+
--icon-size: 18px;
|
|
12
|
+
--state-layer-color: var(--md-sys-color-on-surface);
|
|
13
|
+
--state-layer-size: 40px;
|
|
14
|
+
--track-color: var(--md-sys-color-surface-container-highest);
|
|
15
|
+
--track-height: 32px;
|
|
16
|
+
--track-outline-color: var(--md-sys-color-outline);
|
|
17
|
+
--track-outline-width: 2px;
|
|
18
|
+
--track-width: 52px;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@mixin hovered {
|
|
22
|
+
--handle-color: var(--md-sys-color-on-surface-variant);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@mixin selected {
|
|
26
|
+
--track-color: var(--md-sys-color-primary);
|
|
27
|
+
--track-outline-color: transparent;
|
|
28
|
+
--handle-color: var(--md-sys-color-on-primary);
|
|
29
|
+
--handle-size: 24px;
|
|
30
|
+
--icon-color: var(--md-sys-color-on-primary-container);
|
|
31
|
+
--state-layer-color: var(--md-sys-color-primary);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@mixin selected-hovered {
|
|
35
|
+
--handle-color: var(--md-sys-color-primary-container);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@mixin pressed {
|
|
39
|
+
--handle-size: 28px;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@mixin disabled {
|
|
43
|
+
--handle-color: hsl(from var(--md-sys-color-on-surface) h s l / 38%);
|
|
44
|
+
--track-color: hsl(
|
|
45
|
+
from var(--md-sys-color-surface-container-highest) h s l / 12%
|
|
46
|
+
);
|
|
47
|
+
--track-outline-color: hsl(
|
|
48
|
+
from var(--md-sys-color-on-surface) h s l / 12%
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@mixin disabled-selected {
|
|
53
|
+
--handle-color: var(--md-sys-color-surface);
|
|
54
|
+
--icon-color: hsl(from var(--md-sys-color-on-surface) h s l / 38%);
|
|
55
|
+
--track-color: hsl(from var(--md-sys-color-on-surface) h s l / 12%);
|
|
56
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { CSSResultOrNative, LitElement } from 'lit';
|
|
7
|
+
import { createValidator, getValidityAnchor } from '../../../behaviors/constraint-validation.js';
|
|
8
|
+
import { getFormState, getFormValue } from '../../../behaviors/form-associated.js';
|
|
9
|
+
import { CheckboxValidator } from '../../../behaviors/validators/checkbox-validator.js';
|
|
10
|
+
declare global {
|
|
11
|
+
interface HTMLElementTagNameMap {
|
|
12
|
+
/** A Material Design switch component. */
|
|
13
|
+
'md-switch': Switch;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
declare const baseClass: import("@material/web/labs/behaviors/mixin.js").MixinReturn<import("@material/web/labs/behaviors/mixin.js").MixinReturn<import("@material/web/labs/behaviors/mixin.js").MixinReturn<(abstract new (...args: any[]) => import("../../../behaviors/custom-state-set.js").WithCustomStateSet) & (abstract new (...args: any[]) => import("../../../behaviors/element-internals.js").WithElementInternals) & typeof LitElement & import("../../../behaviors/form-associated.js").FormAssociatedConstructor, import("../../../behaviors/form-associated.js").FormAssociated>, import("../../../behaviors/constraint-validation.js").ConstraintValidation>>;
|
|
17
|
+
/**
|
|
18
|
+
* A Material Design switch component.
|
|
19
|
+
*/
|
|
20
|
+
export declare class Switch extends baseClass {
|
|
21
|
+
/** @nocollapse */
|
|
22
|
+
static shadowRootOptions: ShadowRootInit;
|
|
23
|
+
static styles: CSSResultOrNative[];
|
|
24
|
+
/**
|
|
25
|
+
* Puts the switch in the selected state and sets the form submission value to
|
|
26
|
+
* the `value` property.
|
|
27
|
+
*/
|
|
28
|
+
get selected(): boolean;
|
|
29
|
+
set selected(value: boolean);
|
|
30
|
+
/**
|
|
31
|
+
* The default selected state of the switch.
|
|
32
|
+
*/
|
|
33
|
+
get defaultSelected(): boolean;
|
|
34
|
+
set defaultSelected(value: boolean);
|
|
35
|
+
/**
|
|
36
|
+
* When true, require the switch to be selected when participating in
|
|
37
|
+
* form submission.
|
|
38
|
+
*
|
|
39
|
+
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#validation
|
|
40
|
+
*/
|
|
41
|
+
required: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* The value associated with this switch on form submission. `null` is
|
|
44
|
+
* submitted when `selected` is `false`.
|
|
45
|
+
*/
|
|
46
|
+
value: string;
|
|
47
|
+
private readonly button;
|
|
48
|
+
/**
|
|
49
|
+
* Mimics the behavior of <input> dirty checkedness, where the `checked`
|
|
50
|
+
* attribute only updates the checked state if the checkbox has not been
|
|
51
|
+
* interacted with.
|
|
52
|
+
*
|
|
53
|
+
* @see https://html.spec.whatwg.org/multipage/input.html#concept-input-checked-dirty-flag
|
|
54
|
+
*/
|
|
55
|
+
private dirtyCheckedness;
|
|
56
|
+
protected render(): import("lit-html").TemplateResult<1>;
|
|
57
|
+
private handleChange;
|
|
58
|
+
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
|
|
59
|
+
[getFormValue](): string;
|
|
60
|
+
[getFormState](): string;
|
|
61
|
+
formResetCallback(): void;
|
|
62
|
+
formStateRestoreCallback(state: string): void;
|
|
63
|
+
[createValidator](): CheckboxValidator;
|
|
64
|
+
[getValidityAnchor](): HTMLButtonElement;
|
|
65
|
+
}
|
|
66
|
+
export {};
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { __decorate } from "tslib";
|
|
7
|
+
import { css, html, LitElement, nothing } from 'lit';
|
|
8
|
+
import { customElement, property, query } from 'lit/decorators.js';
|
|
9
|
+
import { mixinDelegatesAria } from '../../../../internal/aria/delegate.js';
|
|
10
|
+
import { redispatchEvent } from '../../../../internal/events/redispatch-event.js';
|
|
11
|
+
import { createValidator, getValidityAnchor, mixinConstraintValidation, } from '../../../behaviors/constraint-validation.js';
|
|
12
|
+
import { hasState, mixinCustomStateSet, toggleState, } from '../../../behaviors/custom-state-set.js';
|
|
13
|
+
import { mixinElementInternals } from '../../../behaviors/element-internals.js';
|
|
14
|
+
import { getFormState, getFormValue, mixinFormAssociated, } from '../../../behaviors/form-associated.js';
|
|
15
|
+
import { CheckboxValidator } from '../../../behaviors/validators/checkbox-validator.js';
|
|
16
|
+
import { hasSlotted } from '../shared/has-slotted.js';
|
|
17
|
+
import focusRingStyles from '../focus/focus-ring.css' with { type: 'css' }; // github-only
|
|
18
|
+
// import focusRingStyles from '../focus/focus-ring.cssresult.js'; // google3-only
|
|
19
|
+
import rippleStyles from '../ripple/ripple.css' with { type: 'css' }; // github-only
|
|
20
|
+
// import rippleStyles from '../ripple/ripple.cssresult.js'; // google3-only
|
|
21
|
+
import switchStyles from './switch.css' with { type: 'css' }; // github-only
|
|
22
|
+
// import switchStyles from './switch.cssresult.js'; // google3-only
|
|
23
|
+
import { switchToggle } from './switch.js';
|
|
24
|
+
// Separate variable needed for closure.
|
|
25
|
+
const baseClass = mixinDelegatesAria(mixinConstraintValidation(mixinFormAssociated(mixinCustomStateSet(mixinElementInternals(LitElement)))));
|
|
26
|
+
/**
|
|
27
|
+
* A Material Design switch component.
|
|
28
|
+
*/
|
|
29
|
+
let Switch = class Switch extends baseClass {
|
|
30
|
+
constructor() {
|
|
31
|
+
super(...arguments);
|
|
32
|
+
/**
|
|
33
|
+
* When true, require the switch to be selected when participating in
|
|
34
|
+
* form submission.
|
|
35
|
+
*
|
|
36
|
+
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#validation
|
|
37
|
+
*/
|
|
38
|
+
this.required = false;
|
|
39
|
+
/**
|
|
40
|
+
* The value associated with this switch on form submission. `null` is
|
|
41
|
+
* submitted when `selected` is `false`.
|
|
42
|
+
*/
|
|
43
|
+
this.value = 'on';
|
|
44
|
+
/**
|
|
45
|
+
* Mimics the behavior of <input> dirty checkedness, where the `checked`
|
|
46
|
+
* attribute only updates the checked state if the checkbox has not been
|
|
47
|
+
* interacted with.
|
|
48
|
+
*
|
|
49
|
+
* @see https://html.spec.whatwg.org/multipage/input.html#concept-input-checked-dirty-flag
|
|
50
|
+
*/
|
|
51
|
+
this.dirtyCheckedness = false;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Puts the switch in the selected state and sets the form submission value to
|
|
55
|
+
* the `value` property.
|
|
56
|
+
*/
|
|
57
|
+
get selected() {
|
|
58
|
+
return this[hasState]('selected');
|
|
59
|
+
}
|
|
60
|
+
set selected(value) {
|
|
61
|
+
this[toggleState]('selected', value);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The default selected state of the switch.
|
|
65
|
+
*/
|
|
66
|
+
get defaultSelected() {
|
|
67
|
+
return this.hasAttribute('selected');
|
|
68
|
+
}
|
|
69
|
+
set defaultSelected(value) {
|
|
70
|
+
this.toggleAttribute('selected', value || false);
|
|
71
|
+
}
|
|
72
|
+
render() {
|
|
73
|
+
const { ariaLabel } = this;
|
|
74
|
+
return html `
|
|
75
|
+
<button
|
|
76
|
+
role="switch"
|
|
77
|
+
part="switch"
|
|
78
|
+
class="${switchToggle()}"
|
|
79
|
+
aria-checked="${this.selected ? 'true' : 'false'}"
|
|
80
|
+
aria-label=${ariaLabel || nothing}
|
|
81
|
+
?disabled=${this.disabled}
|
|
82
|
+
@change=${this.handleChange}>
|
|
83
|
+
<slot name="off-icon" class="switch-icon-off" ${hasSlotted()}></slot>
|
|
84
|
+
<slot name="on-icon" class="switch-icon-on"></slot>
|
|
85
|
+
</button>
|
|
86
|
+
`;
|
|
87
|
+
}
|
|
88
|
+
handleChange(event) {
|
|
89
|
+
this.dirtyCheckedness = true;
|
|
90
|
+
this.selected = this.button?.ariaChecked === 'true';
|
|
91
|
+
// Change event is not composed, re-dispatch it.
|
|
92
|
+
redispatchEvent(this, event);
|
|
93
|
+
}
|
|
94
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
95
|
+
if (name === 'selected' && this.dirtyCheckedness) {
|
|
96
|
+
// The 'selected' attribute does not update switches that have been
|
|
97
|
+
// interacted with.
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
super.attributeChangedCallback(name, oldValue, newValue);
|
|
101
|
+
}
|
|
102
|
+
[getFormValue]() {
|
|
103
|
+
return this.selected ? this.value : null;
|
|
104
|
+
}
|
|
105
|
+
[getFormState]() {
|
|
106
|
+
return String(this.selected);
|
|
107
|
+
}
|
|
108
|
+
formResetCallback() {
|
|
109
|
+
this.dirtyCheckedness = false;
|
|
110
|
+
this.selected = this.defaultSelected;
|
|
111
|
+
}
|
|
112
|
+
formStateRestoreCallback(state) {
|
|
113
|
+
this.selected = state === 'true';
|
|
114
|
+
}
|
|
115
|
+
[createValidator]() {
|
|
116
|
+
return new CheckboxValidator(() => ({
|
|
117
|
+
checked: this.selected,
|
|
118
|
+
required: this.required,
|
|
119
|
+
}));
|
|
120
|
+
}
|
|
121
|
+
[getValidityAnchor]() {
|
|
122
|
+
return this.button;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
/** @nocollapse */
|
|
126
|
+
Switch.shadowRootOptions = {
|
|
127
|
+
mode: 'open',
|
|
128
|
+
delegatesFocus: true,
|
|
129
|
+
};
|
|
130
|
+
Switch.styles = [
|
|
131
|
+
focusRingStyles,
|
|
132
|
+
rippleStyles,
|
|
133
|
+
switchStyles,
|
|
134
|
+
css `
|
|
135
|
+
:host {
|
|
136
|
+
display: inline-flex;
|
|
137
|
+
}
|
|
138
|
+
.switch {
|
|
139
|
+
flex: 1;
|
|
140
|
+
}
|
|
141
|
+
::slotted(*) {
|
|
142
|
+
grid-area: handle;
|
|
143
|
+
}
|
|
144
|
+
`,
|
|
145
|
+
];
|
|
146
|
+
__decorate([
|
|
147
|
+
property({ type: Boolean })
|
|
148
|
+
], Switch.prototype, "selected", null);
|
|
149
|
+
__decorate([
|
|
150
|
+
property({ type: Boolean })
|
|
151
|
+
], Switch.prototype, "required", void 0);
|
|
152
|
+
__decorate([
|
|
153
|
+
property()
|
|
154
|
+
], Switch.prototype, "value", void 0);
|
|
155
|
+
__decorate([
|
|
156
|
+
query('button', true)
|
|
157
|
+
], Switch.prototype, "button", void 0);
|
|
158
|
+
Switch = __decorate([
|
|
159
|
+
customElement('md-switch')
|
|
160
|
+
], Switch);
|
|
161
|
+
export { Switch };
|
|
162
|
+
//# sourceMappingURL=md-switch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"md-switch.js","sourceRoot":"","sources":["md-switch.ts"],"names":[],"mappings":"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","sourcesContent":["/**\n * @license\n * Copyright 2026 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {css, CSSResultOrNative, html, LitElement, nothing} from 'lit';\nimport {customElement, property, query} from 'lit/decorators.js';\nimport {ARIAMixinStrict} from '../../../../internal/aria/aria.js';\nimport {mixinDelegatesAria} from '../../../../internal/aria/delegate.js';\nimport {redispatchEvent} from '../../../../internal/events/redispatch-event.js';\nimport {\n createValidator,\n getValidityAnchor,\n mixinConstraintValidation,\n} from '../../../behaviors/constraint-validation.js';\nimport {\n hasState,\n mixinCustomStateSet,\n toggleState,\n} from '../../../behaviors/custom-state-set.js';\nimport {mixinElementInternals} from '../../../behaviors/element-internals.js';\nimport {\n getFormState,\n getFormValue,\n mixinFormAssociated,\n} from '../../../behaviors/form-associated.js';\nimport {CheckboxValidator} from '../../../behaviors/validators/checkbox-validator.js';\nimport {hasSlotted} from '../shared/has-slotted.js';\n\nimport focusRingStyles from '../focus/focus-ring.css' with {type: 'css'}; // github-only\n// import focusRingStyles from '../focus/focus-ring.cssresult.js'; // google3-only\nimport rippleStyles from '../ripple/ripple.css' with {type: 'css'}; // github-only\n// import rippleStyles from '../ripple/ripple.cssresult.js'; // google3-only\nimport switchStyles from './switch.css' with {type: 'css'}; // github-only\n// import switchStyles from './switch.cssresult.js'; // google3-only\n\nimport {switchToggle} from './switch.js';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n /** A Material Design switch component. */\n 'md-switch': Switch;\n }\n}\n\n// Separate variable needed for closure.\nconst baseClass = mixinDelegatesAria(\n mixinConstraintValidation(\n mixinFormAssociated(mixinCustomStateSet(mixinElementInternals(LitElement))),\n ),\n);\n\n/**\n * A Material Design switch component.\n */\n@customElement('md-switch')\nexport class Switch extends baseClass {\n /** @nocollapse */\n static override shadowRootOptions: ShadowRootInit = {\n mode: 'open',\n delegatesFocus: true,\n };\n\n static override styles: CSSResultOrNative[] = [\n focusRingStyles,\n rippleStyles,\n switchStyles,\n css`\n :host {\n display: inline-flex;\n }\n .switch {\n flex: 1;\n }\n ::slotted(*) {\n grid-area: handle;\n }\n `,\n ];\n\n /**\n * Puts the switch in the selected state and sets the form submission value to\n * the `value` property.\n */\n @property({type: Boolean})\n get selected() {\n return this[hasState]('selected');\n }\n set selected(value: boolean) {\n this[toggleState]('selected', value);\n }\n\n /**\n * The default selected state of the switch.\n */\n get defaultSelected(): boolean {\n return this.hasAttribute('selected');\n }\n set defaultSelected(value: boolean) {\n this.toggleAttribute('selected', value || false);\n }\n\n /**\n * When true, require the switch to be selected when participating in\n * form submission.\n *\n * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#validation\n */\n @property({type: Boolean}) required = false;\n\n /**\n * The value associated with this switch on form submission. `null` is\n * submitted when `selected` is `false`.\n */\n @property() value = 'on';\n\n @query('button', true)\n private readonly button!: HTMLButtonElement | null;\n\n /**\n * Mimics the behavior of <input> dirty checkedness, where the `checked`\n * attribute only updates the checked state if the checkbox has not been\n * interacted with.\n *\n * @see https://html.spec.whatwg.org/multipage/input.html#concept-input-checked-dirty-flag\n */\n private dirtyCheckedness = false;\n\n protected override render() {\n const {ariaLabel} = this as ARIAMixinStrict;\n return html`\n <button\n role=\"switch\"\n part=\"switch\"\n class=\"${switchToggle()}\"\n aria-checked=\"${this.selected ? 'true' : 'false'}\"\n aria-label=${ariaLabel || nothing}\n ?disabled=${this.disabled}\n @change=${this.handleChange}>\n <slot name=\"off-icon\" class=\"switch-icon-off\" ${hasSlotted()}></slot>\n <slot name=\"on-icon\" class=\"switch-icon-on\"></slot>\n </button>\n `;\n }\n\n private handleChange(event: Event) {\n this.dirtyCheckedness = true;\n this.selected = this.button?.ariaChecked === 'true';\n // Change event is not composed, re-dispatch it.\n redispatchEvent(this, event);\n }\n\n override attributeChangedCallback(\n name: string,\n oldValue: string | null,\n newValue: string | null,\n ) {\n if (name === 'selected' && this.dirtyCheckedness) {\n // The 'selected' attribute does not update switches that have been\n // interacted with.\n return;\n }\n\n super.attributeChangedCallback(name, oldValue, newValue);\n }\n\n override [getFormValue]() {\n return this.selected ? this.value : null;\n }\n\n override [getFormState]() {\n return String(this.selected);\n }\n\n override formResetCallback() {\n this.dirtyCheckedness = false;\n this.selected = this.defaultSelected;\n }\n\n override formStateRestoreCallback(state: string) {\n this.selected = state === 'true';\n }\n\n override [createValidator]() {\n return new CheckboxValidator(() => ({\n checked: this.selected,\n required: this.required,\n }));\n }\n\n override [getValidityAnchor]() {\n return this.button;\n }\n}\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright 2026 Google LLC
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/@layer md.sys, md.comp.ripple, md.comp.focus-ring;@layer md.comp.switch{.switch{--handle-color: var(--md-sys-color-outline);--handle-size: 16px;--with-icon-handle-size: 24px;--icon-color: var(--md-sys-color-surface-container-highest);--icon-size: 18px;--state-layer-color: var(--md-sys-color-on-surface);--state-layer-size: 40px;--track-color: var(--md-sys-color-surface-container-highest);--track-height: 32px;--track-outline-color: var(--md-sys-color-outline);--track-outline-width: 2px;--track-width: 52px}.switch:is(:hover,.hover){--handle-color: var(--md-sys-color-on-surface-variant)}.switch:is(:checked,.checked,[aria-checked=true]){--track-color: var(--md-sys-color-primary);--track-outline-color: transparent;--handle-color: var(--md-sys-color-on-primary);--handle-size: 24px;--icon-color: var(--md-sys-color-on-primary-container);--state-layer-color: var(--md-sys-color-primary)}.switch:is(:checked,.checked,[aria-checked=true]):where(:hover,.hover){--handle-color: var(--md-sys-color-primary-container)}.switch:is(:active,.active):where(:not(:disabled,.disabled)){--handle-size: 28px}.switch:is(:disabled,.disabled){--handle-color: hsl(from var(--md-sys-color-on-surface) h s l / 38%);--track-color: hsl( from var(--md-sys-color-surface-container-highest) h s l / 12% );--track-outline-color: hsl( from var(--md-sys-color-on-surface) h s l / 12% )}.switch:is(:disabled,.disabled):where(:checked,.checked,[aria-checked=true]){--handle-color: var(--md-sys-color-surface);--icon-color: hsl(from var(--md-sys-color-on-surface) h s l / 38%);--track-color: hsl(from var(--md-sys-color-on-surface) h s l / 12%)}.switch{display:inline-grid;grid-template:". handle ." 1fr/0fr min-content 1fr;place-items:center;appearance:none;background:var(--track-color);border:var(--track-outline-width) solid var(--track-outline-color);border-radius:calc(var(--track-height)/2);width:var(--track-width);height:var(--track-height);margin:0;padding:0;transition:grid-template-columns 75ms cubic-bezier(0.4, 0, 0.2, 1);isolation:isolate;position:relative;color:var(--icon-color);--md-icon-size: var(--icon-size);--icon: ""}.switch:is(:checked,.checked,[aria-checked=true]){grid-template-columns:1fr min-content 0fr}.switch::before{--_handle-size: if( style(--icon: ""): var(--handle-size); else: max(var(--handle-size), var(--with-icon-handle-size)); );content:var(--icon);font:var(--md-icon-size) var(--md-icon-font);display:grid;place-items:center;z-index:-1;grid-area:handle;aspect-ratio:1;height:100%;clip-path:circle(calc(var(--_handle-size) / 2));transition:clip-path 75ms cubic-bezier(0.4, 0, 0.2, 1);border-radius:50%;background:var(--handle-color)}.switch::after{content:"";z-index:-1;position:absolute;grid-area:handle;background-image:var(--ripple);aspect-ratio:1;width:var(--state-layer-size);border-radius:50%;color:var(--state-layer-color);transition:var(--ripple-transition);animation:var(--ripple-animation)}.switch:has(.switch-icon-off:not(slot),.switch-icon-off.has-slotted){--icon: " "}.switch .switch-icon-off:not(slot),.switch .switch-icon-off::slotted(*),.switch .switch-icon-on:not(slot),.switch .switch-icon-on::slotted(*){grid-area:handle}.switch:is(:checked,.checked,[aria-checked=true]) .switch-icon-off,.switch:not(:checked,.checked,[aria-checked=true]) .switch-icon-on{display:none}}/*# sourceMappingURL=switch.css.map */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sourceRoot":"","sources":["switch.scss","_switch-tokens.scss"],"names":[],"mappings":"AAAA;AAAA;AAAA;AAAA,GASA,kDACA,sBAEI,QCNF,4CACA,oBACA,8BACA,4DACA,kBACA,oDACA,yBACA,6DACA,qBACA,mDACA,2BACA,oBDFE,0BCMF,uDDHE,kDCOF,2CACA,mCACA,+CACA,oBACA,uDACA,iDDVI,uECcJ,sDDVE,6DCcF,oBDXE,gCCeF,qEACA,qFAGA,8EDjBI,6ECuBJ,4CACA,mEACA,oEDpBE,QACE,oBACA,mDACA,mBACA,gBACA,8BACA,mEACA,0CACA,yBACA,2BACA,SACA,UACA,mEACA,kBACA,kBACA,wBACA,iCACA,WAEA,kDACE,0CAGF,gBACE,0HAIA,oBACA,6CACA,aACA,mBACA,WACA,iBACA,eACA,YACA,gDACA,uDACA,kBACA,+BAGF,eACE,WACA,WACA,kBACA,iBACA,+BACA,eACA,8BACA,kBACA,+BACA,oCACA,kCAIJ,qEACE,YAKA,8IAEE,iBAIJ,sIAEE","file":"switch.css"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
// Generated stylesheet for ./labs/gb/components/switch/switch.css.
|
|
7
|
+
import { css } from 'lit';
|
|
8
|
+
export const styles = css `/*!
|
|
9
|
+
* Copyright 2026 Google LLC
|
|
10
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
11
|
+
*/@layer md.sys, md.comp.ripple, md.comp.focus-ring;@layer md.comp.switch{.switch{--handle-color: var(--md-sys-color-outline);--handle-size: 16px;--with-icon-handle-size: 24px;--icon-color: var(--md-sys-color-surface-container-highest);--icon-size: 18px;--state-layer-color: var(--md-sys-color-on-surface);--state-layer-size: 40px;--track-color: var(--md-sys-color-surface-container-highest);--track-height: 32px;--track-outline-color: var(--md-sys-color-outline);--track-outline-width: 2px;--track-width: 52px}.switch:is(:hover,.hover){--handle-color: var(--md-sys-color-on-surface-variant)}.switch:is(:checked,.checked,[aria-checked=true]){--track-color: var(--md-sys-color-primary);--track-outline-color: transparent;--handle-color: var(--md-sys-color-on-primary);--handle-size: 24px;--icon-color: var(--md-sys-color-on-primary-container);--state-layer-color: var(--md-sys-color-primary)}.switch:is(:checked,.checked,[aria-checked=true]):where(:hover,.hover){--handle-color: var(--md-sys-color-primary-container)}.switch:is(:active,.active):where(:not(:disabled,.disabled)){--handle-size: 28px}.switch:is(:disabled,.disabled){--handle-color: hsl(from var(--md-sys-color-on-surface) h s l / 38%);--track-color: hsl( from var(--md-sys-color-surface-container-highest) h s l / 12% );--track-outline-color: hsl( from var(--md-sys-color-on-surface) h s l / 12% )}.switch:is(:disabled,.disabled):where(:checked,.checked,[aria-checked=true]){--handle-color: var(--md-sys-color-surface);--icon-color: hsl(from var(--md-sys-color-on-surface) h s l / 38%);--track-color: hsl(from var(--md-sys-color-on-surface) h s l / 12%)}.switch{display:inline-grid;grid-template:". handle ." 1fr/0fr min-content 1fr;place-items:center;appearance:none;background:var(--track-color);border:var(--track-outline-width) solid var(--track-outline-color);border-radius:calc(var(--track-height)/2);width:var(--track-width);height:var(--track-height);margin:0;padding:0;transition:grid-template-columns 75ms cubic-bezier(0.4, 0, 0.2, 1);isolation:isolate;position:relative;color:var(--icon-color);--md-icon-size: var(--icon-size);--icon: ""}.switch:is(:checked,.checked,[aria-checked=true]){grid-template-columns:1fr min-content 0fr}.switch::before{--_handle-size: if( style(--icon: ""): var(--handle-size); else: max(var(--handle-size), var(--with-icon-handle-size)); );content:var(--icon);font:var(--md-icon-size) var(--md-icon-font);display:grid;place-items:center;z-index:-1;grid-area:handle;aspect-ratio:1;height:100%;clip-path:circle(calc(var(--_handle-size) / 2));transition:clip-path 75ms cubic-bezier(0.4, 0, 0.2, 1);border-radius:50%;background:var(--handle-color)}.switch::after{content:"";z-index:-1;position:absolute;grid-area:handle;background-image:var(--ripple);aspect-ratio:1;width:var(--state-layer-size);border-radius:50%;color:var(--state-layer-color);transition:var(--ripple-transition);animation:var(--ripple-animation)}.switch:has(.switch-icon-off:not(slot),.switch-icon-off.has-slotted){--icon: " "}.switch .switch-icon-off:not(slot),.switch .switch-icon-off::slotted(*),.switch .switch-icon-on:not(slot),.switch .switch-icon-on::slotted(*){grid-area:handle}.switch:is(:checked,.checked,[aria-checked=true]) .switch-icon-off,.switch:not(:checked,.checked,[aria-checked=true]) .switch-icon-on{display:none}}
|
|
12
|
+
`;
|
|
13
|
+
export default styles.styleSheet;
|
|
14
|
+
//# sourceMappingURL=switch.cssresult.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"switch.cssresult.js","sourceRoot":"","sources":["switch.cssresult.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,mEAAmE;AACnE,OAAO,EAAC,GAAG,EAAC,MAAM,KAAK,CAAC;AACxB,MAAM,CAAC,MAAM,MAAM,GAAG,GAAG,CAAA;;;;CAIxB,CAAC;AACF,eAAe,MAAM,CAAC,UAAW,CAAC","sourcesContent":["/**\n * @license\n * Copyright 2026 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n// Generated stylesheet for ./labs/gb/components/switch/switch.css.\nimport {css} from 'lit';\nexport const styles = css`/*!\n * Copyright 2026 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */@layer md.sys, md.comp.ripple, md.comp.focus-ring;@layer md.comp.switch{.switch{--handle-color: var(--md-sys-color-outline);--handle-size: 16px;--with-icon-handle-size: 24px;--icon-color: var(--md-sys-color-surface-container-highest);--icon-size: 18px;--state-layer-color: var(--md-sys-color-on-surface);--state-layer-size: 40px;--track-color: var(--md-sys-color-surface-container-highest);--track-height: 32px;--track-outline-color: var(--md-sys-color-outline);--track-outline-width: 2px;--track-width: 52px}.switch:is(:hover,.hover){--handle-color: var(--md-sys-color-on-surface-variant)}.switch:is(:checked,.checked,[aria-checked=true]){--track-color: var(--md-sys-color-primary);--track-outline-color: transparent;--handle-color: var(--md-sys-color-on-primary);--handle-size: 24px;--icon-color: var(--md-sys-color-on-primary-container);--state-layer-color: var(--md-sys-color-primary)}.switch:is(:checked,.checked,[aria-checked=true]):where(:hover,.hover){--handle-color: var(--md-sys-color-primary-container)}.switch:is(:active,.active):where(:not(:disabled,.disabled)){--handle-size: 28px}.switch:is(:disabled,.disabled){--handle-color: hsl(from var(--md-sys-color-on-surface) h s l / 38%);--track-color: hsl( from var(--md-sys-color-surface-container-highest) h s l / 12% );--track-outline-color: hsl( from var(--md-sys-color-on-surface) h s l / 12% )}.switch:is(:disabled,.disabled):where(:checked,.checked,[aria-checked=true]){--handle-color: var(--md-sys-color-surface);--icon-color: hsl(from var(--md-sys-color-on-surface) h s l / 38%);--track-color: hsl(from var(--md-sys-color-on-surface) h s l / 12%)}.switch{display:inline-grid;grid-template:\". handle .\" 1fr/0fr min-content 1fr;place-items:center;appearance:none;background:var(--track-color);border:var(--track-outline-width) solid var(--track-outline-color);border-radius:calc(var(--track-height)/2);width:var(--track-width);height:var(--track-height);margin:0;padding:0;transition:grid-template-columns 75ms cubic-bezier(0.4, 0, 0.2, 1);isolation:isolate;position:relative;color:var(--icon-color);--md-icon-size: var(--icon-size);--icon: \"\"}.switch:is(:checked,.checked,[aria-checked=true]){grid-template-columns:1fr min-content 0fr}.switch::before{--_handle-size: if( style(--icon: \"\"): var(--handle-size); else: max(var(--handle-size), var(--with-icon-handle-size)); );content:var(--icon);font:var(--md-icon-size) var(--md-icon-font);display:grid;place-items:center;z-index:-1;grid-area:handle;aspect-ratio:1;height:100%;clip-path:circle(calc(var(--_handle-size) / 2));transition:clip-path 75ms cubic-bezier(0.4, 0, 0.2, 1);border-radius:50%;background:var(--handle-color)}.switch::after{content:\"\";z-index:-1;position:absolute;grid-area:handle;background-image:var(--ripple);aspect-ratio:1;width:var(--state-layer-size);border-radius:50%;color:var(--state-layer-color);transition:var(--ripple-transition);animation:var(--ripple-animation)}.switch:has(.switch-icon-off:not(slot),.switch-icon-off.has-slotted){--icon: \" \"}.switch .switch-icon-off:not(slot),.switch .switch-icon-off::slotted(*),.switch .switch-icon-on:not(slot),.switch .switch-icon-on::slotted(*){grid-area:handle}.switch:is(:checked,.checked,[aria-checked=true]) .switch-icon-off,.switch:not(:checked,.checked,[aria-checked=true]) .switch-icon-on{display:none}}\n`;\nexport default styles.styleSheet!;\n"]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { type ClassInfo } from 'lit/directives/class-map.js';
|
|
7
|
+
/** Switch classes. */
|
|
8
|
+
export declare const SWITCH_CLASSES: {
|
|
9
|
+
readonly switch: "switch";
|
|
10
|
+
readonly checked: string;
|
|
11
|
+
readonly hover: string;
|
|
12
|
+
readonly active: string;
|
|
13
|
+
readonly disabled: string;
|
|
14
|
+
};
|
|
15
|
+
/** The state provided to the `switchClasses()` function. */
|
|
16
|
+
export interface SwitchClassesState {
|
|
17
|
+
/** Emulates `:checked`. */
|
|
18
|
+
checked?: boolean;
|
|
19
|
+
/** Emulates `:hover`. */
|
|
20
|
+
hover?: boolean;
|
|
21
|
+
/** Emulates `:active`. */
|
|
22
|
+
active?: boolean;
|
|
23
|
+
/** Emulates `:disabled`. */
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Returns the switch classes to apply to an element based on the given state.
|
|
28
|
+
*
|
|
29
|
+
* @param state The state of the switch.
|
|
30
|
+
* @return An object of class names and truthy values if they apply.
|
|
31
|
+
*/
|
|
32
|
+
export declare function switchClasses({ checked, hover, active, disabled, }?: SwitchClassesState): ClassInfo;
|
|
33
|
+
/**
|
|
34
|
+
* Sets up switch functionality for the given element.
|
|
35
|
+
*
|
|
36
|
+
* @param switchEl The element on which to set up switch functionality.
|
|
37
|
+
* @param opts Setup options, supports a cleanup `signal`.
|
|
38
|
+
*/
|
|
39
|
+
export declare function setupSwitch(switchEl: HTMLElement, opts?: {
|
|
40
|
+
signal?: AbortSignal;
|
|
41
|
+
}): void;
|
|
42
|
+
/**
|
|
43
|
+
* A Lit directive that adds switch styling and functionality to its element.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* html`
|
|
48
|
+
* <input role="switch" type="checkbox" class="${switchToggle()}">
|
|
49
|
+
*
|
|
50
|
+
* <button role="switch" aria-checked="false" class="${switchToggle()}"></button>
|
|
51
|
+
* `;
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare const switchToggle: (state?: SwitchClassesState & import("../shared/directives.js").AdditionalClasses) => import("lit-html/directive.js").DirectiveResult;
|