@exmg/exm-chip-input 1.1.9 → 1.1.10-alpha.26
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/.rollup.cache/root/repo/packages/exm-chip-input/dist/dropdown/dropdown-container.d.ts +6 -0
- package/.rollup.cache/root/repo/packages/exm-chip-input/dist/dropdown/dropdown-container.js +39 -0
- package/.rollup.cache/root/repo/packages/exm-chip-input/dist/exm-chip-input-dropdown.d.ts +35 -0
- package/.rollup.cache/root/repo/packages/exm-chip-input/dist/exm-chip-input-dropdown.js +153 -0
- package/.rollup.cache/root/repo/packages/exm-chip-input/dist/exm-chip-input.d.ts +19 -0
- package/.rollup.cache/root/repo/packages/exm-chip-input/dist/exm-chip-input.js +76 -0
- package/.rollup.cache/root/repo/packages/exm-chip-input/dist/exm-chip.d.ts +51 -0
- package/.rollup.cache/root/repo/packages/exm-chip-input/dist/exm-chip.js +149 -0
- package/.rollup.cache/root/repo/packages/exm-chip-input/dist/index.d.ts +4 -0
- package/.rollup.cache/root/repo/packages/exm-chip-input/dist/index.js +5 -0
- package/.rollup.cache/root/repo/packages/exm-chip-input/dist/selection-controller.d.ts +68 -0
- package/.rollup.cache/root/repo/packages/exm-chip-input/dist/selection-controller.js +74 -0
- package/.rollup.cache/root/repo/packages/exm-chip-input/dist/styles/exm-chip-input-css.d.ts +1 -0
- package/.rollup.cache/root/repo/packages/exm-chip-input/dist/styles/exm-chip-input-css.js +19 -0
- package/.rollup.cache/root/repo/packages/exm-chip-input/dist/styles/exm-chip-input-dropdown-css.d.ts +1 -0
- package/.rollup.cache/root/repo/packages/exm-chip-input/dist/styles/exm-chip-input-dropdown-css.js +20 -0
- package/.rollup.cache/root/repo/packages/exm-chip-input/dist/styles/exm-chips-shared-css.d.ts +1 -0
- package/.rollup.cache/root/repo/packages/exm-chip-input/dist/styles/exm-chips-shared-css.js +77 -0
- package/.rollup.cache/root/repo/packages/exm-chip-input/dist/validator/chip-validator.d.ts +38 -0
- package/.rollup.cache/root/repo/packages/exm-chip-input/dist/validator/chip-validator.js +65 -0
- package/dist/dropdown/dropdown-container.js +6 -4
- package/dist/exm-chip-input-dropdown.d.ts +1 -0
- package/dist/exm-chip-input-dropdown.js +42 -41
- package/dist/exm-chip-input.d.ts +2 -0
- package/dist/exm-chip-input.js +29 -9
- package/dist/exm-chip.js +16 -14
- package/dist/index.js +1 -1
- package/dist/selection-controller.js +4 -2
- package/dist/styles/exm-chip-input-css.js +9 -7
- package/dist/styles/exm-chip-input-dropdown-css.js +8 -15
- package/dist/styles/exm-chips-shared-css.d.ts +1 -0
- package/dist/styles/exm-chips-shared-css.js +80 -0
- package/dist/validator/chip-validator.js +6 -3
- package/package.json +5 -8
|
@@ -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,35 @@
|
|
|
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 { ExmChip } from './exm-chip.js';
|
|
9
|
+
declare global {
|
|
10
|
+
interface HTMLElementTagNameMap {
|
|
11
|
+
'exm-chip-input-dropdown': ExmChipInputDropdown;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @final
|
|
17
|
+
* @suppress {visibility}
|
|
18
|
+
*/
|
|
19
|
+
export declare class ExmChipInputDropdown extends ChipSet {
|
|
20
|
+
label: string;
|
|
21
|
+
dropdownTitle: string;
|
|
22
|
+
btnAddText: string;
|
|
23
|
+
selectedChips?: ExmChip[];
|
|
24
|
+
supportingText: string;
|
|
25
|
+
private menuOpen;
|
|
26
|
+
static styles: import("lit").CSSResult[];
|
|
27
|
+
constructor();
|
|
28
|
+
private _onSelect;
|
|
29
|
+
private onOpenClick;
|
|
30
|
+
private onMenuClosed;
|
|
31
|
+
private _removeSelected;
|
|
32
|
+
private onKeydown;
|
|
33
|
+
protected render(): import("lit-html").TemplateResult<1>;
|
|
34
|
+
private updateTabIndicesOverride;
|
|
35
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
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, nothing } 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
|
+
import { sharedChipStyle } from './styles/exm-chips-shared-css.js';
|
|
15
|
+
import { classMap } from 'lit/directives/class-map.js';
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
* @final
|
|
19
|
+
* @suppress {visibility}
|
|
20
|
+
*/
|
|
21
|
+
let ExmChipInputDropdown = class ExmChipInputDropdown extends ChipSet {
|
|
22
|
+
constructor() {
|
|
23
|
+
super();
|
|
24
|
+
this.label = '';
|
|
25
|
+
this.dropdownTitle = 'Select items';
|
|
26
|
+
this.btnAddText = 'Add items';
|
|
27
|
+
this.supportingText = '';
|
|
28
|
+
this.menuOpen = false;
|
|
29
|
+
// Add event listeners in the constructor
|
|
30
|
+
this.addEventListener('click', this._onSelect);
|
|
31
|
+
}
|
|
32
|
+
_onSelect(e) {
|
|
33
|
+
const clickedElement = e.target;
|
|
34
|
+
const elementType = clickedElement.tagName;
|
|
35
|
+
if (elementType === 'EXM-CHIP') {
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
this.selectedChips = this.chips.filter((chip) => chip.selected);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
onOpenClick() {
|
|
41
|
+
this.menuOpen = true;
|
|
42
|
+
}
|
|
43
|
+
onMenuClosed() {
|
|
44
|
+
this.menuOpen = false;
|
|
45
|
+
}
|
|
46
|
+
_removeSelected(val) {
|
|
47
|
+
const index = (this.selectedChips || []).findIndex((el) => el.value === val);
|
|
48
|
+
if (index > -1) {
|
|
49
|
+
(this.selectedChips || []).splice(index, 1); // 2nd parameter means remove one item only
|
|
50
|
+
// @ts-ignore
|
|
51
|
+
const chip = this.chips.find((el) => el.value === val);
|
|
52
|
+
if (chip) {
|
|
53
|
+
// @ts-ignore
|
|
54
|
+
chip.selected = false;
|
|
55
|
+
setTimeout(() => chip.dispatchEvent(new CustomEvent('blur', { bubbles: true, composed: true })), 0);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
onKeydown(e) {
|
|
60
|
+
if (!e.defaultPrevented && e.key === 'Escape') {
|
|
61
|
+
e.preventDefault();
|
|
62
|
+
this.menuOpen = false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
render() {
|
|
66
|
+
const containerClasses = { 'has-label': !!this.label };
|
|
67
|
+
const labelClasses = { 'not-empty': (this.selectedChips || []).length > 0, 'has-focus': this.menuOpen };
|
|
68
|
+
return html `
|
|
69
|
+
<div class="container ${classMap(containerClasses)}">
|
|
70
|
+
<div class="background"></div>
|
|
71
|
+
<div class="label ${classMap(labelClasses)}">${this.label}</div>
|
|
72
|
+
<div class="input-container" id="input-container" @click="${this.onOpenClick}">
|
|
73
|
+
<div class="selected-chips">
|
|
74
|
+
${repeat(this.selectedChips || [], (chip) => chip.value, (chip) => html `<md-input-chip
|
|
75
|
+
label="${chip.label}"
|
|
76
|
+
data-value=${chip.value}
|
|
77
|
+
selected
|
|
78
|
+
@remove=${() => this._removeSelected(chip.value)}
|
|
79
|
+
></md-input-chip>`)}
|
|
80
|
+
</div>
|
|
81
|
+
<md-menu
|
|
82
|
+
anchor="input-container"
|
|
83
|
+
menu-corner="start-start"
|
|
84
|
+
anchor-corner="end-start"
|
|
85
|
+
default-focus="none"
|
|
86
|
+
role="dialog"
|
|
87
|
+
aria-label="${this.dropdownTitle} controls"
|
|
88
|
+
.open=${this.menuOpen}
|
|
89
|
+
@closed=${this.onMenuClosed}
|
|
90
|
+
@keydown=${this.onKeydown}
|
|
91
|
+
>
|
|
92
|
+
<dropdown-container .dropdownTitle=${this.dropdownTitle}
|
|
93
|
+
><slot @slotchange=${this.updateTabIndicesOverride}></slot
|
|
94
|
+
></dropdown-container>
|
|
95
|
+
</md-menu>
|
|
96
|
+
</div>
|
|
97
|
+
${this.supportingText ? html `<div class="supporting-text">${this.supportingText}</div>` : nothing}
|
|
98
|
+
</div>
|
|
99
|
+
`;
|
|
100
|
+
}
|
|
101
|
+
updateTabIndicesOverride() {
|
|
102
|
+
// The chip that should be focusable is either the chip that currently has
|
|
103
|
+
// focus or the first chip that can be focused.
|
|
104
|
+
const { chips } = this;
|
|
105
|
+
// update selected array after dom change
|
|
106
|
+
// @ts-ignore
|
|
107
|
+
this.selectedChips = this.chips.filter((chip) => chip.selected);
|
|
108
|
+
let chipToFocus;
|
|
109
|
+
for (const chip of chips) {
|
|
110
|
+
const isChipFocusable = chip.alwaysFocusable || !chip.disabled;
|
|
111
|
+
const chipIsFocused = chip.matches(':focus-within');
|
|
112
|
+
if (chipIsFocused && isChipFocusable) {
|
|
113
|
+
// Found the first chip that is actively focused. This overrides the
|
|
114
|
+
// first focusable chip found.
|
|
115
|
+
chipToFocus = chip;
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (isChipFocusable && !chipToFocus) {
|
|
119
|
+
chipToFocus = chip;
|
|
120
|
+
}
|
|
121
|
+
// Disable non-focused chips. If we disable all of them, we'll grant focus
|
|
122
|
+
// to the first focusable child that was found.
|
|
123
|
+
chip.tabIndex = -1;
|
|
124
|
+
}
|
|
125
|
+
if (chipToFocus) {
|
|
126
|
+
chipToFocus.tabIndex = 0;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
ExmChipInputDropdown.styles = [sharedChipStyle, style];
|
|
131
|
+
__decorate([
|
|
132
|
+
property({ type: String })
|
|
133
|
+
], ExmChipInputDropdown.prototype, "label", void 0);
|
|
134
|
+
__decorate([
|
|
135
|
+
property({ type: String })
|
|
136
|
+
], ExmChipInputDropdown.prototype, "dropdownTitle", void 0);
|
|
137
|
+
__decorate([
|
|
138
|
+
property({ type: String })
|
|
139
|
+
], ExmChipInputDropdown.prototype, "btnAddText", void 0);
|
|
140
|
+
__decorate([
|
|
141
|
+
property({ type: Array })
|
|
142
|
+
], ExmChipInputDropdown.prototype, "selectedChips", void 0);
|
|
143
|
+
__decorate([
|
|
144
|
+
property({ type: String, attribute: 'supporting-text' })
|
|
145
|
+
], ExmChipInputDropdown.prototype, "supportingText", void 0);
|
|
146
|
+
__decorate([
|
|
147
|
+
state()
|
|
148
|
+
], ExmChipInputDropdown.prototype, "menuOpen", void 0);
|
|
149
|
+
ExmChipInputDropdown = __decorate([
|
|
150
|
+
customElement('exm-chip-input-dropdown')
|
|
151
|
+
], ExmChipInputDropdown);
|
|
152
|
+
export { ExmChipInputDropdown };
|
|
153
|
+
//# sourceMappingURL=exm-chip-input-dropdown.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ChipSet } from '@material/web/chips/internal/chip-set.js';
|
|
2
|
+
declare global {
|
|
3
|
+
interface HTMLElementTagNameMap {
|
|
4
|
+
'exm-chip-input': ExmChipInput;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @final
|
|
10
|
+
* @suppress {visibility}
|
|
11
|
+
*/
|
|
12
|
+
export declare class ExmChipInput extends ChipSet {
|
|
13
|
+
label: string;
|
|
14
|
+
supportingText: string;
|
|
15
|
+
chipCount: number;
|
|
16
|
+
static styles: import("lit").CSSResult[];
|
|
17
|
+
protected render(): import("lit-html").TemplateResult<1>;
|
|
18
|
+
private updateTabIndicesOverride;
|
|
19
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
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, nothing } from 'lit';
|
|
7
|
+
import { property, state } from 'lit/decorators.js';
|
|
8
|
+
import { sharedChipStyle } from './styles/exm-chips-shared-css.js';
|
|
9
|
+
import { classMap } from 'lit/directives/class-map.js';
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
* @final
|
|
13
|
+
* @suppress {visibility}
|
|
14
|
+
*/
|
|
15
|
+
let ExmChipInput = class ExmChipInput extends ChipSet {
|
|
16
|
+
constructor() {
|
|
17
|
+
super(...arguments);
|
|
18
|
+
this.label = '';
|
|
19
|
+
this.supportingText = '';
|
|
20
|
+
this.chipCount = 0;
|
|
21
|
+
}
|
|
22
|
+
render() {
|
|
23
|
+
const containerClasses = { 'has-label': !!this.label };
|
|
24
|
+
const labelClasses = { 'not-empty': this.chipCount > 0 };
|
|
25
|
+
return html `
|
|
26
|
+
<div class="container ${classMap(containerClasses)}">
|
|
27
|
+
<div class="background"></div>
|
|
28
|
+
<div class="state-layer"></div>
|
|
29
|
+
<div class="label ${classMap(labelClasses)}">${this.label}</div>
|
|
30
|
+
<div class="items"><slot @slotchange=${this.updateTabIndicesOverride}></slot></div>
|
|
31
|
+
${this.supportingText ? html `<div class="supporting-text">${this.supportingText}</div>` : nothing}
|
|
32
|
+
</div>
|
|
33
|
+
`;
|
|
34
|
+
}
|
|
35
|
+
updateTabIndicesOverride() {
|
|
36
|
+
// The chip that should be focusable is either the chip that currently has
|
|
37
|
+
// focus or the first chip that can be focused.
|
|
38
|
+
const { chips } = this;
|
|
39
|
+
this.chipCount = chips.length;
|
|
40
|
+
let chipToFocus;
|
|
41
|
+
for (const chip of chips) {
|
|
42
|
+
const isChipFocusable = chip.alwaysFocusable || !chip.disabled;
|
|
43
|
+
const chipIsFocused = chip.matches(':focus-within');
|
|
44
|
+
if (chipIsFocused && isChipFocusable) {
|
|
45
|
+
// Found the first chip that is actively focused. This overrides the
|
|
46
|
+
// first focusable chip found.
|
|
47
|
+
chipToFocus = chip;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (isChipFocusable && !chipToFocus) {
|
|
51
|
+
chipToFocus = chip;
|
|
52
|
+
}
|
|
53
|
+
// Disable non-focused chips. If we disable all of them, we'll grant focus
|
|
54
|
+
// to the first focusable child that was found.
|
|
55
|
+
chip.tabIndex = -1;
|
|
56
|
+
}
|
|
57
|
+
if (chipToFocus) {
|
|
58
|
+
chipToFocus.tabIndex = 0;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
ExmChipInput.styles = [styles, sharedChipStyle, style];
|
|
63
|
+
__decorate([
|
|
64
|
+
property({ type: String })
|
|
65
|
+
], ExmChipInput.prototype, "label", void 0);
|
|
66
|
+
__decorate([
|
|
67
|
+
property({ type: String, attribute: 'supporting-text' })
|
|
68
|
+
], ExmChipInput.prototype, "supportingText", void 0);
|
|
69
|
+
__decorate([
|
|
70
|
+
state()
|
|
71
|
+
], ExmChipInput.prototype, "chipCount", void 0);
|
|
72
|
+
ExmChipInput = __decorate([
|
|
73
|
+
customElement('exm-chip-input')
|
|
74
|
+
], ExmChipInput);
|
|
75
|
+
export { ExmChipInput };
|
|
76
|
+
//# 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': ExmChip;
|
|
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 ExmChip 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 ExmChip = class ExmChip 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
|
+
ExmChip.styles = [sharedStyles, elevatedStyles, trailingIconStyles, selectableStyles, styles];
|
|
124
|
+
__decorate([
|
|
125
|
+
property({ type: Boolean })
|
|
126
|
+
], ExmChip.prototype, "removable", void 0);
|
|
127
|
+
__decorate([
|
|
128
|
+
property({ type: Boolean, reflect: true }),
|
|
129
|
+
observer(function (selected) {
|
|
130
|
+
this.checked = selected;
|
|
131
|
+
})
|
|
132
|
+
], ExmChip.prototype, "selected", void 0);
|
|
133
|
+
__decorate([
|
|
134
|
+
property({ type: Boolean })
|
|
135
|
+
], ExmChip.prototype, "checked", null);
|
|
136
|
+
__decorate([
|
|
137
|
+
property({ type: Boolean })
|
|
138
|
+
], ExmChip.prototype, "required", void 0);
|
|
139
|
+
__decorate([
|
|
140
|
+
property()
|
|
141
|
+
], ExmChip.prototype, "value", void 0);
|
|
142
|
+
__decorate([
|
|
143
|
+
query('.container')
|
|
144
|
+
], ExmChip.prototype, "container", void 0);
|
|
145
|
+
ExmChip = __decorate([
|
|
146
|
+
customElement('exm-chip')
|
|
147
|
+
], ExmChip);
|
|
148
|
+
export { ExmChip };
|
|
149
|
+
//# sourceMappingURL=exm-chip.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { ExmChipInput } from './exm-chip-input.js';
|
|
2
|
+
export { ExmChip } from './exm-chip.js';
|
|
3
|
+
export { ExmChipInputDropdown } from './exm-chip-input-dropdown.js';
|
|
4
|
+
export { style as chipInputStyles } from './styles/exm-chip-input-css.js';
|
|
5
|
+
//# sourceMappingURL=index.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: ExmChip, 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
|
+
}
|