@chromvoid/uikit 0.1.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 +8 -0
- package/README.md +96 -0
- package/dist/components/cv-accordion-item.d.ts +69 -0
- package/dist/components/cv-accordion-item.js +176 -0
- package/dist/components/cv-accordion.d.ts +79 -0
- package/dist/components/cv-accordion.js +310 -0
- package/dist/components/cv-alert-dialog.d.ts +86 -0
- package/dist/components/cv-alert-dialog.js +393 -0
- package/dist/components/cv-alert.d.ts +48 -0
- package/dist/components/cv-alert.js +156 -0
- package/dist/components/cv-badge.d.ts +56 -0
- package/dist/components/cv-badge.js +280 -0
- package/dist/components/cv-breadcrumb-item.d.ts +35 -0
- package/dist/components/cv-breadcrumb-item.js +64 -0
- package/dist/components/cv-breadcrumb.d.ts +39 -0
- package/dist/components/cv-breadcrumb.js +160 -0
- package/dist/components/cv-button.d.ts +83 -0
- package/dist/components/cv-button.js +541 -0
- package/dist/components/cv-callout.d.ts +32 -0
- package/dist/components/cv-callout.js +221 -0
- package/dist/components/cv-card.d.ts +48 -0
- package/dist/components/cv-card.js +269 -0
- package/dist/components/cv-carousel-slide.d.ts +25 -0
- package/dist/components/cv-carousel-slide.js +51 -0
- package/dist/components/cv-carousel.d.ts +96 -0
- package/dist/components/cv-carousel.js +457 -0
- package/dist/components/cv-checkbox.d.ts +84 -0
- package/dist/components/cv-checkbox.js +274 -0
- package/dist/components/cv-combobox-group.d.ts +15 -0
- package/dist/components/cv-combobox-group.js +34 -0
- package/dist/components/cv-combobox-option.d.ts +30 -0
- package/dist/components/cv-combobox-option.js +66 -0
- package/dist/components/cv-combobox.d.ts +135 -0
- package/dist/components/cv-combobox.js +834 -0
- package/dist/components/cv-command-item.d.ts +30 -0
- package/dist/components/cv-command-item.js +68 -0
- package/dist/components/cv-command-palette.d.ts +105 -0
- package/dist/components/cv-command-palette.js +578 -0
- package/dist/components/cv-context-menu.d.ts +98 -0
- package/dist/components/cv-context-menu.js +515 -0
- package/dist/components/cv-copy-button.d.ts +61 -0
- package/dist/components/cv-copy-button.js +318 -0
- package/dist/components/cv-date-picker.d.ts +161 -0
- package/dist/components/cv-date-picker.js +803 -0
- package/dist/components/cv-dialog.d.ts +89 -0
- package/dist/components/cv-dialog.js +459 -0
- package/dist/components/cv-disclosure.d.ts +57 -0
- package/dist/components/cv-disclosure.js +241 -0
- package/dist/components/cv-drawer.d.ts +102 -0
- package/dist/components/cv-drawer.js +595 -0
- package/dist/components/cv-feed-article.d.ts +26 -0
- package/dist/components/cv-feed-article.js +52 -0
- package/dist/components/cv-feed.d.ts +62 -0
- package/dist/components/cv-feed.js +310 -0
- package/dist/components/cv-grid-cell.d.ts +30 -0
- package/dist/components/cv-grid-cell.js +57 -0
- package/dist/components/cv-grid-column.d.ts +30 -0
- package/dist/components/cv-grid-column.js +43 -0
- package/dist/components/cv-grid-row.d.ts +30 -0
- package/dist/components/cv-grid-row.js +42 -0
- package/dist/components/cv-grid.d.ts +119 -0
- package/dist/components/cv-grid.js +567 -0
- package/dist/components/cv-icon.d.ts +57 -0
- package/dist/components/cv-icon.js +352 -0
- package/dist/components/cv-input.d.ts +127 -0
- package/dist/components/cv-input.js +482 -0
- package/dist/components/cv-landmark.d.ts +32 -0
- package/dist/components/cv-landmark.js +62 -0
- package/dist/components/cv-link.d.ts +22 -0
- package/dist/components/cv-link.js +99 -0
- package/dist/components/cv-listbox-group.d.ts +15 -0
- package/dist/components/cv-listbox-group.js +42 -0
- package/dist/components/cv-listbox.d.ts +81 -0
- package/dist/components/cv-listbox.js +388 -0
- package/dist/components/cv-menu-button.d.ts +118 -0
- package/dist/components/cv-menu-button.js +822 -0
- package/dist/components/cv-menu-group.d.ts +20 -0
- package/dist/components/cv-menu-group.js +48 -0
- package/dist/components/cv-menu-item.d.ts +52 -0
- package/dist/components/cv-menu-item.js +105 -0
- package/dist/components/cv-menu.d.ts +62 -0
- package/dist/components/cv-menu.js +414 -0
- package/dist/components/cv-meter.d.ts +66 -0
- package/dist/components/cv-meter.js +154 -0
- package/dist/components/cv-number.d.ts +139 -0
- package/dist/components/cv-number.js +553 -0
- package/dist/components/cv-option.d.ts +30 -0
- package/dist/components/cv-option.js +84 -0
- package/dist/components/cv-popover.d.ts +87 -0
- package/dist/components/cv-popover.js +373 -0
- package/dist/components/cv-progress-ring.d.ts +45 -0
- package/dist/components/cv-progress-ring.js +169 -0
- package/dist/components/cv-progress.d.ts +45 -0
- package/dist/components/cv-progress.js +148 -0
- package/dist/components/cv-radio-group.d.ts +79 -0
- package/dist/components/cv-radio-group.js +398 -0
- package/dist/components/cv-radio.d.ts +36 -0
- package/dist/components/cv-radio.js +123 -0
- package/dist/components/cv-select-group.d.ts +15 -0
- package/dist/components/cv-select-group.js +44 -0
- package/dist/components/cv-select-option.d.ts +30 -0
- package/dist/components/cv-select-option.js +66 -0
- package/dist/components/cv-select.d.ts +128 -0
- package/dist/components/cv-select.js +666 -0
- package/dist/components/cv-sidebar-item.d.ts +26 -0
- package/dist/components/cv-sidebar-item.js +142 -0
- package/dist/components/cv-sidebar.d.ts +171 -0
- package/dist/components/cv-sidebar.js +767 -0
- package/dist/components/cv-slider-multi-thumb.d.ts +73 -0
- package/dist/components/cv-slider-multi-thumb.js +374 -0
- package/dist/components/cv-slider.d.ts +84 -0
- package/dist/components/cv-slider.js +328 -0
- package/dist/components/cv-spinbutton.d.ts +121 -0
- package/dist/components/cv-spinbutton.js +486 -0
- package/dist/components/cv-spinner.d.ts +18 -0
- package/dist/components/cv-spinner.js +95 -0
- package/dist/components/cv-switch.d.ts +81 -0
- package/dist/components/cv-switch.js +285 -0
- package/dist/components/cv-tab-panel.d.ts +20 -0
- package/dist/components/cv-tab-panel.js +37 -0
- package/dist/components/cv-tab.d.ts +40 -0
- package/dist/components/cv-tab.js +132 -0
- package/dist/components/cv-table-cell.d.ts +31 -0
- package/dist/components/cv-table-cell.js +49 -0
- package/dist/components/cv-table-column.d.ts +37 -0
- package/dist/components/cv-table-column.js +63 -0
- package/dist/components/cv-table-row.d.ts +30 -0
- package/dist/components/cv-table-row.js +45 -0
- package/dist/components/cv-table.d.ts +147 -0
- package/dist/components/cv-table.js +607 -0
- package/dist/components/cv-tabs.d.ts +70 -0
- package/dist/components/cv-tabs.js +524 -0
- package/dist/components/cv-textarea.d.ts +108 -0
- package/dist/components/cv-textarea.js +328 -0
- package/dist/components/cv-toast-region.d.ts +39 -0
- package/dist/components/cv-toast-region.js +162 -0
- package/dist/components/cv-toast.d.ts +67 -0
- package/dist/components/cv-toast.js +315 -0
- package/dist/components/cv-toolbar-item.d.ts +25 -0
- package/dist/components/cv-toolbar-item.js +72 -0
- package/dist/components/cv-toolbar-separator.d.ts +25 -0
- package/dist/components/cv-toolbar-separator.js +45 -0
- package/dist/components/cv-toolbar.d.ts +63 -0
- package/dist/components/cv-toolbar.js +295 -0
- package/dist/components/cv-tooltip.d.ts +83 -0
- package/dist/components/cv-tooltip.js +455 -0
- package/dist/components/cv-treegrid-cell.d.ts +30 -0
- package/dist/components/cv-treegrid-cell.js +57 -0
- package/dist/components/cv-treegrid-column.d.ts +37 -0
- package/dist/components/cv-treegrid-column.js +53 -0
- package/dist/components/cv-treegrid-row.d.ts +55 -0
- package/dist/components/cv-treegrid-row.js +90 -0
- package/dist/components/cv-treegrid.d.ts +96 -0
- package/dist/components/cv-treegrid.js +632 -0
- package/dist/components/cv-treeitem.d.ts +58 -0
- package/dist/components/cv-treeitem.js +144 -0
- package/dist/components/cv-treeview.d.ts +70 -0
- package/dist/components/cv-treeview.js +396 -0
- package/dist/components/cv-window-splitter.d.ts +79 -0
- package/dist/components/cv-window-splitter.js +316 -0
- package/dist/components/index.d.ts +94 -0
- package/dist/components/index.js +79 -0
- package/dist/dialog/create-dialog-controller.d.ts +31 -0
- package/dist/dialog/create-dialog-controller.js +320 -0
- package/dist/dialog/index.d.ts +2 -0
- package/dist/dialog/index.js +1 -0
- package/dist/form-associated/FormAssociatedReatomElement.d.ts +25 -0
- package/dist/form-associated/FormAssociatedReatomElement.js +70 -0
- package/dist/form-associated/withFormAssociated.d.ts +5 -0
- package/dist/form-associated/withFormAssociated.js +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +9 -0
- package/dist/reatom-lit/ReatomLitElement.d.ts +27 -0
- package/dist/reatom-lit/ReatomLitElement.js +118 -0
- package/dist/reatom-lit/html.d.ts +4 -0
- package/dist/reatom-lit/html.js +10 -0
- package/dist/reatom-lit/index.d.ts +4 -0
- package/dist/reatom-lit/index.js +4 -0
- package/dist/reatom-lit/watch.d.ts +15 -0
- package/dist/reatom-lit/watch.js +40 -0
- package/dist/reatom-lit/withReatomElement.d.ts +4 -0
- package/dist/reatom-lit/withReatomElement.js +57 -0
- package/dist/register.d.ts +1 -0
- package/dist/register.js +84 -0
- package/dist/styles/component-styles.d.ts +4 -0
- package/dist/styles/component-styles.js +78 -0
- package/dist/theme/cv-theme-provider.d.ts +32 -0
- package/dist/theme/cv-theme-provider.js +110 -0
- package/dist/theme/index.d.ts +4 -0
- package/dist/theme/index.js +2 -0
- package/dist/theme/theme-engine.d.ts +4 -0
- package/dist/theme/theme-engine.js +67 -0
- package/dist/theme/tokens.css +265 -0
- package/dist/theme/types.d.ts +7 -0
- package/dist/theme/types.js +1 -0
- package/dist/toast/create-toast-controller.d.ts +12 -0
- package/dist/toast/create-toast-controller.js +12 -0
- package/dist/toast/index.d.ts +2 -0
- package/dist/toast/index.js +1 -0
- package/package.json +146 -0
- package/specs/_template.md +110 -0
- package/specs/components/accordion.md +207 -0
- package/specs/components/alert.md +83 -0
- package/specs/components/badge.md +183 -0
- package/specs/components/breadcrumb.md +152 -0
- package/specs/components/button.md +227 -0
- package/specs/components/callout.md +153 -0
- package/specs/components/card.md +192 -0
- package/specs/components/carousel.md +232 -0
- package/specs/components/checkbox.md +141 -0
- package/specs/components/combobox.md +427 -0
- package/specs/components/context-menu.md +375 -0
- package/specs/components/copy-button.md +236 -0
- package/specs/components/date-picker.md +290 -0
- package/specs/components/dialog.md +184 -0
- package/specs/components/disclosure.md +151 -0
- package/specs/components/drawer.md +216 -0
- package/specs/components/feed.md +266 -0
- package/specs/components/grid.md +423 -0
- package/specs/components/input.md +237 -0
- package/specs/components/landmark.md +92 -0
- package/specs/components/link.md +117 -0
- package/specs/components/listbox.md +327 -0
- package/specs/components/menu.md +508 -0
- package/specs/components/meter.md +148 -0
- package/specs/components/number.md +268 -0
- package/specs/components/option.md +167 -0
- package/specs/components/popover.md +207 -0
- package/specs/components/progress-ring.md +134 -0
- package/specs/components/progress.md +110 -0
- package/specs/components/radio.md +208 -0
- package/specs/components/select.md +305 -0
- package/specs/components/sidebar.md +204 -0
- package/specs/components/spinbutton.md +157 -0
- package/specs/components/spinner.md +83 -0
- package/specs/components/switch.md +145 -0
- package/specs/components/table.md +372 -0
- package/specs/components/tabs.md +242 -0
- package/specs/components/textarea.md +166 -0
- package/specs/components/theme.md +364 -0
- package/specs/components/toast.md +198 -0
- package/specs/components/toolbar.md +258 -0
- package/specs/components/tooltip.md +152 -0
- package/specs/components/treegrid.md +363 -0
- package/specs/components/treeview.md +263 -0
- package/specs/components/window-splitter.md +225 -0
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import {} from '@chromvoid/headless-ui/interactions/composite-navigation';
|
|
2
|
+
import { createToolbar } from '@chromvoid/headless-ui/toolbar';
|
|
3
|
+
import { css, html, nothing } from 'lit';
|
|
4
|
+
import { ReatomLitElement } from '../reatom-lit/ReatomLitElement.js';
|
|
5
|
+
import { CVToolbarItem } from './cv-toolbar-item.js';
|
|
6
|
+
import { CVToolbarSeparator } from './cv-toolbar-separator.js';
|
|
7
|
+
const toolbarKeysToPrevent = new Set(['ArrowRight', 'ArrowLeft', 'ArrowDown', 'ArrowUp', 'Home', 'End']);
|
|
8
|
+
let cvToolbarNonce = 0;
|
|
9
|
+
export class CVToolbar extends ReatomLitElement {
|
|
10
|
+
static elementName = 'cv-toolbar';
|
|
11
|
+
static get properties() {
|
|
12
|
+
return {
|
|
13
|
+
value: { type: String, reflect: true },
|
|
14
|
+
orientation: { type: String, reflect: true },
|
|
15
|
+
wrap: { type: Boolean, reflect: true },
|
|
16
|
+
ariaLabel: { type: String, attribute: 'aria-label' },
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
idBase = `cv-toolbar-${++cvToolbarNonce}`;
|
|
20
|
+
itemRecords = [];
|
|
21
|
+
separatorRecords = [];
|
|
22
|
+
itemListeners = new WeakMap();
|
|
23
|
+
hasFocus = false;
|
|
24
|
+
model;
|
|
25
|
+
constructor() {
|
|
26
|
+
super();
|
|
27
|
+
this.value = '';
|
|
28
|
+
this.orientation = 'horizontal';
|
|
29
|
+
this.wrap = true;
|
|
30
|
+
this.ariaLabel = '';
|
|
31
|
+
this.model = createToolbar({
|
|
32
|
+
idBase: this.idBase,
|
|
33
|
+
items: [],
|
|
34
|
+
orientation: this.orientation,
|
|
35
|
+
wrap: this.wrap,
|
|
36
|
+
ariaLabel: undefined,
|
|
37
|
+
initialActiveId: null,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
static styles = [
|
|
41
|
+
css `
|
|
42
|
+
:host {
|
|
43
|
+
display: block;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
[part='base'] {
|
|
47
|
+
display: flex;
|
|
48
|
+
flex-wrap: wrap;
|
|
49
|
+
align-items: center;
|
|
50
|
+
gap: var(--cv-toolbar-gap, var(--cv-space-1, 4px));
|
|
51
|
+
padding: var(--cv-toolbar-padding, var(--cv-space-1, 4px));
|
|
52
|
+
border-radius: var(--cv-toolbar-border-radius, var(--cv-radius-md, 10px));
|
|
53
|
+
border: 1px solid var(--cv-color-border, #2a3245);
|
|
54
|
+
background: var(--cv-color-surface, #141923);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
:host([orientation='vertical']) [part='base'] {
|
|
58
|
+
flex-direction: column;
|
|
59
|
+
align-items: stretch;
|
|
60
|
+
}
|
|
61
|
+
`,
|
|
62
|
+
];
|
|
63
|
+
static define() {
|
|
64
|
+
if (!customElements.get(this.elementName)) {
|
|
65
|
+
customElements.define(this.elementName, this);
|
|
66
|
+
}
|
|
67
|
+
CVToolbarSeparator.define();
|
|
68
|
+
}
|
|
69
|
+
connectedCallback() {
|
|
70
|
+
super.connectedCallback();
|
|
71
|
+
this.rebuildModelFromSlot(false, false);
|
|
72
|
+
}
|
|
73
|
+
disconnectedCallback() {
|
|
74
|
+
super.disconnectedCallback();
|
|
75
|
+
this.detachItemListeners();
|
|
76
|
+
}
|
|
77
|
+
willUpdate(changedProperties) {
|
|
78
|
+
super.willUpdate(changedProperties);
|
|
79
|
+
if (changedProperties.has('orientation') ||
|
|
80
|
+
changedProperties.has('wrap') ||
|
|
81
|
+
changedProperties.has('ariaLabel')) {
|
|
82
|
+
this.rebuildModelFromSlot(true, false);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (changedProperties.has('value')) {
|
|
86
|
+
const next = this.value.trim();
|
|
87
|
+
if (next && this.model.state.activeId() !== next) {
|
|
88
|
+
const previous = this.model.state.activeId();
|
|
89
|
+
this.model.actions.setActive(next);
|
|
90
|
+
this.applyInteractionResult(previous);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
updated(changedProperties) {
|
|
95
|
+
super.updated(changedProperties);
|
|
96
|
+
if (!changedProperties.has('value')) {
|
|
97
|
+
this.syncItemElements();
|
|
98
|
+
this.syncSeparatorElements();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
getItemElements() {
|
|
102
|
+
return Array.from(this.children).filter((element) => element.tagName.toLowerCase() === CVToolbarItem.elementName);
|
|
103
|
+
}
|
|
104
|
+
getSeparatorElements() {
|
|
105
|
+
return Array.from(this.children).filter((element) => element.tagName.toLowerCase() === CVToolbarSeparator.elementName);
|
|
106
|
+
}
|
|
107
|
+
ensureItemValue(item, index) {
|
|
108
|
+
const normalized = item.value?.trim();
|
|
109
|
+
if (normalized)
|
|
110
|
+
return normalized;
|
|
111
|
+
const fallback = `item-${index + 1}`;
|
|
112
|
+
item.value = fallback;
|
|
113
|
+
return fallback;
|
|
114
|
+
}
|
|
115
|
+
ensureSeparatorValue(sep, index) {
|
|
116
|
+
const normalized = sep.value?.trim();
|
|
117
|
+
if (normalized)
|
|
118
|
+
return normalized;
|
|
119
|
+
const fallback = `sep-${index + 1}`;
|
|
120
|
+
sep.value = fallback;
|
|
121
|
+
return fallback;
|
|
122
|
+
}
|
|
123
|
+
rebuildModelFromSlot(preserveState, requestRender = true) {
|
|
124
|
+
const itemElements = this.getItemElements();
|
|
125
|
+
const separatorElements = this.getSeparatorElements();
|
|
126
|
+
const previousActiveId = preserveState ? this.model.state.activeId() : this.value.trim() || null;
|
|
127
|
+
this.detachItemListeners();
|
|
128
|
+
this.itemRecords = itemElements.map((element, index) => ({
|
|
129
|
+
id: this.ensureItemValue(element, index),
|
|
130
|
+
disabled: element.disabled,
|
|
131
|
+
element,
|
|
132
|
+
}));
|
|
133
|
+
this.separatorRecords = separatorElements.map((element, index) => ({
|
|
134
|
+
id: this.ensureSeparatorValue(element, index),
|
|
135
|
+
element,
|
|
136
|
+
}));
|
|
137
|
+
// Build ordered items list (items + separators) preserving DOM order
|
|
138
|
+
const allHeadlessItems = [];
|
|
139
|
+
for (const child of Array.from(this.children)) {
|
|
140
|
+
const tag = child.tagName.toLowerCase();
|
|
141
|
+
if (tag === CVToolbarItem.elementName) {
|
|
142
|
+
const record = this.itemRecords.find((r) => r.element === child);
|
|
143
|
+
if (record)
|
|
144
|
+
allHeadlessItems.push({ id: record.id, disabled: record.disabled });
|
|
145
|
+
}
|
|
146
|
+
else if (tag === CVToolbarSeparator.elementName) {
|
|
147
|
+
const record = this.separatorRecords.find((r) => r.element === child);
|
|
148
|
+
if (record)
|
|
149
|
+
allHeadlessItems.push({ id: record.id, separator: true });
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
this.model = createToolbar({
|
|
153
|
+
idBase: this.idBase,
|
|
154
|
+
items: allHeadlessItems,
|
|
155
|
+
orientation: this.orientation,
|
|
156
|
+
wrap: this.wrap,
|
|
157
|
+
ariaLabel: this.ariaLabel || undefined,
|
|
158
|
+
initialActiveId: previousActiveId,
|
|
159
|
+
});
|
|
160
|
+
this.attachItemListeners();
|
|
161
|
+
this.syncItemElements();
|
|
162
|
+
this.syncSeparatorElements();
|
|
163
|
+
this.value = this.model.state.activeId() ?? '';
|
|
164
|
+
if (requestRender) {
|
|
165
|
+
this.requestUpdate();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
detachItemListeners() {
|
|
169
|
+
for (const record of this.itemRecords) {
|
|
170
|
+
const listeners = this.itemListeners.get(record.element);
|
|
171
|
+
if (!listeners)
|
|
172
|
+
continue;
|
|
173
|
+
record.element.removeEventListener('focus', listeners.focus);
|
|
174
|
+
record.element.removeEventListener('click', listeners.click);
|
|
175
|
+
this.itemListeners.delete(record.element);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
attachItemListeners() {
|
|
179
|
+
for (const record of this.itemRecords) {
|
|
180
|
+
const focus = () => {
|
|
181
|
+
this.handleItemFocus(record.id);
|
|
182
|
+
};
|
|
183
|
+
const click = () => {
|
|
184
|
+
this.handleItemFocus(record.id);
|
|
185
|
+
};
|
|
186
|
+
record.element.addEventListener('focus', focus);
|
|
187
|
+
record.element.addEventListener('click', click);
|
|
188
|
+
this.itemListeners.set(record.element, { focus, click });
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
syncItemElements() {
|
|
192
|
+
for (const record of this.itemRecords) {
|
|
193
|
+
const props = this.model.contracts.getItemProps(record.id);
|
|
194
|
+
record.element.id = props.id;
|
|
195
|
+
record.element.tabIndex = Number(props.tabindex);
|
|
196
|
+
if (props['aria-disabled']) {
|
|
197
|
+
record.element.setAttribute('aria-disabled', props['aria-disabled']);
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
record.element.removeAttribute('aria-disabled');
|
|
201
|
+
}
|
|
202
|
+
record.element.setAttribute('data-active', props['data-active']);
|
|
203
|
+
record.element.active = props['data-active'] === 'true';
|
|
204
|
+
record.element.disabled = props['aria-disabled'] === 'true';
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
syncSeparatorElements() {
|
|
208
|
+
for (const record of this.separatorRecords) {
|
|
209
|
+
const props = this.model.contracts.getSeparatorProps(record.id);
|
|
210
|
+
record.element.id = props.id;
|
|
211
|
+
record.element.separatorRole = props.role;
|
|
212
|
+
record.element.separatorOrientation = props['aria-orientation'];
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
dispatchInput(detail) {
|
|
216
|
+
this.dispatchEvent(new CustomEvent('cv-input', {
|
|
217
|
+
detail,
|
|
218
|
+
bubbles: true,
|
|
219
|
+
composed: true,
|
|
220
|
+
}));
|
|
221
|
+
}
|
|
222
|
+
dispatchChange(detail) {
|
|
223
|
+
this.dispatchEvent(new CustomEvent('cv-change', {
|
|
224
|
+
detail,
|
|
225
|
+
bubbles: true,
|
|
226
|
+
composed: true,
|
|
227
|
+
}));
|
|
228
|
+
}
|
|
229
|
+
focusActiveItem() {
|
|
230
|
+
const activeId = this.model.state.activeId();
|
|
231
|
+
if (!activeId)
|
|
232
|
+
return;
|
|
233
|
+
const activeRecord = this.itemRecords.find((record) => record.id === activeId);
|
|
234
|
+
activeRecord?.element.focus();
|
|
235
|
+
}
|
|
236
|
+
applyInteractionResult(previousActiveId) {
|
|
237
|
+
this.syncItemElements();
|
|
238
|
+
const nextActiveId = this.model.state.activeId();
|
|
239
|
+
this.value = nextActiveId ?? '';
|
|
240
|
+
if (nextActiveId === previousActiveId)
|
|
241
|
+
return;
|
|
242
|
+
const detail = { activeId: nextActiveId };
|
|
243
|
+
this.dispatchInput(detail);
|
|
244
|
+
this.dispatchChange(detail);
|
|
245
|
+
this.focusActiveItem();
|
|
246
|
+
}
|
|
247
|
+
handleItemFocus(id) {
|
|
248
|
+
const previous = this.model.state.activeId();
|
|
249
|
+
this.model.actions.setActive(id);
|
|
250
|
+
this.applyInteractionResult(previous);
|
|
251
|
+
}
|
|
252
|
+
handleToolbarKeyDown(event) {
|
|
253
|
+
if (toolbarKeysToPrevent.has(event.key)) {
|
|
254
|
+
event.preventDefault();
|
|
255
|
+
}
|
|
256
|
+
const previous = this.model.state.activeId();
|
|
257
|
+
this.model.actions.handleKeyDown({ key: event.key });
|
|
258
|
+
this.applyInteractionResult(previous);
|
|
259
|
+
}
|
|
260
|
+
handleSlotChange() {
|
|
261
|
+
this.rebuildModelFromSlot(true, true);
|
|
262
|
+
}
|
|
263
|
+
handleFocusIn() {
|
|
264
|
+
if (!this.hasFocus) {
|
|
265
|
+
this.hasFocus = true;
|
|
266
|
+
this.model.actions.handleToolbarFocus();
|
|
267
|
+
this.syncItemElements();
|
|
268
|
+
this.value = this.model.state.activeId() ?? '';
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
handleFocusOut(event) {
|
|
272
|
+
const related = event.relatedTarget;
|
|
273
|
+
if (!related || !this.contains(related)) {
|
|
274
|
+
this.hasFocus = false;
|
|
275
|
+
this.model.actions.handleToolbarBlur();
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
render() {
|
|
279
|
+
const rootProps = this.model.contracts.getRootProps();
|
|
280
|
+
return html `
|
|
281
|
+
<div
|
|
282
|
+
id=${rootProps.id}
|
|
283
|
+
role=${rootProps.role}
|
|
284
|
+
aria-orientation=${rootProps['aria-orientation']}
|
|
285
|
+
aria-label=${rootProps['aria-label'] ?? nothing}
|
|
286
|
+
part="base"
|
|
287
|
+
@keydown=${this.handleToolbarKeyDown}
|
|
288
|
+
@focusin=${this.handleFocusIn}
|
|
289
|
+
@focusout=${this.handleFocusOut}
|
|
290
|
+
>
|
|
291
|
+
<slot @slotchange=${this.handleSlotChange}></slot>
|
|
292
|
+
</div>
|
|
293
|
+
`;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { PropertyValues } from 'lit';
|
|
2
|
+
import { ReatomLitElement } from '../reatom-lit/ReatomLitElement.js';
|
|
3
|
+
export interface CVTooltipEventDetail {
|
|
4
|
+
open: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare class CVTooltip extends ReatomLitElement {
|
|
7
|
+
static elementName: string;
|
|
8
|
+
static get properties(): {
|
|
9
|
+
open: {
|
|
10
|
+
type: BooleanConstructor;
|
|
11
|
+
reflect: boolean;
|
|
12
|
+
};
|
|
13
|
+
disabled: {
|
|
14
|
+
type: BooleanConstructor;
|
|
15
|
+
reflect: boolean;
|
|
16
|
+
};
|
|
17
|
+
showDelay: {
|
|
18
|
+
type: NumberConstructor;
|
|
19
|
+
attribute: string;
|
|
20
|
+
reflect: boolean;
|
|
21
|
+
};
|
|
22
|
+
hideDelay: {
|
|
23
|
+
type: NumberConstructor;
|
|
24
|
+
attribute: string;
|
|
25
|
+
reflect: boolean;
|
|
26
|
+
};
|
|
27
|
+
trigger: {
|
|
28
|
+
type: StringConstructor;
|
|
29
|
+
reflect: boolean;
|
|
30
|
+
};
|
|
31
|
+
arrow: {
|
|
32
|
+
type: BooleanConstructor;
|
|
33
|
+
reflect: boolean;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
open: boolean;
|
|
37
|
+
disabled: boolean;
|
|
38
|
+
showDelay: number;
|
|
39
|
+
hideDelay: number;
|
|
40
|
+
trigger: string;
|
|
41
|
+
arrow: boolean;
|
|
42
|
+
private readonly idBase;
|
|
43
|
+
private model;
|
|
44
|
+
private triggerTargets;
|
|
45
|
+
private lastEmittedOpen;
|
|
46
|
+
private hasLayoutListeners;
|
|
47
|
+
private layoutFrame;
|
|
48
|
+
constructor();
|
|
49
|
+
static styles: import("lit").CSSResult[];
|
|
50
|
+
static define(): void;
|
|
51
|
+
connectedCallback(): void;
|
|
52
|
+
disconnectedCallback(): void;
|
|
53
|
+
willUpdate(changedProperties: PropertyValues): void;
|
|
54
|
+
updated(changedProperties: PropertyValues): void;
|
|
55
|
+
private getContentElement;
|
|
56
|
+
private getTriggerElement;
|
|
57
|
+
private clearInlineLayout;
|
|
58
|
+
private syncNativePopover;
|
|
59
|
+
private applyFallbackLayout;
|
|
60
|
+
private syncTooltipLayout;
|
|
61
|
+
private cancelLayoutFrame;
|
|
62
|
+
private scheduleLayout;
|
|
63
|
+
private toggleLayoutListeners;
|
|
64
|
+
private handleViewportChange;
|
|
65
|
+
private createModel;
|
|
66
|
+
private dispatchInput;
|
|
67
|
+
private dispatchChange;
|
|
68
|
+
private emitOpenChange;
|
|
69
|
+
private applyInteractionResult;
|
|
70
|
+
private syncTriggerAria;
|
|
71
|
+
private handlePointerEnter;
|
|
72
|
+
private handlePointerLeave;
|
|
73
|
+
private handleFocusIn;
|
|
74
|
+
private handleFocusOut;
|
|
75
|
+
private handleClick;
|
|
76
|
+
private handleKeyDown;
|
|
77
|
+
private handleTriggerSlotChange;
|
|
78
|
+
/** Programmatically opens the tooltip (intended for manual trigger mode). */
|
|
79
|
+
show(): void;
|
|
80
|
+
/** Programmatically closes the tooltip (intended for manual trigger mode). */
|
|
81
|
+
hide(): void;
|
|
82
|
+
protected render(): import("lit").TemplateResult<1>;
|
|
83
|
+
}
|