@exmg/exm-chip-input 1.0.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.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # `<exm-chip-input>` https://www.npmjs.com/package/@exmg/exm-chip-input
package/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export { ExmgChipInput } from './src/exm-chip-input.js';
2
+ export { ExmgChip } from './src/exm-chip.js';
3
+ export { ExmgChipInputDropdown } from './src/exm-chip-input-dropdown.js';
4
+ export { style as chipInputStyles } from './src/styles/exm-chip-input-css.js';
package/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export { ExmgChipInput } from './src/exm-chip-input.js';
2
+ export { ExmgChip } from './src/exm-chip.js';
3
+ export { ExmgChipInputDropdown } from './src/exm-chip-input-dropdown.js';
4
+ export { style as chipInputStyles } from './src/styles/exm-chip-input-css.js';
5
+ //# sourceMappingURL=index.js.map
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@exmg/exm-chip-input",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "main": "index.js",
6
+ "module": "index.js",
7
+ "exports": {
8
+ ".": "./index.js",
9
+ "./exm-chip-input.js": "./src/exm-chip-input.js",
10
+ "./exm-chip-input-dropdown.js": "./src/exm-chip-input-dropdown.js",
11
+ "./exm-chip.js": "./src/exm-chip.js"
12
+ },
13
+ "dependencies": {
14
+ "@exmg/lit-base": "^2.0.1",
15
+ "@material/web": "^1.3.0",
16
+ "lit": "^3.0.0",
17
+ "tslib": "^2.6.2"
18
+ },
19
+ "devDependencies": {
20
+ "@exmg/lit-cli": "1.1.13"
21
+ },
22
+ "keywords": [
23
+ "web-components",
24
+ "lit",
25
+ "chip",
26
+ "input"
27
+ ],
28
+ "files": [
29
+ "**/*.scss",
30
+ "**/*.js",
31
+ "**/*.d.ts"
32
+ ],
33
+ "homepage": "https://github.com/exmg/exmachina-web-components",
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "git@github.com:exmg/exm-web-components.git",
37
+ "directory": "packages/exm-chip-input"
38
+ },
39
+ "license": "MIT",
40
+ "scripts": {
41
+ "build:styles": "exmg-lit-cli sass -f \"./**/*.scss\""
42
+ },
43
+ "publishConfig": {
44
+ "access": "public"
45
+ },
46
+ "gitHead": "0907b55c89325d59902b98a64c352bf6e1fc81ff"
47
+ }
@@ -0,0 +1,6 @@
1
+ import { LitElement } from 'lit';
2
+ export declare class DropdownContainer extends LitElement {
3
+ dropdownTitle: string;
4
+ static styles: import("lit").CSSResult[];
5
+ render(): import("lit-html").TemplateResult<1>;
6
+ }
@@ -0,0 +1,39 @@
1
+ import { __decorate } from "tslib";
2
+ import { LitElement, html, css } from 'lit';
3
+ import { customElement, property } from 'lit/decorators.js';
4
+ let DropdownContainer = class DropdownContainer extends LitElement {
5
+ constructor() {
6
+ super(...arguments);
7
+ this.dropdownTitle = 'Select items';
8
+ }
9
+ render() {
10
+ return html `<div class="container">
11
+ <div class="label">${this.dropdownTitle}</div>
12
+ <div class="items"><slot></slot></div>
13
+ </div>`;
14
+ }
15
+ };
16
+ DropdownContainer.styles = [
17
+ css `
18
+ :host {
19
+ display: block;
20
+ padding: 0 1rem 0.5rem;
21
+ }
22
+ .label {
23
+ margin-bottom: 0.5rem;
24
+ }
25
+ .items {
26
+ display: flex;
27
+ flex-wrap: wrap;
28
+ gap: 0.3rem;
29
+ }
30
+ `,
31
+ ];
32
+ __decorate([
33
+ property({ type: String })
34
+ ], DropdownContainer.prototype, "dropdownTitle", void 0);
35
+ DropdownContainer = __decorate([
36
+ customElement('dropdown-container')
37
+ ], DropdownContainer);
38
+ export { DropdownContainer };
39
+ //# sourceMappingURL=dropdown-container.js.map
@@ -0,0 +1,34 @@
1
+ import '@material/web/iconbutton/icon-button.js';
2
+ import '@material/web/button/text-button.js';
3
+ import '@material/web/chips/input-chip.js';
4
+ import '@material/web/icon/icon.js';
5
+ import '@material/web/menu/menu.js';
6
+ import './dropdown/dropdown-container.js';
7
+ import { ChipSet } from '@material/web/chips/internal/chip-set.js';
8
+ import { ExmgChip } from './exm-chip.js';
9
+ declare global {
10
+ interface HTMLElementTagNameMap {
11
+ 'exm-chip-input-dropdown': ExmgChipInputDropdown;
12
+ }
13
+ }
14
+ /**
15
+ *
16
+ * @final
17
+ * @suppress {visibility}
18
+ */
19
+ export declare class ExmgChipInputDropdown extends ChipSet {
20
+ label: string;
21
+ dropdownTitle: string;
22
+ btnAddText: string;
23
+ selectedChips?: ExmgChip[];
24
+ private menuOpen;
25
+ static styles: import("lit").CSSResult[];
26
+ constructor();
27
+ private _onSelect;
28
+ private onOpenClick;
29
+ private onMenuClosed;
30
+ private _removeSelected;
31
+ private onKeydown;
32
+ protected render(): import("lit-html").TemplateResult<1>;
33
+ private updateTabIndicesOverride;
34
+ }
@@ -0,0 +1,154 @@
1
+ import { __decorate } from "tslib";
2
+ import { customElement } from 'lit/decorators/custom-element.js';
3
+ import '@material/web/iconbutton/icon-button.js';
4
+ import '@material/web/button/text-button.js';
5
+ import '@material/web/chips/input-chip.js';
6
+ import '@material/web/icon/icon.js';
7
+ import '@material/web/menu/menu.js';
8
+ import './dropdown/dropdown-container.js';
9
+ import { ChipSet } from '@material/web/chips/internal/chip-set.js';
10
+ import { html } from 'lit';
11
+ import { property, state } from 'lit/decorators.js';
12
+ import { repeat } from 'lit/directives/repeat.js';
13
+ import { style } from './styles/exm-chip-input-dropdown-css.js';
14
+ /**
15
+ *
16
+ * @final
17
+ * @suppress {visibility}
18
+ */
19
+ let ExmgChipInputDropdown = class ExmgChipInputDropdown extends ChipSet {
20
+ constructor() {
21
+ super();
22
+ this.label = '';
23
+ this.dropdownTitle = 'Select items';
24
+ this.btnAddText = 'Add items';
25
+ this.menuOpen = false;
26
+ // Add event listeners in the constructor
27
+ this.addEventListener('click', this._onSelect);
28
+ }
29
+ _onSelect(e) {
30
+ const clickedElement = e.target;
31
+ const elementType = clickedElement.tagName;
32
+ if (elementType === 'exm-CHIP') {
33
+ // @ts-ignore
34
+ this.selectedChips = this.chips.filter((chip) => chip.selected);
35
+ }
36
+ }
37
+ onOpenClick() {
38
+ this.menuOpen = true;
39
+ }
40
+ onMenuClosed() {
41
+ this.menuOpen = false;
42
+ }
43
+ _removeSelected(val) {
44
+ const index = (this.selectedChips || []).findIndex((el) => el.value === val);
45
+ if (index > -1) {
46
+ (this.selectedChips || []).splice(index, 1); // 2nd parameter means remove one item only
47
+ // @ts-ignore
48
+ const chip = this.chips.find((el) => el.value === val);
49
+ if (chip) {
50
+ // @ts-ignore
51
+ chip.selected = false;
52
+ setTimeout(() => chip.dispatchEvent(new CustomEvent('blur', { bubbles: true, composed: true })), 0);
53
+ }
54
+ }
55
+ }
56
+ onKeydown(e) {
57
+ if (!e.defaultPrevented && e.key === 'Escape') {
58
+ e.preventDefault();
59
+ this.menuOpen = false;
60
+ }
61
+ }
62
+ render() {
63
+ return html `<div class="container">
64
+ <div class="label">${this.label}</div>
65
+ <div class="input-container">
66
+ <div class="selected-chips">
67
+ ${repeat(this.selectedChips || [], (c) => c.value, (c) => html `<md-input-chip
68
+ label="${c.label}"
69
+ data-value=${c.value}
70
+ selected
71
+ @remove=${() => this._removeSelected(c.value)}
72
+ ></md-input-chip>`)}
73
+ </div>
74
+ <div class="add">
75
+ <md-text-button
76
+ id="button"
77
+ @click="${this.onOpenClick}"
78
+ title="${this.dropdownTitle} controls"
79
+ aria-label="${this.dropdownTitle} controls"
80
+ aria-haspopup="dialog"
81
+ aria-expanded=${this.menuOpen ? 'true' : 'false'}
82
+ >
83
+ ${this.btnAddText}
84
+ <md-icon slot="icon">add</md-icon>
85
+ </md-text-button>
86
+ </div>
87
+ <md-menu
88
+ anchor="button"
89
+ menu-corner="start-start"
90
+ anchor-corner="end-start"
91
+ default-focus="none"
92
+ role="dialog"
93
+ aria-label="${this.dropdownTitle} controls"
94
+ .open=${this.menuOpen}
95
+ @closed=${this.onMenuClosed}
96
+ @keydown=${this.onKeydown}
97
+ >
98
+ <dropdown-container .dropdownTitle=${this.dropdownTitle}
99
+ ><slot @slotchange=${this.updateTabIndicesOverride}></slot
100
+ ></dropdown-container>
101
+ </md-menu>
102
+ </div>
103
+ </div>`;
104
+ }
105
+ updateTabIndicesOverride() {
106
+ // The chip that should be focusable is either the chip that currently has
107
+ // focus or the first chip that can be focused.
108
+ const { chips } = this;
109
+ // update selected array after dom change
110
+ // @ts-ignore
111
+ this.selectedChips = this.chips.filter((chip) => chip.selected);
112
+ let chipToFocus;
113
+ for (const chip of chips) {
114
+ const isChipFocusable = chip.alwaysFocusable || !chip.disabled;
115
+ const chipIsFocused = chip.matches(':focus-within');
116
+ if (chipIsFocused && isChipFocusable) {
117
+ // Found the first chip that is actively focused. This overrides the
118
+ // first focusable chip found.
119
+ chipToFocus = chip;
120
+ continue;
121
+ }
122
+ if (isChipFocusable && !chipToFocus) {
123
+ chipToFocus = chip;
124
+ }
125
+ // Disable non-focused chips. If we disable all of them, we'll grant focus
126
+ // to the first focusable child that was found.
127
+ chip.tabIndex = -1;
128
+ }
129
+ if (chipToFocus) {
130
+ chipToFocus.tabIndex = 0;
131
+ }
132
+ }
133
+ };
134
+ ExmgChipInputDropdown.styles = [style];
135
+ __decorate([
136
+ property({ type: String })
137
+ ], ExmgChipInputDropdown.prototype, "label", void 0);
138
+ __decorate([
139
+ property({ type: String })
140
+ ], ExmgChipInputDropdown.prototype, "dropdownTitle", void 0);
141
+ __decorate([
142
+ property({ type: String })
143
+ ], ExmgChipInputDropdown.prototype, "btnAddText", void 0);
144
+ __decorate([
145
+ property({ type: Array })
146
+ ], ExmgChipInputDropdown.prototype, "selectedChips", void 0);
147
+ __decorate([
148
+ state()
149
+ ], ExmgChipInputDropdown.prototype, "menuOpen", void 0);
150
+ ExmgChipInputDropdown = __decorate([
151
+ customElement('exm-chip-input-dropdown')
152
+ ], ExmgChipInputDropdown);
153
+ export { ExmgChipInputDropdown };
154
+ //# sourceMappingURL=exm-chip-input-dropdown.js.map
@@ -0,0 +1,17 @@
1
+ import { ChipSet } from '@material/web/chips/internal/chip-set.js';
2
+ declare global {
3
+ interface HTMLElementTagNameMap {
4
+ 'exm-chip-input': ExmgChipInput;
5
+ }
6
+ }
7
+ /**
8
+ *
9
+ * @final
10
+ * @suppress {visibility}
11
+ */
12
+ export declare class ExmgChipInput extends ChipSet {
13
+ label: string;
14
+ static styles: import("lit").CSSResult[];
15
+ protected render(): import("lit-html").TemplateResult<1>;
16
+ private updateTabIndicesOverride;
17
+ }
@@ -0,0 +1,58 @@
1
+ import { __decorate } from "tslib";
2
+ import { customElement } from 'lit/decorators/custom-element.js';
3
+ import { style } from './styles/exm-chip-input-css.js';
4
+ import { ChipSet } from '@material/web/chips/internal/chip-set.js';
5
+ import { styles } from '@material/web/chips/internal/chip-set-styles.js';
6
+ import { html } from 'lit';
7
+ import { property } from 'lit/decorators.js';
8
+ /**
9
+ *
10
+ * @final
11
+ * @suppress {visibility}
12
+ */
13
+ let ExmgChipInput = class ExmgChipInput extends ChipSet {
14
+ constructor() {
15
+ super(...arguments);
16
+ this.label = '';
17
+ }
18
+ render() {
19
+ return html `<div class="container">
20
+ <div class="label">${this.label}</div>
21
+ <div class="items"><slot @slotchange=${this.updateTabIndicesOverride}></slot></div>
22
+ </div>`;
23
+ }
24
+ updateTabIndicesOverride() {
25
+ // The chip that should be focusable is either the chip that currently has
26
+ // focus or the first chip that can be focused.
27
+ const { chips } = this;
28
+ let chipToFocus;
29
+ for (const chip of chips) {
30
+ const isChipFocusable = chip.alwaysFocusable || !chip.disabled;
31
+ const chipIsFocused = chip.matches(':focus-within');
32
+ if (chipIsFocused && isChipFocusable) {
33
+ // Found the first chip that is actively focused. This overrides the
34
+ // first focusable chip found.
35
+ chipToFocus = chip;
36
+ continue;
37
+ }
38
+ if (isChipFocusable && !chipToFocus) {
39
+ chipToFocus = chip;
40
+ }
41
+ // Disable non-focused chips. If we disable all of them, we'll grant focus
42
+ // to the first focusable child that was found.
43
+ chip.tabIndex = -1;
44
+ }
45
+ if (chipToFocus) {
46
+ chipToFocus.tabIndex = 0;
47
+ }
48
+ }
49
+ };
50
+ ExmgChipInput.styles = [styles, style];
51
+ __decorate([
52
+ property({ type: String })
53
+ ], ExmgChipInput.prototype, "label", void 0);
54
+ ExmgChipInput = __decorate([
55
+ customElement('exm-chip-input')
56
+ ], ExmgChipInput);
57
+ export { ExmgChipInput };
58
+ //# sourceMappingURL=exm-chip-input.js.map
@@ -0,0 +1,51 @@
1
+ import { FilterChip } from '@material/web/chips/internal/filter-chip.js';
2
+ import { createValidator, getValidityAnchor } from '@material/web/labs/behaviors/constraint-validation.js';
3
+ import { getFormState, getFormValue } from '@material/web/labs/behaviors/form-associated.js';
4
+ import { ChipValidator } from './validator/chip-validator.js';
5
+ declare global {
6
+ interface HTMLElementTagNameMap {
7
+ 'exm-chip': ExmgChip;
8
+ }
9
+ }
10
+ declare const CHECKED: unique symbol;
11
+ declare const FilterChipBaseClass: import("@material/web/labs/behaviors/mixin.js").MixinReturn<import("@material/web/labs/behaviors/mixin.js").MixinReturn<(abstract new (...args: any[]) => import("@material/web/labs/behaviors/element-internals.js").WithElementInternals) & (abstract new (...args: any[]) => import("@material/web/labs/behaviors/focusable.js").Focusable) & typeof FilterChip & import("@material/web/labs/behaviors/form-associated.js").FormAssociatedConstructor, import("@material/web/labs/behaviors/form-associated.js").FormAssociated>, import("@material/web/labs/behaviors/constraint-validation.js").ConstraintValidation>;
12
+ /**
13
+ *
14
+ * @final
15
+ * @suppress {visibility}
16
+ */
17
+ export declare class ExmgChip extends FilterChipBaseClass {
18
+ static styles: import("lit").CSSResult[];
19
+ removable: boolean;
20
+ selected: boolean;
21
+ /**
22
+ * Whether or not the radio is selected.
23
+ */
24
+ get checked(): boolean;
25
+ set checked(checked: boolean);
26
+ [CHECKED]: boolean;
27
+ private selectionController;
28
+ /**
29
+ * Whether or not the radio is required. If any radio is required in a group,
30
+ * all radios are implicitly required.
31
+ */
32
+ required: boolean;
33
+ /**
34
+ * The element value to use in form submission when checked.
35
+ */
36
+ value: string;
37
+ private readonly container;
38
+ disabled: boolean;
39
+ name: string;
40
+ [getFormValue](): string | null;
41
+ [getFormState](): string;
42
+ constructor();
43
+ formResetCallback(): void;
44
+ formStateRestoreCallback(state: string): void;
45
+ protected updated(): void;
46
+ protected renderPrimaryAction(content: unknown): import("lit-html").TemplateResult<1>;
47
+ private _handleClick;
48
+ [createValidator](): ChipValidator;
49
+ [getValidityAnchor](): HTMLElement;
50
+ }
51
+ export {};
@@ -0,0 +1,149 @@
1
+ var _a;
2
+ import { __decorate } from "tslib";
3
+ import { customElement, property, query } from 'lit/decorators.js';
4
+ import { styles as elevatedStyles } from '@material/web/chips/internal/elevated-styles.js';
5
+ import { FilterChip } from '@material/web/chips/internal/filter-chip.js';
6
+ import { styles } from '@material/web/chips/internal/filter-styles.js';
7
+ import { styles as selectableStyles } from '@material/web/chips/internal/selectable-styles.js';
8
+ import { styles as sharedStyles } from '@material/web/chips/internal/shared-styles.js';
9
+ import { styles as trailingIconStyles } from '@material/web/chips/internal/trailing-icon-styles.js';
10
+ import { redispatchEvent } from '@material/web/internal/events/redispatch-event.js';
11
+ import { createValidator, getValidityAnchor, mixinConstraintValidation, } from '@material/web/labs/behaviors/constraint-validation.js';
12
+ import { getFormState, getFormValue, mixinFormAssociated } from '@material/web/labs/behaviors/form-associated.js';
13
+ import { internals, mixinElementInternals } from '@material/web/labs/behaviors/element-internals.js';
14
+ import { mixinFocusable } from '@material/web/labs/behaviors/focusable.js';
15
+ import { ChipValidator } from './validator/chip-validator.js';
16
+ import { observer } from '@exmg/lit-base';
17
+ import { SelectionController } from './selection-controller.js';
18
+ import { html, nothing } from 'lit';
19
+ const CHECKED = Symbol('checked');
20
+ // Separate variable needed for closure.
21
+ const FilterChipBaseClass = mixinConstraintValidation(mixinFormAssociated(mixinElementInternals(mixinFocusable(FilterChip))));
22
+ /**
23
+ *
24
+ * @final
25
+ * @suppress {visibility}
26
+ */
27
+ let ExmgChip = class ExmgChip extends FilterChipBaseClass {
28
+ /**
29
+ * Whether or not the radio is selected.
30
+ */
31
+ get checked() {
32
+ return this[CHECKED];
33
+ }
34
+ set checked(checked) {
35
+ const wasChecked = this.checked;
36
+ if (wasChecked === checked) {
37
+ return;
38
+ }
39
+ this[CHECKED] = checked;
40
+ this.requestUpdate('checked', wasChecked);
41
+ }
42
+ [(_a = CHECKED, getFormValue)]() {
43
+ return this.checked ? this.value : null;
44
+ }
45
+ [getFormState]() {
46
+ return String(this.checked);
47
+ }
48
+ constructor() {
49
+ super();
50
+ this.removable = false;
51
+ this.selected = false;
52
+ this[_a] = false;
53
+ this.selectionController = new SelectionController(this);
54
+ /**
55
+ * Whether or not the radio is required. If any radio is required in a group,
56
+ * all radios are implicitly required.
57
+ */
58
+ this.required = false;
59
+ /**
60
+ * The element value to use in form submission when checked.
61
+ */
62
+ this.value = 'on';
63
+ this.addController(this.selectionController);
64
+ this[internals].role = 'radio';
65
+ }
66
+ formResetCallback() {
67
+ // The checked property does not reflect, so the original attribute set by
68
+ // the user is used to determine the default value.
69
+ this.checked = this.hasAttribute('checked');
70
+ }
71
+ formStateRestoreCallback(state) {
72
+ this.checked = state === 'true';
73
+ }
74
+ updated() {
75
+ this[internals].ariaChecked = String(this.checked);
76
+ }
77
+ renderPrimaryAction(content) {
78
+ const { ariaLabel } = this;
79
+ return html `
80
+ <button
81
+ class="primary action"
82
+ id="button"
83
+ aria-label=${ariaLabel || nothing}
84
+ aria-pressed=${this.selected}
85
+ ?disabled=${this.disabled && !this.alwaysFocusable}
86
+ @click=${this._handleClick}
87
+ >
88
+ ${content}
89
+ </button>
90
+ `;
91
+ }
92
+ _handleClick(event) {
93
+ if (this.disabled) {
94
+ return;
95
+ }
96
+ // Store prevValue to revert in case `chip.selected` is changed during an
97
+ // event listener.
98
+ const prevValue = this.selected;
99
+ this.selected = !this.selected;
100
+ const preventDefault = !redispatchEvent(this, event);
101
+ if (preventDefault) {
102
+ // We should not do `this.selected = !this.selected`, since a client
103
+ // click listener could change its value. Instead, always revert to the
104
+ // original value.
105
+ this.selected = prevValue;
106
+ return;
107
+ }
108
+ }
109
+ [createValidator]() {
110
+ return new ChipValidator(() => {
111
+ if (!this.selectionController) {
112
+ // Validation runs on superclass construction, so selection controller
113
+ // might not actually be ready until this class constructs.
114
+ return [this];
115
+ }
116
+ return this.selectionController.controls;
117
+ });
118
+ }
119
+ [getValidityAnchor]() {
120
+ return this.container;
121
+ }
122
+ };
123
+ ExmgChip.styles = [sharedStyles, elevatedStyles, trailingIconStyles, selectableStyles, styles];
124
+ __decorate([
125
+ property({ type: Boolean })
126
+ ], ExmgChip.prototype, "removable", void 0);
127
+ __decorate([
128
+ property({ type: Boolean, reflect: true }),
129
+ observer(function (selected) {
130
+ this.checked = selected;
131
+ })
132
+ ], ExmgChip.prototype, "selected", void 0);
133
+ __decorate([
134
+ property({ type: Boolean })
135
+ ], ExmgChip.prototype, "checked", null);
136
+ __decorate([
137
+ property({ type: Boolean })
138
+ ], ExmgChip.prototype, "required", void 0);
139
+ __decorate([
140
+ property()
141
+ ], ExmgChip.prototype, "value", void 0);
142
+ __decorate([
143
+ query('.container')
144
+ ], ExmgChip.prototype, "container", void 0);
145
+ ExmgChip = __decorate([
146
+ customElement('exm-chip')
147
+ ], ExmgChip);
148
+ export { ExmgChip };
149
+ //# sourceMappingURL=exm-chip.js.map
@@ -0,0 +1,68 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { ReactiveController } from 'lit';
7
+ /**
8
+ * An element that supports single-selection with `SelectionController`.
9
+ */
10
+ export interface SelectionElement extends HTMLElement {
11
+ /**
12
+ * Whether or not the element is selected.
13
+ */
14
+ checked: boolean;
15
+ }
16
+ /**
17
+ * A `ReactiveController` that provides root node-scoped selection for
18
+ * elements, similar to native `<input type="radio">` selection.
19
+ *
20
+ * @example
21
+ * const CHECKED = Symbol('checked');
22
+ *
23
+ * class MyChip extends LitElement {
24
+ * @property({ type: Boolean }) removable = false;
25
+ *
26
+ * @property({ type: Boolean, reflect: true })
27
+ * @observer(function (this: ExmgChip, selected: boolean) {
28
+ * this.checked = selected;
29
+ * })
30
+ * selected = false;
31
+ *
32
+ * @property({ type: Boolean })
33
+ * get checked() {
34
+ * return this[CHECKED];
35
+ * }
36
+ * set checked(checked: boolean) {
37
+ * const wasChecked = this.checked;
38
+ * if (wasChecked === checked) {
39
+ * return;
40
+ * }
41
+ * console.log('checked', checked);
42
+ *
43
+ * this[CHECKED] = checked;
44
+ * this.requestUpdate('checked', wasChecked);
45
+ * }
46
+ *
47
+ * [CHECKED] = false;
48
+ *
49
+ * private selectionController = new SelectionController(this);
50
+ *
51
+ * constructor() {
52
+ * super();
53
+ * this.addController(this.selectionController);
54
+ * }
55
+ * }
56
+ */
57
+ export declare class SelectionController implements ReactiveController {
58
+ private readonly host;
59
+ /**
60
+ * All selection elements in the host element's root with the same
61
+ * `name` attribute, including the host element.
62
+ */
63
+ get controls(): [SelectionElement, ...SelectionElement[]];
64
+ private root;
65
+ constructor(host: SelectionElement);
66
+ hostConnected(): void;
67
+ hostDisconnected(): void;
68
+ }
@@ -0,0 +1,74 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * A `ReactiveController` that provides root node-scoped selection for
8
+ * elements, similar to native `<input type="radio">` selection.
9
+ *
10
+ * @example
11
+ * const CHECKED = Symbol('checked');
12
+ *
13
+ * class MyChip extends LitElement {
14
+ * @property({ type: Boolean }) removable = false;
15
+ *
16
+ * @property({ type: Boolean, reflect: true })
17
+ * @observer(function (this: ExmgChip, selected: boolean) {
18
+ * this.checked = selected;
19
+ * })
20
+ * selected = false;
21
+ *
22
+ * @property({ type: Boolean })
23
+ * get checked() {
24
+ * return this[CHECKED];
25
+ * }
26
+ * set checked(checked: boolean) {
27
+ * const wasChecked = this.checked;
28
+ * if (wasChecked === checked) {
29
+ * return;
30
+ * }
31
+ * console.log('checked', checked);
32
+ *
33
+ * this[CHECKED] = checked;
34
+ * this.requestUpdate('checked', wasChecked);
35
+ * }
36
+ *
37
+ * [CHECKED] = false;
38
+ *
39
+ * private selectionController = new SelectionController(this);
40
+ *
41
+ * constructor() {
42
+ * super();
43
+ * this.addController(this.selectionController);
44
+ * }
45
+ * }
46
+ */
47
+ export class SelectionController {
48
+ /**
49
+ * All selection elements in the host element's root with the same
50
+ * `name` attribute, including the host element.
51
+ */
52
+ get controls() {
53
+ const name = this.host.getAttribute('name');
54
+ if (!name || !this.root || !this.host.isConnected) {
55
+ return [this.host];
56
+ }
57
+ // Cast as unknown since there is not enough information for typescript to
58
+ // know that there is always at least one element (the host).
59
+ return Array.from(this.root.querySelectorAll(`[name="${name}"]`));
60
+ }
61
+ constructor(host) {
62
+ this.host = host;
63
+ // eslint-disable-next-line no-undef
64
+ this.root = null;
65
+ }
66
+ hostConnected() {
67
+ // eslint-disable-next-line no-undef
68
+ this.root = this.host.getRootNode();
69
+ }
70
+ hostDisconnected() {
71
+ this.root = null;
72
+ }
73
+ }
74
+ //# sourceMappingURL=selection-controller.js.map
@@ -0,0 +1,2 @@
1
+ export declare const style: import("lit").CSSResult;
2
+ export default style;
@@ -0,0 +1,4 @@
1
+ import { css } from 'lit';
2
+ export const style = css `:host{display:block}.label{display:block;font-size:1rem;font-weight:500;margin-bottom:.5rem}.items{display:flex;flex-wrap:wrap;gap:.3rem}`;
3
+ export default style;
4
+ //# sourceMappingURL=exm-chip-input-css.js.map
@@ -0,0 +1,2 @@
1
+ export declare const style: import("lit").CSSResult;
2
+ export default style;
@@ -0,0 +1,4 @@
1
+ import { css } from 'lit';
2
+ export const style = css `:host{display:block}.label{display:block;font-size:1rem;font-weight:500;margin-bottom:.5rem}.add{display:flex;align-items:center;margin-top:.5rem}.input-container{position:relative}.selected-chips{display:flex;flex-wrap:wrap;gap:.3rem}`;
3
+ export default style;
4
+ //# sourceMappingURL=exm-chip-input-dropdown-css.js.map
@@ -0,0 +1,26 @@
1
+ :host {
2
+ display: block;
3
+ }
4
+
5
+ .label {
6
+ display: block;
7
+ font-size: 1rem;
8
+ font-weight: 500;
9
+ margin-bottom: 0.5rem;
10
+ }
11
+
12
+ .add {
13
+ display: flex;
14
+ align-items: center;
15
+ margin-top: 0.5rem;
16
+ }
17
+
18
+ .input-container {
19
+ position: relative;
20
+ }
21
+
22
+ .selected-chips {
23
+ display: flex;
24
+ flex-wrap: wrap;
25
+ gap: 0.3rem;
26
+ }
@@ -0,0 +1,16 @@
1
+ :host {
2
+ display: block;
3
+ }
4
+
5
+ .label {
6
+ display: block;
7
+ font-size: 1rem;
8
+ font-weight: 500;
9
+ margin-bottom: 0.5rem;
10
+ }
11
+
12
+ .items {
13
+ display: flex;
14
+ flex-wrap: wrap;
15
+ gap: 0.3rem;
16
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2023 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { Validator } from '@material/web/labs/behaviors/validators/validator.js';
7
+ /**
8
+ * Constraint validation properties for a checkbox.
9
+ */
10
+ export interface ChipState {
11
+ /**
12
+ * Whether the checkbox is checked.
13
+ */
14
+ readonly checked: boolean;
15
+ /**
16
+ * Whether the checkbox is required.
17
+ */
18
+ readonly required: boolean;
19
+ }
20
+ /**
21
+ * Radio constraint validation properties for a single radio and its siblings.
22
+ */
23
+ export type ChipGroupState = readonly [ChipState, ...ChipState[]];
24
+ /**
25
+ * A validator that provides constraint validation that emulates
26
+ * `<input type="checkbox">` validation.
27
+ */
28
+ export declare class ChipValidator extends Validator<ChipGroupState> {
29
+ private radioElement?;
30
+ protected computeValidity(states: ChipGroupState): {
31
+ validity: {
32
+ valueMissing: boolean;
33
+ };
34
+ validationMessage: string;
35
+ };
36
+ protected equals(prevGroup: ChipGroupState, nextGroup: ChipGroupState): boolean;
37
+ protected copy(states: ChipGroupState): ChipGroupState;
38
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2023 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { Validator } from '@material/web/labs/behaviors/validators/validator.js';
7
+ /**
8
+ * A validator that provides constraint validation that emulates
9
+ * `<input type="checkbox">` validation.
10
+ */
11
+ export class ChipValidator extends Validator {
12
+ computeValidity(states) {
13
+ if (!this.radioElement) {
14
+ // Lazily create the radio element
15
+ this.radioElement = document.createElement('input');
16
+ this.radioElement.type = 'radio';
17
+ // A name is required for validation to run
18
+ this.radioElement.name = 'group';
19
+ }
20
+ let isRequired = false;
21
+ let isChecked = false;
22
+ for (const { checked, required } of states) {
23
+ if (required) {
24
+ isRequired = true;
25
+ }
26
+ if (checked) {
27
+ isChecked = true;
28
+ }
29
+ }
30
+ // Firefox v119 doesn't compute grouped radio validation correctly while
31
+ // they are detached from the DOM, which is why we don't render multiple
32
+ // virtual <input>s. Instead, we can check the required/checked states and
33
+ // grab the i18n'd validation message if the value is missing.
34
+ this.radioElement.checked = isChecked;
35
+ this.radioElement.required = isRequired;
36
+ return {
37
+ validity: {
38
+ valueMissing: isRequired && !isChecked,
39
+ },
40
+ validationMessage: this.radioElement.validationMessage,
41
+ };
42
+ }
43
+ equals(prevGroup, nextGroup) {
44
+ if (prevGroup.length !== nextGroup.length) {
45
+ return false;
46
+ }
47
+ for (let i = 0; i < prevGroup.length; i++) {
48
+ const prev = prevGroup[i];
49
+ const next = nextGroup[i];
50
+ if (prev.checked !== next.checked || prev.required !== next.required) {
51
+ return false;
52
+ }
53
+ }
54
+ return true;
55
+ }
56
+ copy(states) {
57
+ // Cast as unknown since typescript does not have enough information to
58
+ // infer that the array always has at least one element.
59
+ return states.map(({ checked, required }) => ({
60
+ checked,
61
+ required,
62
+ }));
63
+ }
64
+ }
65
+ //# sourceMappingURL=chip-validator.js.map