@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,393 @@
|
|
|
1
|
+
import { createAlertDialog } from '@chromvoid/headless-ui/alert-dialog';
|
|
2
|
+
import { css, html, nothing } from 'lit';
|
|
3
|
+
import { ReatomLitElement } from '../reatom-lit/ReatomLitElement.js';
|
|
4
|
+
let cvAlertDialogNonce = 0;
|
|
5
|
+
export class CVAlertDialog extends ReatomLitElement {
|
|
6
|
+
static elementName = 'cv-alert-dialog';
|
|
7
|
+
static get properties() {
|
|
8
|
+
return {
|
|
9
|
+
open: { type: Boolean, reflect: true },
|
|
10
|
+
closeOnEscape: { type: Boolean, attribute: 'close-on-escape', reflect: true },
|
|
11
|
+
closeOnOutsidePointer: { type: Boolean, attribute: 'close-on-outside-pointer', reflect: true },
|
|
12
|
+
closeOnOutsideFocus: { type: Boolean, attribute: 'close-on-outside-focus', reflect: true },
|
|
13
|
+
closeOnAction: { type: Boolean, attribute: 'close-on-action', reflect: true },
|
|
14
|
+
initialFocusId: { type: String, attribute: 'initial-focus-id' },
|
|
15
|
+
ariaLabelledBy: { type: String, attribute: 'aria-labelledby' },
|
|
16
|
+
ariaDescribedBy: { type: String, attribute: 'aria-describedby' },
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
idBase = `cv-alert-dialog-${++cvAlertDialogNonce}`;
|
|
20
|
+
model;
|
|
21
|
+
lockScrollApplied = false;
|
|
22
|
+
previousBodyOverflow = '';
|
|
23
|
+
constructor() {
|
|
24
|
+
super();
|
|
25
|
+
this.open = false;
|
|
26
|
+
this.closeOnEscape = true;
|
|
27
|
+
this.closeOnOutsidePointer = true;
|
|
28
|
+
this.closeOnOutsideFocus = true;
|
|
29
|
+
this.closeOnAction = true;
|
|
30
|
+
this.initialFocusId = '';
|
|
31
|
+
this.ariaLabelledBy = '';
|
|
32
|
+
this.ariaDescribedBy = '';
|
|
33
|
+
this.model = this.createModel();
|
|
34
|
+
}
|
|
35
|
+
static styles = [
|
|
36
|
+
css `
|
|
37
|
+
:host {
|
|
38
|
+
display: inline-block;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
[part='trigger'] {
|
|
42
|
+
display: inline-flex;
|
|
43
|
+
align-items: center;
|
|
44
|
+
justify-content: center;
|
|
45
|
+
min-block-size: 36px;
|
|
46
|
+
padding: 0 var(--cv-space-3, 12px);
|
|
47
|
+
border-radius: var(--cv-radius-sm, 6px);
|
|
48
|
+
border: 1px solid var(--cv-color-border, #2a3245);
|
|
49
|
+
background: var(--cv-color-surface, #141923);
|
|
50
|
+
color: var(--cv-color-text, #e8ecf6);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
[part='trigger']:focus-visible {
|
|
54
|
+
outline: 2px solid var(--cv-color-primary, #65d7ff);
|
|
55
|
+
outline-offset: 1px;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
[part='overlay'] {
|
|
59
|
+
position: fixed;
|
|
60
|
+
inset: 0;
|
|
61
|
+
z-index: 45;
|
|
62
|
+
display: grid;
|
|
63
|
+
place-items: center;
|
|
64
|
+
background: color-mix(in oklab, black 62%, transparent);
|
|
65
|
+
padding: var(--cv-space-4, 16px);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
[part='overlay'][hidden] {
|
|
69
|
+
display: none;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
[part='content'] {
|
|
73
|
+
inline-size: min(540px, calc(100vw - 32px));
|
|
74
|
+
display: grid;
|
|
75
|
+
gap: var(--cv-space-3, 12px);
|
|
76
|
+
padding: var(--cv-space-4, 16px);
|
|
77
|
+
border-radius: var(--cv-radius-lg, 14px);
|
|
78
|
+
border: 1px solid var(--cv-color-border, #2a3245);
|
|
79
|
+
background: var(--cv-color-surface-elevated, #1d2432);
|
|
80
|
+
color: var(--cv-color-text, #e8ecf6);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
[part='content']:focus-visible {
|
|
84
|
+
outline: 2px solid var(--cv-color-primary, #65d7ff);
|
|
85
|
+
outline-offset: 1px;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
[part='header'] {
|
|
89
|
+
display: grid;
|
|
90
|
+
gap: var(--cv-space-1, 4px);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
[part='title'] {
|
|
94
|
+
margin: 0;
|
|
95
|
+
font-size: 1.05rem;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
[part='description'] {
|
|
99
|
+
margin: 0;
|
|
100
|
+
color: var(--cv-color-text-muted, #9aa6bf);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
[part='footer'] {
|
|
104
|
+
display: flex;
|
|
105
|
+
flex-wrap: wrap;
|
|
106
|
+
gap: var(--cv-space-2, 8px);
|
|
107
|
+
justify-content: flex-end;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
[part='cancel'],
|
|
111
|
+
[part='action'] {
|
|
112
|
+
min-block-size: 34px;
|
|
113
|
+
padding: 0 var(--cv-space-3, 12px);
|
|
114
|
+
border-radius: var(--cv-radius-sm, 6px);
|
|
115
|
+
border: 1px solid var(--cv-color-border, #2a3245);
|
|
116
|
+
background: var(--cv-color-surface, #141923);
|
|
117
|
+
color: var(--cv-color-text, #e8ecf6);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
[part='action'] {
|
|
121
|
+
border-color: color-mix(
|
|
122
|
+
in oklab,
|
|
123
|
+
var(--cv-color-danger, #ff7a8a) 52%,
|
|
124
|
+
var(--cv-color-border, #2a3245)
|
|
125
|
+
);
|
|
126
|
+
background: color-mix(
|
|
127
|
+
in oklab,
|
|
128
|
+
var(--cv-color-danger, #ff7a8a) 22%,
|
|
129
|
+
var(--cv-color-surface, #141923)
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
`,
|
|
133
|
+
];
|
|
134
|
+
static define() {
|
|
135
|
+
if (!customElements.get(this.elementName)) {
|
|
136
|
+
customElements.define(this.elementName, this);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
connectedCallback() {
|
|
140
|
+
super.connectedCallback();
|
|
141
|
+
this.syncOutsideFocusListener();
|
|
142
|
+
this.syncScrollLock();
|
|
143
|
+
}
|
|
144
|
+
disconnectedCallback() {
|
|
145
|
+
super.disconnectedCallback();
|
|
146
|
+
this.syncOutsideFocusListener(true);
|
|
147
|
+
this.releaseScrollLock();
|
|
148
|
+
}
|
|
149
|
+
willUpdate(changedProperties) {
|
|
150
|
+
super.willUpdate(changedProperties);
|
|
151
|
+
if (changedProperties.has('closeOnEscape') ||
|
|
152
|
+
changedProperties.has('closeOnOutsidePointer') ||
|
|
153
|
+
changedProperties.has('closeOnOutsideFocus') ||
|
|
154
|
+
changedProperties.has('closeOnAction') ||
|
|
155
|
+
changedProperties.has('initialFocusId') ||
|
|
156
|
+
changedProperties.has('ariaLabelledBy') ||
|
|
157
|
+
changedProperties.has('ariaDescribedBy')) {
|
|
158
|
+
const initialOpen = changedProperties.has('open') ? this.open : this.model.state.isOpen();
|
|
159
|
+
this.model = this.createModel(initialOpen);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (changedProperties.has('open') && this.model.state.isOpen() !== this.open) {
|
|
163
|
+
const previous = this.captureState();
|
|
164
|
+
if (this.open) {
|
|
165
|
+
this.model.actions.open();
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
this.model.actions.close();
|
|
169
|
+
}
|
|
170
|
+
this.applyInteractionResult(previous);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
updated(changedProperties) {
|
|
174
|
+
super.updated(changedProperties);
|
|
175
|
+
this.syncOutsideFocusListener();
|
|
176
|
+
this.syncScrollLock();
|
|
177
|
+
if (changedProperties.has('open') && this.open) {
|
|
178
|
+
this.focusInitialTarget();
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
createModel(initialOpen = this.open) {
|
|
182
|
+
return createAlertDialog({
|
|
183
|
+
idBase: this.idBase,
|
|
184
|
+
initialOpen,
|
|
185
|
+
closeOnEscape: this.closeOnEscape,
|
|
186
|
+
closeOnOutsidePointer: this.closeOnOutsidePointer,
|
|
187
|
+
closeOnOutsideFocus: this.closeOnOutsideFocus,
|
|
188
|
+
closeOnAction: this.closeOnAction,
|
|
189
|
+
initialFocusId: this.initialFocusId || undefined,
|
|
190
|
+
ariaLabelledBy: this.ariaLabelledBy || undefined,
|
|
191
|
+
ariaDescribedBy: this.ariaDescribedBy || undefined,
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
captureState() {
|
|
195
|
+
return {
|
|
196
|
+
open: this.model.state.isOpen(),
|
|
197
|
+
restoreTargetId: this.model.state.restoreTargetId(),
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
dispatchInput(detail) {
|
|
201
|
+
this.dispatchEvent(new CustomEvent('cv-input', {
|
|
202
|
+
detail,
|
|
203
|
+
bubbles: true,
|
|
204
|
+
composed: true,
|
|
205
|
+
}));
|
|
206
|
+
}
|
|
207
|
+
dispatchChange(detail) {
|
|
208
|
+
this.dispatchEvent(new CustomEvent('cv-change', {
|
|
209
|
+
detail,
|
|
210
|
+
bubbles: true,
|
|
211
|
+
composed: true,
|
|
212
|
+
}));
|
|
213
|
+
}
|
|
214
|
+
applyInteractionResult(previous) {
|
|
215
|
+
const nextOpen = this.model.state.isOpen();
|
|
216
|
+
this.open = nextOpen;
|
|
217
|
+
if (previous.open !== nextOpen) {
|
|
218
|
+
const detail = { open: nextOpen };
|
|
219
|
+
this.dispatchInput(detail);
|
|
220
|
+
this.dispatchChange(detail);
|
|
221
|
+
}
|
|
222
|
+
const restoreTargetId = this.model.state.restoreTargetId();
|
|
223
|
+
if (restoreTargetId && previous.restoreTargetId !== restoreTargetId) {
|
|
224
|
+
const trigger = this.shadowRoot?.querySelector(`[id="${restoreTargetId}"]`);
|
|
225
|
+
trigger?.focus();
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
syncOutsideFocusListener(forceOff = false) {
|
|
229
|
+
const shouldListen = !forceOff && this.open;
|
|
230
|
+
if (shouldListen) {
|
|
231
|
+
document.addEventListener('focusin', this.handleDocumentFocusIn);
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
document.removeEventListener('focusin', this.handleDocumentFocusIn);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
syncScrollLock() {
|
|
238
|
+
if (!this.open) {
|
|
239
|
+
this.releaseScrollLock();
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
if (this.lockScrollApplied)
|
|
243
|
+
return;
|
|
244
|
+
this.previousBodyOverflow = document.body.style.overflow;
|
|
245
|
+
document.body.style.overflow = 'hidden';
|
|
246
|
+
this.lockScrollApplied = true;
|
|
247
|
+
}
|
|
248
|
+
releaseScrollLock() {
|
|
249
|
+
if (!this.lockScrollApplied)
|
|
250
|
+
return;
|
|
251
|
+
document.body.style.overflow = this.previousBodyOverflow;
|
|
252
|
+
this.lockScrollApplied = false;
|
|
253
|
+
}
|
|
254
|
+
focusInitialTarget() {
|
|
255
|
+
const contentProps = this.model.contracts.getDialogProps();
|
|
256
|
+
const requestedId = contentProps['data-initial-focus'];
|
|
257
|
+
if (requestedId) {
|
|
258
|
+
const explicit = this.querySelector(`#${requestedId}`) ??
|
|
259
|
+
this.shadowRoot?.querySelector(`#${requestedId}`);
|
|
260
|
+
if (explicit) {
|
|
261
|
+
explicit.focus();
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
const content = this.shadowRoot?.querySelector('[part="content"]');
|
|
266
|
+
content?.focus();
|
|
267
|
+
}
|
|
268
|
+
handleDocumentFocusIn = (event) => {
|
|
269
|
+
if (!this.open)
|
|
270
|
+
return;
|
|
271
|
+
if (event.composedPath().includes(this))
|
|
272
|
+
return;
|
|
273
|
+
const previous = this.captureState();
|
|
274
|
+
this.model.contracts.getOverlayProps().onFocusOutside();
|
|
275
|
+
this.applyInteractionResult(previous);
|
|
276
|
+
};
|
|
277
|
+
handleTriggerClick() {
|
|
278
|
+
const previous = this.captureState();
|
|
279
|
+
if (this.open) {
|
|
280
|
+
this.model.actions.close();
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
this.model.actions.open();
|
|
284
|
+
}
|
|
285
|
+
this.applyInteractionResult(previous);
|
|
286
|
+
}
|
|
287
|
+
handleTriggerKeyDown(event) {
|
|
288
|
+
if (event.key === 'Enter' || event.key === ' ' || event.key === 'Spacebar') {
|
|
289
|
+
event.preventDefault();
|
|
290
|
+
this.handleTriggerClick();
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
handleOverlayPointerDown(event) {
|
|
294
|
+
if (event.target !== event.currentTarget)
|
|
295
|
+
return;
|
|
296
|
+
const previous = this.captureState();
|
|
297
|
+
this.model.contracts.getOverlayProps().onPointerDownOutside();
|
|
298
|
+
this.applyInteractionResult(previous);
|
|
299
|
+
}
|
|
300
|
+
handleContentKeyDown(event) {
|
|
301
|
+
if (event.key === 'Escape') {
|
|
302
|
+
event.preventDefault();
|
|
303
|
+
}
|
|
304
|
+
const previous = this.captureState();
|
|
305
|
+
this.model.contracts.getDialogProps().onKeyDown({ key: event.key });
|
|
306
|
+
this.applyInteractionResult(previous);
|
|
307
|
+
}
|
|
308
|
+
handleCancelClick() {
|
|
309
|
+
const previous = this.captureState();
|
|
310
|
+
this.model.contracts.getCancelButtonProps().onClick();
|
|
311
|
+
this.applyInteractionResult(previous);
|
|
312
|
+
this.dispatchEvent(new CustomEvent('cv-cancel', { bubbles: true, composed: true }));
|
|
313
|
+
}
|
|
314
|
+
handleActionClick() {
|
|
315
|
+
const previous = this.captureState();
|
|
316
|
+
this.model.contracts.getActionButtonProps().onClick();
|
|
317
|
+
this.applyInteractionResult(previous);
|
|
318
|
+
this.dispatchEvent(new CustomEvent('cv-action', { bubbles: true, composed: true }));
|
|
319
|
+
}
|
|
320
|
+
render() {
|
|
321
|
+
const dialogProps = this.model.contracts.getDialogProps();
|
|
322
|
+
const overlayProps = this.model.contracts.getOverlayProps();
|
|
323
|
+
const titleProps = this.model.contracts.getTitleProps();
|
|
324
|
+
const descriptionProps = this.model.contracts.getDescriptionProps();
|
|
325
|
+
const cancelProps = this.model.contracts.getCancelButtonProps();
|
|
326
|
+
const actionProps = this.model.contracts.getActionButtonProps();
|
|
327
|
+
return html `
|
|
328
|
+
<button
|
|
329
|
+
part="trigger"
|
|
330
|
+
type="button"
|
|
331
|
+
aria-haspopup="dialog"
|
|
332
|
+
aria-expanded=${this.open ? 'true' : 'false'}
|
|
333
|
+
@click=${this.handleTriggerClick}
|
|
334
|
+
@keydown=${this.handleTriggerKeyDown}
|
|
335
|
+
>
|
|
336
|
+
<slot name="trigger">Open alert dialog</slot>
|
|
337
|
+
</button>
|
|
338
|
+
|
|
339
|
+
<div
|
|
340
|
+
id=${overlayProps.id}
|
|
341
|
+
?hidden=${overlayProps.hidden}
|
|
342
|
+
data-open=${overlayProps['data-open']}
|
|
343
|
+
part="overlay"
|
|
344
|
+
@mousedown=${this.handleOverlayPointerDown}
|
|
345
|
+
>
|
|
346
|
+
<section
|
|
347
|
+
id=${dialogProps.id}
|
|
348
|
+
role=${dialogProps.role}
|
|
349
|
+
tabindex=${dialogProps.tabindex}
|
|
350
|
+
aria-modal=${dialogProps['aria-modal']}
|
|
351
|
+
aria-labelledby=${dialogProps['aria-labelledby']}
|
|
352
|
+
aria-describedby=${dialogProps['aria-describedby']}
|
|
353
|
+
data-initial-focus=${dialogProps['data-initial-focus'] ?? nothing}
|
|
354
|
+
part="content"
|
|
355
|
+
@keydown=${this.handleContentKeyDown}
|
|
356
|
+
>
|
|
357
|
+
<header part="header">
|
|
358
|
+
<h2 id=${titleProps.id} part="title">
|
|
359
|
+
<slot name="title">Confirm action</slot>
|
|
360
|
+
</h2>
|
|
361
|
+
<p id=${descriptionProps.id} part="description">
|
|
362
|
+
<slot name="description">This action cannot be undone.</slot>
|
|
363
|
+
</p>
|
|
364
|
+
</header>
|
|
365
|
+
|
|
366
|
+
<footer part="footer">
|
|
367
|
+
<button
|
|
368
|
+
id=${cancelProps.id}
|
|
369
|
+
role=${cancelProps.role}
|
|
370
|
+
tabindex=${cancelProps.tabindex}
|
|
371
|
+
type="button"
|
|
372
|
+
part="cancel"
|
|
373
|
+
@click=${this.handleCancelClick}
|
|
374
|
+
>
|
|
375
|
+
<slot name="cancel">Cancel</slot>
|
|
376
|
+
</button>
|
|
377
|
+
|
|
378
|
+
<button
|
|
379
|
+
id=${actionProps.id}
|
|
380
|
+
role=${actionProps.role}
|
|
381
|
+
tabindex=${actionProps.tabindex}
|
|
382
|
+
type="button"
|
|
383
|
+
part="action"
|
|
384
|
+
@click=${this.handleActionClick}
|
|
385
|
+
>
|
|
386
|
+
<slot name="action">Confirm</slot>
|
|
387
|
+
</button>
|
|
388
|
+
</footer>
|
|
389
|
+
</section>
|
|
390
|
+
</div>
|
|
391
|
+
`;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type AlertAriaLive } from '@chromvoid/headless-ui/alert';
|
|
2
|
+
import type { PropertyValues } from 'lit';
|
|
3
|
+
import { ReatomLitElement } from '../reatom-lit/ReatomLitElement.js';
|
|
4
|
+
export interface CVAlertEventDetail {
|
|
5
|
+
visible: boolean;
|
|
6
|
+
message: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class CVAlert extends ReatomLitElement {
|
|
9
|
+
static elementName: string;
|
|
10
|
+
static get properties(): {
|
|
11
|
+
durationMs: {
|
|
12
|
+
type: NumberConstructor;
|
|
13
|
+
attribute: string;
|
|
14
|
+
reflect: boolean;
|
|
15
|
+
};
|
|
16
|
+
ariaLive: {
|
|
17
|
+
type: StringConstructor;
|
|
18
|
+
attribute: string;
|
|
19
|
+
reflect: boolean;
|
|
20
|
+
};
|
|
21
|
+
atomic: {
|
|
22
|
+
type: BooleanConstructor;
|
|
23
|
+
attribute: string;
|
|
24
|
+
reflect: boolean;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
durationMs: number;
|
|
28
|
+
ariaLive: AlertAriaLive;
|
|
29
|
+
atomic: boolean;
|
|
30
|
+
private readonly idBase;
|
|
31
|
+
private model;
|
|
32
|
+
private currentVisible;
|
|
33
|
+
private currentMessage;
|
|
34
|
+
constructor();
|
|
35
|
+
static styles: import("lit").CSSResult[];
|
|
36
|
+
static define(): void;
|
|
37
|
+
connectedCallback(): void;
|
|
38
|
+
willUpdate(changedProperties: PropertyValues): void;
|
|
39
|
+
updated(changedProperties: PropertyValues): void;
|
|
40
|
+
show(message: string): void;
|
|
41
|
+
hide(): void;
|
|
42
|
+
private createModel;
|
|
43
|
+
private captureState;
|
|
44
|
+
private dispatchInput;
|
|
45
|
+
private dispatchChange;
|
|
46
|
+
private syncFromModel;
|
|
47
|
+
protected render(): import("lit").TemplateResult<1>;
|
|
48
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { createAlert } from '@chromvoid/headless-ui/alert';
|
|
2
|
+
import { css, html } from 'lit';
|
|
3
|
+
import { ReatomLitElement } from '../reatom-lit/ReatomLitElement.js';
|
|
4
|
+
let cvAlertNonce = 0;
|
|
5
|
+
export class CVAlert extends ReatomLitElement {
|
|
6
|
+
static elementName = 'cv-alert';
|
|
7
|
+
static get properties() {
|
|
8
|
+
return {
|
|
9
|
+
durationMs: { type: Number, attribute: 'duration-ms', reflect: true },
|
|
10
|
+
ariaLive: { type: String, attribute: 'aria-live', reflect: true },
|
|
11
|
+
atomic: { type: Boolean, attribute: 'aria-atomic', reflect: true },
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
idBase = `cv-alert-${++cvAlertNonce}`;
|
|
15
|
+
model;
|
|
16
|
+
currentVisible = false;
|
|
17
|
+
currentMessage = '';
|
|
18
|
+
constructor() {
|
|
19
|
+
super();
|
|
20
|
+
this.durationMs = 0;
|
|
21
|
+
this.ariaLive = 'assertive';
|
|
22
|
+
this.atomic = true;
|
|
23
|
+
this.model = this.createModel();
|
|
24
|
+
}
|
|
25
|
+
static styles = [
|
|
26
|
+
css `
|
|
27
|
+
:host {
|
|
28
|
+
display: block;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
[part='base'] {
|
|
32
|
+
display: grid;
|
|
33
|
+
gap: var(--cv-alert-gap, var(--cv-space-2, 8px));
|
|
34
|
+
padding: var(--cv-alert-padding-block, var(--cv-space-2, 8px))
|
|
35
|
+
var(--cv-alert-padding-inline, var(--cv-space-3, 12px));
|
|
36
|
+
border-radius: var(--cv-alert-radius, var(--cv-radius-sm, 6px));
|
|
37
|
+
border: 1px solid var(--cv-alert-border-color, var(--cv-color-border, #2a3245));
|
|
38
|
+
background: var(--cv-alert-background, var(--cv-color-surface-elevated, #1d2432));
|
|
39
|
+
color: var(--cv-alert-color, var(--cv-color-text, #e8ecf6));
|
|
40
|
+
transition:
|
|
41
|
+
opacity var(--cv-alert-transition-duration, var(--cv-duration-fast, 120ms))
|
|
42
|
+
var(--cv-alert-transition-easing, var(--cv-easing-standard, ease)),
|
|
43
|
+
transform var(--cv-alert-transition-duration, var(--cv-duration-fast, 120ms))
|
|
44
|
+
var(--cv-alert-transition-easing, var(--cv-easing-standard, ease));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
:host(:not([visible])) [part='base'] {
|
|
48
|
+
opacity: 0;
|
|
49
|
+
transform: translateY(var(--cv-alert-hidden-translate-y, -2px));
|
|
50
|
+
pointer-events: none;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
[part='message']:empty {
|
|
54
|
+
display: none;
|
|
55
|
+
}
|
|
56
|
+
`,
|
|
57
|
+
];
|
|
58
|
+
static define() {
|
|
59
|
+
if (!customElements.get(this.elementName)) {
|
|
60
|
+
customElements.define(this.elementName, this);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
connectedCallback() {
|
|
64
|
+
super.connectedCallback();
|
|
65
|
+
this.syncFromModel(false);
|
|
66
|
+
}
|
|
67
|
+
willUpdate(changedProperties) {
|
|
68
|
+
super.willUpdate(changedProperties);
|
|
69
|
+
if (changedProperties.has('durationMs') ||
|
|
70
|
+
changedProperties.has('ariaLive') ||
|
|
71
|
+
changedProperties.has('atomic')) {
|
|
72
|
+
const state = this.captureState();
|
|
73
|
+
this.model = this.createModel(state.message, state.visible);
|
|
74
|
+
this.syncFromModel(false);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
updated(changedProperties) {
|
|
78
|
+
super.updated(changedProperties);
|
|
79
|
+
if (changedProperties.has('durationMs') ||
|
|
80
|
+
changedProperties.has('ariaLive') ||
|
|
81
|
+
changedProperties.has('atomic')) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
this.syncFromModel(true);
|
|
85
|
+
}
|
|
86
|
+
show(message) {
|
|
87
|
+
this.model.actions.show(message);
|
|
88
|
+
this.syncFromModel(true);
|
|
89
|
+
}
|
|
90
|
+
hide() {
|
|
91
|
+
this.model.actions.hide();
|
|
92
|
+
this.syncFromModel(true);
|
|
93
|
+
}
|
|
94
|
+
createModel(initialMessage = '', initialVisible = false) {
|
|
95
|
+
return createAlert({
|
|
96
|
+
idBase: this.idBase,
|
|
97
|
+
ariaLive: this.ariaLive,
|
|
98
|
+
ariaAtomic: this.atomic,
|
|
99
|
+
durationMs: this.durationMs > 0 ? this.durationMs : undefined,
|
|
100
|
+
initialMessage,
|
|
101
|
+
initialVisible,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
captureState() {
|
|
105
|
+
return {
|
|
106
|
+
visible: this.model.state.isVisible(),
|
|
107
|
+
message: this.model.state.message(),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
dispatchInput(detail) {
|
|
111
|
+
this.dispatchEvent(new CustomEvent('cv-input', {
|
|
112
|
+
detail,
|
|
113
|
+
bubbles: true,
|
|
114
|
+
composed: true,
|
|
115
|
+
}));
|
|
116
|
+
}
|
|
117
|
+
dispatchChange(detail) {
|
|
118
|
+
this.dispatchEvent(new CustomEvent('cv-change', {
|
|
119
|
+
detail,
|
|
120
|
+
bubbles: true,
|
|
121
|
+
composed: true,
|
|
122
|
+
}));
|
|
123
|
+
}
|
|
124
|
+
syncFromModel(emitEvents) {
|
|
125
|
+
const next = this.captureState();
|
|
126
|
+
const visibleChanged = this.currentVisible !== next.visible;
|
|
127
|
+
const messageChanged = this.currentMessage !== next.message;
|
|
128
|
+
this.currentVisible = next.visible;
|
|
129
|
+
this.currentMessage = next.message;
|
|
130
|
+
this.toggleAttribute('visible', next.visible);
|
|
131
|
+
if (!emitEvents || (!visibleChanged && !messageChanged))
|
|
132
|
+
return;
|
|
133
|
+
this.dispatchInput(next);
|
|
134
|
+
if (visibleChanged) {
|
|
135
|
+
this.dispatchChange(next);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
render() {
|
|
139
|
+
const alertProps = this.model.contracts.getAlertProps();
|
|
140
|
+
const isVisible = this.model.state.isVisible();
|
|
141
|
+
const message = this.model.state.message();
|
|
142
|
+
return html `
|
|
143
|
+
<div
|
|
144
|
+
id=${alertProps.id}
|
|
145
|
+
role=${alertProps.role}
|
|
146
|
+
aria-live=${alertProps['aria-live']}
|
|
147
|
+
aria-atomic=${alertProps['aria-atomic']}
|
|
148
|
+
data-visible=${isVisible ? 'true' : 'false'}
|
|
149
|
+
part="base"
|
|
150
|
+
>
|
|
151
|
+
<div part="message">${message}</div>
|
|
152
|
+
<slot></slot>
|
|
153
|
+
</div>
|
|
154
|
+
`;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type BadgeVariant, type BadgeSize } from '@chromvoid/headless-ui/badge';
|
|
2
|
+
import type { PropertyValues } from 'lit';
|
|
3
|
+
import { ReatomLitElement } from '../reatom-lit/ReatomLitElement.js';
|
|
4
|
+
export declare class CVBadge extends ReatomLitElement {
|
|
5
|
+
static elementName: string;
|
|
6
|
+
static get properties(): {
|
|
7
|
+
variant: {
|
|
8
|
+
type: StringConstructor;
|
|
9
|
+
reflect: boolean;
|
|
10
|
+
};
|
|
11
|
+
size: {
|
|
12
|
+
type: StringConstructor;
|
|
13
|
+
reflect: boolean;
|
|
14
|
+
};
|
|
15
|
+
dot: {
|
|
16
|
+
type: BooleanConstructor;
|
|
17
|
+
reflect: boolean;
|
|
18
|
+
};
|
|
19
|
+
pulse: {
|
|
20
|
+
type: BooleanConstructor;
|
|
21
|
+
reflect: boolean;
|
|
22
|
+
};
|
|
23
|
+
pill: {
|
|
24
|
+
type: BooleanConstructor;
|
|
25
|
+
reflect: boolean;
|
|
26
|
+
};
|
|
27
|
+
dynamic: {
|
|
28
|
+
type: BooleanConstructor;
|
|
29
|
+
reflect: boolean;
|
|
30
|
+
};
|
|
31
|
+
decorative: {
|
|
32
|
+
type: BooleanConstructor;
|
|
33
|
+
reflect: boolean;
|
|
34
|
+
};
|
|
35
|
+
_ariaLabel: {
|
|
36
|
+
type: StringConstructor;
|
|
37
|
+
attribute: string;
|
|
38
|
+
reflect: boolean;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
variant: BadgeVariant;
|
|
42
|
+
size: BadgeSize;
|
|
43
|
+
dot: boolean;
|
|
44
|
+
pulse: boolean;
|
|
45
|
+
pill: boolean;
|
|
46
|
+
dynamic: boolean;
|
|
47
|
+
decorative: boolean;
|
|
48
|
+
_ariaLabel: string | null;
|
|
49
|
+
private model;
|
|
50
|
+
constructor();
|
|
51
|
+
static styles: import("lit").CSSResult[];
|
|
52
|
+
static define(): void;
|
|
53
|
+
willUpdate(changedProperties: PropertyValues): void;
|
|
54
|
+
private createModel;
|
|
55
|
+
protected render(): import("lit").TemplateResult<1>;
|
|
56
|
+
}
|