@m3e/chips 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.
- package/README.md +1 -2
- package/dist/custom-elements.json +4884 -608
- package/dist/html-custom-data.json +10 -10
- package/dist/index.js +69 -30
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +87 -76
- package/dist/index.min.js.map +1 -1
- package/dist/src/AssistChipElement.d.ts +2 -1
- package/dist/src/AssistChipElement.d.ts.map +1 -1
- package/dist/src/ChipElement.d.ts +1 -4
- package/dist/src/ChipElement.d.ts.map +1 -1
- package/dist/src/ChipSetElement.d.ts +1 -2
- package/dist/src/ChipSetElement.d.ts.map +1 -1
- package/dist/src/FilterChipElement.d.ts +13 -1
- package/dist/src/FilterChipElement.d.ts.map +1 -1
- package/dist/src/FilterChipSetElement.d.ts +0 -1
- package/dist/src/FilterChipSetElement.d.ts.map +1 -1
- package/dist/src/InputChipElement.d.ts +14 -1
- package/dist/src/InputChipElement.d.ts.map +1 -1
- package/dist/src/InputChipSetElement.d.ts +1 -2
- package/dist/src/InputChipSetElement.d.ts.map +1 -1
- package/dist/src/SuggestionChipElement.d.ts +2 -1
- package/dist/src/SuggestionChipElement.d.ts.map +1 -1
- package/package.json +5 -5
- package/cem.config.mjs +0 -16
- package/demo/index.html +0 -183
- package/eslint.config.mjs +0 -13
- package/rollup.config.js +0 -32
- package/src/AssistChipElement.ts +0 -103
- package/src/ChipElement.ts +0 -336
- package/src/ChipSetElement.ts +0 -60
- package/src/ChipVariant.ts +0 -2
- package/src/FilterChipElement.ts +0 -254
- package/src/FilterChipSetElement.ts +0 -161
- package/src/InputChipElement.ts +0 -287
- package/src/InputChipSetElement.ts +0 -360
- package/src/SuggestionChipElement.ts +0 -104
- package/src/index.ts +0 -9
- package/tsconfig.json +0 -9
package/src/ChipElement.ts
DELETED
|
@@ -1,336 +0,0 @@
|
|
|
1
|
-
import { css, CSSResultGroup, html, LitElement, nothing, PropertyValues, unsafeCSS } from "lit";
|
|
2
|
-
import { customElement, property, query } from "lit/decorators.js";
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
DesignToken,
|
|
6
|
-
getTextContent,
|
|
7
|
-
hasAssignedNodes,
|
|
8
|
-
isDisabledInteractiveMixin,
|
|
9
|
-
isDisabledMixin,
|
|
10
|
-
isLinkButtonMixin,
|
|
11
|
-
M3eElevationElement,
|
|
12
|
-
M3eFocusRingElement,
|
|
13
|
-
M3eRippleElement,
|
|
14
|
-
M3eStateLayerElement,
|
|
15
|
-
renderPseudoLink,
|
|
16
|
-
Role,
|
|
17
|
-
} from "@m3e/core";
|
|
18
|
-
|
|
19
|
-
import { ChipVariant } from "./ChipVariant";
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* @summary
|
|
23
|
-
* A non-interactive chip used to convey small pieces of information.
|
|
24
|
-
*
|
|
25
|
-
* @description
|
|
26
|
-
* The `m3e-chip` component establishes the foundational structure for chips. It supports expressive styling,
|
|
27
|
-
* accessible interaction, and flexible content projection, aligning with Material 3 guidelines. Appearance
|
|
28
|
-
* variants include `elevated` and `outlined`, enabling visual differentiation and contextual emphasis.
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* The following example illustrates use of the `m3e-chip` and `m3e-chip-set` components to present non-interactive chips.
|
|
32
|
-
* ```html
|
|
33
|
-
* <m3e-chip-set>
|
|
34
|
-
* <m3e-chip><m3e-icon slot="icon" name="palette"></m3e-icon>Design</m3e-chip>
|
|
35
|
-
* <m3e-chip><m3e-icon slot="icon" name="accessibility_new"></m3e-icon>Accessibility</m3e-chip>
|
|
36
|
-
* <m3e-chip><m3e-icon slot="icon" name="motion_photos_on"></m3e-icon>Motion</m3e-chip>
|
|
37
|
-
* <m3e-chip><m3e-icon slot="icon" name="description"></m3e-icon>Documentation</m3e-chip>
|
|
38
|
-
* </m3e-chip-set>
|
|
39
|
-
* ```
|
|
40
|
-
*
|
|
41
|
-
* @tag m3e-chip
|
|
42
|
-
*
|
|
43
|
-
* @slot - Renders the label of the chip.
|
|
44
|
-
* @slot icon - Renders an icon before the chip's label.
|
|
45
|
-
* @slot trailing-icon - Renders an icon after the chip's label.
|
|
46
|
-
*
|
|
47
|
-
* @attr value - A string representing the value of the chip.
|
|
48
|
-
* @attr variant - The appearance variant of the chip.
|
|
49
|
-
*
|
|
50
|
-
* @cssprop --m3e-chip-container-shape - Border radius of the chip container.
|
|
51
|
-
* @cssprop --m3e-chip-container-height - Base height of the chip container before density adjustment.
|
|
52
|
-
* @cssprop --m3e-chip-label-text-font-size - Font size of the chip label text.
|
|
53
|
-
* @cssprop --m3e-chip-label-text-font-weight - Font weight of the chip label text.
|
|
54
|
-
* @cssprop --m3e-chip-label-text-line-height - Line height of the chip label text.
|
|
55
|
-
* @cssprop --m3e-chip-label-text-tracking - Letter spacing of the chip label text.
|
|
56
|
-
* @cssprop --m3e-chip-label-text-color - Label text color in default state.
|
|
57
|
-
* @cssprop --m3e-chip-icon-color - Icon color in default state.
|
|
58
|
-
* @cssprop --m3e-chip-icon-size - Font size of leading/trailing icons.
|
|
59
|
-
* @cssprop --m3e-chip-spacing - Horizontal gap between chip content elements.
|
|
60
|
-
* @cssprop --m3e-chip-padding-start - Default start padding when no icon is present.
|
|
61
|
-
* @cssprop --m3e-chip-padding-end - Default end padding when no trailing icon is present.
|
|
62
|
-
* @cssprop --m3e-chip-with-icon-padding-start - Start padding when leading icon is present.
|
|
63
|
-
* @cssprop --m3e-chip-with-icon-padding-end - End padding when trailing icon is present.
|
|
64
|
-
* @cssprop --m3e-elevated-chip-container-color - Background color for elevated variant.
|
|
65
|
-
* @cssprop --m3e-elevated-chip-elevation - Elevation level for elevated variant.
|
|
66
|
-
* @cssprop --m3e-elevated-chip-hover-elevation - Elevation level on hover.
|
|
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
|
-
*/
|
|
70
|
-
@customElement("m3e-chip")
|
|
71
|
-
export class M3eChipElement extends Role(LitElement, "none") {
|
|
72
|
-
/** The styles of the element. */
|
|
73
|
-
static override styles: CSSResultGroup = css`
|
|
74
|
-
:host {
|
|
75
|
-
display: inline-block;
|
|
76
|
-
vertical-align: middle;
|
|
77
|
-
outline: none;
|
|
78
|
-
}
|
|
79
|
-
.base {
|
|
80
|
-
box-sizing: border-box;
|
|
81
|
-
vertical-align: middle;
|
|
82
|
-
display: inline-flex;
|
|
83
|
-
align-items: center;
|
|
84
|
-
justify-content: center;
|
|
85
|
-
position: relative;
|
|
86
|
-
width: 100%;
|
|
87
|
-
transition: ${unsafeCSS(
|
|
88
|
-
`background-color ${DesignToken.motion.duration.short4} ${DesignToken.motion.easing.standard}`
|
|
89
|
-
)};
|
|
90
|
-
border-radius: var(--m3e-chip-container-shape, ${DesignToken.shape.corner.small});
|
|
91
|
-
height: calc(var(--m3e-chip-container-height, 2rem) + ${DesignToken.density.calc(-2)});
|
|
92
|
-
font-size: var(--m3e-chip-label-text-font-size, ${DesignToken.typescale.standard.label.large.fontSize});
|
|
93
|
-
font-weight: var(--m3e-chip-label-text-font-weight, ${DesignToken.typescale.standard.label.large.fontWeight});
|
|
94
|
-
line-height: var(--m3e-chip-label-text-line-height, ${DesignToken.typescale.standard.label.large.lineHeight});
|
|
95
|
-
letter-spacing: var(--m3e-chip-label-text-tracking, ${DesignToken.typescale.standard.label.large.tracking});
|
|
96
|
-
}
|
|
97
|
-
:host(:not(m3e-chip):not(:disabled):not([disabled-interactive])) {
|
|
98
|
-
cursor: pointer;
|
|
99
|
-
}
|
|
100
|
-
:host(:not(m3e-chip):not(:disabled)[disabled-interactive]) {
|
|
101
|
-
cursor: not-allowed;
|
|
102
|
-
}
|
|
103
|
-
:host(:not(m3e-chip):not(:disabled):not([disabled-interactive])) .base {
|
|
104
|
-
user-select: none;
|
|
105
|
-
}
|
|
106
|
-
.touch {
|
|
107
|
-
position: absolute;
|
|
108
|
-
height: 3rem;
|
|
109
|
-
left: 0;
|
|
110
|
-
right: 0;
|
|
111
|
-
}
|
|
112
|
-
.wrapper {
|
|
113
|
-
width: 100%;
|
|
114
|
-
overflow: hidden;
|
|
115
|
-
display: inline-flex;
|
|
116
|
-
align-items: center;
|
|
117
|
-
column-gap: var(--m3e-chip-spacing, 0.5rem);
|
|
118
|
-
}
|
|
119
|
-
.label {
|
|
120
|
-
flex: 1 1 auto;
|
|
121
|
-
min-width: 0;
|
|
122
|
-
white-space: nowrap;
|
|
123
|
-
overflow: hidden;
|
|
124
|
-
text-overflow: ellipsis;
|
|
125
|
-
}
|
|
126
|
-
:host([variant="elevated"]) .base {
|
|
127
|
-
background-color: var(--m3e-elevated-chip-container-color, ${DesignToken.color.surfaceContainerLow});
|
|
128
|
-
|
|
129
|
-
--m3e-elevation-level: var(--m3e-elevated-chip-elevation, ${DesignToken.elevation.level1});
|
|
130
|
-
--m3e-elevation-hover-level: var(--m3e-elevated-chip-hover-elevation, ${DesignToken.elevation.level2});
|
|
131
|
-
--m3e-elevation-focus-level: var(--m3e-elevated-chip-elevation, ${DesignToken.elevation.level1});
|
|
132
|
-
--m3e-elevation-pressed-level: var(--m3e-elevated-chip-elevation, ${DesignToken.elevation.level1});
|
|
133
|
-
}
|
|
134
|
-
:host([variant="outlined"]) .base {
|
|
135
|
-
outline-width: var(--m3e-outlined-chip-outline-thickness, 1px);
|
|
136
|
-
outline-style: solid;
|
|
137
|
-
outline-offset: calc(0px - var(--m3e-outlined-chip-outline-thickness, 1px));
|
|
138
|
-
}
|
|
139
|
-
:host(:not(:disabled):not([disabled-interactive])[variant="outlined"]) .base {
|
|
140
|
-
outline-color: var(--m3e-outlined-chip-outline-color, ${DesignToken.color.outlineVariant});
|
|
141
|
-
}
|
|
142
|
-
:host(:disabled[variant="outlined"]) .base,
|
|
143
|
-
:host([disabled-interactive][variant="outlined"]) .base {
|
|
144
|
-
outline-color: color-mix(
|
|
145
|
-
in srgb,
|
|
146
|
-
var(--m3e-outlined-chip-disabled-outline-color, ${DesignToken.color.onSurface})
|
|
147
|
-
var(--m3e-outlined-chip-disabled-outline-opacity, 12%),
|
|
148
|
-
transparent
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
:host(.-with-icon) .wrapper {
|
|
152
|
-
padding-inline-start: var(--m3e-chip-with-icon-padding-start, 0.5rem);
|
|
153
|
-
}
|
|
154
|
-
:host(:not(.-with-icon)) .wrapper {
|
|
155
|
-
padding-inline-start: var(--m3e-chip-padding-start, 1rem);
|
|
156
|
-
}
|
|
157
|
-
:host(.-with-trailing-icon) .wrapper {
|
|
158
|
-
padding-inline-end: var(--m3e-chip-with-icon-padding-end, 0.5rem);
|
|
159
|
-
}
|
|
160
|
-
:host(:not(.-with-trailing-icon)) .wrapper {
|
|
161
|
-
padding-inline-end: var(--m3e-chip-padding-end, 1rem);
|
|
162
|
-
}
|
|
163
|
-
::slotted([slot="icon"]),
|
|
164
|
-
::slotted([slot="trailing-icon"]) {
|
|
165
|
-
flex: none;
|
|
166
|
-
width: 1em;
|
|
167
|
-
font-size: var(--m3e-chip-icon-size, 1.125rem) !important;
|
|
168
|
-
}
|
|
169
|
-
:host(:not(:disabled):not([disabled-interactive]):not([selected])) .base {
|
|
170
|
-
color: var(--m3e-chip-label-text-color, ${DesignToken.color.onSurface});
|
|
171
|
-
}
|
|
172
|
-
:host(:not(:disabled):not([disabled-interactive]):not([selected])) ::slotted([slot="icon"]),
|
|
173
|
-
:host(:not(:disabled):not([disabled-interactive]):not([selected])) ::slotted([slot="trailing-icon"]) {
|
|
174
|
-
color: var(--m3e-chip-icon-color, ${DesignToken.color.primary});
|
|
175
|
-
}
|
|
176
|
-
:host(:disabled) .base,
|
|
177
|
-
:host([disabled-interactive]) .base {
|
|
178
|
-
color: color-mix(
|
|
179
|
-
in srgb,
|
|
180
|
-
var(--m3e-chip-disabled-label-text-color, ${DesignToken.color.onSurface})
|
|
181
|
-
var(--m3e-chip-disabled-label-text-opacity, 38%),
|
|
182
|
-
transparent
|
|
183
|
-
);
|
|
184
|
-
}
|
|
185
|
-
:host(:disabled) ::slotted([slot="icon"]),
|
|
186
|
-
:host([disabled-interactive]) ::slotted([slot="icon"]),
|
|
187
|
-
:host(:disabled) ::slotted([slot="trailing-icon"]),
|
|
188
|
-
:host([disabled-interactive]) ::slotted([slot="trailing-icon"]) {
|
|
189
|
-
color: color-mix(
|
|
190
|
-
in srgb,
|
|
191
|
-
var(--m3e-chip-disabled-icon-color, ${DesignToken.color.onSurface}) var(--m3e-chip-disabled-icon-opacity, 38%),
|
|
192
|
-
transparent
|
|
193
|
-
);
|
|
194
|
-
}
|
|
195
|
-
:host([variant="elevated"]:disabled) .base,
|
|
196
|
-
:host([variant="elevated"][disabled-interactive]) .base {
|
|
197
|
-
background-color: color-mix(
|
|
198
|
-
in srgb,
|
|
199
|
-
var(--m3e-elevated-chip-disabled-container-color, ${DesignToken.color.onSurface})
|
|
200
|
-
var(--m3e-elevated-chip-disabled-container-opacity, 12%),
|
|
201
|
-
transparent
|
|
202
|
-
);
|
|
203
|
-
--m3e-elevation-level: var(--m3e-elevated-chip-disabled-elevation, ${DesignToken.elevation.level0});
|
|
204
|
-
}
|
|
205
|
-
@media (prefers-reduced-motion) {
|
|
206
|
-
.base {
|
|
207
|
-
transition: none;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
@media (forced-colors: active) {
|
|
211
|
-
.base {
|
|
212
|
-
transition: none;
|
|
213
|
-
}
|
|
214
|
-
:host(:not(:disabled):not([disabled-interactive]):not([selected])) .base,
|
|
215
|
-
:host(:not(:disabled):not([disabled-interactive]):not([selected])) ::slotted([slot="icon"]),
|
|
216
|
-
:host(:not(:disabled):not([disabled-interactive]):not([selected])) ::slotted([slot="trailing-icon"]) {
|
|
217
|
-
color: CanvasText;
|
|
218
|
-
}
|
|
219
|
-
:host(:not(:disabled):not([disabled-interactive])[variant="outlined"]) .base {
|
|
220
|
-
outline-color: CanvasText;
|
|
221
|
-
}
|
|
222
|
-
:host(:disabled) .base,
|
|
223
|
-
:host([disabled-interactive]) .base,
|
|
224
|
-
:host(:disabled) ::slotted([slot="icon"]),
|
|
225
|
-
:host([disabled-interactive]) ::slotted([slot="icon"]),
|
|
226
|
-
:host(:disabled) ::slotted([slot="trailing-icon"]),
|
|
227
|
-
:host([disabled-interactive]) ::slotted([slot="trailing-icon"]) {
|
|
228
|
-
color: GrayText;
|
|
229
|
-
}
|
|
230
|
-
:host(:disabled[variant="outlined"]) .base,
|
|
231
|
-
:host([disabled-interactive][variant="outlined"]) .base {
|
|
232
|
-
outline-color: GrayText;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
`;
|
|
236
|
-
|
|
237
|
-
/** @private */ @query(".elevation") private readonly _elevation?: M3eElevationElement;
|
|
238
|
-
/** @private */ @query(".focus-ring") private readonly _focusRing?: M3eFocusRingElement;
|
|
239
|
-
/** @private */ @query(".state-layer") private readonly _stateLayer?: M3eStateLayerElement;
|
|
240
|
-
/** @private */ @query(".ripple") private readonly _ripple?: M3eRippleElement;
|
|
241
|
-
|
|
242
|
-
/** @private */ #value?: string;
|
|
243
|
-
/** @private */ #textContent = "";
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* The appearance variant of the chip.
|
|
247
|
-
* @default "outlined"
|
|
248
|
-
*/
|
|
249
|
-
@property({ reflect: true }) variant: ChipVariant = "outlined";
|
|
250
|
-
|
|
251
|
-
/** A string representing the value of the chip. */
|
|
252
|
-
@property() get value() {
|
|
253
|
-
return this.#value ?? this.#textContent;
|
|
254
|
-
}
|
|
255
|
-
set value(value: string) {
|
|
256
|
-
this.#value = value;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
/** @inheritdoc */
|
|
260
|
-
protected override firstUpdated(_changedProperties: PropertyValues): void {
|
|
261
|
-
super.firstUpdated(_changedProperties);
|
|
262
|
-
|
|
263
|
-
if (this.role === "listitem") {
|
|
264
|
-
this.removeAttribute("tabindex");
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
[this._elevation, this._focusRing, this._stateLayer, this._ripple].forEach((x) => {
|
|
268
|
-
if (!x?.htmlFor) {
|
|
269
|
-
x?.attach(this);
|
|
270
|
-
}
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
/** @inheritdoc */
|
|
275
|
-
protected override render(): unknown {
|
|
276
|
-
const disabled = !isDisabledMixin(this) || this.disabled;
|
|
277
|
-
const disabledInteractive = isDisabledInteractiveMixin(this) && this.disabledInteractive;
|
|
278
|
-
|
|
279
|
-
return html`<div class="base">
|
|
280
|
-
<m3e-elevation class="elevation" ?disabled="${disabled || disabledInteractive}"></m3e-elevation>
|
|
281
|
-
<m3e-state-layer class="state-layer" ?disabled="${disabled || disabledInteractive}"></m3e-state-layer>
|
|
282
|
-
<m3e-focus-ring class="focus-ring" ?disabled="${disabled}"></m3e-focus-ring>
|
|
283
|
-
<m3e-ripple class="ripple" ?disabled="${disabled || disabledInteractive}"></m3e-ripple>
|
|
284
|
-
<div class="touch" aria-hidden="true"></div>
|
|
285
|
-
${isLinkButtonMixin(this) ? this[renderPseudoLink]() : nothing}
|
|
286
|
-
<div class="wrapper">${this.#renderContent()}</div>
|
|
287
|
-
</div>`;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
/** @private */
|
|
291
|
-
#renderContent(): unknown {
|
|
292
|
-
return html`${this._renderIcon()}
|
|
293
|
-
<div class="label">${this._renderSlot()}</div>
|
|
294
|
-
${this._renderTrailingIcon()}`;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
/** @internal */
|
|
298
|
-
protected _renderIcon(): unknown {
|
|
299
|
-
return html`<slot name="icon" aria-hidden="true" @slotchange="${this.#handleIconSlotChange}"></slot>`;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
/** @internal */
|
|
303
|
-
protected _renderTrailingIcon(): unknown {
|
|
304
|
-
return html`<slot
|
|
305
|
-
name="trailing-icon"
|
|
306
|
-
aria-hidden="true"
|
|
307
|
-
@slotchange="${this.#handleTrailingIconSlotChange}"
|
|
308
|
-
></slot>`;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
/** @internal */
|
|
312
|
-
protected _renderSlot(): unknown {
|
|
313
|
-
return html`<slot @slotchange="${this.#handleSlotChange}"></slot>`;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
/** @private */
|
|
317
|
-
#handleIconSlotChange(e: Event): void {
|
|
318
|
-
this.classList.toggle("-with-icon", hasAssignedNodes(<HTMLSlotElement>e.target));
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
/** @private */
|
|
322
|
-
#handleTrailingIconSlotChange(e: Event): void {
|
|
323
|
-
this.classList.toggle("-with-trailing-icon", hasAssignedNodes(<HTMLSlotElement>e.target));
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
/** @private */
|
|
327
|
-
#handleSlotChange(e: Event): void {
|
|
328
|
-
this.#textContent = getTextContent(<HTMLSlotElement>e.target);
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
declare global {
|
|
333
|
-
interface HTMLElementTagNameMap {
|
|
334
|
-
"m3e-chip": M3eChipElement;
|
|
335
|
-
}
|
|
336
|
-
}
|
package/src/ChipSetElement.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { css, CSSResultGroup, html, LitElement } from "lit";
|
|
2
|
-
import { customElement } from "lit/decorators.js";
|
|
3
|
-
|
|
4
|
-
import { Role, Vertical } from "@m3e/core";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @summary
|
|
8
|
-
* A container used to organize chips into a cohesive unit.
|
|
9
|
-
*
|
|
10
|
-
* @description
|
|
11
|
-
* The `m3e-chip-set` component provides a flexible container for grouping chips, supporting both
|
|
12
|
-
* horizontal and vertical layouts. It manages chip arrangement, spacing, and accessibility, and
|
|
13
|
-
* serves as the foundation for chip set variants such as input and filter chip sets.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* The following example illustrates use of the `m3e-chip` and `m3e-chip-set` components to present non-interactive chips.
|
|
17
|
-
* ```html
|
|
18
|
-
* <m3e-chip-set>
|
|
19
|
-
* <m3e-chip><m3e-icon slot="icon" name="palette"></m3e-icon>Design</m3e-chip>
|
|
20
|
-
* <m3e-chip><m3e-icon slot="icon" name="accessibility_new"></m3e-icon>Accessibility</m3e-chip>
|
|
21
|
-
* <m3e-chip><m3e-icon slot="icon" name="motion_photos_on"></m3e-icon>Motion</m3e-chip>
|
|
22
|
-
* <m3e-chip><m3e-icon slot="icon" name="description"></m3e-icon>Documentation</m3e-chip>
|
|
23
|
-
* </m3e-chip-set>
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* @tag m3e-chip-set
|
|
27
|
-
*
|
|
28
|
-
* @slot - Renders the chips of the set.
|
|
29
|
-
*
|
|
30
|
-
* @attr vertical - Whether the element is oriented vertically.
|
|
31
|
-
*
|
|
32
|
-
* @cssprop --m3e-chip-set-spacing - The spacing (gap) between chips in the set.
|
|
33
|
-
*/
|
|
34
|
-
@customElement("m3e-chip-set")
|
|
35
|
-
export class M3eChipSetElement extends Vertical(Role(LitElement, "none")) {
|
|
36
|
-
/** The styles of the element. */
|
|
37
|
-
static override styles: CSSResultGroup = css`
|
|
38
|
-
:host {
|
|
39
|
-
display: inline-flex;
|
|
40
|
-
flex-wrap: wrap;
|
|
41
|
-
vertical-align: middle;
|
|
42
|
-
gap: var(--m3e-chip-set-spacing, 0.5rem);
|
|
43
|
-
outline: none;
|
|
44
|
-
}
|
|
45
|
-
:host([vertical]) {
|
|
46
|
-
flex-direction: column;
|
|
47
|
-
}
|
|
48
|
-
`;
|
|
49
|
-
|
|
50
|
-
/** @inheritdoc */
|
|
51
|
-
protected override render(): unknown {
|
|
52
|
-
return html`<slot></slot>`;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
declare global {
|
|
57
|
-
interface HTMLElementTagNameMap {
|
|
58
|
-
"m3e-chip-set": M3eChipSetElement;
|
|
59
|
-
}
|
|
60
|
-
}
|
package/src/ChipVariant.ts
DELETED
package/src/FilterChipElement.ts
DELETED
|
@@ -1,254 +0,0 @@
|
|
|
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
|
-
}
|