@m3e/icon-button 1.0.0-rc.1 → 1.0.0-rc.3

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.
@@ -1,514 +0,0 @@
1
- import { CSSResultGroup, html, LitElement, nothing, PropertyValues } from "lit";
2
- import { customElement, property, query } from "lit/decorators.js";
3
-
4
- import {
5
- renderPseudoLink,
6
- AttachInternals,
7
- Disabled,
8
- DisabledInteractive,
9
- Focusable,
10
- FocusController,
11
- FormSubmitter,
12
- LinkButton,
13
- M3eElevationElement,
14
- M3eFocusRingElement,
15
- M3eRippleElement,
16
- M3eStateLayerElement,
17
- PressedController,
18
- Role,
19
- KeyboardClick,
20
- hasAssignedNodes,
21
- debounce,
22
- ResizeController,
23
- } from "@m3e/core";
24
-
25
- import { IconButtonSize } from "./IconButtonSize";
26
- import { IconButtonShape } from "./IconButtonShape";
27
- import { IconButtonVariant } from "./IconButtonVariant";
28
-
29
- import { IconButtonStyle, IconButtonSizeStyle, IconButtonVariantStyle } from "./styles";
30
- import { IconButtonWidth } from "./IconButtonWidth";
31
-
32
- /**
33
- * @summary
34
- * An icon button users interact with to perform a supplementary action.
35
- *
36
- * @description
37
- * The `m3e-icon-button` component is a semantic, expressive UI primitive for triggering actions with a single icon.
38
- * Designed according to Material Design 3 guidelines, it supports five four variants, specified using the
39
- * `variant` attribute—`filled`, `tonal`, `outlined`, and `standard`—each with dynamic elevation, shape morphing, and
40
- * adaptive color theming. The component responds to interaction states (hover, focus, press, disabled) with smooth motion
41
- * transitions, ensuring emotional clarity and visual hierarchy.
42
- *
43
- * The component is accessible by default, with ARIA roles, contrast-safe color tokens, and strong focus indicators.
44
- * It supports optional icons and states for binary actions. When using `m3e-icon` for icons, `filled` is automatically
45
- * set based on the selected state of a toggle button. It can also function as a link or be used to submit form data.
46
- *
47
- * Native disabled `<button>` elements cannot receive focus. This can be problematic in some cases because it can prevent you
48
- * from telling the user why the button is disabled. You can use the `disabled-interactive` attribute to style a `m3e-icon-button`
49
- * as disabled but allow for it to receive focus. The button will have `aria-disabled="true"` for assistive technology.
50
- *
51
- * @example
52
- * The following example illustrates changing the appearance from `standard` (default) to `filled` using the `variant`
53
- * attribute, changing the size using the `size` attribute, and enabling toggle behavior using the `toggle` attribute.
54
- *
55
- * ```html
56
- * <m3e-icon-button variant="filled" size="large" toggle selected>
57
- * <m3e-icon name="favorite"></m3e-icon>
58
- * </m3e-icon-button>
59
- * ```
60
- *
61
- * @tag m3e-icon-button
62
- *
63
- * @slot - Renders the icon of the button.
64
- * @slot selected - Renders an icon, when selected.
65
- *
66
- * @attr disabled - Whether the element is disabled.
67
- * @attr disabled-interactive - Whether the element is disabled and interactive.
68
- * @attr download - A value indicating whether the `target` of the link button will be downloaded, optionally specifying the new name of the file.
69
- * @attr href - The URL to which the link button points.
70
- * @attr name - The name of the element, submitted as a pair with the element's `value` as part of form data, when the element is used to submit a form.
71
- * @attr rel - The relationship between the `target` of the link button and the document.
72
- * @attr selected - Whether the toggle button is selected.
73
- * @attr shape - The shape of the button.
74
- * @attr size - The size of the button.
75
- * @attr target - The target of the link button.
76
- * @attr toggle - Whether the button will toggle between selected and unselected states.
77
- * @attr type - The type of the element.
78
- * @attr value - The value associated with the element's name when it's submitted with form data.
79
- * @attr variant - The appearance variant of the button.
80
- * @attr width - The width of the button.
81
- *
82
- * @fires input - Dispatched when a toggle button's selected state changes.
83
- * @fires change - Dispatched when a toggle button's selected state changes.
84
- *
85
- * @cssprop --m3e-icon-button-extra-small-container-height - Height of the extra-small container.
86
- * @cssprop --m3e-icon-button-extra-small-outline-thickness - Outline thickness for extra-small.
87
- * @cssprop --m3e-icon-button-extra-small-icon-size - Icon size for extra-small.
88
- * @cssprop --m3e-icon-button-extra-small-shape-round - Corner radius for round extra-small.
89
- * @cssprop --m3e-icon-button-extra-small-shape-square - Corner radius for square extra-small.
90
- * @cssprop --m3e-icon-button-extra-small-selected-shape-round - Corner radius for selected round extra-small.
91
- * @cssprop --m3e-icon-button-extra-small-selected-shape-square - Corner radius for selected square extra-small.
92
- * @cssprop --m3e-icon-button-extra-small-shape-pressed-morph - Corner radius for pressed extra-small.
93
- * @cssprop --m3e-icon-button-extra-small-narrow-leading-space - Leading space for extra-small (narrow).
94
- * @cssprop --m3e-icon-button-extra-small-narrow-trailing-space - Trailing space for extra-small (narrow).
95
- * @cssprop --m3e-icon-button-extra-small-default-leading-space - Leading space for extra-small (default).
96
- * @cssprop --m3e-icon-button-extra-small-default-trailing-space - Trailing space for extra-small (default).
97
- * @cssprop --m3e-icon-button-extra-small-wide-leading-space - Leading space for extra-small (wide).
98
- * @cssprop --m3e-icon-button-extra-small-wide-trailing-space - Trailing space for extra-small (wide).
99
- * @cssprop --m3e-icon-button-small-container-height - Height of the small container.
100
- * @cssprop --m3e-icon-button-small-outline-thickness - Outline thickness for small.
101
- * @cssprop --m3e-icon-button-small-icon-size - Icon size for small.
102
- * @cssprop --m3e-icon-button-small-shape-round - Corner radius for round small.
103
- * @cssprop --m3e-icon-button-small-shape-square - Corner radius for square small.
104
- * @cssprop --m3e-icon-button-small-selected-shape-round - Corner radius for selected round small.
105
- * @cssprop --m3e-icon-button-small-selected-shape-square - Corner radius for selected square small.
106
- * @cssprop --m3e-icon-button-small-shape-pressed-morph - Corner radius for pressed small.
107
- * @cssprop --m3e-icon-button-small-narrow-leading-space - Leading space for small (narrow).
108
- * @cssprop --m3e-icon-button-small-narrow-trailing-space - Trailing space for small (narrow).
109
- * @cssprop --m3e-icon-button-small-default-leading-space - Leading space for small (default).
110
- * @cssprop --m3e-icon-button-small-default-trailing-space - Trailing space for small (default).
111
- * @cssprop --m3e-icon-button-small-wide-leading-space - Leading space for small (wide).
112
- * @cssprop --m3e-icon-button-small-wide-trailing-space - Trailing space for small (wide).
113
- * @cssprop --m3e-icon-button-medium-container-height - Height of the medium container.
114
- * @cssprop --m3e-icon-button-medium-outline-thickness - Outline thickness for medium.
115
- * @cssprop --m3e-icon-button-medium-icon-size - Icon size for medium.
116
- * @cssprop --m3e-icon-button-medium-shape-round - Corner radius for round medium.
117
- * @cssprop --m3e-icon-button-medium-shape-square - Corner radius for square medium.
118
- * @cssprop --m3e-icon-button-medium-selected-shape-round - Corner radius for selected round medium.
119
- * @cssprop --m3e-icon-button-medium-selected-shape-square - Corner radius for selected square medium.
120
- * @cssprop --m3e-icon-button-medium-shape-pressed-morph - Corner radius for pressed medium.
121
- * @cssprop --m3e-icon-button-medium-narrow-leading-space - Leading space for medium (narrow).
122
- * @cssprop --m3e-icon-button-medium-narrow-trailing-space - Trailing space for medium (narrow).
123
- * @cssprop --m3e-icon-button-medium-default-leading-space - Leading space for medium (default).
124
- * @cssprop --m3e-icon-button-medium-default-trailing-space - Trailing space for medium (default).
125
- * @cssprop --m3e-icon-button-medium-wide-leading-space - Leading space for medium (wide).
126
- * @cssprop --m3e-icon-button-medium-wide-trailing-space - Trailing space for medium (wide).
127
- * @cssprop --m3e-icon-button-large-container-height - Height of the large container.
128
- * @cssprop --m3e-icon-button-large-outline-thickness - Outline thickness for large.
129
- * @cssprop --m3e-icon-button-large-icon-size - Icon size for large.
130
- * @cssprop --m3e-icon-button-large-shape-round - Corner radius for round large.
131
- * @cssprop --m3e-icon-button-large-shape-square - Corner radius for square large.
132
- * @cssprop --m3e-icon-button-large-selected-shape-round - Corner radius for selected round large.
133
- * @cssprop --m3e-icon-button-large-selected-shape-square - Corner radius for selected square large.
134
- * @cssprop --m3e-icon-button-large-shape-pressed-morph - Corner radius for pressed large.
135
- * @cssprop --m3e-icon-button-large-narrow-leading-space - Leading space for large (narrow).
136
- * @cssprop --m3e-icon-button-large-narrow-trailing-space - Trailing space for large (narrow).
137
- * @cssprop --m3e-icon-button-large-default-leading-space - Leading space for large (default).
138
- * @cssprop --m3e-icon-button-large-default-trailing-space - Trailing space for large (default).
139
- * @cssprop --m3e-icon-button-large-wide-leading-space - Leading space for large (wide).
140
- * @cssprop --m3e-icon-button-large-wide-trailing-space - Trailing space for large (wide).
141
- * @cssprop --m3e-icon-button-extra-large-container-height - Height of the extra-large container.
142
- * @cssprop --m3e-icon-button-extra-large-outline-thickness - Outline thickness for extra-large.
143
- * @cssprop --m3e-icon-button-extra-large-icon-size - Icon size for extra-large.
144
- * @cssprop --m3e-icon-button-extra-large-shape-round - Corner radius for round extra-large.
145
- * @cssprop --m3e-icon-button-extra-large-shape-square - Corner radius for square extra-large.
146
- * @cssprop --m3e-icon-button-extra-large-selected-shape-round - Corner radius for selected round extra-large.
147
- * @cssprop --m3e-icon-button-extra-large-selected-shape-square - Corner radius for selected square extra-large.
148
- * @cssprop --m3e-icon-button-extra-large-shape-pressed-morph - Corner radius for pressed extra-large.
149
- * @cssprop --m3e-icon-button-extra-large-narrow-leading-space - Leading space for extra-large (narrow).
150
- * @cssprop --m3e-icon-button-extra-large-narrow-trailing-space - Trailing space for extra-large (narrow).
151
- * @cssprop --m3e-icon-button-extra-large-default-leading-space - Leading space for extra-large (default).
152
- * @cssprop --m3e-icon-button-extra-large-default-trailing-space - Trailing space for extra-large (default).
153
- * @cssprop --m3e-icon-button-extra-large-wide-leading-space - Leading space for extra-large (wide).
154
- * @cssprop --m3e-icon-button-extra-large-wide-trailing-space - Trailing space for extra-large (wide).
155
- * @cssprop --m3e-outlined-icon-button-icon-color - Default icon color for outlined variant.
156
- * @cssprop --m3e-outlined-icon-button-outline-color - Default outline color for outlined variant.
157
- * @cssprop --m3e-outlined-icon-button-unselected-icon-color - Unselected icon color for outlined variant.
158
- * @cssprop --m3e-outlined-icon-button-selected-icon-color - Selected icon color for outlined variant.
159
- * @cssprop --m3e-outlined-icon-button-selected-container-color - Selected container background color for outlined variant.
160
- * @cssprop --m3e-outlined-icon-button-disabled-container-color - Container background color when disabled (outlined).
161
- * @cssprop --m3e-outlined-icon-button-disabled-container-opacity - Opacity of container when disabled (outlined).
162
- * @cssprop --m3e-outlined-icon-button-disabled-icon-color - Icon color when disabled (outlined).
163
- * @cssprop --m3e-outlined-icon-button-disabled-icon-opacity - Icon opacity when disabled (outlined).
164
- * @cssprop --m3e-outlined-icon-button-disabled-outline-color - Outline color when disabled (outlined).
165
- * @cssprop --m3e-outlined-icon-button-hover-icon-color - Icon color on hover (outlined).
166
- * @cssprop --m3e-outlined-icon-button-hover-outline-color - Outline color on hover (outlined).
167
- * @cssprop --m3e-outlined-icon-button-hover-state-layer-color - State layer color on hover (outlined).
168
- * @cssprop --m3e-outlined-icon-button-hover-state-layer-opacity - State layer opacity on hover (outlined).
169
- * @cssprop --m3e-outlined-icon-button-hover-unselected-icon-color - Unselected icon color on hover (outlined).
170
- * @cssprop --m3e-outlined-icon-button-hover-unselected-state-layer-color - Unselected state layer color on hover (outlined).
171
- * @cssprop --m3e-outlined-icon-button-hover-selected-icon-color - Selected icon color on hover (outlined).
172
- * @cssprop --m3e-outlined-icon-button-hover-selected-state-layer-color - Selected state layer color on hover (outlined).
173
- * @cssprop --m3e-outlined-icon-button-focus-icon-color - Icon color on focus (outlined).
174
- * @cssprop --m3e-outlined-icon-button-focus-outline-color - Outline color on focus (outlined).
175
- * @cssprop --m3e-outlined-icon-button-focus-state-layer-color - State layer color on focus (outlined).
176
- * @cssprop --m3e-outlined-icon-button-focus-state-layer-opacity - State layer opacity on focus (outlined).
177
- * @cssprop --m3e-outlined-icon-button-focus-unselected-icon-color - Unselected icon color on focus (outlined).
178
- * @cssprop --m3e-outlined-icon-button-focus-unselected-state-layer-color - Unselected state layer color on focus (outlined).
179
- * @cssprop --m3e-outlined-icon-button-focus-selected-icon-color - Selected icon color on focus (outlined).
180
- * @cssprop --m3e-outlined-icon-button-focus-selected-state-layer-color - Selected state layer color on focus (outlined).
181
- * @cssprop --m3e-outlined-icon-button-pressed-icon-color - Icon color on pressed (outlined).
182
- * @cssprop --m3e-outlined-icon-button-pressed-outline-color - Outline color on pressed (outlined).
183
- * @cssprop --m3e-outlined-icon-button-pressed-state-layer-color - State layer color on pressed (outlined).
184
- * @cssprop --m3e-outlined-icon-button-pressed-state-layer-opacity - State layer opacity on pressed (outlined).
185
- * @cssprop --m3e-outlined-icon-button-pressed-unselected-icon-color - Unselected icon color on pressed (outlined).
186
- * @cssprop --m3e-outlined-icon-button-pressed-unselected-state-layer-color - Unselected state layer color on pressed (outlined).
187
- * @cssprop --m3e-outlined-icon-button-pressed-selected-icon-color - Selected icon color on pressed (outlined).
188
- * @cssprop --m3e-outlined-icon-button-pressed-selected-state-layer-color - Selected state layer color on pressed (outlined).
189
- * @cssprop --m3e-filled-icon-button-icon-color - Default icon color for filled variant.
190
- * @cssprop --m3e-filled-icon-button-container-color - Default container background color for filled variant.
191
- * @cssprop --m3e-filled-icon-button-unselected-icon-color - Unselected icon color for filled variant.
192
- * @cssprop --m3e-filled-icon-button-unselected-container-color - Unselected container background color for filled variant.
193
- * @cssprop --m3e-filled-icon-button-selected-icon-color - Selected icon color for filled variant.
194
- * @cssprop --m3e-filled-icon-button-selected-container-color - Selected container background color for filled variant.
195
- * @cssprop --m3e-filled-icon-button-disabled-container-color - Container background color when disabled (filled).
196
- * @cssprop --m3e-filled-icon-button-disabled-container-opacity - Opacity of container when disabled (filled).
197
- * @cssprop --m3e-filled-icon-button-disabled-icon-color - Icon color when disabled (filled).
198
- * @cssprop --m3e-filled-icon-button-disabled-icon-opacity - Icon opacity when disabled (filled).
199
- * @cssprop --m3e-filled-icon-button-hover-icon-color - Icon color on hover (filled).
200
- * @cssprop --m3e-filled-icon-button-hover-state-layer-color - State layer color on hover (filled).
201
- * @cssprop --m3e-filled-icon-button-hover-state-layer-opacity - State layer opacity on hover (filled).
202
- * @cssprop --m3e-filled-icon-button-hover-unselected-icon-color - Unselected icon color on hover (filled).
203
- * @cssprop --m3e-filled-icon-button-hover-unselected-state-layer-color - Unselected state layer color on hover (filled).
204
- * @cssprop --m3e-filled-icon-button-hover-selected-icon-color - Selected icon color on hover (filled).
205
- * @cssprop --m3e-filled-icon-button-hover-selected-state-layer-color - Selected state layer color on hover (filled).
206
- * @cssprop --m3e-filled-icon-button-focus-icon-color - Icon color on focus (filled).
207
- * @cssprop --m3e-filled-icon-button-focus-state-layer-color - State layer color on focus (filled).
208
- * @cssprop --m3e-filled-icon-button-focus-state-layer-opacity - State layer opacity on focus (filled).
209
- * @cssprop --m3e-filled-icon-button-focus-unselected-icon-color - Unselected icon color on focus (filled).
210
- * @cssprop --m3e-filled-icon-button-focus-unselected-state-layer-color - Unselected state layer color on focus (filled).
211
- * @cssprop --m3e-filled-icon-button-focus-selected-icon-color - Selected icon color on focus (filled).
212
- * @cssprop --m3e-filled-icon-button-focus-selected-state-layer-color - Selected state layer color on focus (filled).
213
- * @cssprop --m3e-filled-icon-button-pressed-icon-color - Icon color on pressed (filled).
214
- * @cssprop --m3e-filled-icon-button-pressed-state-layer-color - State layer color on pressed (filled).
215
- * @cssprop --m3e-filled-icon-button-pressed-state-layer-opacity - State layer opacity on pressed (filled).
216
- * @cssprop --m3e-filled-icon-button-pressed-unselected-icon-color - Unselected icon color on pressed (filled).
217
- * @cssprop --m3e-filled-icon-button-pressed-unselected-state-layer-color - Unselected state layer color on pressed (filled).
218
- * @cssprop --m3e-filled-icon-button-pressed-selected-icon-color - Selected icon color on pressed (filled).
219
- * @cssprop --m3e-filled-icon-button-pressed-selected-state-layer-color - Selected state layer color on pressed (filled).
220
- * @cssprop --m3e-tonal-icon-button-icon-color - Default icon color for tonal variant.
221
- * @cssprop --m3e-tonal-icon-button-container-color - Default container background color for tonal variant.
222
- * @cssprop --m3e-tonal-icon-button-unselected-icon-color - Unselected icon color for tonal variant.
223
- * @cssprop --m3e-tonal-icon-button-unselected-container-color - Unselected container background color for tonal variant.
224
- * @cssprop --m3e-tonal-icon-button-selected-icon-color - Selected icon color for tonal variant.
225
- * @cssprop --m3e-tonal-icon-button-selected-container-color - Selected container background color for tonal variant.
226
- * @cssprop --m3e-tonal-icon-button-disabled-container-color - Container background color when disabled (tonal).
227
- * @cssprop --m3e-tonal-icon-button-disabled-container-opacity - Opacity of container when disabled (tonal).
228
- * @cssprop --m3e-tonal-icon-button-disabled-icon-color - Icon color when disabled (tonal).
229
- * @cssprop --m3e-tonal-icon-button-disabled-icon-opacity - Icon opacity when disabled (tonal).
230
- * @cssprop --m3e-tonal-icon-button-hover-icon-color - Icon color on hover (tonal).
231
- * @cssprop --m3e-tonal-icon-button-hover-state-layer-color - State layer color on hover (tonal).
232
- * @cssprop --m3e-tonal-icon-button-hover-state-layer-opacity - State layer opacity on hover (tonal).
233
- * @cssprop --m3e-tonal-icon-button-hover-unselected-icon-color - Unselected icon color on hover (tonal).
234
- * @cssprop --m3e-tonal-icon-button-hover-unselected-state-layer-color - Unselected state layer color on hover (tonal).
235
- * @cssprop --m3e-tonal-icon-button-hover-selected-icon-color - Selected icon color on hover (tonal).
236
- * @cssprop --m3e-tonal-icon-button-hover-selected-state-layer-color - Selected state layer color on hover (tonal).
237
- * @cssprop --m3e-tonal-icon-button-focus-icon-color - Icon color on focus (tonal).
238
- * @cssprop --m3e-tonal-icon-button-focus-state-layer-color - State layer color on focus (tonal).
239
- * @cssprop --m3e-tonal-icon-button-focus-state-layer-opacity - State layer opacity on focus (tonal).
240
- * @cssprop --m3e-tonal-icon-button-focus-unselected-icon-color - Unselected icon color on focus (tonal).
241
- * @cssprop --m3e-tonal-icon-button-focus-unselected-state-layer-color - Unselected state layer color on focus (tonal).
242
- * @cssprop --m3e-tonal-icon-button-focus-selected-icon-color - Selected icon color on focus (tonal).
243
- * @cssprop --m3e-tonal-icon-button-focus-selected-state-layer-color - Selected state layer color on focus (tonal).
244
- * @cssprop --m3e-tonal-icon-button-pressed-icon-color - Icon color on pressed (tonal).
245
- * @cssprop --m3e-tonal-icon-button-pressed-state-layer-color - State layer color on pressed (tonal).
246
- * @cssprop --m3e-tonal-icon-button-pressed-state-layer-opacity - State layer opacity on pressed (tonal).
247
- * @cssprop --m3e-tonal-icon-button-pressed-unselected-icon-color - Unselected icon color on pressed (tonal).
248
- * @cssprop --m3e-tonal-icon-button-pressed-unselected-state-layer-color - Unselected state layer color on pressed (tonal).
249
- * @cssprop --m3e-tonal-icon-button-pressed-selected-icon-color - Selected icon color on pressed (tonal).
250
- * @cssprop --m3e-tonal-icon-button-pressed-selected-state-layer-color - Selected state layer color on pressed (tonal).
251
- * @cssprop --m3e-standard-icon-button-icon-color - Default icon color for standard variant.
252
- * @cssprop --m3e-standard-icon-button-unselected-icon-color - Unselected icon color for standard variant.
253
- * @cssprop --m3e-standard-icon-button-selected-icon-color - Selected icon color for standard variant.
254
- * @cssprop --m3e-standard-icon-button-disabled-container-color - Container background color when disabled (standard).
255
- * @cssprop --m3e-standard-icon-button-disabled-container-opacity - Opacity of container when disabled (standard).
256
- * @cssprop --m3e-standard-icon-button-disabled-icon-color - Icon color when disabled (standard).
257
- * @cssprop --m3e-standard-icon-button-disabled-icon-opacity - Icon opacity when disabled (standard).
258
- * @cssprop --m3e-standard-icon-button-hover-icon-color - Icon color on hover (standard).
259
- * @cssprop --m3e-standard-icon-button-hover-state-layer-color - State layer color on hover (standard).
260
- * @cssprop --m3e-standard-icon-button-hover-state-layer-opacity - State layer opacity on hover (standard).
261
- * @cssprop --m3e-standard-icon-button-hover-unselected-icon-color - Unselected icon color on hover (standard).
262
- * @cssprop --m3e-standard-icon-button-hover-unselected-state-layer-color - Unselected state layer color on hover (standard).
263
- * @cssprop --m3e-standard-icon-button-hover-selected-icon-color - Selected icon color on hover (standard).
264
- * @cssprop --m3e-standard-icon-button-hover-selected-state-layer-color - Selected state layer color on hover (standard).
265
- * @cssprop --m3e-standard-icon-button-focus-icon-color - Icon color on focus (standard).
266
- * @cssprop --m3e-standard-icon-button-focus-state-layer-color - State layer color on focus (standard).
267
- * @cssprop --m3e-standard-icon-button-focus-state-layer-opacity - State layer opacity on focus (standard).
268
- * @cssprop --m3e-standard-icon-button-focus-unselected-icon-color - Unselected icon color on focus (standard).
269
- * @cssprop --m3e-standard-icon-button-focus-unselected-state-layer-color - Unselected state layer color on focus (standard).
270
- * @cssprop --m3e-standard-icon-button-focus-selected-icon-color - Selected icon color on focus (standard).
271
- * @cssprop --m3e-standard-icon-button-focus-selected-state-layer-color - Selected state layer color on focus (standard).
272
- * @cssprop --m3e-standard-icon-button-pressed-icon-color - Icon color on pressed (standard).
273
- * @cssprop --m3e-standard-icon-button-pressed-state-layer-color - State layer color on pressed (standard).
274
- * @cssprop --m3e-standard-icon-button-pressed-state-layer-opacity - State layer opacity on pressed (standard).
275
- * @cssprop --m3e-standard-icon-button-pressed-unselected-icon-color - Unselected icon color on pressed (standard).
276
- * @cssprop --m3e-standard-icon-button-pressed-unselected-state-layer-color - Unselected state layer color on pressed (standard).
277
- * @cssprop --m3e-standard-icon-button-pressed-selected-icon-color - Selected icon color on pressed (standard).
278
- * @cssprop --m3e-standard-icon-button-pressed-selected-state-layer-color - Selected state layer color on pressed (standard).
279
- */
280
- @customElement("m3e-icon-button")
281
- export class M3eIconButtonElement extends KeyboardClick(
282
- LinkButton(FormSubmitter(Focusable(DisabledInteractive(Disabled(AttachInternals(Role(LitElement, "button"), true))))))
283
- ) {
284
- /** The styles of the element. */
285
- static override styles: CSSResultGroup = [IconButtonSizeStyle, IconButtonVariantStyle, IconButtonStyle];
286
-
287
- /** @private */ @query(".base") private readonly _base?: HTMLElement;
288
- /** @private */ @query(".elevation") private readonly _elevation?: M3eElevationElement;
289
- /** @private */ @query(".focus-ring") private readonly _focusRing?: M3eFocusRingElement;
290
- /** @private */ @query(".state-layer") private readonly _stateLayer?: M3eStateLayerElement;
291
- /** @private */ @query(".ripple") private readonly _ripple?: M3eRippleElement;
292
-
293
- /** @private */ readonly #clickHandler = (e: Event) => this.#handleClick(e);
294
-
295
- constructor() {
296
- super();
297
-
298
- new ResizeController(this, {
299
- callback: () => {
300
- if (this.grouped) {
301
- this._handleResize();
302
- }
303
- },
304
- });
305
-
306
- new FocusController(this, {
307
- callback: (focused) => {
308
- if (!this.disabledInteractive && this._base) {
309
- if (focused) {
310
- this.#updateButtonShape();
311
- } else if (!this.grouped) {
312
- this._base?.style.removeProperty("--_button-shape");
313
- }
314
- }
315
- },
316
- });
317
-
318
- new PressedController(this, {
319
- isPressedKey: (key) => key === " " || key === "Enter",
320
- callback: (pressed) => {
321
- if (!this.disabled && !this.disabledInteractive) {
322
- this.classList.toggle("-pressed", pressed);
323
- this.classList.toggle("-resting", !pressed);
324
-
325
- const group = this.closest("m3e-button-group");
326
- if (group) {
327
- const clientWidth = this.getBoundingClientRect().width;
328
- const buttons = [...group.querySelectorAll<HTMLElement>("m3e-button,m3e-icon-button")];
329
- const index = buttons.indexOf(this);
330
-
331
- for (let i = 0; i < buttons.length; i++) {
332
- const button = buttons[i];
333
- if (i === index - 1) {
334
- button.style.setProperty("--_adjacent-button-width", `${clientWidth}px`);
335
- button.classList.toggle("-adjacent-pressed", pressed);
336
- } else if (i === index + 1) {
337
- button.style.setProperty("--_adjacent-button-width", `${clientWidth}px`);
338
- button.classList.toggle("-adjacent-pressed", pressed);
339
- } else {
340
- button.style.removeProperty("--_adjacent-button-width");
341
- button.classList.remove("-adjacent-pressed");
342
- }
343
- }
344
- }
345
- }
346
- },
347
- });
348
- }
349
-
350
- /**
351
- * The appearance variant of the button.
352
- * @default "standard"
353
- */
354
- @property({ reflect: true }) variant: IconButtonVariant = "standard";
355
-
356
- /**
357
- * The shape of the button.
358
- * @default "rounded"
359
- */
360
- @property({ reflect: true }) shape: IconButtonShape = "rounded";
361
-
362
- /**
363
- * The size of the button.
364
- * @default "small"
365
- */
366
- @property({ reflect: true }) size: IconButtonSize = "small";
367
-
368
- /**
369
- * The width of the button.
370
- * @default "default"
371
- */
372
- @property({ reflect: true }) width: IconButtonWidth = "default";
373
-
374
- /**
375
- * Whether the button will toggle between selected and unselected states.
376
- * @default false
377
- */
378
- @property({ type: Boolean, reflect: true }) toggle = false;
379
-
380
- /**
381
- * Whether the toggle button is selected.
382
- * @default false
383
- */
384
- @property({ type: Boolean, reflect: true }) selected = false;
385
-
386
- /** Whether the button is contained by a button group. */
387
- get grouped() {
388
- return this.classList.contains("-grouped");
389
- }
390
-
391
- /** @inheritdoc */
392
- override render(): unknown {
393
- return html`<div class="base">
394
- <m3e-state-layer class="state-layer" ?disabled="${this.disabled || this.disabledInteractive}"></m3e-state-layer>
395
- <m3e-elevation class="elevation" ?disabled="${this.disabled || this.disabledInteractive}"></m3e-elevation>
396
- <m3e-focus-ring class="focus-ring" ?disabled="${this.disabled}"></m3e-focus-ring>
397
- <m3e-ripple class="ripple" centered ?disabled="${this.disabled || this.disabledInteractive}"></m3e-ripple>
398
- <div class="touch" aria-hidden="true"></div>
399
- ${this[renderPseudoLink]()}
400
- <div class="wrapper">
401
- ${this.toggle
402
- ? html`<slot
403
- class="icon"
404
- name="selected"
405
- aria-hidden="true"
406
- @slotchange="${this.#handleSelectedIconSlotChange}"
407
- ></slot>`
408
- : nothing}
409
- <slot class="icon" aria-hidden="true"></slot>
410
- </div>
411
- </div>`;
412
- }
413
-
414
- /** @inheritdoc */
415
- override connectedCallback(): void {
416
- super.connectedCallback();
417
-
418
- this.addEventListener("click", this.#clickHandler);
419
- }
420
-
421
- /** @inheritdoc */
422
- override disconnectedCallback(): void {
423
- super.disconnectedCallback();
424
-
425
- ["-pressed", "-resting", "-grouped", "-connected"].forEach((x) => this.classList.remove(x));
426
- this._base?.style.removeProperty("--_button-shape");
427
- this.style.removeProperty("--_button-width");
428
- this.style.removeProperty("--_adjacent-button-width");
429
- this.classList.remove("-adjacent-pressed");
430
-
431
- this.removeEventListener("click", this.#clickHandler);
432
- }
433
-
434
- /** @inheritdoc */
435
- protected override firstUpdated(_changedProperties: PropertyValues<this>): void {
436
- super.firstUpdated(_changedProperties);
437
- [this._elevation, this._focusRing, this._stateLayer, this._ripple].forEach((x) => x?.attach(this));
438
- }
439
-
440
- /** @inheritdoc */
441
- protected override updated(_changedProperties: PropertyValues<this>): void {
442
- super.updated(_changedProperties);
443
-
444
- if (
445
- (_changedProperties.has("disabled") && this.disabled) ||
446
- (_changedProperties.has("disabledInteractive") && this.disabledInteractive)
447
- ) {
448
- this.classList.toggle("-pressed", false);
449
- this.classList.toggle("-resting", false);
450
- }
451
-
452
- if (_changedProperties.has("toggle") || _changedProperties.has("selected")) {
453
- this.ariaPressed = this.toggle ? `${this.selected}` : null;
454
- if (this.toggle) {
455
- for (const icon of this.querySelectorAll("m3e-icon")) {
456
- icon.toggleAttribute("filled", this.selected);
457
- }
458
- }
459
- }
460
- }
461
-
462
- /** @private */
463
- @debounce(40)
464
- private _handleResize(): void {
465
- if (this.grouped && !this.classList.contains("-pressed")) {
466
- this.style.setProperty("--_button-width", `${this.clientWidth}px`);
467
- this.#updateButtonShape(true);
468
- }
469
- }
470
-
471
- /** @private */
472
- #updateButtonShape(force = false): void {
473
- if (!this._base) return;
474
- const shape = parseFloat(getComputedStyle(this._base).borderRadius);
475
- if (!isNaN(shape) || force) {
476
- const adjustedShape = this.clientHeight / 2;
477
- if (adjustedShape < shape || force) {
478
- this._base?.style.setProperty("--_button-shape", `${adjustedShape}px`);
479
- }
480
- }
481
- }
482
-
483
- /** @private */
484
- #handleClick(e: Event): void {
485
- if (this.disabled || this.disabledInteractive) {
486
- e.preventDefault();
487
- e.stopImmediatePropagation();
488
- }
489
-
490
- if (this.toggle && !e.defaultPrevented) {
491
- this.selected = !this.selected;
492
-
493
- // Dispatch an input event and if not prevented, dispatch a change event.
494
- // Otherwise, reset the selected state.
495
-
496
- if (this.dispatchEvent(new Event("input", { bubbles: true, composed: true, cancelable: true }))) {
497
- this.dispatchEvent(new Event("change", { bubbles: true }));
498
- } else {
499
- this.selected = !this.selected;
500
- }
501
- }
502
- }
503
-
504
- /** @private */
505
- #handleSelectedIconSlotChange(e: Event): void {
506
- this._base?.classList.toggle("with-selected-icon", hasAssignedNodes(<HTMLSlotElement>e.target));
507
- }
508
- }
509
-
510
- declare global {
511
- interface HTMLElementTagNameMap {
512
- "m3e-icon-button": M3eIconButtonElement;
513
- }
514
- }
@@ -1,2 +0,0 @@
1
- /** Specifies the possible shape variants of an icon button. */
2
- export type IconButtonShape = "rounded" | "square";
@@ -1,2 +0,0 @@
1
- /** Specifies the possible sizes of an icon button. */
2
- export type IconButtonSize = "extra-small" | "small" | "medium" | "large" | "extra-large";
@@ -1,2 +0,0 @@
1
- /** Specifies the possible appearance variants of an icon button. */
2
- export type IconButtonVariant = "filled" | "tonal" | "outlined" | "standard";
@@ -1,2 +0,0 @@
1
- /** Specifies the possible width variants of an icon button. */
2
- export type IconButtonWidth = "default" | "narrow" | "wide";
package/src/index.ts DELETED
@@ -1,5 +0,0 @@
1
- export * from "./IconButtonElement";
2
- export * from "./IconButtonShape";
3
- export * from "./IconButtonSize";
4
- export * from "./IconButtonVariant";
5
- export * from "./IconButtonWidth";
@@ -1,95 +0,0 @@
1
- import { css, CSSResult, CSSResultGroup, unsafeCSS } from "lit";
2
-
3
- import { IconButtonSize } from "../IconButtonSize";
4
- import { IconButtonSizeToken } from "./IconButtonSizeToken";
5
-
6
- /** @private */
7
- function iconButtonStyle(size: IconButtonSize): CSSResult {
8
- return css`
9
- :host([size="${unsafeCSS(size)}"]) .base {
10
- height: ${IconButtonSizeToken[size].containerHeight};
11
- }
12
- :host([size="${unsafeCSS(size)}"][width="default"]) .wrapper {
13
- padding-inline-start: ${IconButtonSizeToken[size].defaultLeadingSpace};
14
- padding-inline-end: ${IconButtonSizeToken[size].defaultTrailingSpace};
15
- }
16
- :host([size="${unsafeCSS(size)}"][width="narrow"]) .wrapper {
17
- padding-inline-start: ${IconButtonSizeToken[size].narrowLeadingSpace};
18
- padding-inline-end: ${IconButtonSizeToken[size].narrowTrailingSpace};
19
- }
20
- :host([size="${unsafeCSS(size)}"][width="wide"]) .wrapper {
21
- padding-inline-start: ${IconButtonSizeToken[size].wideLeadingSpace};
22
- padding-inline-end: ${IconButtonSizeToken[size].wideTrailingSpace};
23
- }
24
- :host([size="${unsafeCSS(size)}"]) .icon {
25
- font-size: ${IconButtonSizeToken[size].iconSize};
26
- }
27
- :host([size="${unsafeCSS(size)}"]) .base {
28
- outline-offset: calc(0px - ${IconButtonSizeToken[size].outlineThickness});
29
- outline-width: ${IconButtonSizeToken[size].outlineThickness};
30
- }
31
- :host(:not(.-connected)[size="${unsafeCSS(size)}"][shape="rounded"]:not(.-pressed)) .base {
32
- border-radius: var(--_button-shape, ${IconButtonSizeToken[size].shapeRound});
33
- }
34
- :host(:not(.-connected)[size="${unsafeCSS(size)}"][shape="square"]) .base {
35
- border-radius: ${IconButtonSizeToken[size].shapeSquare};
36
- }
37
- :host(:not(.-connected)[size="${unsafeCSS(size)}"][shape="rounded"][toggle][selected]:not(.-pressed)) .base {
38
- border-radius: ${IconButtonSizeToken[size].selectedShapeRound};
39
- }
40
- :host(:not(.-connected)[size="${unsafeCSS(size)}"][shape="square"][toggle][selected]:not(.-pressed)) .base {
41
- border-radius: var(--_button-shape, ${IconButtonSizeToken[size].selectedShapeSquare});
42
- }
43
- :host(:not(.-connected)[size="${unsafeCSS(size)}"].-pressed) .base {
44
- border-radius: ${IconButtonSizeToken[size].shapePressedMorph};
45
- }
46
- :host(.-connected[size="${unsafeCSS(size)}"][shape="rounded"]) .base {
47
- border-start-start-radius: var(
48
- --_button-rounded-start-shape,
49
- var(--_button-shape, ${IconButtonSizeToken[size].shapeRound})
50
- );
51
- border-end-start-radius: var(
52
- --_button-rounded-start-shape,
53
- var(--_button-shape, ${IconButtonSizeToken[size].shapeRound})
54
- );
55
- border-start-end-radius: var(
56
- --_button-rounded-end-shape,
57
- var(--_button-shape, ${IconButtonSizeToken[size].shapeRound})
58
- );
59
- border-end-end-radius: var(
60
- --_button-rounded-end-shape,
61
- var(--_button-shape, ${IconButtonSizeToken[size].shapeRound})
62
- );
63
- }
64
- :host(.-connected[size="${unsafeCSS(size)}"][shape="square"]) .base {
65
- border-start-start-radius: var(--_button-square-start-shape, ${IconButtonSizeToken[size].shapeSquare});
66
- border-end-start-radius: var(--_button-square-start-shape, ${IconButtonSizeToken[size].shapeSquare});
67
- border-start-end-radius: var(--_button-square-end-shape, ${IconButtonSizeToken[size].shapeSquare});
68
- border-end-end-radius: var(--_button-square-end-shape, ${IconButtonSizeToken[size].shapeSquare});
69
- }
70
- :host(.-connected[size="${unsafeCSS(size)}"][shape="square"][toggle][selected]:not(.-pressed)) .base {
71
- border-radius: var(--_button-shape, ${IconButtonSizeToken[size].selectedShapeSquare});
72
- }
73
- :host(.-connected[size="${unsafeCSS(size)}"].-pressed) .base {
74
- border-start-start-radius: var(
75
- --_button-start-shape-pressed-morph,
76
- ${IconButtonSizeToken[size].shapePressedMorph}
77
- );
78
- border-end-start-radius: var(--_button-start-shape-pressed-morph, ${IconButtonSizeToken[size].shapePressedMorph});
79
- border-start-end-radius: var(--_button-end-shape-pressed-morph, ${IconButtonSizeToken[size].shapePressedMorph});
80
- border-end-end-radius: var(--_button-end-shape-pressed-morph, ${IconButtonSizeToken[size].shapePressedMorph});
81
- }
82
- `;
83
- }
84
-
85
- /**
86
- * Size variant styles for `M3eIconButtonElement`.
87
- * @internal
88
- */
89
- export const IconButtonSizeStyle: CSSResultGroup = [
90
- iconButtonStyle("extra-small"),
91
- iconButtonStyle("small"),
92
- iconButtonStyle("medium"),
93
- iconButtonStyle("large"),
94
- iconButtonStyle("extra-large"),
95
- ];