@lit-material/chip 0.0.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 +21 -0
- package/README.md +64 -0
- package/dist/chip-styles.d.ts +2 -0
- package/dist/chip-styles.d.ts.map +1 -0
- package/dist/chip-styles.js +173 -0
- package/dist/chip-styles.js.map +1 -0
- package/dist/chip.d.ts +50 -0
- package/dist/chip.d.ts.map +1 -0
- package/dist/chip.js +180 -0
- package/dist/chip.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 bohdaq
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# @lit-material/chip
|
|
2
|
+
|
|
3
|
+
A Material Design 3 chip web component built with [Lit](https://lit.dev/). Part of
|
|
4
|
+
[lit-material](https://github.com/bohdaq/lit-material).
|
|
5
|
+
|
|
6
|
+

|
|
7
|
+
|
|
8
|
+
Assist, filter, input, and suggestion variants, an elevated style, and a removable trailing button.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
npm install @lit-material/chip @lit-material/tokens
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
```html
|
|
19
|
+
<link rel="stylesheet" href="node_modules/@lit-material/tokens/css/index.css" />
|
|
20
|
+
<script type="module">
|
|
21
|
+
import "@lit-material/chip";
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<lit-material-chip>Assist</lit-material-chip>
|
|
25
|
+
<lit-material-chip elevated>Elevated assist</lit-material-chip>
|
|
26
|
+
<lit-material-chip href="https://lit.dev" target="_blank">Open lit.dev</lit-material-chip>
|
|
27
|
+
|
|
28
|
+
<lit-material-chip variant="filter">Spicy</lit-material-chip>
|
|
29
|
+
<lit-material-chip variant="filter" selected>Vegetarian</lit-material-chip>
|
|
30
|
+
|
|
31
|
+
<lit-material-chip variant="input" removable>Tag one</lit-material-chip>
|
|
32
|
+
|
|
33
|
+
<lit-material-chip variant="suggestion">Nearby</lit-material-chip>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## API
|
|
37
|
+
|
|
38
|
+
| Property | Attribute | Type | Default |
|
|
39
|
+
| ----------- | --------- | ---------------------------------------------------- | ---------- |
|
|
40
|
+
| `variant` | `variant` | `"assist" \| "filter" \| "input" \| "suggestion"` | `"assist"` |
|
|
41
|
+
| `selected` | `selected` | `boolean` | `false` |
|
|
42
|
+
| `disabled` | `disabled` | `boolean` | `false` |
|
|
43
|
+
| `elevated` | `elevated` | `boolean` | `false` |
|
|
44
|
+
| `removable` | `removable` | `boolean` | `false` |
|
|
45
|
+
| `href` | `href` | `string` | `""` |
|
|
46
|
+
| `target` | `target` | `string` | `""` |
|
|
47
|
+
|
|
48
|
+
Slots: default (label), `leading-icon` (ignored on a selected `filter` chip, which shows a
|
|
49
|
+
checkmark in its place).
|
|
50
|
+
|
|
51
|
+
`variant` is presentational, not exclusive: `selected` and `removable` work on any variant, though
|
|
52
|
+
conventionally `selected` toggling is used with `filter` chips and `removable` with `input` chips.
|
|
53
|
+
Clicking a `filter` chip toggles `selected` and fires `change`; the trailing remove button (shown
|
|
54
|
+
when `removable`) fires a cancelable `remove` event and, unless `event.preventDefault()` is
|
|
55
|
+
called, removes the chip from the DOM.
|
|
56
|
+
|
|
57
|
+
Unlike checkbox/radio/switch, chips are **not** form-associated — they're auxiliary UI (filters,
|
|
58
|
+
action triggers, removable tags), not a value a `<form>` submits, matching how Material Design
|
|
59
|
+
itself treats chips. Track a `filter` chip set's selection or an `input` chip list by listening for
|
|
60
|
+
`change`/`remove` rather than reading `FormData`.
|
|
61
|
+
|
|
62
|
+
## License
|
|
63
|
+
|
|
64
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chip-styles.d.ts","sourceRoot":"","sources":["../src/chip-styles.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,MAAM,yBA0KlB,CAAC"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { css } from "lit";
|
|
2
|
+
export const styles = css `
|
|
3
|
+
:host {
|
|
4
|
+
display: inline-flex;
|
|
5
|
+
vertical-align: top;
|
|
6
|
+
-webkit-tap-highlight-color: transparent;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
:host([disabled]) {
|
|
10
|
+
pointer-events: none;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.chip {
|
|
14
|
+
position: relative;
|
|
15
|
+
display: inline-flex;
|
|
16
|
+
align-items: stretch;
|
|
17
|
+
box-sizing: border-box;
|
|
18
|
+
height: 32px;
|
|
19
|
+
border-radius: var(--md-sys-shape-corner-small, 8px);
|
|
20
|
+
background-color: transparent;
|
|
21
|
+
border: 1px solid var(--md-sys-color-outline, #79747e);
|
|
22
|
+
color: var(--md-sys-color-on-surface-variant, #49454f);
|
|
23
|
+
transition:
|
|
24
|
+
background-color 150ms var(--md-sys-motion-easing-standard, cubic-bezier(0.2, 0, 0, 1)),
|
|
25
|
+
border-color 150ms var(--md-sys-motion-easing-standard, cubic-bezier(0.2, 0, 0, 1));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.chip.elevated {
|
|
29
|
+
border-color: transparent;
|
|
30
|
+
background-color: var(--md-sys-color-surface-container-low, #f7f2fa);
|
|
31
|
+
box-shadow: var(--md-sys-elevation-1, 0 1px 2px 0 rgba(0, 0, 0, 0.3), 0 1px 3px 1px rgba(0, 0, 0, 0.15));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.chip.filter.selected {
|
|
35
|
+
border-color: transparent;
|
|
36
|
+
background-color: var(--md-sys-color-secondary-container, #e8def8);
|
|
37
|
+
color: var(--md-sys-color-on-secondary-container, #1d192b);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
:host([disabled]) .chip {
|
|
41
|
+
opacity: 0.38;
|
|
42
|
+
box-shadow: none;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.action {
|
|
46
|
+
position: relative;
|
|
47
|
+
display: inline-flex;
|
|
48
|
+
align-items: center;
|
|
49
|
+
gap: 8px;
|
|
50
|
+
height: 100%;
|
|
51
|
+
padding-inline: 16px;
|
|
52
|
+
margin: 0;
|
|
53
|
+
border: none;
|
|
54
|
+
background: transparent;
|
|
55
|
+
text-decoration: none;
|
|
56
|
+
cursor: pointer;
|
|
57
|
+
color: inherit;
|
|
58
|
+
font-family: var(--md-sys-typescale-label-large-font, Roboto, system-ui, sans-serif);
|
|
59
|
+
font-size: var(--md-sys-typescale-label-large-size, 0.875rem);
|
|
60
|
+
line-height: var(--md-sys-typescale-label-large-line-height, 1.25rem);
|
|
61
|
+
border-radius: inherit;
|
|
62
|
+
-webkit-appearance: none;
|
|
63
|
+
appearance: none;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.action:disabled,
|
|
67
|
+
.action[aria-disabled="true"] {
|
|
68
|
+
cursor: default;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.action:focus-visible {
|
|
72
|
+
outline: 2px solid var(--md-sys-color-secondary, #625b71);
|
|
73
|
+
outline-offset: -2px;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.state-layer {
|
|
77
|
+
position: absolute;
|
|
78
|
+
inset: 0;
|
|
79
|
+
border-radius: inherit;
|
|
80
|
+
background-color: currentColor;
|
|
81
|
+
opacity: 0;
|
|
82
|
+
pointer-events: none;
|
|
83
|
+
transition: opacity 100ms linear;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.action:hover .state-layer {
|
|
87
|
+
opacity: var(--md-sys-state-hover-state-layer-opacity, 0.08);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.state-layer[data-pressed] {
|
|
91
|
+
opacity: var(--md-sys-state-pressed-state-layer-opacity, 0.1);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.leading-icon ::slotted(*) {
|
|
95
|
+
width: 18px;
|
|
96
|
+
height: 18px;
|
|
97
|
+
display: block;
|
|
98
|
+
pointer-events: none;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.checkmark {
|
|
102
|
+
width: 18px;
|
|
103
|
+
height: 18px;
|
|
104
|
+
flex: none;
|
|
105
|
+
pointer-events: none;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.checkmark path {
|
|
109
|
+
fill: none;
|
|
110
|
+
stroke: currentColor;
|
|
111
|
+
stroke-width: 2;
|
|
112
|
+
stroke-linecap: round;
|
|
113
|
+
stroke-linejoin: round;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.label {
|
|
117
|
+
display: inline-flex;
|
|
118
|
+
align-items: center;
|
|
119
|
+
white-space: nowrap;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.remove {
|
|
123
|
+
position: relative;
|
|
124
|
+
display: inline-flex;
|
|
125
|
+
align-items: center;
|
|
126
|
+
justify-content: center;
|
|
127
|
+
flex: none;
|
|
128
|
+
width: 24px;
|
|
129
|
+
margin-inline: -8px 8px;
|
|
130
|
+
padding: 0;
|
|
131
|
+
border: none;
|
|
132
|
+
background: transparent;
|
|
133
|
+
border-radius: 50%;
|
|
134
|
+
color: inherit;
|
|
135
|
+
cursor: pointer;
|
|
136
|
+
-webkit-appearance: none;
|
|
137
|
+
appearance: none;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
.remove:disabled {
|
|
141
|
+
cursor: default;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.remove:hover {
|
|
145
|
+
background-color: color-mix(in srgb, currentColor 8%, transparent);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
.remove:focus-visible {
|
|
149
|
+
outline: 2px solid var(--md-sys-color-secondary, #625b71);
|
|
150
|
+
outline-offset: -1px;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.remove-icon {
|
|
154
|
+
width: 14px;
|
|
155
|
+
height: 14px;
|
|
156
|
+
pointer-events: none;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
.remove-icon path {
|
|
160
|
+
fill: none;
|
|
161
|
+
stroke: currentColor;
|
|
162
|
+
stroke-width: 1.5;
|
|
163
|
+
stroke-linecap: round;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
@media (prefers-reduced-motion: reduce) {
|
|
167
|
+
.chip,
|
|
168
|
+
.state-layer {
|
|
169
|
+
transition: none;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
`;
|
|
173
|
+
//# sourceMappingURL=chip-styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chip-styles.js","sourceRoot":"","sources":["../src/chip-styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,MAAM,CAAC,MAAM,MAAM,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0KxB,CAAC"}
|
package/dist/chip.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { LitElement } from "lit";
|
|
2
|
+
export type ChipVariant = "assist" | "filter" | "input" | "suggestion";
|
|
3
|
+
/**
|
|
4
|
+
* Material Design 3 chip.
|
|
5
|
+
*
|
|
6
|
+
* Unlike checkbox/radio/switch, chips are not form-associated: they're
|
|
7
|
+
* auxiliary UI (filters, action triggers, removable tags) rather than a
|
|
8
|
+
* value a `<form>` submits, matching how Material Design itself treats
|
|
9
|
+
* chips. A `filter` chip's `selected` state and an `input` chip's removal
|
|
10
|
+
* are communicated via `change`/`remove` events instead.
|
|
11
|
+
*
|
|
12
|
+
* @element lit-material-chip
|
|
13
|
+
*
|
|
14
|
+
* @slot - The chip's label.
|
|
15
|
+
* @slot leading-icon - An optional icon before the label. Ignored on a
|
|
16
|
+
* selected `filter` chip, which shows a checkmark in its place.
|
|
17
|
+
*
|
|
18
|
+
* @csspart chip - The outer container (background/border/elevation).
|
|
19
|
+
* @csspart action - The main clickable `<button>` or `<a>` (icon + label).
|
|
20
|
+
* @csspart remove-button - The trailing remove `<button>`, when `removable`.
|
|
21
|
+
* @csspart ripple - The state-layer element the hover/press feedback is drawn on.
|
|
22
|
+
*
|
|
23
|
+
* @fires change - Bubbles when a `filter` chip's `selected` state toggles via user interaction.
|
|
24
|
+
* @fires remove - Cancelable; fires when the remove button is activated. Unless
|
|
25
|
+
* `event.preventDefault()` is called, the chip removes itself from the DOM afterward.
|
|
26
|
+
*/
|
|
27
|
+
export declare class LitMaterialChip extends LitElement {
|
|
28
|
+
static styles: import("lit").CSSResult;
|
|
29
|
+
variant: ChipVariant;
|
|
30
|
+
selected: boolean;
|
|
31
|
+
disabled: boolean;
|
|
32
|
+
elevated: boolean;
|
|
33
|
+
removable: boolean;
|
|
34
|
+
/** If set, renders the main action as a link (`<a>`) instead of a `<button>`. */
|
|
35
|
+
href: string;
|
|
36
|
+
target: string;
|
|
37
|
+
private readonly actionElement?;
|
|
38
|
+
private readonly ripple;
|
|
39
|
+
protected firstUpdated(): void;
|
|
40
|
+
render(): import("lit").TemplateResult<1>;
|
|
41
|
+
private handleActionClick;
|
|
42
|
+
private handleLinkClick;
|
|
43
|
+
private handleRemoveClick;
|
|
44
|
+
}
|
|
45
|
+
declare global {
|
|
46
|
+
interface HTMLElementTagNameMap {
|
|
47
|
+
"lit-material-chip": LitMaterialChip;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=chip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chip.d.ts","sourceRoot":"","sources":["../src/chip.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,UAAU,EAAW,MAAM,KAAK,CAAC;AAKhD,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,QAAQ,GAAG,OAAO,GAAG,YAAY,CAAC;AAEvE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBACa,eAAgB,SAAQ,UAAU;IAC7C,OAAgB,MAAM,0BAAU;IAEpB,OAAO,EAAE,WAAW,CAAY;IACA,QAAQ,UAAS;IACjB,QAAQ,UAAS;IACjB,QAAQ,UAAS;IAChC,SAAS,UAAS;IAE/C,iFAAiF;IACrE,IAAI,SAAM;IACV,MAAM,SAAM;IAEN,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAwC;IAEzF,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA8B;cAElC,YAAY,IAAI,IAAI;IAM9B,MAAM;IA8Ef,OAAO,CAAC,iBAAiB;IAYzB,OAAO,CAAC,eAAe;IAOvB,OAAO,CAAC,iBAAiB;CAQ1B;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,mBAAmB,EAAE,eAAe,CAAC;KACtC;CACF"}
|
package/dist/chip.js
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { html, LitElement, nothing } from "lit";
|
|
8
|
+
import { customElement, property, query } from "lit/decorators.js";
|
|
9
|
+
import { RippleController } from "@lit-material/core";
|
|
10
|
+
import { styles } from "./chip-styles.js";
|
|
11
|
+
/**
|
|
12
|
+
* Material Design 3 chip.
|
|
13
|
+
*
|
|
14
|
+
* Unlike checkbox/radio/switch, chips are not form-associated: they're
|
|
15
|
+
* auxiliary UI (filters, action triggers, removable tags) rather than a
|
|
16
|
+
* value a `<form>` submits, matching how Material Design itself treats
|
|
17
|
+
* chips. A `filter` chip's `selected` state and an `input` chip's removal
|
|
18
|
+
* are communicated via `change`/`remove` events instead.
|
|
19
|
+
*
|
|
20
|
+
* @element lit-material-chip
|
|
21
|
+
*
|
|
22
|
+
* @slot - The chip's label.
|
|
23
|
+
* @slot leading-icon - An optional icon before the label. Ignored on a
|
|
24
|
+
* selected `filter` chip, which shows a checkmark in its place.
|
|
25
|
+
*
|
|
26
|
+
* @csspart chip - The outer container (background/border/elevation).
|
|
27
|
+
* @csspart action - The main clickable `<button>` or `<a>` (icon + label).
|
|
28
|
+
* @csspart remove-button - The trailing remove `<button>`, when `removable`.
|
|
29
|
+
* @csspart ripple - The state-layer element the hover/press feedback is drawn on.
|
|
30
|
+
*
|
|
31
|
+
* @fires change - Bubbles when a `filter` chip's `selected` state toggles via user interaction.
|
|
32
|
+
* @fires remove - Cancelable; fires when the remove button is activated. Unless
|
|
33
|
+
* `event.preventDefault()` is called, the chip removes itself from the DOM afterward.
|
|
34
|
+
*/
|
|
35
|
+
let LitMaterialChip = class LitMaterialChip extends LitElement {
|
|
36
|
+
constructor() {
|
|
37
|
+
super(...arguments);
|
|
38
|
+
this.variant = "assist";
|
|
39
|
+
this.selected = false;
|
|
40
|
+
this.disabled = false;
|
|
41
|
+
this.elevated = false;
|
|
42
|
+
this.removable = false;
|
|
43
|
+
/** If set, renders the main action as a link (`<a>`) instead of a `<button>`. */
|
|
44
|
+
this.href = "";
|
|
45
|
+
this.target = "";
|
|
46
|
+
this.ripple = new RippleController(this);
|
|
47
|
+
}
|
|
48
|
+
static { this.styles = styles; }
|
|
49
|
+
firstUpdated() {
|
|
50
|
+
if (this.actionElement) {
|
|
51
|
+
this.ripple.attach(this.actionElement);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
render() {
|
|
55
|
+
const isFilter = this.variant === "filter";
|
|
56
|
+
const showCheckmark = isFilter && this.selected;
|
|
57
|
+
const chipClasses = [
|
|
58
|
+
"chip",
|
|
59
|
+
this.variant,
|
|
60
|
+
showCheckmark ? "selected" : "",
|
|
61
|
+
this.elevated ? "elevated" : "",
|
|
62
|
+
]
|
|
63
|
+
.filter(Boolean)
|
|
64
|
+
.join(" ");
|
|
65
|
+
const leading = showCheckmark
|
|
66
|
+
? html `
|
|
67
|
+
<svg class="checkmark" viewBox="0 0 18 18" aria-hidden="true">
|
|
68
|
+
<path d="M4 9.5 L7.2 12.7 L14 5.5"></path>
|
|
69
|
+
</svg>
|
|
70
|
+
`
|
|
71
|
+
: html `<slot name="leading-icon" class="leading-icon"></slot>`;
|
|
72
|
+
const actionContent = html `
|
|
73
|
+
<div class="state-layer" part="ripple"></div>
|
|
74
|
+
${leading}
|
|
75
|
+
<span class="label"><slot></slot></span>
|
|
76
|
+
`;
|
|
77
|
+
const action = this.href
|
|
78
|
+
? html `
|
|
79
|
+
<a
|
|
80
|
+
class="action"
|
|
81
|
+
part="action"
|
|
82
|
+
href=${this.disabled ? nothing : this.href}
|
|
83
|
+
target=${this.target || nothing}
|
|
84
|
+
rel=${this.target === "_blank" ? "noopener noreferrer" : nothing}
|
|
85
|
+
aria-disabled=${this.disabled ? "true" : nothing}
|
|
86
|
+
tabindex=${this.disabled ? "-1" : "0"}
|
|
87
|
+
@click=${this.handleLinkClick}
|
|
88
|
+
>
|
|
89
|
+
${actionContent}
|
|
90
|
+
</a>
|
|
91
|
+
`
|
|
92
|
+
: html `
|
|
93
|
+
<button
|
|
94
|
+
class="action"
|
|
95
|
+
part="action"
|
|
96
|
+
type="button"
|
|
97
|
+
?disabled=${this.disabled}
|
|
98
|
+
aria-pressed=${isFilter ? String(this.selected) : nothing}
|
|
99
|
+
@click=${this.handleActionClick}
|
|
100
|
+
>
|
|
101
|
+
${actionContent}
|
|
102
|
+
</button>
|
|
103
|
+
`;
|
|
104
|
+
return html `
|
|
105
|
+
<div class=${chipClasses} part="chip">
|
|
106
|
+
${action}
|
|
107
|
+
${this.removable
|
|
108
|
+
? html `
|
|
109
|
+
<button
|
|
110
|
+
class="remove"
|
|
111
|
+
part="remove-button"
|
|
112
|
+
type="button"
|
|
113
|
+
?disabled=${this.disabled}
|
|
114
|
+
aria-label="Remove"
|
|
115
|
+
@click=${this.handleRemoveClick}
|
|
116
|
+
>
|
|
117
|
+
<svg class="remove-icon" viewBox="0 0 18 18" aria-hidden="true">
|
|
118
|
+
<path d="M5 5 L13 13 M13 5 L5 13"></path>
|
|
119
|
+
</svg>
|
|
120
|
+
</button>
|
|
121
|
+
`
|
|
122
|
+
: nothing}
|
|
123
|
+
</div>
|
|
124
|
+
`;
|
|
125
|
+
}
|
|
126
|
+
handleActionClick(event) {
|
|
127
|
+
if (this.disabled) {
|
|
128
|
+
event.preventDefault();
|
|
129
|
+
event.stopImmediatePropagation();
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (this.variant === "filter") {
|
|
133
|
+
this.selected = !this.selected;
|
|
134
|
+
this.dispatchEvent(new Event("change", { bubbles: true }));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
handleLinkClick(event) {
|
|
138
|
+
if (this.disabled) {
|
|
139
|
+
event.preventDefault();
|
|
140
|
+
event.stopImmediatePropagation();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
handleRemoveClick(event) {
|
|
144
|
+
event.stopPropagation();
|
|
145
|
+
if (this.disabled)
|
|
146
|
+
return;
|
|
147
|
+
const proceed = this.dispatchEvent(new Event("remove", { bubbles: true, cancelable: true, composed: true }));
|
|
148
|
+
if (proceed)
|
|
149
|
+
this.remove();
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
__decorate([
|
|
153
|
+
property()
|
|
154
|
+
], LitMaterialChip.prototype, "variant", void 0);
|
|
155
|
+
__decorate([
|
|
156
|
+
property({ type: Boolean, reflect: true })
|
|
157
|
+
], LitMaterialChip.prototype, "selected", void 0);
|
|
158
|
+
__decorate([
|
|
159
|
+
property({ type: Boolean, reflect: true })
|
|
160
|
+
], LitMaterialChip.prototype, "disabled", void 0);
|
|
161
|
+
__decorate([
|
|
162
|
+
property({ type: Boolean, reflect: true })
|
|
163
|
+
], LitMaterialChip.prototype, "elevated", void 0);
|
|
164
|
+
__decorate([
|
|
165
|
+
property({ type: Boolean })
|
|
166
|
+
], LitMaterialChip.prototype, "removable", void 0);
|
|
167
|
+
__decorate([
|
|
168
|
+
property()
|
|
169
|
+
], LitMaterialChip.prototype, "href", void 0);
|
|
170
|
+
__decorate([
|
|
171
|
+
property()
|
|
172
|
+
], LitMaterialChip.prototype, "target", void 0);
|
|
173
|
+
__decorate([
|
|
174
|
+
query(".action")
|
|
175
|
+
], LitMaterialChip.prototype, "actionElement", void 0);
|
|
176
|
+
LitMaterialChip = __decorate([
|
|
177
|
+
customElement("lit-material-chip")
|
|
178
|
+
], LitMaterialChip);
|
|
179
|
+
export { LitMaterialChip };
|
|
180
|
+
//# sourceMappingURL=chip.js.map
|
package/dist/chip.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chip.js","sourceRoot":"","sources":["../src/chip.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAI1C;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEI,IAAM,eAAe,GAArB,MAAM,eAAgB,SAAQ,UAAU;IAAxC;;QAGO,YAAO,GAAgB,QAAQ,CAAC;QACA,aAAQ,GAAG,KAAK,CAAC;QACjB,aAAQ,GAAG,KAAK,CAAC;QACjB,aAAQ,GAAG,KAAK,CAAC;QAChC,cAAS,GAAG,KAAK,CAAC;QAE/C,iFAAiF;QACrE,SAAI,GAAG,EAAE,CAAC;QACV,WAAM,GAAG,EAAE,CAAC;QAIP,WAAM,GAAG,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAiHvD,CAAC;aA/HiB,WAAM,GAAG,MAAM,AAAT,CAAU;IA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,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CACzE,CAAC;QACF,IAAI,OAAO;YAAE,IAAI,CAAC,MAAM,EAAE,CAAC;IAC7B,CAAC;;AA5HW;IAAX,QAAQ,EAAE;gDAAiC;AACA;IAA3C,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;iDAAkB;AACjB;IAA3C,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;iDAAkB;AACjB;IAA3C,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;iDAAkB;AAChC;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;kDAAmB;AAGnC;IAAX,QAAQ,EAAE;6CAAW;AACV;IAAX,QAAQ,EAAE;+CAAa;AAEW;IAAlC,KAAK,CAAC,SAAS,CAAC;sDAAwE;AAb9E,eAAe;IAD3B,aAAa,CAAC,mBAAmB,CAAC;GACtB,eAAe,CAgI3B"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAoB,MAAM,WAAW,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lit-material/chip",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Material Design 3 chip web component (assist, filter, input, suggestion variants).",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "bohdaq",
|
|
8
|
+
"email": "bohdaq@gmail.com",
|
|
9
|
+
"url": "https://github.com/bohdaq"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/bohdaq/lit-material#readme",
|
|
12
|
+
"bugs": "https://github.com/bohdaq/lit-material/issues",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+ssh://git@github.com/bohdaq/lit-material.git",
|
|
16
|
+
"directory": "packages/chip"
|
|
17
|
+
},
|
|
18
|
+
"keywords": ["lit", "web-components", "lit-material", "material-design", "material-design-3", "chip"],
|
|
19
|
+
"type": "module",
|
|
20
|
+
"main": "./dist/index.js",
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"default": "./dist/index.js"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist"
|
|
30
|
+
],
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsc -p tsconfig.json",
|
|
36
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
37
|
+
"test": "web-test-runner && node --import tsx --test src/chip.ssr.test.ts"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@lit-material/core": "workspace:*",
|
|
41
|
+
"@lit-material/tokens": "workspace:*",
|
|
42
|
+
"lit": "^3.2.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@lit-labs/ssr": "^3.3.1",
|
|
46
|
+
"@open-wc/testing": "^4.0.0",
|
|
47
|
+
"@web/dev-server-esbuild": "^1.0.0",
|
|
48
|
+
"@web/test-runner": "^0.19.0",
|
|
49
|
+
"@web/test-runner-commands": "^0.9.0",
|
|
50
|
+
"@web/test-runner-playwright": "^0.11.0",
|
|
51
|
+
"tsx": "^4.19.0",
|
|
52
|
+
"typescript": "^5.7.0"
|
|
53
|
+
}
|
|
54
|
+
}
|