@f-ewald/components 1.26.0 → 1.27.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/custom-elements.json +1285 -95
- package/dist/calendar-day.d.ts +33 -0
- package/dist/calendar-day.d.ts.map +1 -0
- package/dist/calendar-day.js +280 -0
- package/dist/calendar-day.js.map +1 -0
- package/dist/calendar-timeline-base.d.ts +43 -0
- package/dist/calendar-timeline-base.d.ts.map +1 -0
- package/dist/calendar-timeline-base.js +113 -0
- package/dist/calendar-timeline-base.js.map +1 -0
- package/dist/calendar-week.d.ts +37 -0
- package/dist/calendar-week.d.ts.map +1 -0
- package/dist/calendar-week.js +315 -0
- package/dist/calendar-week.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp-server.js +1 -1
- package/dist/mcp-server.js.map +1 -1
- package/dist/modal-dialog.d.ts +49 -0
- package/dist/modal-dialog.d.ts.map +1 -0
- package/dist/modal-dialog.js +287 -0
- package/dist/modal-dialog.js.map +1 -0
- package/dist/ui-button.d.ts +2 -0
- package/dist/ui-button.d.ts.map +1 -1
- package/dist/ui-button.js +9 -1
- package/dist/ui-button.js.map +1 -1
- package/dist/utils/calendar.d.ts +41 -0
- package/dist/utils/calendar.d.ts.map +1 -1
- package/dist/utils/calendar.js +74 -0
- package/dist/utils/calendar.js.map +1 -1
- package/docs/calendar-day.md +70 -0
- package/docs/calendar-week.md +69 -0
- package/docs/modal-dialog.md +66 -0
- package/docs/ui-button.md +1 -0
- package/llms.txt +88 -1
- package/package.json +1 -1
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { LitElement, css, html, nothing } from "lit";
|
|
8
|
+
import { customElement, property } from "lit/decorators.js";
|
|
9
|
+
import { iconX } from "./icons.js";
|
|
10
|
+
import { tokens } from "./tokens.js";
|
|
11
|
+
import { activateLayer, claimEscape, deactivateLayer, isTopLayer } from "./utils/layer-stack.js";
|
|
12
|
+
/**
|
|
13
|
+
* Generic centered modal-dialog shell: overlay + card with header chrome, a
|
|
14
|
+
* close button, and an arbitrary slotted body — the modal sibling to
|
|
15
|
+
* `slide-panel` (fixed-edge) and `popover-panel` (anchored). Unlike
|
|
16
|
+
* `confirm-dialog`, it has no baked-in actions; the consumer supplies the
|
|
17
|
+
* body content (a form, a read-only viewer, a table) and any footer buttons
|
|
18
|
+
* itself. Instant `display:none` → `display:flex` toggle, no transition.
|
|
19
|
+
* Traps focus, closes on Escape, and restores focus to the trigger on
|
|
20
|
+
* close, stacking correctly against other open `confirm-dialog`/
|
|
21
|
+
* `slide-panel`/`popover-panel`/`modal-dialog` layers.
|
|
22
|
+
*
|
|
23
|
+
* @element modal-dialog
|
|
24
|
+
* @fires panel-close - User clicked the close (✕) button, pressed Escape, or (when `dismissible`) clicked the backdrop.
|
|
25
|
+
* @slot - Dialog body content.
|
|
26
|
+
* @slot title - Overrides the header title text (falls back to the `heading` property).
|
|
27
|
+
*/
|
|
28
|
+
let ModalDialog = class ModalDialog extends LitElement {
|
|
29
|
+
constructor() {
|
|
30
|
+
super(...arguments);
|
|
31
|
+
/** Whether the dialog is visible. */
|
|
32
|
+
this.open = false;
|
|
33
|
+
/** Title text shown in the dialog header (overridable via slot="title"). */
|
|
34
|
+
this.heading = "";
|
|
35
|
+
/**
|
|
36
|
+
* `"lg"` widens the dialog to 60rem for content like tables; `"default"`
|
|
37
|
+
* is 25rem; `"fullscreen"` covers the entire viewport edge-to-edge with
|
|
38
|
+
* no border-radius or overlay padding.
|
|
39
|
+
*/
|
|
40
|
+
this.size = "default";
|
|
41
|
+
/** When true, clicking the backdrop also closes the dialog (off by default — safe for forms with unsaved input). */
|
|
42
|
+
this.dismissible = false;
|
|
43
|
+
this._previousFocus = null;
|
|
44
|
+
this._onDocumentFocusIn = (event) => {
|
|
45
|
+
if (!this.open || !isTopLayer(this) || event.composedPath().includes(this))
|
|
46
|
+
return;
|
|
47
|
+
this._focusInitial();
|
|
48
|
+
};
|
|
49
|
+
this._onWindowKeydown = (event) => {
|
|
50
|
+
if (!this.open || !isTopLayer(this))
|
|
51
|
+
return;
|
|
52
|
+
if (claimEscape(this, event)) {
|
|
53
|
+
this._close();
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (event.key !== "Tab")
|
|
57
|
+
return;
|
|
58
|
+
const focusable = this._getFocusableElements();
|
|
59
|
+
if (focusable.length === 0) {
|
|
60
|
+
event.preventDefault();
|
|
61
|
+
this._focusInitial();
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const active = (this.shadowRoot?.activeElement ?? document.activeElement);
|
|
65
|
+
const index = focusable.indexOf(active);
|
|
66
|
+
if (event.shiftKey && index <= 0) {
|
|
67
|
+
event.preventDefault();
|
|
68
|
+
focusable.at(-1)?.focus();
|
|
69
|
+
}
|
|
70
|
+
else if (!event.shiftKey && index === focusable.length - 1) {
|
|
71
|
+
event.preventDefault();
|
|
72
|
+
focusable[0]?.focus();
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
this._onOverlayClick = (event) => {
|
|
76
|
+
if (this.dismissible && event.target === event.currentTarget)
|
|
77
|
+
this._close();
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
static { this.styles = [
|
|
81
|
+
tokens,
|
|
82
|
+
css `
|
|
83
|
+
.overlay {
|
|
84
|
+
position: fixed;
|
|
85
|
+
inset: 0;
|
|
86
|
+
background: var(--ui-overlay, rgb(15 23 42 / 0.45));
|
|
87
|
+
z-index: var(--component-layer-z, 50);
|
|
88
|
+
display: none;
|
|
89
|
+
align-items: flex-start;
|
|
90
|
+
justify-content: center;
|
|
91
|
+
padding: 10vh 1.25rem 1.25rem;
|
|
92
|
+
box-sizing: border-box;
|
|
93
|
+
}
|
|
94
|
+
.overlay.open {
|
|
95
|
+
display: flex;
|
|
96
|
+
}
|
|
97
|
+
.overlay.fullscreen {
|
|
98
|
+
padding: 0;
|
|
99
|
+
align-items: stretch;
|
|
100
|
+
}
|
|
101
|
+
.dialog {
|
|
102
|
+
background: var(--ui-surface, #ffffff);
|
|
103
|
+
border-radius: var(--ui-radius, 0.5rem);
|
|
104
|
+
box-shadow: var(
|
|
105
|
+
--ui-shadow-lg,
|
|
106
|
+
0 20px 25px -5px rgb(0 0 0 / 0.1),
|
|
107
|
+
0 8px 10px -6px rgb(0 0 0 / 0.1)
|
|
108
|
+
);
|
|
109
|
+
width: 100%;
|
|
110
|
+
max-width: min(25rem, calc(100vw - 2rem));
|
|
111
|
+
max-height: calc(100vh - 10vh - 1.25rem);
|
|
112
|
+
display: flex;
|
|
113
|
+
flex-direction: column;
|
|
114
|
+
overflow: hidden;
|
|
115
|
+
box-sizing: border-box;
|
|
116
|
+
outline: none;
|
|
117
|
+
}
|
|
118
|
+
.dialog.lg {
|
|
119
|
+
max-width: min(60rem, calc(100vw - 2rem));
|
|
120
|
+
}
|
|
121
|
+
.dialog.fullscreen {
|
|
122
|
+
width: 100vw;
|
|
123
|
+
height: 100vh;
|
|
124
|
+
max-width: 100vw;
|
|
125
|
+
max-height: 100vh;
|
|
126
|
+
border-radius: 0;
|
|
127
|
+
}
|
|
128
|
+
.dialog-header {
|
|
129
|
+
display: flex;
|
|
130
|
+
align-items: center;
|
|
131
|
+
justify-content: space-between;
|
|
132
|
+
padding: 0.75rem;
|
|
133
|
+
border-bottom: 1px solid var(--ui-border, #e2e8f0);
|
|
134
|
+
flex: 0 0 auto;
|
|
135
|
+
}
|
|
136
|
+
.dialog-title {
|
|
137
|
+
font-weight: var(--ui-font-weight-semibold, 600);
|
|
138
|
+
font-size: var(--ui-font-size-lg, 1rem);
|
|
139
|
+
line-height: var(--ui-line-height-tight, 1.25);
|
|
140
|
+
font-family: var(
|
|
141
|
+
--ui-font,
|
|
142
|
+
ui-sans-serif,
|
|
143
|
+
system-ui,
|
|
144
|
+
sans-serif,
|
|
145
|
+
"Apple Color Emoji",
|
|
146
|
+
"Segoe UI Emoji",
|
|
147
|
+
"Segoe UI Symbol",
|
|
148
|
+
"Noto Color Emoji"
|
|
149
|
+
);
|
|
150
|
+
color: var(--ui-text, #0f172a);
|
|
151
|
+
flex: 1 1 auto;
|
|
152
|
+
overflow: hidden;
|
|
153
|
+
white-space: nowrap;
|
|
154
|
+
text-overflow: ellipsis;
|
|
155
|
+
padding-right: 0.5rem;
|
|
156
|
+
}
|
|
157
|
+
.close-btn {
|
|
158
|
+
background: none;
|
|
159
|
+
border: none;
|
|
160
|
+
cursor: pointer;
|
|
161
|
+
width: 2rem;
|
|
162
|
+
height: 2rem;
|
|
163
|
+
padding: 0;
|
|
164
|
+
color: var(--ui-text-muted, #64748b);
|
|
165
|
+
border-radius: var(--ui-radius-sm, 0.25rem);
|
|
166
|
+
flex: 0 0 auto;
|
|
167
|
+
display: inline-flex;
|
|
168
|
+
align-items: center;
|
|
169
|
+
justify-content: center;
|
|
170
|
+
}
|
|
171
|
+
.close-btn:hover {
|
|
172
|
+
background: var(--ui-surface-muted, #f8fafc);
|
|
173
|
+
}
|
|
174
|
+
.close-btn:focus-visible {
|
|
175
|
+
outline: none;
|
|
176
|
+
box-shadow: var(--ui-focus-ring, 0 0 0 3px rgb(79 70 229 / 0.35));
|
|
177
|
+
}
|
|
178
|
+
.body {
|
|
179
|
+
overflow-y: auto;
|
|
180
|
+
flex: 1 1 auto;
|
|
181
|
+
}
|
|
182
|
+
@media (forced-colors: active) {
|
|
183
|
+
.close-btn:focus-visible {
|
|
184
|
+
outline: 2px solid CanvasText;
|
|
185
|
+
outline-offset: 2px;
|
|
186
|
+
box-shadow: none;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
@media (max-width: 48rem) {
|
|
190
|
+
.overlay {
|
|
191
|
+
padding: 0.75rem;
|
|
192
|
+
overflow-y: auto;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
`,
|
|
196
|
+
]; }
|
|
197
|
+
_close() {
|
|
198
|
+
this.dispatchEvent(new CustomEvent("panel-close", { bubbles: true, composed: true }));
|
|
199
|
+
}
|
|
200
|
+
_getFocusableElements() {
|
|
201
|
+
const selector = "a[href], button:not(:disabled), input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex='-1'])";
|
|
202
|
+
const slotted = Array.from(this.querySelectorAll(selector));
|
|
203
|
+
const internal = Array.from(this.shadowRoot?.querySelectorAll(selector) ?? []).filter((element) => element.closest(".dialog") !== null);
|
|
204
|
+
return [...slotted, ...internal].filter((element) => !element.hasAttribute("hidden"));
|
|
205
|
+
}
|
|
206
|
+
_focusInitial() {
|
|
207
|
+
const autofocus = this.querySelector("[autofocus]");
|
|
208
|
+
const close = this.shadowRoot?.querySelector(".close-btn");
|
|
209
|
+
const dialog = this.shadowRoot?.querySelector(".dialog");
|
|
210
|
+
(autofocus ?? close ?? this._getFocusableElements()[0] ?? dialog)?.focus();
|
|
211
|
+
}
|
|
212
|
+
updated(changed) {
|
|
213
|
+
if (!changed.has("open"))
|
|
214
|
+
return;
|
|
215
|
+
if (this.open) {
|
|
216
|
+
activateLayer(this);
|
|
217
|
+
this._previousFocus = document.activeElement;
|
|
218
|
+
document.addEventListener("focusin", this._onDocumentFocusIn, true);
|
|
219
|
+
window.addEventListener("keydown", this._onWindowKeydown, true);
|
|
220
|
+
this._focusInitial();
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
deactivateLayer(this);
|
|
224
|
+
document.removeEventListener("focusin", this._onDocumentFocusIn, true);
|
|
225
|
+
window.removeEventListener("keydown", this._onWindowKeydown, true);
|
|
226
|
+
if (this._previousFocus?.isConnected)
|
|
227
|
+
this._previousFocus.focus();
|
|
228
|
+
this._previousFocus = null;
|
|
229
|
+
}
|
|
230
|
+
disconnectedCallback() {
|
|
231
|
+
super.disconnectedCallback();
|
|
232
|
+
document.removeEventListener("focusin", this._onDocumentFocusIn, true);
|
|
233
|
+
window.removeEventListener("keydown", this._onWindowKeydown, true);
|
|
234
|
+
deactivateLayer(this);
|
|
235
|
+
if (this._previousFocus?.isConnected)
|
|
236
|
+
this._previousFocus.focus();
|
|
237
|
+
this._previousFocus = null;
|
|
238
|
+
this.open = false;
|
|
239
|
+
}
|
|
240
|
+
render() {
|
|
241
|
+
const explicitLabel = this.getAttribute("aria-label");
|
|
242
|
+
return html `
|
|
243
|
+
<div
|
|
244
|
+
class="overlay ${this.open ? "open" : ""} ${this.size === "fullscreen" ? "fullscreen" : ""}"
|
|
245
|
+
@click=${this._onOverlayClick}
|
|
246
|
+
>
|
|
247
|
+
<div
|
|
248
|
+
class="dialog ${this.size === "lg" ? "lg" : this.size === "fullscreen" ? "fullscreen" : ""}"
|
|
249
|
+
role="dialog"
|
|
250
|
+
aria-modal="true"
|
|
251
|
+
aria-label=${explicitLabel ?? nothing}
|
|
252
|
+
aria-labelledby=${explicitLabel ? nothing : "dialog-title"}
|
|
253
|
+
tabindex="-1"
|
|
254
|
+
>
|
|
255
|
+
<div class="dialog-header">
|
|
256
|
+
<span id="dialog-title" class="dialog-title">
|
|
257
|
+
<slot name="title">${this.heading}</slot>
|
|
258
|
+
</span>
|
|
259
|
+
<button class="close-btn" aria-label="Close" @click=${this._close}>
|
|
260
|
+
<span aria-hidden="true">${iconX(18)}</span>
|
|
261
|
+
</button>
|
|
262
|
+
</div>
|
|
263
|
+
<div class="body">
|
|
264
|
+
<slot></slot>
|
|
265
|
+
</div>
|
|
266
|
+
</div>
|
|
267
|
+
</div>
|
|
268
|
+
`;
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
__decorate([
|
|
272
|
+
property({ type: Boolean })
|
|
273
|
+
], ModalDialog.prototype, "open", void 0);
|
|
274
|
+
__decorate([
|
|
275
|
+
property()
|
|
276
|
+
], ModalDialog.prototype, "heading", void 0);
|
|
277
|
+
__decorate([
|
|
278
|
+
property()
|
|
279
|
+
], ModalDialog.prototype, "size", void 0);
|
|
280
|
+
__decorate([
|
|
281
|
+
property({ type: Boolean })
|
|
282
|
+
], ModalDialog.prototype, "dismissible", void 0);
|
|
283
|
+
ModalDialog = __decorate([
|
|
284
|
+
customElement("modal-dialog")
|
|
285
|
+
], ModalDialog);
|
|
286
|
+
export { ModalDialog };
|
|
287
|
+
//# sourceMappingURL=modal-dialog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modal-dialog.js","sourceRoot":"","sources":["../src/modal-dialog.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAuB,MAAM,KAAK,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAIjG;;;;;;;;;;;;;;;GAeG;AAEI,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,UAAU;IAApC;;QAuHL,qCAAqC;QACR,SAAI,GAAG,KAAK,CAAC;QAC1C,4EAA4E;QAChE,YAAO,GAAG,EAAE,CAAC;QACzB;;;;WAIG;QACS,SAAI,GAAoB,SAAS,CAAC;QAC9C,oHAAoH;QACvF,gBAAW,GAAG,KA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QAAQ,EAAE;4CAAc;AAMb;IAAX,QAAQ,EAAE;yCAAmC;AAEjB;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;gDAAqB;AAlItC,WAAW;IADvB,aAAa,CAAC,cAAc,CAAC;GACjB,WAAW,CAsPvB","sourcesContent":["import { LitElement, css, html, nothing, type PropertyValues } from \"lit\";\nimport { customElement, property } from \"lit/decorators.js\";\nimport { iconX } from \"./icons.js\";\nimport { tokens } from \"./tokens.js\";\nimport { activateLayer, claimEscape, deactivateLayer, isTopLayer } from \"./utils/layer-stack.js\";\n\nexport type ModalDialogSize = \"default\" | \"lg\" | \"fullscreen\";\n\n/**\n * Generic centered modal-dialog shell: overlay + card with header chrome, a\n * close button, and an arbitrary slotted body — the modal sibling to\n * `slide-panel` (fixed-edge) and `popover-panel` (anchored). Unlike\n * `confirm-dialog`, it has no baked-in actions; the consumer supplies the\n * body content (a form, a read-only viewer, a table) and any footer buttons\n * itself. Instant `display:none` → `display:flex` toggle, no transition.\n * Traps focus, closes on Escape, and restores focus to the trigger on\n * close, stacking correctly against other open `confirm-dialog`/\n * `slide-panel`/`popover-panel`/`modal-dialog` layers.\n *\n * @element modal-dialog\n * @fires panel-close - User clicked the close (✕) button, pressed Escape, or (when `dismissible`) clicked the backdrop.\n * @slot - Dialog body content.\n * @slot title - Overrides the header title text (falls back to the `heading` property).\n */\n@customElement(\"modal-dialog\")\nexport class ModalDialog extends LitElement {\n static override styles = [\n tokens,\n css`\n .overlay {\n position: fixed;\n inset: 0;\n background: var(--ui-overlay, rgb(15 23 42 / 0.45));\n z-index: var(--component-layer-z, 50);\n display: none;\n align-items: flex-start;\n justify-content: center;\n padding: 10vh 1.25rem 1.25rem;\n box-sizing: border-box;\n }\n .overlay.open {\n display: flex;\n }\n .overlay.fullscreen {\n padding: 0;\n align-items: stretch;\n }\n .dialog {\n background: var(--ui-surface, #ffffff);\n border-radius: var(--ui-radius, 0.5rem);\n box-shadow: var(\n --ui-shadow-lg,\n 0 20px 25px -5px rgb(0 0 0 / 0.1),\n 0 8px 10px -6px rgb(0 0 0 / 0.1)\n );\n width: 100%;\n max-width: min(25rem, calc(100vw - 2rem));\n max-height: calc(100vh - 10vh - 1.25rem);\n display: flex;\n flex-direction: column;\n overflow: hidden;\n box-sizing: border-box;\n outline: none;\n }\n .dialog.lg {\n max-width: min(60rem, calc(100vw - 2rem));\n }\n .dialog.fullscreen {\n width: 100vw;\n height: 100vh;\n max-width: 100vw;\n max-height: 100vh;\n border-radius: 0;\n }\n .dialog-header {\n display: flex;\n align-items: center;\n justify-content: space-between;\n padding: 0.75rem;\n border-bottom: 1px solid var(--ui-border, #e2e8f0);\n flex: 0 0 auto;\n }\n .dialog-title {\n font-weight: var(--ui-font-weight-semibold, 600);\n font-size: var(--ui-font-size-lg, 1rem);\n line-height: var(--ui-line-height-tight, 1.25);\n font-family: var(\n --ui-font,\n ui-sans-serif,\n system-ui,\n sans-serif,\n \"Apple Color Emoji\",\n \"Segoe UI Emoji\",\n \"Segoe UI Symbol\",\n \"Noto Color Emoji\"\n );\n color: var(--ui-text, #0f172a);\n flex: 1 1 auto;\n overflow: hidden;\n white-space: nowrap;\n text-overflow: ellipsis;\n padding-right: 0.5rem;\n }\n .close-btn {\n background: none;\n border: none;\n cursor: pointer;\n width: 2rem;\n height: 2rem;\n padding: 0;\n color: var(--ui-text-muted, #64748b);\n border-radius: var(--ui-radius-sm, 0.25rem);\n flex: 0 0 auto;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n }\n .close-btn:hover {\n background: var(--ui-surface-muted, #f8fafc);\n }\n .close-btn:focus-visible {\n outline: none;\n box-shadow: var(--ui-focus-ring, 0 0 0 3px rgb(79 70 229 / 0.35));\n }\n .body {\n overflow-y: auto;\n flex: 1 1 auto;\n }\n @media (forced-colors: active) {\n .close-btn:focus-visible {\n outline: 2px solid CanvasText;\n outline-offset: 2px;\n box-shadow: none;\n }\n }\n @media (max-width: 48rem) {\n .overlay {\n padding: 0.75rem;\n overflow-y: auto;\n }\n }\n `,\n ];\n\n /** Whether the dialog is visible. */\n @property({ type: Boolean }) open = false;\n /** Title text shown in the dialog header (overridable via slot=\"title\"). */\n @property() heading = \"\";\n /**\n * `\"lg\"` widens the dialog to 60rem for content like tables; `\"default\"`\n * is 25rem; `\"fullscreen\"` covers the entire viewport edge-to-edge with\n * no border-radius or overlay padding.\n */\n @property() size: ModalDialogSize = \"default\";\n /** When true, clicking the backdrop also closes the dialog (off by default — safe for forms with unsaved input). */\n @property({ type: Boolean }) dismissible = false;\n\n private _previousFocus: HTMLElement | null = null;\n\n private _close() {\n this.dispatchEvent(new CustomEvent(\"panel-close\", { bubbles: true, composed: true }));\n }\n\n private _getFocusableElements(): HTMLElement[] {\n const selector =\n \"a[href], button:not(:disabled), input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex='-1'])\";\n const slotted = Array.from(this.querySelectorAll<HTMLElement>(selector));\n const internal = Array.from(\n this.shadowRoot?.querySelectorAll<HTMLElement>(selector) ?? [],\n ).filter((element) => element.closest(\".dialog\") !== null);\n return [...slotted, ...internal].filter((element) => !element.hasAttribute(\"hidden\"));\n }\n\n private _focusInitial(): void {\n const autofocus = this.querySelector<HTMLElement>(\"[autofocus]\");\n const close = this.shadowRoot?.querySelector<HTMLElement>(\".close-btn\");\n const dialog = this.shadowRoot?.querySelector<HTMLElement>(\".dialog\");\n (autofocus ?? close ?? this._getFocusableElements()[0] ?? dialog)?.focus();\n }\n\n private _onDocumentFocusIn = (event: FocusEvent): void => {\n if (!this.open || !isTopLayer(this) || event.composedPath().includes(this)) return;\n this._focusInitial();\n };\n\n private _onWindowKeydown = (event: KeyboardEvent): void => {\n if (!this.open || !isTopLayer(this)) return;\n if (claimEscape(this, event)) {\n this._close();\n return;\n }\n if (event.key !== \"Tab\") return;\n\n const focusable = this._getFocusableElements();\n if (focusable.length === 0) {\n event.preventDefault();\n this._focusInitial();\n return;\n }\n const active = (this.shadowRoot?.activeElement ?? document.activeElement) as HTMLElement | null;\n const index = focusable.indexOf(active as HTMLElement);\n if (event.shiftKey && index <= 0) {\n event.preventDefault();\n focusable.at(-1)?.focus();\n } else if (!event.shiftKey && index === focusable.length - 1) {\n event.preventDefault();\n focusable[0]?.focus();\n }\n };\n\n private _onOverlayClick = (event: MouseEvent): void => {\n if (this.dismissible && event.target === event.currentTarget) this._close();\n };\n\n protected override updated(changed: PropertyValues): void {\n if (!changed.has(\"open\")) return;\n if (this.open) {\n activateLayer(this);\n this._previousFocus = document.activeElement as HTMLElement | null;\n document.addEventListener(\"focusin\", this._onDocumentFocusIn, true);\n window.addEventListener(\"keydown\", this._onWindowKeydown, true);\n this._focusInitial();\n return;\n }\n deactivateLayer(this);\n document.removeEventListener(\"focusin\", this._onDocumentFocusIn, true);\n window.removeEventListener(\"keydown\", this._onWindowKeydown, true);\n if (this._previousFocus?.isConnected) this._previousFocus.focus();\n this._previousFocus = null;\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n document.removeEventListener(\"focusin\", this._onDocumentFocusIn, true);\n window.removeEventListener(\"keydown\", this._onWindowKeydown, true);\n deactivateLayer(this);\n if (this._previousFocus?.isConnected) this._previousFocus.focus();\n this._previousFocus = null;\n this.open = false;\n }\n\n override render() {\n const explicitLabel = this.getAttribute(\"aria-label\");\n return html`\n <div\n class=\"overlay ${this.open ? \"open\" : \"\"} ${this.size === \"fullscreen\" ? \"fullscreen\" : \"\"}\"\n @click=${this._onOverlayClick}\n >\n <div\n class=\"dialog ${this.size === \"lg\" ? \"lg\" : this.size === \"fullscreen\" ? \"fullscreen\" : \"\"}\"\n role=\"dialog\"\n aria-modal=\"true\"\n aria-label=${explicitLabel ?? nothing}\n aria-labelledby=${explicitLabel ? nothing : \"dialog-title\"}\n tabindex=\"-1\"\n >\n <div class=\"dialog-header\">\n <span id=\"dialog-title\" class=\"dialog-title\">\n <slot name=\"title\">${this.heading}</slot>\n </span>\n <button class=\"close-btn\" aria-label=\"Close\" @click=${this._close}>\n <span aria-hidden=\"true\">${iconX(18)}</span>\n </button>\n </div>\n <div class=\"body\">\n <slot></slot>\n </div>\n </div>\n </div>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"modal-dialog\": ModalDialog;\n }\n}\n"]}
|
package/dist/ui-button.d.ts
CHANGED
|
@@ -44,6 +44,8 @@ export declare class UiButton extends LitElement {
|
|
|
44
44
|
variant: ButtonVariant;
|
|
45
45
|
/** Size — `sm` reduces height/padding/font-size one step below the default. */
|
|
46
46
|
size: "sm" | "md";
|
|
47
|
+
/** Renders fully rounded (pill-shaped) corners instead of the default `--ui-radius-sm`. */
|
|
48
|
+
pill: boolean;
|
|
47
49
|
/** Renders an `<a href="...">` instead of a `<button>` when set. */
|
|
48
50
|
href: string | null;
|
|
49
51
|
/** Native button `type`. Ignored when `href` is set. */
|
package/dist/ui-button.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ui-button.d.ts","sourceRoot":"","sources":["../src/ui-button.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAa,MAAM,KAAK,CAAC;AAK5C,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,qBACa,QAAS,SAAQ,UAAU;;IACtC,MAAM,CAAC,cAAc,UAAQ;IAG7B,OAAgB,MAAM,
|
|
1
|
+
{"version":3,"file":"ui-button.d.ts","sourceRoot":"","sources":["../src/ui-button.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAa,MAAM,KAAK,CAAC;AAK5C,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,qBACa,QAAS,SAAQ,UAAU;;IACtC,MAAM,CAAC,cAAc,UAAQ;IAG7B,OAAgB,MAAM,4BA+HpB;IAEF,qBAAqB;IACT,OAAO,EAAE,aAAa,CAAa;IAC/C,+EAA+E;IACnE,IAAI,EAAE,IAAI,GAAG,IAAI,CAAQ;IACrC,2FAA2F;IAC9D,IAAI,UAAS;IAC1C,oEAAoE;IACxD,IAAI,EAAE,MAAM,GAAG,IAAI,CAAQ;IACvC,wDAAwD;IAC5C,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,OAAO,CAAY;IAC3D,wCAAwC;IACX,QAAQ,UAAS;IAC9C,0EAA0E;IAC7C,IAAI,UAAS;IAE1C,qHAAqH;IACrH,OAAO,CAAC,QAAQ;IAKhB,4EAA4E;IAC5E,OAAO,CAAC,YAAY;IAKX,MAAM,yCA+Bd;CACF;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,WAAW,EAAE,QAAQ,CAAC;KACvB;CACF"}
|
package/dist/ui-button.js
CHANGED
|
@@ -52,6 +52,8 @@ let UiButton = class UiButton extends LitElement {
|
|
|
52
52
|
this.variant = "primary";
|
|
53
53
|
/** Size — `sm` reduces height/padding/font-size one step below the default. */
|
|
54
54
|
this.size = "md";
|
|
55
|
+
/** Renders fully rounded (pill-shaped) corners instead of the default `--ui-radius-sm`. */
|
|
56
|
+
this.pill = false;
|
|
55
57
|
/** Renders an `<a href="...">` instead of a `<button>` when set. */
|
|
56
58
|
this.href = null;
|
|
57
59
|
/** Native button `type`. Ignored when `href` is set. */
|
|
@@ -156,6 +158,9 @@ let UiButton = class UiButton extends LitElement {
|
|
|
156
158
|
padding: 0.25rem 0.5rem;
|
|
157
159
|
font-size: var(--ui-font-size-xs, 0.6875rem);
|
|
158
160
|
}
|
|
161
|
+
.btn.pill {
|
|
162
|
+
border-radius: 999px;
|
|
163
|
+
}
|
|
159
164
|
.spin {
|
|
160
165
|
display: inline-flex;
|
|
161
166
|
animation: spin 0.8s linear infinite;
|
|
@@ -202,7 +207,7 @@ let UiButton = class UiButton extends LitElement {
|
|
|
202
207
|
e.preventDefault();
|
|
203
208
|
}
|
|
204
209
|
render() {
|
|
205
|
-
const classes = `btn ${this.variant} ${this.size}`;
|
|
210
|
+
const classes = `btn ${this.variant} ${this.size}${this.pill ? " pill" : ""}`;
|
|
206
211
|
const isDisabled = this.disabled || this.busy;
|
|
207
212
|
if (this.href) {
|
|
208
213
|
return html `
|
|
@@ -240,6 +245,9 @@ __decorate([
|
|
|
240
245
|
__decorate([
|
|
241
246
|
property()
|
|
242
247
|
], UiButton.prototype, "size", void 0);
|
|
248
|
+
__decorate([
|
|
249
|
+
property({ type: Boolean })
|
|
250
|
+
], UiButton.prototype, "pill", void 0);
|
|
243
251
|
__decorate([
|
|
244
252
|
property()
|
|
245
253
|
], UiButton.prototype, "href", void 0);
|
package/dist/ui-button.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ui-button.js","sourceRoot":"","sources":["../src/ui-button.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAIrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEI,IAAM,QAAQ,GAAd,MAAM,QAAS,SAAQ,UAAU;IAAjC;;QAGL,eAAU,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;QA+HpC,qBAAqB;QACT,YAAO,GAAkB,SAAS,CAAC;QAC/C,+EAA+E;QACnE,SAAI,GAAgB,IAAI,CAAC;QACrC,oEAAoE;QACxD,SAAI,GAAkB,IAAI,CAAC;QACvC,wDAAwD;QAC5C,SAAI,GAAkC,QAAQ,CAAC;QAC3D,wCAAwC;QACX,aAAQ,GAAG,KAAK,CAAC;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a,CAAC,EAAE,CAAC;sCACnD,IAAI,CAAC,IAAI;;;OAGxC,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,CAAA;;gBAEC,OAAO;;oBAEH,UAAU;oBACV,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO;iBAC/B,IAAI,CAAC,QAAQ;;wDAE0B,CAAC,IAAI,CAAC,IAAI,IAAI,aAAa,CAAC,EAAE,CAAC;oCACnD,IAAI,CAAC,IAAI;;;KAGxC,CAAC;IACJ,CAAC;CACF,CAAA;AAxDa;IAAX,QAAQ,EAAE;yCAAoC;AAEnC;IAAX,QAAQ,EAAE;sCAA0B;AAEzB;IAAX,QAAQ,EAAE;sCAA4B;AAE3B;IAAX,QAAQ,EAAE;sCAAgD;AAE9B;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;0CAAkB;AAEjB;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;sCAAc;AA7I/B,QAAQ;IADpB,aAAa,CAAC,WAAW,CAAC;GACd,QAAQ,CA2LpB","sourcesContent":["import { LitElement, css, html } from \"lit\";\nimport { customElement, property } from \"lit/decorators.js\";\nimport { iconArrowPath } from \"./icons.js\";\nimport { tokens } from \"./tokens.js\";\n\nexport type ButtonVariant = \"primary\" | \"secondary\" | \"danger\";\n\n/**\n * Button (or link styled as one) with an optional leading icon, in three\n * visual weights. Set `href` to render an `<a>` instead of a `<button>` —\n * same styling either way — for cross-page navigation that should look like\n * an action button; a disabled/busy link stays a real `<a>` with\n * `aria-disabled` + `pointer-events: none` rather than losing its href.\n * Put the icon in the `icon` slot and the label in the default slot.\n *\n * Form-associated (`type=\"submit\"`/`\"reset\"`): the actual `<button>` lives in\n * this element's shadow root, which native HTML form association does not\n * cross into from an ancestor light-DOM `<form>`. `type=\"submit\"`/`\"reset\"`\n * is instead wired through `ElementInternals.form` — the same mechanism\n * `address-autocomplete` uses to associate with an ancestor form.\n *\n * `primary`/`danger` backgrounds read `--ui-button-background`/\n * `--ui-button-danger-background` (and their `-hover`/`-active`\n * counterparts), which default to the flat `--ui-primary`/`--ui-danger`\n * tokens unchanged — so `--ui-primary`/`--ui-danger` stay the single source\n * of truth for every other component. A consumer can override just these\n * button-specific tokens with a `linear-gradient(...)` to opt every\n * `ui-button` into a gradient look without touching component markup —\n * `gradientTokenValues` in `tokens.ts` ships exactly this, wired up via\n * `data-theme=\"gradient\"` (see `tokens.css`'s \"Gradient theme\" section) —\n * pairing it with `--ui-button-border`/`--ui-button-danger-border` (default\n * `transparent`) for a defining edge a shade darker than the gradient's dark\n * stop, and setting the `-active` variant's stops in reverse for a\n * pressed/\"indented\" look while the button is held down. `secondary`'s\n * background/border read the equivalent `--ui-button-secondary-*` tokens\n * (shared with `confirm-dialog`'s Cancel button), defaulting to today's\n * transparent/bordered look, so it can be themed into a matching (e.g.\n * white-to-gray) gradient too.\n *\n * @element ui-button\n * @slot icon - Optional leading icon (e.g. an inline SVG).\n * @slot - Button label.\n */\n@customElement(\"ui-button\")\nexport class UiButton extends LitElement {\n static formAssociated = true;\n\n #internals = this.attachInternals();\n static override styles = [\n tokens,\n css`\n :host {\n display: inline-flex;\n }\n .btn {\n display: inline-flex;\n align-items: center;\n gap: 0.25rem;\n height: 2rem;\n border-radius: var(--ui-radius-sm, 0.25rem);\n padding: 0.5rem 1rem;\n font-size: var(--ui-font-size-sm, 0.75rem);\n font-weight: var(--ui-font-weight-medium, 500);\n line-height: var(--ui-line-height-tight, 1.25);\n font-family: var(\n --ui-font,\n ui-sans-serif,\n system-ui,\n sans-serif,\n \"Apple Color Emoji\",\n \"Segoe UI Emoji\",\n \"Segoe UI Symbol\",\n \"Noto Color Emoji\"\n );\n cursor: pointer;\n border: 1px solid transparent;\n text-decoration: none;\n box-sizing: border-box;\n }\n .btn.primary {\n background: var(--ui-button-background, var(--ui-primary, #4f46e5));\n border-color: var(--ui-button-border, transparent);\n color: var(--ui-on-accent, #ffffff);\n box-shadow: var(--ui-button-highlight, 0 0 0 0 transparent);\n text-shadow: var(--ui-button-text-shadow, none);\n }\n .btn.primary:hover:not(:disabled) {\n background: var(--ui-button-background-hover, var(--ui-primary-hover, #4338ca));\n }\n .btn.primary:active:not(:disabled) {\n background: var(--ui-button-background-active, var(--ui-button-background, var(--ui-primary, #4f46e5)));\n box-shadow: none;\n }\n .btn.secondary {\n background: var(--ui-button-secondary-background, none);\n border-color: var(--ui-button-secondary-border, var(--ui-border, #e2e8f0));\n color: var(--ui-text, #0f172a);\n box-shadow: var(--ui-button-highlight, 0 0 0 0 transparent);\n }\n .btn.secondary:hover:not(:disabled) {\n background: var(--ui-button-secondary-background-hover, none);\n border-color: var(--ui-button-secondary-border-hover, var(--ui-text-muted, #64748b));\n }\n .btn.secondary:active:not(:disabled) {\n background: var(--ui-button-secondary-background-active, var(--ui-button-secondary-background, none));\n box-shadow: none;\n }\n .btn.danger {\n background: var(--ui-button-danger-background, var(--ui-danger, #dc2626));\n border-color: var(--ui-button-danger-border, transparent);\n color: var(--ui-on-accent, #ffffff);\n box-shadow: var(--ui-button-highlight, 0 0 0 0 transparent);\n text-shadow: var(--ui-button-text-shadow, none);\n }\n .btn.danger:hover:not(:disabled) {\n background: var(--ui-button-danger-background-hover, var(--ui-danger-hover, #b91c1c));\n }\n .btn.danger:active:not(:disabled) {\n background: var(--ui-button-danger-background-active, var(--ui-button-danger-background, var(--ui-danger, #dc2626)));\n box-shadow: none;\n }\n .btn:disabled,\n .btn[aria-disabled=\"true\"] {\n opacity: 0.6;\n cursor: default;\n pointer-events: none;\n }\n .btn:focus-visible {\n outline: none;\n box-shadow: var(--ui-focus-ring, 0 0 0 3px rgb(79 70 229 / 0.35));\n }\n .btn.primary:focus-visible:not(:active),\n .btn.danger:focus-visible:not(:active),\n .btn.secondary:focus-visible:not(:active) {\n box-shadow: var(--ui-focus-ring, 0 0 0 3px rgb(79 70 229 / 0.35)), var(--ui-button-highlight, 0 0 0 0 transparent);\n }\n .btn.sm {\n height: 1.5rem;\n padding: 0.25rem 0.5rem;\n font-size: var(--ui-font-size-xs, 0.6875rem);\n }\n .spin {\n display: inline-flex;\n animation: spin 0.8s linear infinite;\n }\n .spin[hidden] {\n display: none;\n }\n @keyframes spin {\n to {\n transform: rotate(360deg);\n }\n }\n @media (prefers-reduced-motion: reduce) {\n .spin {\n animation: none;\n }\n }\n @media (forced-colors: active) {\n .btn:focus-visible {\n outline: 2px solid CanvasText;\n outline-offset: 2px;\n box-shadow: none;\n }\n .btn:disabled,\n .btn[aria-disabled=\"true\"] {\n color: GrayText;\n border-color: GrayText;\n opacity: 1;\n }\n }\n `,\n ];\n\n /** Visual weight. */\n @property() variant: ButtonVariant = \"primary\";\n /** Size — `sm` reduces height/padding/font-size one step below the default. */\n @property() size: \"sm\" | \"md\" = \"md\";\n /** Renders an `<a href=\"...\">` instead of a `<button>` when set. */\n @property() href: string | null = null;\n /** Native button `type`. Ignored when `href` is set. */\n @property() type: \"button\" | \"submit\" | \"reset\" = \"button\";\n /** Disables the control and dims it. */\n @property({ type: Boolean }) disabled = false;\n /** Shows a spinner in place of the icon slot and disables the control. */\n @property({ type: Boolean }) busy = false;\n\n /** Drives submit/reset on the ancestor form via ElementInternals, since a shadow-DOM button can't do it natively. */\n private _onClick() {\n if (this.type === \"submit\") this.#internals.form?.requestSubmit();\n else if (this.type === \"reset\") this.#internals.form?.reset();\n }\n\n /** Suppresses navigation while a link-styled button is disabled or busy. */\n private _onLinkClick(e: MouseEvent) {\n if (!this.disabled && !this.busy) return;\n e.preventDefault();\n }\n\n override render() {\n const classes = `btn ${this.variant} ${this.size}`;\n const isDisabled = this.disabled || this.busy;\n if (this.href) {\n return html`\n <a\n class=${classes}\n href=${this.href}\n aria-disabled=${isDisabled ? \"true\" : \"false\"}\n aria-busy=${this.busy ? \"true\" : \"false\"}\n @click=${this._onLinkClick}\n >\n <span class=\"spin\" aria-hidden=\"true\" ?hidden=${!this.busy}>${iconArrowPath(14)}</span>\n <slot name=\"icon\" ?hidden=${this.busy}></slot>\n <slot></slot>\n </a>\n `;\n }\n return html`\n <button\n class=${classes}\n type=\"button\"\n ?disabled=${isDisabled}\n aria-busy=${this.busy ? \"true\" : \"false\"}\n @click=${this._onClick}\n >\n <span class=\"spin\" aria-hidden=\"true\" ?hidden=${!this.busy}>${iconArrowPath(14)}</span>\n <slot name=\"icon\" ?hidden=${this.busy}></slot>\n <slot></slot>\n </button>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"ui-button\": UiButton;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ui-button.js","sourceRoot":"","sources":["../src/ui-button.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAIrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEI,IAAM,QAAQ,GAAd,MAAM,QAAS,SAAQ,UAAU;IAAjC;;QAGL,eAAU,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;QAkIpC,qBAAqB;QACT,YAAO,GAAkB,SAAS,CAAC;QAC/C,+EAA+E;QACnE,SAAI,GAAgB,IAAI,CAAC;QACrC,2FAA2F;QAC9D,SAAI,GAAG,KAAK,CAAC;QAC1C,oEAAoE;QACxD,SAAI,GAAkB,IAAI,CAAC;QACvC,wDAAwD;QAC5C,SAAI,GAAkC,QAAQ,CAAC;QAC3D,wCAAwC;QACX,aAAQ,GAAG,KAAK,CAAC;QAC9C,0EAA0E;QAC7C,SAAI,GAAG,KAAK,CAAC;IA8C5C,CAAC;aA/LQ,mBAAc,GAAG,IAAI,AAAP,CAAQ;IAE7B,UAAU,CAA0B;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;;;OAGxC,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,CAAA;;gBAEC,OAAO;;oBAEH,UAAU;oBACV,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO;iBAC/B,IAAI,CAAC,QAAQ;;wDAE0B,CAAC,IAAI,CAAC,IAAI,IAAI,aAAa,CAAC,EAAE,CAAC;oCACnD,IAAI,CAAC,IAAI;;;KAGxC,CAAC;IACJ,CAAC;CACF,CAAA;AA1Da;IAAX,QAAQ,EAAE;yCAAoC;AAEnC;IAAX,QAAQ,EAAE;sCAA0B;AAER;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;sCAAc;AAE9B;IAAX,QAAQ,EAAE;sCAA4B;AAE3B;IAAX,QAAQ,EAAE;sCAAgD;AAE9B;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;0CAAkB;AAEjB;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;sCAAc;AAlJ/B,QAAQ;IADpB,aAAa,CAAC,WAAW,CAAC;GACd,QAAQ,CAgMpB","sourcesContent":["import { LitElement, css, html } from \"lit\";\nimport { customElement, property } from \"lit/decorators.js\";\nimport { iconArrowPath } from \"./icons.js\";\nimport { tokens } from \"./tokens.js\";\n\nexport type ButtonVariant = \"primary\" | \"secondary\" | \"danger\";\n\n/**\n * Button (or link styled as one) with an optional leading icon, in three\n * visual weights. Set `href` to render an `<a>` instead of a `<button>` —\n * same styling either way — for cross-page navigation that should look like\n * an action button; a disabled/busy link stays a real `<a>` with\n * `aria-disabled` + `pointer-events: none` rather than losing its href.\n * Put the icon in the `icon` slot and the label in the default slot.\n *\n * Form-associated (`type=\"submit\"`/`\"reset\"`): the actual `<button>` lives in\n * this element's shadow root, which native HTML form association does not\n * cross into from an ancestor light-DOM `<form>`. `type=\"submit\"`/`\"reset\"`\n * is instead wired through `ElementInternals.form` — the same mechanism\n * `address-autocomplete` uses to associate with an ancestor form.\n *\n * `primary`/`danger` backgrounds read `--ui-button-background`/\n * `--ui-button-danger-background` (and their `-hover`/`-active`\n * counterparts), which default to the flat `--ui-primary`/`--ui-danger`\n * tokens unchanged — so `--ui-primary`/`--ui-danger` stay the single source\n * of truth for every other component. A consumer can override just these\n * button-specific tokens with a `linear-gradient(...)` to opt every\n * `ui-button` into a gradient look without touching component markup —\n * `gradientTokenValues` in `tokens.ts` ships exactly this, wired up via\n * `data-theme=\"gradient\"` (see `tokens.css`'s \"Gradient theme\" section) —\n * pairing it with `--ui-button-border`/`--ui-button-danger-border` (default\n * `transparent`) for a defining edge a shade darker than the gradient's dark\n * stop, and setting the `-active` variant's stops in reverse for a\n * pressed/\"indented\" look while the button is held down. `secondary`'s\n * background/border read the equivalent `--ui-button-secondary-*` tokens\n * (shared with `confirm-dialog`'s Cancel button), defaulting to today's\n * transparent/bordered look, so it can be themed into a matching (e.g.\n * white-to-gray) gradient too.\n *\n * @element ui-button\n * @slot icon - Optional leading icon (e.g. an inline SVG).\n * @slot - Button label.\n */\n@customElement(\"ui-button\")\nexport class UiButton extends LitElement {\n static formAssociated = true;\n\n #internals = this.attachInternals();\n static override styles = [\n tokens,\n css`\n :host {\n display: inline-flex;\n }\n .btn {\n display: inline-flex;\n align-items: center;\n gap: 0.25rem;\n height: 2rem;\n border-radius: var(--ui-radius-sm, 0.25rem);\n padding: 0.5rem 1rem;\n font-size: var(--ui-font-size-sm, 0.75rem);\n font-weight: var(--ui-font-weight-medium, 500);\n line-height: var(--ui-line-height-tight, 1.25);\n font-family: var(\n --ui-font,\n ui-sans-serif,\n system-ui,\n sans-serif,\n \"Apple Color Emoji\",\n \"Segoe UI Emoji\",\n \"Segoe UI Symbol\",\n \"Noto Color Emoji\"\n );\n cursor: pointer;\n border: 1px solid transparent;\n text-decoration: none;\n box-sizing: border-box;\n }\n .btn.primary {\n background: var(--ui-button-background, var(--ui-primary, #4f46e5));\n border-color: var(--ui-button-border, transparent);\n color: var(--ui-on-accent, #ffffff);\n box-shadow: var(--ui-button-highlight, 0 0 0 0 transparent);\n text-shadow: var(--ui-button-text-shadow, none);\n }\n .btn.primary:hover:not(:disabled) {\n background: var(--ui-button-background-hover, var(--ui-primary-hover, #4338ca));\n }\n .btn.primary:active:not(:disabled) {\n background: var(--ui-button-background-active, var(--ui-button-background, var(--ui-primary, #4f46e5)));\n box-shadow: none;\n }\n .btn.secondary {\n background: var(--ui-button-secondary-background, none);\n border-color: var(--ui-button-secondary-border, var(--ui-border, #e2e8f0));\n color: var(--ui-text, #0f172a);\n box-shadow: var(--ui-button-highlight, 0 0 0 0 transparent);\n }\n .btn.secondary:hover:not(:disabled) {\n background: var(--ui-button-secondary-background-hover, none);\n border-color: var(--ui-button-secondary-border-hover, var(--ui-text-muted, #64748b));\n }\n .btn.secondary:active:not(:disabled) {\n background: var(--ui-button-secondary-background-active, var(--ui-button-secondary-background, none));\n box-shadow: none;\n }\n .btn.danger {\n background: var(--ui-button-danger-background, var(--ui-danger, #dc2626));\n border-color: var(--ui-button-danger-border, transparent);\n color: var(--ui-on-accent, #ffffff);\n box-shadow: var(--ui-button-highlight, 0 0 0 0 transparent);\n text-shadow: var(--ui-button-text-shadow, none);\n }\n .btn.danger:hover:not(:disabled) {\n background: var(--ui-button-danger-background-hover, var(--ui-danger-hover, #b91c1c));\n }\n .btn.danger:active:not(:disabled) {\n background: var(--ui-button-danger-background-active, var(--ui-button-danger-background, var(--ui-danger, #dc2626)));\n box-shadow: none;\n }\n .btn:disabled,\n .btn[aria-disabled=\"true\"] {\n opacity: 0.6;\n cursor: default;\n pointer-events: none;\n }\n .btn:focus-visible {\n outline: none;\n box-shadow: var(--ui-focus-ring, 0 0 0 3px rgb(79 70 229 / 0.35));\n }\n .btn.primary:focus-visible:not(:active),\n .btn.danger:focus-visible:not(:active),\n .btn.secondary:focus-visible:not(:active) {\n box-shadow: var(--ui-focus-ring, 0 0 0 3px rgb(79 70 229 / 0.35)), var(--ui-button-highlight, 0 0 0 0 transparent);\n }\n .btn.sm {\n height: 1.5rem;\n padding: 0.25rem 0.5rem;\n font-size: var(--ui-font-size-xs, 0.6875rem);\n }\n .btn.pill {\n border-radius: 999px;\n }\n .spin {\n display: inline-flex;\n animation: spin 0.8s linear infinite;\n }\n .spin[hidden] {\n display: none;\n }\n @keyframes spin {\n to {\n transform: rotate(360deg);\n }\n }\n @media (prefers-reduced-motion: reduce) {\n .spin {\n animation: none;\n }\n }\n @media (forced-colors: active) {\n .btn:focus-visible {\n outline: 2px solid CanvasText;\n outline-offset: 2px;\n box-shadow: none;\n }\n .btn:disabled,\n .btn[aria-disabled=\"true\"] {\n color: GrayText;\n border-color: GrayText;\n opacity: 1;\n }\n }\n `,\n ];\n\n /** Visual weight. */\n @property() variant: ButtonVariant = \"primary\";\n /** Size — `sm` reduces height/padding/font-size one step below the default. */\n @property() size: \"sm\" | \"md\" = \"md\";\n /** Renders fully rounded (pill-shaped) corners instead of the default `--ui-radius-sm`. */\n @property({ type: Boolean }) pill = false;\n /** Renders an `<a href=\"...\">` instead of a `<button>` when set. */\n @property() href: string | null = null;\n /** Native button `type`. Ignored when `href` is set. */\n @property() type: \"button\" | \"submit\" | \"reset\" = \"button\";\n /** Disables the control and dims it. */\n @property({ type: Boolean }) disabled = false;\n /** Shows a spinner in place of the icon slot and disables the control. */\n @property({ type: Boolean }) busy = false;\n\n /** Drives submit/reset on the ancestor form via ElementInternals, since a shadow-DOM button can't do it natively. */\n private _onClick() {\n if (this.type === \"submit\") this.#internals.form?.requestSubmit();\n else if (this.type === \"reset\") this.#internals.form?.reset();\n }\n\n /** Suppresses navigation while a link-styled button is disabled or busy. */\n private _onLinkClick(e: MouseEvent) {\n if (!this.disabled && !this.busy) return;\n e.preventDefault();\n }\n\n override render() {\n const classes = `btn ${this.variant} ${this.size}${this.pill ? \" pill\" : \"\"}`;\n const isDisabled = this.disabled || this.busy;\n if (this.href) {\n return html`\n <a\n class=${classes}\n href=${this.href}\n aria-disabled=${isDisabled ? \"true\" : \"false\"}\n aria-busy=${this.busy ? \"true\" : \"false\"}\n @click=${this._onLinkClick}\n >\n <span class=\"spin\" aria-hidden=\"true\" ?hidden=${!this.busy}>${iconArrowPath(14)}</span>\n <slot name=\"icon\" ?hidden=${this.busy}></slot>\n <slot></slot>\n </a>\n `;\n }\n return html`\n <button\n class=${classes}\n type=\"button\"\n ?disabled=${isDisabled}\n aria-busy=${this.busy ? \"true\" : \"false\"}\n @click=${this._onClick}\n >\n <span class=\"spin\" aria-hidden=\"true\" ?hidden=${!this.busy}>${iconArrowPath(14)}</span>\n <slot name=\"icon\" ?hidden=${this.busy}></slot>\n <slot></slot>\n </button>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"ui-button\": UiButton;\n }\n}\n"]}
|
package/dist/utils/calendar.d.ts
CHANGED
|
@@ -74,4 +74,45 @@ export declare function assignLanes(entries: ResolvedCalendarEntry[]): {
|
|
|
74
74
|
entries: LanedEntry[];
|
|
75
75
|
laneCount: number;
|
|
76
76
|
};
|
|
77
|
+
/** Adds `days` (negative to subtract) to `date`, returning a new local `Date`. */
|
|
78
|
+
export declare function addDays(date: Date, days: number): Date;
|
|
79
|
+
/** The Sunday (local midnight) of the week containing `date`, per `WEEKDAY_ABBR`'s Sunday-first convention. */
|
|
80
|
+
export declare function startOfWeek(date: Date): Date;
|
|
81
|
+
/** Minutes elapsed since local midnight on `date`'s day, for hour-grid vertical positioning. */
|
|
82
|
+
export declare function minutesSinceMidnight(date: Date): number;
|
|
83
|
+
/** Whether `iso` carries a time-of-day component (`"YYYY-MM-DDTHH:MM"`) rather than being date-only. */
|
|
84
|
+
export declare function hasTimeComponent(iso: string): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Parses `"YYYY-MM-DDTHH:MM"` as a local `Date`, falling back to
|
|
87
|
+
* `parseIsoDate` (local midnight) for a plain `"YYYY-MM-DD"` string. Returns
|
|
88
|
+
* `null` for anything else, including a datetime whose components don't
|
|
89
|
+
* round-trip (e.g. an invalid hour).
|
|
90
|
+
*/
|
|
91
|
+
export declare function parseIsoDateTime(iso: string): Date | null;
|
|
92
|
+
/**
|
|
93
|
+
* A `CalendarEntryData` resolved for hour-grid (`calendar-day`/`calendar-week`)
|
|
94
|
+
* rendering. Reuses the `startDate`/`endDate` field names from
|
|
95
|
+
* `ResolvedCalendarEntry` so it stays structurally compatible with
|
|
96
|
+
* `assignLanes`/`overlapsRange` — both operate purely on those two `Date`
|
|
97
|
+
* fields via `.getTime()`, which already generalizes correctly to sub-day
|
|
98
|
+
* time granularity and multi-day ranges with no changes needed.
|
|
99
|
+
*/
|
|
100
|
+
export interface ResolvedTimedEntry extends CalendarEntryData {
|
|
101
|
+
startDate: Date;
|
|
102
|
+
endDate: Date;
|
|
103
|
+
/** True when neither `start` nor `end` carries a time-of-day component. */
|
|
104
|
+
allDay: boolean;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Resolves a `CalendarEntryData`'s date/datetime strings for hour-grid
|
|
108
|
+
* rendering. Returns `null` when `start` is missing or unparseable. A blank
|
|
109
|
+
* `end` defaults to `start`; when `start` has a time but `end` doesn't (or is
|
|
110
|
+
* blank), `end` defaults to one hour after `start` rather than clamping to
|
|
111
|
+
* `start`'s instant, so a timed entry with no explicit end still renders as
|
|
112
|
+
* a visible block. `allDay` is true only when neither endpoint carries a
|
|
113
|
+
* time-of-day component — this is a separate, additive resolution path from
|
|
114
|
+
* `resolveEntry`/`ResolvedCalendarEntry`, which stay date-only and are used
|
|
115
|
+
* unchanged by `calendar-month`/`calendar-year`.
|
|
116
|
+
*/
|
|
117
|
+
export declare function resolveTimedEntry(data: CalendarEntryData): ResolvedTimedEntry | null;
|
|
77
118
|
//# sourceMappingURL=calendar.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calendar.d.ts","sourceRoot":"","sources":["../../src/utils/calendar.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAA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gGAAgG;AAChG,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAEvD;AAED,wGAAwG;AACxG,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAErD;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAoBzD;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,kBAAmB,SAAQ,iBAAiB;IAC3D,SAAS,EAAE,IAAI,CAAC;IAChB,OAAO,EAAE,IAAI,CAAC;IACd,2EAA2E;IAC3E,MAAM,EAAE,OAAO,CAAC;CACjB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,iBAAiB,GAAG,kBAAkB,GAAG,IAAI,CAoBpF"}
|
package/dist/utils/calendar.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const ISO_DATE_PATTERN = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
2
|
+
const ISO_DATETIME_PATTERN = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})$/;
|
|
2
3
|
/** Attributes whose mutations can change a rendered calendar entry. */
|
|
3
4
|
export const CALENDAR_ENTRY_ATTRIBUTES = ["start", "end", "label", "color", "href", "slot"];
|
|
4
5
|
/** Number of days in `month` (1-12) of `year`, leap years included. */
|
|
@@ -132,4 +133,77 @@ export function assignLanes(entries) {
|
|
|
132
133
|
}
|
|
133
134
|
return { entries: laned, laneCount: laneEnds.length };
|
|
134
135
|
}
|
|
136
|
+
/** Adds `days` (negative to subtract) to `date`, returning a new local `Date`. */
|
|
137
|
+
export function addDays(date, days) {
|
|
138
|
+
const result = new Date(date);
|
|
139
|
+
result.setDate(result.getDate() + days);
|
|
140
|
+
return result;
|
|
141
|
+
}
|
|
142
|
+
/** The Sunday (local midnight) of the week containing `date`, per `WEEKDAY_ABBR`'s Sunday-first convention. */
|
|
143
|
+
export function startOfWeek(date) {
|
|
144
|
+
return addDays(date, -date.getDay());
|
|
145
|
+
}
|
|
146
|
+
/** Minutes elapsed since local midnight on `date`'s day, for hour-grid vertical positioning. */
|
|
147
|
+
export function minutesSinceMidnight(date) {
|
|
148
|
+
return date.getHours() * 60 + date.getMinutes();
|
|
149
|
+
}
|
|
150
|
+
/** Whether `iso` carries a time-of-day component (`"YYYY-MM-DDTHH:MM"`) rather than being date-only. */
|
|
151
|
+
export function hasTimeComponent(iso) {
|
|
152
|
+
return ISO_DATETIME_PATTERN.test(iso);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Parses `"YYYY-MM-DDTHH:MM"` as a local `Date`, falling back to
|
|
156
|
+
* `parseIsoDate` (local midnight) for a plain `"YYYY-MM-DD"` string. Returns
|
|
157
|
+
* `null` for anything else, including a datetime whose components don't
|
|
158
|
+
* round-trip (e.g. an invalid hour).
|
|
159
|
+
*/
|
|
160
|
+
export function parseIsoDateTime(iso) {
|
|
161
|
+
const match = ISO_DATETIME_PATTERN.exec(iso);
|
|
162
|
+
if (!match)
|
|
163
|
+
return parseIsoDate(iso);
|
|
164
|
+
const year = Number(match[1]);
|
|
165
|
+
const month = Number(match[2]);
|
|
166
|
+
const day = Number(match[3]);
|
|
167
|
+
const hours = Number(match[4]);
|
|
168
|
+
const minutes = Number(match[5]);
|
|
169
|
+
const date = new Date(year, month - 1, day, hours, minutes);
|
|
170
|
+
if (date.getFullYear() !== year ||
|
|
171
|
+
date.getMonth() !== month - 1 ||
|
|
172
|
+
date.getDate() !== day ||
|
|
173
|
+
date.getHours() !== hours ||
|
|
174
|
+
date.getMinutes() !== minutes) {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
return date;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Resolves a `CalendarEntryData`'s date/datetime strings for hour-grid
|
|
181
|
+
* rendering. Returns `null` when `start` is missing or unparseable. A blank
|
|
182
|
+
* `end` defaults to `start`; when `start` has a time but `end` doesn't (or is
|
|
183
|
+
* blank), `end` defaults to one hour after `start` rather than clamping to
|
|
184
|
+
* `start`'s instant, so a timed entry with no explicit end still renders as
|
|
185
|
+
* a visible block. `allDay` is true only when neither endpoint carries a
|
|
186
|
+
* time-of-day component — this is a separate, additive resolution path from
|
|
187
|
+
* `resolveEntry`/`ResolvedCalendarEntry`, which stay date-only and are used
|
|
188
|
+
* unchanged by `calendar-month`/`calendar-year`.
|
|
189
|
+
*/
|
|
190
|
+
export function resolveTimedEntry(data) {
|
|
191
|
+
const startDate = parseIsoDateTime(data.start);
|
|
192
|
+
if (!startDate)
|
|
193
|
+
return null;
|
|
194
|
+
const startHasTime = hasTimeComponent(data.start);
|
|
195
|
+
const endHasTime = hasTimeComponent(data.end);
|
|
196
|
+
const allDay = !startHasTime && !endHasTime;
|
|
197
|
+
let endDate = data.end ? parseIsoDateTime(data.end) : null;
|
|
198
|
+
if (!endDate) {
|
|
199
|
+
endDate = startHasTime ? new Date(startDate.getTime() + 60 * 60 * 1000) : startDate;
|
|
200
|
+
}
|
|
201
|
+
return {
|
|
202
|
+
...data,
|
|
203
|
+
details: data.details ?? [],
|
|
204
|
+
startDate,
|
|
205
|
+
endDate: endDate < startDate ? startDate : endDate,
|
|
206
|
+
allDay,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
135
209
|
//# sourceMappingURL=calendar.js.map
|