@arclux/arc-ui 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/LICENSE +21 -0
- package/README.md +64 -0
- package/package.json +186 -0
- package/src/content/accordion-item.js +27 -0
- package/src/content/accordion.js +151 -0
- package/src/content/animated-number.js +160 -0
- package/src/content/aspect-ratio.js +78 -0
- package/src/content/avatar-group.js +101 -0
- package/src/content/avatar.js +92 -0
- package/src/content/badge.js +98 -0
- package/src/content/callout.js +141 -0
- package/src/content/card.js +75 -0
- package/src/content/carousel.js +300 -0
- package/src/content/code-block.js +152 -0
- package/src/content/collapsible.js +142 -0
- package/src/content/color-swatch.js +86 -0
- package/src/content/column.js +28 -0
- package/src/content/data-table.js +332 -0
- package/src/content/divider.js +153 -0
- package/src/content/empty-state.js +78 -0
- package/src/content/feature-card.js +142 -0
- package/src/content/highlight.js +63 -0
- package/src/content/icon-library.js +30 -0
- package/src/content/icon-registry.js +39 -0
- package/src/content/icon.js +95 -0
- package/src/content/index.js +44 -0
- package/src/content/infinite-scroll.js +144 -0
- package/src/content/kbd.js +40 -0
- package/src/content/markdown.js +294 -0
- package/src/content/marquee.js +166 -0
- package/src/content/meter.js +167 -0
- package/src/content/scroll-area.js +107 -0
- package/src/content/skeleton.js +85 -0
- package/src/content/spinner.js +77 -0
- package/src/content/stack.js +68 -0
- package/src/content/stat.js +72 -0
- package/src/content/step.js +22 -0
- package/src/content/stepper.js +202 -0
- package/src/content/table.js +134 -0
- package/src/content/tag.js +156 -0
- package/src/content/text.js +111 -0
- package/src/content/timeline-item.js +29 -0
- package/src/content/timeline.js +170 -0
- package/src/content/truncate.js +161 -0
- package/src/content/value-card.js +94 -0
- package/src/feedback/alert.js +187 -0
- package/src/feedback/command-item.js +28 -0
- package/src/feedback/command-palette.js +346 -0
- package/src/feedback/context-menu.js +299 -0
- package/src/feedback/dialog.js +298 -0
- package/src/feedback/dropdown-menu.js +259 -0
- package/src/feedback/hover-card.js +186 -0
- package/src/feedback/index.js +17 -0
- package/src/feedback/modal.js +226 -0
- package/src/feedback/notification-panel.js +196 -0
- package/src/feedback/popover.js +184 -0
- package/src/feedback/progress.js +169 -0
- package/src/feedback/sheet.js +249 -0
- package/src/feedback/toast.js +207 -0
- package/src/feedback/tooltip.js +189 -0
- package/src/icons/lucide.d.ts +1915 -0
- package/src/icons/lucide.js +1915 -0
- package/src/icons/phosphor.d.ts +1517 -0
- package/src/icons/phosphor.js +1517 -0
- package/src/icons/types.d.ts +8 -0
- package/src/index.js +9 -0
- package/src/input/button.js +127 -0
- package/src/input/calendar.js +340 -0
- package/src/input/checkbox.js +159 -0
- package/src/input/chip.js +120 -0
- package/src/input/color-picker.js +461 -0
- package/src/input/combobox.js +295 -0
- package/src/input/copy-button.js +144 -0
- package/src/input/date-picker.js +534 -0
- package/src/input/file-upload.js +333 -0
- package/src/input/form.js +179 -0
- package/src/input/icon-button.js +179 -0
- package/src/input/index.js +31 -0
- package/src/input/input.js +158 -0
- package/src/input/multi-select.js +392 -0
- package/src/input/number-input.js +239 -0
- package/src/input/otp-input.js +221 -0
- package/src/input/pin-input.js +294 -0
- package/src/input/radio-group.js +177 -0
- package/src/input/radio.js +28 -0
- package/src/input/rating.js +195 -0
- package/src/input/search.js +371 -0
- package/src/input/segmented-control.js +174 -0
- package/src/input/select.js +267 -0
- package/src/input/slider.js +217 -0
- package/src/input/sortable-list.js +345 -0
- package/src/input/suggestion.js +26 -0
- package/src/input/textarea.js +203 -0
- package/src/input/theme-toggle.js +196 -0
- package/src/input/toggle.js +166 -0
- package/src/layout/app-shell.js +266 -0
- package/src/layout/auth-shell.js +153 -0
- package/src/layout/container.js +37 -0
- package/src/layout/dashboard-grid.js +62 -0
- package/src/layout/index.js +15 -0
- package/src/layout/page-header.js +100 -0
- package/src/layout/page-layout.js +112 -0
- package/src/layout/resizable.js +221 -0
- package/src/layout/section.js +54 -0
- package/src/layout/settings-layout.js +91 -0
- package/src/layout/split-pane.js +172 -0
- package/src/layout/status-bar.js +84 -0
- package/src/layout/toolbar.js +92 -0
- package/src/navigation/breadcrumb-item.js +26 -0
- package/src/navigation/breadcrumb.js +129 -0
- package/src/navigation/drawer.js +183 -0
- package/src/navigation/footer.js +99 -0
- package/src/navigation/index.js +22 -0
- package/src/navigation/link.js +120 -0
- package/src/navigation/nav-item.js +46 -0
- package/src/navigation/navigation-menu.js +687 -0
- package/src/navigation/pagination.js +186 -0
- package/src/navigation/scroll-spy.js +198 -0
- package/src/navigation/scroll-to-top.js +163 -0
- package/src/navigation/sidebar-link.js +28 -0
- package/src/navigation/sidebar-section.js +45 -0
- package/src/navigation/sidebar.js +336 -0
- package/src/navigation/spy-link.js +26 -0
- package/src/navigation/tab.js +26 -0
- package/src/navigation/tabs.js +202 -0
- package/src/navigation/top-bar.js +263 -0
- package/src/navigation/tree-item.js +38 -0
- package/src/navigation/tree-view.js +255 -0
- package/src/shared/index.js +6 -0
- package/src/shared/menu-divider.js +9 -0
- package/src/shared/menu-item.js +30 -0
- package/src/shared/option.js +31 -0
- package/src/shared-styles.js +81 -0
- package/src/tokens.js +445 -0
- package/types/index.d.ts +973 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// ARC UI — Input tier
|
|
2
|
+
// Form controls and user input components
|
|
3
|
+
|
|
4
|
+
export { ArcButton } from './button.js';
|
|
5
|
+
export { ArcCalendar } from './calendar.js';
|
|
6
|
+
export { ArcCheckbox } from './checkbox.js';
|
|
7
|
+
export { ArcChip } from './chip.js';
|
|
8
|
+
export { ArcColorPicker } from './color-picker.js';
|
|
9
|
+
export { ArcCombobox } from './combobox.js';
|
|
10
|
+
export { ArcCopyButton } from './copy-button.js';
|
|
11
|
+
export { ArcDatePicker } from './date-picker.js';
|
|
12
|
+
export { ArcFileUpload } from './file-upload.js';
|
|
13
|
+
export { ArcForm } from './form.js';
|
|
14
|
+
export { ArcIconButton } from './icon-button.js';
|
|
15
|
+
export { ArcInput } from './input.js';
|
|
16
|
+
export { ArcMultiSelect } from './multi-select.js';
|
|
17
|
+
export { ArcNumberInput } from './number-input.js';
|
|
18
|
+
export { ArcOtpInput } from './otp-input.js';
|
|
19
|
+
export { ArcPinInput } from './pin-input.js';
|
|
20
|
+
export { ArcRadio } from './radio.js';
|
|
21
|
+
export { ArcRadioGroup } from './radio-group.js';
|
|
22
|
+
export { ArcRating } from './rating.js';
|
|
23
|
+
export { ArcSearch } from './search.js';
|
|
24
|
+
export { ArcSegmentedControl } from './segmented-control.js';
|
|
25
|
+
export { ArcSelect } from './select.js';
|
|
26
|
+
export { ArcSlider } from './slider.js';
|
|
27
|
+
export { ArcSortableList } from './sortable-list.js';
|
|
28
|
+
export { ArcSuggestion } from './suggestion.js';
|
|
29
|
+
export { ArcTextarea } from './textarea.js';
|
|
30
|
+
export { ArcThemeToggle } from './theme-toggle.js';
|
|
31
|
+
export { ArcToggle } from './toggle.js';
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { LitElement, html, css } from 'lit';
|
|
2
|
+
import { tokenStyles } from '../shared-styles.js';
|
|
3
|
+
|
|
4
|
+
let inputIdCounter = 0;
|
|
5
|
+
|
|
6
|
+
export class ArcInput extends LitElement {
|
|
7
|
+
static formAssociated = true;
|
|
8
|
+
|
|
9
|
+
static properties = {
|
|
10
|
+
type: { type: String },
|
|
11
|
+
name: { type: String },
|
|
12
|
+
label: { type: String },
|
|
13
|
+
placeholder: { type: String },
|
|
14
|
+
value: { type: String },
|
|
15
|
+
disabled: { type: Boolean, reflect: true },
|
|
16
|
+
required: { type: Boolean },
|
|
17
|
+
multiline: { type: Boolean },
|
|
18
|
+
rows: { type: Number },
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
static styles = [
|
|
22
|
+
tokenStyles,
|
|
23
|
+
css`
|
|
24
|
+
:host { display: block; }
|
|
25
|
+
|
|
26
|
+
.input-group {
|
|
27
|
+
display: flex;
|
|
28
|
+
flex-direction: column;
|
|
29
|
+
gap: var(--space-xs);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.input-group__label {
|
|
33
|
+
font-family: var(--font-accent);
|
|
34
|
+
font-weight: 600;
|
|
35
|
+
font-size: var(--label-inline-size);
|
|
36
|
+
letter-spacing: var(--label-inline-spacing);
|
|
37
|
+
text-transform: uppercase;
|
|
38
|
+
color: var(--text-muted);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.input-group__field {
|
|
42
|
+
font-family: var(--font-body);
|
|
43
|
+
font-size: var(--body-size);
|
|
44
|
+
font-weight: 300;
|
|
45
|
+
color: var(--text-primary);
|
|
46
|
+
background: var(--bg-surface);
|
|
47
|
+
border: 1px solid var(--border-default);
|
|
48
|
+
border-radius: var(--radius-md);
|
|
49
|
+
padding: var(--space-sm) var(--space-md);
|
|
50
|
+
transition:
|
|
51
|
+
border-color var(--transition-fast),
|
|
52
|
+
box-shadow var(--transition-fast),
|
|
53
|
+
background var(--transition-fast);
|
|
54
|
+
box-sizing: border-box;
|
|
55
|
+
width: 100%;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
textarea.input-group__field { resize: vertical; }
|
|
59
|
+
|
|
60
|
+
.input-group__field::placeholder { color: var(--text-ghost); }
|
|
61
|
+
.input-group__field:hover:not(:focus) { border-color: var(--border-bright); }
|
|
62
|
+
.input-group__field:focus {
|
|
63
|
+
outline: none;
|
|
64
|
+
border-color: rgba(var(--accent-primary-rgb), 0.4);
|
|
65
|
+
box-shadow: var(--focus-glow);
|
|
66
|
+
background: var(--bg-card);
|
|
67
|
+
}
|
|
68
|
+
.input-group__field:disabled { opacity: 0.4; cursor: not-allowed; }
|
|
69
|
+
|
|
70
|
+
@media (prefers-reduced-motion: reduce) {
|
|
71
|
+
:host *,
|
|
72
|
+
:host *::before,
|
|
73
|
+
:host *::after {
|
|
74
|
+
animation-duration: 0.01ms !important;
|
|
75
|
+
animation-iteration-count: 1 !important;
|
|
76
|
+
transition-duration: 0.01ms !important;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
`,
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
constructor() {
|
|
83
|
+
super();
|
|
84
|
+
this._internals = this.attachInternals();
|
|
85
|
+
this.type = 'text';
|
|
86
|
+
this.name = '';
|
|
87
|
+
this.label = '';
|
|
88
|
+
this.placeholder = '';
|
|
89
|
+
this.value = '';
|
|
90
|
+
this.disabled = false;
|
|
91
|
+
this.required = false;
|
|
92
|
+
this.multiline = false;
|
|
93
|
+
this.rows = 5;
|
|
94
|
+
this._fieldId = `arc-input-${++inputIdCounter}`;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
updated(changed) {
|
|
98
|
+
if (changed.has('value')) {
|
|
99
|
+
this._internals.setFormValue(this.value);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
_handleInput(e) {
|
|
104
|
+
this.value = e.target.value;
|
|
105
|
+
this._internals.setFormValue(this.value);
|
|
106
|
+
this.dispatchEvent(new CustomEvent('arc-input', { detail: { value: this.value }, bubbles: true, composed: true }));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
_handleChange(e) {
|
|
110
|
+
this.value = e.target.value;
|
|
111
|
+
this._internals.setFormValue(this.value);
|
|
112
|
+
this.dispatchEvent(new CustomEvent('arc-change', { detail: { value: this.value }, bubbles: true, composed: true }));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
render() {
|
|
116
|
+
const id = this.name || this._fieldId;
|
|
117
|
+
const field = this.multiline
|
|
118
|
+
? html`<textarea
|
|
119
|
+
class="input-group__field"
|
|
120
|
+
id=${id}
|
|
121
|
+
name=${this.name}
|
|
122
|
+
placeholder=${this.placeholder}
|
|
123
|
+
rows=${this.rows}
|
|
124
|
+
?required=${this.required}
|
|
125
|
+
?disabled=${this.disabled}
|
|
126
|
+
aria-required=${this.required ? 'true' : 'false'}
|
|
127
|
+
aria-disabled=${this.disabled ? 'true' : 'false'}
|
|
128
|
+
.value=${this.value}
|
|
129
|
+
@input=${this._handleInput}
|
|
130
|
+
@change=${this._handleChange}
|
|
131
|
+
part="field"
|
|
132
|
+
></textarea>`
|
|
133
|
+
: html`<input
|
|
134
|
+
class="input-group__field"
|
|
135
|
+
type=${this.type}
|
|
136
|
+
id=${id}
|
|
137
|
+
name=${this.name}
|
|
138
|
+
placeholder=${this.placeholder}
|
|
139
|
+
?required=${this.required}
|
|
140
|
+
?disabled=${this.disabled}
|
|
141
|
+
aria-required=${this.required ? 'true' : 'false'}
|
|
142
|
+
aria-disabled=${this.disabled ? 'true' : 'false'}
|
|
143
|
+
.value=${this.value}
|
|
144
|
+
@input=${this._handleInput}
|
|
145
|
+
@change=${this._handleChange}
|
|
146
|
+
part="field"
|
|
147
|
+
/>`;
|
|
148
|
+
|
|
149
|
+
return html`
|
|
150
|
+
<div class="input-group">
|
|
151
|
+
${this.label ? html`<label class="input-group__label" for=${id} part="label">${this.label}</label>` : ''}
|
|
152
|
+
${field}
|
|
153
|
+
</div>
|
|
154
|
+
`;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
customElements.define('arc-input', ArcInput);
|
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
import { LitElement, html, css } from 'lit';
|
|
2
|
+
import { tokenStyles } from '../shared-styles.js';
|
|
3
|
+
import '../shared/option.js';
|
|
4
|
+
|
|
5
|
+
export class ArcMultiSelect extends LitElement {
|
|
6
|
+
static properties = {
|
|
7
|
+
value: { type: Array },
|
|
8
|
+
placeholder: { type: String },
|
|
9
|
+
label: { type: String },
|
|
10
|
+
disabled: { type: Boolean, reflect: true },
|
|
11
|
+
_query: { state: true },
|
|
12
|
+
_open: { state: true },
|
|
13
|
+
_activeIndex: { state: true },
|
|
14
|
+
_options: { state: true },
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
static styles = [
|
|
18
|
+
tokenStyles,
|
|
19
|
+
css`
|
|
20
|
+
:host {
|
|
21
|
+
display: block;
|
|
22
|
+
position: relative;
|
|
23
|
+
font-family: var(--font-body);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
:host([disabled]) {
|
|
27
|
+
opacity: 0.5;
|
|
28
|
+
pointer-events: none;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.ms__label {
|
|
32
|
+
display: block;
|
|
33
|
+
font-family: var(--font-accent);
|
|
34
|
+
font-size: var(--text-xs);
|
|
35
|
+
font-weight: 600;
|
|
36
|
+
letter-spacing: 1px;
|
|
37
|
+
text-transform: uppercase;
|
|
38
|
+
color: var(--text-muted);
|
|
39
|
+
margin-bottom: var(--space-xs);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.ms__control {
|
|
43
|
+
display: flex;
|
|
44
|
+
flex-wrap: wrap;
|
|
45
|
+
align-items: center;
|
|
46
|
+
gap: var(--space-xs);
|
|
47
|
+
min-height: 38px;
|
|
48
|
+
background: var(--bg-card);
|
|
49
|
+
border: 1px solid var(--border-default);
|
|
50
|
+
border-radius: var(--radius-md);
|
|
51
|
+
padding: var(--space-xs) var(--space-sm);
|
|
52
|
+
cursor: text;
|
|
53
|
+
transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.ms__control--focused {
|
|
57
|
+
border-color: rgba(var(--accent-primary-rgb), 0.4);
|
|
58
|
+
box-shadow: var(--focus-glow);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.ms__tag {
|
|
62
|
+
display: inline-flex;
|
|
63
|
+
align-items: center;
|
|
64
|
+
gap: var(--space-xs);
|
|
65
|
+
font-size: var(--text-xs);
|
|
66
|
+
font-weight: 500;
|
|
67
|
+
color: var(--text-primary);
|
|
68
|
+
background: var(--bg-elevated);
|
|
69
|
+
border: 1px solid var(--border-default);
|
|
70
|
+
border-radius: var(--radius-full);
|
|
71
|
+
padding: 2px calc(var(--space-xs) + 2px) 2px calc(var(--space-sm) + 2px); /* cosmetic 2px vertical for inline tag */
|
|
72
|
+
white-space: nowrap;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.ms__tag-remove {
|
|
76
|
+
display: inline-flex;
|
|
77
|
+
align-items: center;
|
|
78
|
+
justify-content: center;
|
|
79
|
+
width: 16px;
|
|
80
|
+
height: 16px;
|
|
81
|
+
border: none;
|
|
82
|
+
background: none;
|
|
83
|
+
color: var(--text-muted);
|
|
84
|
+
cursor: pointer;
|
|
85
|
+
border-radius: var(--radius-full);
|
|
86
|
+
font-size: var(--text-sm);
|
|
87
|
+
line-height: 1;
|
|
88
|
+
padding: 0;
|
|
89
|
+
transition: color var(--transition-fast), background var(--transition-fast);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.ms__tag-remove:hover {
|
|
93
|
+
color: var(--text-primary);
|
|
94
|
+
background: rgba(var(--accent-primary-rgb), 0.1);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.ms__input {
|
|
98
|
+
flex: 1;
|
|
99
|
+
min-width: 60px;
|
|
100
|
+
font-family: var(--font-body);
|
|
101
|
+
font-size: var(--text-sm);
|
|
102
|
+
color: var(--text-primary);
|
|
103
|
+
background: none;
|
|
104
|
+
border: none;
|
|
105
|
+
outline: none;
|
|
106
|
+
padding: var(--space-xs) 0;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.ms__input::placeholder {
|
|
110
|
+
color: var(--text-muted);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
.ms__dropdown {
|
|
114
|
+
position: absolute;
|
|
115
|
+
top: calc(100% + var(--space-xs));
|
|
116
|
+
left: 0;
|
|
117
|
+
right: 0;
|
|
118
|
+
max-height: 220px;
|
|
119
|
+
overflow-y: auto;
|
|
120
|
+
background: var(--bg-card);
|
|
121
|
+
border: 1px solid var(--border-default);
|
|
122
|
+
border-radius: var(--radius-md);
|
|
123
|
+
box-shadow: var(--shadow-overlay);
|
|
124
|
+
z-index: 1000;
|
|
125
|
+
padding: var(--space-xs) 0;
|
|
126
|
+
display: none;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
.ms__dropdown--open {
|
|
130
|
+
display: block;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.ms__option {
|
|
134
|
+
display: flex;
|
|
135
|
+
align-items: center;
|
|
136
|
+
gap: var(--space-sm);
|
|
137
|
+
width: 100%;
|
|
138
|
+
text-align: left;
|
|
139
|
+
font-family: var(--font-body);
|
|
140
|
+
font-size: var(--text-sm);
|
|
141
|
+
color: var(--text-primary);
|
|
142
|
+
background: none;
|
|
143
|
+
border: none;
|
|
144
|
+
padding: var(--space-sm) var(--space-md);
|
|
145
|
+
cursor: pointer;
|
|
146
|
+
transition: background var(--transition-fast);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.ms__option:hover,
|
|
150
|
+
.ms__option--active {
|
|
151
|
+
background: rgba(var(--accent-primary-rgb), 0.1);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
.ms__option:focus-visible {
|
|
155
|
+
outline: none;
|
|
156
|
+
box-shadow: var(--focus-glow);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
.ms__check {
|
|
160
|
+
width: 16px;
|
|
161
|
+
height: 16px;
|
|
162
|
+
flex-shrink: 0;
|
|
163
|
+
color: var(--accent-primary);
|
|
164
|
+
opacity: 0;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
.ms__check--visible {
|
|
168
|
+
opacity: 1;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
.ms__empty {
|
|
172
|
+
padding: var(--space-sm) var(--space-md);
|
|
173
|
+
font-size: var(--text-sm);
|
|
174
|
+
color: var(--text-muted);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
.ms__slot-host { display: none; }
|
|
178
|
+
|
|
179
|
+
@media (prefers-reduced-motion: reduce) {
|
|
180
|
+
:host *,
|
|
181
|
+
:host *::before,
|
|
182
|
+
:host *::after {
|
|
183
|
+
animation-duration: 0.01ms !important;
|
|
184
|
+
animation-iteration-count: 1 !important;
|
|
185
|
+
transition-duration: 0.01ms !important;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
`,
|
|
189
|
+
];
|
|
190
|
+
|
|
191
|
+
constructor() {
|
|
192
|
+
super();
|
|
193
|
+
this.value = [];
|
|
194
|
+
this.placeholder = '';
|
|
195
|
+
this.label = '';
|
|
196
|
+
this.disabled = false;
|
|
197
|
+
this._query = '';
|
|
198
|
+
this._open = false;
|
|
199
|
+
this._activeIndex = -1;
|
|
200
|
+
this._focused = false;
|
|
201
|
+
this._options = [];
|
|
202
|
+
this._onDocClick = this._onDocClick.bind(this);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
connectedCallback() {
|
|
206
|
+
super.connectedCallback();
|
|
207
|
+
document.addEventListener('click', this._onDocClick, true);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
disconnectedCallback() {
|
|
211
|
+
super.disconnectedCallback();
|
|
212
|
+
document.removeEventListener('click', this._onDocClick, true);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
_onSlotChange(e) {
|
|
216
|
+
this._options = e.target.assignedElements({ flatten: true })
|
|
217
|
+
.filter(el => el.tagName === 'ARC-OPTION');
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
_onDocClick(e) {
|
|
221
|
+
if (!e.composedPath().includes(this)) {
|
|
222
|
+
this._open = false;
|
|
223
|
+
this._focused = false;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
get _normalizedItems() {
|
|
228
|
+
return this._options.map(opt => ({ label: opt.label, value: opt.value }));
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
get _filteredItems() {
|
|
232
|
+
const q = this._query.toLowerCase();
|
|
233
|
+
if (!q) return this._normalizedItems;
|
|
234
|
+
return this._normalizedItems.filter(item =>
|
|
235
|
+
item.label.toLowerCase().includes(q)
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
_isSelected(item) {
|
|
240
|
+
return (this.value || []).includes(item.value);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
_toggleItem(item) {
|
|
244
|
+
const current = [...(this.value || [])];
|
|
245
|
+
const idx = current.indexOf(item.value);
|
|
246
|
+
|
|
247
|
+
if (idx >= 0) {
|
|
248
|
+
current.splice(idx, 1);
|
|
249
|
+
} else {
|
|
250
|
+
current.push(item.value);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
this.value = current;
|
|
254
|
+
this._query = '';
|
|
255
|
+
this._activeIndex = -1;
|
|
256
|
+
|
|
257
|
+
this.dispatchEvent(new CustomEvent('arc-change', {
|
|
258
|
+
detail: { value: this.value },
|
|
259
|
+
bubbles: true,
|
|
260
|
+
composed: true,
|
|
261
|
+
}));
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
_removeItem(val, e) {
|
|
265
|
+
e.stopPropagation();
|
|
266
|
+
this.value = (this.value || []).filter(v => v !== val);
|
|
267
|
+
|
|
268
|
+
this.dispatchEvent(new CustomEvent('arc-change', {
|
|
269
|
+
detail: { value: this.value },
|
|
270
|
+
bubbles: true,
|
|
271
|
+
composed: true,
|
|
272
|
+
}));
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
_onInput(e) {
|
|
276
|
+
this._query = e.target.value;
|
|
277
|
+
this._open = true;
|
|
278
|
+
this._activeIndex = -1;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
_onFocusIn() {
|
|
282
|
+
this._focused = true;
|
|
283
|
+
this._open = true;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
_onKeyDown(e) {
|
|
287
|
+
const items = this._filteredItems;
|
|
288
|
+
|
|
289
|
+
switch (e.key) {
|
|
290
|
+
case 'ArrowDown':
|
|
291
|
+
e.preventDefault();
|
|
292
|
+
if (!this._open) { this._open = true; return; }
|
|
293
|
+
this._activeIndex = Math.min(this._activeIndex + 1, items.length - 1);
|
|
294
|
+
break;
|
|
295
|
+
case 'ArrowUp':
|
|
296
|
+
e.preventDefault();
|
|
297
|
+
this._activeIndex = Math.max(this._activeIndex - 1, 0);
|
|
298
|
+
break;
|
|
299
|
+
case 'Enter':
|
|
300
|
+
e.preventDefault();
|
|
301
|
+
if (this._activeIndex >= 0 && items[this._activeIndex]) {
|
|
302
|
+
this._toggleItem(items[this._activeIndex]);
|
|
303
|
+
}
|
|
304
|
+
break;
|
|
305
|
+
case 'Escape':
|
|
306
|
+
this._open = false;
|
|
307
|
+
this._activeIndex = -1;
|
|
308
|
+
break;
|
|
309
|
+
case 'Backspace':
|
|
310
|
+
if (!this._query && this.value && this.value.length > 0) {
|
|
311
|
+
this._removeItem(this.value[this.value.length - 1], e);
|
|
312
|
+
}
|
|
313
|
+
break;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
_getLabel(val) {
|
|
318
|
+
const item = this._normalizedItems.find(i => i.value === val);
|
|
319
|
+
return item ? item.label : val;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
render() {
|
|
323
|
+
const filtered = this._filteredItems;
|
|
324
|
+
const selected = this.value || [];
|
|
325
|
+
const showPlaceholder = selected.length === 0 && !this._query;
|
|
326
|
+
|
|
327
|
+
return html`
|
|
328
|
+
<div class="ms__slot-host">
|
|
329
|
+
<slot @slotchange=${this._onSlotChange}></slot>
|
|
330
|
+
</div>
|
|
331
|
+
${this.label ? html`<label class="ms__label" part="label">${this.label}</label>` : ''}
|
|
332
|
+
<div
|
|
333
|
+
class="ms__control ${this._focused ? 'ms__control--focused' : ''}"
|
|
334
|
+
@click=${() => this.shadowRoot.querySelector('.ms__input')?.focus()}
|
|
335
|
+
part="control"
|
|
336
|
+
>
|
|
337
|
+
${selected.map(val => html`
|
|
338
|
+
<span class="ms__tag" part="tag">
|
|
339
|
+
${this._getLabel(val)}
|
|
340
|
+
<button
|
|
341
|
+
class="ms__tag-remove"
|
|
342
|
+
@click=${(e) => this._removeItem(val, e)}
|
|
343
|
+
aria-label="Remove ${this._getLabel(val)}"
|
|
344
|
+
tabindex="-1"
|
|
345
|
+
>×</button>
|
|
346
|
+
</span>
|
|
347
|
+
`)}
|
|
348
|
+
<input
|
|
349
|
+
class="ms__input"
|
|
350
|
+
type="text"
|
|
351
|
+
.value=${this._query}
|
|
352
|
+
placeholder=${showPlaceholder ? this.placeholder : ''}
|
|
353
|
+
?disabled=${this.disabled}
|
|
354
|
+
aria-expanded=${String(this._open)}
|
|
355
|
+
@input=${this._onInput}
|
|
356
|
+
@focus=${this._onFocusIn}
|
|
357
|
+
@keydown=${this._onKeyDown}
|
|
358
|
+
part="input"
|
|
359
|
+
/>
|
|
360
|
+
</div>
|
|
361
|
+
<div
|
|
362
|
+
class="ms__dropdown ${this._open ? 'ms__dropdown--open' : ''}"
|
|
363
|
+
role="listbox"
|
|
364
|
+
aria-multiselectable="true"
|
|
365
|
+
part="dropdown"
|
|
366
|
+
>
|
|
367
|
+
${filtered.length > 0
|
|
368
|
+
? filtered.map((item, i) => {
|
|
369
|
+
const checked = this._isSelected(item);
|
|
370
|
+
return html`
|
|
371
|
+
<button
|
|
372
|
+
class="ms__option ${i === this._activeIndex ? 'ms__option--active' : ''}"
|
|
373
|
+
role="option"
|
|
374
|
+
aria-selected=${String(checked)}
|
|
375
|
+
@click=${() => this._toggleItem(item)}
|
|
376
|
+
part="option"
|
|
377
|
+
>
|
|
378
|
+
<svg class="ms__check ${checked ? 'ms__check--visible' : ''}" viewBox="0 0 16 16" fill="none" aria-hidden="true">
|
|
379
|
+
<path d="M3.5 8L6.5 11L12.5 5" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
|
380
|
+
</svg>
|
|
381
|
+
${item.label}
|
|
382
|
+
</button>
|
|
383
|
+
`;
|
|
384
|
+
})
|
|
385
|
+
: html`<div class="ms__empty">No results found</div>`
|
|
386
|
+
}
|
|
387
|
+
</div>
|
|
388
|
+
`;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
customElements.define('arc-multi-select', ArcMultiSelect);
|