@reliability-design/web 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,17 +1,38 @@
1
1
  import { LitElement, html, css } from "lit";
2
- import { customElement, property } from "lit/decorators.js";
2
+ import { customElement, property, state } from "lit/decorators.js";
3
3
  import "../rel-avatar/rel-avatar.js";
4
+ import "@reliability-design/icons/rel-icon";
5
+
6
+ export type ChipTone = "neutral" | "danger" | "warning" | "success" | "info";
7
+ export type ChipVariant = "fill" | "subtle";
8
+ export type ChipSize = "sm" | "md" | "lg";
9
+ export type ChipBorder = "default" | "rounded";
4
10
 
5
11
  @customElement("rel-chip")
6
12
  export class RelChip extends LitElement {
13
+ // The actually-focusable element is the inner <span tabindex="0">, not the
14
+ // host. Without delegatesFocus, calling host.focus() (e.g. from a parent
15
+ // component, or a "focus this" demo button) is a no-op since the host
16
+ // itself carries no tabindex — only real Tab-key traversal would still
17
+ // reach the inner span, because that walks the flattened DOM regardless.
18
+ static override shadowRootOptions: ShadowRootInit = {
19
+ ...LitElement.shadowRootOptions,
20
+ delegatesFocus: true,
21
+ };
22
+
7
23
  @property({ type: String }) label = "Label";
8
24
 
9
- // "yellow" renamed to "orange" — existing serialized "yellow" values will fall through to chip-yellow class (no match) and render unstyled
10
- @property({ type: String })
11
- tone: "default" | "blue" | "orange" | "red" | "green" = "default";
25
+ @property({ type: String, reflect: true }) tone: ChipTone = "neutral";
26
+
27
+ @property({ type: String, reflect: true }) variant: ChipVariant = "fill";
28
+
29
+ @property({ type: String, reflect: true }) size: ChipSize = "md";
12
30
 
13
- @property({ type: String }) leadingIcon?: string;
14
- @property({ type: String }) trailingIcon?: string;
31
+ @property({ type: String, reflect: true }) border: ChipBorder = "default";
32
+
33
+ /** Icon name from the generated icon dictionary (e.g. "settings") — rendered via <rel-icon>. */
34
+ @property({ type: String, attribute: "leading-icon" }) leadingIcon?: string;
35
+ @property({ type: String, attribute: "trailing-icon" }) trailingIcon?: string;
15
36
  /** Initials text for the avatar (e.g. "JD"). Mutually exclusive with leadingIcon. */
16
37
  @property({ type: String }) avatar?: string;
17
38
 
@@ -20,6 +41,15 @@ export class RelChip extends LitElement {
20
41
  /** IMPORTANT: reflected so CSS + Angular can see it */
21
42
  @property({ type: Boolean, reflect: true }) removed = false;
22
43
 
44
+ /** Opt-in native drag-and-drop — reflects the Figma "Dragged" state automatically during a real drag gesture. */
45
+ // Explicit attribute mapping — Lit's default attribute name for a camelCase
46
+ // property is the name fully lowercased (no hyphens), so without this it'd
47
+ // only respond to draggablechip="", not draggable-chip.
48
+ @property({ type: Boolean, attribute: "draggable-chip" }) draggableChip = false;
49
+
50
+ /** Reflected so CSS can target the Figma "Dragged" visual state. Driven automatically by dragstart/dragend when draggableChip is set. */
51
+ @state() private dragging = false;
52
+
23
53
  static styles = css`
24
54
  :host {
25
55
  display: inline-flex;
@@ -34,108 +64,184 @@ export class RelChip extends LitElement {
34
64
  .chip {
35
65
  display: inline-flex;
36
66
  align-items: center;
67
+ box-sizing: border-box;
37
68
  font-family: var(--rel-fontFamilies-primary);
38
- font-size: var(--rel-fontSizes-md);
39
- font-weight: var(--rel-fontWeights-medium);
40
- border-radius: var(--rel-borders-radius-border-radius-100);
41
- padding: var(--rel-spacing-space-2xs) var(--rel-spacing-space-xs);
42
- gap: var(--rel-spacing-space-2xs);
69
+ font-weight: 500;
70
+ letter-spacing: -0.6px;
71
+ gap: 8px;
43
72
  cursor: pointer;
44
- border: var(--rel-borders-width-stroke-100) solid transparent;
45
73
  user-select: none;
46
74
  white-space: nowrap;
75
+ outline: none;
47
76
  background: transparent;
77
+ transition: background-color 0.15s ease;
48
78
  }
49
79
 
50
- .chip:hover {
51
- filter: brightness(0.88);
52
- box-shadow: var(--rel-shadows-shadow-100);
80
+ /* ── Size ── */
81
+ :host([size="lg"]) .chip {
82
+ height: 32px;
83
+ padding: 4px 8px;
84
+ font-size: 16px;
85
+ line-height: 24px;
53
86
  }
54
87
 
55
- .chip:focus-visible {
56
- outline: 2px solid var(--rel-color-border-focus);
57
- outline-offset: 2px;
88
+ :host([size="md"]) .chip {
89
+ height: 28px;
90
+ padding: 4px 8px;
91
+ font-size: 14px;
92
+ line-height: 22px;
58
93
  }
59
94
 
60
- .chip:active {
61
- filter: brightness(0.80);
62
- box-shadow: var(--rel-shadows-shadow-200);
95
+ :host([size="sm"]) .chip {
96
+ height: 24px;
97
+ padding: 4px 8px;
98
+ font-size: 12px;
99
+ line-height: 20px;
63
100
  }
64
101
 
65
- /* TONES — light (default) */
66
- /* NOTE: #717171 has no exact vars-v2 token; nearest candidates are
67
- --rel-colors-gray-toast-bg (#404040) and --rel-colors-gray-divider (#BDBDBD) */
68
- .chip-default {
69
- background: #717171;
70
- color: var(--rel-colors-white);
102
+ /* ── Border / shape — "Rounded" also widens horizontal padding to 12px,
103
+ consistent across all three sizes per the Figma spec. ── */
104
+ :host([border="default"]) .chip {
105
+ border-radius: 4px;
71
106
  }
72
107
 
73
- .chip-blue {
74
- background: var(--rel-colors-blue-tertiary);
75
- color: var(--rel-colors-white);
108
+ :host([border="rounded"]) .chip {
109
+ border-radius: 1000px;
110
+ padding-left: 12px;
111
+ padding-right: 12px;
76
112
  }
77
113
 
78
- .chip-orange {
79
- background: var(--rel-colors-yellow-pending);
80
- color: var(--rel-colors-white);
114
+ /* ── Tone x Variant — Default/Default state colors ── */
115
+ :host([tone="neutral"][variant="fill"]) .chip {
116
+ background: #0b0b0b;
117
+ color: #ffffff;
118
+ }
119
+ :host([tone="neutral"][variant="subtle"]) .chip {
120
+ background: #f5f5f5;
121
+ color: #0b0b0b;
122
+ }
123
+ :host([tone="danger"][variant="fill"]) .chip {
124
+ background: #f83b3b;
125
+ color: #ffffff;
126
+ }
127
+ :host([tone="danger"][variant="subtle"]) .chip {
128
+ background: #fff1f1;
129
+ color: #ce3131;
130
+ }
131
+ :host([tone="warning"][variant="fill"]) .chip {
132
+ background: #ffcb66;
133
+ color: #0b0b0b;
134
+ }
135
+ :host([tone="warning"][variant="subtle"]) .chip {
136
+ background: #ffefd1;
137
+ color: #713f12;
138
+ }
139
+ :host([tone="success"][variant="fill"]) .chip {
140
+ background: #00a86b;
141
+ color: #ffffff;
142
+ }
143
+ :host([tone="success"][variant="subtle"]) .chip {
144
+ background: #edf8f4;
145
+ color: #008655;
146
+ }
147
+ :host([tone="info"][variant="fill"]) .chip {
148
+ background: #0091ea;
149
+ color: #ffffff;
150
+ }
151
+ :host([tone="info"][variant="subtle"]) .chip {
152
+ background: #eff7ff;
153
+ color: #00528d;
81
154
  }
82
155
 
83
- .chip-red {
84
- background: var(--rel-colors-red-primary);
85
- color: var(--rel-colors-white);
156
+ /* ── Hover / Dragged — Figma only specs explicit color shifts for the
157
+ "neutral" tone; the other four tones have no hover/dragged sample to
158
+ match, so a generic brightness dim covers them instead of leaving
159
+ hover completely inert. Flagged in the handoff notes. ── */
160
+ :host([tone="neutral"][variant="fill"]) .chip:hover {
161
+ background: #363636;
162
+ }
163
+ :host([tone="neutral"][variant="fill"]) .chip:active,
164
+ :host([tone="neutral"][variant="fill"][dragging]) .chip {
165
+ background: #404040;
166
+ }
167
+ :host([tone="neutral"][variant="subtle"]) .chip:active,
168
+ :host([tone="neutral"][variant="subtle"][dragging]) .chip {
169
+ background: #e5e5e5;
86
170
  }
87
171
 
88
- .chip-green {
89
- background: var(--rel-colors-green-tertiary);
90
- color: var(--rel-colors-white);
172
+ :host(:not([tone="neutral"])) .chip:hover {
173
+ filter: brightness(0.96);
174
+ }
175
+ :host(:not([tone="neutral"])) .chip:active,
176
+ :host(:not([tone="neutral"])[dragging]) .chip {
177
+ filter: brightness(0.92);
91
178
  }
92
179
 
93
- /* AVATAR — light mode (all tones)
94
- rel-avatar uses background-color: var(--rel-colors-gray-disabled-text).
95
- Overriding that custom property here pins avatar bg to white across all tones.
96
- NOTE: rel-avatar hardcodes color: #ffffff — text color (#000000) cannot be
97
- overridden from outside the shadow DOM without ::part() or a custom property
98
- in rel-avatar itself. */
99
- .chip rel-avatar {
100
- display: inline-flex;
101
- width: 20px !important;
102
- height: 20px !important;
103
- flex-shrink: 0;
104
- font-size: 10px;
180
+ :host([dragging]) .chip {
181
+ cursor: grabbing;
105
182
  }
106
183
 
107
- .chip-default rel-avatar,
108
- .chip-blue rel-avatar,
109
- .chip-orange rel-avatar,
110
- .chip-red rel-avatar,
111
- .chip-green rel-avatar {
112
- --rel-colors-gray-disabled-text: #ffffff;
113
- --rel-avatar-color: #000000;
184
+ /* ── Focused — 1.5px outline, drawn outside (matches Figma's
185
+ strokeAlign:OUTSIDE) so it never affects layout. Same color
186
+ regardless of tone, per spec. OUTSIDE alignment means the stroke
187
+ sits flush against the shape's edge with zero gap, extending
188
+ outward by strokeWeight — outline-offset must be 0, not a positive
189
+ gap (a positive offset was the bug: it drew a visible gap that
190
+ doesn't exist in Figma). ── */
191
+ .chip:focus-visible {
192
+ outline: 1.5px solid var(--rel-chip-focus-ring, #0b0b0b);
193
+ outline-offset: 0;
114
194
  }
115
195
 
196
+ /* ── Icons ── */
197
+ /* rel-icon renders its SVG inside its own shadow root, so sizing has to
198
+ go through --rel-icon-size (a custom property — pierces shadow
199
+ boundaries) rather than a ".chip-icon svg" selector, which can never
200
+ reach across shadow DOM. */
116
201
  .chip-icon {
202
+ flex-shrink: 0;
203
+ }
204
+
205
+ :host([size="lg"]) .chip-icon {
206
+ --rel-icon-size: 16px;
207
+ }
208
+
209
+ :host([size="md"]) .chip-icon {
210
+ --rel-icon-size: 14px;
211
+ }
212
+
213
+ :host([size="sm"]) .chip-icon {
214
+ --rel-icon-size: 12px;
215
+ }
216
+
217
+ /* ── Avatar — not shown in the Figma sample. rel-avatar sizes its inner
218
+ .avatar div directly from its own "size" prop (fixed presets only —
219
+ no --rel-avatar-size custom property escape hatch like rel-icon has),
220
+ so a host-level width/height override here would only resize the
221
+ empty outer wrapper, not the actual painted circle. "xs" (20px) is
222
+ rel-avatar's smallest preset; used uniformly across all three chip
223
+ sizes since there's nothing smaller to ask for. ── */
224
+ .chip rel-avatar {
117
225
  display: inline-flex;
118
- align-items: center;
119
- justify-content: center;
120
- width: 16px;
121
- height: 16px;
122
226
  flex-shrink: 0;
123
227
  }
124
228
 
125
- .chip-icon * {
126
- width: 100%;
127
- height: 100%;
229
+ :host([variant="fill"]) .chip rel-avatar {
230
+ --rel-avatar-bg-fill: rgba(255, 255, 255, 0.25);
231
+ --rel-avatar-color-fill: #ffffff;
128
232
  }
129
233
 
130
- .chip-icon ::slotted(svg),
131
- .chip-icon svg {
132
- width: 16px;
133
- height: 16px;
134
- fill: currentColor;
234
+ :host([variant="subtle"]) .chip rel-avatar {
235
+ --rel-avatar-bg-fill: rgba(11, 11, 11, 0.12);
236
+ --rel-avatar-color-fill: currentColor;
135
237
  }
136
238
 
239
+ /* ── Remove (close) button ── */
137
240
  .chip-remove {
138
- margin-left: var(--rel-spacing-space-3xs);
241
+ display: inline-flex;
242
+ align-items: center;
243
+ justify-content: center;
244
+ flex-shrink: 0;
139
245
  cursor: pointer;
140
246
  opacity: 0.7;
141
247
  background: none;
@@ -151,78 +257,68 @@ export class RelChip extends LitElement {
151
257
  }
152
258
 
153
259
  .chip-remove:focus-visible {
154
- outline: 2px solid var(--rel-colors-white);
260
+ outline: 1.5px solid currentColor;
155
261
  outline-offset: 1px;
156
262
  border-radius: 2px;
157
263
  }
158
264
 
159
- /* DARK THEME */
160
- /* NOTE: #717171 (chip-default dark color) has no exact vars-v2 token */
161
- /* NOTE: #FFFBF5 (chip-orange dark bg) has no exact vars-v2 token;
162
- nearest is --rel-colors-gray-light (#FAFAFA) */
163
-
164
- /* Reinforce layout — external dark-mode stylesheets can override display/width on the host */
165
- :host-context([data-theme="dark"]) .chip {
166
- display: inline-flex;
167
- width: auto;
265
+ :host([size="lg"]) .chip-remove {
266
+ --rel-icon-size: 16px;
168
267
  }
169
-
170
- :host-context([data-theme="dark"]) .chip-default {
171
- /* --rel-colors-gray-screen-bg flips to #262626 in dark — hardcoded to preserve #EEEEEE */
172
- background: #EEEEEE;
173
- color: #717171;
268
+ :host([size="md"]) .chip-remove {
269
+ --rel-icon-size: 14px;
174
270
  }
175
-
176
- :host-context([data-theme="dark"]) .chip-blue {
177
- /* --rel-colors-blue-bg flips to #0f1e2c in dark mode — hardcoded to preserve #E1F2FF */
178
- background: #E1F2FF;
179
- color: var(--rel-colors-blue-tertiary);
271
+ :host([size="sm"]) .chip-remove {
272
+ --rel-icon-size: 12px;
180
273
  }
181
274
 
182
- :host-context([data-theme="dark"]) .chip-orange {
183
- background: #FFFBF5;
184
- color: var(--rel-colors-yellow-pending);
275
+ /* ── Dark mode — Figma had no dark-mode sample for this new component
276
+ set. Fill stays unchanged (the saturated tones already read fine on
277
+ dark surfaces); Subtle gets a dark-tinted background, following the
278
+ same invert pattern used elsewhere in this design system. Flagged in
279
+ the handoff notes — adjust if exact values exist.
280
+ No [data-theme="dark"] :host(...) fallback here — :host() can never
281
+ be preceded by a combinator, so that form is invalid and silently
282
+ matches nothing (the exact bug hit and fixed multiple times in
283
+ rel-avatar/rel-select earlier this session). :host-context() alone
284
+ has universal modern browser support, so no fallback is needed. ── */
285
+ :host-context([data-theme="dark"])[tone="neutral"][variant="subtle"] .chip {
286
+ background: #333333;
287
+ color: #f5f5f5;
185
288
  }
186
289
 
187
- :host-context([data-theme="dark"]) .chip-red {
188
- background: var(--rel-colors-red-light);
189
- color: var(--rel-colors-red-primary);
290
+ :host-context([data-theme="dark"])[tone="danger"][variant="subtle"] .chip {
291
+ background: #3d1414;
292
+ color: #ff8080;
190
293
  }
191
294
 
192
- :host-context([data-theme="dark"]) .chip-green {
193
- background: var(--rel-colors-green-bg-light);
194
- color: var(--rel-colors-green-tertiary);
295
+ :host-context([data-theme="dark"])[tone="warning"][variant="subtle"] .chip {
296
+ background: #3d2e0a;
297
+ color: #ffd980;
195
298
  }
196
299
 
197
- /* AVATAR — dark mode (per tone: bg = light fill color, text = white) */
198
- :host-context([data-theme="dark"]) .chip-default rel-avatar {
199
- --rel-colors-gray-disabled-text: #717171;
200
- --rel-avatar-color: #ffffff;
300
+ :host-context([data-theme="dark"])[tone="success"][variant="subtle"] .chip {
301
+ background: #0d2e22;
302
+ color: #4ddba3;
201
303
  }
202
304
 
203
- :host-context([data-theme="dark"]) .chip-blue rel-avatar {
204
- --rel-colors-gray-disabled-text: #0059F4;
205
- --rel-avatar-color: #ffffff;
305
+ :host-context([data-theme="dark"])[tone="info"][variant="subtle"] .chip {
306
+ background: #0a2e45;
307
+ color: #66c2ff;
206
308
  }
207
309
 
208
- :host-context([data-theme="dark"]) .chip-orange rel-avatar {
209
- --rel-colors-gray-disabled-text: #FFBF43;
210
- --rel-avatar-color: #ffffff;
310
+ :host-context([data-theme="dark"])[tone="neutral"][variant="fill"] .chip {
311
+ background: #f5f5f5;
312
+ color: #0b0b0b;
211
313
  }
212
314
 
213
- :host-context([data-theme="dark"]) .chip-red rel-avatar {
214
- --rel-colors-gray-disabled-text: #CC0000;
215
- --rel-avatar-color: #ffffff;
216
- }
217
-
218
- :host-context([data-theme="dark"]) .chip-green rel-avatar {
219
- --rel-colors-gray-disabled-text: #00A86B;
220
- --rel-avatar-color: #ffffff;
315
+ :host-context([data-theme="dark"]) .chip-remove:focus-visible {
316
+ outline-color: currentColor;
221
317
  }
222
318
  `;
223
319
 
224
320
  private get classes() {
225
- return ["chip", `chip-${this.tone}`].join(" ");
321
+ return "chip";
226
322
  }
227
323
 
228
324
  private handleRemove(event: Event) {
@@ -237,6 +333,34 @@ export class RelChip extends LitElement {
237
333
  );
238
334
  }
239
335
 
336
+ private onDragStart = (e: DragEvent) => {
337
+ if (!this.draggableChip) return;
338
+ this.dragging = true;
339
+ e.dataTransfer?.setData("text/plain", this.label);
340
+ };
341
+
342
+ private onDragEnd = () => {
343
+ this.dragging = false;
344
+ };
345
+
346
+ protected updated(changed: Map<string, unknown>) {
347
+ if (changed.has("draggableChip")) {
348
+ if (this.draggableChip) {
349
+ this.setAttribute("draggable", "true");
350
+ this.addEventListener("dragstart", this.onDragStart);
351
+ this.addEventListener("dragend", this.onDragEnd);
352
+ } else {
353
+ this.removeAttribute("draggable");
354
+ this.removeEventListener("dragstart", this.onDragStart);
355
+ this.removeEventListener("dragend", this.onDragEnd);
356
+ this.dragging = false;
357
+ }
358
+ }
359
+ if (changed.has("dragging")) {
360
+ this.toggleAttribute("dragging", this.dragging);
361
+ }
362
+ }
363
+
240
364
  render() {
241
365
  const showAvatar = !!this.avatar;
242
366
  const showLeadingIcon = !showAvatar && !!this.leadingIcon;
@@ -258,17 +382,13 @@ export class RelChip extends LitElement {
258
382
  ? html`<rel-avatar type="text" text=${this.avatar} size="xs"></rel-avatar>`
259
383
  : null}
260
384
  ${showLeadingIcon
261
- ? html`<span class="chip-icon">
262
- ${this.renderIcon(this.leadingIcon!)}
263
- </span>`
385
+ ? html`<rel-icon class="chip-icon" name="${this.leadingIcon}"></rel-icon>`
264
386
  : null}
265
387
 
266
388
  <span class="chip-label">${this.label}</span>
267
389
 
268
390
  ${this.trailingIcon
269
- ? html`<span class="chip-icon">
270
- ${this.renderIcon(this.trailingIcon)}
271
- </span>`
391
+ ? html`<rel-icon class="chip-icon" name="${this.trailingIcon}"></rel-icon>`
272
392
  : null}
273
393
  ${this.removable
274
394
  ? html`<button
@@ -276,16 +396,16 @@ export class RelChip extends LitElement {
276
396
  aria-label="Remove ${this.label}"
277
397
  @click=${this.handleRemove}
278
398
  >
279
- ✕
399
+ <rel-icon name="close"></rel-icon>
280
400
  </button>`
281
401
  : null}
282
402
  </span>
283
403
  `;
284
404
  }
405
+ }
285
406
 
286
- private renderIcon(iconString: string) {
287
- const template = document.createElement("template");
288
- template.innerHTML = iconString.trim();
289
- return template.content.cloneNode(true);
407
+ declare global {
408
+ interface HTMLElementTagNameMap {
409
+ "rel-chip": RelChip;
290
410
  }
291
411
  }
@@ -282,7 +282,10 @@ export class RelDrawer extends LitElement {
282
282
 
283
283
  if (this.modal) {
284
284
  this.updateComplete.then(() => {
285
- const focusTarget = this.shadowRoot?.querySelector<HTMLElement>("[autofocus], .close-button, .panel");
285
+ const focusTarget =
286
+ this.querySelector<HTMLElement>("[autofocus]") ??
287
+ this.querySelector<HTMLElement>(".close-button") ??
288
+ this.querySelector<HTMLElement>(".panel");
286
289
  focusTarget?.focus();
287
290
  });
288
291
  }
@@ -387,7 +390,7 @@ export class RelDrawer extends LitElement {
387
390
 
388
391
  const firstFocusable = focusable[0];
389
392
  const lastFocusable = focusable[focusable.length - 1];
390
- const activeElement = this.shadowRoot?.activeElement || document.activeElement;
393
+ const activeElement = document.activeElement;
391
394
 
392
395
  if (e.shiftKey) {
393
396
  if (activeElement === firstFocusable) {
@@ -44,6 +44,7 @@ export class RelMenubar extends LitElement {
44
44
  font-family: var(--rel-fontFamilies-primary);
45
45
  font-size: var(--rel-fontSizes-sm);
46
46
  height: 40px;
47
+ width: fit-content;
47
48
  }
48
49
 
49
50
  .menubar-trigger {