@ucalgary-design-system/chip-group 1.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/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # ChipGroup
2
+
3
+ This package provides the **ChipGroup** web component.
4
+
5
+ ## Installation
6
+
7
+ Install the component using npm:
8
+
9
+ ```sh
10
+ npm install @ucalgary-design-system/chip-group
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ Import the component into your application:
16
+
17
+ ```ts
18
+ import "@ucalgary-design-system/chip-group";
19
+ ```
20
+
21
+ Use the component in your HTML:
22
+
23
+ ```html
24
+ <ucds-chip-group></ucds-chip-group>
25
+ ```
26
+
27
+ ## Development
28
+
29
+ Build the component:
30
+
31
+ ```sh
32
+ npm run build
33
+ ```
34
+
35
+ Alternatively, build from the monorepo root:
36
+
37
+ ```sh
38
+ npm run build -w @ucalgary-design-system/ucds-chip-group
39
+ ```
40
+
41
+ Run storybook from the monorepo root.
42
+
43
+ ## Testing
44
+
45
+ Run the test from this package:
46
+
47
+ ```sh
48
+ npm run test
49
+ ```
50
+
51
+ Alternatively, run the tests from the monorepo root:
52
+
53
+ ```sh
54
+ npm run test -w @ucalgary-design-system/ucds-chip-group
55
+ ```
56
+
57
+
package/chip-group.css ADDED
@@ -0,0 +1 @@
1
+ :root{--ucds-color-palette-brand-red: #d6001c;--ucds-color-palette-brand-gold: #ffcd00;--ucds-color-palette-brand-light-orange: #ffa300;--ucds-color-palette-brand-dark-orange: #ff7b1f;--ucds-color-palette-brand-berry: #9c0534;--ucds-color-palette-brand-rubine: #ce0058;--ucds-color-palette-brand-brown: #6b3529;--ucds-color-palette-brand-teal: #47a67c;--ucds-color-palette-white: #ffffff;--ucds-color-palette-black: #000000;--ucds-color-palette-gray-100: #2d2d2d;--ucds-color-palette-gray-200: #3d3d3d;--ucds-color-palette-gray-250: #4d4d4d;--ucds-color-palette-gray-300: #5d5d5d;--ucds-color-palette-gray-400: #8d8d8d;--ucds-color-palette-gray-500: #adadad;--ucds-color-palette-gray-600: #c0c0c0;--ucds-color-palette-gray-700: #d8d8d8;--ucds-color-palette-gray-800: #e5e5e5;--ucds-color-palette-gray-900: #f4f4f4;--ucds-color-palette-red-100: #3d0910;--ucds-color-palette-red-200: #5c0e18;--ucds-color-palette-red-300: #7a111f;--ucds-color-palette-red-400: #991022;--ucds-color-palette-red-500: #b70b21;--ucds-color-palette-red-600: #d6001c;--ucds-color-palette-red-700: #df3047;--ucds-color-palette-red-800: #ee0e2c;--ucds-color-palette-red-900: #ffadad;--ucds-color-palette-berry-600: #9c0534;--ucds-color-palette-berry-700: #a6192e;--ucds-color-palette-berry-800: #ea7b8a;--ucds-color-palette-berry-900: #f6ebed;--ucds-color-palette-rubine-600: #ce0058;--ucds-color-palette-rubine-800: #ed0a72;--ucds-color-palette-rubine-900: #ffa3c9;--ucds-color-palette-dark-orange-200: #6b3529;--ucds-color-palette-dark-orange-600: #ff671f;--ucds-color-palette-dark-orange-900: #fff2e9;--ucds-color-palette-light-orange-200: #614e00;--ucds-color-palette-light-orange-600: #ffa300;--ucds-color-palette-light-orange-900: #fff6e7;--ucds-color-palette-brown-600: #6c3302;--ucds-color-palette-brown-900: #ca7d68;--ucds-color-surface-page: #ffffff;--ucds-color-surface-primary: #ffffff;--ucds-color-border-neutral: #8d8d8d;--ucds-color-text-primary: #2d2d2d;--ucds-color-text-primary-inverse: #ffffff;--ucds-color-text-secondary: #5d5d5d;--ucds-color-text-error: #df3047;--ucds-color-text-disabled: #e5e5e5;--ucds-color-icon-primary: #2d2d2d;--ucds-color-icon-primary-inverse: #ffffff;--ucds-color-forms-input-background-rest: #ffffff;--ucds-color-forms-input-background-hover: #9c0534;--ucds-color-forms-input-background-active: #9c0534;--ucds-color-forms-input-background-selected: #9c0534;--ucds-color-forms-input-background-disabled: #e5e5e5;--ucds-color-forms-input-background-error: rgb(255 173 173 / 50%);--ucds-color-forms-input-border-rest: #8d8d8d;--ucds-color-forms-input-border-hover: #3d3d3d;--ucds-color-forms-input-border-active: #3d3d3d;--ucds-color-forms-input-border-selected: #9c0534;--ucds-color-forms-input-border-disabled: #e5e5e5;--ucds-color-forms-input-border-error: #df3047;--ucds-color-forms-input-element-disabled: #f4f4f4;--ucds-color-action-rest: #d6001c;--ucds-color-action-hover: #991022;--ucds-color-action-active: #991022;--ucds-color-action-focus: #4d4d4d;--ucds-color-action-visited: #991022;--ucds-color-action-secondary-rest: #2d2d2d;--ucds-color-action-secondary-hover: #4d4d4d;--ucds-color-action-secondary-active: #4d4d4d;--ucds-color-action-secondary-focus: #4d4d4d;--ucds-color-action-inverse-rest: #ffffff;--ucds-color-action-inverse-hover: #e5e5e5;--ucds-color-action-inverse-active: #e5e5e5;--ucds-color-action-inverse-focus: #ffffff;--ucds-color-feedback-error-light: #df3047;--ucds-color-feedback-error-background-light: rgb(255 173 173 / 50%);--ucds-font-base-size: 16px;--ucds-font-base-line-height: 24px;--ucds-font-base-weight-light: 200;--ucds-font-base-weight-normal: 400;--ucds-font-base-weight-medium: 500;--ucds-font-base-weight-semibold: 600;--ucds-font-base-weight-bold: 700;--ucds-font-sans-serif-family: "Proxima Nova", Arial, Helvetica, sans-serif;--ucds-font-serif-family: "Museo Slab", "Proxima Nova", Arial, Helvetica, sans-serif;--ucds-form-element-border-radius: 8px;--ucds-form-element-border-width: 2px;--ucds-form-element-height: 48px;--ucds-form-element-width: 100%;--ucds-form-element-maxwidth: 555px;--ucds-form-element-horizontal-padding: 16px;--ucds-form-component-intra-spacing: 8px;--ucds-form-component-inter-spacing: 16px}
package/index.js ADDED
@@ -0,0 +1,349 @@
1
+ import { unsafeCSS as C, html as U } from "lit";
2
+ import { BaseElement as v } from "@ucalgary-design-system/core";
3
+ /**
4
+ * @license
5
+ * Copyright 2017 Google LLC
6
+ * SPDX-License-Identifier: BSD-3-Clause
7
+ */
8
+ const O = (r) => (t, e) => {
9
+ e !== void 0 ? e.addInitializer(() => {
10
+ customElements.define(r, t);
11
+ }) : customElements.define(r, t);
12
+ };
13
+ /**
14
+ * @license
15
+ * Copyright 2019 Google LLC
16
+ * SPDX-License-Identifier: BSD-3-Clause
17
+ */
18
+ const d = globalThis, m = d.ShadowRoot && (d.ShadyCSS === void 0 || d.ShadyCSS.nativeShadow) && "adoptedStyleSheets" in Document.prototype && "replace" in CSSStyleSheet.prototype, b = Symbol(), _ = /* @__PURE__ */ new WeakMap();
19
+ let A = class {
20
+ constructor(t, e, s) {
21
+ if (this._$cssResult$ = !0, s !== b) throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");
22
+ this.cssText = t, this.t = e;
23
+ }
24
+ get styleSheet() {
25
+ let t = this.o;
26
+ const e = this.t;
27
+ if (m && t === void 0) {
28
+ const s = e !== void 0 && e.length === 1;
29
+ s && (t = _.get(e)), t === void 0 && ((this.o = t = new CSSStyleSheet()).replaceSync(this.cssText), s && _.set(e, t));
30
+ }
31
+ return t;
32
+ }
33
+ toString() {
34
+ return this.cssText;
35
+ }
36
+ };
37
+ const R = (r) => new A(typeof r == "string" ? r : r + "", void 0, b), x = (r, t) => {
38
+ if (m) r.adoptedStyleSheets = t.map((e) => e instanceof CSSStyleSheet ? e : e.styleSheet);
39
+ else for (const e of t) {
40
+ const s = document.createElement("style"), i = d.litNonce;
41
+ i !== void 0 && s.setAttribute("nonce", i), s.textContent = e.cssText, r.appendChild(s);
42
+ }
43
+ }, E = m ? (r) => r : (r) => r instanceof CSSStyleSheet ? ((t) => {
44
+ let e = "";
45
+ for (const s of t.cssRules) e += s.cssText;
46
+ return R(e);
47
+ })(r) : r;
48
+ /**
49
+ * @license
50
+ * Copyright 2017 Google LLC
51
+ * SPDX-License-Identifier: BSD-3-Clause
52
+ */
53
+ const { is: M, defineProperty: k, getOwnPropertyDescriptor: z, getOwnPropertyNames: T, getOwnPropertySymbols: j, getPrototypeOf: L } = Object, a = globalThis, $ = a.trustedTypes, N = $ ? $.emptyScript : "", u = a.reactiveElementPolyfillSupport, l = (r, t) => r, f = { toAttribute(r, t) {
54
+ switch (t) {
55
+ case Boolean:
56
+ r = r ? N : null;
57
+ break;
58
+ case Object:
59
+ case Array:
60
+ r = r == null ? r : JSON.stringify(r);
61
+ }
62
+ return r;
63
+ }, fromAttribute(r, t) {
64
+ let e = r;
65
+ switch (t) {
66
+ case Boolean:
67
+ e = r !== null;
68
+ break;
69
+ case Number:
70
+ e = r === null ? null : Number(r);
71
+ break;
72
+ case Object:
73
+ case Array:
74
+ try {
75
+ e = JSON.parse(r);
76
+ } catch {
77
+ e = null;
78
+ }
79
+ }
80
+ return e;
81
+ } }, g = (r, t) => !M(r, t), S = { attribute: !0, type: String, converter: f, reflect: !1, hasChanged: g };
82
+ Symbol.metadata ?? (Symbol.metadata = Symbol("metadata")), a.litPropertyMetadata ?? (a.litPropertyMetadata = /* @__PURE__ */ new WeakMap());
83
+ class c extends HTMLElement {
84
+ static addInitializer(t) {
85
+ this._$Ei(), (this.l ?? (this.l = [])).push(t);
86
+ }
87
+ static get observedAttributes() {
88
+ return this.finalize(), this._$Eh && [...this._$Eh.keys()];
89
+ }
90
+ static createProperty(t, e = S) {
91
+ if (e.state && (e.attribute = !1), this._$Ei(), this.elementProperties.set(t, e), !e.noAccessor) {
92
+ const s = Symbol(), i = this.getPropertyDescriptor(t, s, e);
93
+ i !== void 0 && k(this.prototype, t, i);
94
+ }
95
+ }
96
+ static getPropertyDescriptor(t, e, s) {
97
+ const { get: i, set: n } = z(this.prototype, t) ?? { get() {
98
+ return this[e];
99
+ }, set(o) {
100
+ this[e] = o;
101
+ } };
102
+ return { get() {
103
+ return i == null ? void 0 : i.call(this);
104
+ }, set(o) {
105
+ const h = i == null ? void 0 : i.call(this);
106
+ n.call(this, o), this.requestUpdate(t, h, s);
107
+ }, configurable: !0, enumerable: !0 };
108
+ }
109
+ static getPropertyOptions(t) {
110
+ return this.elementProperties.get(t) ?? S;
111
+ }
112
+ static _$Ei() {
113
+ if (this.hasOwnProperty(l("elementProperties"))) return;
114
+ const t = L(this);
115
+ t.finalize(), t.l !== void 0 && (this.l = [...t.l]), this.elementProperties = new Map(t.elementProperties);
116
+ }
117
+ static finalize() {
118
+ if (this.hasOwnProperty(l("finalized"))) return;
119
+ if (this.finalized = !0, this._$Ei(), this.hasOwnProperty(l("properties"))) {
120
+ const e = this.properties, s = [...T(e), ...j(e)];
121
+ for (const i of s) this.createProperty(i, e[i]);
122
+ }
123
+ const t = this[Symbol.metadata];
124
+ if (t !== null) {
125
+ const e = litPropertyMetadata.get(t);
126
+ if (e !== void 0) for (const [s, i] of e) this.elementProperties.set(s, i);
127
+ }
128
+ this._$Eh = /* @__PURE__ */ new Map();
129
+ for (const [e, s] of this.elementProperties) {
130
+ const i = this._$Eu(e, s);
131
+ i !== void 0 && this._$Eh.set(i, e);
132
+ }
133
+ this.elementStyles = this.finalizeStyles(this.styles);
134
+ }
135
+ static finalizeStyles(t) {
136
+ const e = [];
137
+ if (Array.isArray(t)) {
138
+ const s = new Set(t.flat(1 / 0).reverse());
139
+ for (const i of s) e.unshift(E(i));
140
+ } else t !== void 0 && e.push(E(t));
141
+ return e;
142
+ }
143
+ static _$Eu(t, e) {
144
+ const s = e.attribute;
145
+ return s === !1 ? void 0 : typeof s == "string" ? s : typeof t == "string" ? t.toLowerCase() : void 0;
146
+ }
147
+ constructor() {
148
+ super(), this._$Ep = void 0, this.isUpdatePending = !1, this.hasUpdated = !1, this._$Em = null, this._$Ev();
149
+ }
150
+ _$Ev() {
151
+ var t;
152
+ this._$ES = new Promise((e) => this.enableUpdating = e), this._$AL = /* @__PURE__ */ new Map(), this._$E_(), this.requestUpdate(), (t = this.constructor.l) == null || t.forEach((e) => e(this));
153
+ }
154
+ addController(t) {
155
+ var e;
156
+ (this._$EO ?? (this._$EO = /* @__PURE__ */ new Set())).add(t), this.renderRoot !== void 0 && this.isConnected && ((e = t.hostConnected) == null || e.call(t));
157
+ }
158
+ removeController(t) {
159
+ var e;
160
+ (e = this._$EO) == null || e.delete(t);
161
+ }
162
+ _$E_() {
163
+ const t = /* @__PURE__ */ new Map(), e = this.constructor.elementProperties;
164
+ for (const s of e.keys()) this.hasOwnProperty(s) && (t.set(s, this[s]), delete this[s]);
165
+ t.size > 0 && (this._$Ep = t);
166
+ }
167
+ createRenderRoot() {
168
+ const t = this.shadowRoot ?? this.attachShadow(this.constructor.shadowRootOptions);
169
+ return x(t, this.constructor.elementStyles), t;
170
+ }
171
+ connectedCallback() {
172
+ var t;
173
+ this.renderRoot ?? (this.renderRoot = this.createRenderRoot()), this.enableUpdating(!0), (t = this._$EO) == null || t.forEach((e) => {
174
+ var s;
175
+ return (s = e.hostConnected) == null ? void 0 : s.call(e);
176
+ });
177
+ }
178
+ enableUpdating(t) {
179
+ }
180
+ disconnectedCallback() {
181
+ var t;
182
+ (t = this._$EO) == null || t.forEach((e) => {
183
+ var s;
184
+ return (s = e.hostDisconnected) == null ? void 0 : s.call(e);
185
+ });
186
+ }
187
+ attributeChangedCallback(t, e, s) {
188
+ this._$AK(t, s);
189
+ }
190
+ _$EC(t, e) {
191
+ var n;
192
+ const s = this.constructor.elementProperties.get(t), i = this.constructor._$Eu(t, s);
193
+ if (i !== void 0 && s.reflect === !0) {
194
+ const o = (((n = s.converter) == null ? void 0 : n.toAttribute) !== void 0 ? s.converter : f).toAttribute(e, s.type);
195
+ this._$Em = t, o == null ? this.removeAttribute(i) : this.setAttribute(i, o), this._$Em = null;
196
+ }
197
+ }
198
+ _$AK(t, e) {
199
+ var n;
200
+ const s = this.constructor, i = s._$Eh.get(t);
201
+ if (i !== void 0 && this._$Em !== i) {
202
+ const o = s.getPropertyOptions(i), h = typeof o.converter == "function" ? { fromAttribute: o.converter } : ((n = o.converter) == null ? void 0 : n.fromAttribute) !== void 0 ? o.converter : f;
203
+ this._$Em = i, this[i] = h.fromAttribute(e, o.type), this._$Em = null;
204
+ }
205
+ }
206
+ requestUpdate(t, e, s) {
207
+ if (t !== void 0) {
208
+ if (s ?? (s = this.constructor.getPropertyOptions(t)), !(s.hasChanged ?? g)(this[t], e)) return;
209
+ this.P(t, e, s);
210
+ }
211
+ this.isUpdatePending === !1 && (this._$ES = this._$ET());
212
+ }
213
+ P(t, e, s) {
214
+ this._$AL.has(t) || this._$AL.set(t, e), s.reflect === !0 && this._$Em !== t && (this._$Ej ?? (this._$Ej = /* @__PURE__ */ new Set())).add(t);
215
+ }
216
+ async _$ET() {
217
+ this.isUpdatePending = !0;
218
+ try {
219
+ await this._$ES;
220
+ } catch (e) {
221
+ Promise.reject(e);
222
+ }
223
+ const t = this.scheduleUpdate();
224
+ return t != null && await t, !this.isUpdatePending;
225
+ }
226
+ scheduleUpdate() {
227
+ return this.performUpdate();
228
+ }
229
+ performUpdate() {
230
+ var s;
231
+ if (!this.isUpdatePending) return;
232
+ if (!this.hasUpdated) {
233
+ if (this.renderRoot ?? (this.renderRoot = this.createRenderRoot()), this._$Ep) {
234
+ for (const [n, o] of this._$Ep) this[n] = o;
235
+ this._$Ep = void 0;
236
+ }
237
+ const i = this.constructor.elementProperties;
238
+ if (i.size > 0) for (const [n, o] of i) o.wrapped !== !0 || this._$AL.has(n) || this[n] === void 0 || this.P(n, this[n], o);
239
+ }
240
+ let t = !1;
241
+ const e = this._$AL;
242
+ try {
243
+ t = this.shouldUpdate(e), t ? (this.willUpdate(e), (s = this._$EO) == null || s.forEach((i) => {
244
+ var n;
245
+ return (n = i.hostUpdate) == null ? void 0 : n.call(i);
246
+ }), this.update(e)) : this._$EU();
247
+ } catch (i) {
248
+ throw t = !1, this._$EU(), i;
249
+ }
250
+ t && this._$AE(e);
251
+ }
252
+ willUpdate(t) {
253
+ }
254
+ _$AE(t) {
255
+ var e;
256
+ (e = this._$EO) == null || e.forEach((s) => {
257
+ var i;
258
+ return (i = s.hostUpdated) == null ? void 0 : i.call(s);
259
+ }), this.hasUpdated || (this.hasUpdated = !0, this.firstUpdated(t)), this.updated(t);
260
+ }
261
+ _$EU() {
262
+ this._$AL = /* @__PURE__ */ new Map(), this.isUpdatePending = !1;
263
+ }
264
+ get updateComplete() {
265
+ return this.getUpdateComplete();
266
+ }
267
+ getUpdateComplete() {
268
+ return this._$ES;
269
+ }
270
+ shouldUpdate(t) {
271
+ return !0;
272
+ }
273
+ update(t) {
274
+ this._$Ej && (this._$Ej = this._$Ej.forEach((e) => this._$EC(e, this[e]))), this._$EU();
275
+ }
276
+ updated(t) {
277
+ }
278
+ firstUpdated(t) {
279
+ }
280
+ }
281
+ c.elementStyles = [], c.shadowRootOptions = { mode: "open" }, c[l("elementProperties")] = /* @__PURE__ */ new Map(), c[l("finalized")] = /* @__PURE__ */ new Map(), u == null || u({ ReactiveElement: c }), (a.reactiveElementVersions ?? (a.reactiveElementVersions = [])).push("2.0.4");
282
+ /**
283
+ * @license
284
+ * Copyright 2017 Google LLC
285
+ * SPDX-License-Identifier: BSD-3-Clause
286
+ */
287
+ const D = (r, t, e) => (e.configurable = !0, e.enumerable = !0, Reflect.decorate && typeof t != "object" && Object.defineProperty(r, t, e), e);
288
+ /**
289
+ * @license
290
+ * Copyright 2021 Google LLC
291
+ * SPDX-License-Identifier: BSD-3-Clause
292
+ */
293
+ function q(r) {
294
+ return (t, e) => {
295
+ const { slot: s, selector: i } = {}, n = "slot" + (s ? `[name=${s}]` : ":not([name])");
296
+ return D(t, e, { get() {
297
+ var y;
298
+ const o = (y = this.renderRoot) == null ? void 0 : y.querySelector(n), h = (o == null ? void 0 : o.assignedElements(r)) ?? [];
299
+ return i === void 0 ? h : h.filter((w) => w.matches(i));
300
+ } });
301
+ };
302
+ }
303
+ const B = ":host{display:block}.chip-group{display:flex;flex-direction:row;flex-wrap:wrap;align-items:center;gap:16px}";
304
+ var H = Object.defineProperty, I = Object.getOwnPropertyDescriptor, P = (r, t, e, s) => {
305
+ for (var i = s > 1 ? void 0 : s ? I(t, e) : t, n = r.length - 1, o; n >= 0; n--)
306
+ (o = r[n]) && (i = (s ? o(t, e, i) : o(i)) || i);
307
+ return s && i && H(t, e, i), i;
308
+ };
309
+ let p = class extends v {
310
+ // Focus the next sibling of the Chip being removed.
311
+ _focusNextSiblingOf(r) {
312
+ const t = this._defaultSlotNodes, e = t.indexOf(r);
313
+ if (e >= 0) {
314
+ const s = t[e + 1] || t[e - 1];
315
+ s instanceof HTMLElement && s.focus();
316
+ }
317
+ }
318
+ // Capture the removal of a child Chip.
319
+ _onChildRemove(r) {
320
+ const t = r.detail.element;
321
+ this._focusNextSiblingOf(t);
322
+ }
323
+ connectedCallback() {
324
+ super.connectedCallback && super.connectedCallback(), this.addEventListener("chipRemoved", this._onChildRemove);
325
+ }
326
+ disconnectedCallback() {
327
+ super.disconnectedCallback && super.disconnectedCallback(), this.removeEventListener("chipRemoved", this._onChildRemove);
328
+ }
329
+ render() {
330
+ return U`
331
+ <div class="chip-group">
332
+ <slot></slot>
333
+ </div>
334
+ `;
335
+ }
336
+ };
337
+ p.styles = [
338
+ v.styles,
339
+ C(B)
340
+ ];
341
+ P([
342
+ q()
343
+ ], p.prototype, "_defaultSlotNodes", 2);
344
+ p = P([
345
+ O("ucds-chip-group")
346
+ ], p);
347
+ export {
348
+ p as ChipGroup
349
+ };
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@ucalgary-design-system/chip-group",
3
+ "version": "1.0.1",
4
+ "type": "module",
5
+ "main": "index.js",
6
+ "module": "index.js",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./index.js",
10
+ "require": "./index.js"
11
+ }
12
+ },
13
+ "dependencies": {
14
+ "@ucalgary-design-system/core": "^1.0.1",
15
+ "@ucalgary-design-system/tokens": "^1.0.1",
16
+ "lit": "^3.2.1"
17
+ },
18
+ "description": "A web component for ChipGroup",
19
+ "publishConfig": {
20
+ "access": "public"
21
+ }
22
+ }