@firstprateek/vastu 0.0.0-stage → 1.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 +15 -0
- package/README.md +52 -2
- package/custom-elements.json +3737 -0
- package/dist/dev/all.d.ts +12 -0
- package/dist/dev/all.d.ts.map +1 -0
- package/dist/dev/all.js +13 -0
- package/dist/dev/all.js.map +1 -0
- package/dist/dev/bar-chart/bar-chart.d.ts +63 -0
- package/dist/dev/bar-chart/bar-chart.d.ts.map +1 -0
- package/dist/dev/bar-chart/bar-chart.js +316 -0
- package/dist/dev/bar-chart/bar-chart.js.map +1 -0
- package/dist/dev/bar-chart/index.d.ts +3 -0
- package/dist/dev/bar-chart/index.d.ts.map +1 -0
- package/dist/dev/bar-chart/index.js +5 -0
- package/dist/dev/bar-chart/index.js.map +1 -0
- package/dist/dev/button/button.d.ts +98 -0
- package/dist/dev/button/button.d.ts.map +1 -0
- package/dist/dev/button/button.js +292 -0
- package/dist/dev/button/button.js.map +1 -0
- package/dist/dev/button/index.d.ts +4 -0
- package/dist/dev/button/index.d.ts.map +1 -0
- package/dist/dev/button/index.js +5 -0
- package/dist/dev/button/index.js.map +1 -0
- package/dist/dev/checkbox/checkbox.d.ts +71 -0
- package/dist/dev/checkbox/checkbox.d.ts.map +1 -0
- package/dist/dev/checkbox/checkbox.js +232 -0
- package/dist/dev/checkbox/checkbox.js.map +1 -0
- package/dist/dev/checkbox/index.d.ts +3 -0
- package/dist/dev/checkbox/index.d.ts.map +1 -0
- package/dist/dev/checkbox/index.js +5 -0
- package/dist/dev/checkbox/index.js.map +1 -0
- package/dist/dev/core/cssom.d.ts +15 -0
- package/dist/dev/core/cssom.d.ts.map +1 -0
- package/dist/dev/core/cssom.js +30 -0
- package/dist/dev/core/cssom.js.map +1 -0
- package/dist/dev/core/define.d.ts +3 -0
- package/dist/dev/core/define.d.ts.map +1 -0
- package/dist/dev/core/define.js +6 -0
- package/dist/dev/core/define.js.map +1 -0
- package/dist/dev/core/dev-mode.d.ts +6 -0
- package/dist/dev/core/dev-mode.d.ts.map +1 -0
- package/dist/dev/core/dev-mode.js +6 -0
- package/dist/dev/core/dev-mode.js.map +1 -0
- package/dist/dev/core/focus-ring.d.ts +3 -0
- package/dist/dev/core/focus-ring.d.ts.map +1 -0
- package/dist/dev/core/focus-ring.js +14 -0
- package/dist/dev/core/focus-ring.js.map +1 -0
- package/dist/dev/core/form-control.d.ts +47 -0
- package/dist/dev/core/form-control.d.ts.map +1 -0
- package/dist/dev/core/form-control.js +75 -0
- package/dist/dev/core/form-control.js.map +1 -0
- package/dist/dev/core/warn.d.ts +12 -0
- package/dist/dev/core/warn.d.ts.map +1 -0
- package/dist/dev/core/warn.js +35 -0
- package/dist/dev/core/warn.js.map +1 -0
- package/dist/dev/dialog/dialog.d.ts +77 -0
- package/dist/dev/dialog/dialog.d.ts.map +1 -0
- package/dist/dev/dialog/dialog.js +253 -0
- package/dist/dev/dialog/dialog.js.map +1 -0
- package/dist/dev/dialog/index.d.ts +4 -0
- package/dist/dev/dialog/index.d.ts.map +1 -0
- package/dist/dev/dialog/index.js +5 -0
- package/dist/dev/dialog/index.js.map +1 -0
- package/dist/dev/menu/index.d.ts +3 -0
- package/dist/dev/menu/index.d.ts.map +1 -0
- package/dist/dev/menu/index.js +5 -0
- package/dist/dev/menu/index.js.map +1 -0
- package/dist/dev/menu/menu.d.ts +71 -0
- package/dist/dev/menu/menu.d.ts.map +1 -0
- package/dist/dev/menu/menu.js +330 -0
- package/dist/dev/menu/menu.js.map +1 -0
- package/dist/dev/navbar/index.d.ts +3 -0
- package/dist/dev/navbar/index.d.ts.map +1 -0
- package/dist/dev/navbar/index.js +5 -0
- package/dist/dev/navbar/index.js.map +1 -0
- package/dist/dev/navbar/navbar.d.ts +69 -0
- package/dist/dev/navbar/navbar.d.ts.map +1 -0
- package/dist/dev/navbar/navbar.js +353 -0
- package/dist/dev/navbar/navbar.js.map +1 -0
- package/dist/dev/poll/index.d.ts +3 -0
- package/dist/dev/poll/index.d.ts.map +1 -0
- package/dist/dev/poll/index.js +5 -0
- package/dist/dev/poll/index.js.map +1 -0
- package/dist/dev/poll/poll.d.ts +67 -0
- package/dist/dev/poll/poll.d.ts.map +1 -0
- package/dist/dev/poll/poll.js +301 -0
- package/dist/dev/poll/poll.js.map +1 -0
- package/dist/dev/switch/index.d.ts +3 -0
- package/dist/dev/switch/index.d.ts.map +1 -0
- package/dist/dev/switch/index.js +5 -0
- package/dist/dev/switch/index.js.map +1 -0
- package/dist/dev/switch/switch.d.ts +69 -0
- package/dist/dev/switch/switch.d.ts.map +1 -0
- package/dist/dev/switch/switch.js +213 -0
- package/dist/dev/switch/switch.js.map +1 -0
- package/dist/dev/tabs/index.d.ts +3 -0
- package/dist/dev/tabs/index.d.ts.map +1 -0
- package/dist/dev/tabs/index.js +5 -0
- package/dist/dev/tabs/index.js.map +1 -0
- package/dist/dev/tabs/tabs.d.ts +64 -0
- package/dist/dev/tabs/tabs.d.ts.map +1 -0
- package/dist/dev/tabs/tabs.js +212 -0
- package/dist/dev/tabs/tabs.js.map +1 -0
- package/dist/dev/text-field/index.d.ts +3 -0
- package/dist/dev/text-field/index.d.ts.map +1 -0
- package/dist/dev/text-field/index.js +5 -0
- package/dist/dev/text-field/index.js.map +1 -0
- package/dist/dev/text-field/text-field.d.ts +91 -0
- package/dist/dev/text-field/text-field.d.ts.map +1 -0
- package/dist/dev/text-field/text-field.js +267 -0
- package/dist/dev/text-field/text-field.js.map +1 -0
- package/dist/dev/toast/index.d.ts +4 -0
- package/dist/dev/toast/index.d.ts.map +1 -0
- package/dist/dev/toast/index.js +5 -0
- package/dist/dev/toast/index.js.map +1 -0
- package/dist/dev/toast/toast.d.ts +71 -0
- package/dist/dev/toast/toast.d.ts.map +1 -0
- package/dist/dev/toast/toast.js +258 -0
- package/dist/dev/toast/toast.js.map +1 -0
- package/dist/prod/all.js +13 -0
- package/dist/prod/bar-chart/bar-chart.js +316 -0
- package/dist/prod/bar-chart/index.js +5 -0
- package/dist/prod/button/button.js +292 -0
- package/dist/prod/button/index.js +5 -0
- package/dist/prod/checkbox/checkbox.js +232 -0
- package/dist/prod/checkbox/index.js +5 -0
- package/dist/prod/core/cssom.js +30 -0
- package/dist/prod/core/define.js +6 -0
- package/dist/prod/core/dev-mode.js +1 -0
- package/dist/prod/core/focus-ring.js +14 -0
- package/dist/prod/core/form-control.js +75 -0
- package/dist/prod/core/warn.js +2 -0
- package/dist/prod/dialog/dialog.js +253 -0
- package/dist/prod/dialog/index.js +5 -0
- package/dist/prod/menu/index.js +5 -0
- package/dist/prod/menu/menu.js +330 -0
- package/dist/prod/navbar/index.js +5 -0
- package/dist/prod/navbar/navbar.js +353 -0
- package/dist/prod/poll/index.js +5 -0
- package/dist/prod/poll/poll.js +301 -0
- package/dist/prod/switch/index.js +5 -0
- package/dist/prod/switch/switch.js +213 -0
- package/dist/prod/tabs/index.js +5 -0
- package/dist/prod/tabs/tabs.js +212 -0
- package/dist/prod/text-field/index.js +5 -0
- package/dist/prod/text-field/text-field.js +267 -0
- package/dist/prod/toast/index.js +5 -0
- package/dist/prod/toast/toast.js +258 -0
- package/package.json +110 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toast.js","sourceRoot":"","sources":["../../../src/toast/toast.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAA6B,MAAM,KAAK,CAAC;AAChF,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAM7D,MAAM,QAAQ,GAA4B,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;AAYvE,IAAI,MAAM,GAAG,CAAC,CAAC;AAEf;;;;;;;;;;;;;;;;;;;;;;;;;;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,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,cAAc,CAAC;;;;aAI/H,CACF;;;KAGN,CAAC;IACJ,CAAC;aAEe,WAAM,GAAG;QACvB,SAAS;QACT,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAqEF;KACF,CAAC","sourcesContent":["import { LitElement, css, html, nothing, type PropertyDeclarations } from 'lit';\nimport { repeat } from 'lit/directives/repeat.js';\nimport { focusRing } from '../core/focus-ring.js';\nimport { checkTokensLoaded, devWarn } from '../core/warn.js';\n\n/** How a toast looks and how urgently it is announced. */\nexport type ToastVariant = 'info' | 'success' | 'error';\n/** Why a message closed, in the `va-dismiss` event's `detail.reason`. */\nexport type ToastDismissReason = 'timeout' | 'close-button' | 'escape' | 'method';\nconst VARIANTS: readonly ToastVariant[] = ['info', 'success', 'error'];\n\ninterface Toast {\n id: number;\n message: string;\n variant: ToastVariant;\n duration: number;\n remaining: number;\n started: number;\n timer?: ReturnType<typeof setTimeout>;\n}\n\nlet nextId = 1;\n\n/**\n * A region for short, non-blocking status messages (\"toasts\"). Place one per page and call `show()`,\n * or point a `va-button` at it with `command=\"--show\"`; the button's `value` is the message.\n *\n * @tag va-toast\n * @summary Shows short status messages, such as \"Changes saved\", without interrupting the user.\n *\n * @csspart region - The fixed area the toasts appear in.\n * @csspart toast - Each message.\n * @csspart close-button - Each message's close button.\n *\n * @cssprop {<color>} --va-toast-bg - Background colour of a message.\n * @cssprop {<color>} --va-toast-fg - Text colour of a message.\n * @cssprop {<length>} --va-toast-radius - Corner radius of a message.\n *\n * @cssprop-applies --va-toast-bg toast:open background-color\n * @cssprop-applies --va-toast-fg toast:open color\n * @cssprop-applies --va-toast-radius toast:open border-top-left-radius\n *\n * @keyboard-items [part~=\"close-button\"]\n * @keyboard open: Escape | closes | Dismisses the message that has focus.\n *\n * @a11y-role status\n * @a11y-name The `accessible-label` attribute, \"Notifications\" by default (not shown).\n * @a11y-note Info and success messages are announced politely; errors use `role=\"alert\"` and are announced at once.\n * @a11y-note Messages pause their timer while hovered or focused, and errors stay until dismissed (WCAG 2.2.1).\n * @a11y-note While a modal dialog is open, the element moves itself into that dialog (a light-DOM move, so its messages stay clickable and announced) and back to its place when the dialog closes. Don't render it from a framework that would fight the move; place it once, outside framework-managed DOM.\n *\n * @guidance-use To confirm that something happened, such as \"Changes saved\" or \"Link copied\", or to report a background failure.\n * @guidance-avoid For anything the user must act on or read in full, or for form validation errors.\n * @guidance-instead `va-dialog` for decisions; `va-text-field`'s `error` for field errors.\n *\n * @command --show | Shows the sending button's `value` as a message. Its `data-toast-variant` sets the look: `info` (default), `success` or `error`.\n * @command-data --show | toast-variant | info success error\n * @fires {CustomEvent<{ id: number, reason: 'timeout' | 'close-button' | 'escape' | 'method' }>} va-dismiss - After a message has closed. `event.detail.id` is the id `show()` returned.\n * @event-trigger va-dismiss | press Escape | open\n */\nexport class VaToast extends LitElement {\n static override properties: PropertyDeclarations = {\n duration: { type: Number },\n accessibleLabel: { attribute: 'accessible-label' },\n _toasts: { state: true },\n };\n\n /** Milliseconds before an info or success message closes by itself. Errors stay until dismissed. */\n declare duration: number;\n /** Accessible name of the region. Not shown. */\n declare accessibleLabel: string;\n\n declare private _toasts: Toast[];\n\n constructor() {\n super();\n this.duration = 5000;\n this.accessibleLabel = 'Notifications';\n this._toasts = [];\n this.addEventListener('command', this.#onCommand as EventListener);\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n checkTokensLoaded(this);\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n for (const t of this._toasts) clearTimeout(t.timer);\n }\n\n /** True while at least one message is showing. */\n get hasMessages(): boolean {\n return this._toasts.length > 0;\n }\n\n #home: { parent: Node; next: Node | null } | null = null;\n #dialogWatch: MutationObserver | null = null;\n\n /**\n * A modal dialog makes the rest of the page inert, so a toast outside it could be seen but not\n * clicked or read by screen readers. While a modal is open, move into it; move back when it closes.\n */\n #followModal(): void {\n const modal = document.querySelector<HTMLElement>('va-dialog[open], dialog:modal');\n if (!modal || modal.contains(this)) return;\n if (!this.#home) this.#home = { parent: this.parentNode!, next: this.nextSibling };\n modal.append(this);\n this.#dialogWatch?.disconnect();\n this.#dialogWatch = new MutationObserver(() => {\n if (modal.hasAttribute('open')) return;\n this.#dialogWatch?.disconnect();\n this.#dialogWatch = null;\n const home = this.#home;\n this.#home = null;\n if (home?.parent.isConnected) home.parent.insertBefore(this, home.next?.parentNode === home.parent ? home.next : null);\n });\n this.#dialogWatch.observe(modal, { attributes: true, attributeFilter: ['open'] });\n }\n\n /** Shows a message and returns its id. `variant` defaults to `info`; errors stay until dismissed. */\n show(message: string, options: { variant?: 'info' | 'success' | 'error'; duration?: number } = {}): number {\n this.#followModal();\n const variant = options.variant ?? 'info';\n const duration = variant === 'error' ? 0 : (options.duration ?? this.duration);\n const toast: Toast = { id: nextId++, message, variant, duration, remaining: duration, started: 0 };\n this._toasts = [...this._toasts, toast];\n this.#start(toast);\n return toast.id;\n }\n\n /** Closes one message by id, or every message when no id is given. */\n dismiss(id?: number): void {\n for (const t of [...this._toasts]) if (id === undefined || t.id === id) this.#close(t, 'method');\n }\n\n #onCommand = (event: Event & { command?: string; source?: Element | null }): void => {\n if (event.command !== '--show') return;\n const source = event.source as (Element & { value?: string }) | null;\n const message = source?.value || source?.textContent?.trim() || '';\n const asked = source?.getAttribute('data-toast-variant');\n let variant: ToastVariant | undefined;\n if (asked && VARIANTS.includes(asked as ToastVariant)) variant = asked as ToastVariant;\n else if (asked) {\n devWarn('va-toast', `data-toast-variant=\"${asked}\" is not a toast variant, so the message shows as info.`, `Use one of: ${VARIANTS.join(', ')}${asked === 'danger' ? ' (error is the toast for failures)' : ''}.`);\n }\n if (message) this.show(message, { variant });\n };\n\n #start(toast: Toast): void {\n if (!toast.remaining) return;\n toast.started = Date.now();\n toast.timer = setTimeout(() => this.#close(toast, 'timeout'), toast.remaining);\n }\n\n #pause(toast: Toast): void {\n if (!toast.timer) return;\n clearTimeout(toast.timer);\n toast.timer = undefined;\n toast.remaining = Math.max(1000, toast.remaining - (Date.now() - toast.started));\n }\n\n #resume(toast: Toast, item: HTMLElement): void {\n // Stay paused while the pointer or focus is still on the message.\n if (item.matches(':hover') || item.matches(':focus-within')) return;\n if (!toast.timer) this.#start(toast);\n }\n\n #close(toast: Toast, reason: ToastDismissReason): void {\n if (!this._toasts.includes(toast)) return;\n clearTimeout(toast.timer);\n const hadFocus = !!this.shadowRoot?.activeElement;\n this._toasts = this._toasts.filter((t) => t !== toast);\n this.dispatchEvent(new CustomEvent('va-dismiss', { detail: { id: toast.id, reason }, bubbles: true, composed: true }));\n if (hadFocus) {\n // Don't strand focus: move it to the next message, or let it go back to the page.\n this.updateComplete.then(() => this.shadowRoot?.querySelector<HTMLElement>('.dismiss')?.focus());\n }\n }\n\n override render() {\n return html`\n <section part=\"region\" class=\"region\" aria-label=${this.accessibleLabel}>\n <ol class=\"list\" role=\"status\" aria-live=\"polite\">\n ${repeat(\n this._toasts,\n (t) => t.id,\n (t) => html`\n <li\n part=\"toast\"\n class=\"toast ${t.variant}\"\n role=${t.variant === 'error' ? 'alert' : nothing}\n @mouseenter=${() => this.#pause(t)}\n @mouseleave=${(e: Event) => this.#resume(t, e.currentTarget as HTMLElement)}\n @focusin=${() => this.#pause(t)}\n @focusout=${(e: Event) => this.#resume(t, e.currentTarget as HTMLElement)}\n @keydown=${(e: KeyboardEvent) => e.key === 'Escape' && this.#close(t, 'escape')}\n >\n <span class=\"message\">${t.message}</span>\n <button part=\"close-button\" class=\"dismiss\" type=\"button\" aria-label=\"Dismiss\" @click=${() => this.#close(t, 'close-button')}>\n <svg viewBox=\"0 0 24 24\" aria-hidden=\"true\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"><path d=\"M6 6l12 12M18 6L6 18\" /></svg>\n </button>\n </li>\n `\n )}\n </ol>\n </section>\n `;\n }\n\n static override styles = [\n focusRing,\n css`\n :host {\n position: fixed;\n inset: auto 16px 16px auto;\n z-index: 1000;\n font-family: var(--va-font-family-ui);\n }\n .list {\n display: flex;\n flex-direction: column;\n gap: var(--va-space-gap-md);\n margin: 0;\n padding: 0;\n list-style: none;\n }\n .toast {\n display: flex;\n align-items: center;\n gap: var(--va-space-inline-sm);\n min-width: 16rem;\n max-width: min(24rem, calc(100vw - 32px));\n padding: var(--va-space-inline-sm) var(--va-space-inline-sm) var(--va-space-inline-sm) var(--va-space-inline-md);\n border-radius: var(--va-toast-radius, var(--va-radius-surface));\n background-color: var(--va-toast-bg, var(--va-color-text-default));\n color: var(--va-toast-fg, var(--va-color-surface-default));\n box-shadow: 0 8px 24px rgb(0 0 0 / 0.2);\n font-size: var(--va-font-size-md);\n }\n .toast.success {\n border-left: 4px solid var(--va-color-accent-default);\n }\n .toast.error {\n background-color: var(--va-toast-bg, var(--va-color-danger-default));\n color: var(--va-toast-fg, var(--va-color-text-on-danger));\n }\n .message {\n flex: 1;\n }\n .dismiss {\n flex: none;\n display: grid;\n place-items: center;\n width: 2rem;\n height: 2rem;\n padding: 0;\n border: none;\n border-radius: var(--va-radius-control);\n background: transparent;\n color: inherit;\n cursor: pointer;\n }\n .dismiss svg {\n width: 1.125rem;\n height: 1.125rem;\n }\n @media (max-width: 480px) {\n :host {\n inset: auto 16px 16px 16px;\n }\n .toast {\n min-width: 0;\n max-width: none;\n }\n }\n @media (forced-colors: active) {\n .toast {\n border: 2px solid CanvasText;\n }\n }\n `,\n ];\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'va-toast': VaToast;\n }\n}\n"]}
|
package/dist/prod/all.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Generated by build.js: registers every Vastu component.
|
|
2
|
+
export * from './bar-chart/index.js';
|
|
3
|
+
export * from './button/index.js';
|
|
4
|
+
export * from './checkbox/index.js';
|
|
5
|
+
export * from './dialog/index.js';
|
|
6
|
+
export * from './menu/index.js';
|
|
7
|
+
export * from './navbar/index.js';
|
|
8
|
+
export * from './poll/index.js';
|
|
9
|
+
export * from './switch/index.js';
|
|
10
|
+
export * from './tabs/index.js';
|
|
11
|
+
export * from './text-field/index.js';
|
|
12
|
+
export * from './toast/index.js';
|
|
13
|
+
//# sourceMappingURL=all.js.map
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import { LitElement, css, html } from 'lit';
|
|
2
|
+
import { cssom } from '../core/cssom.js';
|
|
3
|
+
import { checkTokensLoaded, devWarn } from '../core/warn.js';
|
|
4
|
+
/** A step of 1, 2 or 5 times a power of ten that splits `range` into about `count` parts. */
|
|
5
|
+
function niceStep(range, count) {
|
|
6
|
+
const raw = range / count;
|
|
7
|
+
const power = 10 ** Math.floor(Math.log10(raw));
|
|
8
|
+
const f = raw / power;
|
|
9
|
+
return (f <= 1 ? 1 : f <= 2 ? 2 : f <= 5 ? 5 : 10) * power;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* A bar chart that compares values across a few categories. The data is plain markup, and the
|
|
13
|
+
* bars animate when it changes, so it can follow live values.
|
|
14
|
+
*
|
|
15
|
+
* @tag va-bar-chart
|
|
16
|
+
* @summary Compares a number across a few categories, one bar per category.
|
|
17
|
+
*
|
|
18
|
+
* @slot - The data, as `<data value="N">Category</data>` elements, in order. Change them and the bars animate to the new values.
|
|
19
|
+
*
|
|
20
|
+
* @csspart label - The chart's title.
|
|
21
|
+
* @csspart plot - The area the bars are drawn in.
|
|
22
|
+
* @csspart bar - Each bar.
|
|
23
|
+
* @csspart axis - The value labels along the left edge.
|
|
24
|
+
*
|
|
25
|
+
* @cssprop {<color>} --va-bar-chart-bar-bg - Colour of the bars.
|
|
26
|
+
* @cssprop {<length>} --va-bar-chart-bar-radius - Corner radius of the bars' outer end.
|
|
27
|
+
* @cssprop {<length>} --va-bar-chart-size - Height of the plot area.
|
|
28
|
+
*
|
|
29
|
+
* @cssprop-applies --va-bar-chart-bar-bg bar background-color
|
|
30
|
+
* @cssprop-applies --va-bar-chart-bar-radius bar border-top-left-radius
|
|
31
|
+
* @cssprop-applies --va-bar-chart-size plot height
|
|
32
|
+
*
|
|
33
|
+
* @keyboard-items data
|
|
34
|
+
* @keyboard items: ArrowRight | next | Moves to the next bar, wrapping round.
|
|
35
|
+
* @keyboard items: ArrowLeft | previous | Moves to the previous bar, wrapping round.
|
|
36
|
+
* @keyboard items: Home | first | Moves to the first bar.
|
|
37
|
+
* @keyboard items: End | last | Moves to the last bar.
|
|
38
|
+
*
|
|
39
|
+
* @a11y-role figure
|
|
40
|
+
* @a11y-name-from label
|
|
41
|
+
* @a11y-name The `label`, which is the chart's visible title.
|
|
42
|
+
* @a11y-note Each `<data>` element is in the Tab order once (roving tabindex) and is announced as "Category: value". Arrow keys move between bars.
|
|
43
|
+
* @a11y-note The value axis is hidden from assistive technology, because every bar announces its own value.
|
|
44
|
+
*
|
|
45
|
+
* @guidance-use To compare one number across a few categories (up to about 12), such as visitors per day or sales per region.
|
|
46
|
+
* @guidance-avoid For trends over many points in time, for parts of a whole, or when readers need to look up exact values.
|
|
47
|
+
* @guidance-instead A line chart for trends; a table when exact values matter.
|
|
48
|
+
*/
|
|
49
|
+
export class VaBarChart extends LitElement {
|
|
50
|
+
static { this.shadowRootOptions = { ...LitElement.shadowRootOptions, slotAssignment: 'manual' }; }
|
|
51
|
+
static { this.properties = {
|
|
52
|
+
label: {},
|
|
53
|
+
max: { type: Number },
|
|
54
|
+
_revision: { state: true },
|
|
55
|
+
_focused: { state: true },
|
|
56
|
+
}; }
|
|
57
|
+
#observer = new MutationObserver(() => this._revision++);
|
|
58
|
+
constructor() {
|
|
59
|
+
super();
|
|
60
|
+
this.label = '';
|
|
61
|
+
this.max = 0;
|
|
62
|
+
this._revision = 0;
|
|
63
|
+
this._focused = -1;
|
|
64
|
+
this.addEventListener('keydown', this.#onKeydown);
|
|
65
|
+
this.addEventListener('focusin', this.#onFocusin);
|
|
66
|
+
this.addEventListener('focusout', () => (this._focused = -1));
|
|
67
|
+
}
|
|
68
|
+
connectedCallback() {
|
|
69
|
+
super.connectedCallback();
|
|
70
|
+
checkTokensLoaded(this);
|
|
71
|
+
this.#observer.observe(this, { childList: true, subtree: true, characterData: true, attributes: true, attributeFilter: ['value'] });
|
|
72
|
+
// Children may have changed while the chart was detached and unobserved.
|
|
73
|
+
if (this.hasUpdated)
|
|
74
|
+
this._revision++;
|
|
75
|
+
}
|
|
76
|
+
disconnectedCallback() {
|
|
77
|
+
super.disconnectedCallback();
|
|
78
|
+
this.#observer.disconnect();
|
|
79
|
+
}
|
|
80
|
+
get #items() {
|
|
81
|
+
return [...this.children];
|
|
82
|
+
}
|
|
83
|
+
#valueOf(item) {
|
|
84
|
+
const value = Number(item.getAttribute('value'));
|
|
85
|
+
return Number.isFinite(value) ? value : 0;
|
|
86
|
+
}
|
|
87
|
+
get #format() {
|
|
88
|
+
return new Intl.NumberFormat(this.closest('[lang]')?.getAttribute('lang') || undefined);
|
|
89
|
+
}
|
|
90
|
+
firstUpdated() {
|
|
91
|
+
if (!this.label)
|
|
92
|
+
devWarn('va-bar-chart', 'This chart has no label, so it has no title or accessible name.', 'Add label="…" that says what the bars show (e.g. label="Visitors per day").');
|
|
93
|
+
}
|
|
94
|
+
updated(changed) {
|
|
95
|
+
const items = this.#items;
|
|
96
|
+
const slots = [...this.shadowRoot.querySelectorAll('slot')];
|
|
97
|
+
items.forEach((item, i) => slots[i]?.assign(item));
|
|
98
|
+
const format = this.#format;
|
|
99
|
+
const current = Math.max(0, items.findIndex((i) => i.tabIndex === 0));
|
|
100
|
+
items.forEach((item, i) => {
|
|
101
|
+
item.tabIndex = i === current ? 0 : -1;
|
|
102
|
+
item.setAttribute('role', 'img');
|
|
103
|
+
item.setAttribute('aria-label', `${item.textContent?.trim()}: ${format.format(this.#valueOf(item))}`);
|
|
104
|
+
});
|
|
105
|
+
if (changed.has('_revision')) {
|
|
106
|
+
if (items.some((i) => i.localName !== 'data')) {
|
|
107
|
+
devWarn('va-bar-chart', 'A child is not a <data> element, so it is drawn as a bar with value 0.', 'Use <data value="N">Category</data> for each bar.');
|
|
108
|
+
}
|
|
109
|
+
for (const item of items.filter((i) => i.localName === 'data' && !Number.isFinite(Number(i.getAttribute('value') ?? 'x')))) {
|
|
110
|
+
devWarn('va-bar-chart', `"${item.textContent?.trim()}" has value="${item.getAttribute('value') ?? ''}", which is not a number.`, 'Set value to a plain number, without units or separators (e.g. value="1200").');
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
#onFocusin = (event) => {
|
|
115
|
+
const items = this.#items;
|
|
116
|
+
const index = items.indexOf(event.target);
|
|
117
|
+
if (index < 0)
|
|
118
|
+
return;
|
|
119
|
+
items.forEach((item, i) => (item.tabIndex = i === index ? 0 : -1));
|
|
120
|
+
this._focused = index;
|
|
121
|
+
};
|
|
122
|
+
#onKeydown = (event) => {
|
|
123
|
+
const items = this.#items;
|
|
124
|
+
const current = items.indexOf(event.target);
|
|
125
|
+
if (current < 0 || !items.length)
|
|
126
|
+
return;
|
|
127
|
+
const next = { ArrowRight: current + 1, ArrowLeft: current - 1, Home: 0, End: items.length - 1 }[event.key];
|
|
128
|
+
if (next === undefined)
|
|
129
|
+
return;
|
|
130
|
+
event.preventDefault();
|
|
131
|
+
items[(next + items.length) % items.length].focus();
|
|
132
|
+
};
|
|
133
|
+
render() {
|
|
134
|
+
const items = this.#items;
|
|
135
|
+
const values = items.map((i) => this.#valueOf(i));
|
|
136
|
+
const format = this.#format;
|
|
137
|
+
// The axis always includes 0, so bars start from a baseline and their lengths compare honestly.
|
|
138
|
+
let lo = Math.min(0, ...values);
|
|
139
|
+
let hi = this.max > 0 ? this.max : Math.max(0, ...values);
|
|
140
|
+
if (hi === lo)
|
|
141
|
+
hi = lo + 1;
|
|
142
|
+
const step = niceStep(hi - lo, 5);
|
|
143
|
+
lo = Math.floor(lo / step) * step;
|
|
144
|
+
if (!(this.max > 0))
|
|
145
|
+
hi = Math.ceil(hi / step) * step;
|
|
146
|
+
const ticks = [];
|
|
147
|
+
// Count steps instead of adding them up, and round to the step's decimals, so float error
|
|
148
|
+
// never gives a "-0" label or a missing zero line.
|
|
149
|
+
const decimals = Math.max(0, -Math.floor(Math.log10(step)));
|
|
150
|
+
for (let i = 0; lo + i * step <= hi + step / 1e6; i++)
|
|
151
|
+
ticks.push(Number((lo + i * step).toFixed(decimals)) + 0);
|
|
152
|
+
const pos = (v) => ((Math.min(Math.max(v, lo), hi) - lo) / (hi - lo)) * 100;
|
|
153
|
+
return html `
|
|
154
|
+
<div class="chart" role="figure" aria-labelledby="label">
|
|
155
|
+
<div part="label" id="label" class="label">${this.label}</div>
|
|
156
|
+
<div class="body">
|
|
157
|
+
<div part="axis" class="axis" aria-hidden="true">
|
|
158
|
+
${ticks.map((t) => html `<span class="tick" ${cssom({ bottom: `${pos(t)}%` })}>${format.format(t)}</span>`)}
|
|
159
|
+
</div>
|
|
160
|
+
<div class="columns">
|
|
161
|
+
<div part="plot" class="plot">
|
|
162
|
+
${ticks.map((t) => html `<span class=${t === 0 ? 'grid zero' : 'grid'} ${cssom({ bottom: `${pos(t)}%` })}></span>`)}
|
|
163
|
+
${values.map((v, i) => {
|
|
164
|
+
const top = pos(Math.max(v, 0));
|
|
165
|
+
const bottom = pos(Math.min(v, 0));
|
|
166
|
+
return html `
|
|
167
|
+
<div class=${i === this._focused ? 'column focused' : 'column'}>
|
|
168
|
+
<span
|
|
169
|
+
part="bar"
|
|
170
|
+
class=${v < 0 ? 'bar negative' : 'bar'}
|
|
171
|
+
${cssom({ bottom: `${bottom}%`, height: `${top - bottom}%` })}
|
|
172
|
+
></span>
|
|
173
|
+
<span class="value" aria-hidden="true" ${cssom(v < 0 ? { top: `${100 - bottom}%` } : { bottom: `${top}%` })}>${format.format(v)}</span>
|
|
174
|
+
</div>
|
|
175
|
+
`;
|
|
176
|
+
})}
|
|
177
|
+
</div>
|
|
178
|
+
<div class="labels">${items.map(() => html `<div class="category"><slot></slot></div>`)}</div>
|
|
179
|
+
</div>
|
|
180
|
+
</div>
|
|
181
|
+
</div>
|
|
182
|
+
`;
|
|
183
|
+
}
|
|
184
|
+
static { this.styles = css `
|
|
185
|
+
:host {
|
|
186
|
+
display: block;
|
|
187
|
+
box-sizing: border-box;
|
|
188
|
+
width: 100%;
|
|
189
|
+
font-family: var(--va-font-family-ui);
|
|
190
|
+
font-size: var(--va-font-size-sm);
|
|
191
|
+
color: var(--va-color-text-default);
|
|
192
|
+
}
|
|
193
|
+
:host([hidden]) {
|
|
194
|
+
display: none;
|
|
195
|
+
}
|
|
196
|
+
.label {
|
|
197
|
+
margin-bottom: var(--va-space-gap-md);
|
|
198
|
+
font-size: var(--va-font-size-md);
|
|
199
|
+
font-weight: var(--va-font-weight-bold);
|
|
200
|
+
}
|
|
201
|
+
.body {
|
|
202
|
+
display: grid;
|
|
203
|
+
grid-template-columns: auto 1fr;
|
|
204
|
+
gap: var(--va-space-gap-md);
|
|
205
|
+
}
|
|
206
|
+
.axis {
|
|
207
|
+
position: relative;
|
|
208
|
+
height: var(--va-bar-chart-size, 12rem);
|
|
209
|
+
min-width: 2ch;
|
|
210
|
+
color: var(--va-color-text-muted);
|
|
211
|
+
font-variant-numeric: tabular-nums;
|
|
212
|
+
}
|
|
213
|
+
.tick {
|
|
214
|
+
position: absolute;
|
|
215
|
+
right: 0;
|
|
216
|
+
transform: translateY(50%);
|
|
217
|
+
line-height: 1;
|
|
218
|
+
white-space: nowrap;
|
|
219
|
+
}
|
|
220
|
+
.columns {
|
|
221
|
+
min-width: 0;
|
|
222
|
+
}
|
|
223
|
+
.plot {
|
|
224
|
+
position: relative;
|
|
225
|
+
display: flex;
|
|
226
|
+
height: var(--va-bar-chart-size, 12rem);
|
|
227
|
+
}
|
|
228
|
+
.grid {
|
|
229
|
+
position: absolute;
|
|
230
|
+
left: 0;
|
|
231
|
+
right: 0;
|
|
232
|
+
border-top: 1px solid var(--va-color-border-subtle);
|
|
233
|
+
}
|
|
234
|
+
.grid.zero {
|
|
235
|
+
border-top-color: var(--va-color-border-control);
|
|
236
|
+
}
|
|
237
|
+
.column {
|
|
238
|
+
position: relative;
|
|
239
|
+
flex: 1;
|
|
240
|
+
min-width: 0;
|
|
241
|
+
}
|
|
242
|
+
.bar {
|
|
243
|
+
position: absolute;
|
|
244
|
+
left: 18%;
|
|
245
|
+
right: 18%;
|
|
246
|
+
border-radius: var(--va-bar-chart-bar-radius, 3px) var(--va-bar-chart-bar-radius, 3px) 0 0;
|
|
247
|
+
background-color: var(--va-bar-chart-bar-bg, var(--va-color-accent-default));
|
|
248
|
+
transition:
|
|
249
|
+
height var(--va-motion-duration-slow) ease-out,
|
|
250
|
+
bottom var(--va-motion-duration-slow) ease-out;
|
|
251
|
+
}
|
|
252
|
+
.bar.negative {
|
|
253
|
+
border-radius: 0 0 var(--va-bar-chart-bar-radius, 3px) var(--va-bar-chart-bar-radius, 3px);
|
|
254
|
+
}
|
|
255
|
+
.column:hover .bar,
|
|
256
|
+
.focused .bar {
|
|
257
|
+
background-color: var(--va-bar-chart-bar-bg, var(--va-color-accent-hover));
|
|
258
|
+
filter: brightness(1.1);
|
|
259
|
+
}
|
|
260
|
+
.value {
|
|
261
|
+
position: absolute;
|
|
262
|
+
left: 0;
|
|
263
|
+
right: 0;
|
|
264
|
+
padding: 2px 0;
|
|
265
|
+
font-variant-numeric: tabular-nums;
|
|
266
|
+
font-weight: var(--va-font-weight-medium);
|
|
267
|
+
text-align: center;
|
|
268
|
+
visibility: hidden;
|
|
269
|
+
}
|
|
270
|
+
.column:hover .value,
|
|
271
|
+
.focused .value {
|
|
272
|
+
visibility: visible;
|
|
273
|
+
}
|
|
274
|
+
.labels {
|
|
275
|
+
display: flex;
|
|
276
|
+
margin-top: var(--va-space-gap-sm);
|
|
277
|
+
}
|
|
278
|
+
.category {
|
|
279
|
+
flex: 1;
|
|
280
|
+
min-width: 0;
|
|
281
|
+
text-align: center;
|
|
282
|
+
}
|
|
283
|
+
::slotted(*) {
|
|
284
|
+
display: block;
|
|
285
|
+
overflow: hidden;
|
|
286
|
+
padding: 2px;
|
|
287
|
+
border-radius: var(--va-radius-control);
|
|
288
|
+
color: var(--va-color-text-muted);
|
|
289
|
+
text-overflow: ellipsis;
|
|
290
|
+
white-space: nowrap;
|
|
291
|
+
}
|
|
292
|
+
::slotted(:focus-visible) {
|
|
293
|
+
outline: var(--va-size-focus-ring, 2px) solid var(--va-color-focus);
|
|
294
|
+
outline-offset: 0;
|
|
295
|
+
color: var(--va-color-text-default);
|
|
296
|
+
}
|
|
297
|
+
@media (prefers-reduced-motion: reduce) {
|
|
298
|
+
.bar {
|
|
299
|
+
transition: none;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
@media (forced-colors: active) {
|
|
303
|
+
.bar {
|
|
304
|
+
background-color: CanvasText;
|
|
305
|
+
forced-color-adjust: none;
|
|
306
|
+
}
|
|
307
|
+
.grid {
|
|
308
|
+
border-top-color: GrayText;
|
|
309
|
+
}
|
|
310
|
+
::slotted(:focus-visible) {
|
|
311
|
+
outline-color: Highlight;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
`; }
|
|
315
|
+
}
|
|
316
|
+
//# sourceMappingURL=bar-chart.js.map
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import { LitElement, css, html, nothing } from 'lit';
|
|
2
|
+
import { focusRing } from '../core/focus-ring.js';
|
|
3
|
+
import { checkTokensLoaded, devWarn } from '../core/warn.js';
|
|
4
|
+
/**
|
|
5
|
+
* A button that starts an action or submits a form.
|
|
6
|
+
*
|
|
7
|
+
* @tag va-button
|
|
8
|
+
* @summary Starts an action, or submits or resets the form it is in.
|
|
9
|
+
*
|
|
10
|
+
* @slot - The button's text. This is its accessible name.
|
|
11
|
+
* @slot start - An icon before the text. Mark decorative icons `aria-hidden="true"`.
|
|
12
|
+
* @slot end - An icon after the text.
|
|
13
|
+
*
|
|
14
|
+
* @csspart control - The native button inside.
|
|
15
|
+
* @csspart label - The wrapper around the text.
|
|
16
|
+
*
|
|
17
|
+
* @cssprop {<color>} --va-button-bg - Background colour.
|
|
18
|
+
* @cssprop {<color>} --va-button-bg-hover - Background colour on hover.
|
|
19
|
+
* @cssprop {<color>} --va-button-fg - Text and icon colour.
|
|
20
|
+
* @cssprop {<color>} --va-button-border - Border colour.
|
|
21
|
+
* @cssprop {<length>} --va-button-radius - Corner radius.
|
|
22
|
+
* @cssprop {<length>} --va-button-height - Minimum height.
|
|
23
|
+
* @cssprop {<length>} --va-button-padding-inline - Space before and after the text.
|
|
24
|
+
* @cssprop {<length>} --va-button-font-size - Text size.
|
|
25
|
+
*
|
|
26
|
+
* @cssprop-applies --va-button-bg control background-color
|
|
27
|
+
* @cssprop-applies --va-button-bg-hover control:hover background-color
|
|
28
|
+
* @cssprop-applies --va-button-fg control color
|
|
29
|
+
* @cssprop-applies --va-button-border control border-top-color
|
|
30
|
+
* @cssprop-applies --va-button-radius control border-top-left-radius
|
|
31
|
+
* @cssprop-applies --va-button-height control min-height
|
|
32
|
+
* @cssprop-applies --va-button-padding-inline control padding-left
|
|
33
|
+
* @cssprop-applies --va-button-font-size control font-size
|
|
34
|
+
*
|
|
35
|
+
* @keyboard Enter | activates | Activates the button.
|
|
36
|
+
* @keyboard Space | activates | Activates the button.
|
|
37
|
+
* @keyboard Tab | focus-next | Moves focus to the next control. A disabled button is skipped.
|
|
38
|
+
*
|
|
39
|
+
* @a11y-role button
|
|
40
|
+
* @a11y-name-from text, accessible-label
|
|
41
|
+
* @replaces button
|
|
42
|
+
* @a11y-name The slotted text. A button with only an icon must have `accessible-label`.
|
|
43
|
+
* @a11y-note `loading` keeps the button focusable, sets `aria-disabled` and `aria-busy`, and adds "Loading" to its name.
|
|
44
|
+
*
|
|
45
|
+
* @guidance-use For an action on the current page (Save, Delete, Open dialog) or to submit a form.
|
|
46
|
+
* @guidance-avoid For navigation to another page or URL.
|
|
47
|
+
* @guidance-instead A link (`<a href>`) for navigation.
|
|
48
|
+
*
|
|
49
|
+
* @fires click - The native click event. Not fired while `disabled` or `loading`.
|
|
50
|
+
* @event-trigger click | click
|
|
51
|
+
*/
|
|
52
|
+
export class VaButton extends LitElement {
|
|
53
|
+
static { this.shadowRootOptions = { ...LitElement.shadowRootOptions, delegatesFocus: true }; }
|
|
54
|
+
/** @internal */
|
|
55
|
+
static { this.formAssociated = true; }
|
|
56
|
+
static { this.properties = {
|
|
57
|
+
variant: { reflect: true },
|
|
58
|
+
size: { reflect: true },
|
|
59
|
+
type: { reflect: true },
|
|
60
|
+
disabled: { type: Boolean, reflect: true },
|
|
61
|
+
loading: { type: Boolean, reflect: true },
|
|
62
|
+
name: {},
|
|
63
|
+
value: {},
|
|
64
|
+
accessibleLabel: { attribute: 'accessible-label' },
|
|
65
|
+
commandfor: {},
|
|
66
|
+
command: {},
|
|
67
|
+
}; }
|
|
68
|
+
#internals;
|
|
69
|
+
constructor() {
|
|
70
|
+
super();
|
|
71
|
+
this.variant = 'primary';
|
|
72
|
+
this.size = 'md';
|
|
73
|
+
this.type = 'button';
|
|
74
|
+
this.disabled = false;
|
|
75
|
+
this.loading = false;
|
|
76
|
+
this.name = '';
|
|
77
|
+
this.value = '';
|
|
78
|
+
this.accessibleLabel = '';
|
|
79
|
+
this.commandfor = '';
|
|
80
|
+
this.command = '';
|
|
81
|
+
this.#internals = this.attachInternals();
|
|
82
|
+
this.addEventListener('click', this.#onClick);
|
|
83
|
+
}
|
|
84
|
+
/** The form this button belongs to, if any. */
|
|
85
|
+
get form() {
|
|
86
|
+
return this.#internals.form;
|
|
87
|
+
}
|
|
88
|
+
connectedCallback() {
|
|
89
|
+
super.connectedCallback();
|
|
90
|
+
checkTokensLoaded(this);
|
|
91
|
+
}
|
|
92
|
+
#onClick = (event) => {
|
|
93
|
+
if (this.disabled || this.loading) {
|
|
94
|
+
event.preventDefault();
|
|
95
|
+
event.stopImmediatePropagation();
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (this.commandfor && this.command) {
|
|
99
|
+
// Same shape as the native CommandEvent, so components handle both.
|
|
100
|
+
const target = this.getRootNode().getElementById(this.commandfor);
|
|
101
|
+
if (target)
|
|
102
|
+
target.dispatchEvent(Object.assign(new Event('command', { cancelable: true }), { command: this.command, source: this }));
|
|
103
|
+
else
|
|
104
|
+
devWarn('va-button', `commandfor="${this.commandfor}" doesn't match any element id.`, 'Set commandfor to the id of the element to control, in the same document or shadow root.');
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const form = this.#internals.form;
|
|
108
|
+
if (!form)
|
|
109
|
+
return;
|
|
110
|
+
if (this.type === 'submit') {
|
|
111
|
+
// requestSubmit() needs a real submit button as the submitter, so name=value is sent.
|
|
112
|
+
const submitter = document.createElement('button');
|
|
113
|
+
submitter.type = 'submit';
|
|
114
|
+
submitter.hidden = true;
|
|
115
|
+
if (this.name) {
|
|
116
|
+
submitter.name = this.name;
|
|
117
|
+
submitter.value = this.value;
|
|
118
|
+
}
|
|
119
|
+
form.append(submitter);
|
|
120
|
+
form.requestSubmit(submitter);
|
|
121
|
+
submitter.remove();
|
|
122
|
+
}
|
|
123
|
+
else if (this.type === 'reset') {
|
|
124
|
+
form.reset();
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
firstUpdated() {
|
|
128
|
+
// Wait a frame so children parsed after the upgrade are in place before checking the name.
|
|
129
|
+
requestAnimationFrame(() => this.#checkName());
|
|
130
|
+
}
|
|
131
|
+
#checkName = () => {
|
|
132
|
+
const text = this.textContent?.trim() ?? '';
|
|
133
|
+
if (!text && !this.accessibleLabel) {
|
|
134
|
+
devWarn('va-button', 'This button has no accessible name: it has no text and no accessible-label.', 'Put text inside it, or add accessible-label="…" that says what it does (e.g. accessible-label="Close").');
|
|
135
|
+
}
|
|
136
|
+
else if (text && this.accessibleLabel && !this.accessibleLabel.toLowerCase().includes(text.toLowerCase())) {
|
|
137
|
+
devWarn('va-button', `accessible-label="${this.accessibleLabel}" replaces the visible text "${text}" for screen readers, so voice users can't say what they see (WCAG 2.5.3).`, 'Remove accessible-label, or make it start with the visible text.');
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
/** While loading, the name gains ", loading"; otherwise only accessible-label overrides the text. */
|
|
141
|
+
#ariaLabel() {
|
|
142
|
+
const name = this.accessibleLabel || this.textContent?.trim() || '';
|
|
143
|
+
if (this.loading)
|
|
144
|
+
return name ? `${name}, loading` : 'Loading';
|
|
145
|
+
return this.accessibleLabel || undefined;
|
|
146
|
+
}
|
|
147
|
+
render() {
|
|
148
|
+
return html `
|
|
149
|
+
<button
|
|
150
|
+
part="control"
|
|
151
|
+
class="control"
|
|
152
|
+
type="button"
|
|
153
|
+
?disabled=${this.disabled}
|
|
154
|
+
aria-disabled=${this.loading ? 'true' : nothing}
|
|
155
|
+
aria-busy=${this.loading ? 'true' : nothing}
|
|
156
|
+
aria-label=${this.#ariaLabel() ?? nothing}
|
|
157
|
+
>
|
|
158
|
+
<slot name="start"></slot>
|
|
159
|
+
<span part="label" class="label"><slot @slotchange=${this.#checkName}></slot></span>
|
|
160
|
+
${this.loading ? html `<span class="spinner" aria-hidden="true"></span>` : nothing}
|
|
161
|
+
<slot name="end"></slot>
|
|
162
|
+
</button>
|
|
163
|
+
`;
|
|
164
|
+
}
|
|
165
|
+
static { this.styles = [
|
|
166
|
+
focusRing,
|
|
167
|
+
css `
|
|
168
|
+
:host {
|
|
169
|
+
--_bg: var(--va-button-bg, var(--va-color-accent-default));
|
|
170
|
+
--_bg-hover: var(--va-button-bg-hover, var(--va-color-accent-hover));
|
|
171
|
+
--_fg: var(--va-button-fg, var(--va-color-text-on-accent));
|
|
172
|
+
--_border: var(--va-button-border, transparent);
|
|
173
|
+
--_height: var(--va-button-height, var(--va-size-control-md));
|
|
174
|
+
--_padding: var(--va-button-padding-inline, var(--va-space-inline-lg));
|
|
175
|
+
--_font-size: var(--va-button-font-size, var(--va-font-size-md));
|
|
176
|
+
display: inline-block;
|
|
177
|
+
vertical-align: middle;
|
|
178
|
+
}
|
|
179
|
+
:host([hidden]) {
|
|
180
|
+
display: none;
|
|
181
|
+
}
|
|
182
|
+
:host([variant='secondary']) {
|
|
183
|
+
--_bg: var(--va-button-bg, transparent);
|
|
184
|
+
--_bg-hover: var(--va-button-bg-hover, var(--va-color-surface-subtle));
|
|
185
|
+
--_fg: var(--va-button-fg, var(--va-color-text-default));
|
|
186
|
+
--_border: var(--va-button-border, var(--va-color-border-control));
|
|
187
|
+
}
|
|
188
|
+
:host([variant='ghost']) {
|
|
189
|
+
--_bg: var(--va-button-bg, transparent);
|
|
190
|
+
--_bg-hover: var(--va-button-bg-hover, var(--va-color-surface-subtle));
|
|
191
|
+
--_fg: var(--va-button-fg, var(--va-color-accent-default));
|
|
192
|
+
}
|
|
193
|
+
:host([variant='danger']) {
|
|
194
|
+
--_bg: var(--va-button-bg, var(--va-color-danger-default));
|
|
195
|
+
--_bg-hover: var(--va-button-bg-hover, var(--va-color-danger-hover));
|
|
196
|
+
--_fg: var(--va-button-fg, var(--va-color-text-on-danger));
|
|
197
|
+
}
|
|
198
|
+
:host([size='sm']) {
|
|
199
|
+
--_height: var(--va-button-height, var(--va-size-control-sm));
|
|
200
|
+
--_padding: var(--va-button-padding-inline, var(--va-space-inline-md));
|
|
201
|
+
--_font-size: var(--va-button-font-size, var(--va-font-size-sm));
|
|
202
|
+
}
|
|
203
|
+
:host([size='lg']) {
|
|
204
|
+
--_height: var(--va-button-height, var(--va-size-control-lg));
|
|
205
|
+
--_font-size: var(--va-button-font-size, var(--va-font-size-lg));
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
.control {
|
|
209
|
+
box-sizing: border-box;
|
|
210
|
+
display: inline-flex;
|
|
211
|
+
align-items: center;
|
|
212
|
+
justify-content: center;
|
|
213
|
+
gap: var(--va-space-gap-md);
|
|
214
|
+
width: 100%;
|
|
215
|
+
min-height: var(--_height);
|
|
216
|
+
margin: 0;
|
|
217
|
+
padding: 0 var(--_padding);
|
|
218
|
+
border: 1px solid var(--_border);
|
|
219
|
+
border-radius: var(--va-button-radius, var(--va-radius-control));
|
|
220
|
+
background-color: var(--_bg);
|
|
221
|
+
color: var(--_fg);
|
|
222
|
+
font-family: var(--va-font-family-ui);
|
|
223
|
+
font-size: var(--_font-size);
|
|
224
|
+
font-weight: var(--va-font-weight-medium);
|
|
225
|
+
line-height: 1.2;
|
|
226
|
+
cursor: pointer;
|
|
227
|
+
transition: background-color var(--va-motion-duration-fast) ease-out;
|
|
228
|
+
-webkit-tap-highlight-color: transparent;
|
|
229
|
+
}
|
|
230
|
+
.control:hover:not(:disabled):not([aria-disabled='true']) {
|
|
231
|
+
background-color: var(--_bg-hover);
|
|
232
|
+
}
|
|
233
|
+
.control:disabled {
|
|
234
|
+
opacity: 0.5;
|
|
235
|
+
cursor: not-allowed;
|
|
236
|
+
}
|
|
237
|
+
.control[aria-disabled='true'] {
|
|
238
|
+
cursor: progress;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
::slotted(svg),
|
|
242
|
+
::slotted([slot='start']),
|
|
243
|
+
::slotted([slot='end']) {
|
|
244
|
+
flex: none;
|
|
245
|
+
width: 1.25em;
|
|
246
|
+
height: 1.25em;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
.spinner {
|
|
250
|
+
flex: none;
|
|
251
|
+
width: 1em;
|
|
252
|
+
height: 1em;
|
|
253
|
+
border: 2px solid currentColor;
|
|
254
|
+
border-right-color: transparent;
|
|
255
|
+
border-radius: 50%;
|
|
256
|
+
animation: spin 0.8s linear infinite;
|
|
257
|
+
}
|
|
258
|
+
@keyframes spin {
|
|
259
|
+
to {
|
|
260
|
+
transform: rotate(1turn);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
@media (prefers-reduced-motion: reduce) {
|
|
265
|
+
.control {
|
|
266
|
+
transition: none;
|
|
267
|
+
}
|
|
268
|
+
.spinner {
|
|
269
|
+
animation-duration: 2.4s;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
@media (forced-colors: active) {
|
|
274
|
+
.control {
|
|
275
|
+
border-color: ButtonText;
|
|
276
|
+
}
|
|
277
|
+
:host(:not([variant])) .control,
|
|
278
|
+
:host([variant='primary']) .control,
|
|
279
|
+
:host([variant='danger']) .control {
|
|
280
|
+
background-color: ButtonText;
|
|
281
|
+
color: ButtonFace;
|
|
282
|
+
forced-color-adjust: none;
|
|
283
|
+
}
|
|
284
|
+
.control:disabled {
|
|
285
|
+
border-color: GrayText;
|
|
286
|
+
color: GrayText;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
`,
|
|
290
|
+
]; }
|
|
291
|
+
}
|
|
292
|
+
//# sourceMappingURL=button.js.map
|