@m3e/chips 1.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +539 -0
- package/cem.config.mjs +16 -0
- package/demo/index.html +183 -0
- package/dist/css-custom-data.json +777 -0
- package/dist/custom-elements.json +3307 -0
- package/dist/html-custom-data.json +277 -0
- package/dist/index.js +1516 -0
- package/dist/index.js.map +1 -0
- package/dist/index.min.js +480 -0
- package/dist/index.min.js.map +1 -0
- package/dist/src/AssistChipElement.d.ts +82 -0
- package/dist/src/AssistChipElement.d.ts.map +1 -0
- package/dist/src/ChipElement.d.ts +86 -0
- package/dist/src/ChipElement.d.ts.map +1 -0
- package/dist/src/ChipSetElement.d.ts +43 -0
- package/dist/src/ChipSetElement.d.ts.map +1 -0
- package/dist/src/ChipVariant.d.ts +3 -0
- package/dist/src/ChipVariant.d.ts.map +1 -0
- package/dist/src/FilterChipElement.d.ts +93 -0
- package/dist/src/FilterChipElement.d.ts.map +1 -0
- package/dist/src/FilterChipSetElement.d.ts +78 -0
- package/dist/src/FilterChipSetElement.d.ts.map +1 -0
- package/dist/src/InputChipElement.d.ts +104 -0
- package/dist/src/InputChipElement.d.ts.map +1 -0
- package/dist/src/InputChipSetElement.d.ts +75 -0
- package/dist/src/InputChipSetElement.d.ts.map +1 -0
- package/dist/src/SuggestionChipElement.d.ts +83 -0
- package/dist/src/SuggestionChipElement.d.ts.map +1 -0
- package/dist/src/index.d.ts +10 -0
- package/dist/src/index.d.ts.map +1 -0
- package/eslint.config.mjs +13 -0
- package/package.json +55 -0
- package/rollup.config.js +32 -0
- package/src/AssistChipElement.ts +103 -0
- package/src/ChipElement.ts +336 -0
- package/src/ChipSetElement.ts +60 -0
- package/src/ChipVariant.ts +2 -0
- package/src/FilterChipElement.ts +254 -0
- package/src/FilterChipSetElement.ts +161 -0
- package/src/InputChipElement.ts +287 -0
- package/src/InputChipSetElement.ts +360 -0
- package/src/SuggestionChipElement.ts +104 -0
- package/src/index.ts +9 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { css, CSSResultGroup, html, PropertyValues } from "lit";
|
|
2
|
+
import { customElement } from "lit/decorators.js";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
AttachInternals,
|
|
6
|
+
DesignToken,
|
|
7
|
+
Disabled,
|
|
8
|
+
DisabledInteractive,
|
|
9
|
+
Focusable,
|
|
10
|
+
KeyboardClick,
|
|
11
|
+
Role,
|
|
12
|
+
Selected,
|
|
13
|
+
} from "@m3e/core";
|
|
14
|
+
|
|
15
|
+
import { selectionManager } from "@m3e/core/a11y";
|
|
16
|
+
|
|
17
|
+
import { M3eChipElement } from "./ChipElement";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @summary
|
|
21
|
+
* A chip users interact with to select/deselect options.
|
|
22
|
+
*
|
|
23
|
+
* @description
|
|
24
|
+
* The `m3e-filter-chip` component presents a chip that users can select or deselect to filter
|
|
25
|
+
* content or data sets. It supports single and multi-selection, keyboard interaction, accessibility,
|
|
26
|
+
* and expressive state styling, providing a modern and interactive filtering experience in line
|
|
27
|
+
* with Material 3 guidelines. Appearance variants include `elevated` and `outlined`, enabling visual
|
|
28
|
+
* differentiation and contextual emphasis.
|
|
29
|
+
*
|
|
30
|
+
* @tag m3e-filter-chip
|
|
31
|
+
*
|
|
32
|
+
* @slot - Renders the label of the chip.
|
|
33
|
+
* @slot icon - Renders an icon before the chip's label.
|
|
34
|
+
* @slot trailing-icon - Renders an icon after the chip's label.
|
|
35
|
+
*
|
|
36
|
+
* @attr disabled - A value indicating whether the element is disabled.
|
|
37
|
+
* @attr disabled-interactive - A value indicating whether the element is disabled and interactive.
|
|
38
|
+
* @attr selected - A value indicating whether the element is selected.
|
|
39
|
+
* @attr value - A string representing the value of the chip.
|
|
40
|
+
* @attr variant - The appearance variant of the chip.
|
|
41
|
+
*
|
|
42
|
+
* @fires input - Emitted when the selected state changes.
|
|
43
|
+
* @fires change - Emitted when the selected state changes.
|
|
44
|
+
*
|
|
45
|
+
* @cssprop --m3e-chip-container-shape - Border radius of the chip container.
|
|
46
|
+
* @cssprop --m3e-chip-container-height - Base height of the chip container before density adjustment.
|
|
47
|
+
* @cssprop --m3e-chip-label-text-font-size - Font size of the chip label text.
|
|
48
|
+
* @cssprop --m3e-chip-label-text-font-weight - Font weight of the chip label text.
|
|
49
|
+
* @cssprop --m3e-chip-label-text-line-height - Line height of the chip label text.
|
|
50
|
+
* @cssprop --m3e-chip-label-text-tracking - Letter spacing of the chip label text.
|
|
51
|
+
* @cssprop --m3e-chip-icon-size - Font size of leading/trailing icons.
|
|
52
|
+
* @cssprop --m3e-chip-spacing - Horizontal gap between chip content elements.
|
|
53
|
+
* @cssprop --m3e-chip-padding-start - Default start padding when no icon is present.
|
|
54
|
+
* @cssprop --m3e-chip-padding-end - Default end padding when no trailing icon is present.
|
|
55
|
+
* @cssprop --m3e-chip-with-icon-padding-start - Start padding when leading icon is present.
|
|
56
|
+
* @cssprop --m3e-chip-with-icon-padding-end - End padding when trailing icon is present.
|
|
57
|
+
* @cssprop --m3e-chip-disabled-label-text-color - Base color for disabled label text.
|
|
58
|
+
* @cssprop --m3e-chip-disabled-label-text-opacity - Opacity applied to disabled label text.
|
|
59
|
+
* @cssprop --m3e-chip-disabled-icon-color - Base color for disabled icons.
|
|
60
|
+
* @cssprop --m3e-chip-disabled-icon-opacity - Opacity applied to disabled icons.
|
|
61
|
+
* @cssprop --m3e-elevated-chip-container-color - Background color for elevated variant.
|
|
62
|
+
* @cssprop --m3e-elevated-chip-elevation - Elevation level for elevated variant.
|
|
63
|
+
* @cssprop --m3e-elevated-chip-hover-elevation - Elevation level on hover.
|
|
64
|
+
* @cssprop --m3e-elevated-chip-disabled-container-color - Background color for disabled elevated variant.
|
|
65
|
+
* @cssprop --m3e-elevated-chip-disabled-container-opacity - Opacity applied to disabled elevated background.
|
|
66
|
+
* @cssprop --m3e-elevated-chip-disabled-elevation - Elevation level for disabled elevated variant.
|
|
67
|
+
* @cssprop --m3e-outlined-chip-outline-thickness - Outline thickness for outlined variant.
|
|
68
|
+
* @cssprop --m3e-outlined-chip-outline-color - Outline color for outlined variant.
|
|
69
|
+
* @cssprop --m3e-outlined-chip-disabled-outline-color - Outline color for disabled outlined variant.
|
|
70
|
+
* @cssprop --m3e-outlined-chip-disabled-outline-opacity - Opacity applied to disabled outline.
|
|
71
|
+
* @cssprop --m3e-chip-selected-outline-thickness - Outline thickness for selected state.
|
|
72
|
+
* @cssprop --m3e-chip-selected-label-text-color - Text color in selected state.
|
|
73
|
+
* @cssprop --m3e-chip-selected-container-color - Background color in selected state.
|
|
74
|
+
* @cssprop --m3e-chip-selected-container-hover-color - Hover state layer color in selected state.
|
|
75
|
+
* @cssprop --m3e-chip-selected-container-focus-color - Focus state layer color in selected state.
|
|
76
|
+
* @cssprop --m3e-chip-selected-hover-elevation - Elevation on hover in selected state.
|
|
77
|
+
* @cssprop --m3e-chip-selected-ripple-color - Ripple color in selected state.
|
|
78
|
+
* @cssprop --m3e-chip-selected-state-layer-focus-color - Focus state layer color in selected state.
|
|
79
|
+
* @cssprop --m3e-chip-selected-state-layer-hover-color - Hover state layer color in selected state.
|
|
80
|
+
* @cssprop --m3e-chip-selected-leading-icon-color - Leading icon color in selected state.
|
|
81
|
+
* @cssprop --m3e-chip-selected-trailing-icon-color - Trailing icon color in selected state.
|
|
82
|
+
* @cssprop --m3e-chip-unselected-label-text-color - Text color in unselected state.
|
|
83
|
+
* @cssprop --m3e-chip-unselected-ripple-color - Ripple color in unselected state.
|
|
84
|
+
* @cssprop --m3e-chip-unselected-state-layer-focus-color - Focus state layer color in unselected state.
|
|
85
|
+
* @cssprop --m3e-chip-unselected-state-layer-hover-color - Hover state layer color in unselected state.
|
|
86
|
+
* @cssprop --m3e-chip-unselected-leading-icon-color - Leading icon color in unselected state.
|
|
87
|
+
* @cssprop --m3e-chip-unselected-trailing-icon-color - Trailing icon color in unselected state.
|
|
88
|
+
*/
|
|
89
|
+
@customElement("m3e-filter-chip")
|
|
90
|
+
export class M3eFilterChipElement extends Selected(
|
|
91
|
+
KeyboardClick(Focusable(DisabledInteractive(Disabled(AttachInternals(Role(M3eChipElement, "option"), true)))))
|
|
92
|
+
) {
|
|
93
|
+
/** The styles of the element. */
|
|
94
|
+
static override styles: CSSResultGroup = [
|
|
95
|
+
M3eChipElement.styles,
|
|
96
|
+
css`
|
|
97
|
+
:host([selected]:not(.-hide-selection)) .wrapper {
|
|
98
|
+
padding-inline-start: var(--m3e-chip-with-icon-padding-start, 0.5rem);
|
|
99
|
+
}
|
|
100
|
+
.icon {
|
|
101
|
+
display: flex;
|
|
102
|
+
align-items: center;
|
|
103
|
+
justify-content: center;
|
|
104
|
+
}
|
|
105
|
+
.check {
|
|
106
|
+
width: 1em;
|
|
107
|
+
font-size: var(--m3e-chip-icon-size, 1.125rem);
|
|
108
|
+
}
|
|
109
|
+
:host(:not(:disabled):not([disabled-interactive])) .check {
|
|
110
|
+
color: var(--m3e-chip-selected-leading-icon-color, ${DesignToken.color.onSecondaryContainer});
|
|
111
|
+
}
|
|
112
|
+
:host(:not([selected])) .check,
|
|
113
|
+
:host(.-hide-selection) .check,
|
|
114
|
+
:host(.-hide-selection:not(.-with-icon)) .icon {
|
|
115
|
+
display: none;
|
|
116
|
+
}
|
|
117
|
+
:host(:not(.-with-icon)) .icon {
|
|
118
|
+
margin-inline-start: calc(0px - var(--m3e-chip-with-icon-padding-start, 0.5rem));
|
|
119
|
+
transition: margin-inline-start ${DesignToken.motion.spring.fastEffects};
|
|
120
|
+
}
|
|
121
|
+
:host([selected]) .icon {
|
|
122
|
+
margin-inline-start: 0;
|
|
123
|
+
}
|
|
124
|
+
:host([selected]:not(.-hide-selection)) ::slotted([slot="icon"]) {
|
|
125
|
+
display: none !important;
|
|
126
|
+
}
|
|
127
|
+
:host(:not(:disabled):not([disabled-interactive]):not([selected])) .base {
|
|
128
|
+
color: var(--m3e-chip-unselected-label-text-color, ${DesignToken.color.onSurfaceVariant});
|
|
129
|
+
--m3e-ripple-color: var(--m3e-chip-unselected-ripple-color, ${DesignToken.color.onSurfaceVariant});
|
|
130
|
+
--m3e-state-layer-focus-color: var(
|
|
131
|
+
--m3e-chip-unselected-state-layer-focus-color,
|
|
132
|
+
${DesignToken.color.onSurfaceVariant}
|
|
133
|
+
);
|
|
134
|
+
--m3e-state-layer-hover-color: var(
|
|
135
|
+
--m3e-chip-unselected-state-layer-hover-color,
|
|
136
|
+
${DesignToken.color.onSurfaceVariant}
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
:host(:not(:disabled):not([disabled-interactive]):not([selected])) ::slotted([slot="icon"]) {
|
|
140
|
+
color: var(--m3e-chip-unselected-leading-icon-color, ${DesignToken.color.primary});
|
|
141
|
+
}
|
|
142
|
+
:host(:not(:disabled):not([disabled-interactive]):not([selected])) ::slotted([slot="trailing-icon"]) {
|
|
143
|
+
color: var(--m3e-chip-unselected-trailing-icon-color, ${DesignToken.color.onSurfaceVariant});
|
|
144
|
+
}
|
|
145
|
+
:host(:not(:disabled):not([disabled-interactive])[selected]) .base {
|
|
146
|
+
outline-offset: unset;
|
|
147
|
+
outline-width: var(--m3e-chip-selected-outline-thickness, 0);
|
|
148
|
+
color: var(--m3e-chip-selected-label-text-color, ${DesignToken.color.onSecondaryContainer});
|
|
149
|
+
background-color: var(--m3e-chip-selected-container-color, ${DesignToken.color.secondaryContainer});
|
|
150
|
+
--m3e-state-layer-hover-color: var(
|
|
151
|
+
--m3e-chip-selected-container-hover-color,
|
|
152
|
+
${DesignToken.color.onSecondaryContainer}
|
|
153
|
+
);
|
|
154
|
+
--m3e-state-layer-focus-color: var(
|
|
155
|
+
--m3e-chip-selected-container-focus-color,
|
|
156
|
+
${DesignToken.color.onSecondaryContainer}
|
|
157
|
+
);
|
|
158
|
+
--m3e-elevation-hover-level: var(--m3e-chip-selected-hover-elevation, ${DesignToken.elevation.level1});
|
|
159
|
+
--m3e-ripple-color: var(--m3e-chip-selected-ripple-color, ${DesignToken.color.onSecondaryContainer});
|
|
160
|
+
--m3e-state-layer-focus-color: var(
|
|
161
|
+
--m3e-chip-selected-state-layer-focus-color,
|
|
162
|
+
${DesignToken.color.onSecondaryContainer}
|
|
163
|
+
);
|
|
164
|
+
--m3e-state-layer-hover-color: var(
|
|
165
|
+
--m3e-chip-selected-state-layer-hover-color,
|
|
166
|
+
${DesignToken.color.onSecondaryContainer}
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
:host(:not(:disabled):not([disabled-interactive])[selected]) ::slotted([slot="icon"]) {
|
|
170
|
+
color: var(--m3e-chip-selected-leading-icon-color, ${DesignToken.color.onSecondaryContainer});
|
|
171
|
+
}
|
|
172
|
+
:host(:not(:disabled):not([disabled-interactive]):not([selected])) ::slotted([slot="trailing-icon"]) {
|
|
173
|
+
color: var(--m3e-chip-selected-trailing-icon-color, ${DesignToken.color.onSecondaryContainer});
|
|
174
|
+
}
|
|
175
|
+
@media (prefers-reduced-motion) {
|
|
176
|
+
.base,
|
|
177
|
+
:host(:not(.-with-icon)) .icon {
|
|
178
|
+
transition: none;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
@media (forced-colors: active) {
|
|
182
|
+
:host(:not(:disabled):not([disabled-interactive]):not([selected])) .base,
|
|
183
|
+
:host(:not(:disabled):not([disabled-interactive]):not([selected])) ::slotted([slot="icon"]),
|
|
184
|
+
:host(:not(:disabled):not([disabled-interactive]):not([selected])) ::slotted([slot="trailing-icon"]) {
|
|
185
|
+
color: CanvasText;
|
|
186
|
+
}
|
|
187
|
+
:host(:not(:disabled):not([disabled-interactive])[selected]) .base,
|
|
188
|
+
:host(:not(:disabled):not([disabled-interactive])[selected]) ::slotted([slot="icon"]),
|
|
189
|
+
:host(:not(:disabled):not([disabled-interactive])[selected]) ::slotted([slot="trailing-icon"]),
|
|
190
|
+
:host(:not(:disabled):not([disabled-interactive])) .check {
|
|
191
|
+
color: ButtonText;
|
|
192
|
+
}
|
|
193
|
+
:host(:not(:disabled):not([disabled-interactive])[selected]) .base {
|
|
194
|
+
outline-offset: calc(0px - var(--m3e-outlined-chip-outline-thickness, 1px));
|
|
195
|
+
outline-width: var(--m3e-outlined-chip-outline-thickness, 1px);
|
|
196
|
+
outline-color: ButtonText;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
`,
|
|
200
|
+
];
|
|
201
|
+
|
|
202
|
+
/** @private */ readonly #clickHandler = (e: Event) => this.#handleClick(e);
|
|
203
|
+
|
|
204
|
+
/** @inheritdoc */
|
|
205
|
+
override connectedCallback(): void {
|
|
206
|
+
super.connectedCallback();
|
|
207
|
+
this.addEventListener("click", this.#clickHandler);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** @inheritdoc */
|
|
211
|
+
override disconnectedCallback(): void {
|
|
212
|
+
super.disconnectedCallback();
|
|
213
|
+
this.removeEventListener("click", this.#clickHandler);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** @inheritdoc */
|
|
217
|
+
protected override update(changedProperties: PropertyValues<this>): void {
|
|
218
|
+
super.update(changedProperties);
|
|
219
|
+
|
|
220
|
+
if (changedProperties.has("selected")) {
|
|
221
|
+
this.closest("m3e-filter-chip-set")?.[selectionManager].notifySelectionChange(this);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** @inheritdoc @private */
|
|
226
|
+
protected override _renderIcon(): unknown {
|
|
227
|
+
return html`<div class="icon" aria-hidden="true">
|
|
228
|
+
<svg class="check" viewBox="0 -960 960 960" aria-hidden="true">
|
|
229
|
+
<path fill="currentColor" d="M382-240 154-468l57-57 171 171 367-367 57 57-424 424Z" />
|
|
230
|
+
</svg>
|
|
231
|
+
${super._renderIcon()}
|
|
232
|
+
</div>`;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** @private */
|
|
236
|
+
#handleClick(e: Event): void {
|
|
237
|
+
if (e.defaultPrevented) return;
|
|
238
|
+
|
|
239
|
+
const selected = this.selected;
|
|
240
|
+
this.selected = !this.selected;
|
|
241
|
+
if (this.dispatchEvent(new Event("input", { bubbles: true, composed: true, cancelable: true }))) {
|
|
242
|
+
this.closest("m3e-filter-chip-set")?.[selectionManager].notifySelectionChange(this);
|
|
243
|
+
this.dispatchEvent(new Event("change", { bubbles: true }));
|
|
244
|
+
} else {
|
|
245
|
+
this.selected = selected;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
declare global {
|
|
251
|
+
interface HTMLElementTagNameMap {
|
|
252
|
+
"m3e-filter-chip": M3eFilterChipElement;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { html, PropertyValues } from "lit";
|
|
2
|
+
import { customElement, property } from "lit/decorators.js";
|
|
3
|
+
|
|
4
|
+
import { AttachInternals, Labelled, Dirty, Disabled, FormAssociated, formValue, Touched, Role } from "@m3e/core";
|
|
5
|
+
import { SelectionManager, selectionManager } from "@m3e/core/a11y";
|
|
6
|
+
|
|
7
|
+
import { M3eChipSetElement } from "./ChipSetElement";
|
|
8
|
+
import { M3eFilterChipElement } from "./FilterChipElement";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @summary
|
|
12
|
+
* A container that organizes filter chips into a cohesive group, enabling selection and
|
|
13
|
+
* deselection of values used to refine content or trigger contextual behavior.
|
|
14
|
+
*
|
|
15
|
+
* @description
|
|
16
|
+
* The `m3e-filter-chip-set` component presents a group of filter chips, enabling users to select
|
|
17
|
+
* one or more options to filter content or data sets. It supports single and multi-selection,
|
|
18
|
+
* keyboard navigation, accessibility, and seamless form association, providing expressive and
|
|
19
|
+
* interactive filtering experiences in line with Material 3 guidelines.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* The following example illustrates a single-select `m3e-filter-chip-set` containing multiple `m3e-filter-chip` components that
|
|
23
|
+
* allow a user to choose an option. You can use the `multi` attribute to enable multiselect.
|
|
24
|
+
* ```html
|
|
25
|
+
* <m3e-filter-chip-set aria-label="Filter by topic">
|
|
26
|
+
* <m3e-filter-chip><m3e-icon slot="icon" name="palette"></m3e-icon>Design</m3e-filter-chip>
|
|
27
|
+
* <m3e-filter-chip><m3e-icon slot="icon" name="accessibility_new"></m3e-icon>Accessibility</m3e-filter-chip>
|
|
28
|
+
* <m3e-filter-chip><m3e-icon slot="icon" name="motion_photos_on"></m3e-icon>Motion</m3e-filter-chip>
|
|
29
|
+
* <m3e-filter-chip><m3e-icon slot="icon" name="description"></m3e-icon>Documentation</m3e-filter-chip>
|
|
30
|
+
* </m3e-filter-chip-set>
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @tag m3e-filter-chip-set
|
|
34
|
+
*
|
|
35
|
+
* @slot - Renders the chips of the set.
|
|
36
|
+
*
|
|
37
|
+
* @attr disabled - Whether the element is disabled.
|
|
38
|
+
* @attr hide-selection-indicator - Whether to hide the selection indicator.
|
|
39
|
+
* @attr multi - Whether multiple chips can be selected.
|
|
40
|
+
* @attr name - The name that identifies the element when submitting the associated form.
|
|
41
|
+
* @attr vertical - Whether the element is oriented vertically.
|
|
42
|
+
*
|
|
43
|
+
* @fires input - Emitted when the selected state of a chip changes.
|
|
44
|
+
* @fires change - Emitted when the selected state of a chip changes.
|
|
45
|
+
*
|
|
46
|
+
* @cssprop --m3e-chip-set-spacing - The spacing (gap) between chips in the set.
|
|
47
|
+
*/
|
|
48
|
+
@customElement("m3e-filter-chip-set")
|
|
49
|
+
export class M3eFilterChipSetElement extends Labelled(
|
|
50
|
+
Dirty(Touched(FormAssociated(Disabled(AttachInternals(Role(M3eChipSetElement, "listbox"))))))
|
|
51
|
+
) {
|
|
52
|
+
/** @internal */
|
|
53
|
+
readonly [selectionManager] = new SelectionManager<M3eFilterChipElement>()
|
|
54
|
+
.onActiveItemChange(() => this[selectionManager].activeItem?.focus())
|
|
55
|
+
.withWrap();
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Whether multiple chips can be selected.
|
|
59
|
+
* @default false
|
|
60
|
+
*/
|
|
61
|
+
@property({ type: Boolean }) multi = false;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Whether to hide the selection indicator.
|
|
65
|
+
* @default false
|
|
66
|
+
*/
|
|
67
|
+
@property({ attribute: "hide-selection-indicator", type: Boolean }) hideSelectionIndicator = false;
|
|
68
|
+
|
|
69
|
+
/** The chips of the set. */
|
|
70
|
+
get chips(): readonly M3eFilterChipElement[] {
|
|
71
|
+
return this[selectionManager]?.items ?? [];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** The selected chip(s) of the set. */
|
|
75
|
+
get selected(): readonly M3eFilterChipElement[] {
|
|
76
|
+
return this[selectionManager]?.selectedItems ?? [];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** The selected value(s) of the set. */
|
|
80
|
+
get value(): string | readonly string[] | null {
|
|
81
|
+
const values = this.selected.map((x) => x.value);
|
|
82
|
+
switch (values.length) {
|
|
83
|
+
case 0:
|
|
84
|
+
return null;
|
|
85
|
+
case 1:
|
|
86
|
+
return values[0];
|
|
87
|
+
default:
|
|
88
|
+
return values;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** @inheritdoc @internal */
|
|
93
|
+
override get [formValue]() {
|
|
94
|
+
const values = this.value;
|
|
95
|
+
if (Array.isArray(values)) {
|
|
96
|
+
const data = new FormData();
|
|
97
|
+
for (const value of values) {
|
|
98
|
+
data.append(this.name, value);
|
|
99
|
+
}
|
|
100
|
+
return data;
|
|
101
|
+
}
|
|
102
|
+
return <string | null>values;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** @inheritdoc */
|
|
106
|
+
protected override update(changedProperties: PropertyValues<this>): void {
|
|
107
|
+
super.update(changedProperties);
|
|
108
|
+
|
|
109
|
+
if (changedProperties.has("vertical")) {
|
|
110
|
+
this[selectionManager].vertical = this.vertical;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (changedProperties.has("disabled") && (changedProperties.get("disabled") !== undefined || this.disabled)) {
|
|
114
|
+
this[selectionManager].disabled = this.disabled;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (changedProperties.has("multi")) {
|
|
118
|
+
this.ariaMultiSelectable = `${this.multi}`;
|
|
119
|
+
this[selectionManager].multi = this.multi;
|
|
120
|
+
this[selectionManager].disableRovingTabIndex(this.multi);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (changedProperties.has("hideSelectionIndicator")) {
|
|
124
|
+
this.chips.forEach((x) => x.classList.toggle("-hide-selection", this.hideSelectionIndicator));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** @inheritdoc */
|
|
129
|
+
protected override render(): unknown {
|
|
130
|
+
return html`<slot
|
|
131
|
+
@slotchange="${this.#handleSlotChange}"
|
|
132
|
+
@keydown="${this.#handleKeyDown}"
|
|
133
|
+
@change="${this.#handleChange}"
|
|
134
|
+
></slot>`;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** @internal */
|
|
138
|
+
#handleSlotChange() {
|
|
139
|
+
const { added } = this[selectionManager].setItems([...this.querySelectorAll("m3e-filter-chip")]);
|
|
140
|
+
added.forEach((x) => x.classList.toggle("-hide-selection", this.hideSelectionIndicator));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** @internal */
|
|
144
|
+
#handleKeyDown(e: KeyboardEvent): void {
|
|
145
|
+
if (!this.multi) {
|
|
146
|
+
this[selectionManager].onKeyDown(e);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** @internal */
|
|
151
|
+
#handleChange(e: Event): void {
|
|
152
|
+
e.stopPropagation();
|
|
153
|
+
this.dispatchEvent(new Event("change", { bubbles: true }));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
declare global {
|
|
158
|
+
interface HTMLElementTagNameMap {
|
|
159
|
+
"m3e-filter-chip-set": M3eFilterChipSetElement;
|
|
160
|
+
}
|
|
161
|
+
}
|