@unframed/cli 0.12.0 → 0.13.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/package.json
CHANGED
package/registry.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
2
|
+
"version": "0.13.0",
|
|
3
3
|
"components": {
|
|
4
4
|
"accordion": {
|
|
5
5
|
"name": "accordion",
|
|
@@ -361,6 +361,27 @@
|
|
|
361
361
|
"lit"
|
|
362
362
|
]
|
|
363
363
|
},
|
|
364
|
+
"empty-state": {
|
|
365
|
+
"name": "empty-state",
|
|
366
|
+
"entry": "components/empty-state/empty-state.ts",
|
|
367
|
+
"tag": "uf-empty-state",
|
|
368
|
+
"summary": "Fills an empty list or page with a message and what to do next.",
|
|
369
|
+
"files": [
|
|
370
|
+
"components/empty-state/empty-state.ts"
|
|
371
|
+
],
|
|
372
|
+
"internal": [
|
|
373
|
+
"internal/define.ts",
|
|
374
|
+
"internal/shared.styles.ts",
|
|
375
|
+
"internal/slot.ts",
|
|
376
|
+
"internal/icons.ts"
|
|
377
|
+
],
|
|
378
|
+
"dependencies": [
|
|
379
|
+
"icon"
|
|
380
|
+
],
|
|
381
|
+
"npm": [
|
|
382
|
+
"lit"
|
|
383
|
+
]
|
|
384
|
+
},
|
|
364
385
|
"file-upload": {
|
|
365
386
|
"name": "file-upload",
|
|
366
387
|
"entry": "components/file-upload/file-upload.ts",
|
|
@@ -440,6 +461,30 @@
|
|
|
440
461
|
"lit"
|
|
441
462
|
]
|
|
442
463
|
},
|
|
464
|
+
"multi-select": {
|
|
465
|
+
"name": "multi-select",
|
|
466
|
+
"entry": "components/multi-select/multi-select.ts",
|
|
467
|
+
"tag": "uf-multi-select",
|
|
468
|
+
"summary": "Lets users search a list and pick several options.",
|
|
469
|
+
"files": [
|
|
470
|
+
"components/multi-select/multi-select.ts"
|
|
471
|
+
],
|
|
472
|
+
"internal": [
|
|
473
|
+
"internal/define.ts",
|
|
474
|
+
"internal/field.ts",
|
|
475
|
+
"internal/form-control.ts",
|
|
476
|
+
"internal/i18n.ts",
|
|
477
|
+
"internal/icons.ts",
|
|
478
|
+
"internal/options.ts",
|
|
479
|
+
"internal/position.ts",
|
|
480
|
+
"internal/shared.styles.ts",
|
|
481
|
+
"internal/slot.ts"
|
|
482
|
+
],
|
|
483
|
+
"dependencies": [],
|
|
484
|
+
"npm": [
|
|
485
|
+
"lit"
|
|
486
|
+
]
|
|
487
|
+
},
|
|
443
488
|
"number-input": {
|
|
444
489
|
"name": "number-input",
|
|
445
490
|
"entry": "components/number-input/number-input.ts",
|
|
@@ -559,6 +604,28 @@
|
|
|
559
604
|
"lit"
|
|
560
605
|
]
|
|
561
606
|
},
|
|
607
|
+
"segmented-control": {
|
|
608
|
+
"name": "segmented-control",
|
|
609
|
+
"entry": "components/segmented-control/segmented-control.ts",
|
|
610
|
+
"tag": "uf-segmented-control",
|
|
611
|
+
"summary": "Picks one of a few options, side by side.",
|
|
612
|
+
"files": [
|
|
613
|
+
"components/segmented-control/segmented-control.ts"
|
|
614
|
+
],
|
|
615
|
+
"internal": [
|
|
616
|
+
"internal/define.ts",
|
|
617
|
+
"internal/field.ts",
|
|
618
|
+
"internal/form-control.ts",
|
|
619
|
+
"internal/i18n.ts",
|
|
620
|
+
"internal/options.ts",
|
|
621
|
+
"internal/shared.styles.ts",
|
|
622
|
+
"internal/slot.ts"
|
|
623
|
+
],
|
|
624
|
+
"dependencies": [],
|
|
625
|
+
"npm": [
|
|
626
|
+
"lit"
|
|
627
|
+
]
|
|
628
|
+
},
|
|
562
629
|
"select": {
|
|
563
630
|
"name": "select",
|
|
564
631
|
"entry": "components/select/select.ts",
|
|
@@ -759,10 +826,10 @@
|
|
|
759
826
|
"components/accordion/accordion.ts": "import { LitElement, css, html, type PropertyDeclarations } from 'lit';\nimport { defineElement } from '../../internal/define.js';\nimport './accordion-item.js';\nimport type { UfAccordionItem } from './accordion-item.js';\n\nexport { UfAccordionItem } from './accordion-item.js';\n\n/**\n * Groups `<uf-accordion-item>`s. By default opening one item closes the\n * others; set `multiple` to let several stay open. Up and Down arrows move\n * between headers, Home and End jump to the first and last.\n *\n * @summary A stack of sections that expand and collapse.\n * @tag uf-accordion\n *\n * @slot - `<uf-accordion-item>` elements.\n *\n * @csspart base - The wrapper around the items.\n */\nexport class UfAccordion extends LitElement {\n static override styles = css`\n :host {\n display: block;\n border-top: 1px solid var(--uf-color-border);\n }\n `;\n\n static override properties: PropertyDeclarations = {\n multiple: { type: Boolean, reflect: true },\n };\n\n /** Allows several items to be open at once. */\n declare multiple: boolean;\n\n constructor() {\n super();\n this.multiple = false;\n // uf-show doesn't bubble, but it still passes through ancestors while capturing.\n this.addEventListener('uf-show', this.#onShow, { capture: true });\n this.addEventListener('keydown', this.#onKeyDown);\n }\n\n get #items(): UfAccordionItem[] {\n return [...this.querySelectorAll<UfAccordionItem>(':scope > uf-accordion-item')];\n }\n\n #onShow = (event: Event): void => {\n if (this.multiple) return;\n const opened = event.target as UfAccordionItem;\n if (opened.parentElement !== this) return;\n for (const item of this.#items) if (item !== opened) item.hide();\n };\n\n #onKeyDown = (event: KeyboardEvent): void => {\n const item = (event.target as Element).closest('uf-accordion-item');\n // Only react to keys on a header, not inside the content.\n if (!item || item.parentElement !== this || event.composedPath()[0] !== item.header) return;\n\n const items = this.#items.filter((i) => !i.disabled);\n const index = items.indexOf(item);\n const target = {\n ArrowDown: items[(index + 1) % items.length],\n ArrowUp: items[(index - 1 + items.length) % items.length],\n Home: items[0],\n End: items[items.length - 1],\n }[event.key];\n if (!target) return;\n event.preventDefault();\n target.focus();\n };\n\n override render() {\n return html`<div part=\"base\"><slot></slot></div>`;\n }\n}\n\ndefineElement('uf-accordion', UfAccordion);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'uf-accordion': UfAccordion;\n }\n}\n",
|
|
760
827
|
"components/accordion/accordion-item.ts": "import { LitElement, css, html, type PropertyDeclarations, type PropertyValues } from 'lit';\nimport { defineElement } from '../../internal/define.js';\nimport { iconSvg, icons } from '../../internal/icons.js';\nimport { hostStyles } from '../../internal/shared.styles.js';\n\n/**\n * A collapsible section, built on the native `<details>` element: the header\n * is a real disclosure button, and the browser's find-in-page opens a closed\n * item when it contains the match. Use it alone or inside `<uf-accordion>`.\n *\n * @summary A section that expands and collapses.\n * @tag uf-accordion-item\n *\n * @slot - The content.\n * @slot summary - The header, when you need markup. Overrides `summary`.\n *\n * @event uf-show - The item opened.\n * @event uf-hide - The item closed.\n *\n * @csspart base - The native `<details>`.\n * @csspart header - The clickable header (`<summary>`).\n * @csspart chevron - The arrow icon.\n * @csspart content - The content wrapper.\n *\n * @cssprop --uf-accordion-padding - Horizontal padding of header and content.\n */\nexport class UfAccordionItem extends LitElement {\n static override styles = [\n hostStyles,\n css`\n :host {\n --_padding: var(--uf-accordion-padding, var(--uf-space-1));\n display: block;\n border-bottom: 1px solid var(--uf-color-border);\n font-family: var(--uf-font-family-sans);\n font-size: var(--uf-font-size-md);\n color: var(--uf-color-text);\n /* Lets block-size animate to and from auto, where supported. */\n interpolate-size: allow-keywords;\n /* Gets going right away and glides to a stop: responsive, but smooth. */\n --_duration: var(--uf-duration-base);\n --_easing: cubic-bezier(0.4, 0, 0.2, 1);\n }\n\n summary {\n display: flex;\n align-items: center;\n gap: var(--uf-space-2);\n padding: var(--uf-space-3) var(--_padding);\n font-weight: var(--uf-font-weight-medium);\n line-height: 1.4;\n cursor: pointer;\n list-style: none;\n user-select: none;\n }\n\n summary::-webkit-details-marker {\n display: none;\n }\n\n summary:hover {\n background: var(--uf-color-accent-tint);\n color: var(--uf-color-on-accent-tint);\n }\n\n summary:focus-visible {\n outline: var(--uf-focus-ring-width) solid var(--uf-color-focus-ring);\n outline-offset: calc(var(--uf-focus-ring-width) * -1);\n }\n\n .summary {\n flex: 1;\n min-width: 0;\n }\n\n .icon {\n flex: none;\n width: 1.125rem;\n height: 1.125rem;\n color: var(--uf-color-text-muted);\n transition: rotate var(--_duration) var(--_easing);\n }\n\n details[open] .icon {\n rotate: 180deg;\n }\n\n .content {\n padding: 0 var(--_padding) var(--uf-space-4);\n line-height: 1.5;\n color: var(--uf-color-text-muted);\n opacity: 0;\n transition: opacity var(--_duration) var(--_easing);\n }\n\n /* The content fades in as the panel opens, instead of appearing all at once. */\n details[open] .content {\n opacity: 1;\n }\n\n details::details-content {\n block-size: 0;\n overflow: clip;\n transition:\n block-size var(--_duration) var(--_easing),\n content-visibility var(--_duration) allow-discrete;\n }\n\n details[open]::details-content {\n block-size: auto;\n }\n\n :host([disabled]) summary {\n opacity: 0.5;\n cursor: not-allowed;\n }\n\n :host([disabled]) summary:hover {\n background: none;\n color: inherit;\n }\n\n @media (prefers-reduced-motion: reduce) {\n details::details-content,\n .icon,\n .content {\n transition: none;\n }\n }\n `,\n ];\n\n static override properties: PropertyDeclarations = {\n open: { type: Boolean, reflect: true },\n summary: {},\n disabled: { type: Boolean, reflect: true },\n };\n\n /** Whether the item is expanded. */\n declare open: boolean;\n /** Header text. */\n declare summary: string | undefined;\n /** Prevents the user from toggling the item. */\n declare disabled: boolean;\n\n constructor() {\n super();\n this.open = false;\n this.disabled = false;\n }\n\n get #details(): HTMLDetailsElement | null {\n return this.renderRoot.querySelector('details');\n }\n\n /** The header element, for keyboard navigation between items. */\n get header(): HTMLElement | null {\n return this.renderRoot.querySelector('summary');\n }\n\n /** Expands the item. */\n show(): void {\n this.open = true;\n }\n\n /** Collapses the item. */\n hide(): void {\n this.open = false;\n }\n\n /** Focuses the header. */\n override focus(options?: FocusOptions): void {\n this.header?.focus(options);\n }\n\n override updated(changed: PropertyValues<this>): void {\n const details = this.#details;\n if (details && changed.has('open') && details.open !== this.open) details.open = this.open;\n }\n\n #onSummaryClick = (event: MouseEvent): void => {\n if (this.disabled) event.preventDefault();\n };\n\n /** The last state announced with uf-show / uf-hide. */\n #reported = false;\n\n override firstUpdated(): void {\n this.#reported = this.open;\n }\n\n /** Fires for user clicks, find-in-page and programmatic changes alike. */\n #onToggle = (): void => {\n const open = this.#details!.open;\n this.open = open;\n if (open === this.#reported) return;\n this.#reported = open;\n this.dispatchEvent(new Event(open ? 'uf-show' : 'uf-hide'));\n };\n\n override render() {\n return html`\n <details part=\"base\" ?open=${this.open} @toggle=${this.#onToggle}>\n <summary part=\"header\" aria-disabled=${this.disabled ? 'true' : 'false'} @click=${this.#onSummaryClick}>\n <span class=\"summary\"><slot name=\"summary\">${this.summary}</slot></span>\n ${iconSvg(icons['chevron-down'], 'chevron')}\n </summary>\n <div class=\"content\" part=\"content\"><slot></slot></div>\n </details>\n `;\n }\n}\n\ndefineElement('uf-accordion-item', UfAccordionItem);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'uf-accordion-item': UfAccordionItem;\n }\n}\n",
|
|
761
828
|
"internal/define.ts": "/**\n * Registers a custom element unless the tag is already taken, so loading the\n * library twice (e.g. two micro-frontends) doesn't throw.\n */\nexport function defineElement(tagName: string, ctor: CustomElementConstructor): void {\n if (!customElements.get(tagName)) customElements.define(tagName, ctor);\n}\n",
|
|
762
|
-
"internal/icons.ts": "import { svg, type SVGTemplateResult } from 'lit';\n\n/** Built-in 24×24 stroke icons, drawn with currentColor. */\nexport const icons = {\n check: svg`<path d=\"M5 12.5l4.5 4.5L19 7.5\" />`,\n minus: svg`<path d=\"M6 12h12\" />`,\n x: svg`<path d=\"M6 6l12 12M18 6L6 18\" />`,\n 'chevron-down': svg`<path d=\"M6 9l6 6 6-6\" />`,\n 'chevron-up': svg`<path d=\"M6 15l6-6 6 6\" />`,\n 'chevron-left': svg`<path d=\"M15 6l-6 6 6 6\" />`,\n 'chevron-right': svg`<path d=\"M9 6l6 6-6 6\" />`,\n plus: svg`<path d=\"M12 5v14M5 12h14\" />`,\n search: svg`<circle cx=\"11\" cy=\"11\" r=\"7\" /><path d=\"M20 20l-4-4\" />`,\n info: svg`<circle cx=\"12\" cy=\"12\" r=\"9\" /><path d=\"M12 11v5M12 8h.01\" />`,\n 'check-circle': svg`<circle cx=\"12\" cy=\"12\" r=\"9\" /><path d=\"M8 12.5l2.5 2.5L16 9.5\" />`,\n 'alert-triangle': svg`<path d=\"M12 4L2.5 20h19L12 4z\" /><path d=\"M12 10v4M12 17h.01\" />`,\n 'alert-circle': svg`<circle cx=\"12\" cy=\"12\" r=\"9\" /><path d=\"M12 7.5v5M12 16h.01\" />`,\n sun: svg`<circle cx=\"12\" cy=\"12\" r=\"4\" /><path d=\"M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4\" />`,\n calendar: svg`<rect x=\"3.5\" y=\"5\" width=\"17\" height=\"15.5\" rx=\"2\" /><path d=\"M3.5 10h17M8 3v4M16 3v4\" />`,\n user: svg`<circle cx=\"12\" cy=\"8\" r=\"4\" /><path d=\"M4 21a8 8 0 0 1 16 0\" />`,\n moon: svg`<path d=\"M20 14.5A8 8 0 0 1 9.5 4a8 8 0 1 0 10.5 10.5z\" />`,\n upload: svg`<path d=\"M12 15V4M7.5 8.5L12 4l4.5 4.5\" /><path d=\"M4 15v3.5A1.5 1.5 0 0 0 5.5 20h13a1.5 1.5 0 0 0 1.5-1.5V15\" />`,\n file: svg`<path d=\"M13.5 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8.5z\" /><path d=\"M13.5 3v5.5H19\" />`,\n} satisfies Record<string, SVGTemplateResult>;\n\nexport type BuiltInIconName = keyof typeof icons;\n\n/** Wraps an icon's paths in an `<svg>` element. */\nexport function iconSvg(paths: SVGTemplateResult, part = 'icon') {\n return svg`<svg part=${part} class=\"icon\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\"\n stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\">${paths}</svg>`;\n}\n",
|
|
829
|
+
"internal/icons.ts": "import { svg, type SVGTemplateResult } from 'lit';\n\n/** Built-in 24×24 stroke icons, drawn with currentColor. */\nexport const icons = {\n check: svg`<path d=\"M5 12.5l4.5 4.5L19 7.5\" />`,\n minus: svg`<path d=\"M6 12h12\" />`,\n x: svg`<path d=\"M6 6l12 12M18 6L6 18\" />`,\n 'chevron-down': svg`<path d=\"M6 9l6 6 6-6\" />`,\n 'chevron-up': svg`<path d=\"M6 15l6-6 6 6\" />`,\n 'chevron-left': svg`<path d=\"M15 6l-6 6 6 6\" />`,\n 'chevron-right': svg`<path d=\"M9 6l6 6-6 6\" />`,\n plus: svg`<path d=\"M12 5v14M5 12h14\" />`,\n search: svg`<circle cx=\"11\" cy=\"11\" r=\"7\" /><path d=\"M20 20l-4-4\" />`,\n info: svg`<circle cx=\"12\" cy=\"12\" r=\"9\" /><path d=\"M12 11v5M12 8h.01\" />`,\n 'check-circle': svg`<circle cx=\"12\" cy=\"12\" r=\"9\" /><path d=\"M8 12.5l2.5 2.5L16 9.5\" />`,\n 'alert-triangle': svg`<path d=\"M12 4L2.5 20h19L12 4z\" /><path d=\"M12 10v4M12 17h.01\" />`,\n 'alert-circle': svg`<circle cx=\"12\" cy=\"12\" r=\"9\" /><path d=\"M12 7.5v5M12 16h.01\" />`,\n sun: svg`<circle cx=\"12\" cy=\"12\" r=\"4\" /><path d=\"M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4\" />`,\n calendar: svg`<rect x=\"3.5\" y=\"5\" width=\"17\" height=\"15.5\" rx=\"2\" /><path d=\"M3.5 10h17M8 3v4M16 3v4\" />`,\n user: svg`<circle cx=\"12\" cy=\"8\" r=\"4\" /><path d=\"M4 21a8 8 0 0 1 16 0\" />`,\n moon: svg`<path d=\"M20 14.5A8 8 0 0 1 9.5 4a8 8 0 1 0 10.5 10.5z\" />`,\n upload: svg`<path d=\"M12 15V4M7.5 8.5L12 4l4.5 4.5\" /><path d=\"M4 15v3.5A1.5 1.5 0 0 0 5.5 20h13a1.5 1.5 0 0 0 1.5-1.5V15\" />`,\n file: svg`<path d=\"M13.5 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8.5z\" /><path d=\"M13.5 3v5.5H19\" />`,\n inbox: svg`<path d=\"M3 13l2.6-7.4A1.5 1.5 0 0 1 7 4.5h10a1.5 1.5 0 0 1 1.4 1L21 13v5.5a1.5 1.5 0 0 1-1.5 1.5h-15A1.5 1.5 0 0 1 3 18.5z\" /><path d=\"M3 13h5l1.5 2.5h5L16 13h5\" />`,\n} satisfies Record<string, SVGTemplateResult>;\n\nexport type BuiltInIconName = keyof typeof icons;\n\n/** Wraps an icon's paths in an `<svg>` element. */\nexport function iconSvg(paths: SVGTemplateResult, part = 'icon') {\n return svg`<svg part=${part} class=\"icon\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\"\n stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\">${paths}</svg>`;\n}\n",
|
|
763
830
|
"internal/shared.styles.ts": "import { css } from 'lit';\n\n/** Base styles every component includes. */\nexport const hostStyles = css`\n :host {\n box-sizing: border-box;\n }\n\n :host *,\n :host *::before,\n :host *::after {\n box-sizing: inherit;\n }\n\n :host([hidden]) {\n display: none !important;\n }\n`;\n\n/** Shared keyboard focus ring, driven by the focus tokens. */\nexport const focusRing = css`\n outline: var(--uf-focus-ring-width) solid var(--uf-color-focus-ring);\n outline-offset: var(--uf-focus-ring-offset);\n`;\n",
|
|
764
831
|
"components/alert/alert.ts": "import { LitElement, css, html, nothing, type PropertyDeclarations } from 'lit';\nimport { defineElement } from '../../internal/define.js';\nimport { Translator } from '../../internal/i18n.js';\nimport { iconSvg, icons } from '../../internal/icons.js';\nimport { hostStyles } from '../../internal/shared.styles.js';\nimport { HasSlotController } from '../../internal/slot.js';\n\nexport type AlertVariant = 'neutral' | 'accent' | 'info' | 'success' | 'warning' | 'danger';\n\nconst variantIcons = {\n neutral: icons.info,\n accent: icons.info,\n info: icons.info,\n success: icons['check-circle'],\n warning: icons['alert-triangle'],\n danger: icons['alert-circle'],\n} as const;\n\n/**\n * A message in the page, like \"Your trial ends in 3 days\" or \"We couldn't save\n * your changes\". Unlike a toast it stays where it is until it's dismissed.\n *\n * `warning` and `danger` alerts are announced right away (`role=\"alert\"`), the\n * others politely (`role=\"status\"`). Assistive tech announces an alert when it's\n * added to the page or shown, not when the page loads with it.\n *\n * @summary Shows a message in the page, by meaning: info, success, warning or danger.\n * @tag uf-alert\n *\n * @slot - The message.\n * @slot heading - The heading, when you need markup. Overrides `heading`.\n * @slot icon - Replaces the variant's icon.\n * @slot actions - Buttons or links below the message.\n *\n * @event uf-show - The alert was shown with `show()`.\n * @event uf-hide - The alert was hidden, with the close button or `hide()`.\n *\n * @csspart base - The alert.\n * @csspart icon - The icon.\n * @csspart content - The wrapper around the heading, message and actions.\n * @csspart heading - The heading.\n * @csspart message - The message.\n * @csspart actions - The wrapper around the actions.\n * @csspart close-button - The close button, when `closable` is set.\n *\n * @cssprop --uf-alert-bg - Background color.\n * @cssprop --uf-alert-border-color - Border color.\n * @cssprop --uf-alert-color - Text color.\n * @cssprop --uf-alert-icon-color - Icon color.\n * @cssprop --uf-alert-radius - Corner radius.\n * @cssprop --uf-alert-padding - Space inside the alert.\n */\nexport class UfAlert extends LitElement {\n static override styles = [\n hostStyles,\n css`\n :host {\n display: block;\n --_bg: var(--uf-color-surface-hover);\n --_border: var(--uf-color-border);\n --_icon: var(--uf-color-text-muted);\n }\n\n :host([hidden]) {\n display: none;\n }\n\n :host([variant='accent']) {\n --_bg: var(--uf-color-accent-subtle);\n --_icon: var(--uf-color-accent-strong);\n }\n :host([variant='info']) {\n --_bg: var(--uf-color-info-subtle);\n --_icon: var(--uf-color-info);\n }\n :host([variant='success']) {\n --_bg: var(--uf-color-success-subtle);\n --_icon: var(--uf-color-success);\n }\n :host([variant='warning']) {\n --_bg: var(--uf-color-warning-subtle);\n --_icon: var(--uf-color-warning);\n }\n :host([variant='danger']) {\n --_bg: var(--uf-color-danger-subtle);\n --_icon: var(--uf-color-danger-text);\n }\n /* A border in the variant's color, faint enough to keep the text the focus. */\n :host(:not([variant='neutral'])) {\n --_border: color-mix(in srgb, var(--_icon) 35%, transparent);\n }\n\n .base {\n display: flex;\n align-items: flex-start;\n gap: var(--uf-space-3);\n padding: var(--uf-alert-padding, var(--uf-space-3) var(--uf-space-4));\n border: 1px solid var(--uf-alert-border-color, var(--_border));\n border-radius: var(--uf-alert-radius, var(--uf-radius-md));\n background: var(--uf-alert-bg, var(--_bg));\n color: var(--uf-alert-color, var(--uf-color-text));\n font-family: var(--uf-font-family-sans);\n font-size: var(--uf-font-size-md);\n line-height: 1.5;\n }\n\n .icon-slot {\n display: inline-flex;\n flex: none;\n /* Centers the icon on the first line of text. */\n margin-top: calc((1.5em - 1.125rem) / 2);\n color: var(--uf-alert-icon-color, var(--_icon));\n }\n\n .icon-slot .icon,\n ::slotted([slot='icon']) {\n width: 1.125rem;\n height: 1.125rem;\n }\n\n .content {\n flex: 1;\n min-width: 0;\n }\n\n .heading {\n display: block;\n font-weight: var(--uf-font-weight-semibold);\n }\n\n .actions {\n display: flex;\n flex-wrap: wrap;\n gap: var(--uf-space-2);\n margin-top: var(--uf-space-3);\n }\n\n .close {\n display: inline-flex;\n flex: none;\n align-items: center;\n justify-content: center;\n width: 1.75rem;\n height: 1.75rem;\n /* Lines up with the first line of text, without making the alert taller. */\n margin: calc((1.5em - 1.75rem) / 2) calc(var(--uf-space-1) * -1) 0 0;\n padding: 0;\n border: 0;\n border-radius: var(--uf-radius-sm);\n background: transparent;\n color: var(--uf-color-text-muted);\n cursor: pointer;\n }\n\n .close:hover {\n background: color-mix(in srgb, currentColor 14%, transparent);\n color: var(--uf-color-text);\n }\n\n .close:focus-visible {\n outline: var(--uf-focus-ring-width) solid var(--uf-color-focus-ring);\n outline-offset: 0;\n }\n\n .close .icon {\n width: 1rem;\n height: 1rem;\n }\n\n [hidden] {\n display: none !important;\n }\n `,\n ];\n\n static override properties: PropertyDeclarations = {\n variant: { reflect: true },\n heading: {},\n closable: { type: Boolean, reflect: true },\n withoutIcon: { type: Boolean, reflect: true, attribute: 'without-icon' },\n };\n\n /** Color, icon and urgency, by meaning: `neutral`, `accent`, `info`, `success`, `warning` or `danger`. */\n declare variant: AlertVariant;\n /** Bold first line. */\n declare heading: string | undefined;\n /** Shows a close button that hides the alert. */\n declare closable: boolean;\n /** Hides the icon. */\n declare withoutIcon: boolean;\n\n readonly #slots = new HasSlotController(this, 'heading', 'actions');\n readonly #translator = new Translator(this);\n\n constructor() {\n super();\n this.variant = 'info';\n this.closable = false;\n this.withoutIcon = false;\n }\n\n /** Shows the alert again after it was hidden. */\n show(): void {\n if (!this.hidden) return;\n this.hidden = false;\n this.dispatchEvent(new Event('uf-show'));\n }\n\n /** Hides the alert, like its close button. */\n hide(): void {\n if (this.hidden) return;\n this.hidden = true;\n this.dispatchEvent(new Event('uf-hide'));\n }\n\n override render() {\n const hasHeading = Boolean(this.heading) || this.#slots.has('heading');\n const urgent = this.variant === 'warning' || this.variant === 'danger';\n return html`\n <div class=\"base\" part=\"base\" role=${urgent ? 'alert' : 'status'}>\n <span class=\"icon-slot\" part=\"icon\" ?hidden=${this.withoutIcon}>\n <slot name=\"icon\">${iconSvg(variantIcons[this.variant] ?? icons.info, '')}</slot>\n </span>\n <div class=\"content\" part=\"content\">\n <strong class=\"heading\" part=\"heading\" ?hidden=${!hasHeading}><slot name=\"heading\">${this.heading ?? nothing}</slot></strong>\n <div class=\"message\" part=\"message\"><slot></slot></div>\n <div class=\"actions\" part=\"actions\" ?hidden=${!this.#slots.has('actions')}><slot name=\"actions\"></slot></div>\n </div>\n ${this.closable\n ? html`<button class=\"close\" part=\"close-button\" type=\"button\" aria-label=${this.#translator.t('close')} @click=${() => this.hide()}>\n ${iconSvg(icons.x, '')}\n </button>`\n : nothing}\n </div>\n `;\n }\n}\n\ndefineElement('uf-alert', UfAlert);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'uf-alert': UfAlert;\n }\n}\n",
|
|
765
|
-
"internal/i18n.ts": "import type { ReactiveController, ReactiveControllerHost } from 'lit';\n\n/** Every built-in text, by key. `{page}` is replaced with the page number. */\nexport interface Translations {\n /** Dialog and alert: the close button's accessible name. */\n close: string;\n /** Toast: the dismiss button's accessible name. */\n dismiss: string;\n /** Toaster: the notification region's accessible name, unless `label` is set. */\n notifications: string;\n /** Combobox: the arrow button's accessible name. */\n showOptions: string;\n /** Combobox: shown when the search matches nothing. */\n noResults: string;\n /** Combobox: error when required and empty. */\n selectItem: string;\n /** Combobox: announced while typing when one option matches. */\n oneResult: string;\n /** Combobox: announced while typing; `{count}` is the number of matches. */\n results: `${string}{count}${string}`;\n /** Radio group: error when required and empty. */\n selectOption: string;\n /** Pagination: the navigation's accessible name, unless `label` is set. */\n pagination: string;\n /** Pagination: the previous button's accessible name. */\n previousPage: string;\n /** Pagination: the next button's accessible name. */\n nextPage: string;\n /** Pagination: a page button's accessible name. Must contain `{page}`. */\n page: `${string}{page}${string}`;\n /** Table: shown when there are no rows, unless the `empty` slot is used. */\n noData: string;\n /** Form controls: error for an invalid value that has no message of its own. */\n invalidValue: string;\n /** Date picker: the calendar button's accessible name. */\n chooseDate: string;\n /** Calendar: the previous month button's accessible name. */\n previousMonth: string;\n /** Calendar: the next month button's accessible name. */\n nextMonth: string;\n /** Date picker: error for text that isn't a date; `{example}` is a date in the expected format. */\n invalidDate: `${string}{example}${string}`;\n /** Date picker: error for a date before `min`; `{date}` is the minimum. */\n dateTooEarly: `${string}{date}${string}`;\n /** Date picker: error for a date after `max`; `{date}` is the maximum. */\n dateTooLate: `${string}{date}${string}`;\n /** Date picker: error for a date that `isDateDisabled` rules out. */\n dateUnavailable: string;\n /** Date picker: placeholder letters for day, month and year, in the language's date order. */\n dayPlaceholder: string;\n monthPlaceholder: string;\n yearPlaceholder: string;\n /** Progress: the bar's accessible name, unless `label` is set. */\n progress: string;\n /** Spinner: its accessible name, unless `label` is set. */\n loading: string;\n /** Breadcrumbs: the navigation's accessible name, unless `label` is set. */\n breadcrumb: string;\n /** File upload: the button, with `multiple`. */\n chooseFiles: string;\n /** File upload: the button, for one file. */\n chooseFile: string;\n /** File upload: next to the button, with `multiple`. */\n dropFiles: string;\n /** File upload: next to the button, for one file. */\n dropFile: string;\n /** File upload: a file's remove button. Must contain `{name}`. */\n removeFile: `${string}{name}${string}`;\n /** File upload: a file over `max-size`. Must contain `{name}`, then `{size}`. */\n fileTooLarge: `${string}{name}${string}{size}${string}`;\n /** File upload: a file `accept` rules out. Must contain `{name}`. */\n fileTypeRejected: `${string}{name}${string}`;\n /** Date range picker: the calendar button's accessible name, and the popup's without a `label`. */\n chooseDates: string;\n /** Date range picker: the start input's accessible name, after the label. */\n startDate: string;\n /** Date range picker: the end input's accessible name, after the label. */\n endDate: string;\n /** Date range picker: error when only one of the two dates is set. */\n rangeIncomplete: string;\n /** Date range picker: error when the end date is before the start date. */\n endBeforeStart: string;\n /** Number input: the minus button's accessible name. */\n decrease: string;\n /** Number input: the plus button's accessible name. */\n increase: string;\n}\n\nconst english: Translations = {\n close: 'Close',\n dismiss: 'Dismiss',\n notifications: 'Notifications',\n showOptions: 'Show options',\n noResults: 'No results',\n selectItem: 'Please select an item in the list.',\n oneResult: '1 result',\n results: '{count} results',\n selectOption: 'Please select one of these options.',\n pagination: 'Pagination',\n previousPage: 'Previous page',\n nextPage: 'Next page',\n page: 'Page {page}',\n noData: 'No data',\n invalidValue: 'Invalid value',\n chooseDate: 'Choose date',\n previousMonth: 'Previous month',\n nextMonth: 'Next month',\n invalidDate: 'Enter a date like {example}.',\n dateTooEarly: 'Choose {date} or later.',\n dateTooLate: 'Choose {date} or earlier.',\n dateUnavailable: 'This date is not available.',\n dayPlaceholder: 'dd',\n monthPlaceholder: 'mm',\n yearPlaceholder: 'yyyy',\n progress: 'Progress',\n loading: 'Loading',\n breadcrumb: 'Breadcrumb',\n chooseFiles: 'Choose files',\n chooseFile: 'Choose a file',\n dropFiles: 'or drag them here',\n dropFile: 'or drag it here',\n removeFile: 'Remove {name}',\n fileTooLarge: '{name} is larger than {size}.',\n fileTypeRejected: \"{name} isn't an accepted file type.\",\n chooseDates: 'Choose dates',\n startDate: 'Start date',\n endDate: 'End date',\n rangeIncomplete: 'Enter both a start and an end date.',\n endBeforeStart: \"The end date can't be before the start date.\",\n decrease: 'Decrease',\n increase: 'Increase',\n};\n\n/** Registered translations by lowercase language code; '' applies to every language. */\nconst registered = new Map<string, Partial<Translations>>();\nconst hosts = new Set<ReactiveControllerHost>();\nlet langObserver: MutationObserver | undefined;\n\nconst refreshAll = () => hosts.forEach((host) => host.requestUpdate());\n\n/**\n * Replaces the built-in English text of every component. Pass only the keys\n * you want to change; the rest stay in English. Components already on the page\n * update at once.\n *\n * With a language code, the strings apply where the nearest `lang` attribute\n * matches it (`'pt'` also covers `pt-BR`), so a page can switch language by\n * changing `<html lang>`, or mix languages by section. Without one, they apply\n * everywhere no registered language matches.\n *\n * @example setTranslations({ close: 'Chiudi', page: 'Pagina {page}' }, 'it')\n */\nexport function setTranslations(translations: Partial<Translations>, lang = ''): void {\n const key = lang.toLowerCase();\n registered.set(key, { ...registered.get(key), ...translations });\n refreshAll();\n}\n\n/** Forgets every registered translation. For tests. */\nexport function resetTranslations(): void {\n registered.clear();\n refreshAll();\n}\n\n/** The `lang` that applies to an element: the nearest one, across shadow roots. */\nfunction langOf(element: Element): string {\n let node: Element | null = element;\n while (node) {\n const lang = node.closest('[lang]')?.getAttribute('lang');\n if (lang) return lang.toLowerCase();\n const root = node.getRootNode();\n node = root instanceof ShadowRoot ? root.host : null;\n }\n return '';\n}\n\n/** The text for a key: the element's language, then its base language, then the default, then English. */\nfunction lookup(element: Element, key: keyof Translations): string {\n const lang = langOf(element);\n const candidates = lang ? [lang, lang.split('-')[0], ''] : [''];\n for (const candidate of candidates) {\n const value = registered.get(candidate)?.[key];\n if (value) return value;\n }\n return english[key];\n}\n\n/**\n * Gives a component its built-in text, and re-renders it when translations or\n * the page's `lang` change.\n */\nexport class Translator implements ReactiveController {\n readonly #host: ReactiveControllerHost & HTMLElement;\n\n constructor(host: ReactiveControllerHost & HTMLElement) {\n this.#host = host;\n host.addController(this);\n }\n\n /** The translated text, with `{name}` placeholders filled in. */\n t(key: keyof Translations, values: Record<string, string | number> = {}): string {\n return lookup(this.#host, key).replace(/\\{(\\w+)\\}/g, (match, name: string) => (name in values ? String(values[name]) : match));\n }\n\n hostConnected(): void {\n hosts.add(this.#host);\n if (!langObserver && typeof MutationObserver !== 'undefined') {\n // One observer for the whole document: a `lang` change anywhere re-renders the components.\n langObserver = new MutationObserver(refreshAll);\n langObserver.observe(document.documentElement, { attributes: true, attributeFilter: ['lang'], subtree: true });\n }\n }\n\n /** The language that applies to the component, from the nearest `lang` attribute ('' when none). */\n get lang(): string {\n return langOf(this.#host);\n }\n\n hostDisconnected(): void {\n hosts.delete(this.#host);\n }\n}\n",
|
|
832
|
+
"internal/i18n.ts": "import type { ReactiveController, ReactiveControllerHost } from 'lit';\n\n/** Every built-in text, by key. `{page}` is replaced with the page number. */\nexport interface Translations {\n /** Dialog and alert: the close button's accessible name. */\n close: string;\n /** Toast: the dismiss button's accessible name. */\n dismiss: string;\n /** Toaster: the notification region's accessible name, unless `label` is set. */\n notifications: string;\n /** Combobox: the arrow button's accessible name. */\n showOptions: string;\n /** Combobox: shown when the search matches nothing. */\n noResults: string;\n /** Combobox: error when required and empty. */\n selectItem: string;\n /** Combobox: announced while typing when one option matches. */\n oneResult: string;\n /** Combobox: announced while typing; `{count}` is the number of matches. */\n results: `${string}{count}${string}`;\n /** Radio group: error when required and empty. */\n selectOption: string;\n /** Pagination: the navigation's accessible name, unless `label` is set. */\n pagination: string;\n /** Pagination: the previous button's accessible name. */\n previousPage: string;\n /** Pagination: the next button's accessible name. */\n nextPage: string;\n /** Pagination: a page button's accessible name. Must contain `{page}`. */\n page: `${string}{page}${string}`;\n /** Table: shown when there are no rows, unless the `empty` slot is used. */\n noData: string;\n /** Form controls: error for an invalid value that has no message of its own. */\n invalidValue: string;\n /** Date picker: the calendar button's accessible name. */\n chooseDate: string;\n /** Calendar: the previous month button's accessible name. */\n previousMonth: string;\n /** Calendar: the next month button's accessible name. */\n nextMonth: string;\n /** Date picker: error for text that isn't a date; `{example}` is a date in the expected format. */\n invalidDate: `${string}{example}${string}`;\n /** Date picker: error for a date before `min`; `{date}` is the minimum. */\n dateTooEarly: `${string}{date}${string}`;\n /** Date picker: error for a date after `max`; `{date}` is the maximum. */\n dateTooLate: `${string}{date}${string}`;\n /** Date picker: error for a date that `isDateDisabled` rules out. */\n dateUnavailable: string;\n /** Date picker: placeholder letters for day, month and year, in the language's date order. */\n dayPlaceholder: string;\n monthPlaceholder: string;\n yearPlaceholder: string;\n /** Progress: the bar's accessible name, unless `label` is set. */\n progress: string;\n /** Spinner: its accessible name, unless `label` is set. */\n loading: string;\n /** Breadcrumbs: the navigation's accessible name, unless `label` is set. */\n breadcrumb: string;\n /** File upload: the button, with `multiple`. */\n chooseFiles: string;\n /** File upload: the button, for one file. */\n chooseFile: string;\n /** File upload: next to the button, with `multiple`. */\n dropFiles: string;\n /** File upload: next to the button, for one file. */\n dropFile: string;\n /** File upload: a file's remove button. Must contain `{name}`. */\n removeFile: `${string}{name}${string}`;\n /** File upload: a file over `max-size`. Must contain `{name}`, then `{size}`. */\n fileTooLarge: `${string}{name}${string}{size}${string}`;\n /** File upload: a file `accept` rules out. Must contain `{name}`. */\n fileTypeRejected: `${string}{name}${string}`;\n /** Date range picker: the calendar button's accessible name, and the popup's without a `label`. */\n chooseDates: string;\n /** Date range picker: the start input's accessible name, after the label. */\n startDate: string;\n /** Date range picker: the end input's accessible name, after the label. */\n endDate: string;\n /** Date range picker: error when only one of the two dates is set. */\n rangeIncomplete: string;\n /** Date range picker: error when the end date is before the start date. */\n endBeforeStart: string;\n /** Number input: the minus button's accessible name. */\n decrease: string;\n /** Number input: the plus button's accessible name. */\n increase: string;\n /** Multi-select: a chip's remove button. Must contain `{name}`. */\n removeOption: `${string}{name}${string}`;\n}\n\nconst english: Translations = {\n close: 'Close',\n dismiss: 'Dismiss',\n notifications: 'Notifications',\n showOptions: 'Show options',\n noResults: 'No results',\n selectItem: 'Please select an item in the list.',\n oneResult: '1 result',\n results: '{count} results',\n selectOption: 'Please select one of these options.',\n pagination: 'Pagination',\n previousPage: 'Previous page',\n nextPage: 'Next page',\n page: 'Page {page}',\n noData: 'No data',\n invalidValue: 'Invalid value',\n chooseDate: 'Choose date',\n previousMonth: 'Previous month',\n nextMonth: 'Next month',\n invalidDate: 'Enter a date like {example}.',\n dateTooEarly: 'Choose {date} or later.',\n dateTooLate: 'Choose {date} or earlier.',\n dateUnavailable: 'This date is not available.',\n dayPlaceholder: 'dd',\n monthPlaceholder: 'mm',\n yearPlaceholder: 'yyyy',\n progress: 'Progress',\n loading: 'Loading',\n breadcrumb: 'Breadcrumb',\n chooseFiles: 'Choose files',\n chooseFile: 'Choose a file',\n dropFiles: 'or drag them here',\n dropFile: 'or drag it here',\n removeFile: 'Remove {name}',\n fileTooLarge: '{name} is larger than {size}.',\n fileTypeRejected: \"{name} isn't an accepted file type.\",\n chooseDates: 'Choose dates',\n startDate: 'Start date',\n endDate: 'End date',\n rangeIncomplete: 'Enter both a start and an end date.',\n endBeforeStart: \"The end date can't be before the start date.\",\n decrease: 'Decrease',\n increase: 'Increase',\n removeOption: 'Remove {name}',\n};\n\n/** Registered translations by lowercase language code; '' applies to every language. */\nconst registered = new Map<string, Partial<Translations>>();\nconst hosts = new Set<ReactiveControllerHost>();\nlet langObserver: MutationObserver | undefined;\n\nconst refreshAll = () => hosts.forEach((host) => host.requestUpdate());\n\n/**\n * Replaces the built-in English text of every component. Pass only the keys\n * you want to change; the rest stay in English. Components already on the page\n * update at once.\n *\n * With a language code, the strings apply where the nearest `lang` attribute\n * matches it (`'pt'` also covers `pt-BR`), so a page can switch language by\n * changing `<html lang>`, or mix languages by section. Without one, they apply\n * everywhere no registered language matches.\n *\n * @example setTranslations({ close: 'Chiudi', page: 'Pagina {page}' }, 'it')\n */\nexport function setTranslations(translations: Partial<Translations>, lang = ''): void {\n const key = lang.toLowerCase();\n registered.set(key, { ...registered.get(key), ...translations });\n refreshAll();\n}\n\n/** Forgets every registered translation. For tests. */\nexport function resetTranslations(): void {\n registered.clear();\n refreshAll();\n}\n\n/** The `lang` that applies to an element: the nearest one, across shadow roots. */\nfunction langOf(element: Element): string {\n let node: Element | null = element;\n while (node) {\n const lang = node.closest('[lang]')?.getAttribute('lang');\n if (lang) return lang.toLowerCase();\n const root = node.getRootNode();\n node = root instanceof ShadowRoot ? root.host : null;\n }\n return '';\n}\n\n/** The text for a key: the element's language, then its base language, then the default, then English. */\nfunction lookup(element: Element, key: keyof Translations): string {\n const lang = langOf(element);\n const candidates = lang ? [lang, lang.split('-')[0], ''] : [''];\n for (const candidate of candidates) {\n const value = registered.get(candidate)?.[key];\n if (value) return value;\n }\n return english[key];\n}\n\n/**\n * Gives a component its built-in text, and re-renders it when translations or\n * the page's `lang` change.\n */\nexport class Translator implements ReactiveController {\n readonly #host: ReactiveControllerHost & HTMLElement;\n\n constructor(host: ReactiveControllerHost & HTMLElement) {\n this.#host = host;\n host.addController(this);\n }\n\n /** The translated text, with `{name}` placeholders filled in. */\n t(key: keyof Translations, values: Record<string, string | number> = {}): string {\n return lookup(this.#host, key).replace(/\\{(\\w+)\\}/g, (match, name: string) => (name in values ? String(values[name]) : match));\n }\n\n hostConnected(): void {\n hosts.add(this.#host);\n if (!langObserver && typeof MutationObserver !== 'undefined') {\n // One observer for the whole document: a `lang` change anywhere re-renders the components.\n langObserver = new MutationObserver(refreshAll);\n langObserver.observe(document.documentElement, { attributes: true, attributeFilter: ['lang'], subtree: true });\n }\n }\n\n /** The language that applies to the component, from the nearest `lang` attribute ('' when none). */\n get lang(): string {\n return langOf(this.#host);\n }\n\n hostDisconnected(): void {\n hosts.delete(this.#host);\n }\n}\n",
|
|
766
833
|
"internal/slot.ts": "import type { ReactiveController, ReactiveControllerHost } from 'lit';\n\n/** Re-renders the host when the content of the given named slots changes. */\nexport class HasSlotController implements ReactiveController {\n readonly #host: ReactiveControllerHost & HTMLElement;\n readonly #names: string[];\n\n constructor(host: ReactiveControllerHost & HTMLElement, ...names: string[]) {\n this.#host = host;\n this.#names = names;\n host.addController(this);\n }\n\n /** True when a direct child is assigned to the named slot. */\n has(name: string): boolean {\n return [...this.#host.children].some((child) => child.getAttribute('slot') === name);\n }\n\n hostConnected(): void {\n this.#host.shadowRoot?.addEventListener('slotchange', this.#onSlotChange);\n }\n\n hostDisconnected(): void {\n this.#host.shadowRoot?.removeEventListener('slotchange', this.#onSlotChange);\n }\n\n #onSlotChange = (event: Event): void => {\n const slot = event.target as HTMLSlotElement;\n if (this.#names.includes(slot.name)) this.#host.requestUpdate();\n };\n}\n\nlet counter = 0;\n\n/** A document-unique id, for ARIA references within one tree. */\nexport function uniqueId(prefix = 'uf'): string {\n counter += 1;\n return `${prefix}-${counter}`;\n}\n",
|
|
767
834
|
"components/avatar/avatar.ts": "import { LitElement, css, html, nothing, type PropertyDeclarations, type PropertyValues } from 'lit';\nimport { defineElement } from '../../internal/define.js';\nimport { iconSvg, icons } from '../../internal/icons.js';\nimport { hostStyles } from '../../internal/shared.styles.js';\n\nexport type AvatarSize = 'sm' | 'md' | 'lg' | 'xl';\nexport type AvatarShape = 'circle' | 'square';\n\n/** \"John Smith\" -> \"JS\", \"john\" -> \"J\". */\nfunction initialsOf(name: string): string {\n const words = name.trim().split(/\\s+/).filter(Boolean);\n const letters = words.length > 1 ? [words[0], words[words.length - 1]] : words;\n return letters.map((w) => [...w][0]?.toUpperCase() ?? '').join('');\n}\n\n/**\n * A picture of a person or an entity. Shows the image when it loads, the\n * initials of `name` when there's no image or it fails, and a generic icon\n * when there's neither.\n *\n * `name` is also the accessible name. When the name is already written next\n * to the avatar, set `decorative` so screen readers don't read it twice.\n *\n * @summary Shows a person's picture, initials or icon.\n * @tag uf-avatar\n *\n * @slot - Custom content instead of the initials or icon, e.g. an `<uf-icon>`.\n *\n * @csspart base - The avatar.\n * @csspart image - The `<img>`.\n * @csspart initials - The initials.\n * @csspart icon - The fallback icon.\n *\n * @cssprop --uf-avatar-size - Width and height. Overrides `size`.\n * @cssprop --uf-avatar-bg - Background behind initials and icon.\n * @cssprop --uf-avatar-color - Color of the initials and icon.\n * @cssprop --uf-avatar-radius - Corner radius. Overrides `shape`.\n */\nexport class UfAvatar extends LitElement {\n static override styles = [\n hostStyles,\n css`\n :host {\n display: inline-flex;\n vertical-align: middle;\n --_size: 2.5rem;\n --_radius: 50%;\n }\n\n :host([size='sm']) {\n --_size: 2rem;\n }\n :host([size='lg']) {\n --_size: 3rem;\n }\n :host([size='xl']) {\n --_size: 4rem;\n }\n :host([shape='square']) {\n --_radius: var(--uf-radius-md);\n }\n\n .base {\n position: relative;\n display: inline-grid;\n place-items: center;\n width: var(--uf-avatar-size, var(--_size));\n height: var(--uf-avatar-size, var(--_size));\n overflow: hidden;\n border-radius: var(--uf-avatar-radius, var(--_radius));\n background: var(--uf-avatar-bg, var(--uf-color-accent-tint));\n color: var(--uf-avatar-color, var(--uf-color-on-accent-tint));\n font-family: var(--uf-font-family-sans);\n /* Initials scale with the avatar. */\n font-size: calc(var(--uf-avatar-size, var(--_size)) * 0.4);\n font-weight: var(--uf-font-weight-semibold);\n line-height: 1;\n user-select: none;\n }\n\n .image {\n width: 100%;\n height: 100%;\n object-fit: cover;\n }\n\n .icon {\n width: 60%;\n height: 60%;\n }\n\n ::slotted(*) {\n font-size: inherit;\n }\n `,\n ];\n\n static override properties: PropertyDeclarations = {\n src: {},\n name: {},\n initials: {},\n size: { reflect: true },\n shape: { reflect: true },\n decorative: { type: Boolean },\n loading: {},\n };\n\n /** Image URL. */\n declare src: string | undefined;\n /** The person's or entity's name: the accessible name, and the source of the initials. */\n declare name: string | undefined;\n /** Initials to show instead of the ones taken from `name`. */\n declare initials: string | undefined;\n /** Size: `sm`, `md`, `lg` or `xl`. */\n declare size: AvatarSize;\n /** `circle` or `square` (rounded corners). */\n declare shape: AvatarShape;\n /** Hides the avatar from assistive tech, when the name is already shown next to it. */\n declare decorative: boolean;\n /** The image's `loading` attribute: `lazy` waits until it's near the viewport. */\n declare loading: 'eager' | 'lazy';\n\n /** The image failed to load: show the fallback. */\n #failed = false;\n\n constructor() {\n super();\n this.size = 'md';\n this.shape = 'circle';\n this.decorative = false;\n this.loading = 'eager';\n }\n\n override willUpdate(changed: PropertyValues<this>): void {\n // A new image gets a new chance to load.\n if (changed.has('src')) this.#failed = false;\n }\n\n override render() {\n const showImage = Boolean(this.src) && !this.#failed;\n const initials = this.initials ?? (this.name ? initialsOf(this.name) : '');\n const labelled = !this.decorative && Boolean(this.name);\n\n return html`<span\n class=\"base\"\n part=\"base\"\n role=${labelled ? 'img' : nothing}\n aria-label=${labelled ? this.name! : nothing}\n aria-hidden=${labelled ? nothing : 'true'}\n >\n ${showImage\n ? html`<img\n class=\"image\"\n part=\"image\"\n src=${this.src!}\n alt=\"\"\n loading=${this.loading}\n @error=${() => {\n this.#failed = true;\n this.requestUpdate();\n }}\n />`\n : html`<slot>\n ${initials\n ? html`<span part=\"initials\">${initials}</span>`\n : iconSvg(icons.user)}\n </slot>`}\n </span>`;\n }\n}\n\ndefineElement('uf-avatar', UfAvatar);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'uf-avatar': UfAvatar;\n }\n}\n",
|
|
768
835
|
"components/badge/badge.ts": "import { LitElement, css, html, type PropertyDeclarations } from 'lit';\nimport { defineElement } from '../../internal/define.js';\nimport { hostStyles } from '../../internal/shared.styles.js';\n\nexport type BadgeVariant = 'neutral' | 'accent' | 'info' | 'success' | 'warning' | 'danger';\nexport type BadgeAppearance = 'soft' | 'solid' | 'outline';\nexport type BadgeSize = 'sm' | 'md' | 'lg';\n\n/**\n * A short label for a status, a category or a count. It's plain text for\n * assistive tech: write text that makes sense out of context (\"3 unread\", not\n * just \"3\"), or describe it in the surrounding element's label.\n *\n * @summary Labels a status, a category or a count.\n * @tag uf-badge\n *\n * @slot - The badge text.\n * @slot prefix - An icon before the text.\n *\n * @csspart base - The badge.\n * @csspart dot - The status dot, when `dot` is set.\n *\n * @cssprop --uf-badge-bg - Background color.\n * @cssprop --uf-badge-color - Text color.\n * @cssprop --uf-badge-border-color - Border color.\n * @cssprop --uf-badge-radius - Corner radius. Use `999px` for a pill.\n */\nexport class UfBadge extends LitElement {\n static override styles = [\n hostStyles,\n css`\n :host {\n display: inline-flex;\n vertical-align: middle;\n --_bg: var(--uf-color-surface-hover);\n --_fg: var(--uf-color-text);\n --_border: transparent;\n }\n\n .base {\n display: inline-flex;\n align-items: center;\n gap: 0.375em;\n min-height: 1.5rem;\n padding: 0 var(--uf-space-2);\n border: 1px solid var(--uf-badge-border-color, var(--_border));\n border-radius: var(--uf-badge-radius, var(--uf-radius-sm));\n background: var(--uf-badge-bg, var(--_bg));\n color: var(--uf-badge-color, var(--_fg));\n font-family: var(--uf-font-family-sans);\n font-size: var(--uf-font-size-sm);\n font-weight: var(--uf-font-weight-medium);\n line-height: 1;\n white-space: nowrap;\n }\n\n :host([size='sm']) .base {\n min-height: 1.25rem;\n padding: 0 var(--uf-space-1);\n font-size: 0.75rem;\n }\n\n :host([size='lg']) .base {\n min-height: 1.75rem;\n padding: 0 var(--uf-space-3);\n font-size: var(--uf-font-size-md);\n }\n\n .dot {\n width: 0.5em;\n height: 0.5em;\n border-radius: 50%;\n background: currentColor;\n }\n\n ::slotted([slot='prefix']) {\n display: inline-flex;\n font-size: 1.1em;\n }\n\n /* Soft (default): a subtle background with strong text. */\n :host([variant='accent']) {\n --_bg: var(--uf-color-accent-tint);\n --_fg: var(--uf-color-on-accent-tint);\n }\n :host([variant='info']) {\n --_bg: var(--uf-color-info-subtle);\n --_fg: var(--uf-color-info);\n }\n :host([variant='success']) {\n --_bg: var(--uf-color-success-subtle);\n --_fg: var(--uf-color-success);\n }\n :host([variant='warning']) {\n --_bg: var(--uf-color-warning-subtle);\n --_fg: var(--uf-color-warning);\n }\n :host([variant='danger']) {\n --_bg: var(--uf-color-danger-subtle);\n --_fg: var(--uf-color-danger-text);\n }\n\n /* Solid: the bold colors of toasts. */\n :host([appearance='solid']) {\n --_bg: var(--uf-color-toast-neutral-bg);\n --_fg: var(--uf-color-toast-neutral-text);\n }\n :host([appearance='solid'][variant='accent']) {\n --_bg: var(--uf-color-accent);\n --_fg: var(--uf-color-on-accent);\n }\n :host([appearance='solid'][variant='info']) {\n --_bg: var(--uf-color-toast-info-bg);\n --_fg: var(--uf-color-toast-info-text);\n }\n :host([appearance='solid'][variant='success']) {\n --_bg: var(--uf-color-toast-success-bg);\n --_fg: var(--uf-color-toast-success-text);\n }\n :host([appearance='solid'][variant='warning']) {\n --_bg: var(--uf-color-toast-warning-bg);\n --_fg: var(--uf-color-toast-warning-text);\n }\n :host([appearance='solid'][variant='danger']) {\n --_bg: var(--uf-color-toast-danger-bg);\n --_fg: var(--uf-color-toast-danger-text);\n }\n\n /* Outline: no fill, the text color as border. */\n :host([appearance='outline']) {\n --_bg: transparent;\n --_border: currentColor;\n }\n :host([appearance='outline'][variant='neutral']) {\n --_border: var(--uf-color-border-strong);\n }\n :host([appearance='outline'][variant='accent']) {\n --_fg: var(--uf-color-accent-strong);\n }\n `,\n ];\n\n static override properties: PropertyDeclarations = {\n variant: { reflect: true },\n appearance: { reflect: true },\n size: { reflect: true },\n dot: { type: Boolean, reflect: true },\n };\n\n /** Color, by meaning: `neutral`, `accent`, `info`, `success`, `warning` or `danger`. */\n declare variant: BadgeVariant;\n /** `soft` (tinted background), `solid` (bold background) or `outline` (border only). */\n declare appearance: BadgeAppearance;\n /** Size: `sm`, `md` or `lg`. */\n declare size: BadgeSize;\n /** Shows a status dot before the text. */\n declare dot: boolean;\n\n constructor() {\n super();\n this.variant = 'neutral';\n this.appearance = 'soft';\n this.size = 'md';\n this.dot = false;\n }\n\n override render() {\n return html`<span class=\"base\" part=\"base\">\n ${this.dot ? html`<span class=\"dot\" part=\"dot\" aria-hidden=\"true\"></span>` : null}\n <slot name=\"prefix\"></slot>\n <slot></slot>\n </span>`;\n }\n}\n\ndefineElement('uf-badge', UfBadge);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'uf-badge': UfBadge;\n }\n}\n",
|
|
@@ -788,18 +855,21 @@
|
|
|
788
855
|
"components/divider/divider.ts": "import { LitElement, css, html, type PropertyDeclarations } from 'lit';\nimport { defineElement } from '../../internal/define.js';\nimport { hostStyles } from '../../internal/shared.styles.js';\nimport { HasSlotController } from '../../internal/slot.js';\n\nexport type DividerOrientation = 'horizontal' | 'vertical';\n\n/**\n * A line between groups of content, across or beside them. Assistive tech\n * announces it as a separator. With a label (\"or\"), the label is read as plain\n * text and the line around it is decorative.\n *\n * @summary Separates groups of content with a line.\n * @tag uf-divider\n *\n * @slot - An optional label in the middle of the line, like \"or\".\n *\n * @csspart base - The line, or the wrapper around a labelled one.\n * @csspart label - The label.\n *\n * @cssprop --uf-divider-color - Color of the line.\n * @cssprop --uf-divider-width - Thickness of the line.\n * @cssprop --uf-divider-spacing - Space before and after the line.\n */\nexport class UfDivider extends LitElement {\n static override styles = [\n hostStyles,\n css`\n :host {\n --_color: var(--uf-divider-color, var(--uf-color-border));\n --_width: var(--uf-divider-width, 1px);\n --_spacing: var(--uf-divider-spacing, var(--uf-space-4));\n display: block;\n margin-block: var(--_spacing);\n }\n\n :host([orientation='vertical']) {\n display: inline-flex;\n align-self: stretch;\n min-height: 1em;\n margin-block: 0;\n margin-inline: var(--_spacing);\n vertical-align: middle;\n }\n\n .base {\n display: flex;\n align-items: center;\n gap: var(--uf-space-3);\n height: 100%;\n color: var(--uf-color-text-muted);\n font-family: var(--uf-font-family-sans);\n font-size: var(--uf-font-size-sm);\n }\n\n :host([orientation='vertical']) .base {\n flex-direction: column;\n }\n\n .line {\n flex: 1;\n border-top: var(--_width) solid var(--_color);\n }\n\n :host([orientation='vertical']) .line {\n border-top: 0;\n border-inline-start: var(--_width) solid var(--_color);\n }\n\n .label {\n flex: none;\n }\n\n [hidden] {\n display: none !important;\n }\n `,\n ];\n\n static override properties: PropertyDeclarations = {\n orientation: { reflect: true },\n };\n\n /** `horizontal` (across the content) or `vertical` (between items in a row). */\n declare orientation: DividerOrientation;\n\n constructor() {\n super();\n this.orientation = 'horizontal';\n // Re-renders when a label is added or removed.\n new HasSlotController(this, '');\n }\n\n override render() {\n // A separator's content isn't read, so a labelled divider is plain text between two decorative lines.\n const labelled = [...this.childNodes].some((n) => (n.nodeType === Node.ELEMENT_NODE ? !(n as Element).slot : n.textContent?.trim()));\n return labelled\n ? html`<div class=\"base\" part=\"base\">\n <span class=\"line\" aria-hidden=\"true\"></span>\n <span class=\"label\" part=\"label\"><slot></slot></span>\n <span class=\"line\" aria-hidden=\"true\"></span>\n </div>`\n : html`<div class=\"base\" part=\"base\" role=\"separator\" aria-orientation=${this.orientation}>\n <span class=\"line\"></span>\n <slot hidden></slot>\n </div>`;\n }\n}\n\ndefineElement('uf-divider', UfDivider);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'uf-divider': UfDivider;\n }\n}\n",
|
|
789
856
|
"components/drawer/drawer.ts": "import { css, type PropertyDeclarations } from 'lit';\nimport { defineElement } from '../../internal/define.js';\nimport { UfDialog } from '../dialog/dialog.js';\n\nexport type DrawerPlacement = 'start' | 'end' | 'top' | 'bottom';\n\n/**\n * A panel that slides in from an edge of the screen, for navigation, filters or\n * details. It is a modal dialog, so it behaves like `<uf-dialog>`: it traps\n * focus, makes the page inert, closes with Escape, and returns focus to the\n * opener. Any element inside with `data-dialog=\"close\"` closes it.\n *\n * @summary A panel that slides in from an edge of the screen.\n * @tag uf-drawer\n *\n * @slot - The drawer content.\n * @slot label - The title, when you need markup. Overrides `label`.\n * @slot header-actions - Extra buttons next to the close button.\n * @slot footer - Actions at the bottom, usually buttons.\n *\n * @event uf-show - The drawer opened.\n * @event uf-hide - The drawer closed.\n * @event {CustomEvent<DialogRequestCloseDetail>} uf-request-close - The user tried to close the drawer. Call `preventDefault()` to keep it open.\n *\n * @csspart dialog - The native `<dialog>`.\n * @csspart header - The header with title and close button.\n * @csspart title - The title.\n * @csspart close-button - The close button.\n * @csspart body - The content area.\n * @csspart footer - The footer.\n *\n * @cssprop --uf-drawer-size - Width of a side drawer, or height of a top or bottom one. Defaults to `24rem`.\n * @cssprop --uf-drawer-radius - Corner radius of the corners on the open side; the side against the screen edge stays square.\n * @cssprop --uf-dialog-bg - Background of the drawer.\n * @cssprop --uf-dialog-padding - Padding of header, body and footer.\n * @cssprop --uf-dialog-backdrop - Backdrop color.\n */\nexport class UfDrawer extends UfDialog {\n static override styles = [\n ...UfDialog.styles,\n css`\n dialog {\n --_size: min(var(--uf-drawer-size, 24rem), 100vw);\n --_radius: var(--uf-drawer-radius, var(--uf-radius-md));\n --_from: 100% 0;\n position: fixed;\n inset: 0 0 0 auto;\n width: var(--_size);\n max-width: 100vw;\n height: 100dvh;\n max-height: 100dvh;\n margin: 0;\n border-width: 0 0 0 1px;\n border-radius: var(--_radius) 0 0 var(--_radius);\n /* Even on every side: the dialog's shadow falls downward, too far below a top drawer and off screen for a bottom one. */\n box-shadow: var(--uf-shadow-drawer);\n }\n\n :host([placement='start']) dialog {\n --_from: -100% 0;\n inset: 0 auto 0 0;\n border-width: 0 1px 0 0;\n border-radius: 0 var(--_radius) var(--_radius) 0;\n }\n\n /* Right-to-left pages: start is on the right, end on the left. */\n :host(:dir(rtl)) dialog {\n --_from: -100% 0;\n inset: 0 auto 0 0;\n border-width: 0 1px 0 0;\n border-radius: 0 var(--_radius) var(--_radius) 0;\n }\n\n :host(:dir(rtl)[placement='start']) dialog {\n --_from: 100% 0;\n inset: 0 0 0 auto;\n border-width: 0 0 0 1px;\n border-radius: var(--_radius) 0 0 var(--_radius);\n }\n\n :host([placement='top']) dialog,\n :host([placement='bottom']) dialog {\n --_size: min(var(--uf-drawer-size, 24rem), 100dvh);\n width: 100vw;\n height: var(--_size);\n }\n\n :host([placement='top']) dialog {\n --_from: 0 -100%;\n inset: 0 0 auto 0;\n border-width: 0 0 1px 0;\n border-radius: 0 0 var(--_radius) var(--_radius);\n }\n\n :host([placement='bottom']) dialog {\n --_from: 0 100%;\n inset: auto 0 0 0;\n border-width: 1px 0 0 0;\n border-radius: var(--_radius) var(--_radius) 0 0;\n }\n\n dialog[open] {\n animation-name: uf-drawer-in;\n }\n\n dialog.closing {\n animation-name: uf-drawer-out;\n }\n\n @keyframes uf-drawer-in {\n from {\n translate: var(--_from);\n }\n }\n\n @keyframes uf-drawer-out {\n to {\n translate: var(--_from);\n }\n }\n `,\n ];\n\n static override properties: PropertyDeclarations = {\n placement: { reflect: true },\n };\n\n /** The edge it slides in from: `start` (left, in left-to-right pages), `end`, `top` or `bottom`. */\n declare placement: DrawerPlacement;\n\n constructor() {\n super();\n this.placement = 'end';\n }\n}\n\ndefineElement('uf-drawer', UfDrawer);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'uf-drawer': UfDrawer;\n }\n}\n",
|
|
790
857
|
"components/dropdown/dropdown.ts": "import { css } from 'lit';\nimport { defineElement } from '../../internal/define.js';\nimport { UfPopover } from '../popover/popover.js';\nimport '../menu/menu.js';\nimport type { MenuSelectDetail, UfMenu } from '../menu/menu.js';\n\nexport { UfMenu, UfMenuItem } from '../menu/menu.js';\nexport type { MenuSelectDetail } from '../menu/menu.js';\n\n/**\n * A button that opens a `<uf-menu>`, following the WAI-ARIA menu button\n * pattern: Enter, Space or Down open it on the first item, Up on the last;\n * choosing an item or pressing Escape closes it and returns focus to the button.\n *\n * @summary Opens a menu of actions from a button.\n * @tag uf-dropdown\n *\n * @slot trigger - The button that opens the menu.\n * @slot - A `<uf-menu>`.\n *\n * @event {CustomEvent<MenuSelectDetail>} uf-select - An item was chosen (bubbles up from the menu).\n * @event uf-show - The menu opened.\n * @event uf-hide - The menu closed.\n *\n * @csspart panel - The floating panel around the menu.\n */\nexport class UfDropdown extends UfPopover {\n static override styles = [\n UfPopover.styles,\n css`\n .panel {\n --uf-popover-padding: var(--uf-space-1) 0;\n }\n `,\n ];\n\n #focusLastOnOpen = false;\n\n constructor() {\n super();\n this.addEventListener('uf-select', this.#onSelect as EventListener);\n this.addEventListener('keydown', this.#onKeyDown);\n }\n\n protected override get popupKind(): 'menu' {\n return 'menu';\n }\n\n get #menu(): UfMenu | null {\n return this.querySelector('uf-menu');\n }\n\n protected override afterShow(): void {\n const menu = this.#menu;\n if (this.#focusLastOnOpen) menu?.focusLast();\n else menu?.focusFirst();\n this.#focusLastOnOpen = false;\n }\n\n protected override onTriggerKeyDown(event: KeyboardEvent): void {\n if (event.key !== 'ArrowDown' && event.key !== 'ArrowUp') return;\n event.preventDefault();\n this.#focusLastOnOpen = event.key === 'ArrowUp';\n if (this.open) this.afterShow();\n else this.show();\n }\n\n #onSelect = (event: CustomEvent<MenuSelectDetail>): void => {\n // Checkbox items stay open so several can be toggled; cancel the event to keep any item open.\n if (event.defaultPrevented || event.detail.item.type === 'checkbox') return;\n this.hide();\n this.trigger?.focus();\n };\n\n #onKeyDown = (event: KeyboardEvent): void => {\n // Tab leaves the menu: close it and let focus move on.\n if (event.key === 'Tab' && this.open && this.focusInPanel) this.hide();\n };\n}\n\ndefineElement('uf-dropdown', UfDropdown);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'uf-dropdown': UfDropdown;\n }\n}\n",
|
|
858
|
+
"components/empty-state/empty-state.ts": "import { LitElement, css, html, nothing, type PropertyDeclarations } from 'lit';\nimport { defineElement } from '../../internal/define.js';\nimport { hostStyles } from '../../internal/shared.styles.js';\nimport { HasSlotController } from '../../internal/slot.js';\nimport '../icon/icon.js';\n\n/**\n * What to show where content would be: an empty list, no search results, a\n * first visit. An icon, a heading, a short explanation and what to do next.\n *\n * The `heading` attribute is bold text. For a real heading in the page's\n * outline, put an `<h2>` or `<h3>` in the `heading` slot.\n *\n * @summary Fills an empty list or page with a message and what to do next.\n * @tag uf-empty-state\n *\n * @slot - The explanation.\n * @slot heading - The heading, when you need markup or a heading level. Overrides `heading`.\n * @slot icon - Replaces the icon.\n * @slot actions - Buttons or links, like \"Create a project\".\n *\n * @csspart base - The empty state.\n * @csspart icon - The icon.\n * @csspart heading - The heading.\n * @csspart description - The explanation.\n * @csspart actions - The wrapper around the actions.\n *\n * @cssprop --uf-empty-state-icon-size - Size of the icon.\n * @cssprop --uf-empty-state-icon-color - Color of the icon.\n * @cssprop --uf-empty-state-padding - Space around the content.\n */\nexport class UfEmptyState extends LitElement {\n static override styles = [\n hostStyles,\n css`\n :host {\n display: block;\n }\n\n .base {\n display: flex;\n flex-direction: column;\n align-items: center;\n gap: var(--uf-space-2);\n max-width: 28rem;\n margin-inline: auto;\n padding: var(--uf-empty-state-padding, var(--uf-space-6) var(--uf-space-4));\n color: var(--uf-color-text-muted);\n font-family: var(--uf-font-family-sans);\n font-size: var(--uf-font-size-md);\n line-height: 1.5;\n text-align: center;\n }\n\n .icon {\n display: inline-flex;\n margin-bottom: var(--uf-space-2);\n color: var(--uf-empty-state-icon-color, var(--uf-color-accent));\n font-size: var(--uf-empty-state-icon-size, 2.5rem);\n }\n\n .icon uf-icon,\n ::slotted([slot='icon']) {\n --uf-icon-size: 1em;\n width: 1em;\n height: 1em;\n }\n\n .heading {\n color: var(--uf-color-text);\n font-size: var(--uf-font-size-lg);\n font-weight: var(--uf-font-weight-semibold);\n }\n\n /* A heading element in the slot: the same look, without its default margins. */\n ::slotted([slot='heading']) {\n margin: 0;\n font: inherit;\n }\n\n .actions {\n display: flex;\n flex-wrap: wrap;\n justify-content: center;\n gap: var(--uf-space-2);\n margin-top: var(--uf-space-3);\n }\n\n [hidden] {\n display: none !important;\n }\n `,\n ];\n\n static override properties: PropertyDeclarations = {\n heading: {},\n icon: {},\n };\n\n /** Bold text above the explanation. */\n declare heading: string | undefined;\n /** A built-in or registered icon name. An empty string hides the icon. */\n declare icon: string;\n\n readonly #slots = new HasSlotController(this, 'heading', 'icon', 'actions');\n\n constructor() {\n super();\n this.icon = 'inbox';\n }\n\n override render() {\n const hasIcon = Boolean(this.icon) || this.#slots.has('icon');\n const hasHeading = Boolean(this.heading) || this.#slots.has('heading');\n return html`\n <div class=\"base\" part=\"base\">\n <span class=\"icon\" part=\"icon\" aria-hidden=\"true\" ?hidden=${!hasIcon}>\n <slot name=\"icon\">${this.icon ? html`<uf-icon name=${this.icon}></uf-icon>` : nothing}</slot>\n </span>\n <div class=\"heading\" part=\"heading\" ?hidden=${!hasHeading}><slot name=\"heading\">${this.heading ?? nothing}</slot></div>\n <div class=\"description\" part=\"description\"><slot></slot></div>\n <div class=\"actions\" part=\"actions\" ?hidden=${!this.#slots.has('actions')}><slot name=\"actions\"></slot></div>\n </div>\n `;\n }\n}\n\ndefineElement('uf-empty-state', UfEmptyState);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'uf-empty-state': UfEmptyState;\n }\n}\n",
|
|
791
859
|
"components/file-upload/file-upload.ts": "import { css, html, nothing, type PropertyDeclarations, type PropertyValues } from 'lit';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { ifDefined } from 'lit/directives/if-defined.js';\nimport { defineElement } from '../../internal/define.js';\nimport { describedBy, fieldStyles, renderField, type FieldSize } from '../../internal/field.js';\nimport { FormControl } from '../../internal/form-control.js';\nimport { iconSvg, icons } from '../../internal/icons.js';\nimport { focusRing, hostStyles } from '../../internal/shared.styles.js';\nimport { HasSlotController, uniqueId } from '../../internal/slot.js';\n\n/** Whether a file matches an `accept` list: extensions (`.pdf`), MIME types (`image/png`) or wildcards (`image/*`). */\nfunction accepts(file: File, accept: string | undefined): boolean {\n const tokens = (accept ?? '')\n .split(',')\n .map((token) => token.trim().toLowerCase())\n .filter(Boolean);\n if (!tokens.length) return true;\n const name = file.name.toLowerCase();\n const type = file.type.toLowerCase();\n return tokens.some((token) =>\n token.startsWith('.') ? name.endsWith(token) : token.endsWith('/*') ? type.startsWith(token.slice(0, -1)) : type === token,\n );\n}\n\n/** A size in the language's format, in bytes, kB, MB or GB. */\nfunction formatSize(bytes: number, lang: string): string {\n const units = ['byte', 'kilobyte', 'megabyte', 'gigabyte'] as const;\n let value = bytes;\n let unit = 0;\n while (value >= 1000 && unit < units.length - 1) {\n value /= 1000;\n unit += 1;\n }\n try {\n return new Intl.NumberFormat(lang || undefined, { style: 'unit', unit: units[unit], unitDisplay: 'short', maximumFractionDigits: unit ? 1 : 0 }).format(value);\n } catch {\n return `${Math.round(value * 10) / 10} ${['B', 'kB', 'MB', 'GB'][unit]}`;\n }\n}\n\n/**\n * Picks files to send with a form: from a button, or by dragging them onto the\n * drop zone. The chosen files are listed with their size and a remove button.\n * Files that don't match `accept` or are larger than `max-size` are refused,\n * with a message saying why. It submits like a native `<input type=\"file\">`.\n *\n * @summary Lets users choose files to upload.\n * @tag uf-file-upload\n *\n * @slot label - The label, when you need markup. Overrides `label`.\n * @slot hint - Help text below the label. Overrides `hint`.\n *\n * @event input - Fired when files are added or removed.\n * @event change - Fired when files are added or removed.\n *\n * @csspart field - The wrapper around label, drop zone, files, hint and error.\n * @csspart form-label - The label.\n * @csspart dropzone - The area files can be dropped on.\n * @csspart button - The button that opens the file picker.\n * @csspart files - The list of chosen files.\n * @csspart file - A chosen file.\n * @csspart remove-button - A file's remove button.\n * @csspart rejected - Why files were refused.\n * @csspart hint - The hint text.\n * @csspart error - The validation message.\n *\n * @cssprop --uf-file-upload-border-color - Border color of the drop zone.\n * @cssprop --uf-file-upload-bg - Background of the drop zone.\n * @cssprop --uf-file-upload-radius - Corner radius of the drop zone. Defaults to the theme's control radius.\n * @cssprop --uf-file-upload-active-color - Border and background tint while files are dragged over.\n *\n * @cssstate user-invalid - Required but empty, after the user interacted.\n */\nexport class UfFileUpload extends FormControl {\n static override styles = [\n hostStyles,\n fieldStyles,\n css`\n .dropzone {\n --_active: var(--uf-file-upload-active-color, var(--uf-color-accent-strong));\n position: relative;\n display: flex;\n flex-direction: column;\n align-items: center;\n gap: var(--uf-space-2);\n padding: var(--_padding, var(--uf-space-5) var(--uf-space-4));\n border: 1px solid var(--uf-file-upload-border-color, var(--uf-color-border-strong));\n /* Like the fields: square by default, following the theme's control radius. */\n border-radius: var(--uf-file-upload-radius, var(--uf-radius-control));\n background: var(--uf-file-upload-bg, transparent);\n color: var(--uf-color-text-muted);\n font-size: var(--_font-size, var(--uf-font-size-sm));\n text-align: center;\n transition:\n border-color var(--uf-duration-fast) ease,\n background-color var(--uf-duration-fast) ease;\n }\n\n :host([size='sm']) {\n --_padding: var(--uf-space-3) var(--uf-space-4);\n --_icon: 1.25rem;\n }\n\n :host([size='lg']) {\n --_padding: var(--uf-space-6) var(--uf-space-5);\n --_icon: 2.25rem;\n --_font-size: var(--uf-font-size-md);\n }\n\n .dropzone > .icon {\n width: var(--_icon, 1.75rem);\n height: var(--_icon, 1.75rem);\n color: var(--uf-color-text-muted);\n }\n\n /* Files dragged over it: an accent border, thicker like a focused field. */\n .dropzone.dragging {\n border-color: var(--_active);\n box-shadow: inset 0 0 0 1px var(--_active);\n background: color-mix(in srgb, var(--_active) 8%, transparent);\n }\n\n /* A 2px error outline, as on the fields. */\n .invalid .dropzone {\n border-color: var(--uf-color-danger-text);\n box-shadow: inset 0 0 0 1px var(--uf-color-danger-text);\n }\n\n /* Grey, like disabled fields. */\n .dropzone.disabled {\n border-color: var(--uf-color-border);\n background: var(--uf-color-neutral-fill);\n }\n\n .browse {\n min-height: var(--uf-size-control-sm);\n padding: 0 var(--uf-space-3);\n border: 1px solid var(--uf-color-border-strong);\n border-radius: var(--uf-radius-control);\n background: var(--uf-color-surface);\n color: var(--uf-color-text);\n font: inherit;\n font-weight: var(--uf-font-weight-medium);\n cursor: pointer;\n }\n\n .browse:hover:not(:disabled) {\n border-color: var(--uf-color-accent-strong);\n color: var(--uf-color-accent-strong);\n }\n\n .browse:focus-visible {\n ${focusRing}\n }\n\n .browse:disabled {\n color: var(--uf-color-text-muted);\n cursor: not-allowed;\n }\n\n .native {\n position: absolute;\n width: 1px;\n height: 1px;\n opacity: 0;\n pointer-events: none;\n }\n\n .files {\n display: grid;\n gap: var(--uf-space-1);\n margin: var(--uf-space-2) 0 0;\n padding: 0;\n list-style: none;\n }\n\n .file {\n display: flex;\n align-items: center;\n gap: var(--uf-space-2);\n min-height: var(--uf-size-control-sm);\n padding: 0 var(--uf-space-1) 0 var(--uf-space-3);\n border: 1px solid var(--uf-color-border);\n border-radius: var(--uf-radius-control);\n font-size: var(--uf-font-size-sm);\n color: var(--uf-color-text);\n }\n\n .file > .icon {\n flex: none;\n width: 1rem;\n height: 1rem;\n color: var(--uf-color-text-muted);\n }\n\n .name {\n flex: 1;\n min-width: 0;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n\n .size {\n flex: none;\n color: var(--uf-color-text-muted);\n font-variant-numeric: tabular-nums;\n }\n\n .remove {\n display: inline-flex;\n flex: none;\n align-items: center;\n justify-content: center;\n width: 1.75rem;\n height: 1.75rem;\n padding: 0;\n border: 0;\n border-radius: var(--uf-radius-sm);\n background: transparent;\n color: var(--uf-color-text-muted);\n cursor: pointer;\n }\n\n .remove:hover:not(:disabled) {\n background: var(--uf-color-surface-hover);\n color: var(--uf-color-text);\n }\n\n .remove:focus-visible {\n ${focusRing}\n }\n\n .remove .icon {\n width: 1rem;\n height: 1rem;\n }\n\n .rejected {\n margin: var(--uf-space-1) 0 0;\n color: var(--uf-color-danger-text);\n font-size: var(--uf-font-size-sm);\n }\n\n .rejected:empty {\n display: none;\n }\n\n [hidden] {\n display: none !important;\n }\n `,\n ];\n\n protected static override formStateProperties: ReadonlySet<PropertyKey> = new Set([...FormControl.formStateProperties, 'files']);\n\n static override properties: PropertyDeclarations = {\n files: { attribute: false },\n label: {},\n hint: {},\n accept: {},\n multiple: { type: Boolean, reflect: true },\n maxSize: { type: Number, attribute: 'max-size' },\n size: { reflect: true },\n };\n\n /** The chosen files. Set it to `[]` to clear them. */\n declare files: File[];\n /** Visible label. */\n declare label: string | undefined;\n /** Help text, e.g. the accepted types and size. */\n declare hint: string | undefined;\n /** Accepted files, as in a native file input: extensions (`.pdf`), MIME types (`image/png`) or wildcards (`image/*`), comma-separated. */\n declare accept: string | undefined;\n /** Lets users choose more than one file. */\n declare multiple: boolean;\n /** Largest accepted file, in bytes, e.g. `5000000` for 5 MB. */\n declare maxSize: number | undefined;\n /** Size of the drop zone: `sm`, `md` or `lg`. */\n declare size: FieldSize;\n\n readonly #slots = new HasSlotController(this, 'label', 'hint');\n readonly #id = uniqueId('uf-file-upload');\n #dragging = false;\n #rejected: string[] = [];\n\n constructor() {\n super();\n this.files = [];\n this.multiple = false;\n this.size = 'md';\n }\n\n get #input(): HTMLInputElement | null {\n return this.renderRoot.querySelector('.native');\n }\n\n get #button(): HTMLButtonElement | null {\n return this.renderRoot.querySelector('.browse');\n }\n\n /** Opens the file picker. */\n showPicker(): void {\n if (!this.isDisabled) this.#input?.click();\n }\n\n override willUpdate(changed: PropertyValues<this>): void {\n if (changed.has('multiple') && !this.multiple && this.files.length > 1) this.files = this.files.slice(0, 1);\n }\n\n override updated(): void {\n this.syncFormState();\n }\n\n protected syncFormState(): void {\n if (!this.hasUpdated) return;\n if (this.files.length && this.name) {\n const data = new FormData();\n for (const file of this.files) data.append(this.name, file);\n this.internals.setFormValue(data);\n } else {\n this.internals.setFormValue(null);\n }\n const missing = this.required && !this.files.length;\n this.setValidity({ valueMissing: missing }, missing ? this.#missingMessage() : '', this.#button ?? undefined);\n }\n\n /** The browser's own \"Please select a file\" message, in the user's language. */\n #missingMessage(): string {\n const probe = document.createElement('input');\n probe.type = 'file';\n probe.required = true;\n return probe.validationMessage;\n }\n\n protected resetValue(): void {\n this.files = [];\n this.#rejected = [];\n }\n\n /** Adds files, refusing those that don't fit `accept` and `max-size`. */\n #add(list: FileList | File[]): void {\n const lang = this.translator.lang;\n const rejected: string[] = [];\n const added: File[] = [];\n for (const file of list) {\n if (!accepts(file, this.accept)) rejected.push(this.translator.t('fileTypeRejected', { name: file.name }));\n else if (this.maxSize && file.size > this.maxSize) rejected.push(this.translator.t('fileTooLarge', { name: file.name, size: formatSize(this.maxSize, lang) }));\n else added.push(file);\n }\n this.#rejected = rejected;\n if (added.length) {\n // A new pick replaces the file of a single upload; with `multiple`, files add up (same name and size: kept once).\n const kept = this.multiple ? this.files.filter((f) => !added.some((a) => a.name === f.name && a.size === f.size)) : [];\n this.files = this.multiple ? [...kept, ...added] : added.slice(0, 1);\n this.#changed();\n } else {\n this.requestUpdate();\n }\n }\n\n #remove(index: number): void {\n this.files = this.files.filter((_, i) => i !== index);\n this.#rejected = [];\n this.#changed();\n // Focus moves to the next file's remove button, or the picker button, so it isn't lost.\n void this.updateComplete.then(() => {\n const buttons = this.renderRoot.querySelectorAll<HTMLButtonElement>('.remove');\n (buttons[Math.min(index, buttons.length - 1)] ?? this.#button)?.focus();\n });\n }\n\n #changed(): void {\n this.markInteracted();\n this.dispatchEvent(new Event('input', { bubbles: true, composed: true }));\n this.emitChange();\n }\n\n #onPick = (event: Event): void => {\n event.stopPropagation();\n const input = event.target as HTMLInputElement;\n if (input.files?.length) this.#add(input.files);\n // Cleared, so choosing the same file again still fires `change`.\n input.value = '';\n };\n\n #onDragOver = (event: DragEvent): void => {\n if (this.isDisabled || !event.dataTransfer?.types.includes('Files')) return;\n event.preventDefault();\n event.dataTransfer.dropEffect = 'copy';\n if (!this.#dragging) {\n this.#dragging = true;\n this.requestUpdate();\n }\n };\n\n #onDragLeave = (event: DragEvent): void => {\n if ((event.currentTarget as Element).contains(event.relatedTarget as Node)) return;\n this.#dragging = false;\n this.requestUpdate();\n };\n\n #onDrop = (event: DragEvent): void => {\n event.preventDefault();\n this.#dragging = false;\n if (this.isDisabled || !event.dataTransfer?.files.length) {\n this.requestUpdate();\n return;\n }\n const files = [...event.dataTransfer.files];\n this.#add(this.multiple ? files : files.slice(0, 1));\n };\n\n override render() {\n const ids = { hintId: `${this.#id}-hint`, errorId: `${this.#id}-error` };\n const error = this.showInvalid ? this.validationMessage : '';\n const hasHintSlot = this.#slots.has('hint');\n const disabled = this.isDisabled;\n const lang = this.translator.lang;\n const choose = this.translator.t(this.multiple ? 'chooseFiles' : 'chooseFile');\n\n return renderField({\n ...ids,\n controlId: `${this.#id}-input`,\n label: this.label,\n hasLabelSlot: this.#slots.has('label'),\n hint: this.hint,\n hasHintSlot,\n error,\n required: this.required,\n control: html`\n <div\n class=${classMap({ dropzone: true, dragging: this.#dragging, disabled })}\n part=\"dropzone\"\n @dragover=${this.#onDragOver}\n @dragleave=${this.#onDragLeave}\n @drop=${this.#onDrop}\n >\n ${iconSvg(icons.upload)}\n <button\n class=\"browse\"\n part=\"button\"\n type=\"button\"\n ?disabled=${disabled}\n aria-label=${this.label ? `${choose}: ${this.label}` : choose}\n aria-invalid=${error ? 'true' : 'false'}\n aria-describedby=${ifDefined(describedBy({ ...ids, hint: this.hint, hasHintSlot, error }))}\n @click=${() => this.showPicker()}\n >\n ${choose}\n </button>\n <span>${this.translator.t(this.multiple ? 'dropFiles' : 'dropFile')}</span>\n <input\n id=${`${this.#id}-input`}\n class=\"native\"\n type=\"file\"\n tabindex=\"-1\"\n aria-hidden=\"true\"\n accept=${ifDefined(this.accept)}\n ?multiple=${this.multiple}\n ?disabled=${disabled}\n @change=${this.#onPick}\n @input=${(event: Event) => event.stopPropagation()}\n />\n </div>\n <ul class=\"files\" part=\"files\" ?hidden=${!this.files.length}>\n ${this.files.map(\n (file, i) => html`<li class=\"file\" part=\"file\">\n ${iconSvg(icons.file)}\n <span class=\"name\" title=${file.name}>${file.name}</span>\n <span class=\"size\">${formatSize(file.size, lang)}</span>\n <button\n class=\"remove\"\n part=\"remove-button\"\n type=\"button\"\n ?disabled=${disabled}\n aria-label=${this.translator.t('removeFile', { name: file.name })}\n @click=${() => this.#remove(i)}\n >\n ${iconSvg(icons.x)}\n </button>\n </li>`,\n )}\n </ul>\n <div class=\"rejected\" part=\"rejected\" role=\"status\">${this.#rejected.length ? this.#rejected.join(' ') : nothing}</div>\n `,\n });\n }\n}\n\ndefineElement('uf-file-upload', UfFileUpload);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'uf-file-upload': UfFileUpload;\n }\n}\n",
|
|
792
860
|
"components/icon/icon.ts": "import { LitElement, css, html, nothing, type PropertyDeclarations } from 'lit';\nimport { unsafeSVG } from 'lit/directives/unsafe-svg.js';\nimport { defineElement } from '../../internal/define.js';\nimport { iconSvg, icons, type BuiltInIconName } from '../../internal/icons.js';\n\nconst registry = new Map<string, string>();\nconst instances = new Set<UfIcon>();\n\n/**\n * Registers custom icons by name, as SVG markup. The markup is trusted and\n * inserted as-is, so only register icons from your own code, never user input.\n *\n * @example registerIcons({ heart: '<svg viewBox=\"0 0 24 24\">…</svg>' })\n */\nexport function registerIcons(svgs: Record<string, string>): void {\n for (const [name, markup] of Object.entries(svgs)) registry.set(name, markup);\n for (const icon of instances) icon.requestUpdate();\n}\n\n/**\n * An icon from the built-in set, or one added with `registerIcons()`.\n * Icons are decorative unless you give them a `label`.\n *\n * @summary Shows a small symbol.\n * @tag uf-icon\n *\n * @csspart svg - The `<svg>` element.\n *\n * @cssprop --uf-icon-size - Width and height. Defaults to `1em`, so it follows the font size.\n * @cssprop --uf-icon-stroke-width - Stroke width of built-in icons.\n */\nexport class UfIcon extends LitElement {\n static override styles = css`\n :host {\n display: inline-flex;\n width: var(--uf-icon-size, 1em);\n height: var(--uf-icon-size, 1em);\n flex: none;\n vertical-align: -0.125em;\n }\n\n svg {\n width: 100%;\n height: 100%;\n stroke-width: var(--uf-icon-stroke-width, 2);\n }\n `;\n\n static override properties: PropertyDeclarations = {\n name: { reflect: true },\n label: {},\n };\n\n /** Icon name: a built-in icon or one added with `registerIcons()`. */\n declare name: BuiltInIconName | (string & {});\n /** Accessible label. Without it the icon is hidden from assistive tech. */\n declare label: string | undefined;\n\n constructor() {\n super();\n this.name = '';\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n instances.add(this);\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n instances.delete(this);\n }\n\n override updated(): void {\n if (this.label) {\n this.setAttribute('role', 'img');\n this.setAttribute('aria-label', this.label);\n this.removeAttribute('aria-hidden');\n } else {\n this.removeAttribute('role');\n this.removeAttribute('aria-label');\n this.setAttribute('aria-hidden', 'true');\n }\n }\n\n override render() {\n const custom = registry.get(this.name);\n if (custom) return html`${unsafeSVG(custom)}`;\n const builtIn = icons[this.name as BuiltInIconName];\n return builtIn ? iconSvg(builtIn, 'svg') : nothing;\n }\n}\n\ndefineElement('uf-icon', UfIcon);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'uf-icon': UfIcon;\n }\n}\n",
|
|
793
861
|
"components/input/input.ts": "import { html, type PropertyDeclarations, type PropertyValues } from 'lit';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { ifDefined } from 'lit/directives/if-defined.js';\nimport { live } from 'lit/directives/live.js';\nimport { defineElement } from '../../internal/define.js';\nimport { controlBoxStyles, describedBy, fieldStyles, renderField, type FieldSize } from '../../internal/field.js';\nimport { FormControl } from '../../internal/form-control.js';\nimport { submitOnEnter } from '../../internal/implicit-submission.js';\nimport { hostStyles } from '../../internal/shared.styles.js';\nimport { HasSlotController, uniqueId } from '../../internal/slot.js';\n\nexport type { FieldSize };\n\nexport type InputType = 'text' | 'email' | 'password' | 'search' | 'tel' | 'url' | 'number' | 'date' | 'time';\n\n/**\n * A single-line text field with a built-in label, hint and validation message.\n *\n * @summary Lets users enter a single line of text.\n * @tag uf-input\n *\n * @slot label - The label, when you need markup. Overrides `label`.\n * @slot hint - Help text below the field. Overrides `hint`.\n * @slot prefix - An icon or text before the input.\n * @slot suffix - An icon or text after the input.\n *\n * @event input - Fired on every keystroke.\n * @event change - Fired when the value is committed (blur or Enter).\n *\n * @csspart field - The wrapper around label, control, hint and error.\n * @csspart form-label - The label.\n * @csspart box - The bordered box around the input.\n * @csspart input - The native `<input>`.\n * @csspart hint - The hint text.\n * @csspart error - The validation message.\n *\n * @cssprop --uf-field-bg - Background of the box.\n * @cssprop --uf-field-border-color - Border color of the box.\n * @cssprop --uf-field-radius - Corner radius of the box.\n *\n * @cssstate user-invalid - The value is invalid and the user has interacted with the field.\n */\nexport class UfInput extends FormControl {\n static override styles = [hostStyles, fieldStyles, controlBoxStyles];\n\n protected static override formStateProperties: ReadonlySet<PropertyKey> = new Set([\n ...FormControl.formStateProperties,\n 'type',\n 'readonly',\n 'pattern',\n 'min',\n 'max',\n 'step',\n 'minlength',\n 'maxlength',\n ]);\n\n static override properties: PropertyDeclarations = {\n type: { reflect: true },\n value: { attribute: false },\n defaultValue: { attribute: 'value' },\n label: {},\n hint: {},\n placeholder: {},\n size: { reflect: true },\n readonly: { type: Boolean, reflect: true },\n autocomplete: {},\n inputmode: {},\n pattern: {},\n min: {},\n max: {},\n step: {},\n minlength: { type: Number },\n maxlength: { type: Number },\n };\n\n /** Input type. */\n declare type: InputType;\n /** Current value. */\n declare value: string;\n /** Initial value, restored on form reset. Set with the `value` attribute. */\n declare defaultValue: string;\n /** Visible label. */\n declare label: string | undefined;\n /** Help text below the field. */\n declare hint: string | undefined;\n /** Placeholder text. */\n declare placeholder: string | undefined;\n /** Size of the field. */\n declare size: FieldSize;\n /** Makes the field read-only. */\n declare readonly: boolean;\n /** Native `autocomplete` hint. */\n declare autocomplete: AutoFill | undefined;\n /** Native `inputmode` hint for virtual keyboards. */\n declare inputmode: string | undefined;\n /** Regex the value must match. */\n declare pattern: string | undefined;\n /** Minimum value, for number and date types. */\n declare min: string | undefined;\n /** Maximum value, for number and date types. */\n declare max: string | undefined;\n /** Step, for number and date types. */\n declare step: string | undefined;\n /** Minimum length. */\n declare minlength: number | undefined;\n /** Maximum length. */\n declare maxlength: number | undefined;\n\n readonly #slots = new HasSlotController(this, 'label', 'hint');\n readonly #id = uniqueId('uf-input');\n\n constructor() {\n super();\n this.type = 'text';\n this.value = '';\n this.defaultValue = '';\n this.size = 'md';\n this.readonly = false;\n }\n\n get #input(): HTMLInputElement | null {\n return this.renderRoot.querySelector('input');\n }\n\n /** Selects all text in the field. */\n select(): void {\n this.#input?.select();\n }\n\n override willUpdate(changed: PropertyValues<this>): void {\n // Like a native input: the value follows the `value` attribute until it is edited.\n if (changed.has('defaultValue') && this.value === (changed.get('defaultValue') ?? '')) {\n this.value = this.defaultValue ?? '';\n }\n }\n\n override updated(): void {\n this.syncFormState();\n }\n\n protected syncFormState(): void {\n const input = this.#input;\n if (!input) return;\n this.internals.setFormValue(this.value);\n this.setValidityFrom(input);\n }\n\n protected resetValue(): void {\n this.value = this.defaultValue ?? '';\n }\n\n /** @internal */\n formStateRestoreCallback(state: string | null): void {\n this.value = state ?? '';\n }\n\n #onInput = (event: Event): void => {\n this.value = (event.target as HTMLInputElement).value;\n };\n\n #onChange = (): void => {\n this.markInteracted();\n this.emitChange();\n };\n\n #onKeyDown = (event: KeyboardEvent): void => submitOnEnter(event, this.form);\n\n override render() {\n const ids = {\n hintId: `${this.#id}-hint`,\n errorId: `${this.#id}-error`,\n };\n const error = this.showInvalid ? this.validationMessage : '';\n const hasHintSlot = this.#slots.has('hint');\n\n return renderField({\n ...ids,\n controlId: this.#id,\n label: this.label,\n hasLabelSlot: this.#slots.has('label'),\n hint: this.hint,\n hasHintSlot,\n error,\n required: this.required,\n control: html`\n <div class=${classMap({ box: true, disabled: this.isDisabled })} part=\"box\">\n <slot name=\"prefix\"></slot>\n <input\n id=${this.#id}\n class=\"native\"\n part=\"input\"\n type=${this.type}\n name=${ifDefined(this.name || undefined)}\n .value=${live(this.value)}\n placeholder=${ifDefined(this.placeholder)}\n autocomplete=${ifDefined(this.autocomplete)}\n inputmode=${ifDefined(this.inputmode)}\n pattern=${ifDefined(this.pattern)}\n min=${ifDefined(this.min)}\n max=${ifDefined(this.max)}\n step=${ifDefined(this.step)}\n minlength=${ifDefined(this.minlength)}\n maxlength=${ifDefined(this.maxlength)}\n ?required=${this.required}\n ?readonly=${this.readonly}\n ?disabled=${this.isDisabled}\n aria-invalid=${error ? 'true' : 'false'}\n aria-describedby=${ifDefined(describedBy({ ...ids, hint: this.hint, hasHintSlot, error }))}\n @input=${this.#onInput}\n @change=${this.#onChange}\n @keydown=${this.#onKeyDown}\n />\n <slot name=\"suffix\"></slot>\n </div>\n `,\n });\n }\n}\n\ndefineElement('uf-input', UfInput);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'uf-input': UfInput;\n }\n}\n",
|
|
794
862
|
"internal/implicit-submission.ts": "const submitTypes = new Set(['submit', 'image']);\n\nfunction isSubmitButton(el: Element): boolean {\n if (el instanceof HTMLButtonElement) return el.type === 'submit';\n if (el instanceof HTMLInputElement) return submitTypes.has(el.type);\n // The property, not the attribute: frameworks may set only the property.\n return el.localName === 'uf-button' && (el as Element & { type?: string }).type === 'submit';\n}\n\n/** Fields where Enter submits, the ones that count for implicit submission. */\nconst textTypes = new Set(['text', 'search', 'url', 'tel', 'email', 'password', 'date', 'month', 'week', 'time', 'datetime-local', 'number']);\n\nfunction blocksImplicitSubmission(el: Element): boolean {\n if (el instanceof HTMLInputElement) return textTypes.has(el.type);\n return el.localName === 'uf-input' || el.localName === 'uf-number-input';\n}\n\n/**\n * Enter submits the form, like in a native input: through its default button (the\n * first submit button), unless that's disabled. Without one, only when the field\n * is the form's only text field.\n */\nexport function submitOnEnter(event: KeyboardEvent, form: HTMLFormElement | null): void {\n if (event.key !== 'Enter' || event.isComposing || event.defaultPrevented || !form) return;\n const fields = [...form.elements];\n const submitter = fields.find(isSubmitButton);\n if (submitter) {\n if ((submitter as Element & { disabled?: boolean }).disabled || submitter.matches(':disabled')) return;\n } else if (fields.filter(blocksImplicitSubmission).length > 1) {\n return;\n }\n event.preventDefault();\n // Native submit buttons go with the form data; ours submit no value.\n form.requestSubmit(submitter instanceof HTMLButtonElement || submitter instanceof HTMLInputElement ? submitter : undefined);\n}\n",
|
|
795
863
|
"components/menu/menu.ts": "import { LitElement, css, html, type PropertyDeclarations } from 'lit';\nimport { defineElement } from '../../internal/define.js';\nimport './menu-item.js';\nimport type { UfMenuItem } from './menu-item.js';\n\nexport { UfMenuItem } from './menu-item.js';\n\nexport interface MenuSelectDetail {\n item: UfMenuItem;\n value: string;\n}\n\n/**\n * A list of actions with full keyboard support: arrow keys, Home and End,\n * and typing a letter jumps to the next item starting with it. Use `<hr>`\n * between items for a separator. Usually placed inside `<uf-dropdown>`.\n *\n * @summary A list of actions or options.\n * @tag uf-menu\n *\n * @slot - `<uf-menu-item>` elements and `<hr>` separators.\n *\n * @event {CustomEvent<MenuSelectDetail>} uf-select - An item was chosen. Cancel it to keep a dropdown open.\n */\nexport class UfMenu extends LitElement {\n static override styles = css`\n :host {\n display: block;\n min-width: 10rem;\n outline: none;\n }\n\n ::slotted(hr) {\n height: 1px;\n margin: var(--uf-space-1) 0;\n border: 0;\n background: var(--uf-color-border);\n }\n `;\n\n static override properties: PropertyDeclarations = {\n label: {},\n };\n\n /** Accessible name of the menu. */\n declare label: string | undefined;\n\n #typeahead = '';\n #typeaheadTimer = 0;\n\n constructor() {\n super();\n this.addEventListener('click', this.#onClick);\n this.addEventListener('keydown', this.#onKeyDown);\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n this.setAttribute('role', 'menu');\n }\n\n override updated(): void {\n if (this.label) this.setAttribute('aria-label', this.label);\n else this.removeAttribute('aria-label');\n this.#alignItems();\n }\n\n /** Reserves the check column on every item when any item is a checkbox. */\n #alignItems(): void {\n const items = [...this.querySelectorAll('uf-menu-item')].filter((i) => i.closest('uf-menu') === this);\n const hasCheckbox = items.some((i) => i.type === 'checkbox');\n for (const item of items) item.toggleAttribute('data-check-space', hasCheckbox);\n }\n\n /** Enabled items that belong to this menu (not to a nested one). */\n get items(): UfMenuItem[] {\n return [...this.querySelectorAll<UfMenuItem>('uf-menu-item')].filter(\n (item) => item.closest('uf-menu') === this && !item.disabled,\n );\n }\n\n /** Focuses the first enabled item. */\n focusFirst(): void {\n this.#focusItem(this.items[0]);\n }\n\n /** Focuses the last enabled item. */\n focusLast(): void {\n const items = this.items;\n this.#focusItem(items[items.length - 1]);\n }\n\n #focusItem(item: UfMenuItem | undefined): void {\n if (!item) return;\n for (const other of this.items) other.tabIndex = other === item ? 0 : -1;\n item.focus();\n }\n\n #activate(item: UfMenuItem): void {\n if (item.disabled) return;\n if (item.type === 'checkbox') item.checked = !item.checked;\n this.dispatchEvent(\n new CustomEvent<MenuSelectDetail>('uf-select', {\n bubbles: true,\n composed: true,\n cancelable: true,\n detail: { item, value: item.value },\n }),\n );\n }\n\n #onClick = (event: MouseEvent): void => {\n const item = (event.target as Element).closest('uf-menu-item');\n if (item && item.closest('uf-menu') === this) this.#activate(item);\n };\n\n #onKeyDown = (event: KeyboardEvent): void => {\n const items = this.items;\n const current = (event.target as Element).closest('uf-menu-item');\n const index = current ? items.indexOf(current) : -1;\n\n switch (event.key) {\n case 'ArrowDown':\n this.#focusItem(items[(index + 1) % items.length]);\n break;\n case 'ArrowUp':\n this.#focusItem(items[(index - 1 + items.length) % items.length]);\n break;\n case 'Home':\n this.#focusItem(items[0]);\n break;\n case 'End':\n this.#focusItem(items[items.length - 1]);\n break;\n case 'Enter':\n case ' ':\n if (current) this.#activate(current);\n break;\n default:\n if (event.key.length === 1 && !event.ctrlKey && !event.metaKey && !event.altKey) {\n this.#onTypeahead(event.key, items, index);\n break;\n }\n return;\n }\n event.preventDefault();\n };\n\n /** Jumps to the next item whose label starts with the typed characters. */\n #onTypeahead(key: string, items: UfMenuItem[], index: number): void {\n clearTimeout(this.#typeaheadTimer);\n this.#typeaheadTimer = window.setTimeout(() => (this.#typeahead = ''), 500);\n this.#typeahead += key.toLowerCase();\n // Repeating one letter cycles through the items that start with it.\n const search = /^(.)\\1*$/.test(this.#typeahead) ? this.#typeahead[0] : this.#typeahead;\n const ordered = [...items.slice(index + 1), ...items.slice(0, index + 1)];\n const match = ordered.find((item) => item.textContent?.trim().toLowerCase().startsWith(search));\n this.#focusItem(match);\n }\n\n override render() {\n return html`<slot @slotchange=${() => this.#alignItems()}></slot>`;\n }\n}\n\ndefineElement('uf-menu', UfMenu);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'uf-menu': UfMenu;\n }\n}\n",
|
|
796
864
|
"components/menu/menu-item.ts": "import { LitElement, css, html, nothing, type PropertyDeclarations } from 'lit';\nimport { defineElement } from '../../internal/define.js';\nimport { iconSvg, icons } from '../../internal/icons.js';\n\n/**\n * An action inside `<uf-menu>`. With `type=\"checkbox\"` it toggles on and off.\n *\n * @summary An item in a menu.\n * @tag uf-menu-item\n *\n * @slot - The label.\n * @slot prefix - An icon before the label.\n * @slot suffix - Trailing content, e.g. a keyboard shortcut.\n *\n * @csspart checkmark - The check shown for checked checkbox items.\n * @csspart label - The label wrapper.\n *\n * @cssstate checked - A checkbox item that is on.\n */\nexport class UfMenuItem extends LitElement {\n static override styles = css`\n :host {\n display: flex;\n align-items: center;\n gap: var(--uf-space-2);\n min-height: var(--uf-size-control-sm);\n padding: 0 var(--uf-space-3) 0 var(--uf-space-2);\n color: var(--uf-color-text);\n font-family: var(--uf-font-family-sans);\n font-size: var(--uf-font-size-md);\n line-height: 1.3;\n white-space: nowrap;\n cursor: pointer;\n user-select: none;\n outline: none;\n }\n\n :host(:hover),\n :host(:focus) {\n background: var(--uf-color-accent-tint);\n color: var(--uf-color-on-accent-tint);\n }\n\n :host(:focus-visible) {\n outline: var(--uf-focus-ring-width) solid var(--uf-color-focus-ring);\n outline-offset: calc(var(--uf-focus-ring-width) * -1);\n }\n\n :host([disabled]) {\n opacity: 0.5;\n cursor: not-allowed;\n background: none;\n color: var(--uf-color-text);\n }\n\n .check {\n display: inline-flex;\n width: 1rem;\n flex: none;\n }\n\n /* In menus with checkbox items, every label lines up after the check column. */\n :host([data-check-space]:not([type='checkbox'])) {\n padding-inline-start: calc(var(--uf-space-2) * 2 + 1rem);\n }\n\n .icon {\n width: 1rem;\n height: 1rem;\n }\n\n .label {\n flex: 1;\n }\n\n ::slotted([slot='suffix']) {\n margin-inline-start: var(--uf-space-4);\n color: var(--uf-color-text-muted);\n font-size: var(--uf-font-size-sm);\n }\n\n ::slotted(svg),\n ::slotted(uf-icon) {\n width: 1rem;\n height: 1rem;\n }\n `;\n\n static override properties: PropertyDeclarations = {\n value: { reflect: true },\n type: { reflect: true },\n checked: { type: Boolean, reflect: true },\n disabled: { type: Boolean, reflect: true },\n };\n\n /** Identifies the item in the menu's `uf-select` event. */\n declare value: string;\n /** `checkbox` items toggle `checked` when selected. */\n declare type: 'normal' | 'checkbox';\n /** Whether a checkbox item is on. */\n declare checked: boolean;\n /** Disables the item. */\n declare disabled: boolean;\n\n readonly #internals = this.attachInternals();\n\n constructor() {\n super();\n this.value = '';\n this.type = 'normal';\n this.checked = false;\n this.disabled = false;\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n if (!this.hasAttribute('tabindex')) this.tabIndex = -1;\n }\n\n override updated(): void {\n // Real attributes, so every accessibility tool and test library sees them.\n const checkbox = this.type === 'checkbox';\n this.setAttribute('role', checkbox ? 'menuitemcheckbox' : 'menuitem');\n this.setAttribute('aria-disabled', String(this.disabled));\n if (checkbox) this.setAttribute('aria-checked', String(this.checked));\n else this.removeAttribute('aria-checked');\n this.#internals.states?.[checkbox && this.checked ? 'add' : 'delete']('checked');\n }\n\n override render() {\n return html`\n ${this.type === 'checkbox'\n ? html`<span class=\"check\">${this.checked ? iconSvg(icons.check, 'checkmark') : nothing}</span>`\n : nothing}\n <slot name=\"prefix\"></slot>\n <span class=\"label\" part=\"label\"><slot></slot></span>\n <slot name=\"suffix\"></slot>\n `;\n }\n}\n\ndefineElement('uf-menu-item', UfMenuItem);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'uf-menu-item': UfMenuItem;\n }\n}\n",
|
|
865
|
+
"components/multi-select/multi-select.ts": "import { css, html, nothing, type PropertyDeclarations, type PropertyValues } from 'lit';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { ifDefined } from 'lit/directives/if-defined.js';\nimport { live } from 'lit/directives/live.js';\nimport { defineElement } from '../../internal/define.js';\nimport { controlBoxStyles, describedBy, fieldStyles, renderField, type FieldSize } from '../../internal/field.js';\nimport { FormControl } from '../../internal/form-control.js';\nimport { iconSvg, icons } from '../../internal/icons.js';\nimport { flattenOptions, observeOptions, readItems, type Item, type OptionItem } from '../../internal/options.js';\nimport { autoUpdate, positionFloating } from '../../internal/position.js';\nimport { focusRing, hostStyles } from '../../internal/shared.styles.js';\nimport { HasSlotController, uniqueId } from '../../internal/slot.js';\n\n/** A visible option, with its group and its index among visible options. */\ninterface Row {\n option: OptionItem;\n group?: string;\n index: number;\n}\n\n/**\n * A field to pick several options from a list you can search. The picked ones\n * show as chips in the field, each with a remove button. Write options as plain\n * `<option>` and `<optgroup>` children; `selected` ones start picked.\n *\n * It follows the WAI-ARIA combobox pattern with a multi-select listbox: typing\n * filters the list, arrow keys move through it, Enter picks or unpicks an\n * option and keeps the list open, and Backspace in an empty field removes the\n * last chip. With a `name`, every picked value is submitted with the form.\n *\n * @summary Lets users search a list and pick several options.\n * @tag uf-multi-select\n *\n * @slot - `<option>` and `<optgroup>` elements. They are read, not rendered.\n * @slot label - The label, when you need markup. Overrides `label`.\n * @slot hint - Help text below the field. Overrides `hint`.\n *\n * @event input - Fired as the user types in the field (the search text, not the value).\n * @event change - Fired when an option is picked or removed.\n * @event uf-show - The list opened.\n * @event uf-hide - The list closed.\n *\n * @csspart field - The wrapper around label, control, hint and error.\n * @csspart form-label - The label.\n * @csspart box - The bordered box with the chips and the input.\n * @csspart chips - The list of picked options.\n * @csspart chip - A picked option.\n * @csspart chip-remove - A chip's remove button.\n * @csspart input - The native `<input>`.\n * @csspart toggle - The button that opens the list.\n * @csspart listbox - The floating list.\n * @csspart option - Each option.\n * @csspart group-label - Each group heading.\n * @csspart empty - The \"no results\" message.\n * @csspart hint - The hint text.\n * @csspart error - The validation message.\n *\n * @cssprop --uf-multi-select-max-height - Maximum height of the list before it scrolls.\n * @cssprop --uf-multi-select-chip-bg - Background of the chips.\n * @cssprop --uf-multi-select-chip-color - Text color of the chips.\n * @cssprop --uf-field-bg - Background of the box.\n * @cssprop --uf-field-border-color - Border color of the box.\n * @cssprop --uf-field-radius - Corner radius of the box.\n *\n * @cssstate user-invalid - The value is invalid and the user has interacted with the field.\n */\nexport class UfMultiSelect extends FormControl {\n static override styles = [\n hostStyles,\n fieldStyles,\n controlBoxStyles,\n css`\n /* Chips and the input wrap onto more lines, inside the box. The toggle stays on the first. */\n .box {\n align-items: flex-start;\n gap: var(--uf-space-1);\n padding-block: 3px;\n padding-inline: 3px 0;\n cursor: text;\n }\n\n /* Without chips, the text lines up with the other fields'. */\n .chips[hidden] + .native {\n padding-inline-start: calc(var(--_padding) - 3px);\n }\n\n .values {\n display: flex;\n flex: 1;\n flex-wrap: wrap;\n align-items: center;\n gap: var(--uf-space-1);\n min-width: 0;\n }\n\n .chips {\n display: flex;\n flex-wrap: wrap;\n gap: var(--uf-space-1);\n min-width: 0;\n margin: 0;\n padding: 0;\n list-style: none;\n }\n\n .chip {\n display: inline-flex;\n align-items: center;\n gap: 0.125rem;\n min-height: calc(var(--_height) - 8px);\n padding-inline-start: var(--uf-space-2);\n background: var(--uf-multi-select-chip-bg, var(--uf-color-accent-tint));\n color: var(--uf-multi-select-chip-color, var(--uf-color-on-accent-tint));\n font-size: var(--uf-font-size-sm);\n font-weight: var(--uf-font-weight-medium);\n line-height: 1.2;\n }\n\n .chip-remove {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n align-self: stretch;\n width: 1.5rem;\n padding: 0;\n border: 0;\n background: transparent;\n color: inherit;\n cursor: pointer;\n opacity: 0.75;\n }\n\n .chip-remove:hover {\n background: color-mix(in srgb, currentColor 16%, transparent);\n opacity: 1;\n }\n\n .chip-remove:focus-visible {\n ${focusRing}\n outline-offset: 0;\n }\n\n .chip-remove .icon {\n width: 0.875rem;\n height: 0.875rem;\n }\n\n /* Narrow enough to stay after the chips, growing to fill the rest of the line. */\n .native {\n flex: 1 1 2rem;\n min-height: calc(var(--_height) - 8px);\n }\n\n .toggle {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n flex: none;\n width: calc(var(--_height) - 2px);\n height: calc(var(--_height) - 2px);\n margin-block: -3px;\n padding: 0;\n border: 0;\n background: transparent;\n color: var(--uf-color-text-muted);\n cursor: pointer;\n }\n\n .toggle:disabled,\n .chip-remove:disabled {\n cursor: not-allowed;\n }\n\n .toggle .icon {\n width: 1em;\n height: 1em;\n transition: rotate var(--uf-duration-fast) ease;\n }\n\n .toggle.open .icon {\n rotate: 180deg;\n }\n\n .listbox {\n position: fixed;\n inset: auto;\n margin: 0;\n max-height: var(--uf-multi-select-max-height, 16rem);\n padding: var(--uf-space-1) 0;\n overflow: auto;\n border: 1px solid var(--uf-color-border);\n border-radius: var(--uf-radius-control);\n background: var(--uf-color-surface-overlay);\n color: var(--uf-color-text);\n font-family: var(--uf-font-family-sans);\n font-size: var(--uf-font-size-md);\n box-shadow: var(--uf-shadow-overlay);\n }\n\n .option {\n display: flex;\n align-items: center;\n gap: var(--uf-space-2);\n min-height: var(--uf-size-control-sm);\n padding: 0 var(--uf-space-3) 0 var(--uf-space-2);\n cursor: pointer;\n user-select: none;\n }\n\n /* A checkbox look: several options can be picked. */\n .option .check {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n flex: none;\n width: 1rem;\n height: 1rem;\n border: 1px solid var(--uf-color-border-strong);\n color: var(--uf-color-on-accent);\n }\n\n .option[aria-selected='true'] .check {\n border-color: var(--uf-color-accent);\n background: var(--uf-color-accent);\n }\n\n .option .icon {\n width: 0.875rem;\n height: 0.875rem;\n }\n\n .option.active {\n background: var(--uf-color-accent-tint);\n color: var(--uf-color-on-accent-tint);\n }\n\n .option[aria-disabled='true'] {\n opacity: 0.5;\n cursor: not-allowed;\n }\n\n .group-label {\n padding: var(--uf-space-2) var(--uf-space-3) var(--uf-space-1);\n color: var(--uf-color-text-muted);\n font-size: var(--uf-font-size-sm);\n font-weight: var(--uf-font-weight-semibold);\n }\n\n .empty {\n padding: var(--uf-space-2) var(--uf-space-3);\n color: var(--uf-color-text-muted);\n }\n\n .sr-only {\n position: absolute;\n width: 1px;\n height: 1px;\n overflow: hidden;\n clip-path: inset(50%);\n white-space: nowrap;\n }\n `,\n ];\n\n static override properties: PropertyDeclarations = {\n value: { attribute: false },\n label: {},\n hint: {},\n placeholder: {},\n size: { reflect: true },\n open: { type: Boolean, reflect: true },\n };\n\n /** The picked options' values, in the order of the options. */\n declare value: string[];\n /** Visible label. */\n declare label: string | undefined;\n /** Help text below the field. */\n declare hint: string | undefined;\n /** Placeholder text in the field, while nothing is picked. */\n declare placeholder: string | undefined;\n /** Size of the field. */\n declare size: FieldSize;\n /** Whether the list is showing. */\n declare open: boolean;\n\n readonly #slots = new HasSlotController(this, 'label', 'hint');\n readonly #id = uniqueId('uf-multi-select');\n #observer?: MutationObserver;\n #items: Item[] = [];\n #itemsChanged = false;\n #hasInitialized = false;\n /** Text the user typed, to filter the list. */\n #query = '';\n /** Index of the highlighted row among visible options, or -1. */\n #active = -1;\n #cleanup?: () => void;\n\n constructor() {\n super();\n this.value = [];\n this.size = 'md';\n this.open = false;\n this.addEventListener('focusout', this.#onFocusOut);\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n this.#readItems();\n this.#observer = observeOptions(this, () => this.#readItems());\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n this.#observer?.disconnect();\n this.#cleanup?.();\n }\n\n get #input(): HTMLInputElement | null {\n return this.renderRoot.querySelector('input');\n }\n\n get #listbox(): HTMLElement | null {\n return this.renderRoot.querySelector('.listbox');\n }\n\n get #options(): OptionItem[] {\n return flattenOptions(this.#items);\n }\n\n get #values(): string[] {\n return Array.isArray(this.value) ? this.value : [];\n }\n\n /** The picked options, in the order of the options. */\n get #picked(): OptionItem[] {\n const values = new Set(this.#values);\n return this.#options.filter((o) => values.has(o.value));\n }\n\n /** Options matching the search, in order, with their group. */\n get #rows(): Row[] {\n const query = this.#query.trim().toLowerCase();\n const rows: Row[] = [];\n const add = (option: OptionItem, group?: string) => {\n if (!query || option.label.toLowerCase().includes(query)) rows.push({ option, group, index: rows.length });\n };\n for (const item of this.#items) {\n if (item.kind === 'group') item.options.forEach((o) => add(o, item.label));\n else add(item);\n }\n return rows;\n }\n\n #readItems(): void {\n this.#items = readItems(this);\n this.#itemsChanged = true;\n this.requestUpdate();\n }\n\n #initialValue(): string[] {\n return this.#options.filter((o) => o.selected).map((o) => o.value);\n }\n\n /** Opens the list. */\n show(): void {\n if (!this.isDisabled) this.open = true;\n }\n\n /** Closes the list. */\n hide(): void {\n this.open = false;\n }\n\n override willUpdate(changed: PropertyValues<this>): void {\n if (this.#itemsChanged) {\n this.#itemsChanged = false;\n // Frameworks often connect the element before appending its options: wait for them.\n if (this.#items.length && !this.#hasInitialized) {\n // Values set before the options were read (e.g. by a framework) win.\n if (!this.#values.length) this.value = this.#initialValue();\n this.#hasInitialized = true;\n }\n }\n if (changed.has('open') && !this.open) {\n this.#query = '';\n this.#active = -1;\n }\n }\n\n override updated(changed: PropertyValues<this>): void {\n this.syncFormState();\n if (changed.has('open')) this.#syncPopup();\n this.renderRoot.querySelector('.option.active')?.scrollIntoView({ block: 'nearest' });\n }\n\n #syncPopup(): void {\n const listbox = this.#listbox;\n const box = this.renderRoot.querySelector<HTMLElement>('.box');\n if (!listbox || !box) return;\n if (this.open && !listbox.matches(':popover-open')) {\n listbox.showPopover();\n this.#cleanup = autoUpdate(box, listbox, () => {\n listbox.style.minWidth = `${box.offsetWidth}px`;\n positionFloating(box, listbox, 'bottom-start', 4);\n });\n this.dispatchEvent(new Event('uf-show'));\n } else if (!this.open && listbox.matches(':popover-open')) {\n listbox.hidePopover();\n this.#cleanup?.();\n this.#cleanup = undefined;\n this.dispatchEvent(new Event('uf-hide'));\n }\n }\n\n protected syncFormState(): void {\n const input = this.#input;\n if (!input) return;\n const values = this.#values;\n // Every value under the same name, like a native <select multiple>.\n const data = new FormData();\n if (this.name) for (const value of values) data.append(this.name, value);\n this.internals.setFormValue(data, JSON.stringify(values));\n this.setValidity({ valueMissing: this.required && !values.length }, this.translator.t('selectItem'), input);\n }\n\n protected resetValue(): void {\n this.value = this.#initialValue();\n this.#query = '';\n }\n\n /** @internal */\n formStateRestoreCallback(state: string | null): void {\n try {\n const values: unknown = JSON.parse(state ?? '[]');\n this.value = Array.isArray(values) ? values.map(String) : [];\n } catch {\n this.value = [];\n }\n }\n\n #setValue(values: string[]): void {\n // In the order of the options, so the value doesn't depend on the clicking order.\n const wanted = new Set(values);\n this.value = this.#options.filter((o) => wanted.has(o.value)).map((o) => o.value);\n this.markInteracted();\n this.emitChange();\n }\n\n #toggle(option: OptionItem): void {\n if (option.disabled || this.isDisabled) return;\n const values = this.#values;\n this.#setValue(values.includes(option.value) ? values.filter((v) => v !== option.value) : [...values, option.value]);\n // Picking clears the search, so the next option is easy to find.\n if (this.#query) {\n this.#query = '';\n const index = this.#rows.find((r) => r.option.value === option.value)?.index;\n this.#active = index ?? -1;\n }\n this.requestUpdate();\n }\n\n #remove(option: OptionItem): void {\n if (this.isDisabled) return;\n this.#setValue(this.#values.filter((v) => v !== option.value));\n this.#input?.focus();\n }\n\n /** Highlights the next or previous enabled row, wrapping around. */\n #move(step: 1 | -1, rows: Row[]): void {\n const enabled = rows.filter((r) => !r.option.disabled);\n if (!enabled.length) return;\n const position = enabled.findIndex((r) => r.index === this.#active);\n const next = position === -1 ? (step === 1 ? 0 : enabled.length - 1) : (position + step + enabled.length) % enabled.length;\n this.#active = enabled[next].index;\n this.requestUpdate();\n }\n\n #openWithActive(rows: Row[], fromEnd = false): void {\n const enabled = rows.filter((r) => !r.option.disabled);\n this.#active = (fromEnd ? enabled[enabled.length - 1] : enabled[0])?.index ?? -1;\n this.show();\n }\n\n #onInput = (event: Event): void => {\n this.#query = (event.target as HTMLInputElement).value;\n // Highlight the first match, so Enter picks it.\n this.#active = this.#rows.find((r) => !r.option.disabled)?.index ?? -1;\n this.show();\n this.requestUpdate();\n };\n\n #onKeyDown = (event: KeyboardEvent): void => {\n const rows = this.#rows;\n switch (event.key) {\n case 'ArrowDown':\n event.preventDefault();\n if (!this.open || event.altKey) this.#openWithActive(rows);\n else this.#move(1, rows);\n break;\n case 'ArrowUp':\n event.preventDefault();\n if (!this.open) this.#openWithActive(rows, true);\n else this.#move(-1, rows);\n break;\n case 'Enter': {\n const row = rows.find((r) => r.index === this.#active);\n if (this.open && row) {\n event.preventDefault();\n this.#toggle(row.option);\n }\n break;\n }\n case 'Escape':\n if (this.open) {\n event.preventDefault();\n this.hide();\n }\n break;\n case 'Backspace': {\n const last = this.#picked[this.#picked.length - 1];\n if (!this.#query && last) {\n event.preventDefault();\n this.#setValue(this.#values.filter((v) => v !== last.value));\n }\n break;\n }\n }\n };\n\n #onFocusOut = (event: FocusEvent): void => {\n const next = event.relatedTarget as Node | null;\n if (next && (this.contains(next) || this.renderRoot.contains(next))) return;\n this.markInteracted();\n this.hide();\n };\n\n #onBoxClick = (event: MouseEvent): void => {\n // A click on the box, around the chips, goes to the input; the chips' buttons do their own thing.\n if ((event.target as Element).closest('.chip-remove, .toggle')) return;\n this.#input?.focus();\n if (!this.open) this.#openWithActive(this.#rows);\n };\n\n #onToggleClick = (): void => {\n if (this.open) this.hide();\n else this.#openWithActive(this.#rows);\n this.#input?.focus();\n };\n\n #renderOption(row: Row) {\n const { option } = row;\n const selected = this.#values.includes(option.value);\n return html`\n <div\n id=${`${this.#id}-option-${row.index}`}\n class=${classMap({ option: true, active: row.index === this.#active })}\n part=\"option\"\n role=\"option\"\n aria-selected=${selected ? 'true' : 'false'}\n aria-disabled=${option.disabled ? 'true' : 'false'}\n @pointerdown=${(e: Event) => e.preventDefault()}\n @click=${() => this.#toggle(option)}\n @pointermove=${() => {\n if (!option.disabled && this.#active !== row.index) {\n this.#active = row.index;\n this.requestUpdate();\n }\n }}\n >\n <span class=\"check\">${selected ? iconSvg(icons.check) : nothing}</span>\n ${option.label}\n </div>\n `;\n }\n\n #renderRows(rows: Row[]) {\n const out = [];\n let group: string | undefined;\n for (const row of rows) {\n if (row.group !== group) {\n group = row.group;\n if (group) out.push(html`<div class=\"group-label\" part=\"group-label\" role=\"presentation\">${group}</div>`);\n }\n out.push(this.#renderOption(row));\n }\n return out;\n }\n\n override render() {\n const ids = { hintId: `${this.#id}-hint`, errorId: `${this.#id}-error` };\n const listboxId = `${this.#id}-listbox`;\n const chipsId = `${this.#id}-chips`;\n const error = this.showInvalid ? this.validationMessage : '';\n const hasHintSlot = this.#slots.has('hint');\n const rows = this.#rows;\n const picked = this.#picked;\n const activeId = this.open && this.#active >= 0 ? `${this.#id}-option-${this.#active}` : undefined;\n const described = [describedBy({ ...ids, hint: this.hint, hasHintSlot, error }), picked.length ? chipsId : ''].filter(Boolean).join(' ');\n\n return renderField({\n ...ids,\n controlId: this.#id,\n label: this.label,\n hasLabelSlot: this.#slots.has('label'),\n hint: this.hint,\n hasHintSlot,\n error,\n required: this.required,\n control: html`\n <div class=${classMap({ box: true, disabled: this.isDisabled })} part=\"box\" @click=${this.#onBoxClick}>\n <div class=\"values\">\n <ul id=${chipsId} class=\"chips\" part=\"chips\" ?hidden=${!picked.length}>\n ${picked.map(\n (option) => html`<li class=\"chip\" part=\"chip\">\n ${option.label}\n <button\n class=\"chip-remove\"\n part=\"chip-remove\"\n type=\"button\"\n aria-label=${this.translator.t('removeOption', { name: option.label })}\n ?disabled=${this.isDisabled}\n @click=${() => this.#remove(option)}\n >\n ${iconSvg(icons.x)}\n </button>\n </li>`,\n )}\n </ul>\n <input\n id=${this.#id}\n class=\"native\"\n part=\"input\"\n type=\"text\"\n role=\"combobox\"\n autocomplete=\"off\"\n .value=${live(this.#query)}\n placeholder=${ifDefined(picked.length ? undefined : this.placeholder)}\n ?disabled=${this.isDisabled}\n aria-expanded=${this.open ? 'true' : 'false'}\n aria-controls=${listboxId}\n aria-autocomplete=\"list\"\n aria-activedescendant=${ifDefined(activeId)}\n aria-required=${this.required ? 'true' : 'false'}\n aria-invalid=${error ? 'true' : 'false'}\n aria-describedby=${ifDefined(described || undefined)}\n @input=${this.#onInput}\n @keydown=${this.#onKeyDown}\n />\n </div>\n <button\n class=${classMap({ toggle: true, open: this.open })}\n part=\"toggle\"\n type=\"button\"\n tabindex=\"-1\"\n aria-label=${this.translator.t('showOptions')}\n ?disabled=${this.isDisabled}\n @pointerdown=${(e: Event) => e.preventDefault()}\n @click=${this.#onToggleClick}\n >\n ${iconSvg(icons['chevron-down'])}\n </button>\n </div>\n <div\n id=${listboxId}\n class=\"listbox\"\n part=\"listbox\"\n popover=\"manual\"\n role=\"listbox\"\n aria-multiselectable=\"true\"\n aria-label=${ifDefined(this.label)}\n >\n ${rows.length ? this.#renderRows(rows) : html`<div class=\"empty\" part=\"empty\" role=\"option\" aria-disabled=\"true\" aria-selected=\"false\">${this.translator.t('noResults')}</div>`}\n </div>\n <div class=\"sr-only\" role=\"status\">\n ${this.open && this.#query\n ? rows.length === 1\n ? this.translator.t('oneResult')\n : this.translator.t('results', { count: rows.length })\n : ''}\n </div>\n `,\n });\n }\n}\n\ndefineElement('uf-multi-select', UfMultiSelect);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'uf-multi-select': UfMultiSelect;\n }\n}\n",
|
|
797
866
|
"components/number-input/number-input.ts": "import { css, html, type PropertyDeclarations, type PropertyValues } from 'lit';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { ifDefined } from 'lit/directives/if-defined.js';\nimport { live } from 'lit/directives/live.js';\nimport { defineElement } from '../../internal/define.js';\nimport { controlBoxStyles, describedBy, fieldStyles, renderField, type FieldSize } from '../../internal/field.js';\nimport { FormControl } from '../../internal/form-control.js';\nimport { iconSvg, icons } from '../../internal/icons.js';\nimport { submitOnEnter } from '../../internal/implicit-submission.js';\nimport { hostStyles } from '../../internal/shared.styles.js';\nimport { HasSlotController, uniqueId } from '../../internal/slot.js';\n\n/** An attribute that may be missing or empty, as a number or `null`. */\nconst optionalNumber = {\n fromAttribute: (value: string | null) => (value === null || value.trim() === '' ? null : Number(value)),\n toAttribute: (value: number | null) => (value === null ? null : String(value)),\n};\n\n/**\n * A field for a number, with buttons to step it down and up. The value is a\n * number, or `null` while the field is empty. Arrow keys step it too, Enter\n * submits the form, and `min`, `max` and `step` validate it like a native\n * number input.\n *\n * The buttons are out of the tab order: arrow keys do the same from the field.\n *\n * @summary Lets users enter a number, or step it with buttons.\n * @tag uf-number-input\n *\n * @slot label - The label, when you need markup. Overrides `label`.\n * @slot hint - Help text below the field. Overrides `hint`.\n * @slot prefix - An icon or text before the number, like a currency.\n * @slot suffix - An icon or text after the number, like a unit.\n *\n * @event input - Fired on every keystroke and every step.\n * @event change - Fired when the value is committed: blur, Enter or a step.\n *\n * @csspart field - The wrapper around label, control, hint and error.\n * @csspart form-label - The label.\n * @csspart box - The bordered box around the input and the buttons.\n * @csspart input - The native `<input type=\"number\">`.\n * @csspart steppers - The wrapper around the two buttons.\n * @csspart decrement - The minus button.\n * @csspart increment - The plus button.\n * @csspart hint - The hint text.\n * @csspart error - The validation message.\n *\n * @cssprop --uf-field-bg - Background of the box.\n * @cssprop --uf-field-border-color - Border color of the box.\n * @cssprop --uf-field-radius - Corner radius of the box.\n *\n * @cssstate user-invalid - The value is invalid and the user has interacted with the field.\n */\nexport class UfNumberInput extends FormControl {\n static override styles = [\n hostStyles,\n fieldStyles,\n controlBoxStyles,\n css`\n /* The buttons fill the box's height, flush with its right edge. */\n .box {\n padding-inline-end: 0;\n }\n\n .native {\n font-variant-numeric: tabular-nums;\n -moz-appearance: textfield;\n }\n\n /* The buttons replace the browser's spinners. */\n .native::-webkit-inner-spin-button,\n .native::-webkit-outer-spin-button {\n margin: 0;\n -webkit-appearance: none;\n }\n\n .steppers {\n display: flex;\n flex: none;\n align-self: stretch;\n }\n\n .step {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: var(--_height);\n padding: 0;\n border: 0;\n border-inline-start: 1px solid var(--uf-color-border);\n background: transparent;\n color: var(--uf-color-text-muted);\n cursor: pointer;\n transition:\n background-color var(--uf-duration-fast) ease,\n color var(--uf-duration-fast) ease;\n }\n\n .step:hover:not(:disabled) {\n background: var(--uf-color-surface-hover);\n color: var(--uf-color-text);\n }\n\n .step:active:not(:disabled) {\n background: var(--uf-color-surface-active);\n }\n\n .step:disabled {\n color: var(--uf-color-border-strong);\n cursor: not-allowed;\n }\n\n .step .icon {\n width: 1em;\n height: 1em;\n }\n `,\n ];\n\n protected static override formStateProperties: ReadonlySet<PropertyKey> = new Set([\n ...FormControl.formStateProperties,\n 'readonly',\n 'min',\n 'max',\n 'step',\n ]);\n\n static override properties: PropertyDeclarations = {\n value: { attribute: false },\n defaultValue: { attribute: 'value', converter: optionalNumber },\n label: {},\n hint: {},\n placeholder: {},\n size: { reflect: true },\n readonly: { type: Boolean, reflect: true },\n min: { converter: optionalNumber },\n max: { converter: optionalNumber },\n step: { type: Number },\n };\n\n /** Current value, or `null` while the field is empty. */\n declare value: number | null;\n /** Initial value, restored on form reset. Set with the `value` attribute. */\n declare defaultValue: number | null;\n /** Visible label. */\n declare label: string | undefined;\n /** Help text below the field. */\n declare hint: string | undefined;\n /** Placeholder text. */\n declare placeholder: string | undefined;\n /** Size of the field. */\n declare size: FieldSize;\n /** Makes the field read-only, without the buttons doing anything. */\n declare readonly: boolean;\n /** Lowest value. */\n declare min: number | null;\n /** Highest value. */\n declare max: number | null;\n /** The buttons and arrow keys move by this much, and the value must be a multiple of it (from `min`). */\n declare step: number;\n\n readonly #slots = new HasSlotController(this, 'label', 'hint');\n readonly #id = uniqueId('uf-number-input');\n /** The text in the field, kept as typed: \"1.50\" stays \"1.50\", not the number's \"1.5\". */\n #text = '';\n\n constructor() {\n super();\n this.value = null;\n this.defaultValue = null;\n this.size = 'md';\n this.readonly = false;\n this.min = null;\n this.max = null;\n this.step = 1;\n }\n\n get #input(): HTMLInputElement | null {\n return this.renderRoot.querySelector('input');\n }\n\n /** Steps the value up by `step` (or `count` steps), like the plus button. */\n stepUp(count = 1): void {\n this.#step(count);\n }\n\n /** Steps the value down by `step` (or `count` steps), like the minus button. */\n stepDown(count = 1): void {\n this.#step(-count);\n }\n\n override willUpdate(changed: PropertyValues<this>): void {\n // Like a native input: the value follows the `value` attribute until it is edited.\n if (changed.has('defaultValue') && this.value === (changed.get('defaultValue') ?? null)) {\n this.value = this.defaultValue ?? null;\n }\n // A value set from code replaces the text; one the user typed keeps it.\n if (changed.has('value') && toNumber(this.#text) !== this.value) {\n this.#text = this.value === null || Number.isNaN(this.value) ? '' : String(this.value);\n }\n }\n\n override updated(): void {\n this.syncFormState();\n }\n\n protected syncFormState(): void {\n const input = this.#input;\n if (!input) return;\n this.internals.setFormValue(this.value === null ? '' : String(this.value));\n this.setValidityFrom(input);\n }\n\n protected resetValue(): void {\n this.value = this.defaultValue ?? null;\n }\n\n /** @internal */\n formStateRestoreCallback(state: string | null): void {\n this.value = toNumber(state ?? '');\n }\n\n #step(count: number): void {\n const input = this.#input;\n if (!input || this.isDisabled || this.readonly) return;\n // The native input steps from `min`, clamps to the range and rounds to `step`.\n if (count > 0) input.stepUp(count);\n else input.stepDown(-count);\n this.#text = input.value;\n this.value = toNumber(input.value);\n this.dispatchEvent(new Event('input', { bubbles: true, composed: true }));\n this.emitChange();\n }\n\n #onInput = (event: Event): void => {\n const input = event.target as HTMLInputElement;\n this.#text = input.value;\n this.value = toNumber(input.value);\n };\n\n #onChange = (): void => {\n this.markInteracted();\n this.emitChange();\n };\n\n #onKeyDown = (event: KeyboardEvent): void => submitOnEnter(event, this.form);\n\n override render() {\n const ids = { hintId: `${this.#id}-hint`, errorId: `${this.#id}-error` };\n const error = this.showInvalid ? this.validationMessage : '';\n const hasHintSlot = this.#slots.has('hint');\n const locked = this.isDisabled || this.readonly;\n const value = this.value;\n\n return renderField({\n ...ids,\n controlId: this.#id,\n label: this.label,\n hasLabelSlot: this.#slots.has('label'),\n hint: this.hint,\n hasHintSlot,\n error,\n required: this.required,\n control: html`\n <div class=${classMap({ box: true, disabled: this.isDisabled })} part=\"box\">\n <slot name=\"prefix\"></slot>\n <input\n id=${this.#id}\n class=\"native\"\n part=\"input\"\n type=\"number\"\n name=${ifDefined(this.name || undefined)}\n .value=${live(this.#text)}\n placeholder=${ifDefined(this.placeholder)}\n min=${ifDefined(this.min ?? undefined)}\n max=${ifDefined(this.max ?? undefined)}\n step=${ifDefined(Number.isFinite(this.step) && this.step > 0 ? this.step : undefined)}\n ?required=${this.required}\n ?readonly=${this.readonly}\n ?disabled=${this.isDisabled}\n aria-invalid=${error ? 'true' : 'false'}\n aria-describedby=${ifDefined(describedBy({ ...ids, hint: this.hint, hasHintSlot, error }))}\n @input=${this.#onInput}\n @change=${this.#onChange}\n @keydown=${this.#onKeyDown}\n />\n <slot name=\"suffix\"></slot>\n <span class=\"steppers\" part=\"steppers\">\n <button\n class=\"step\"\n part=\"decrement\"\n type=\"button\"\n tabindex=\"-1\"\n aria-label=${this.translator.t('decrease')}\n aria-controls=${this.#id}\n ?disabled=${locked || (value !== null && this.min !== null && value <= this.min)}\n @click=${() => this.#step(-1)}\n >\n ${iconSvg(icons.minus, '')}\n </button>\n <button\n class=\"step\"\n part=\"increment\"\n type=\"button\"\n tabindex=\"-1\"\n aria-label=${this.translator.t('increase')}\n aria-controls=${this.#id}\n ?disabled=${locked || (value !== null && this.max !== null && value >= this.max)}\n @click=${() => this.#step(1)}\n >\n ${iconSvg(icons.plus, '')}\n </button>\n </span>\n </div>\n `,\n });\n }\n}\n\n/** The number in the field's text, or `null` when it's empty or not a number. */\nfunction toNumber(text: string): number | null {\n if (text.trim() === '') return null;\n const number = Number(text);\n return Number.isNaN(number) ? null : number;\n}\n\ndefineElement('uf-number-input', UfNumberInput);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'uf-number-input': UfNumberInput;\n }\n}\n",
|
|
798
867
|
"components/pagination/pagination.ts": "import { LitElement, css, html, type PropertyDeclarations } from 'lit';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { repeat } from 'lit/directives/repeat.js';\nimport { defineElement } from '../../internal/define.js';\nimport { Translator } from '../../internal/i18n.js';\nimport { iconSvg, icons } from '../../internal/icons.js';\nimport { focusRing, hostStyles } from '../../internal/shared.styles.js';\n\nexport type PaginationSize = 'sm' | 'md' | 'lg';\n\nexport interface PageChangeDetail {\n /** The new page, from 1. */\n page: number;\n}\n\ntype Item = number | 'start-ellipsis' | 'end-ellipsis';\n\n/**\n * The page buttons to show: the first and last pages, the current page with\n * `siblings` pages on each side, and an ellipsis for the gaps. The number of\n * items stays the same from page to page, so the buttons don't jump around.\n */\nfunction pageItems(page: number, pages: number, siblings: number): Item[] {\n // Enough room to show everything: first, last, current, siblings and two ellipses.\n if (pages <= 2 * siblings + 5) return Array.from({ length: pages }, (_, i) => i + 1);\n const start = Math.max(2, Math.min(page - siblings, pages - 2 * siblings - 2));\n const end = Math.min(pages - 1, Math.max(page + siblings, 2 * siblings + 3));\n const items: Item[] = [1];\n if (start > 2) items.push('start-ellipsis');\n for (let p = start; p <= end; p++) items.push(p);\n if (end < pages - 1) items.push('end-ellipsis');\n items.push(pages);\n return items;\n}\n\n/**\n * Navigation between the pages of a list or table. Set `pages` and `page`; the\n * user changes `page`, and `uf-page-change` tells you which page to show.\n *\n * It's a navigation landmark: when a page has more than one, give each a\n * different `label`.\n *\n * @summary Moves between the pages of a long list.\n * @tag uf-pagination\n *\n * @event {CustomEvent<PageChangeDetail>} uf-page-change - The user chose another page.\n *\n * @csspart base - The `<nav>`.\n * @csspart list - The list of buttons.\n * @csspart button - Every button: pages, previous and next.\n * @csspart current - The current page's button.\n * @csspart previous - The previous button.\n * @csspart next - The next button.\n * @csspart ellipsis - The \"…\" between pages.\n *\n * @cssprop --uf-pagination-gap - Space between the buttons.\n */\nexport class UfPagination extends LitElement {\n static override styles = [\n hostStyles,\n css`\n :host {\n display: block;\n --_size: var(--uf-size-control-md);\n }\n\n :host([size='sm']) {\n --_size: var(--uf-size-control-sm);\n }\n\n :host([size='lg']) {\n --_size: var(--uf-size-control-lg);\n --_font-size: var(--uf-font-size-md);\n }\n\n .list {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n gap: var(--uf-pagination-gap, var(--uf-space-1));\n margin: 0;\n padding: 0;\n list-style: none;\n font-family: var(--uf-font-family-sans);\n font-size: var(--_font-size, var(--uf-font-size-sm));\n }\n\n .button {\n display: inline-grid;\n place-items: center;\n min-width: var(--_size);\n height: var(--_size);\n padding: 0 var(--uf-space-2);\n border: 1px solid transparent;\n border-radius: var(--uf-radius-control);\n background: transparent;\n color: var(--uf-color-text);\n font: inherit;\n font-variant-numeric: tabular-nums;\n cursor: pointer;\n transition: background-color var(--uf-duration-fast) ease;\n }\n\n .button:hover:not(:disabled) {\n background: var(--uf-color-accent-tint);\n color: var(--uf-color-on-accent-tint);\n }\n\n .button:focus-visible {\n ${focusRing}\n }\n\n .button:disabled {\n color: var(--uf-color-text-muted);\n cursor: not-allowed;\n opacity: 0.5;\n }\n\n .current,\n .current:hover:not(:disabled) {\n background: var(--uf-color-accent);\n color: var(--uf-color-on-accent);\n font-weight: var(--uf-font-weight-semibold);\n }\n\n .arrow svg {\n width: 1.125em;\n height: 1.125em;\n }\n\n .ellipsis {\n display: inline-grid;\n place-items: center;\n min-width: var(--_size);\n color: var(--uf-color-text-muted);\n }\n `,\n ];\n\n static override properties: PropertyDeclarations = {\n page: { type: Number, reflect: true },\n pages: { type: Number },\n siblings: { type: Number },\n label: {},\n size: { reflect: true },\n };\n\n /** The current page, from 1. */\n declare page: number;\n /** How many pages there are. */\n declare pages: number;\n /** How many pages to show on each side of the current one. */\n declare siblings: number;\n /** Accessible name of the navigation, e.g. \"Search results pages\". Defaults to \"Pagination\", or its translation. */\n declare label: string | undefined;\n /** Size: `sm`, `md` or `lg`. */\n declare size: PaginationSize;\n\n readonly #translator = new Translator(this);\n\n constructor() {\n super();\n this.page = 1;\n this.pages = 1;\n this.siblings = 1;\n this.size = 'md';\n }\n\n /** The current page, kept between 1 and `pages`. */\n get #current(): number {\n return Math.min(Math.max(1, Math.round(this.page) || 1), Math.max(1, this.pages));\n }\n\n #go(page: number): void {\n if (page === this.#current || page < 1 || page > this.pages) return;\n this.page = page;\n this.dispatchEvent(new CustomEvent<PageChangeDetail>('uf-page-change', { bubbles: true, composed: true, detail: { page } }));\n }\n\n override render() {\n const current = this.#current;\n const pages = Math.max(1, Math.floor(this.pages) || 1);\n const items = pageItems(current, pages, Math.max(0, Math.floor(this.siblings)));\n\n return html`<nav part=\"base\" aria-label=${this.label ?? this.#translator.t('pagination')}>\n <ul class=\"list\" part=\"list\">\n <li>\n <button\n class=\"button arrow\"\n part=\"button previous\"\n type=\"button\"\n aria-label=${this.#translator.t('previousPage')}\n ?disabled=${current <= 1}\n @click=${() => this.#go(this.#current - 1)}\n >\n ${iconSvg(icons['chevron-left'])}\n </button>\n </li>\n ${repeat(\n items,\n (item) => item,\n (item) =>\n typeof item === 'number'\n ? html`<li>\n <button\n class=${classMap({ button: true, current: item === current })}\n part=${item === current ? 'button current' : 'button'}\n type=\"button\"\n aria-label=${this.#translator.t('page', { page: item })}\n aria-current=${item === current ? 'page' : 'false'}\n @click=${() => this.#go(item)}\n >\n ${item}\n </button>\n </li>`\n : html`<li class=\"ellipsis\" part=\"ellipsis\" aria-hidden=\"true\">…</li>`,\n )}\n <li>\n <button\n class=\"button arrow\"\n part=\"button next\"\n type=\"button\"\n aria-label=${this.#translator.t('nextPage')}\n ?disabled=${current >= pages}\n @click=${() => this.#go(this.#current + 1)}\n >\n ${iconSvg(icons['chevron-right'])}\n </button>\n </li>\n </ul>\n </nav>`;\n }\n}\n\ndefineElement('uf-pagination', UfPagination);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'uf-pagination': UfPagination;\n }\n}\n",
|
|
799
868
|
"components/popover/popover.ts": "import { LitElement, css, html, type CSSResultGroup, type PropertyDeclarations, type PropertyValues } from 'lit';\nimport { ifDefined } from 'lit/directives/if-defined.js';\nimport { defineElement } from '../../internal/define.js';\nimport { autoUpdate, positionFloating, type Placement } from '../../internal/position.js';\nimport { hostStyles } from '../../internal/shared.styles.js';\n\n/**\n * A panel anchored to a trigger, built on the Popover API: it renders in the\n * top layer and closes on Escape or a click outside. Use it for menus of\n * actions, filters or small forms; use a dialog for anything that blocks the page.\n *\n * @summary Shows floating content next to a trigger.\n * @tag uf-popover\n *\n * @slot trigger - The element that toggles the popover, usually a button.\n * @slot - The popover content.\n *\n * @event uf-show - The popover opened.\n * @event uf-hide - The popover closed.\n *\n * @csspart panel - The floating panel.\n *\n * @cssprop --uf-popover-padding - Padding of the panel.\n * @cssprop --uf-popover-width - Width of the panel. Defaults to its content.\n */\nexport class UfPopover extends LitElement {\n static override styles: CSSResultGroup = [\n hostStyles,\n css`\n :host {\n display: inline-block;\n }\n\n .panel {\n position: fixed;\n inset: auto;\n margin: 0;\n width: var(--uf-popover-width, max-content);\n max-width: calc(100vw - 1rem);\n padding: var(--uf-popover-padding, var(--uf-space-3));\n border: 1px solid var(--uf-color-border);\n border-radius: var(--uf-radius-md);\n background: var(--uf-color-surface-overlay);\n color: var(--uf-color-text);\n font-family: var(--uf-font-family-sans);\n font-size: var(--uf-font-size-md);\n box-shadow: var(--uf-shadow-overlay);\n opacity: 0;\n transition:\n opacity var(--uf-duration-fast) ease,\n overlay var(--uf-duration-fast) allow-discrete,\n display var(--uf-duration-fast) allow-discrete;\n }\n\n .panel:popover-open {\n opacity: 1;\n }\n\n @starting-style {\n .panel:popover-open {\n opacity: 0;\n }\n }\n `,\n ];\n\n static override properties: PropertyDeclarations = {\n open: { type: Boolean, reflect: true },\n placement: { reflect: true },\n distance: { type: Number },\n label: {},\n };\n\n /** Whether the popover is open. */\n declare open: boolean;\n /** Preferred side. Flips when there is no room. */\n declare placement: Placement;\n /** Gap between trigger and panel, in pixels. */\n declare distance: number;\n /** Accessible name of the panel. Defaults to the trigger's text. */\n declare label: string | undefined;\n\n #cleanup?: () => void;\n #openAtPointerDown: boolean | undefined;\n #restoreFocus = false;\n\n constructor() {\n super();\n this.open = false;\n this.placement = 'bottom-start';\n this.distance = 6;\n }\n\n protected get panel(): HTMLElement | null {\n return this.renderRoot.querySelector('.panel');\n }\n\n protected get trigger(): HTMLElement | undefined {\n const slot = this.renderRoot.querySelector<HTMLSlotElement>('slot[name=\"trigger\"]');\n return slot?.assignedElements()[0] as HTMLElement | undefined;\n }\n\n /** What the panel is, for `aria-haspopup` and the panel's role. Subclasses override it. */\n protected get popupKind(): 'dialog' | 'menu' {\n return 'dialog';\n }\n\n /** Called after the panel opened. */\n protected afterShow(): void {}\n\n /** Keys pressed on the trigger. */\n protected onTriggerKeyDown(_event: KeyboardEvent): void {}\n\n /** True when focus is in the panel's content (light-DOM children other than the trigger). */\n protected get focusInPanel(): boolean {\n const active = document.activeElement;\n return Boolean(active && this.contains(active) && !this.trigger?.contains(active));\n }\n\n /** Opens the popover. */\n show(): void {\n this.open = true;\n }\n\n /** Closes the popover. */\n hide(): void {\n this.open = false;\n }\n\n /** Opens the popover if closed, closes it if open. */\n toggle(): void {\n this.open = !this.open;\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n this.#cleanup?.();\n }\n\n override updated(changed: PropertyValues<this>): void {\n const panel = this.panel;\n const trigger = this.trigger;\n trigger?.setAttribute('aria-haspopup', this.popupKind);\n trigger?.setAttribute('aria-expanded', String(this.open));\n if (!changed.has('open') || !panel) return;\n\n if (this.open && !panel.matches(':popover-open')) {\n panel.showPopover();\n if (trigger) this.#cleanup = autoUpdate(trigger, panel, () => positionFloating(trigger, panel, this.placement, this.distance));\n this.dispatchEvent(new Event('uf-show'));\n this.afterShow();\n } else if (!this.open && panel.matches(':popover-open')) {\n panel.hidePopover();\n }\n }\n\n #onBeforeToggle = (event: ToggleEvent): void => {\n // Checked before the panel hides, while focus is still inside it.\n if (event.newState === 'closed') this.#restoreFocus = this.focusInPanel;\n };\n\n /** Keeps `open` in sync when the browser closes the popover (Escape, outside click). */\n #onToggle = (event: ToggleEvent): void => {\n if (event.newState === 'closed') {\n this.#cleanup?.();\n this.#cleanup = undefined;\n this.open = false;\n // Focus would otherwise fall back to <body>.\n if (this.#restoreFocus) this.trigger?.focus();\n this.#restoreFocus = false;\n this.dispatchEvent(new Event('uf-hide'));\n }\n };\n\n // A click on the trigger while open first light-dismisses the popover on\n // pointerdown; remembering the state lets the click close it instead of reopening.\n #onTriggerPointerDown = (): void => {\n this.#openAtPointerDown = this.open;\n };\n\n #onTriggerClick = (): void => {\n const wasOpen = this.#openAtPointerDown ?? this.open;\n this.#openAtPointerDown = undefined;\n this.open = !wasOpen;\n };\n\n override render() {\n return html`\n <slot\n name=\"trigger\"\n @pointerdown=${this.#onTriggerPointerDown}\n @click=${this.#onTriggerClick}\n @keydown=${(event: KeyboardEvent) => this.onTriggerKeyDown(event)}\n @slotchange=${() => this.requestUpdate()}\n ></slot>\n <div\n class=\"panel\"\n part=\"panel\"\n popover=\"auto\"\n role=${ifDefined(this.popupKind === 'dialog' ? 'dialog' : undefined)}\n aria-label=${ifDefined(this.popupKind === 'dialog' ? (this.label ?? (this.trigger?.textContent?.trim() || undefined)) : undefined)}\n @beforetoggle=${this.#onBeforeToggle}\n @toggle=${this.#onToggle}\n >\n <slot></slot>\n </div>\n `;\n }\n}\n\ndefineElement('uf-popover', UfPopover);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'uf-popover': UfPopover;\n }\n}\n",
|
|
800
869
|
"components/progress/progress.ts": "import { LitElement, css, html, nothing, type PropertyDeclarations } from 'lit';\nimport { ifDefined } from 'lit/directives/if-defined.js';\nimport { defineElement } from '../../internal/define.js';\nimport { Translator } from '../../internal/i18n.js';\nimport { hostStyles } from '../../internal/shared.styles.js';\nimport { HasSlotController, uniqueId } from '../../internal/slot.js';\n\nexport type ProgressVariant = 'accent' | 'success' | 'warning' | 'danger';\nexport type ProgressSize = 'sm' | 'md' | 'lg';\n\n/**\n * A bar that shows how far a task has got. Without a `value` it's\n * indeterminate: an animated bar for work whose length isn't known, like a\n * native `<progress>`.\n *\n * @summary Shows how far a task has got.\n * @tag uf-progress\n *\n * @slot label - The label, when you need markup. Overrides `label`.\n *\n * @csspart base - The wrapper around label and bar.\n * @csspart label - The label.\n * @csspart value - The percentage, when `show-value` is set.\n * @csspart track - The bar's background.\n * @csspart indicator - The filled part of the bar.\n *\n * @cssprop --uf-progress-height - Height of the bar.\n * @cssprop --uf-progress-radius - Corner radius of the bar. Use `999px` for a pill.\n * @cssprop --uf-progress-track-color - Color of the bar's background.\n * @cssprop --uf-progress-indicator-color - Color of the filled part.\n */\nexport class UfProgress extends LitElement {\n static override styles = [\n hostStyles,\n css`\n :host {\n display: block;\n --_height: var(--uf-progress-height, 0.5rem);\n --_color: var(--uf-color-accent);\n }\n\n :host([size='sm']) {\n --_height: var(--uf-progress-height, 0.25rem);\n }\n\n :host([size='lg']) {\n --_height: var(--uf-progress-height, 0.75rem);\n }\n\n :host([variant='success']) {\n --_color: var(--uf-color-success);\n }\n :host([variant='warning']) {\n --_color: var(--uf-color-warning);\n }\n :host([variant='danger']) {\n --_color: var(--uf-color-danger);\n }\n\n .base {\n display: flex;\n flex-direction: column;\n gap: var(--uf-space-1);\n font-family: var(--uf-font-family-sans);\n font-size: var(--uf-font-size-sm);\n color: var(--uf-color-text);\n }\n\n .header {\n display: flex;\n justify-content: space-between;\n gap: var(--uf-space-2);\n }\n\n .label {\n font-weight: var(--uf-font-weight-medium);\n }\n\n .value {\n color: var(--uf-color-text-muted);\n font-variant-numeric: tabular-nums;\n }\n\n .track {\n position: relative;\n height: var(--_height);\n border-radius: var(--uf-progress-radius, var(--uf-radius-control));\n background: var(--uf-progress-track-color, var(--uf-color-surface-hover));\n overflow: hidden;\n }\n\n .indicator {\n height: 100%;\n border-radius: inherit;\n background: var(--uf-progress-indicator-color, var(--_color));\n transition: width var(--uf-duration-base) ease;\n }\n\n .indeterminate .indicator {\n position: absolute;\n width: 40%;\n animation: uf-progress-slide 1.5s ease-in-out infinite;\n }\n\n @keyframes uf-progress-slide {\n from {\n left: -40%;\n }\n to {\n left: 100%;\n }\n }\n\n @media (prefers-reduced-motion: reduce) {\n .indicator {\n transition: none;\n }\n .indeterminate .indicator {\n animation-duration: 4s;\n }\n }\n\n [hidden] {\n display: none !important;\n }\n `,\n ];\n\n static override properties: PropertyDeclarations = {\n value: { type: Number },\n max: { type: Number },\n label: {},\n showValue: { type: Boolean, attribute: 'show-value' },\n variant: { reflect: true },\n size: { reflect: true },\n };\n\n /** Progress so far, from 0 to `max`. Leave it out for an indeterminate bar. */\n declare value: number | undefined;\n /** The value that means done. */\n declare max: number;\n /** Visible label, also the bar's accessible name. Without one, it's named \"Progress\". */\n declare label: string | undefined;\n /** Shows the percentage next to the label. */\n declare showValue: boolean;\n /** Color, by meaning: `accent`, `success`, `warning` or `danger`. */\n declare variant: ProgressVariant;\n /** Height of the bar: `sm`, `md` or `lg`. */\n declare size: ProgressSize;\n\n readonly #slots = new HasSlotController(this, 'label');\n readonly #id = uniqueId('uf-progress');\n readonly #translator = new Translator(this);\n\n constructor() {\n super();\n this.max = 100;\n this.showValue = false;\n this.variant = 'accent';\n this.size = 'md';\n }\n\n /** The value as a percentage, or undefined when indeterminate. */\n get #percent(): number | undefined {\n if (this.value == null || Number.isNaN(this.value)) return undefined;\n const max = this.max > 0 ? this.max : 100;\n return Math.round((Math.min(Math.max(this.value, 0), max) / max) * 100);\n }\n\n override render() {\n const percent = this.#percent;\n const indeterminate = percent === undefined;\n const hasLabel = Boolean(this.label) || this.#slots.has('label');\n const showValue = this.showValue && !indeterminate;\n const labelId = `${this.#id}-label`;\n return html`\n <div class=\"base\" part=\"base\">\n <div class=\"header\" ?hidden=${!hasLabel && !showValue}>\n <span id=${labelId} class=\"label\" part=\"label\" ?hidden=${!hasLabel}><slot name=\"label\">${this.label}</slot></span>\n ${showValue ? html`<span class=\"value\" part=\"value\" aria-hidden=\"true\">${percent}%</span>` : nothing}\n </div>\n <div\n class=\"track ${indeterminate ? 'indeterminate' : ''}\"\n part=\"track\"\n role=\"progressbar\"\n aria-labelledby=${ifDefined(hasLabel ? labelId : undefined)}\n aria-label=${ifDefined(hasLabel ? undefined : this.#translator.t('progress'))}\n aria-valuemin=\"0\"\n aria-valuemax=\"100\"\n aria-valuenow=${ifDefined(percent)}\n >\n <div class=\"indicator\" part=\"indicator\" style=${indeterminate ? '' : `width: ${percent}%`}></div>\n </div>\n </div>\n `;\n }\n}\n\ndefineElement('uf-progress', UfProgress);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'uf-progress': UfProgress;\n }\n}\n",
|
|
801
870
|
"components/radio/radio.ts": "import { LitElement, css, html, type PropertyDeclarations } from 'lit';\nimport { defineElement } from '../../internal/define.js';\nimport { hostStyles } from '../../internal/shared.styles.js';\n\n/**\n * One option inside `<uf-radio-group>`. The group manages checked state,\n * focus and keyboard navigation.\n *\n * @summary An option in a radio group.\n * @tag uf-radio\n *\n * @slot - The label.\n *\n * @csspart control - The circle.\n * @csspart label - The label text.\n *\n * @cssprop --uf-radio-size - Size of the circle.\n * @cssprop --uf-radio-checked-bg - Color of the circle when checked.\n *\n * @cssstate checked - The radio is selected.\n */\nexport class UfRadio extends LitElement {\n static override styles = [\n hostStyles,\n css`\n :host {\n --_size: var(--uf-radio-size, var(--_circle, 1.125rem));\n display: flex;\n align-items: flex-start;\n gap: var(--uf-space-2);\n font-family: var(--uf-font-family-sans);\n font-size: var(--uf-font-size-md);\n line-height: 1.4;\n color: var(--uf-color-text);\n cursor: pointer;\n outline: none;\n }\n\n /* The group's size. */\n :host([data-group-size='sm']) {\n --_circle: 1rem;\n font-size: var(--uf-font-size-sm);\n }\n\n :host([data-group-size='lg']) {\n --_circle: 1.25rem;\n font-size: var(--uf-font-size-lg);\n }\n\n /* Grey instead of faded, like disabled fields. */\n :host([disabled]),\n :host([data-group-disabled]) {\n color: var(--uf-color-text-muted);\n cursor: not-allowed;\n }\n\n .control {\n position: relative;\n flex: none;\n width: var(--_size);\n height: var(--_size);\n margin-top: calc((1.4em - var(--_size)) / 2);\n border: 1px solid var(--uf-color-border-strong);\n border-radius: 50%;\n background: var(--uf-color-surface);\n transition: border-color var(--uf-duration-fast) ease;\n }\n\n :host(:hover:not([disabled], [data-group-disabled])) .control {\n border-color: var(--uf-color-text-muted);\n }\n\n :host([checked]) .control {\n border: calc(var(--_size) * 0.3) solid var(--uf-radio-checked-bg, var(--uf-color-accent-strong));\n }\n\n :host([disabled]) .control,\n :host([data-group-disabled]) .control {\n border-color: var(--uf-color-border);\n background: var(--uf-color-neutral-fill);\n }\n\n :host([disabled][checked]) .control,\n :host([data-group-disabled][checked]) .control {\n border-color: var(--uf-color-text-muted);\n }\n\n :host([data-invalid]) .control {\n border-color: var(--uf-color-danger-text);\n box-shadow: inset 0 0 0 1px var(--uf-color-danger-text);\n }\n\n :host(:focus-visible) .control {\n outline: var(--uf-focus-ring-width) solid var(--uf-color-focus-ring);\n outline-offset: var(--uf-focus-ring-offset);\n }\n `,\n ];\n\n static override properties: PropertyDeclarations = {\n value: { reflect: true },\n checked: { type: Boolean, reflect: true },\n disabled: { type: Boolean, reflect: true },\n };\n\n /** Value the group takes when this radio is selected. */\n declare value: string;\n /** Whether this radio is selected. Set by the group. */\n declare checked: boolean;\n /** Disables this option. */\n declare disabled: boolean;\n\n readonly #internals = this.attachInternals();\n\n constructor() {\n super();\n this.value = '';\n this.checked = false;\n this.disabled = false;\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n // Real attributes rather than ElementInternals ARIA, so axe, Testing Library\n // and older assistive tech all see them.\n this.setAttribute('role', 'radio');\n }\n\n override updated(): void {\n const groupDisabled = this.hasAttribute('data-group-disabled');\n this.setAttribute('aria-checked', String(this.checked));\n this.setAttribute('aria-disabled', String(this.disabled || groupDisabled));\n this.#internals.states?.[this.checked ? 'add' : 'delete']('checked');\n }\n\n override render() {\n return html`\n <span class=\"control\" part=\"control\"></span>\n <span class=\"label\" part=\"label\"><slot></slot></span>\n `;\n }\n}\n\ndefineElement('uf-radio', UfRadio);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'uf-radio': UfRadio;\n }\n}\n",
|
|
802
871
|
"components/radio-group/radio-group.ts": "import { css, html, nothing, type PropertyDeclarations, type PropertyValues } from 'lit';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { ifDefined } from 'lit/directives/if-defined.js';\nimport { defineElement } from '../../internal/define.js';\nimport { describedBy, fieldStyles, type FieldSize } from '../../internal/field.js';\nimport { FormControl } from '../../internal/form-control.js';\nimport { hostStyles } from '../../internal/shared.styles.js';\nimport { HasSlotController, uniqueId } from '../../internal/slot.js';\nimport '../radio/radio.js';\nimport type { UfRadio } from '../radio/radio.js';\n\n/**\n * A group of `<uf-radio>` options with one selected value. Arrow keys move\n * the selection, and only the selected option is in the tab order.\n *\n * @summary Lets users pick exactly one option from a list.\n * @tag uf-radio-group\n *\n * @slot - `<uf-radio>` elements.\n * @slot label - The group label, when you need markup. Overrides `label`.\n * @slot hint - Help text below the options. Overrides `hint`.\n *\n * @event input - Fired when the selection changes.\n * @event change - Fired when the selection changes.\n *\n * @csspart base - The element with `role=\"radiogroup\"`.\n * @csspart form-label - The group label.\n * @csspart options - The wrapper around the radios.\n * @csspart hint - The hint text.\n * @csspart error - The validation message.\n *\n * @cssstate user-invalid - Required with nothing selected, after the user interacted.\n */\nexport class UfRadioGroup extends FormControl {\n static override shadowRootOptions = { ...FormControl.shadowRootOptions, delegatesFocus: false };\n\n static override styles = [\n hostStyles,\n fieldStyles,\n css`\n .options {\n display: flex;\n flex-direction: column;\n gap: var(--uf-space-2);\n margin-top: var(--uf-space-1);\n }\n\n :host([orientation='horizontal']) .options {\n flex-direction: row;\n flex-wrap: wrap;\n gap: var(--uf-space-2) var(--uf-space-5);\n }\n `,\n ];\n\n static override properties: PropertyDeclarations = {\n value: { attribute: false },\n defaultValue: { attribute: 'value' },\n label: {},\n hint: {},\n orientation: { reflect: true },\n size: { reflect: true },\n };\n\n /** The selected radio's value, or an empty string. */\n declare value: string;\n /** Initially selected value, restored on form reset. Set with the `value` attribute. */\n declare defaultValue: string;\n /** Visible group label. */\n declare label: string | undefined;\n /** Help text below the options. */\n declare hint: string | undefined;\n /** Lays the options out in a column or a row. */\n declare orientation: 'vertical' | 'horizontal';\n /** Size of the radios and their labels: `sm`, `md` or `lg`. */\n declare size: FieldSize;\n\n readonly #slots = new HasSlotController(this, 'label', 'hint');\n readonly #id = uniqueId('uf-radio-group');\n\n constructor() {\n super();\n this.value = '';\n this.defaultValue = '';\n this.orientation = 'vertical';\n this.size = 'md';\n this.addEventListener('click', this.#onClick);\n this.addEventListener('keydown', this.#onKeyDown);\n }\n\n get #radios(): UfRadio[] {\n return [...this.querySelectorAll('uf-radio')];\n }\n\n #isEnabled(radio: UfRadio): boolean {\n return !radio.disabled && !this.isDisabled;\n }\n\n override willUpdate(changed: PropertyValues<this>): void {\n if (changed.has('defaultValue') && this.value === (changed.get('defaultValue') ?? '')) {\n this.value = this.defaultValue ?? '';\n }\n }\n\n override updated(): void {\n this.#syncRadios();\n this.syncFormState();\n }\n\n /** Reflects the group's value, disabled state, size and roving tabindex onto the radios. */\n #syncRadios(): void {\n const radios = this.#radios;\n const enabled = radios.filter((r) => this.#isEnabled(r));\n const focusable = enabled.find((r) => r.value === this.value) ?? enabled[0];\n const invalid = this.showInvalid;\n for (const radio of radios) {\n radio.checked = radio.value === this.value;\n radio.tabIndex = radio === focusable ? 0 : -1;\n radio.toggleAttribute('data-group-disabled', this.isDisabled);\n radio.setAttribute('data-group-size', this.size);\n radio.toggleAttribute('data-invalid', invalid);\n radio.requestUpdate();\n }\n }\n\n protected syncFormState(): void {\n this.internals.setFormValue(this.value || null);\n this.setValidity(\n { valueMissing: this.required && !this.value },\n this.translator.t('selectOption'),\n this.#radios[0],\n );\n }\n\n protected resetValue(): void {\n this.value = this.defaultValue ?? '';\n }\n\n /** @internal */\n formStateRestoreCallback(state: string | null): void {\n this.value = state ?? '';\n }\n\n #select(radio: UfRadio): void {\n radio.focus();\n if (radio.value === this.value) return;\n this.value = radio.value;\n this.markInteracted();\n this.dispatchEvent(new Event('input', { bubbles: true, composed: true }));\n this.emitChange();\n }\n\n #onClick = (event: MouseEvent): void => {\n const radio = (event.target as Element).closest('uf-radio');\n if (radio && this.contains(radio) && this.#isEnabled(radio)) this.#select(radio);\n };\n\n #onKeyDown = (event: KeyboardEvent): void => {\n const radios = this.#radios.filter((r) => this.#isEnabled(r));\n const current = (event.target as Element).closest('uf-radio');\n if (!current || !radios.length) return;\n\n const index = radios.indexOf(current);\n const step = { ArrowDown: 1, ArrowRight: 1, ArrowUp: -1, ArrowLeft: -1 }[event.key];\n if (step) {\n event.preventDefault();\n this.#select(radios[(index + step + radios.length) % radios.length]);\n } else if (event.key === ' ') {\n event.preventDefault();\n this.#select(current);\n }\n };\n\n /** Moves focus to the selected radio, or the first enabled one. */\n override focus(options?: FocusOptions): void {\n this.#radios.find((r) => r.tabIndex === 0)?.focus(options);\n }\n\n override render() {\n const ids = { hintId: `${this.#id}-hint`, errorId: `${this.#id}-error` };\n const labelId = `${this.#id}-label`;\n const error = this.showInvalid ? this.validationMessage : '';\n const hasHintSlot = this.#slots.has('hint');\n const hasLabel = Boolean(this.label) || this.#slots.has('label');\n\n return html`\n <div\n class=${classMap({ field: true, invalid: Boolean(error) })}\n part=\"base\"\n role=\"radiogroup\"\n aria-labelledby=${ifDefined(hasLabel ? labelId : undefined)}\n aria-describedby=${ifDefined(describedBy({ ...ids, hint: this.hint, hasHintSlot, error }))}\n aria-required=${this.required ? 'true' : 'false'}\n aria-invalid=${error ? 'true' : 'false'}\n aria-disabled=${this.isDisabled ? 'true' : 'false'}\n >\n <div id=${labelId} class=\"field-label\" part=\"form-label\" ?hidden=${!hasLabel}>\n <slot name=\"label\">${this.label}</slot>\n ${this.required ? html`<span class=\"required\" aria-hidden=\"true\">*</span>` : nothing}\n </div>\n <div class=\"options\" part=\"options\">\n <slot @slotchange=${() => this.#syncRadios()}></slot>\n </div>\n <div id=${ids.hintId} class=\"field-hint\" part=\"hint\" ?hidden=${!this.hint && !hasHintSlot}>\n <slot name=\"hint\">${this.hint}</slot>\n </div>\n <div id=${ids.errorId} class=\"field-error\" part=\"error\" ?hidden=${!error}>${error}</div>\n </div>\n `;\n }\n}\n\ndefineElement('uf-radio-group', UfRadioGroup);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'uf-radio-group': UfRadioGroup;\n }\n}\n",
|
|
872
|
+
"components/segmented-control/segmented-control.ts": "import { css, html, nothing, type PropertyDeclarations, type PropertyValues } from 'lit';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { ifDefined } from 'lit/directives/if-defined.js';\nimport { defineElement } from '../../internal/define.js';\nimport { describedBy, fieldStyles, type FieldSize } from '../../internal/field.js';\nimport { FormControl } from '../../internal/form-control.js';\nimport { flattenOptions, readItems, type OptionItem } from '../../internal/options.js';\nimport { focusRing, hostStyles } from '../../internal/shared.styles.js';\nimport { HasSlotController, uniqueId } from '../../internal/slot.js';\n\n/**\n * A row of buttons for one choice among a few, like \"List / Grid\" or \"Day /\n * Week / Month\". The choices are plain `<option>` children. One is always\n * selected: the `value` attribute, an option marked `selected`, or the first.\n *\n * It's a radio group for assistive tech: arrow keys move and select, Home and\n * End jump to the ends, and it submits its value with a form.\n *\n * @summary Picks one of a few options, side by side.\n * @tag uf-segmented-control\n *\n * @slot - `<option>` elements. `disabled` options can't be picked.\n * @slot label - The label, when you need markup. Overrides `label`.\n * @slot hint - Help text below the options. Overrides `hint`.\n *\n * @event input - The user picked another option.\n * @event change - The user picked another option.\n *\n * @csspart base - The element with `role=\"radiogroup\"`.\n * @csspart form-label - The label.\n * @csspart options - The row of buttons.\n * @csspart option - One button. The selected one also has the part `selected`.\n * @csspart selected - The selected button.\n * @csspart hint - The hint text.\n *\n * @cssprop --uf-segmented-control-bg - Background behind the buttons.\n * @cssprop --uf-segmented-control-selected-bg - Background of the selected button.\n * @cssprop --uf-segmented-control-selected-color - Text color of the selected button.\n * @cssprop --uf-segmented-control-radius - Corner radius of the row.\n */\nexport class UfSegmentedControl extends FormControl {\n static override styles = [\n hostStyles,\n fieldStyles,\n css`\n :host {\n display: inline-block;\n }\n\n .options {\n --_height: var(--uf-size-control-md);\n display: inline-flex;\n gap: 2px;\n padding: 2px;\n border: 1px solid var(--uf-color-border-strong);\n border-radius: var(--uf-segmented-control-radius, var(--uf-radius-control));\n background: var(--uf-segmented-control-bg, var(--uf-color-surface));\n }\n\n :host([size='sm']) .options {\n --_height: var(--uf-size-control-sm);\n }\n\n :host([size='lg']) .options {\n --_height: var(--uf-size-control-lg);\n }\n\n .option {\n min-height: calc(var(--_height) - 6px);\n padding: 0 var(--uf-space-3);\n border: 0;\n border-radius: inherit;\n background: transparent;\n color: var(--uf-color-text-muted);\n font: inherit;\n font-size: var(--uf-font-size-md);\n font-weight: var(--uf-font-weight-medium);\n white-space: nowrap;\n cursor: pointer;\n transition:\n background-color var(--uf-duration-fast) ease,\n color var(--uf-duration-fast) ease;\n }\n\n :host([size='sm']) .option {\n padding: 0 var(--uf-space-2);\n font-size: var(--uf-font-size-sm);\n }\n\n :host([size='lg']) .option {\n padding: 0 var(--uf-space-4);\n font-size: var(--uf-font-size-lg);\n }\n\n .option:hover:not(:disabled):not(.selected) {\n background: var(--uf-color-surface-hover);\n color: var(--uf-color-text);\n }\n\n .option.selected {\n background: var(--uf-segmented-control-selected-bg, var(--uf-color-accent));\n color: var(--uf-segmented-control-selected-color, var(--uf-color-on-accent));\n }\n\n .option:focus-visible {\n ${focusRing}\n }\n\n .option:disabled {\n color: var(--uf-color-border-strong);\n cursor: not-allowed;\n }\n\n /* Grey, like disabled fields. */\n .disabled .options {\n border-color: var(--uf-color-border);\n background: var(--uf-color-neutral-fill);\n }\n\n .disabled .option.selected {\n background: var(--uf-color-border-strong);\n color: var(--uf-color-surface);\n }\n `,\n ];\n\n static override properties: PropertyDeclarations = {\n value: { attribute: false },\n defaultValue: { attribute: 'value' },\n label: {},\n hint: {},\n size: { reflect: true },\n };\n\n /** The selected option's value. */\n declare value: string;\n /** Initially selected value, restored on form reset. Set with the `value` attribute. */\n declare defaultValue: string | undefined;\n /** Visible label, also the group's accessible name. */\n declare label: string | undefined;\n /** Help text below the options. */\n declare hint: string | undefined;\n /** Size of the buttons. */\n declare size: FieldSize;\n\n readonly #slots = new HasSlotController(this, 'label', 'hint');\n readonly #id = uniqueId('uf-segmented-control');\n readonly #observer = new MutationObserver(() => this.#readOptions());\n #options: OptionItem[] = [];\n #optionsChanged = false;\n #hasInitialized = false;\n\n constructor() {\n super();\n this.value = '';\n this.size = 'md';\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n this.#readOptions();\n this.#observer.observe(this, { childList: true, subtree: true, attributes: true, characterData: true });\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n this.#observer.disconnect();\n }\n\n #readOptions(): void {\n this.#options = flattenOptions(readItems(this));\n this.#optionsChanged = true;\n this.requestUpdate();\n }\n\n /** The value a reset returns to: the `value` attribute, a `selected` option, or the first enabled one. */\n #initialValue(): string {\n if (this.defaultValue !== undefined && this.defaultValue !== null) return this.defaultValue;\n return (this.#options.find((o) => o.selected) ?? this.#options.find((o) => !o.disabled))?.value ?? '';\n }\n\n override willUpdate(changed: PropertyValues<this>): void {\n if (!changed.has('defaultValue') && !this.#optionsChanged) return;\n this.#optionsChanged = false;\n // Frameworks often connect the element before appending its options: wait for them.\n if (!this.#options.length) return;\n const valid = this.#options.some((o) => o.value === this.value);\n if (!this.#hasInitialized) {\n // A value set before the options were read (e.g. by a framework) wins if it exists.\n if (!(this.value && valid)) this.value = this.#initialValue();\n this.#hasInitialized = true;\n } else if (!valid || changed.has('defaultValue')) {\n this.value = this.#initialValue();\n }\n }\n\n override updated(): void {\n this.syncFormState();\n }\n\n protected syncFormState(): void {\n this.internals.setFormValue(this.value);\n // One option is always selected: nothing to validate.\n this.setValidity({}, '');\n }\n\n protected resetValue(): void {\n this.value = this.#initialValue();\n }\n\n /** @internal */\n formStateRestoreCallback(state: string | null): void {\n this.value = state ?? '';\n }\n\n get #buttons(): HTMLButtonElement[] {\n return [...this.renderRoot.querySelectorAll<HTMLButtonElement>('.option')];\n }\n\n /** Moves focus to the selected option. */\n override focus(options?: FocusOptions): void {\n this.#buttons.find((b) => b.tabIndex === 0)?.focus(options);\n }\n\n #select(option: OptionItem, focus = false): void {\n if (option.disabled || this.isDisabled) return;\n if (focus) this.updateComplete.then(() => this.focus());\n if (option.value === this.value) return;\n this.value = option.value;\n this.markInteracted();\n this.dispatchEvent(new Event('input', { bubbles: true, composed: true }));\n this.emitChange();\n }\n\n #onKeyDown = (event: KeyboardEvent): void => {\n const enabled = this.#options.filter((o) => !o.disabled);\n const index = enabled.findIndex((o) => o.value === this.value);\n const rtl = getComputedStyle(this).direction === 'rtl';\n const next = { ArrowRight: rtl ? -1 : 1, ArrowLeft: rtl ? 1 : -1, ArrowDown: 1, ArrowUp: -1 }[event.key];\n let target: OptionItem | undefined;\n if (next) target = enabled[(index + next + enabled.length) % enabled.length];\n else if (event.key === 'Home') target = enabled[0];\n else if (event.key === 'End') target = enabled[enabled.length - 1];\n if (!target) return;\n event.preventDefault();\n this.#select(target, true);\n };\n\n override render() {\n const ids = { hintId: `${this.#id}-hint`, errorId: `${this.#id}-error` };\n const labelId = `${this.#id}-label`;\n const hasHintSlot = this.#slots.has('hint');\n const hasLabel = Boolean(this.label) || this.#slots.has('label');\n const disabled = this.isDisabled;\n // The selected option takes Tab; with none (no options yet), the first enabled one.\n const focusable = this.#options.find((o) => o.value === this.value && !o.disabled) ?? this.#options.find((o) => !o.disabled);\n\n return html`\n <div\n class=${classMap({ field: true, disabled })}\n part=\"base\"\n role=\"radiogroup\"\n aria-labelledby=${ifDefined(hasLabel ? labelId : undefined)}\n aria-describedby=${ifDefined(describedBy({ ...ids, hint: this.hint, hasHintSlot, error: '' }))}\n aria-disabled=${disabled ? 'true' : 'false'}\n >\n <div id=${labelId} class=\"field-label\" part=\"form-label\" ?hidden=${!hasLabel}>\n <slot name=\"label\">${this.label ?? nothing}</slot>\n </div>\n <div class=\"options\" part=\"options\" @keydown=${this.#onKeyDown}>\n ${this.#options.map((option) => {\n const selected = option.value === this.value;\n return html`<button\n class=${classMap({ option: true, selected })}\n part=${selected ? 'option selected' : 'option'}\n type=\"button\"\n role=\"radio\"\n aria-checked=${selected ? 'true' : 'false'}\n tabindex=${option === focusable ? 0 : -1}\n ?disabled=${disabled || option.disabled}\n @click=${() => this.#select(option)}\n >\n ${option.label}\n </button>`;\n })}\n </div>\n <div id=${ids.hintId} class=\"field-hint\" part=\"hint\" ?hidden=${!(this.hint || hasHintSlot)}>\n <slot name=\"hint\">${this.hint ?? nothing}</slot>\n </div>\n </div>\n `;\n }\n}\n\ndefineElement('uf-segmented-control', UfSegmentedControl);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'uf-segmented-control': UfSegmentedControl;\n }\n}\n",
|
|
803
873
|
"components/select/select.ts": "import { css, html, nothing, type PropertyDeclarations, type PropertyValues } from 'lit';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { ifDefined } from 'lit/directives/if-defined.js';\nimport { live } from 'lit/directives/live.js';\nimport { defineElement } from '../../internal/define.js';\nimport { controlBoxStyles, describedBy, fieldStyles, renderField, type FieldSize } from '../../internal/field.js';\nimport { FormControl } from '../../internal/form-control.js';\nimport { iconSvg, icons } from '../../internal/icons.js';\nimport { hostStyles } from '../../internal/shared.styles.js';\nimport { HasSlotController, uniqueId } from '../../internal/slot.js';\nimport { flattenOptions, readItems, type Item, type OptionItem } from '../../internal/options.js';\n\n/**\n * A dropdown built on the native `<select>`, so it gets the platform's\n * keyboard support, screen reader support and mobile pickers for free.\n * Write options as plain `<option>` and `<optgroup>` children.\n *\n * @summary Lets users pick one option from a dropdown list.\n * @tag uf-select\n *\n * @slot - `<option>` and `<optgroup>` elements. They are mirrored into the native select.\n * @slot label - The label, when you need markup. Overrides `label`.\n * @slot hint - Help text below the field. Overrides `hint`.\n * @slot prefix - An icon before the selected value.\n *\n * @event input - Fired when the selection changes.\n * @event change - Fired when the selection changes.\n *\n * @csspart field - The wrapper around label, control, hint and error.\n * @csspart form-label - The label.\n * @csspart box - The bordered box.\n * @csspart select - The native `<select>`.\n * @csspart chevron - The dropdown arrow.\n * @csspart hint - The hint text.\n * @csspart error - The validation message.\n *\n * @cssprop --uf-field-bg - Background of the box.\n * @cssprop --uf-field-border-color - Border color of the box.\n * @cssprop --uf-field-radius - Corner radius of the box.\n *\n * @cssstate user-invalid - The value is invalid and the user has interacted with the field.\n */\nexport class UfSelect extends FormControl {\n static override styles = [\n hostStyles,\n fieldStyles,\n controlBoxStyles,\n css`\n .box {\n position: relative;\n padding-inline-end: 0;\n }\n\n .native {\n appearance: none;\n min-height: calc(var(--_height) - 2px);\n padding-inline-end: calc(var(--_padding) + 1.25em);\n cursor: pointer;\n }\n\n .native:invalid,\n .native.placeholder {\n color: var(--uf-color-text-muted);\n }\n\n .native option {\n color: var(--uf-color-text);\n background: var(--uf-color-surface-overlay);\n }\n\n .icon {\n position: absolute;\n inset-inline-end: var(--_padding);\n width: 1em;\n height: 1em;\n color: var(--uf-color-text-muted);\n pointer-events: none;\n }\n `,\n ];\n\n static override properties: PropertyDeclarations = {\n value: { attribute: false },\n defaultValue: { attribute: 'value' },\n label: {},\n hint: {},\n placeholder: {},\n size: { reflect: true },\n autocomplete: {},\n };\n\n /** The selected option's value. */\n declare value: string;\n /** Initially selected value, restored on form reset. Set with the `value` attribute. */\n declare defaultValue: string | undefined;\n /** Visible label. */\n declare label: string | undefined;\n /** Help text below the field. */\n declare hint: string | undefined;\n /** Text shown while nothing is selected. */\n declare placeholder: string | undefined;\n /** Size of the field. */\n declare size: FieldSize;\n /** Native `autocomplete` hint. */\n declare autocomplete: AutoFill | undefined;\n\n readonly #slots = new HasSlotController(this, 'label', 'hint');\n readonly #id = uniqueId('uf-select');\n readonly #observer = new MutationObserver(() => this.#readItems());\n #items: Item[] = [];\n #itemsChanged = false;\n #hasInitialized = false;\n\n constructor() {\n super();\n this.value = '';\n this.size = 'md';\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n this.#readItems();\n this.#observer.observe(this, { childList: true, subtree: true, attributes: true, characterData: true });\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n this.#observer.disconnect();\n }\n\n get #select(): HTMLSelectElement | null {\n return this.renderRoot.querySelector('select');\n }\n\n get #options(): OptionItem[] {\n return flattenOptions(this.#items);\n }\n\n /** Mirrors the light-DOM options into the native select. */\n #readItems(): void {\n this.#items = readItems(this);\n this.#itemsChanged = true;\n this.requestUpdate();\n }\n\n /** The value a reset returns to: the `value` attribute, a `selected` option, or the native default. */\n #initialValue(): string {\n if (this.defaultValue !== undefined && this.defaultValue !== null) return this.defaultValue;\n const options = this.#options;\n const selected = options.find((o) => o.selected);\n if (selected) return selected.value;\n if (this.placeholder) return '';\n return options.find((o) => !o.disabled)?.value ?? '';\n }\n\n override willUpdate(changed: PropertyValues<this>): void {\n const defaultChanged = changed.has('defaultValue') || changed.has('placeholder') || this.#itemsChanged;\n if (!defaultChanged) return;\n this.#itemsChanged = false;\n // Frameworks often connect the element before appending its options: wait for them.\n if (!this.#items.length) return;\n const valid = this.#options.some((o) => o.value === this.value);\n if (!this.#hasInitialized) {\n // A value set before the options were read (e.g. by a framework) wins if it exists.\n if (!(this.value && valid)) this.value = this.#initialValue();\n this.#hasInitialized = true;\n } else if (!valid) {\n this.value = this.#initialValue();\n }\n }\n\n override updated(): void {\n this.syncFormState();\n }\n\n protected syncFormState(): void {\n const select = this.#select;\n if (!select) return;\n this.internals.setFormValue(this.value);\n this.setValidityFrom(select);\n }\n\n protected resetValue(): void {\n this.value = this.#initialValue();\n }\n\n /** @internal */\n formStateRestoreCallback(state: string | null): void {\n this.value = state ?? '';\n }\n\n #onChange = (event: Event): void => {\n this.value = (event.target as HTMLSelectElement).value;\n this.markInteracted();\n this.emitChange();\n };\n\n #renderOption(option: OptionItem) {\n return html`<option value=${option.value} ?disabled=${option.disabled} ?selected=${option.value === this.value}>\n ${option.label}\n </option>`;\n }\n\n override render() {\n const ids = { hintId: `${this.#id}-hint`, errorId: `${this.#id}-error` };\n const error = this.showInvalid ? this.validationMessage : '';\n const hasHintSlot = this.#slots.has('hint');\n const showingPlaceholder = Boolean(this.placeholder) && !this.value;\n\n return renderField({\n ...ids,\n controlId: this.#id,\n label: this.label,\n hasLabelSlot: this.#slots.has('label'),\n hint: this.hint,\n hasHintSlot,\n error,\n required: this.required,\n control: html`\n <div class=${classMap({ box: true, disabled: this.isDisabled })} part=\"box\">\n <slot name=\"prefix\"></slot>\n <select\n id=${this.#id}\n class=${classMap({ native: true, placeholder: showingPlaceholder })}\n part=\"select\"\n name=${ifDefined(this.name || undefined)}\n autocomplete=${ifDefined(this.autocomplete)}\n .value=${live(this.value)}\n ?required=${this.required}\n ?disabled=${this.isDisabled}\n aria-invalid=${error ? 'true' : 'false'}\n aria-describedby=${ifDefined(describedBy({ ...ids, hint: this.hint, hasHintSlot, error }))}\n @change=${this.#onChange}\n >\n ${this.placeholder\n ? html`<option value=\"\" disabled hidden ?selected=${!this.value}>${this.placeholder}</option>`\n : nothing}\n ${this.#items.map((item) =>\n item.kind === 'group'\n ? html`<optgroup label=${item.label} ?disabled=${item.disabled}>\n ${item.options.map((o) => this.#renderOption(o))}\n </optgroup>`\n : this.#renderOption(item),\n )}\n </select>\n ${iconSvg(icons['chevron-down'], 'chevron')}\n </div>\n `,\n });\n }\n}\n\ndefineElement('uf-select', UfSelect);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'uf-select': UfSelect;\n }\n}\n",
|
|
804
874
|
"components/skeleton/skeleton.ts": "import { LitElement, css, html, type PropertyDeclarations } from 'lit';\nimport { defineElement } from '../../internal/define.js';\nimport { hostStyles } from '../../internal/shared.styles.js';\n\nexport type SkeletonShape = 'text' | 'rect' | 'circle';\n\n/**\n * A grey placeholder in the shape of content that's still loading: lines of\n * text, a block or a circle. It's decorative, hidden from assistive tech: mark\n * the region that's loading with `aria-busy=\"true\"`, and announce the result\n * when it arrives.\n *\n * Size it with `width` and `height` in CSS; `text` lines take the height of a\n * line of text, and `circle` stays round.\n *\n * @summary Holds the place of content while it loads.\n * @tag uf-skeleton\n *\n * @csspart base - The placeholder, or the wrapper around its lines.\n * @csspart line - One line of a `text` placeholder.\n *\n * @cssprop --uf-skeleton-color - Background of the placeholder.\n * @cssprop --uf-skeleton-highlight - Color of the shimmer that sweeps across it.\n * @cssprop --uf-skeleton-radius - Corner radius of `text` and `rect` placeholders.\n */\nexport class UfSkeleton extends LitElement {\n static override styles = [\n hostStyles,\n css`\n :host {\n --_color: var(--uf-skeleton-color, var(--uf-color-surface-hover));\n /* Toward the text color: lighter in dark mode, darker in light, clearly visible in both. */\n --_highlight: var(--uf-skeleton-highlight, color-mix(in srgb, var(--_color), var(--uf-color-text) 8%));\n display: block;\n }\n\n :host([shape='rect']) {\n height: 6rem;\n }\n\n :host([shape='circle']) {\n display: inline-block;\n width: 2.5rem;\n height: 2.5rem;\n vertical-align: middle;\n }\n\n .base {\n display: grid;\n gap: 0.5em;\n height: 100%;\n }\n\n .block,\n .line {\n border-radius: var(--uf-skeleton-radius, var(--uf-radius-sm));\n /*\n * Three times as wide as the placeholder: the outer thirds are plain, so the\n * loop starts and ends on the plain color and the highlight sweeps through the middle.\n */\n background: linear-gradient(\n /* A slanted band, sweeping from left to right. */\n 110deg,\n var(--_color) 0%,\n var(--_color) 36%,\n var(--_highlight) 50%,\n var(--_color) 64%,\n var(--_color) 100%\n )\n 0 0 / 300% 100%;\n animation: uf-skeleton-shimmer 1.6s ease-in-out infinite;\n }\n\n /* A line of text: as tall as the text around it, a little less than the line height. */\n .line {\n height: 0.9em;\n margin-block: 0.25em;\n }\n\n /* The last of several lines is shorter, like the end of a paragraph. */\n .line.last {\n width: 60%;\n }\n\n :host([shape='circle']) .block {\n border-radius: 50%;\n }\n\n @keyframes uf-skeleton-shimmer {\n from {\n background-position: 100% 0;\n }\n to {\n background-position: 0 0;\n }\n }\n\n /* Still, for people who asked for less motion: the shape alone says \"loading\". */\n @media (prefers-reduced-motion: reduce) {\n .block,\n .line {\n animation: none;\n }\n }\n `,\n ];\n\n static override properties: PropertyDeclarations = {\n shape: { reflect: true },\n lines: { type: Number },\n };\n\n /** `text` (lines of text), `rect` (a block, like an image) or `circle` (like an avatar). */\n declare shape: SkeletonShape;\n /** Number of lines of a `text` placeholder. */\n declare lines: number;\n\n constructor() {\n super();\n this.shape = 'text';\n this.lines = 1;\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n // A real attribute, so it's hidden for every assistive tech and test tool.\n this.setAttribute('aria-hidden', 'true');\n }\n\n override render() {\n if (this.shape !== 'text') return html`<div class=\"base\" part=\"base\"><div class=\"block\"></div></div>`;\n const count = Math.max(1, Math.floor(this.lines) || 1);\n return html`<div class=\"base\" part=\"base\">\n ${Array.from(\n { length: count },\n (_, i) => html`<div class=${i === count - 1 && count > 1 ? 'line last' : 'line'} part=\"line\"></div>`,\n )}\n </div>`;\n }\n}\n\ndefineElement('uf-skeleton', UfSkeleton);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'uf-skeleton': UfSkeleton;\n }\n}\n",
|
|
805
875
|
"components/slider/slider.ts": "import { css, html, type PropertyDeclarations, type PropertyValues } from 'lit';\nimport { ifDefined } from 'lit/directives/if-defined.js';\nimport { live } from 'lit/directives/live.js';\nimport { defineElement } from '../../internal/define.js';\nimport { describedBy, fieldStyles, renderField, type FieldSize } from '../../internal/field.js';\nimport { FormControl } from '../../internal/form-control.js';\nimport { focusRing, hostStyles } from '../../internal/shared.styles.js';\nimport { HasSlotController, uniqueId } from '../../internal/slot.js';\n\n/**\n * Picks a number in a range by dragging a handle, or with the arrow keys. Built\n * on the native range input, so keyboard, touch and screen readers work as\n * they do everywhere; it submits its value with the form.\n *\n * @summary Lets users pick a number in a range.\n * @tag uf-slider\n *\n * @slot label - The label, when you need markup. Overrides `label`.\n * @slot hint - Help text below the slider. Overrides `hint`.\n *\n * @event input - Fired while the handle moves.\n * @event change - Fired when the user lets go, or after a key press.\n *\n * @csspart field - The wrapper around label, slider, hint and error.\n * @csspart form-label - The label.\n * @csspart value - The current value, when `show-value` is set.\n * @csspart input - The native range `<input>`.\n * @csspart hint - The hint text.\n * @csspart error - The validation message.\n *\n * @cssprop --uf-slider-track-height - Height of the track.\n * @cssprop --uf-slider-track-color - Color of the track's empty part.\n * @cssprop --uf-slider-indicator-color - Color of the track up to the handle.\n * @cssprop --uf-slider-thumb-size - Diameter of the handle.\n */\nexport class UfSlider extends FormControl {\n static override styles = [\n hostStyles,\n fieldStyles,\n css`\n :host {\n --_track: var(--uf-slider-track-height, var(--_track-size, 0.375rem));\n --_thumb: var(--uf-slider-thumb-size, var(--_thumb-size, 1.125rem));\n --_fill-color: var(--uf-slider-indicator-color, var(--uf-color-accent));\n --_track-color: var(--uf-slider-track-color, var(--uf-color-surface-hover));\n }\n\n :host([size='sm']) {\n --_track-size: 0.25rem;\n --_thumb-size: 1rem;\n }\n\n :host([size='lg']) {\n --_track-size: 0.5rem;\n --_thumb-size: 1.375rem;\n }\n\n .value {\n color: var(--uf-color-text-muted);\n font-size: var(--uf-font-size-md);\n font-variant-numeric: tabular-nums;\n }\n\n .native {\n width: 100%;\n height: var(--_thumb);\n margin: 0;\n background: transparent;\n cursor: pointer;\n appearance: none;\n }\n\n .native:focus-visible {\n outline: none;\n }\n\n .native::-webkit-slider-runnable-track {\n height: var(--_track);\n border-radius: var(--uf-radius-control);\n background: linear-gradient(to right, var(--_fill-color) var(--_fill), var(--_track-color) var(--_fill));\n }\n\n .native::-moz-range-track {\n height: var(--_track);\n border-radius: var(--uf-radius-control);\n background: linear-gradient(to right, var(--_fill-color) var(--_fill), var(--_track-color) var(--_fill));\n }\n\n .native::-webkit-slider-thumb {\n width: var(--_thumb);\n height: var(--_thumb);\n margin-top: calc((var(--_track) - var(--_thumb)) / 2);\n border: 2px solid var(--_fill-color);\n border-radius: 50%;\n background: var(--uf-color-surface);\n box-shadow: var(--uf-shadow-sm);\n appearance: none;\n }\n\n .native::-moz-range-thumb {\n width: var(--_thumb);\n height: var(--_thumb);\n border: 2px solid var(--_fill-color);\n border-radius: 50%;\n background: var(--uf-color-surface);\n box-shadow: var(--uf-shadow-sm);\n }\n\n .native:focus-visible::-webkit-slider-thumb {\n ${focusRing}\n }\n\n .native:focus-visible::-moz-range-thumb {\n ${focusRing}\n }\n\n /* Grey, like disabled fields. */\n .native:disabled {\n --_fill-color: var(--uf-color-text-muted);\n --_track-color: var(--uf-color-neutral-fill);\n cursor: not-allowed;\n }\n\n :host([disabled]) .field-label,\n :host([disabled]) .value {\n color: var(--uf-color-text-muted);\n }\n `,\n ];\n\n protected static override formStateProperties: ReadonlySet<PropertyKey> = new Set([\n ...FormControl.formStateProperties,\n 'min',\n 'max',\n 'step',\n ]);\n\n static override properties: PropertyDeclarations = {\n value: { type: Number, attribute: false },\n defaultValue: { type: Number, attribute: 'value' },\n min: { type: Number },\n max: { type: Number },\n step: { type: Number },\n label: {},\n hint: {},\n showValue: { type: Boolean, attribute: 'show-value' },\n size: { reflect: true },\n };\n\n /** Current value. */\n declare value: number;\n /** Initial value, restored on form reset. Set with the `value` attribute. Defaults to the middle of the range, like a native slider. */\n declare defaultValue: number | undefined;\n /** Lowest value. */\n declare min: number;\n /** Highest value. */\n declare max: number;\n /** Granularity: the value moves in steps of this size. */\n declare step: number;\n /** Visible label, also the slider's accessible name. */\n declare label: string | undefined;\n /** Help text below the slider. */\n declare hint: string | undefined;\n /** Shows the current value next to the label. */\n declare showValue: boolean;\n /** Size of the track and handle: `sm`, `md` or `lg`. */\n declare size: FieldSize;\n\n readonly #slots = new HasSlotController(this, 'label', 'hint');\n readonly #id = uniqueId('uf-slider');\n\n constructor() {\n super();\n this.min = 0;\n this.max = 100;\n this.step = 1;\n this.showValue = false;\n this.size = 'md';\n // Not a number yet: the first update puts it in the middle of min and max.\n this.value = Number.NaN;\n }\n\n get #input(): HTMLInputElement | null {\n return this.renderRoot.querySelector('input');\n }\n\n /** The value a native slider would hold: within min and max, on a step. */\n #normalize(value: number | undefined): number {\n const min = this.min;\n const max = Math.max(this.max, min);\n const fallback = min + (max - min) / 2;\n const v = value == null || Number.isNaN(value) ? fallback : value;\n const clamped = Math.min(Math.max(v, min), max);\n const step = this.step > 0 ? this.step : 1;\n const stepped = min + Math.round((clamped - min) / step) * step;\n // Avoid 0.30000000000000004 with decimal steps.\n return Number(Math.min(stepped, max).toFixed(10));\n }\n\n override willUpdate(changed: PropertyValues<this>): void {\n // Like a native input: the value follows the `value` attribute until it is changed.\n if (changed.has('defaultValue') && (!this.hasUpdated || this.value === this.#normalize(changed.get('defaultValue')))) {\n this.value = this.#normalize(this.defaultValue);\n }\n if (changed.has('value') || changed.has('min') || changed.has('max') || changed.has('step')) {\n const normalized = this.#normalize(this.value);\n if (normalized !== this.value) this.value = normalized;\n }\n }\n\n override updated(): void {\n this.syncFormState();\n }\n\n protected syncFormState(): void {\n const input = this.#input;\n if (!input) return;\n this.internals.setFormValue(String(this.value));\n this.setValidityFrom(input);\n }\n\n protected resetValue(): void {\n this.value = this.#normalize(this.defaultValue);\n }\n\n /** @internal */\n formStateRestoreCallback(state: string | null): void {\n this.value = this.#normalize(state == null ? undefined : Number(state));\n }\n\n #onInput = (event: Event): void => {\n this.value = Number((event.target as HTMLInputElement).value);\n };\n\n #onChange = (): void => {\n this.markInteracted();\n this.emitChange();\n };\n\n override render() {\n const ids = { hintId: `${this.#id}-hint`, errorId: `${this.#id}-error` };\n const error = this.showInvalid ? this.validationMessage : '';\n const hasHintSlot = this.#slots.has('hint');\n const range = this.max - this.min;\n const fill = range > 0 ? ((this.value - this.min) / range) * 100 : 0;\n\n return renderField({\n ...ids,\n controlId: this.#id,\n label: this.label,\n hasLabelSlot: this.#slots.has('label'),\n hint: this.hint,\n hasHintSlot,\n error,\n required: false,\n // The native slider announces its value already.\n labelEnd: this.showValue ? html`<span class=\"value\" part=\"value\" aria-hidden=\"true\">${this.value}</span>` : undefined,\n control: html`\n <input\n id=${this.#id}\n class=\"native\"\n part=\"input\"\n type=\"range\"\n style=\"--_fill: ${fill}%\"\n name=${ifDefined(this.name || undefined)}\n min=${this.min}\n max=${this.max}\n step=${this.step}\n .value=${live(String(this.value))}\n ?disabled=${this.isDisabled}\n aria-invalid=${error ? 'true' : 'false'}\n aria-describedby=${ifDefined(describedBy({ ...ids, hint: this.hint, hasHintSlot, error }))}\n @input=${this.#onInput}\n @change=${this.#onChange}\n />\n `,\n });\n }\n}\n\ndefineElement('uf-slider', UfSlider);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'uf-slider': UfSlider;\n }\n}\n",
|
|
@@ -812,5 +882,5 @@
|
|
|
812
882
|
"components/toast/toast.ts": "import { LitElement, css, html, nothing, type PropertyDeclarations } from 'lit';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { repeat } from 'lit/directives/repeat.js';\nimport { defineElement } from '../../internal/define.js';\nimport { Translator } from '../../internal/i18n.js';\nimport { iconSvg, icons } from '../../internal/icons.js';\n\nexport type ToastVariant = 'neutral' | 'accent' | 'info' | 'success' | 'warning' | 'danger';\nexport type ToasterPlacement = 'top-start' | 'top-center' | 'top-end' | 'bottom-start' | 'bottom-center' | 'bottom-end';\n\nexport interface ToastOptions {\n /** Bold first line. */\n title?: string;\n /** Color and icon. `danger` toasts are announced assertively. */\n variant?: ToastVariant;\n /** Milliseconds before it hides. `0` keeps it until dismissed. Defaults to 5000. */\n duration?: number;\n /** Shows a dismiss button. Defaults to true. */\n closable?: boolean;\n}\n\nexport interface ToastHandle {\n /** Hides the toast now. */\n dismiss(): void;\n}\n\ninterface ToastItem extends Required<Omit<ToastOptions, 'title'>> {\n id: number;\n title?: string;\n message: string;\n leaving: boolean;\n}\n\ninterface Timer {\n handle: number;\n started: number;\n remaining: number;\n}\n\nconst variantIcons = {\n neutral: null,\n accent: null,\n info: icons.info,\n success: icons['check-circle'],\n warning: icons['alert-triangle'],\n danger: icons['alert-circle'],\n} as const;\n\nconst MAX_TOASTS = 5;\nconst EXIT_MS = 200;\nlet nextId = 1;\n\n/**\n * The region that shows toasts. You rarely need to add it yourself: `toast()`\n * creates one on first use. Add it to choose a placement, or to hold\n * toasts in a specific place in the DOM.\n *\n * @summary Shows short, temporary notifications.\n * @tag uf-toaster\n *\n * @csspart region - The list holding the toasts.\n * @csspart toast - Each toast.\n * @csspart title - A toast's title.\n * @csspart message - A toast's message.\n * @csspart close-button - A toast's dismiss button.\n *\n * @cssprop --uf-toast-width - Width of each toast.\n * @cssprop --uf-toaster-offset - Distance from the viewport edges.\n */\nexport class UfToaster extends LitElement {\n static override styles = css`\n :host {\n --_offset: var(--uf-toaster-offset, var(--uf-space-4));\n position: fixed;\n inset: auto;\n margin: 0;\n padding: 0;\n border: 0;\n background: transparent;\n overflow: visible;\n width: min(var(--uf-toast-width, 22rem), calc(100vw - 2 * var(--_offset)));\n font-family: var(--uf-font-family-sans);\n }\n\n :host([placement^='top']) {\n top: var(--_offset);\n }\n :host([placement^='bottom']) {\n bottom: var(--_offset);\n }\n :host([placement$='start']) {\n left: var(--_offset);\n }\n :host([placement$='end']) {\n right: var(--_offset);\n }\n :host([placement$='center']) {\n left: 50%;\n translate: -50% 0;\n }\n\n ol {\n display: flex;\n flex-direction: column;\n gap: var(--uf-space-2);\n margin: 0;\n padding: 0;\n list-style: none;\n }\n\n :host([placement^='bottom']) ol {\n flex-direction: column-reverse;\n }\n\n .toast {\n --_bg: var(--uf-color-toast-neutral-bg);\n --_border: var(--uf-color-toast-neutral-border);\n --_text: var(--uf-color-toast-neutral-text);\n display: flex;\n align-items: flex-start;\n gap: var(--uf-space-3);\n padding: var(--uf-space-3) var(--uf-space-3) var(--uf-space-3) var(--uf-space-4);\n border: 1px solid var(--_border);\n border-radius: var(--uf-radius-md);\n background: var(--_bg);\n color: var(--_text);\n font-size: var(--uf-font-size-md);\n line-height: 1.45;\n box-shadow: var(--uf-shadow-md);\n animation: enter var(--uf-duration-base) ease;\n }\n\n .toast.leaving {\n opacity: 0;\n translate: 0 0.25rem;\n transition:\n opacity ${EXIT_MS}ms ease,\n translate ${EXIT_MS}ms ease;\n }\n\n .accent {\n --_bg: var(--uf-color-toast-accent-bg);\n --_border: var(--uf-color-toast-accent-border);\n --_text: var(--uf-color-toast-accent-text);\n }\n .info {\n --_bg: var(--uf-color-toast-info-bg);\n --_border: var(--uf-color-toast-info-border);\n --_text: var(--uf-color-toast-info-text);\n }\n .success {\n --_bg: var(--uf-color-toast-success-bg);\n --_border: var(--uf-color-toast-success-border);\n --_text: var(--uf-color-toast-success-text);\n }\n .warning {\n --_bg: var(--uf-color-toast-warning-bg);\n --_border: var(--uf-color-toast-warning-border);\n --_text: var(--uf-color-toast-warning-text);\n }\n .danger {\n --_bg: var(--uf-color-toast-danger-bg);\n --_border: var(--uf-color-toast-danger-border);\n --_text: var(--uf-color-toast-danger-text);\n }\n\n .icon {\n flex: none;\n width: 1.125rem;\n height: 1.125rem;\n margin-top: 0.1em;\n color: currentColor;\n }\n\n .content {\n flex: 1;\n min-width: 0;\n padding-block: 0.0625rem;\n }\n\n .title {\n display: block;\n font-weight: var(--uf-font-weight-semibold);\n }\n\n .title + .message {\n margin-top: 0.125rem;\n }\n\n\n .close {\n display: inline-flex;\n flex: none;\n align-items: center;\n justify-content: center;\n width: 1.75rem;\n height: 1.75rem;\n margin: -0.125rem -0.25rem 0 0;\n padding: 0;\n border: 0;\n border-radius: var(--uf-radius-sm);\n background: transparent;\n color: inherit;\n opacity: 0.8;\n cursor: pointer;\n }\n\n .close:hover {\n background: color-mix(in srgb, currentColor 16%, transparent);\n opacity: 1;\n }\n\n .close:focus-visible {\n outline: var(--uf-focus-ring-width) solid var(--uf-color-focus-ring);\n outline-offset: 0;\n }\n\n .close .icon {\n width: 1rem;\n height: 1rem;\n margin: 0;\n color: inherit;\n }\n\n @keyframes enter {\n from {\n opacity: 0;\n translate: 0 0.5rem;\n }\n }\n\n @media (prefers-reduced-motion: reduce) {\n .toast {\n animation: none;\n }\n .toast.leaving {\n transition: none;\n }\n }\n `;\n\n static override properties: PropertyDeclarations = {\n placement: { reflect: true },\n label: {},\n };\n\n /** Corner or edge of the viewport where toasts appear. */\n declare placement: ToasterPlacement;\n /** Accessible name of the notification region. Defaults to \"Notifications\", or its translation. */\n declare label: string | undefined;\n\n #items: ToastItem[] = [];\n readonly #translator = new Translator(this);\n readonly #timers = new Map<number, Timer>();\n\n constructor() {\n super();\n this.placement = 'bottom-end';\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n // The host itself is a manual popover, so toasts render in the top layer.\n this.popover = 'manual';\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n for (const timer of this.#timers.values()) clearTimeout(timer.handle);\n this.#timers.clear();\n }\n\n /** Shows a toast in this region. Prefer the `toast()` function. */\n add(message: string, options: ToastOptions = {}): ToastHandle {\n const item: ToastItem = {\n id: nextId++,\n message,\n title: options.title,\n variant: options.variant ?? 'neutral',\n duration: options.duration ?? 5000,\n closable: options.closable ?? true,\n leaving: false,\n };\n this.#items = [...this.#items, item];\n const overflow = this.#items.filter((i) => !i.leaving).length - MAX_TOASTS;\n if (overflow > 0) this.#items.filter((i) => !i.leaving).slice(0, overflow).forEach((i) => this.dismiss(i.id));\n\n this.#bringToFront();\n if (item.duration > 0) this.#startTimer(item.id, item.duration);\n this.requestUpdate();\n return { dismiss: () => this.dismiss(item.id) };\n }\n\n /** Hides a toast by id. */\n dismiss(id: number): void {\n const item = this.#items.find((i) => i.id === id);\n if (!item || item.leaving) return;\n clearTimeout(this.#timers.get(id)?.handle);\n this.#timers.delete(id);\n item.leaving = true;\n this.requestUpdate();\n\n const reduced = matchMedia('(prefers-reduced-motion: reduce)').matches;\n setTimeout(() => {\n this.#items = this.#items.filter((i) => i.id !== id);\n if (!this.#items.length && this.matches(':popover-open')) this.hidePopover();\n this.requestUpdate();\n }, reduced ? 0 : EXIT_MS);\n }\n\n /** Re-shows the popover, so toasts appear above a dialog opened after the last one. */\n #bringToFront(): void {\n if (this.matches(':popover-open')) this.hidePopover();\n this.showPopover();\n }\n\n #startTimer(id: number, ms: number): void {\n this.#timers.set(id, { handle: window.setTimeout(() => this.dismiss(id), ms), started: Date.now(), remaining: ms });\n }\n\n #pause(id: number): void {\n const timer = this.#timers.get(id);\n if (!timer) return;\n clearTimeout(timer.handle);\n timer.remaining -= Date.now() - timer.started;\n }\n\n #resume(id: number): void {\n const timer = this.#timers.get(id);\n if (timer) this.#startTimer(id, Math.max(timer.remaining, 1000));\n }\n\n #renderToast(item: ToastItem) {\n const icon = variantIcons[item.variant];\n return html`\n <li\n class=${classMap({ toast: true, [item.variant]: true, leaving: item.leaving })}\n part=\"toast\"\n role=${item.variant === 'danger' ? 'alert' : nothing}\n @pointerenter=${() => this.#pause(item.id)}\n @pointerleave=${() => this.#resume(item.id)}\n @focusin=${() => this.#pause(item.id)}\n @focusout=${() => this.#resume(item.id)}\n >\n ${icon ? iconSvg(icon) : nothing}\n <div class=\"content\">\n ${item.title ? html`<strong class=\"title\" part=\"title\">${item.title}</strong>` : nothing}\n <div class=\"message\" part=\"message\">${item.message}</div>\n </div>\n ${item.closable\n ? html`<button class=\"close\" part=\"close-button\" type=\"button\" aria-label=${this.#translator.t('dismiss')} @click=${() => this.dismiss(item.id)}>\n ${iconSvg(icons.x)}\n </button>`\n : nothing}\n </li>\n `;\n }\n\n override render() {\n return html`\n <section aria-label=${this.label ?? this.#translator.t('notifications')}>\n <ol part=\"region\" aria-live=\"polite\" aria-relevant=\"additions\">\n ${repeat(this.#items, (item) => item.id, (item) => this.#renderToast(item))}\n </ol>\n </section>\n `;\n }\n}\n\ndefineElement('uf-toaster', UfToaster);\n\n/**\n * Shows a toast. Creates a `<uf-toaster>` on first use. Does nothing on the\n * server, when rendering with SSR.\n *\n * @example toast('Saved', { variant: 'success' })\n */\nexport function toast(message: string, options?: ToastOptions): ToastHandle {\n // On the server (SSR) there is no page to show it on: do nothing.\n if (typeof document === 'undefined') return { dismiss() {} };\n let toaster = document.querySelector('uf-toaster');\n if (toaster) return toaster.add(message, options);\n\n // A live region must exist before content is added to it, or screen readers\n // may skip the first message. Create it now and add the toast a moment later.\n toaster = document.body.appendChild(document.createElement('uf-toaster'));\n let handle: ToastHandle | undefined;\n let dismissed = false;\n setTimeout(() => {\n if (!dismissed) handle = toaster.add(message, options);\n }, 100);\n return {\n dismiss() {\n dismissed = true;\n handle?.dismiss();\n },\n };\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'uf-toaster': UfToaster;\n }\n}\n",
|
|
813
883
|
"components/tooltip/tooltip.ts": "import { LitElement, css, html, type PropertyDeclarations, type PropertyValues } from 'lit';\nimport { defineElement } from '../../internal/define.js';\nimport { autoUpdate, positionFloating, type Placement } from '../../internal/position.js';\n\n/**\n * A short label that appears on hover and keyboard focus. Wrap the element it\n * describes. The text is also set as the trigger's `aria-description` (unless it\n * repeats the trigger's own label), so screen reader users get it too. Don't put\n * interactive content in a tooltip.\n *\n * @summary Shows a short hint for the element it wraps.\n * @tag uf-tooltip\n *\n * @slot - The element the tooltip describes.\n *\n * @event uf-show - The tooltip opened.\n * @event uf-hide - The tooltip closed.\n *\n * @csspart body - The tooltip bubble.\n *\n * @cssprop --uf-tooltip-bg - Background color.\n * @cssprop --uf-tooltip-color - Text color.\n * @cssprop --uf-tooltip-max-width - Maximum width.\n * @cssprop --uf-tooltip-radius - Corner radius. Square by default.\n */\nexport class UfTooltip extends LitElement {\n static override styles = css`\n :host {\n display: contents;\n }\n\n .body {\n position: fixed;\n inset: auto;\n margin: 0;\n max-width: var(--uf-tooltip-max-width, 18rem);\n padding: var(--uf-space-1) var(--uf-space-2);\n border: 0;\n border-radius: var(--uf-tooltip-radius, 0);\n background: var(--uf-tooltip-bg, var(--uf-color-text));\n color: var(--uf-tooltip-color, var(--uf-color-surface));\n font-family: var(--uf-font-family-sans);\n font-size: var(--uf-font-size-sm);\n line-height: 1.4;\n overflow: visible;\n opacity: 0;\n transition:\n opacity var(--uf-duration-fast) ease,\n overlay var(--uf-duration-fast) allow-discrete,\n display var(--uf-duration-fast) allow-discrete;\n }\n\n .body:popover-open {\n opacity: 1;\n }\n\n @starting-style {\n .body:popover-open {\n opacity: 0;\n }\n }\n `;\n\n static override properties: PropertyDeclarations = {\n content: {},\n placement: { reflect: true },\n disabled: { type: Boolean, reflect: true },\n delay: { type: Number },\n open: { type: Boolean, reflect: true },\n };\n\n /** The tooltip text. */\n declare content: string;\n /** Preferred side. Flips when there is no room. */\n declare placement: Placement;\n /** Turns the tooltip off. */\n declare disabled: boolean;\n /** Milliseconds to wait on hover before showing. Focus shows it immediately. */\n declare delay: number;\n /** Whether the tooltip is showing. */\n declare open: boolean;\n\n #timer = 0;\n #cleanup?: () => void;\n\n constructor() {\n super();\n this.content = '';\n this.placement = 'top';\n this.disabled = false;\n this.delay = 300;\n this.open = false;\n this.addEventListener('pointerenter', this.#onPointerEnter);\n this.addEventListener('pointerleave', this.#onLeave);\n this.addEventListener('focusin', this.#onFocusIn);\n this.addEventListener('focusout', this.#onLeave);\n }\n\n get #body(): HTMLElement | null {\n return this.renderRoot.querySelector('.body');\n }\n\n get #trigger(): HTMLElement | undefined {\n const slot = this.renderRoot.querySelector<HTMLSlotElement>('slot');\n return slot?.assignedElements()[0] as HTMLElement | undefined;\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n document.addEventListener('keydown', this.#onKeyDown);\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n document.removeEventListener('keydown', this.#onKeyDown);\n clearTimeout(this.#timer);\n this.#cleanup?.();\n }\n\n /** Shows the tooltip, unless it's disabled. */\n show(): void {\n if (!this.disabled) this.open = true;\n }\n\n /** Hides the tooltip. */\n hide(): void {\n clearTimeout(this.#timer);\n this.open = false;\n }\n\n override updated(changed: PropertyValues<this>): void {\n const trigger = this.#trigger;\n if (trigger && changed.has('content')) {\n // Skip when the tooltip repeats the trigger's name (icon buttons), or it's read twice.\n const name = trigger.getAttribute('aria-label') ?? (trigger as HTMLElement & { label?: string }).label;\n if (this.content && this.content !== name) trigger.setAttribute('aria-description', this.content);\n else trigger.removeAttribute('aria-description');\n }\n const body = this.#body;\n if (!changed.has('open') || !body) return;\n\n if (this.open && trigger && !body.matches(':popover-open')) {\n body.showPopover();\n this.#cleanup = autoUpdate(trigger, body, () => positionFloating(trigger, body, this.placement, 6));\n this.dispatchEvent(new Event('uf-show'));\n } else if (!this.open && body.matches(':popover-open')) {\n body.hidePopover();\n this.#cleanup?.();\n this.#cleanup = undefined;\n this.dispatchEvent(new Event('uf-hide'));\n }\n }\n\n #onPointerEnter = (): void => {\n clearTimeout(this.#timer);\n this.#timer = window.setTimeout(() => this.show(), this.delay);\n };\n\n #onFocusIn = (): void => this.show();\n\n #onLeave = (): void => this.hide();\n\n #onKeyDown = (event: KeyboardEvent): void => {\n if (event.key === 'Escape' && this.open) this.hide();\n };\n\n override render() {\n return html`\n <slot @slotchange=${() => this.requestUpdate('content')}></slot>\n <div class=\"body\" part=\"body\" popover=\"manual\" role=\"tooltip\">${this.content}</div>\n `;\n }\n}\n\ndefineElement('uf-tooltip', UfTooltip);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'uf-tooltip': UfTooltip;\n }\n}\n"
|
|
814
884
|
},
|
|
815
|
-
"tokens": "/* @unframed/tokens — generated by scripts/build.mjs, do not edit. */\n:root {\n --uf-palette-neutral-0: #ffffff;\n --uf-palette-neutral-50: #f7f6f9;\n --uf-palette-neutral-100: #efedf2;\n --uf-palette-neutral-200: #e1dfe6;\n --uf-palette-neutral-300: #c9c6d1;\n --uf-palette-neutral-400: #a29eae;\n --uf-palette-neutral-500: #7c778a;\n --uf-palette-neutral-600: #5d586b;\n --uf-palette-neutral-700: #464155;\n --uf-palette-neutral-750: #373442;\n --uf-palette-neutral-800: #302d38;\n --uf-palette-neutral-825: #28262e;\n --uf-palette-neutral-850: #212026;\n --uf-palette-neutral-900: #19191c;\n --uf-palette-neutral-925: #111312;\n --uf-palette-neutral-950: #0a0b08;\n --uf-palette-accent-50: #f3eefb;\n --uf-palette-accent-100: #e5dbf6;\n --uf-palette-accent-200: #cbb7ee;\n --uf-palette-accent-300: #ad8fe3;\n --uf-palette-accent-400: #9067d6;\n --uf-palette-accent-500: #7b47cc;\n --uf-palette-accent-600: #6930c3;\n --uf-palette-accent-700: #5726a3;\n --uf-palette-accent-800: #461f83;\n --uf-palette-accent-900: #361865;\n --uf-palette-accent-950: #1f0e3b;\n --uf-palette-danger-50: #fcedf0;\n --uf-palette-danger-100: #f8d3db;\n --uf-palette-danger-200: #f0a8b8;\n --uf-palette-danger-300: #e57d93;\n --uf-palette-danger-400: #d4566f;\n --uf-palette-danger-500: #b13650;\n --uf-palette-danger-600: #7c162e;\n --uf-palette-danger-700: #661126;\n --uf-palette-danger-800: #510d1e;\n --uf-palette-danger-900: #3d0a17;\n --uf-palette-danger-950: #24050d;\n --uf-palette-success-50: #f0fdf4;\n --uf-palette-success-100: #dcfce7;\n --uf-palette-success-400: #4ade80;\n --uf-palette-success-500: #22c55e;\n --uf-palette-success-600: #16a34a;\n --uf-palette-success-700: #15803d;\n --uf-palette-success-800: #166534;\n --uf-palette-success-950: #052e16;\n --uf-palette-warning-50: #fffbeb;\n --uf-palette-warning-100: #fef3c7;\n --uf-palette-warning-400: #fbbf24;\n --uf-palette-warning-500: #f59e0b;\n --uf-palette-warning-600: #d97706;\n --uf-palette-warning-700: #b45309;\n --uf-palette-warning-800: #92400e;\n --uf-palette-warning-950: #451a03;\n --uf-palette-info-50: #eef2fc;\n --uf-palette-info-100: #dbe3f8;\n --uf-palette-info-300: #93a8e6;\n --uf-palette-info-400: #6f88db;\n --uf-palette-info-600: #4763c9;\n --uf-palette-info-700: #3a51a8;\n --uf-palette-info-950: #121a36;\n --uf-palette-signal-blue: #4763c9;\n --uf-palette-signal-green: #1f7a66;\n --uf-palette-signal-orange: #f2a65a;\n --uf-palette-signal-orange-ink: #1b1407;\n --uf-font-family-sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;\n --uf-font-family-mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;\n --uf-font-size-sm: 0.8125rem;\n --uf-font-size-md: 0.875rem;\n --uf-font-size-lg: 1rem;\n --uf-font-weight-regular: 400;\n --uf-font-weight-medium: 500;\n --uf-font-weight-semibold: 600;\n --uf-radius-sm: 4px;\n --uf-radius-md: 8px;\n --uf-radius-lg: 12px;\n --uf-radius-full: 9999px;\n --uf-radius-control: 0px;\n --uf-space-1: 0.25rem;\n --uf-space-2: 0.5rem;\n --uf-space-3: 0.75rem;\n --uf-space-4: 1rem;\n --uf-space-5: 1.25rem;\n --uf-space-6: 1.5rem;\n --uf-size-control-sm: 2rem;\n --uf-size-control-md: 2.5rem;\n --uf-size-control-lg: 3rem;\n --uf-focus-ring-width: 2px;\n --uf-focus-ring-offset: 2px;\n --uf-duration-fast: 120ms;\n --uf-duration-base: 200ms;\n --uf-shadow-sm: 0 1px 2px rgb(0 0 0 / 0.06);\n --uf-shadow-md: 0 4px 12px rgb(0 0 0 / 0.10), 0 1px 3px rgb(0 0 0 / 0.08);\n --uf-shadow-lg: 0 16px 40px rgb(0 0 0 / 0.18), 0 4px 12px rgb(0 0 0 / 0.10);\n}\n\n:root,\n[data-uf-theme='light'] {\n color-scheme: light;\n --uf-color-surface: var(--uf-palette-neutral-0);\n --uf-color-surface-raised: var(--uf-palette-neutral-50);\n --uf-color-surface-overlay: var(--uf-palette-neutral-0);\n --uf-color-surface-hover: var(--uf-palette-neutral-100);\n --uf-color-surface-active: var(--uf-palette-neutral-200);\n --uf-color-text: var(--uf-palette-neutral-925);\n --uf-color-text-muted: var(--uf-palette-neutral-600);\n --uf-color-border: var(--uf-palette-neutral-200);\n --uf-color-border-strong: var(--uf-palette-neutral-500);\n --uf-color-accent: var(--uf-palette-accent-600);\n --uf-color-accent-hover: var(--uf-palette-accent-700);\n --uf-color-accent-active: var(--uf-palette-accent-800);\n --uf-color-accent-strong: var(--uf-palette-accent-600);\n --uf-color-accent-subtle: var(--uf-palette-accent-50);\n --uf-color-on-accent: var(--uf-palette-neutral-0);\n --uf-color-accent-tint: var(--uf-palette-accent-100);\n --uf-color-accent-tint-hover: var(--uf-palette-accent-200);\n --uf-color-accent-tint-active: var(--uf-palette-accent-300);\n --uf-color-on-accent-tint: var(--uf-palette-accent-900);\n --uf-color-neutral-fill: var(--uf-palette-neutral-100);\n --uf-color-danger: var(--uf-palette-danger-500);\n --uf-color-danger-hover: var(--uf-palette-danger-600);\n --uf-color-danger-subtle: var(--uf-palette-danger-50);\n --uf-color-danger-text: var(--uf-palette-danger-500);\n --uf-color-on-danger: var(--uf-palette-neutral-0);\n --uf-color-success: var(--uf-palette-success-700);\n --uf-color-success-subtle: var(--uf-palette-success-50);\n --uf-color-warning: var(--uf-palette-warning-700);\n --uf-color-warning-subtle: var(--uf-palette-warning-50);\n --uf-color-info: var(--uf-palette-info-700);\n --uf-color-info-subtle: var(--uf-palette-info-50);\n --uf-color-focus-ring: var(--uf-palette-accent-600);\n --uf-color-backdrop: var(--uf-palette-neutral-950);\n --uf-color-toast-neutral-bg: var(--uf-palette-neutral-800);\n --uf-color-toast-neutral-border: var(--uf-palette-neutral-800);\n --uf-color-toast-neutral-text: var(--uf-palette-neutral-0);\n --uf-color-toast-accent-bg: var(--uf-palette-accent-600);\n --uf-color-toast-accent-border: var(--uf-palette-accent-600);\n --uf-color-toast-accent-text: var(--uf-palette-neutral-0);\n --uf-color-toast-info-bg: var(--uf-palette-signal-blue);\n --uf-color-toast-info-border: var(--uf-palette-signal-blue);\n --uf-color-toast-info-text: var(--uf-palette-neutral-0);\n --uf-color-toast-success-bg: var(--uf-palette-signal-green);\n --uf-color-toast-success-border: var(--uf-palette-signal-green);\n --uf-color-toast-success-text: var(--uf-palette-neutral-0);\n --uf-color-toast-warning-bg: var(--uf-palette-signal-orange);\n --uf-color-toast-warning-border: var(--uf-palette-signal-orange);\n --uf-color-toast-warning-text: var(--uf-palette-signal-orange-ink);\n --uf-color-toast-danger-bg: var(--uf-palette-danger-500);\n --uf-color-toast-danger-border: var(--uf-palette-danger-500);\n --uf-color-toast-danger-text: var(--uf-palette-neutral-0);\n --uf-shadow-raised: var(--uf-shadow-md);\n --uf-shadow-overlay: var(--uf-shadow-md);\n --uf-shadow-modal: var(--uf-shadow-lg);\n --uf-shadow-drawer: 0 0 40px rgb(0 0 0 / 0.16), 0 0 12px rgb(0 0 0 / 0.08);\n}\n\n[data-uf-theme='dark'] {\n color-scheme: dark;\n --uf-color-surface: var(--uf-palette-neutral-950);\n --uf-color-surface-raised: var(--uf-palette-neutral-925);\n --uf-color-surface-overlay: var(--uf-palette-neutral-900);\n --uf-color-surface-hover: var(--uf-palette-neutral-850);\n --uf-color-surface-active: var(--uf-palette-neutral-825);\n --uf-color-text: var(--uf-palette-neutral-50);\n --uf-color-text-muted: var(--uf-palette-neutral-400);\n --uf-color-border: var(--uf-palette-neutral-825);\n --uf-color-border-strong: var(--uf-palette-neutral-500);\n --uf-color-accent: var(--uf-palette-accent-600);\n --uf-color-accent-hover: var(--uf-palette-accent-500);\n --uf-color-accent-active: var(--uf-palette-accent-700);\n --uf-color-accent-strong: var(--uf-palette-accent-300);\n --uf-color-accent-subtle: var(--uf-palette-accent-950);\n --uf-color-on-accent: var(--uf-palette-neutral-0);\n --uf-color-accent-tint: var(--uf-palette-accent-800);\n --uf-color-accent-tint-hover: var(--uf-palette-accent-700);\n --uf-color-accent-tint-active: var(--uf-palette-accent-900);\n --uf-color-on-accent-tint: var(--uf-palette-accent-200);\n --uf-color-neutral-fill: var(--uf-palette-neutral-800);\n --uf-color-danger: var(--uf-palette-danger-600);\n --uf-color-danger-hover: var(--uf-palette-danger-500);\n --uf-color-danger-subtle: var(--uf-palette-danger-950);\n --uf-color-danger-text: var(--uf-palette-danger-300);\n --uf-color-on-danger: var(--uf-palette-neutral-0);\n --uf-color-success: var(--uf-palette-success-400);\n --uf-color-success-subtle: var(--uf-palette-success-950);\n --uf-color-warning: var(--uf-palette-warning-400);\n --uf-color-warning-subtle: var(--uf-palette-warning-950);\n --uf-color-info: var(--uf-palette-info-300);\n --uf-color-info-subtle: var(--uf-palette-info-950);\n --uf-color-focus-ring: var(--uf-palette-accent-400);\n --uf-color-backdrop: var(--uf-palette-neutral-950);\n --uf-color-toast-neutral-bg: var(--uf-palette-neutral-750);\n --uf-color-toast-neutral-border: var(--uf-palette-neutral-700);\n --uf-color-toast-neutral-text: var(--uf-palette-neutral-0);\n --uf-color-toast-accent-bg: var(--uf-palette-accent-600);\n --uf-color-toast-accent-border: var(--uf-palette-accent-600);\n --uf-color-toast-accent-text: var(--uf-palette-neutral-0);\n --uf-color-toast-info-bg: var(--uf-palette-signal-blue);\n --uf-color-toast-info-border: var(--uf-palette-signal-blue);\n --uf-color-toast-info-text: var(--uf-palette-neutral-0);\n --uf-color-toast-success-bg: var(--uf-palette-signal-green);\n --uf-color-toast-success-border: var(--uf-palette-signal-green);\n --uf-color-toast-success-text: var(--uf-palette-neutral-0);\n --uf-color-toast-warning-bg: var(--uf-palette-signal-orange);\n --uf-color-toast-warning-border: var(--uf-palette-signal-orange);\n --uf-color-toast-warning-text: var(--uf-palette-signal-orange-ink);\n --uf-color-toast-danger-bg: var(--uf-palette-danger-600);\n --uf-color-toast-danger-border: var(--uf-palette-danger-600);\n --uf-color-toast-danger-text: var(--uf-palette-neutral-0);\n --uf-shadow-raised: 0 0 0 1px color-mix(in srgb, var(--uf-palette-accent-400) 30%, transparent), 0 12px 32px -8px color-mix(in srgb, var(--uf-palette-accent-600) 55%, transparent);\n --uf-shadow-overlay: 0 0 0 1px color-mix(in srgb, var(--uf-palette-accent-400) 25%, transparent), 0 8px 24px -6px color-mix(in srgb, var(--uf-palette-accent-600) 50%, transparent);\n --uf-shadow-modal: 0 0 0 1px color-mix(in srgb, var(--uf-palette-accent-400) 30%, transparent), 0 24px 64px -12px color-mix(in srgb, var(--uf-palette-accent-600) 60%, transparent);\n --uf-shadow-drawer: 0 0 0 1px color-mix(in srgb, var(--uf-palette-accent-400) 30%, transparent), 0 0 48px -8px color-mix(in srgb, var(--uf-palette-accent-600) 55%, transparent);\n}\n\n@media (prefers-color-scheme: dark) {\n :root:not([data-uf-theme='light']) {\n color-scheme: dark;\n --uf-color-surface: var(--uf-palette-neutral-950);\n --uf-color-surface-raised: var(--uf-palette-neutral-925);\n --uf-color-surface-overlay: var(--uf-palette-neutral-900);\n --uf-color-surface-hover: var(--uf-palette-neutral-850);\n --uf-color-surface-active: var(--uf-palette-neutral-825);\n --uf-color-text: var(--uf-palette-neutral-50);\n --uf-color-text-muted: var(--uf-palette-neutral-400);\n --uf-color-border: var(--uf-palette-neutral-825);\n --uf-color-border-strong: var(--uf-palette-neutral-500);\n --uf-color-accent: var(--uf-palette-accent-600);\n --uf-color-accent-hover: var(--uf-palette-accent-500);\n --uf-color-accent-active: var(--uf-palette-accent-700);\n --uf-color-accent-strong: var(--uf-palette-accent-300);\n --uf-color-accent-subtle: var(--uf-palette-accent-950);\n --uf-color-on-accent: var(--uf-palette-neutral-0);\n --uf-color-accent-tint: var(--uf-palette-accent-800);\n --uf-color-accent-tint-hover: var(--uf-palette-accent-700);\n --uf-color-accent-tint-active: var(--uf-palette-accent-900);\n --uf-color-on-accent-tint: var(--uf-palette-accent-200);\n --uf-color-neutral-fill: var(--uf-palette-neutral-800);\n --uf-color-danger: var(--uf-palette-danger-600);\n --uf-color-danger-hover: var(--uf-palette-danger-500);\n --uf-color-danger-subtle: var(--uf-palette-danger-950);\n --uf-color-danger-text: var(--uf-palette-danger-300);\n --uf-color-on-danger: var(--uf-palette-neutral-0);\n --uf-color-success: var(--uf-palette-success-400);\n --uf-color-success-subtle: var(--uf-palette-success-950);\n --uf-color-warning: var(--uf-palette-warning-400);\n --uf-color-warning-subtle: var(--uf-palette-warning-950);\n --uf-color-info: var(--uf-palette-info-300);\n --uf-color-info-subtle: var(--uf-palette-info-950);\n --uf-color-focus-ring: var(--uf-palette-accent-400);\n --uf-color-backdrop: var(--uf-palette-neutral-950);\n --uf-color-toast-neutral-bg: var(--uf-palette-neutral-750);\n --uf-color-toast-neutral-border: var(--uf-palette-neutral-700);\n --uf-color-toast-neutral-text: var(--uf-palette-neutral-0);\n --uf-color-toast-accent-bg: var(--uf-palette-accent-600);\n --uf-color-toast-accent-border: var(--uf-palette-accent-600);\n --uf-color-toast-accent-text: var(--uf-palette-neutral-0);\n --uf-color-toast-info-bg: var(--uf-palette-signal-blue);\n --uf-color-toast-info-border: var(--uf-palette-signal-blue);\n --uf-color-toast-info-text: var(--uf-palette-neutral-0);\n --uf-color-toast-success-bg: var(--uf-palette-signal-green);\n --uf-color-toast-success-border: var(--uf-palette-signal-green);\n --uf-color-toast-success-text: var(--uf-palette-neutral-0);\n --uf-color-toast-warning-bg: var(--uf-palette-signal-orange);\n --uf-color-toast-warning-border: var(--uf-palette-signal-orange);\n --uf-color-toast-warning-text: var(--uf-palette-signal-orange-ink);\n --uf-color-toast-danger-bg: var(--uf-palette-danger-600);\n --uf-color-toast-danger-border: var(--uf-palette-danger-600);\n --uf-color-toast-danger-text: var(--uf-palette-neutral-0);\n --uf-shadow-raised: 0 0 0 1px color-mix(in srgb, var(--uf-palette-accent-400) 30%, transparent), 0 12px 32px -8px color-mix(in srgb, var(--uf-palette-accent-600) 55%, transparent);\n --uf-shadow-overlay: 0 0 0 1px color-mix(in srgb, var(--uf-palette-accent-400) 25%, transparent), 0 8px 24px -6px color-mix(in srgb, var(--uf-palette-accent-600) 50%, transparent);\n --uf-shadow-modal: 0 0 0 1px color-mix(in srgb, var(--uf-palette-accent-400) 30%, transparent), 0 24px 64px -12px color-mix(in srgb, var(--uf-palette-accent-600) 60%, transparent);\n --uf-shadow-drawer: 0 0 0 1px color-mix(in srgb, var(--uf-palette-accent-400) 30%, transparent), 0 0 48px -8px color-mix(in srgb, var(--uf-palette-accent-600) 55%, transparent);\n }\n}\n\n/* Before the components load: no flash of raw content on server-rendered pages. */\n:where(uf-accordion, uf-accordion-item, uf-alert, uf-avatar, uf-badge, uf-breadcrumb-item, uf-breadcrumbs, uf-button, uf-calendar, uf-card, uf-checkbox, uf-checkbox-group, uf-combobox, uf-date-picker, uf-date-range-picker, uf-dialog, uf-divider, uf-drawer, uf-dropdown, uf-file-upload, uf-icon, uf-input, uf-menu, uf-menu-item, uf-number-input, uf-pagination, uf-popover, uf-progress, uf-radio, uf-radio-group, uf-select, uf-skeleton, uf-slider, uf-spinner, uf-switch, uf-tab, uf-tab-panel, uf-table, uf-tabs, uf-textarea, uf-toaster, uf-tooltip):not(:defined) {\n visibility: hidden;\n}\n\n:where(uf-dialog, uf-drawer, uf-toaster, uf-tab-panel):not(:defined),\n:where(uf-dropdown, uf-popover):not(:defined) > :not([slot]),\n:where(uf-select, uf-combobox):not(:defined) > :where(option, optgroup),\nuf-accordion-item:not(:defined):not([open]) > :not([slot]) {\n display: none;\n}\n"
|
|
885
|
+
"tokens": "/* @unframed/tokens — generated by scripts/build.mjs, do not edit. */\n:root {\n --uf-palette-neutral-0: #ffffff;\n --uf-palette-neutral-50: #f7f6f9;\n --uf-palette-neutral-100: #efedf2;\n --uf-palette-neutral-200: #e1dfe6;\n --uf-palette-neutral-300: #c9c6d1;\n --uf-palette-neutral-400: #a29eae;\n --uf-palette-neutral-500: #7c778a;\n --uf-palette-neutral-600: #5d586b;\n --uf-palette-neutral-700: #464155;\n --uf-palette-neutral-750: #373442;\n --uf-palette-neutral-800: #302d38;\n --uf-palette-neutral-825: #28262e;\n --uf-palette-neutral-850: #212026;\n --uf-palette-neutral-900: #19191c;\n --uf-palette-neutral-925: #111312;\n --uf-palette-neutral-950: #0a0b08;\n --uf-palette-accent-50: #f3eefb;\n --uf-palette-accent-100: #e5dbf6;\n --uf-palette-accent-200: #cbb7ee;\n --uf-palette-accent-300: #ad8fe3;\n --uf-palette-accent-400: #9067d6;\n --uf-palette-accent-500: #7b47cc;\n --uf-palette-accent-600: #6930c3;\n --uf-palette-accent-700: #5726a3;\n --uf-palette-accent-800: #461f83;\n --uf-palette-accent-900: #361865;\n --uf-palette-accent-950: #1f0e3b;\n --uf-palette-danger-50: #fcedf0;\n --uf-palette-danger-100: #f8d3db;\n --uf-palette-danger-200: #f0a8b8;\n --uf-palette-danger-300: #e57d93;\n --uf-palette-danger-400: #d4566f;\n --uf-palette-danger-500: #b13650;\n --uf-palette-danger-600: #7c162e;\n --uf-palette-danger-700: #661126;\n --uf-palette-danger-800: #510d1e;\n --uf-palette-danger-900: #3d0a17;\n --uf-palette-danger-950: #24050d;\n --uf-palette-success-50: #f0fdf4;\n --uf-palette-success-100: #dcfce7;\n --uf-palette-success-400: #4ade80;\n --uf-palette-success-500: #22c55e;\n --uf-palette-success-600: #16a34a;\n --uf-palette-success-700: #15803d;\n --uf-palette-success-800: #166534;\n --uf-palette-success-950: #052e16;\n --uf-palette-warning-50: #fffbeb;\n --uf-palette-warning-100: #fef3c7;\n --uf-palette-warning-400: #fbbf24;\n --uf-palette-warning-500: #f59e0b;\n --uf-palette-warning-600: #d97706;\n --uf-palette-warning-700: #b45309;\n --uf-palette-warning-800: #92400e;\n --uf-palette-warning-950: #451a03;\n --uf-palette-info-50: #eef2fc;\n --uf-palette-info-100: #dbe3f8;\n --uf-palette-info-300: #93a8e6;\n --uf-palette-info-400: #6f88db;\n --uf-palette-info-600: #4763c9;\n --uf-palette-info-700: #3a51a8;\n --uf-palette-info-950: #121a36;\n --uf-palette-signal-blue: #4763c9;\n --uf-palette-signal-green: #1f7a66;\n --uf-palette-signal-orange: #f2a65a;\n --uf-palette-signal-orange-ink: #1b1407;\n --uf-font-family-sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;\n --uf-font-family-mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;\n --uf-font-size-sm: 0.8125rem;\n --uf-font-size-md: 0.875rem;\n --uf-font-size-lg: 1rem;\n --uf-font-weight-regular: 400;\n --uf-font-weight-medium: 500;\n --uf-font-weight-semibold: 600;\n --uf-radius-sm: 4px;\n --uf-radius-md: 8px;\n --uf-radius-lg: 12px;\n --uf-radius-full: 9999px;\n --uf-radius-control: 0px;\n --uf-space-1: 0.25rem;\n --uf-space-2: 0.5rem;\n --uf-space-3: 0.75rem;\n --uf-space-4: 1rem;\n --uf-space-5: 1.25rem;\n --uf-space-6: 1.5rem;\n --uf-size-control-sm: 2rem;\n --uf-size-control-md: 2.5rem;\n --uf-size-control-lg: 3rem;\n --uf-focus-ring-width: 2px;\n --uf-focus-ring-offset: 2px;\n --uf-duration-fast: 120ms;\n --uf-duration-base: 200ms;\n --uf-shadow-sm: 0 1px 2px rgb(0 0 0 / 0.06);\n --uf-shadow-md: 0 4px 12px rgb(0 0 0 / 0.10), 0 1px 3px rgb(0 0 0 / 0.08);\n --uf-shadow-lg: 0 16px 40px rgb(0 0 0 / 0.18), 0 4px 12px rgb(0 0 0 / 0.10);\n}\n\n:root,\n[data-uf-theme='light'] {\n color-scheme: light;\n --uf-color-surface: var(--uf-palette-neutral-0);\n --uf-color-surface-raised: var(--uf-palette-neutral-50);\n --uf-color-surface-overlay: var(--uf-palette-neutral-0);\n --uf-color-surface-hover: var(--uf-palette-neutral-100);\n --uf-color-surface-active: var(--uf-palette-neutral-200);\n --uf-color-text: var(--uf-palette-neutral-925);\n --uf-color-text-muted: var(--uf-palette-neutral-600);\n --uf-color-border: var(--uf-palette-neutral-200);\n --uf-color-border-strong: var(--uf-palette-neutral-500);\n --uf-color-accent: var(--uf-palette-accent-600);\n --uf-color-accent-hover: var(--uf-palette-accent-700);\n --uf-color-accent-active: var(--uf-palette-accent-800);\n --uf-color-accent-strong: var(--uf-palette-accent-600);\n --uf-color-accent-subtle: var(--uf-palette-accent-50);\n --uf-color-on-accent: var(--uf-palette-neutral-0);\n --uf-color-accent-tint: var(--uf-palette-accent-100);\n --uf-color-accent-tint-hover: var(--uf-palette-accent-200);\n --uf-color-accent-tint-active: var(--uf-palette-accent-300);\n --uf-color-on-accent-tint: var(--uf-palette-accent-900);\n --uf-color-neutral-fill: var(--uf-palette-neutral-100);\n --uf-color-danger: var(--uf-palette-danger-500);\n --uf-color-danger-hover: var(--uf-palette-danger-600);\n --uf-color-danger-subtle: var(--uf-palette-danger-50);\n --uf-color-danger-text: var(--uf-palette-danger-500);\n --uf-color-on-danger: var(--uf-palette-neutral-0);\n --uf-color-success: var(--uf-palette-success-700);\n --uf-color-success-subtle: var(--uf-palette-success-50);\n --uf-color-warning: var(--uf-palette-warning-700);\n --uf-color-warning-subtle: var(--uf-palette-warning-50);\n --uf-color-info: var(--uf-palette-info-700);\n --uf-color-info-subtle: var(--uf-palette-info-50);\n --uf-color-focus-ring: var(--uf-palette-accent-600);\n --uf-color-backdrop: var(--uf-palette-neutral-950);\n --uf-color-toast-neutral-bg: var(--uf-palette-neutral-800);\n --uf-color-toast-neutral-border: var(--uf-palette-neutral-800);\n --uf-color-toast-neutral-text: var(--uf-palette-neutral-0);\n --uf-color-toast-accent-bg: var(--uf-palette-accent-600);\n --uf-color-toast-accent-border: var(--uf-palette-accent-600);\n --uf-color-toast-accent-text: var(--uf-palette-neutral-0);\n --uf-color-toast-info-bg: var(--uf-palette-signal-blue);\n --uf-color-toast-info-border: var(--uf-palette-signal-blue);\n --uf-color-toast-info-text: var(--uf-palette-neutral-0);\n --uf-color-toast-success-bg: var(--uf-palette-signal-green);\n --uf-color-toast-success-border: var(--uf-palette-signal-green);\n --uf-color-toast-success-text: var(--uf-palette-neutral-0);\n --uf-color-toast-warning-bg: var(--uf-palette-signal-orange);\n --uf-color-toast-warning-border: var(--uf-palette-signal-orange);\n --uf-color-toast-warning-text: var(--uf-palette-signal-orange-ink);\n --uf-color-toast-danger-bg: var(--uf-palette-danger-500);\n --uf-color-toast-danger-border: var(--uf-palette-danger-500);\n --uf-color-toast-danger-text: var(--uf-palette-neutral-0);\n --uf-shadow-raised: var(--uf-shadow-md);\n --uf-shadow-overlay: var(--uf-shadow-md);\n --uf-shadow-modal: var(--uf-shadow-lg);\n --uf-shadow-drawer: 0 0 40px rgb(0 0 0 / 0.16), 0 0 12px rgb(0 0 0 / 0.08);\n}\n\n[data-uf-theme='dark'] {\n color-scheme: dark;\n --uf-color-surface: var(--uf-palette-neutral-950);\n --uf-color-surface-raised: var(--uf-palette-neutral-925);\n --uf-color-surface-overlay: var(--uf-palette-neutral-900);\n --uf-color-surface-hover: var(--uf-palette-neutral-850);\n --uf-color-surface-active: var(--uf-palette-neutral-825);\n --uf-color-text: var(--uf-palette-neutral-50);\n --uf-color-text-muted: var(--uf-palette-neutral-400);\n --uf-color-border: var(--uf-palette-neutral-825);\n --uf-color-border-strong: var(--uf-palette-neutral-500);\n --uf-color-accent: var(--uf-palette-accent-600);\n --uf-color-accent-hover: var(--uf-palette-accent-500);\n --uf-color-accent-active: var(--uf-palette-accent-700);\n --uf-color-accent-strong: var(--uf-palette-accent-300);\n --uf-color-accent-subtle: var(--uf-palette-accent-950);\n --uf-color-on-accent: var(--uf-palette-neutral-0);\n --uf-color-accent-tint: var(--uf-palette-accent-800);\n --uf-color-accent-tint-hover: var(--uf-palette-accent-700);\n --uf-color-accent-tint-active: var(--uf-palette-accent-900);\n --uf-color-on-accent-tint: var(--uf-palette-accent-200);\n --uf-color-neutral-fill: var(--uf-palette-neutral-800);\n --uf-color-danger: var(--uf-palette-danger-600);\n --uf-color-danger-hover: var(--uf-palette-danger-500);\n --uf-color-danger-subtle: var(--uf-palette-danger-950);\n --uf-color-danger-text: var(--uf-palette-danger-300);\n --uf-color-on-danger: var(--uf-palette-neutral-0);\n --uf-color-success: var(--uf-palette-success-400);\n --uf-color-success-subtle: var(--uf-palette-success-950);\n --uf-color-warning: var(--uf-palette-warning-400);\n --uf-color-warning-subtle: var(--uf-palette-warning-950);\n --uf-color-info: var(--uf-palette-info-300);\n --uf-color-info-subtle: var(--uf-palette-info-950);\n --uf-color-focus-ring: var(--uf-palette-accent-400);\n --uf-color-backdrop: var(--uf-palette-neutral-950);\n --uf-color-toast-neutral-bg: var(--uf-palette-neutral-750);\n --uf-color-toast-neutral-border: var(--uf-palette-neutral-700);\n --uf-color-toast-neutral-text: var(--uf-palette-neutral-0);\n --uf-color-toast-accent-bg: var(--uf-palette-accent-600);\n --uf-color-toast-accent-border: var(--uf-palette-accent-600);\n --uf-color-toast-accent-text: var(--uf-palette-neutral-0);\n --uf-color-toast-info-bg: var(--uf-palette-signal-blue);\n --uf-color-toast-info-border: var(--uf-palette-signal-blue);\n --uf-color-toast-info-text: var(--uf-palette-neutral-0);\n --uf-color-toast-success-bg: var(--uf-palette-signal-green);\n --uf-color-toast-success-border: var(--uf-palette-signal-green);\n --uf-color-toast-success-text: var(--uf-palette-neutral-0);\n --uf-color-toast-warning-bg: var(--uf-palette-signal-orange);\n --uf-color-toast-warning-border: var(--uf-palette-signal-orange);\n --uf-color-toast-warning-text: var(--uf-palette-signal-orange-ink);\n --uf-color-toast-danger-bg: var(--uf-palette-danger-600);\n --uf-color-toast-danger-border: var(--uf-palette-danger-600);\n --uf-color-toast-danger-text: var(--uf-palette-neutral-0);\n --uf-shadow-raised: 0 0 0 1px color-mix(in srgb, var(--uf-palette-accent-400) 30%, transparent), 0 12px 32px -8px color-mix(in srgb, var(--uf-palette-accent-600) 55%, transparent);\n --uf-shadow-overlay: 0 0 0 1px color-mix(in srgb, var(--uf-palette-accent-400) 25%, transparent), 0 8px 24px -6px color-mix(in srgb, var(--uf-palette-accent-600) 50%, transparent);\n --uf-shadow-modal: 0 0 0 1px color-mix(in srgb, var(--uf-palette-accent-400) 30%, transparent), 0 24px 64px -12px color-mix(in srgb, var(--uf-palette-accent-600) 60%, transparent);\n --uf-shadow-drawer: 0 0 0 1px color-mix(in srgb, var(--uf-palette-accent-400) 30%, transparent), 0 0 48px -8px color-mix(in srgb, var(--uf-palette-accent-600) 55%, transparent);\n}\n\n@media (prefers-color-scheme: dark) {\n :root:not([data-uf-theme='light']) {\n color-scheme: dark;\n --uf-color-surface: var(--uf-palette-neutral-950);\n --uf-color-surface-raised: var(--uf-palette-neutral-925);\n --uf-color-surface-overlay: var(--uf-palette-neutral-900);\n --uf-color-surface-hover: var(--uf-palette-neutral-850);\n --uf-color-surface-active: var(--uf-palette-neutral-825);\n --uf-color-text: var(--uf-palette-neutral-50);\n --uf-color-text-muted: var(--uf-palette-neutral-400);\n --uf-color-border: var(--uf-palette-neutral-825);\n --uf-color-border-strong: var(--uf-palette-neutral-500);\n --uf-color-accent: var(--uf-palette-accent-600);\n --uf-color-accent-hover: var(--uf-palette-accent-500);\n --uf-color-accent-active: var(--uf-palette-accent-700);\n --uf-color-accent-strong: var(--uf-palette-accent-300);\n --uf-color-accent-subtle: var(--uf-palette-accent-950);\n --uf-color-on-accent: var(--uf-palette-neutral-0);\n --uf-color-accent-tint: var(--uf-palette-accent-800);\n --uf-color-accent-tint-hover: var(--uf-palette-accent-700);\n --uf-color-accent-tint-active: var(--uf-palette-accent-900);\n --uf-color-on-accent-tint: var(--uf-palette-accent-200);\n --uf-color-neutral-fill: var(--uf-palette-neutral-800);\n --uf-color-danger: var(--uf-palette-danger-600);\n --uf-color-danger-hover: var(--uf-palette-danger-500);\n --uf-color-danger-subtle: var(--uf-palette-danger-950);\n --uf-color-danger-text: var(--uf-palette-danger-300);\n --uf-color-on-danger: var(--uf-palette-neutral-0);\n --uf-color-success: var(--uf-palette-success-400);\n --uf-color-success-subtle: var(--uf-palette-success-950);\n --uf-color-warning: var(--uf-palette-warning-400);\n --uf-color-warning-subtle: var(--uf-palette-warning-950);\n --uf-color-info: var(--uf-palette-info-300);\n --uf-color-info-subtle: var(--uf-palette-info-950);\n --uf-color-focus-ring: var(--uf-palette-accent-400);\n --uf-color-backdrop: var(--uf-palette-neutral-950);\n --uf-color-toast-neutral-bg: var(--uf-palette-neutral-750);\n --uf-color-toast-neutral-border: var(--uf-palette-neutral-700);\n --uf-color-toast-neutral-text: var(--uf-palette-neutral-0);\n --uf-color-toast-accent-bg: var(--uf-palette-accent-600);\n --uf-color-toast-accent-border: var(--uf-palette-accent-600);\n --uf-color-toast-accent-text: var(--uf-palette-neutral-0);\n --uf-color-toast-info-bg: var(--uf-palette-signal-blue);\n --uf-color-toast-info-border: var(--uf-palette-signal-blue);\n --uf-color-toast-info-text: var(--uf-palette-neutral-0);\n --uf-color-toast-success-bg: var(--uf-palette-signal-green);\n --uf-color-toast-success-border: var(--uf-palette-signal-green);\n --uf-color-toast-success-text: var(--uf-palette-neutral-0);\n --uf-color-toast-warning-bg: var(--uf-palette-signal-orange);\n --uf-color-toast-warning-border: var(--uf-palette-signal-orange);\n --uf-color-toast-warning-text: var(--uf-palette-signal-orange-ink);\n --uf-color-toast-danger-bg: var(--uf-palette-danger-600);\n --uf-color-toast-danger-border: var(--uf-palette-danger-600);\n --uf-color-toast-danger-text: var(--uf-palette-neutral-0);\n --uf-shadow-raised: 0 0 0 1px color-mix(in srgb, var(--uf-palette-accent-400) 30%, transparent), 0 12px 32px -8px color-mix(in srgb, var(--uf-palette-accent-600) 55%, transparent);\n --uf-shadow-overlay: 0 0 0 1px color-mix(in srgb, var(--uf-palette-accent-400) 25%, transparent), 0 8px 24px -6px color-mix(in srgb, var(--uf-palette-accent-600) 50%, transparent);\n --uf-shadow-modal: 0 0 0 1px color-mix(in srgb, var(--uf-palette-accent-400) 30%, transparent), 0 24px 64px -12px color-mix(in srgb, var(--uf-palette-accent-600) 60%, transparent);\n --uf-shadow-drawer: 0 0 0 1px color-mix(in srgb, var(--uf-palette-accent-400) 30%, transparent), 0 0 48px -8px color-mix(in srgb, var(--uf-palette-accent-600) 55%, transparent);\n }\n}\n\n/* Before the components load: no flash of raw content on server-rendered pages. */\n:where(uf-accordion, uf-accordion-item, uf-alert, uf-avatar, uf-badge, uf-breadcrumb-item, uf-breadcrumbs, uf-button, uf-calendar, uf-card, uf-checkbox, uf-checkbox-group, uf-combobox, uf-date-picker, uf-date-range-picker, uf-dialog, uf-divider, uf-drawer, uf-dropdown, uf-empty-state, uf-file-upload, uf-icon, uf-input, uf-menu, uf-menu-item, uf-multi-select, uf-number-input, uf-pagination, uf-popover, uf-progress, uf-radio, uf-radio-group, uf-segmented-control, uf-select, uf-skeleton, uf-slider, uf-spinner, uf-switch, uf-tab, uf-tab-panel, uf-table, uf-tabs, uf-textarea, uf-toaster, uf-tooltip):not(:defined) {\n visibility: hidden;\n}\n\n:where(uf-dialog, uf-drawer, uf-toaster, uf-tab-panel):not(:defined),\n:where(uf-dropdown, uf-popover):not(:defined) > :not([slot]),\n:where(uf-select, uf-combobox, uf-multi-select, uf-segmented-control):not(:defined) > :where(option, optgroup),\nuf-accordion-item:not(:defined):not([open]) > :not([slot]) {\n display: none;\n}\n"
|
|
816
886
|
}
|
package/skill/unframed/SKILL.md
CHANGED
|
@@ -5,7 +5,7 @@ description: Builds UI with Unframed web components (@unframed/core, @unframed/r
|
|
|
5
5
|
|
|
6
6
|
# Unframed UI
|
|
7
7
|
|
|
8
|
-
Unframed 0.
|
|
8
|
+
Unframed 0.13.0: accessible UI components as standard custom elements (Lit). Every tag starts with `uf-`. They work in plain HTML and every framework; React, Vue and Angular have wrapper packages for typed props, events and form bindings.
|
|
9
9
|
|
|
10
10
|
## Before writing code
|
|
11
11
|
|
|
@@ -49,14 +49,17 @@ Unframed 0.12.0: accessible UI components as standard custom elements (Lit). Eve
|
|
|
49
49
|
| Divider: Separates groups of content with a line. | `<uf-divider>` | `@unframed/core/divider` |
|
|
50
50
|
| Drawer: A panel that slides in from an edge of the screen. | `<uf-drawer>` | `@unframed/core/drawer` |
|
|
51
51
|
| Dropdown menu: Opens a menu of actions from a button. | `<uf-dropdown>` `<uf-menu>` `<uf-menu-item>` | `@unframed/core/dropdown` `@unframed/core/menu` |
|
|
52
|
+
| Empty state: Fills an empty list or page with a message and what to do next. | `<uf-empty-state>` | `@unframed/core/empty-state` |
|
|
52
53
|
| File upload: Lets users choose files to upload. | `<uf-file-upload>` | `@unframed/core/file-upload` |
|
|
53
54
|
| Icon: Shows a small symbol. | `<uf-icon>` | `@unframed/core/icon` |
|
|
54
55
|
| Input: Lets users enter a single line of text. | `<uf-input>` | `@unframed/core/input` |
|
|
56
|
+
| Multi-select: Lets users search a list and pick several options. | `<uf-multi-select>` | `@unframed/core/multi-select` |
|
|
55
57
|
| Number input: Lets users enter a number, or step it with buttons. | `<uf-number-input>` | `@unframed/core/number-input` |
|
|
56
58
|
| Pagination: Moves between the pages of a long list. | `<uf-pagination>` | `@unframed/core/pagination` |
|
|
57
59
|
| Popover: Shows floating content next to a trigger. | `<uf-popover>` | `@unframed/core/popover` |
|
|
58
60
|
| Progress: Shows how far a task has got. | `<uf-progress>` | `@unframed/core/progress` |
|
|
59
61
|
| Radio group: Lets users pick exactly one option from a list. | `<uf-radio-group>` `<uf-radio>` | `@unframed/core/radio-group` `@unframed/core/radio` |
|
|
62
|
+
| Segmented control: Picks one of a few options, side by side. | `<uf-segmented-control>` | `@unframed/core/segmented-control` |
|
|
60
63
|
| Select: Lets users pick one option from a dropdown list. | `<uf-select>` | `@unframed/core/select` |
|
|
61
64
|
| Skeleton: Holds the place of content while it loads. | `<uf-skeleton>` | `@unframed/core/skeleton` |
|
|
62
65
|
| Slider: Lets users pick a number in a range. | `<uf-slider>` | `@unframed/core/slider` |
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Unframed 0.
|
|
1
|
+
# Unframed 0.13.0 components
|
|
2
2
|
|
|
3
3
|
## Accordion
|
|
4
4
|
|
|
@@ -1572,6 +1572,75 @@ Arrow keys move, typing a letter jumps to an item, Escape closes.
|
|
|
1572
1572
|
| `checkmark` | The check shown for checked checkbox items. |
|
|
1573
1573
|
| `label` | The label wrapper. |
|
|
1574
1574
|
|
|
1575
|
+
## Empty state
|
|
1576
|
+
|
|
1577
|
+
What to show where content would be: an empty list, no search results, a
|
|
1578
|
+
first visit. An icon, a heading, a short explanation and what to do next.
|
|
1579
|
+
|
|
1580
|
+
The `heading` attribute is bold text. For a real heading in the page's
|
|
1581
|
+
outline, put an `<h2>` or `<h3>` in the `heading` slot.
|
|
1582
|
+
|
|
1583
|
+
Tags: `<uf-empty-state>`. Import: `import '@unframed/core/empty-state';` (or `npx @unframed/cli add empty-state` to copy the source).
|
|
1584
|
+
|
|
1585
|
+
### Basic
|
|
1586
|
+
|
|
1587
|
+
An icon, a heading, a short explanation and what to do next.
|
|
1588
|
+
|
|
1589
|
+
```html
|
|
1590
|
+
<uf-empty-state heading="No projects yet">
|
|
1591
|
+
Projects keep your files and your team together.
|
|
1592
|
+
<uf-button slot="actions">New project</uf-button>
|
|
1593
|
+
</uf-empty-state>
|
|
1594
|
+
```
|
|
1595
|
+
|
|
1596
|
+
### No search results
|
|
1597
|
+
|
|
1598
|
+
Another `icon`, and a real heading in the `heading` slot when it belongs in the page outline.
|
|
1599
|
+
|
|
1600
|
+
```html
|
|
1601
|
+
<uf-empty-state icon="search">
|
|
1602
|
+
<h3 slot="heading">No results for “invoice 2019”</h3>
|
|
1603
|
+
Check the spelling, or try a shorter search.
|
|
1604
|
+
<uf-button slot="actions" variant="outline">Clear search</uf-button>
|
|
1605
|
+
</uf-empty-state>
|
|
1606
|
+
```
|
|
1607
|
+
|
|
1608
|
+
### `<uf-empty-state>` API
|
|
1609
|
+
|
|
1610
|
+
#### Attributes and properties
|
|
1611
|
+
|
|
1612
|
+
| Attribute | Property | Type | Default | Description |
|
|
1613
|
+
|---|---|---|---|---|
|
|
1614
|
+
| `heading` | | `string \| undefined` | | Bold text above the explanation. |
|
|
1615
|
+
| `icon` | | `string` | `'inbox'` | A built-in or registered icon name. An empty string hides the icon. |
|
|
1616
|
+
|
|
1617
|
+
#### Slots
|
|
1618
|
+
|
|
1619
|
+
| Slot | Description |
|
|
1620
|
+
|---|---|
|
|
1621
|
+
| (default) | The explanation. |
|
|
1622
|
+
| `heading` | The heading, when you need markup or a heading level. Overrides `heading`. |
|
|
1623
|
+
| `icon` | Replaces the icon. |
|
|
1624
|
+
| `actions` | Buttons or links, like "Create a project". |
|
|
1625
|
+
|
|
1626
|
+
#### CSS parts
|
|
1627
|
+
|
|
1628
|
+
| Part | Description |
|
|
1629
|
+
|---|---|
|
|
1630
|
+
| `base` | The empty state. |
|
|
1631
|
+
| `icon` | The icon. |
|
|
1632
|
+
| `heading` | The heading. |
|
|
1633
|
+
| `description` | The explanation. |
|
|
1634
|
+
| `actions` | The wrapper around the actions. |
|
|
1635
|
+
|
|
1636
|
+
#### CSS custom properties
|
|
1637
|
+
|
|
1638
|
+
| Property | Description |
|
|
1639
|
+
|---|---|
|
|
1640
|
+
| `--uf-empty-state-icon-size` | Size of the icon. |
|
|
1641
|
+
| `--uf-empty-state-icon-color` | Color of the icon. |
|
|
1642
|
+
| `--uf-empty-state-padding` | Space around the content. |
|
|
1643
|
+
|
|
1575
1644
|
## File upload
|
|
1576
1645
|
|
|
1577
1646
|
Picks files to send with a form: from a button, or by dragging them onto the
|
|
@@ -1833,6 +1902,130 @@ Errors appear after the user edits the field or tries to submit.
|
|
|
1833
1902
|
| `--uf-field-border-color` | Border color of the box. |
|
|
1834
1903
|
| `--uf-field-radius` | Corner radius of the box. |
|
|
1835
1904
|
|
|
1905
|
+
## Multi-select
|
|
1906
|
+
|
|
1907
|
+
A field to pick several options from a list you can search. The picked ones
|
|
1908
|
+
show as chips in the field, each with a remove button. Write options as plain
|
|
1909
|
+
`<option>` and `<optgroup>` children; `selected` ones start picked.
|
|
1910
|
+
|
|
1911
|
+
It follows the WAI-ARIA combobox pattern with a multi-select listbox: typing
|
|
1912
|
+
filters the list, arrow keys move through it, Enter picks or unpicks an
|
|
1913
|
+
option and keeps the list open, and Backspace in an empty field removes the
|
|
1914
|
+
last chip. With a `name`, every picked value is submitted with the form.
|
|
1915
|
+
|
|
1916
|
+
Tags: `<uf-multi-select>`. Import: `import '@unframed/core/multi-select';` (or `npx @unframed/cli add multi-select` to copy the source).
|
|
1917
|
+
|
|
1918
|
+
### Basic
|
|
1919
|
+
|
|
1920
|
+
Type to filter, Enter or a click to pick, and the list stays open for the next one. Backspace removes the last chip. The value is an array, in the order of the options.
|
|
1921
|
+
|
|
1922
|
+
```html
|
|
1923
|
+
<uf-multi-select name="toppings" label="Toppings" placeholder="Pick toppings">
|
|
1924
|
+
<option value="cheese" selected>Cheese</option>
|
|
1925
|
+
<option value="olives">Olives</option>
|
|
1926
|
+
<option value="basil">Basil</option>
|
|
1927
|
+
<option value="ham" disabled>Ham (sold out)</option>
|
|
1928
|
+
</uf-multi-select>
|
|
1929
|
+
```
|
|
1930
|
+
|
|
1931
|
+
- With a `name`, every picked value is submitted under that name, like a native `<select multiple>`: read them with `formData.getAll(name)`.
|
|
1932
|
+
|
|
1933
|
+
### Groups and validation
|
|
1934
|
+
|
|
1935
|
+
```html
|
|
1936
|
+
<uf-multi-select name="languages" label="Languages" hint="Pick at least one." required>
|
|
1937
|
+
<optgroup label="Europe">
|
|
1938
|
+
<option>English</option>
|
|
1939
|
+
<option>Italian</option>
|
|
1940
|
+
</optgroup>
|
|
1941
|
+
<optgroup label="Asia">
|
|
1942
|
+
<option>Japanese</option>
|
|
1943
|
+
</optgroup>
|
|
1944
|
+
</uf-multi-select>
|
|
1945
|
+
```
|
|
1946
|
+
|
|
1947
|
+
### `<uf-multi-select>` API
|
|
1948
|
+
|
|
1949
|
+
#### Attributes and properties
|
|
1950
|
+
|
|
1951
|
+
| Attribute | Property | Type | Default | Description |
|
|
1952
|
+
|---|---|---|---|---|
|
|
1953
|
+
| `label` | | `string \| undefined` | | Visible label. |
|
|
1954
|
+
| `hint` | | `string \| undefined` | | Help text below the field. |
|
|
1955
|
+
| `placeholder` | | `string \| undefined` | | Placeholder text in the field, while nothing is picked. |
|
|
1956
|
+
| `size` | | `FieldSize` | `'md'` | Size of the field. |
|
|
1957
|
+
| `open` | | `boolean` | `false` | Whether the list is showing. |
|
|
1958
|
+
| `name` | | `string` | `''` | Name submitted with the form. |
|
|
1959
|
+
| `disabled` | | `boolean` | `false` | Disables the control. |
|
|
1960
|
+
| `required` | | `boolean` | `false` | Makes the control required for form submission. |
|
|
1961
|
+
|
|
1962
|
+
#### Properties only
|
|
1963
|
+
|
|
1964
|
+
| Property | Type | Description |
|
|
1965
|
+
|---|---|---|
|
|
1966
|
+
| `value` | `string[]` | The picked options' values, in the order of the options. |
|
|
1967
|
+
| `form` | `HTMLFormElement \| null` | Read-only. The form this control belongs to, if any. |
|
|
1968
|
+
| `validity` | `ValidityState` | Read-only. The control's validity state, like a native input's. |
|
|
1969
|
+
| `validationMessage` | `string` | Read-only. The error message shown when the value is invalid. |
|
|
1970
|
+
| `willValidate` | `boolean` | Read-only. Whether the control takes part in form validation. |
|
|
1971
|
+
|
|
1972
|
+
#### Methods
|
|
1973
|
+
|
|
1974
|
+
| Method | Description |
|
|
1975
|
+
|---|---|
|
|
1976
|
+
| `show()` | Opens the list. |
|
|
1977
|
+
| `hide()` | Closes the list. |
|
|
1978
|
+
| `checkValidity()` | Returns whether the value is valid, without showing an error. |
|
|
1979
|
+
| `reportValidity()` | Returns whether the value is valid, and shows the error if not. |
|
|
1980
|
+
| `setCustomValidity(message: string)` | Sets a custom error message. Pass an empty string to clear it. |
|
|
1981
|
+
|
|
1982
|
+
#### Events
|
|
1983
|
+
|
|
1984
|
+
| Event | Type | Description |
|
|
1985
|
+
|---|---|---|
|
|
1986
|
+
| `uf-show` | `Event` | The list opened. |
|
|
1987
|
+
| `uf-hide` | `Event` | The list closed. |
|
|
1988
|
+
| `input` | | Fired as the user types in the field (the search text, not the value). |
|
|
1989
|
+
| `change` | `Event` | Fired when an option is picked or removed. |
|
|
1990
|
+
|
|
1991
|
+
#### Slots
|
|
1992
|
+
|
|
1993
|
+
| Slot | Description |
|
|
1994
|
+
|---|---|
|
|
1995
|
+
| (default) | `<option>` and `<optgroup>` elements. They are read, not rendered. |
|
|
1996
|
+
| `label` | The label, when you need markup. Overrides `label`. |
|
|
1997
|
+
| `hint` | Help text below the field. Overrides `hint`. |
|
|
1998
|
+
|
|
1999
|
+
#### CSS parts
|
|
2000
|
+
|
|
2001
|
+
| Part | Description |
|
|
2002
|
+
|---|---|
|
|
2003
|
+
| `field` | The wrapper around label, control, hint and error. |
|
|
2004
|
+
| `form-label` | The label. |
|
|
2005
|
+
| `box` | The bordered box with the chips and the input. |
|
|
2006
|
+
| `chips` | The list of picked options. |
|
|
2007
|
+
| `chip` | A picked option. |
|
|
2008
|
+
| `chip-remove` | A chip's remove button. |
|
|
2009
|
+
| `input` | The native `<input>`. |
|
|
2010
|
+
| `toggle` | The button that opens the list. |
|
|
2011
|
+
| `listbox` | The floating list. |
|
|
2012
|
+
| `option` | Each option. |
|
|
2013
|
+
| `group-label` | Each group heading. |
|
|
2014
|
+
| `empty` | The "no results" message. |
|
|
2015
|
+
| `hint` | The hint text. |
|
|
2016
|
+
| `error` | The validation message. |
|
|
2017
|
+
|
|
2018
|
+
#### CSS custom properties
|
|
2019
|
+
|
|
2020
|
+
| Property | Description |
|
|
2021
|
+
|---|---|
|
|
2022
|
+
| `--uf-multi-select-max-height` | Maximum height of the list before it scrolls. |
|
|
2023
|
+
| `--uf-multi-select-chip-bg` | Background of the chips. |
|
|
2024
|
+
| `--uf-multi-select-chip-color` | Text color of the chips. |
|
|
2025
|
+
| `--uf-field-bg` | Background of the box. |
|
|
2026
|
+
| `--uf-field-border-color` | Border color of the box. |
|
|
2027
|
+
| `--uf-field-radius` | Corner radius of the box. |
|
|
2028
|
+
|
|
1836
2029
|
## Number input
|
|
1837
2030
|
|
|
1838
2031
|
A field for a number, with buttons to step it down and up. The value is a
|
|
@@ -2250,6 +2443,109 @@ Arrow keys move the selection; only the selected radio is in the tab order.
|
|
|
2250
2443
|
| `--uf-radio-size` | Size of the circle. |
|
|
2251
2444
|
| `--uf-radio-checked-bg` | Color of the circle when checked. |
|
|
2252
2445
|
|
|
2446
|
+
## Segmented control
|
|
2447
|
+
|
|
2448
|
+
A row of buttons for one choice among a few, like "List / Grid" or "Day /
|
|
2449
|
+
Week / Month". The choices are plain `<option>` children. One is always
|
|
2450
|
+
selected: the `value` attribute, an option marked `selected`, or the first.
|
|
2451
|
+
|
|
2452
|
+
It's a radio group for assistive tech: arrow keys move and select, Home and
|
|
2453
|
+
End jump to the ends, and it submits its value with a form.
|
|
2454
|
+
|
|
2455
|
+
Tags: `<uf-segmented-control>`. Import: `import '@unframed/core/segmented-control';` (or `npx @unframed/cli add segmented-control` to copy the source).
|
|
2456
|
+
|
|
2457
|
+
### Basic
|
|
2458
|
+
|
|
2459
|
+
One choice among a few, always with one picked: the `value` attribute, a `selected` option, or the first. Arrow keys move and pick.
|
|
2460
|
+
|
|
2461
|
+
```html
|
|
2462
|
+
<uf-segmented-control name="view" label="View" value="week">
|
|
2463
|
+
<option value="day">Day</option>
|
|
2464
|
+
<option value="week">Week</option>
|
|
2465
|
+
<option value="month">Month</option>
|
|
2466
|
+
<option value="year" disabled>Year</option>
|
|
2467
|
+
</uf-segmented-control>
|
|
2468
|
+
```
|
|
2469
|
+
|
|
2470
|
+
- For more than five or six options, or long labels, use a select or a radio group instead.
|
|
2471
|
+
|
|
2472
|
+
### Sizes
|
|
2473
|
+
|
|
2474
|
+
```html
|
|
2475
|
+
<uf-segmented-control size="sm" label="Layout">
|
|
2476
|
+
<option>List</option>
|
|
2477
|
+
<option>Grid</option>
|
|
2478
|
+
</uf-segmented-control>
|
|
2479
|
+
```
|
|
2480
|
+
|
|
2481
|
+
### `<uf-segmented-control>` API
|
|
2482
|
+
|
|
2483
|
+
#### Attributes and properties
|
|
2484
|
+
|
|
2485
|
+
| Attribute | Property | Type | Default | Description |
|
|
2486
|
+
|---|---|---|---|---|
|
|
2487
|
+
| `value` | `defaultValue` | `string \| undefined` | | Initially selected value, restored on form reset. Set with the `value` attribute. |
|
|
2488
|
+
| `label` | | `string \| undefined` | | Visible label, also the group's accessible name. |
|
|
2489
|
+
| `hint` | | `string \| undefined` | | Help text below the options. |
|
|
2490
|
+
| `size` | | `FieldSize` | `'md'` | Size of the buttons. |
|
|
2491
|
+
| `name` | | `string` | `''` | Name submitted with the form. |
|
|
2492
|
+
| `disabled` | | `boolean` | `false` | Disables the control. |
|
|
2493
|
+
| `required` | | `boolean` | `false` | Makes the control required for form submission. |
|
|
2494
|
+
|
|
2495
|
+
#### Properties only
|
|
2496
|
+
|
|
2497
|
+
| Property | Type | Description |
|
|
2498
|
+
|---|---|---|
|
|
2499
|
+
| `value` | `string` | The selected option's value. |
|
|
2500
|
+
| `form` | `HTMLFormElement \| null` | Read-only. The form this control belongs to, if any. |
|
|
2501
|
+
| `validity` | `ValidityState` | Read-only. The control's validity state, like a native input's. |
|
|
2502
|
+
| `validationMessage` | `string` | Read-only. The error message shown when the value is invalid. |
|
|
2503
|
+
| `willValidate` | `boolean` | Read-only. Whether the control takes part in form validation. |
|
|
2504
|
+
|
|
2505
|
+
#### Methods
|
|
2506
|
+
|
|
2507
|
+
| Method | Description |
|
|
2508
|
+
|---|---|
|
|
2509
|
+
| `focus(options: FocusOptions)` | Moves focus to the selected option. |
|
|
2510
|
+
| `checkValidity()` | Returns whether the value is valid, without showing an error. |
|
|
2511
|
+
| `reportValidity()` | Returns whether the value is valid, and shows the error if not. |
|
|
2512
|
+
| `setCustomValidity(message: string)` | Sets a custom error message. Pass an empty string to clear it. |
|
|
2513
|
+
|
|
2514
|
+
#### Events
|
|
2515
|
+
|
|
2516
|
+
| Event | Type | Description |
|
|
2517
|
+
|---|---|---|
|
|
2518
|
+
| `input` | `Event` | The user picked another option. |
|
|
2519
|
+
| `change` | `Event` | The user picked another option. |
|
|
2520
|
+
|
|
2521
|
+
#### Slots
|
|
2522
|
+
|
|
2523
|
+
| Slot | Description |
|
|
2524
|
+
|---|---|
|
|
2525
|
+
| (default) | `<option>` elements. `disabled` options can't be picked. |
|
|
2526
|
+
| `label` | The label, when you need markup. Overrides `label`. |
|
|
2527
|
+
| `hint` | Help text below the options. Overrides `hint`. |
|
|
2528
|
+
|
|
2529
|
+
#### CSS parts
|
|
2530
|
+
|
|
2531
|
+
| Part | Description |
|
|
2532
|
+
|---|---|
|
|
2533
|
+
| `base` | The element with `role="radiogroup"`. |
|
|
2534
|
+
| `form-label` | The label. |
|
|
2535
|
+
| `options` | The row of buttons. |
|
|
2536
|
+
| `option` | One button. The selected one also has the part `selected`. |
|
|
2537
|
+
| `selected` | The selected button. |
|
|
2538
|
+
| `hint` | The hint text. |
|
|
2539
|
+
|
|
2540
|
+
#### CSS custom properties
|
|
2541
|
+
|
|
2542
|
+
| Property | Description |
|
|
2543
|
+
|---|---|
|
|
2544
|
+
| `--uf-segmented-control-bg` | Background behind the buttons. |
|
|
2545
|
+
| `--uf-segmented-control-selected-bg` | Background of the selected button. |
|
|
2546
|
+
| `--uf-segmented-control-selected-color` | Text color of the selected button. |
|
|
2547
|
+
| `--uf-segmented-control-radius` | Corner radius of the row. |
|
|
2548
|
+
|
|
2253
2549
|
## Select
|
|
2254
2550
|
|
|
2255
2551
|
A dropdown built on the native `<select>`, so it gets the platform's
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Using Unframed 0.
|
|
1
|
+
# Using Unframed 0.13.0 in each framework
|
|
2
2
|
|
|
3
3
|
## HTML & JavaScript
|
|
4
4
|
|
|
@@ -68,8 +68,8 @@ dialog.addEventListener('uf-hide', () => toast('Welcome aboard!', { variant: 'su
|
|
|
68
68
|
<!doctype html>
|
|
69
69
|
<html lang="en">
|
|
70
70
|
<head>
|
|
71
|
-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@unframed/tokens@0.
|
|
72
|
-
<script type="module" src="https://cdn.jsdelivr.net/npm/@unframed/core@0.
|
|
71
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@unframed/tokens@0.13/dist/tokens.css" />
|
|
72
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/@unframed/core@0.13/+esm"></script>
|
|
73
73
|
</head>
|
|
74
74
|
<body>
|
|
75
75
|
<uf-button variant="primary">It works</uf-button>
|