@unframed/cli 1.0.0-rc.3 → 1.0.0-rc.4
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": "1.0.0-rc.
|
|
2
|
+
"version": "1.0.0-rc.4",
|
|
3
3
|
"components": {
|
|
4
4
|
"accordion": {
|
|
5
5
|
"name": "accordion",
|
|
@@ -876,7 +876,7 @@
|
|
|
876
876
|
"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",
|
|
877
877
|
"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: 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",
|
|
878
878
|
"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",
|
|
879
|
-
"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",
|
|
879
|
+
"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: `email`, `nickname`, `shipping street-address`. Any HTML autofill token works. */\n declare autocomplete: AutoFill | (string & {}) | 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",
|
|
880
880
|
"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",
|
|
881
881
|
"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",
|
|
882
882
|
"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",
|
|
@@ -888,15 +888,15 @@
|
|
|
888
888
|
"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",
|
|
889
889
|
"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",
|
|
890
890
|
"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 /* Share any extra width when the row is stretched, as in a grid; no effect at its natural width. */\n .option {\n flex: 1 1 auto;\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",
|
|
891
|
-
"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",
|
|
891
|
+
"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: `email`, `nickname`, `shipping street-address`. Any HTML autofill token works. */\n declare autocomplete: AutoFill | (string & {}) | 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",
|
|
892
892
|
"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",
|
|
893
893
|
"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",
|
|
894
894
|
"components/spinner/spinner.ts": "import { LitElement, css, html, type PropertyDeclarations } from 'lit';\nimport { defineElement } from '../../internal/define.js';\nimport { Translator } from '../../internal/i18n.js';\nimport { hostStyles } from '../../internal/shared.styles.js';\n\nexport type SpinnerSize = 'sm' | 'md' | 'lg';\n\n/**\n * A spinning circle for work in progress whose length isn't known. Screen\n * readers announce it as \"Loading\" (translatable), or as its `label`.\n *\n * @summary Shows that something is loading.\n * @tag uf-spinner\n *\n * @csspart base - The spinner.\n *\n * @cssprop --uf-spinner-size - Diameter. Overrides `size`.\n * @cssprop --uf-spinner-track-color - Color of the circle.\n * @cssprop --uf-spinner-indicator-color - Color of the moving arc.\n */\nexport class UfSpinner extends LitElement {\n static override styles = [\n hostStyles,\n css`\n :host {\n display: inline-flex;\n vertical-align: middle;\n --_size: var(--uf-spinner-size, 1.5rem);\n }\n\n :host([size='sm']) {\n --_size: var(--uf-spinner-size, 1rem);\n }\n\n :host([size='lg']) {\n --_size: var(--uf-spinner-size, 2.5rem);\n }\n\n .base {\n width: var(--_size);\n height: var(--_size);\n border: max(2px, calc(var(--_size) / 10)) solid var(--uf-spinner-track-color, var(--uf-color-surface-hover));\n border-top-color: var(--uf-spinner-indicator-color, var(--uf-color-accent));\n border-radius: 50%;\n animation: uf-spin 0.7s linear infinite;\n }\n\n @keyframes uf-spin {\n to {\n rotate: 360deg;\n }\n }\n\n /* Still turning, so it still says \"working\", but slowly. */\n @media (prefers-reduced-motion: reduce) {\n .base {\n animation-duration: 2s;\n }\n }\n `,\n ];\n\n static override properties: PropertyDeclarations = {\n label: {},\n size: { reflect: true },\n };\n\n /** Accessible name. Defaults to \"Loading\", in the page's language. */\n declare label: string | undefined;\n /** Size: `sm`, `md` or `lg`. */\n declare size: SpinnerSize;\n\n readonly #translator = new Translator(this);\n\n constructor() {\n super();\n this.size = 'md';\n }\n\n override render() {\n return html`<div class=\"base\" part=\"base\" role=\"progressbar\" aria-label=${this.label || this.#translator.t('loading')}></div>`;\n }\n}\n\ndefineElement('uf-spinner', UfSpinner);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'uf-spinner': UfSpinner;\n }\n}\n",
|
|
895
895
|
"components/switch/switch.ts": "import { css, html, type PropertyDeclarations } 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 { describedBy } from '../../internal/field.js';\nimport { hostStyles } from '../../internal/shared.styles.js';\nimport { HasSlotController, uniqueId } from '../../internal/slot.js';\nimport { ToggleControl } from '../../internal/toggle-control.js';\nimport { toggleStyles } from '../../internal/toggle.styles.js';\n\n/**\n * An on/off switch with its label as content. Use it for settings that apply\n * immediately; use a checkbox for choices submitted later with a form.\n *\n * @summary Turns a setting on or off.\n * @tag uf-switch\n *\n * @slot - The label.\n * @slot hint - Help text below the label. Overrides `hint`.\n *\n * @event input - Fired when the state changes.\n * @event change - Fired when the state changes.\n *\n * @csspart base - The `<label>` wrapping control and label.\n * @csspart control - The track.\n * @csspart thumb - The moving knob.\n * @csspart label - The label text.\n * @csspart hint - The hint text.\n * @csspart error - The validation message.\n *\n * @cssprop --uf-switch-width - Width of the track.\n * @cssprop --uf-switch-height - Height of the track.\n * @cssprop --uf-switch-checked-bg - Track color when on.\n * @cssprop --uf-switch-radius - Corner radius of track and thumb. Use `999px` for a pill.\n *\n * @cssstate checked - The switch is on.\n * @cssstate user-invalid - Required but off, after the user interacted.\n */\nexport class UfSwitch extends ToggleControl {\n static override styles = [\n hostStyles,\n toggleStyles,\n css`\n :host {\n --_track-width: 2.25rem;\n --_track-height: 1.25rem;\n --_control-width: var(--uf-switch-width, var(--_track-width));\n --_control-height: var(--uf-switch-height, var(--_track-height));\n --_thumb: calc(var(--_control-height) - 4px);\n }\n\n :host([size='sm']) {\n --_track-width: 1.875rem;\n --_track-height: 1rem;\n }\n\n :host([size='lg']) {\n --_track-width: 2.75rem;\n --_track-height: 1.5rem;\n }\n\n .native {\n width: var(--_control-width);\n height: var(--_control-height);\n border-radius: var(--uf-switch-radius, var(--uf-radius-control));\n background: var(--uf-color-border-strong);\n }\n\n .native:checked {\n background: var(--uf-switch-checked-bg, var(--uf-color-accent));\n }\n\n .disabled .native {\n background: var(--uf-color-neutral-fill);\n box-shadow: inset 0 0 0 1px var(--uf-color-border);\n }\n\n .disabled .native:checked {\n background: var(--uf-color-text-muted);\n box-shadow: none;\n }\n\n .disabled .thumb {\n background: var(--uf-color-border-strong);\n box-shadow: none;\n }\n\n .disabled .native:checked + .thumb {\n background: var(--uf-color-surface);\n }\n\n .invalid .native {\n box-shadow: 0 0 0 2px var(--uf-color-danger-text);\n }\n\n .thumb {\n position: absolute;\n top: 2px;\n left: 2px;\n width: var(--_thumb);\n height: var(--_thumb);\n border-radius: var(--uf-switch-radius, var(--uf-radius-control));\n background: var(--uf-palette-neutral-0);\n box-shadow: var(--uf-shadow-sm);\n pointer-events: none;\n transition: translate var(--uf-duration-base) ease;\n }\n\n .native:checked + .thumb {\n translate: calc(var(--_control-width) - var(--_thumb) - 4px) 0;\n }\n\n @media (prefers-reduced-motion: reduce) {\n .thumb {\n transition: none;\n }\n }\n `,\n ];\n\n static override properties: PropertyDeclarations = {\n hint: {},\n };\n\n /** Help text below the label. */\n declare hint: string | undefined;\n\n readonly #slots = new HasSlotController(this, 'hint');\n readonly #id = uniqueId('uf-switch');\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\n return html`\n <label class=${classMap({ root: true, disabled, invalid: Boolean(error) })} part=\"base\">\n <span class=\"control\" part=\"control\">\n <input\n class=\"native\"\n type=\"checkbox\"\n role=\"switch\"\n name=${ifDefined(this.name || undefined)}\n .value=${this.value}\n .checked=${live(this.checked)}\n ?required=${this.required}\n ?disabled=${disabled}\n aria-invalid=${error ? 'true' : 'false'}\n aria-describedby=${ifDefined(describedBy({ ...ids, hint: this.hint, hasHintSlot, error }))}\n @change=${this.onNativeChange}\n />\n <span class=\"thumb\" part=\"thumb\"></span>\n </span>\n <span class=\"label\" part=\"label\"><slot></slot></span>\n </label>\n <div id=${ids.hintId} class=\"hint\" part=\"hint\" ?hidden=${!this.hint && !hasHintSlot}>\n <slot name=\"hint\">${this.hint}</slot>\n </div>\n <div id=${ids.errorId} class=\"error\" part=\"error\" ?hidden=${!error}>${error}</div>\n `;\n }\n}\n\ndefineElement('uf-switch', UfSwitch);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'uf-switch': UfSwitch;\n }\n}\n",
|
|
896
|
-
"components/table/table.ts": "import { LitElement, css, html, nothing, type PropertyDeclarations, type PropertyValues } from 'lit';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { repeat } from 'lit/directives/repeat.js';\nimport { styleMap } from 'lit/directives/style-map.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\n/** A row of data: column keys to values. */\nexport type TableRow = Record<string, unknown>;\nexport type SortDirection = 'ascending' | 'descending';\nexport type TableDensity = 'comfortable' | 'compact';\n\nexport interface TableColumn<Row extends TableRow = TableRow> {\n /** The row property this column shows, and its id for sorting. */\n key: string;\n /** Header text. */\n label: string;\n /** Lets the user sort by this column. */\n sortable?: boolean;\n /** Text alignment. Use `end` for numbers. Defaults to `start`. */\n align?: 'start' | 'center' | 'end';\n /** Column width, as CSS: `8rem`, `20%`. */\n width?: string;\n /** Cell content from the value: text, or a DOM node such as a badge. Defaults to the value as text. */\n format?: (value: unknown, row: Row) => string | number | Node | null | undefined;\n /** Sort order for two rows, like `Array.prototype.sort`. Defaults to comparing the values. */\n compare?: (a: Row, b: Row) => number;\n}\n\nexport interface TableSortDetail {\n /** Key of the sorted column. */\n key: string;\n direction: SortDirection;\n}\n\nconst collator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' });\n\n/** Numbers and dates by value, everything else as text; empty values last. */\nfunction compareValues(a: unknown, b: unknown): number {\n const empty = (v: unknown) => v === null || v === undefined || v === '';\n if (empty(a) || empty(b)) return Number(empty(a)) - Number(empty(b));\n if (typeof a === 'number' && typeof b === 'number') return a - b;\n if (a instanceof Date && b instanceof Date) return a.getTime() - b.getTime();\n return collator.compare(String(a), String(b));\n}\n\n/**\n * A table of data, from `columns` and `rows`. Users can sort by the columns\n * marked `sortable`. Rendered as a native `<table>`, so assistive tech reads\n * headers and cells as usual.\n *\n * Set `columns` and `rows` as properties, or as JSON attributes in plain HTML.\n * The table sorts `rows` itself; with `manual-sort` it only shows the order\n * and tells you, so you can sort on the server. Combine it with\n * `<uf-pagination>` for long lists.\n *\n * @summary Shows data in rows and columns, with sorting.\n * @tag uf-table\n *\n * @slot empty - Shown when there are no rows. Defaults to \"No data\", or its translation.\n *\n * @event {CustomEvent<TableSortDetail>} uf-sort - The user sorted by a column.\n *\n * @csspart base - The scroll container around the table.\n * @csspart table - The `<table>`.\n * @csspart header-cell - Every header cell (`<th>`).\n * @csspart sort-button - The button in a sortable header.\n * @csspart row - Every body row.\n * @csspart cell - Every body cell.\n * @csspart empty - The cell shown when there are no rows.\n *\n * @cssprop --uf-table-max-height - Height after which the body scrolls under a sticky header.\n * @cssprop --uf-table-border-color - Border color between rows.\n * @cssprop --uf-table-header-bg - Background of the header row.\n * @cssprop --uf-table-stripe-bg - Background of every other row, with `striped`.\n * @cssprop --uf-table-hover-bg - Background of the row under the pointer.\n */\nexport class UfTable extends LitElement {\n static override styles = [\n hostStyles,\n css`\n :host {\n display: block;\n /* In flex and grid layouts, shrink to the space there is and scroll, instead of overflowing the page. */\n min-width: 0;\n --_pad-y: var(--uf-space-3);\n --_pad-x: var(--uf-space-4);\n --_border: var(--uf-table-border-color, var(--uf-color-border));\n }\n\n :host([density='compact']) {\n --_pad-y: var(--uf-space-1);\n --_pad-x: var(--uf-space-3);\n }\n\n .base {\n max-height: var(--uf-table-max-height, none);\n overflow: auto;\n border: 1px solid var(--_border);\n border-radius: var(--uf-radius-md);\n }\n\n .base:focus-visible {\n ${focusRing}\n }\n\n table {\n width: 100%;\n border-collapse: separate;\n border-spacing: 0;\n color: var(--uf-color-text);\n font-family: var(--uf-font-family-sans);\n font-size: var(--uf-font-size-sm);\n font-variant-numeric: tabular-nums;\n }\n\n th,\n td {\n padding: var(--_pad-y) var(--_pad-x);\n border-bottom: 1px solid var(--_border);\n text-align: start;\n vertical-align: middle;\n }\n\n tbody tr:last-child td {\n border-bottom: 0;\n }\n\n /* Code in cells from \\`format\\`, e.g. an API reference: like inline code in text. */\n td code {\n padding: 0.1em 0.35em;\n border-radius: var(--uf-radius-sm);\n background: var(--uf-color-surface-hover);\n font-family: var(--uf-font-family-mono);\n font-size: 0.875em;\n }\n\n th {\n position: sticky;\n top: 0;\n z-index: 1;\n background: var(--uf-table-header-bg, var(--uf-color-surface-raised));\n color: var(--uf-color-text-muted);\n font-weight: var(--uf-font-weight-semibold);\n white-space: nowrap;\n }\n\n .align-center {\n text-align: center;\n }\n .align-end {\n text-align: end;\n }\n\n .sort {\n display: inline-flex;\n align-items: center;\n gap: var(--uf-space-1);\n margin: calc(var(--uf-space-1) * -1) calc(var(--uf-space-2) * -1);\n padding: var(--uf-space-1) var(--uf-space-2);\n border: 0;\n border-radius: var(--uf-radius-sm);\n background: none;\n color: inherit;\n font: inherit;\n cursor: pointer;\n }\n\n .sort:hover {\n color: var(--uf-color-text);\n }\n\n .sort:focus-visible {\n ${focusRing}\n }\n\n .sort svg {\n width: 1em;\n height: 1em;\n opacity: 0;\n }\n\n /* A hint on hover and focus, solid when sorted. */\n .sort:hover svg,\n .sort:focus-visible svg {\n opacity: 0.5;\n }\n [aria-sort] .sort {\n color: var(--uf-color-text);\n }\n [aria-sort] .sort svg {\n opacity: 1;\n }\n\n :host([striped]) tbody tr:nth-child(even) td {\n background: var(--uf-table-stripe-bg, var(--uf-color-surface-hover));\n }\n\n tbody tr:hover td {\n background: var(--uf-table-hover-bg, var(--uf-color-accent-tint));\n }\n\n .empty {\n padding: var(--uf-space-6) var(--_pad-x);\n color: var(--uf-color-text-muted);\n text-align: center;\n }\n\n tbody tr.empty-row:hover td {\n background: none;\n }\n `,\n ];\n\n static override properties: PropertyDeclarations = {\n columns: { type: Array },\n rows: { type: Array },\n label: {},\n sortKey: { attribute: 'sort-key', reflect: true },\n sortDirection: { attribute: 'sort-direction', reflect: true },\n manualSort: { type: Boolean, attribute: 'manual-sort' },\n rowKey: { attribute: 'row-key' },\n striped: { type: Boolean, reflect: true },\n density: { reflect: true },\n };\n\n /** The columns, in order. As an attribute, JSON: `[{\"key\": \"name\", \"label\": \"Name\"}]`. */\n declare columns: TableColumn[];\n /** The data, one object per row. As an attribute, JSON: `[{\"name\": \"John\"}]`. */\n declare rows: TableRow[];\n /** Accessible name of the table, e.g. \"Invoices\". */\n declare label: string | undefined;\n /** Key of the column the rows are sorted by. */\n declare sortKey: string | undefined;\n /** Sort order: `ascending` or `descending`. */\n declare sortDirection: SortDirection;\n /** Doesn't sort the rows: only shows the sort and fires `uf-sort`, for sorting on the server. */\n declare manualSort: boolean;\n /** Row property that identifies each row, so rows keep their DOM when the data changes. Defaults to the index. */\n declare rowKey: string | undefined;\n /** Shades every other row. */\n declare striped: boolean;\n /** Row spacing: `comfortable` or `compact`. */\n declare density: TableDensity;\n\n /** The table overflows its container, so it scrolls. */\n #scrollable = false;\n\n readonly #translator = new Translator(this);\n readonly #resizeObserver = new ResizeObserver(() => this.#checkScrollable());\n\n constructor() {\n super();\n this.columns = [];\n this.rows = [];\n this.sortDirection = 'ascending';\n this.manualSort = false;\n this.striped = false;\n this.density = 'comfortable';\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n this.#resizeObserver.disconnect();\n }\n\n override firstUpdated(): void {\n const base = this.renderRoot.querySelector('.base')!;\n this.#resizeObserver.observe(base);\n this.#resizeObserver.observe(this.renderRoot.querySelector('table')!);\n }\n\n override updated(changed: PropertyValues<this>): void {\n if (changed.has('rows') || changed.has('columns')) this.#checkScrollable();\n }\n\n /** A scrolling table must be reachable by keyboard, to scroll it. */\n #checkScrollable(): void {\n const base = this.renderRoot.querySelector('.base');\n if (!base) return;\n const scrollable = base.scrollWidth > base.clientWidth || base.scrollHeight > base.clientHeight;\n if (scrollable === this.#scrollable) return;\n this.#scrollable = scrollable;\n this.requestUpdate();\n }\n\n /** The rows in display order. */\n get #sortedRows(): TableRow[] {\n const rows = Array.isArray(this.rows) ? this.rows : [];\n const column = this.columns.find((c) => c.key === this.sortKey);\n if (!column || this.manualSort) return rows;\n const compare = column.compare ?? ((a: TableRow, b: TableRow) => compareValues(a[column.key], b[column.key]));\n const sign = this.sortDirection === 'descending' ? -1 : 1;\n // Stable: equal rows keep their order.\n return [...rows].sort((a, b) => sign * compare(a, b));\n }\n\n #sortBy(column: TableColumn): void {\n const direction: SortDirection = this.sortKey === column.key && this.sortDirection === 'ascending' ? 'descending' : 'ascending';\n this.sortKey = column.key;\n this.sortDirection = direction;\n this.dispatchEvent(\n new CustomEvent<TableSortDetail>('uf-sort', { bubbles: true, composed: true, detail: { key: column.key, direction } }),\n );\n }\n\n #renderHeader(column: TableColumn) {\n const sorted = column.key === this.sortKey;\n const align = { [`align-${column.align ?? 'start'}`]: true };\n return html`<th\n scope=\"col\"\n part=\"header-cell\"\n class=${classMap(align)}\n style=${styleMap({ width: column.width })}\n aria-sort=${sorted && column.sortable ? this.sortDirection : nothing}\n >\n ${column.sortable\n ? html`<button class=\"sort\" part=\"sort-button\" type=\"button\" @click=${() => this.#sortBy(column)}>\n ${column.label}${iconSvg(sorted && this.sortDirection === 'descending' ? icons['chevron-down'] : icons['chevron-up'])}\n </button>`\n : column.label}\n </th>`;\n }\n\n #renderCell(column: TableColumn, row: TableRow) {\n const value = row[column.key];\n const content = column.format ? column.format(value, row) : value;\n return html`<td part=\"cell\" class=${classMap({ [`align-${column.align ?? 'start'}`]: true })}>\n ${content === null || content === undefined ? '' : content instanceof Node ? content : String(content)}\n </td>`;\n }\n\n override render() {\n const columns = Array.isArray(this.columns) ? this.columns : [];\n const rows = this.#sortedRows;\n return html`<div\n class=\"base\"\n part=\"base\"\n tabindex=${this.#scrollable ? '0' : nothing}\n role=${this.#scrollable ? 'region' : nothing}\n aria-label=${this.#scrollable && this.label ? this.label : nothing}\n >\n <table part=\"table\" aria-label=${this.label ?? nothing}>\n <thead>\n <tr>\n ${columns.map((column) => this.#renderHeader(column))}\n </tr>\n </thead>\n <tbody>\n ${rows.length\n ? repeat(\n rows,\n (row, index) => (this.rowKey ? row[this.rowKey] : index),\n (row) => html`<tr part=\"row\">${columns.map((column) => this.#renderCell(column, row))}</tr>`,\n )\n : html`<tr class=\"empty-row\">\n <td class=\"empty\" part=\"empty\" colspan=${Math.max(1, columns.length)}><slot name=\"empty\">${this.#translator.t('noData')}</slot></td>\n </tr>`}\n </tbody>\n </table>\n </div>`;\n }\n}\n\ndefineElement('uf-table', UfTable);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'uf-table': UfTable;\n }\n}\n",
|
|
896
|
+
"components/table/table.ts": "import { LitElement, css, html, nothing, type PropertyDeclarations, type PropertyValues } from 'lit';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { repeat } from 'lit/directives/repeat.js';\nimport { styleMap } from 'lit/directives/style-map.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\n/**\n * A row of data: any object, such as an `interface Order { … }`. Columns read\n * its properties by `key`.\n */\nexport type TableRow = object;\nexport type SortDirection = 'ascending' | 'descending';\nexport type TableDensity = 'comfortable' | 'compact';\n\nexport interface TableColumn<Row extends TableRow = TableRow> {\n /** The row property this column shows, and its id for sorting. */\n key: Extract<keyof Row, string> | (string & {});\n /** Header text. */\n label: string;\n /** Lets the user sort by this column. */\n sortable?: boolean;\n /** Text alignment. Use `end` for numbers. Defaults to `start`. */\n align?: 'start' | 'center' | 'end';\n /** Column width, as CSS: `8rem`, `20%`. */\n width?: string;\n /** Cell content from the value: text, or a DOM node such as a badge. Defaults to the value as text. */\n format?(value: unknown, row: Row): string | number | Node | null | undefined;\n /** Sort order for two rows, like `Array.prototype.sort`. Defaults to comparing the values. */\n compare?(a: Row, b: Row): number;\n}\n\nexport interface TableSortDetail {\n /** Key of the sorted column. */\n key: string;\n direction: SortDirection;\n}\n\n/** The value of `key` in a row. */\nfunction valueOf(row: TableRow, key: string): unknown {\n return (row as Record<string, unknown>)[key];\n}\n\nconst collator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' });\n\n/** Numbers and dates by value, everything else as text; empty values last. */\nfunction compareValues(a: unknown, b: unknown): number {\n const empty = (v: unknown) => v === null || v === undefined || v === '';\n if (empty(a) || empty(b)) return Number(empty(a)) - Number(empty(b));\n if (typeof a === 'number' && typeof b === 'number') return a - b;\n if (a instanceof Date && b instanceof Date) return a.getTime() - b.getTime();\n return collator.compare(String(a), String(b));\n}\n\n/**\n * A table of data, from `columns` and `rows`. Users can sort by the columns\n * marked `sortable`. Rendered as a native `<table>`, so assistive tech reads\n * headers and cells as usual.\n *\n * Set `columns` and `rows` as properties, or as JSON attributes in plain HTML.\n * The table sorts `rows` itself; with `manual-sort` it only shows the order\n * and tells you, so you can sort on the server. Combine it with\n * `<uf-pagination>` for long lists.\n *\n * @summary Shows data in rows and columns, with sorting.\n * @tag uf-table\n *\n * @slot empty - Shown when there are no rows. Defaults to \"No data\", or its translation.\n *\n * @event {CustomEvent<TableSortDetail>} uf-sort - The user sorted by a column.\n *\n * @csspart base - The scroll container around the table.\n * @csspart table - The `<table>`.\n * @csspart header-cell - Every header cell (`<th>`).\n * @csspart sort-button - The button in a sortable header.\n * @csspart row - Every body row.\n * @csspart cell - Every body cell.\n * @csspart empty - The cell shown when there are no rows.\n *\n * @cssprop --uf-table-max-height - Height after which the body scrolls under a sticky header.\n * @cssprop --uf-table-border-color - Border color between rows.\n * @cssprop --uf-table-header-bg - Background of the header row.\n * @cssprop --uf-table-stripe-bg - Background of every other row, with `striped`.\n * @cssprop --uf-table-hover-bg - Background of the row under the pointer.\n */\nexport class UfTable extends LitElement {\n static override styles = [\n hostStyles,\n css`\n :host {\n display: block;\n /* In flex and grid layouts, shrink to the space there is and scroll, instead of overflowing the page. */\n min-width: 0;\n --_pad-y: var(--uf-space-3);\n --_pad-x: var(--uf-space-4);\n --_border: var(--uf-table-border-color, var(--uf-color-border));\n }\n\n :host([density='compact']) {\n --_pad-y: var(--uf-space-1);\n --_pad-x: var(--uf-space-3);\n }\n\n .base {\n max-height: var(--uf-table-max-height, none);\n overflow: auto;\n border: 1px solid var(--_border);\n border-radius: var(--uf-radius-md);\n }\n\n .base:focus-visible {\n ${focusRing}\n }\n\n table {\n width: 100%;\n border-collapse: separate;\n border-spacing: 0;\n color: var(--uf-color-text);\n font-family: var(--uf-font-family-sans);\n font-size: var(--uf-font-size-sm);\n font-variant-numeric: tabular-nums;\n }\n\n th,\n td {\n padding: var(--_pad-y) var(--_pad-x);\n border-bottom: 1px solid var(--_border);\n text-align: start;\n vertical-align: middle;\n }\n\n tbody tr:last-child td {\n border-bottom: 0;\n }\n\n /* Code in cells from \\`format\\`, e.g. an API reference: like inline code in text. */\n td code {\n padding: 0.1em 0.35em;\n border-radius: var(--uf-radius-sm);\n background: var(--uf-color-surface-hover);\n font-family: var(--uf-font-family-mono);\n font-size: 0.875em;\n }\n\n th {\n position: sticky;\n top: 0;\n z-index: 1;\n background: var(--uf-table-header-bg, var(--uf-color-surface-raised));\n color: var(--uf-color-text-muted);\n font-weight: var(--uf-font-weight-semibold);\n white-space: nowrap;\n }\n\n .align-center {\n text-align: center;\n }\n .align-end {\n text-align: end;\n }\n\n .sort {\n display: inline-flex;\n align-items: center;\n gap: var(--uf-space-1);\n margin: calc(var(--uf-space-1) * -1) calc(var(--uf-space-2) * -1);\n padding: var(--uf-space-1) var(--uf-space-2);\n border: 0;\n border-radius: var(--uf-radius-sm);\n background: none;\n color: inherit;\n font: inherit;\n cursor: pointer;\n }\n\n .sort:hover {\n color: var(--uf-color-text);\n }\n\n .sort:focus-visible {\n ${focusRing}\n }\n\n .sort svg {\n width: 1em;\n height: 1em;\n opacity: 0;\n }\n\n /* A hint on hover and focus, solid when sorted. */\n .sort:hover svg,\n .sort:focus-visible svg {\n opacity: 0.5;\n }\n [aria-sort] .sort {\n color: var(--uf-color-text);\n }\n [aria-sort] .sort svg {\n opacity: 1;\n }\n\n :host([striped]) tbody tr:nth-child(even) td {\n background: var(--uf-table-stripe-bg, var(--uf-color-surface-hover));\n }\n\n tbody tr:hover td {\n background: var(--uf-table-hover-bg, var(--uf-color-accent-tint));\n }\n\n .empty {\n padding: var(--uf-space-6) var(--_pad-x);\n color: var(--uf-color-text-muted);\n text-align: center;\n }\n\n tbody tr.empty-row:hover td {\n background: none;\n }\n `,\n ];\n\n static override properties: PropertyDeclarations = {\n columns: { type: Array },\n rows: { type: Array },\n label: {},\n sortKey: { attribute: 'sort-key', reflect: true },\n sortDirection: { attribute: 'sort-direction', reflect: true },\n manualSort: { type: Boolean, attribute: 'manual-sort' },\n rowKey: { attribute: 'row-key' },\n striped: { type: Boolean, reflect: true },\n density: { reflect: true },\n };\n\n /** The columns, in order. As an attribute, JSON: `[{\"key\": \"name\", \"label\": \"Name\"}]`. */\n declare columns: TableColumn[];\n /** The data, one object per row. As an attribute, JSON: `[{\"name\": \"John\"}]`. */\n declare rows: TableRow[];\n /** Accessible name of the table, e.g. \"Invoices\". */\n declare label: string | undefined;\n /** Key of the column the rows are sorted by. */\n declare sortKey: string | undefined;\n /** Sort order: `ascending` or `descending`. */\n declare sortDirection: SortDirection;\n /** Doesn't sort the rows: only shows the sort and fires `uf-sort`, for sorting on the server. */\n declare manualSort: boolean;\n /** Row property that identifies each row, so rows keep their DOM when the data changes. Defaults to the index. */\n declare rowKey: string | undefined;\n /** Shades every other row. */\n declare striped: boolean;\n /** Row spacing: `comfortable` or `compact`. */\n declare density: TableDensity;\n\n /** The table overflows its container, so it scrolls. */\n #scrollable = false;\n\n readonly #translator = new Translator(this);\n readonly #resizeObserver = new ResizeObserver(() => this.#checkScrollable());\n\n constructor() {\n super();\n this.columns = [];\n this.rows = [];\n this.sortDirection = 'ascending';\n this.manualSort = false;\n this.striped = false;\n this.density = 'comfortable';\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n this.#resizeObserver.disconnect();\n }\n\n override firstUpdated(): void {\n const base = this.renderRoot.querySelector('.base')!;\n this.#resizeObserver.observe(base);\n this.#resizeObserver.observe(this.renderRoot.querySelector('table')!);\n }\n\n override updated(changed: PropertyValues<this>): void {\n if (changed.has('rows') || changed.has('columns')) this.#checkScrollable();\n }\n\n /** A scrolling table must be reachable by keyboard, to scroll it. */\n #checkScrollable(): void {\n const base = this.renderRoot.querySelector('.base');\n if (!base) return;\n const scrollable = base.scrollWidth > base.clientWidth || base.scrollHeight > base.clientHeight;\n if (scrollable === this.#scrollable) return;\n this.#scrollable = scrollable;\n this.requestUpdate();\n }\n\n /** The rows in display order. */\n get #sortedRows(): TableRow[] {\n const rows = Array.isArray(this.rows) ? this.rows : [];\n const column = this.columns.find((c) => c.key === this.sortKey);\n if (!column || this.manualSort) return rows;\n const compare = column.compare ?? ((a: TableRow, b: TableRow) => compareValues(valueOf(a, column.key), valueOf(b, column.key)));\n const sign = this.sortDirection === 'descending' ? -1 : 1;\n // Stable: equal rows keep their order.\n return [...rows].sort((a, b) => sign * compare(a, b));\n }\n\n #sortBy(column: TableColumn): void {\n const direction: SortDirection = this.sortKey === column.key && this.sortDirection === 'ascending' ? 'descending' : 'ascending';\n this.sortKey = column.key;\n this.sortDirection = direction;\n this.dispatchEvent(\n new CustomEvent<TableSortDetail>('uf-sort', { bubbles: true, composed: true, detail: { key: column.key, direction } }),\n );\n }\n\n #renderHeader(column: TableColumn) {\n const sorted = column.key === this.sortKey;\n const align = { [`align-${column.align ?? 'start'}`]: true };\n return html`<th\n scope=\"col\"\n part=\"header-cell\"\n class=${classMap(align)}\n style=${styleMap({ width: column.width })}\n aria-sort=${sorted && column.sortable ? this.sortDirection : nothing}\n >\n ${column.sortable\n ? html`<button class=\"sort\" part=\"sort-button\" type=\"button\" @click=${() => this.#sortBy(column)}>\n ${column.label}${iconSvg(sorted && this.sortDirection === 'descending' ? icons['chevron-down'] : icons['chevron-up'])}\n </button>`\n : column.label}\n </th>`;\n }\n\n #renderCell(column: TableColumn, row: TableRow) {\n const value = valueOf(row, column.key);\n const content = column.format ? column.format(value, row) : value;\n return html`<td part=\"cell\" class=${classMap({ [`align-${column.align ?? 'start'}`]: true })}>\n ${content === null || content === undefined ? '' : content instanceof Node ? content : String(content)}\n </td>`;\n }\n\n override render() {\n const columns = Array.isArray(this.columns) ? this.columns : [];\n const rows = this.#sortedRows;\n return html`<div\n class=\"base\"\n part=\"base\"\n tabindex=${this.#scrollable ? '0' : nothing}\n role=${this.#scrollable ? 'region' : nothing}\n aria-label=${this.#scrollable && this.label ? this.label : nothing}\n >\n <table part=\"table\" aria-label=${this.label ?? nothing}>\n <thead>\n <tr>\n ${columns.map((column) => this.#renderHeader(column))}\n </tr>\n </thead>\n <tbody>\n ${rows.length\n ? repeat(\n rows,\n (row, index) => (this.rowKey ? valueOf(row, this.rowKey) : index),\n (row) => html`<tr part=\"row\">${columns.map((column) => this.#renderCell(column, row))}</tr>`,\n )\n : html`<tr class=\"empty-row\">\n <td class=\"empty\" part=\"empty\" colspan=${Math.max(1, columns.length)}><slot name=\"empty\">${this.#translator.t('noData')}</slot></td>\n </tr>`}\n </tbody>\n </table>\n </div>`;\n }\n}\n\ndefineElement('uf-table', UfTable);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'uf-table': UfTable;\n }\n}\n",
|
|
897
897
|
"components/tabs/tabs.ts": "import { LitElement, css, html, type PropertyDeclarations } from 'lit';\nimport { ifDefined } from 'lit/directives/if-defined.js';\nimport { defineElement } from '../../internal/define.js';\nimport { uniqueId } from '../../internal/slot.js';\nimport './tab.js';\nimport type { UfTab, UfTabPanel } from './tab.js';\n\nexport { UfTab, UfTabPanel } from './tab.js';\n\nexport interface TabChangeDetail {\n name: string;\n}\n\n/**\n * Tabs that switch between panels. Arrow keys move between tabs, Home and End\n * jump to the ends, and only the selected tab is in the tab order.\n *\n * @summary Organizes content into panels, one visible at a time.\n * @tag uf-tabs\n *\n * @slot - `<uf-tab>` and `<uf-tab-panel>` elements. Tabs are moved into the tab list automatically.\n * @slot nav - The tab list. You don't need to set this yourself.\n *\n * @event {CustomEvent<TabChangeDetail>} uf-tab-change - The selected tab changed.\n *\n * @csspart tablist - The element with `role=\"tablist\"`.\n * @csspart panels - The wrapper around the panels.\n *\n * @cssprop --uf-tabs-indicator-color - Color of the selected tab's underline.\n */\nexport class UfTabs extends LitElement {\n static override styles = css`\n :host {\n display: block;\n }\n\n .tablist {\n display: flex;\n gap: var(--uf-space-1);\n border-bottom: 1px solid var(--uf-color-border);\n overflow-x: auto;\n scrollbar-width: none;\n }\n\n :host([orientation='vertical']) {\n display: flex;\n gap: var(--uf-space-4);\n }\n\n :host([orientation='vertical']) .tablist {\n flex-direction: column;\n border-bottom: 0;\n border-inline-end: 1px solid var(--uf-color-border);\n overflow: visible;\n }\n\n .panels {\n flex: 1;\n min-width: 0;\n }\n `;\n\n static override properties: PropertyDeclarations = {\n value: { reflect: true },\n activation: { reflect: true },\n orientation: { reflect: true },\n label: {},\n };\n\n /** Name of the selected panel. Defaults to the first enabled tab. */\n declare value: string;\n /** `auto` selects a tab as soon as it gets focus; `manual` waits for Enter or Space. */\n declare activation: 'auto' | 'manual';\n /** Lays the tab list out horizontally or vertically. */\n declare orientation: 'horizontal' | 'vertical';\n /** Accessible name for the tab list. */\n declare label: string | undefined;\n\n readonly #id = uniqueId('uf-tabs');\n\n constructor() {\n super();\n this.value = '';\n this.activation = 'auto';\n this.orientation = 'horizontal';\n this.addEventListener('click', this.#onClick);\n this.addEventListener('keydown', this.#onKeyDown);\n }\n\n get #tabs(): UfTab[] {\n return [...this.querySelectorAll<UfTab>(':scope > uf-tab')];\n }\n\n get #panels(): UfTabPanel[] {\n return [...this.querySelectorAll<UfTabPanel>(':scope > uf-tab-panel')];\n }\n\n /** Selects the tab for the given panel name. */\n select(name: string): void {\n const tab = this.#tabs.find((t) => t.panel === name);\n if (tab && !tab.disabled) this.#activate(tab);\n }\n\n // Picks the active tab before rendering: setting it after (in updated) would\n // render twice, which Lit warns about in development.\n override willUpdate(): void {\n this.#activeTab();\n }\n\n override updated(): void {\n this.#sync();\n }\n\n /** The tab to show: the one for `value`, or the first enabled one. Keeps `value` in step. */\n #activeTab() {\n const enabled = this.#tabs.filter((t) => !t.disabled);\n const activeTab = enabled.find((t) => t.panel === this.value) ?? enabled[0];\n if (activeTab && this.value !== activeTab.panel) this.value = activeTab.panel;\n return activeTab;\n }\n\n /** Wires up roles, ids and visibility on the light-DOM tabs and panels. */\n #sync(): void {\n const tabs = this.#tabs;\n const panels = this.#panels;\n const activeTab = this.#activeTab();\n\n tabs.forEach((tab, i) => {\n tab.slot = 'nav';\n tab.id ||= `${this.#id}-tab-${i}`;\n const panel = panels.find((p) => p.name === tab.panel);\n const selected = tab === activeTab;\n tab.setAttribute('role', 'tab');\n tab.setAttribute('aria-selected', String(selected));\n tab.setAttribute('aria-disabled', String(tab.disabled));\n tab.tabIndex = selected ? 0 : -1;\n if (panel) {\n panel.id ||= `${this.#id}-panel-${i}`;\n tab.setAttribute('aria-controls', panel.id);\n panel.setAttribute('aria-labelledby', tab.id);\n }\n });\n\n for (const panel of panels) {\n panel.setAttribute('role', 'tabpanel');\n panel.tabIndex = 0;\n panel.hidden = panel.name !== activeTab?.panel;\n }\n }\n\n #activate(tab: UfTab): void {\n tab.focus();\n if (tab.panel === this.value) return;\n this.value = tab.panel;\n this.dispatchEvent(\n new CustomEvent<TabChangeDetail>('uf-tab-change', {\n bubbles: true,\n composed: true,\n detail: { name: tab.panel },\n }),\n );\n }\n\n #onClick = (event: MouseEvent): void => {\n const tab = (event.target as Element).closest('uf-tab');\n if (tab?.parentElement === this && !tab.disabled) this.#activate(tab);\n };\n\n #onKeyDown = (event: KeyboardEvent): void => {\n const current = (event.target as Element).closest('uf-tab');\n if (!current || current.parentElement !== this) return;\n\n const tabs = this.#tabs.filter((t) => !t.disabled);\n const index = tabs.indexOf(current);\n const vertical = this.orientation === 'vertical';\n const next = vertical ? 'ArrowDown' : 'ArrowRight';\n const prev = vertical ? 'ArrowUp' : 'ArrowLeft';\n\n let target: UfTab | undefined;\n if (event.key === next) target = tabs[(index + 1) % tabs.length];\n else if (event.key === prev) target = tabs[(index - 1 + tabs.length) % tabs.length];\n else if (event.key === 'Home') target = tabs[0];\n else if (event.key === 'End') target = tabs[tabs.length - 1];\n else if (event.key === 'Enter' || event.key === ' ') {\n event.preventDefault();\n this.#activate(current);\n return;\n }\n if (!target) return;\n\n event.preventDefault();\n if (this.activation === 'auto') this.#activate(target);\n else target.focus();\n };\n\n override render() {\n return html`\n <div\n class=\"tablist\"\n part=\"tablist\"\n role=\"tablist\"\n aria-label=${ifDefined(this.label)}\n aria-orientation=${this.orientation}\n >\n <slot name=\"nav\" @slotchange=${() => this.#sync()}></slot>\n </div>\n <div class=\"panels\" part=\"panels\">\n <slot @slotchange=${() => this.#sync()}></slot>\n </div>\n `;\n }\n}\n\ndefineElement('uf-tabs', UfTabs);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'uf-tabs': UfTabs;\n }\n}\n",
|
|
898
898
|
"components/tabs/tab.ts": "import { LitElement, css, html, type PropertyDeclarations } from 'lit';\nimport { defineElement } from '../../internal/define.js';\n\n/**\n * A tab inside `<uf-tabs>`. Its `panel` names the `<uf-tab-panel>` it shows.\n *\n * @summary A tab in a tab list.\n * @tag uf-tab\n *\n * @slot - The tab label.\n *\n * @csspart base - The tab's inner wrapper.\n *\n * @cssstate active - The tab is selected.\n */\nexport class UfTab extends LitElement {\n static override styles = css`\n :host {\n position: relative;\n display: inline-flex;\n align-items: center;\n gap: var(--uf-space-2);\n padding: var(--uf-space-2) var(--uf-space-3);\n color: var(--uf-color-text-muted);\n font-family: var(--uf-font-family-sans);\n font-size: var(--uf-font-size-md);\n font-weight: var(--uf-font-weight-medium);\n white-space: nowrap;\n cursor: pointer;\n user-select: none;\n outline: none;\n border-radius: var(--uf-radius-sm);\n transition: color var(--uf-duration-fast) ease;\n }\n\n :host(:hover:not([disabled])) {\n color: var(--uf-color-text);\n }\n\n :host([aria-selected='true']) {\n color: var(--uf-color-text);\n }\n\n :host::after {\n content: '';\n position: absolute;\n inset: auto 0 -1px 0;\n height: 2px;\n border-radius: 2px;\n background: var(--uf-tabs-indicator-color, var(--uf-color-accent-strong));\n scale: 0 1;\n transition: scale var(--uf-duration-base) ease;\n }\n\n :host([aria-selected='true'])::after {\n scale: 1 1;\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 }\n\n @media (prefers-reduced-motion: reduce) {\n :host::after {\n transition: none;\n }\n }\n `;\n\n static override properties: PropertyDeclarations = {\n panel: { reflect: true },\n disabled: { type: Boolean, reflect: true },\n };\n\n /** Name of the `<uf-tab-panel>` this tab shows. */\n declare panel: string;\n /** Disables the tab. */\n declare disabled: boolean;\n\n constructor() {\n super();\n this.panel = '';\n this.disabled = false;\n }\n\n override render() {\n return html`<slot part=\"base\"></slot>`;\n }\n}\n\n/**\n * The content shown when its tab is selected.\n *\n * @summary A panel of content inside `<uf-tabs>`.\n * @tag uf-tab-panel\n *\n * @slot - The panel content.\n *\n * @cssprop --uf-tab-panel-padding - Padding around the content.\n */\nexport class UfTabPanel extends LitElement {\n static override styles = css`\n :host {\n display: block;\n padding: var(--uf-tab-panel-padding, var(--uf-space-4) 0);\n outline: none;\n }\n\n :host([hidden]) {\n display: none;\n }\n\n :host(:focus-visible) {\n outline: var(--uf-focus-ring-width) solid var(--uf-color-focus-ring);\n outline-offset: var(--uf-focus-ring-offset);\n border-radius: var(--uf-radius-sm);\n }\n `;\n\n static override properties: PropertyDeclarations = {\n name: { reflect: true },\n };\n\n /** Name the matching tab refers to with `panel`. */\n declare name: string;\n\n constructor() {\n super();\n this.name = '';\n }\n\n override render() {\n return html`<slot></slot>`;\n }\n}\n\ndefineElement('uf-tab', UfTab);\ndefineElement('uf-tab-panel', UfTabPanel);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'uf-tab': UfTab;\n 'uf-tab-panel': UfTabPanel;\n }\n}\n",
|
|
899
|
-
"components/textarea/textarea.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 { hostStyles } from '../../internal/shared.styles.js';\nimport { HasSlotController, uniqueId } from '../../internal/slot.js';\n\nexport type TextareaResize = 'none' | 'vertical' | 'auto';\n\n/**\n * A multi-line text field with a built-in label, hint and validation message.\n *\n * @summary Lets users enter multiple lines of text.\n * @tag uf-textarea\n *\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 on every keystroke.\n * @event change - Fired when the value is committed (blur).\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 textarea.\n * @csspart textarea - The native `<textarea>`.\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 UfTextarea extends FormControl {\n static override styles = [\n hostStyles,\n fieldStyles,\n controlBoxStyles,\n css`\n .box {\n align-items: stretch;\n padding-block: var(--uf-space-2);\n }\n\n .native {\n min-height: 3lh;\n line-height: 1.5;\n resize: vertical;\n }\n\n :host([resize='none']) .native {\n resize: none;\n }\n\n /* Grows with its content where supported (field-sizing), otherwise resizable. */\n :host([resize='auto']) .native {\n field-sizing: content;\n resize: none;\n }\n `,\n ];\n\n protected static override formStateProperties: ReadonlySet<PropertyKey> = new Set([\n ...FormControl.formStateProperties,\n 'readonly',\n 'minlength',\n 'maxlength',\n ]);\n\n static override properties: PropertyDeclarations = {\n value: { attribute: false },\n defaultValue: { attribute: 'value' },\n label: {},\n hint: {},\n placeholder: {},\n rows: { type: Number },\n resize: { reflect: true },\n size: { reflect: true },\n readonly: { type: Boolean, reflect: true },\n autocomplete: {},\n minlength: { type: Number },\n maxlength: { type: Number },\n };\n\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 /** Visible number of lines. */\n declare rows: number;\n /** How the user can resize the field. `auto` grows with the content. */\n declare resize: TextareaResize;\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 /** 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-textarea');\n\n constructor() {\n super();\n this.value = '';\n this.defaultValue = '';\n this.rows = 4;\n this.resize = 'vertical';\n this.size = 'md';\n this.readonly = false;\n }\n\n get #textarea(): HTMLTextAreaElement | null {\n return this.renderRoot.querySelector('textarea');\n }\n\n /** Selects all text in the field. */\n select(): void {\n this.#textarea?.select();\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.syncFormState();\n }\n\n protected syncFormState(): void {\n const textarea = this.#textarea;\n if (!textarea) return;\n this.internals.setFormValue(this.value);\n this.setValidityFrom(textarea);\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 HTMLTextAreaElement).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\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 <textarea\n id=${this.#id}\n class=\"native\"\n part=\"textarea\"\n name=${ifDefined(this.name || undefined)}\n .value=${live(this.value)}\n rows=${this.rows}\n placeholder=${ifDefined(this.placeholder)}\n autocomplete=${ifDefined(this.autocomplete)}\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 ></textarea>\n </div>\n `,\n });\n }\n}\n\ndefineElement('uf-textarea', UfTextarea);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'uf-textarea': UfTextarea;\n }\n}\n",
|
|
899
|
+
"components/textarea/textarea.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 { hostStyles } from '../../internal/shared.styles.js';\nimport { HasSlotController, uniqueId } from '../../internal/slot.js';\n\nexport type TextareaResize = 'none' | 'vertical' | 'auto';\n\n/**\n * A multi-line text field with a built-in label, hint and validation message.\n *\n * @summary Lets users enter multiple lines of text.\n * @tag uf-textarea\n *\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 on every keystroke.\n * @event change - Fired when the value is committed (blur).\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 textarea.\n * @csspart textarea - The native `<textarea>`.\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 UfTextarea extends FormControl {\n static override styles = [\n hostStyles,\n fieldStyles,\n controlBoxStyles,\n css`\n .box {\n align-items: stretch;\n padding-block: var(--uf-space-2);\n }\n\n .native {\n min-height: 3lh;\n line-height: 1.5;\n resize: vertical;\n }\n\n :host([resize='none']) .native {\n resize: none;\n }\n\n /* Grows with its content where supported (field-sizing), otherwise resizable. */\n :host([resize='auto']) .native {\n field-sizing: content;\n resize: none;\n }\n `,\n ];\n\n protected static override formStateProperties: ReadonlySet<PropertyKey> = new Set([\n ...FormControl.formStateProperties,\n 'readonly',\n 'minlength',\n 'maxlength',\n ]);\n\n static override properties: PropertyDeclarations = {\n value: { attribute: false },\n defaultValue: { attribute: 'value' },\n label: {},\n hint: {},\n placeholder: {},\n rows: { type: Number },\n resize: { reflect: true },\n size: { reflect: true },\n readonly: { type: Boolean, reflect: true },\n autocomplete: {},\n minlength: { type: Number },\n maxlength: { type: Number },\n };\n\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 /** Visible number of lines. */\n declare rows: number;\n /** How the user can resize the field. `auto` grows with the content. */\n declare resize: TextareaResize;\n /** Size of the field. */\n declare size: FieldSize;\n /** Makes the field read-only. */\n declare readonly: boolean;\n /** Native `autocomplete` hint: `email`, `nickname`, `shipping street-address`. Any HTML autofill token works. */\n declare autocomplete: AutoFill | (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-textarea');\n\n constructor() {\n super();\n this.value = '';\n this.defaultValue = '';\n this.rows = 4;\n this.resize = 'vertical';\n this.size = 'md';\n this.readonly = false;\n }\n\n get #textarea(): HTMLTextAreaElement | null {\n return this.renderRoot.querySelector('textarea');\n }\n\n /** Selects all text in the field. */\n select(): void {\n this.#textarea?.select();\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.syncFormState();\n }\n\n protected syncFormState(): void {\n const textarea = this.#textarea;\n if (!textarea) return;\n this.internals.setFormValue(this.value);\n this.setValidityFrom(textarea);\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 HTMLTextAreaElement).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\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 <textarea\n id=${this.#id}\n class=\"native\"\n part=\"textarea\"\n name=${ifDefined(this.name || undefined)}\n .value=${live(this.value)}\n rows=${this.rows}\n placeholder=${ifDefined(this.placeholder)}\n autocomplete=${ifDefined(this.autocomplete)}\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 ></textarea>\n </div>\n `,\n });\n }\n}\n\ndefineElement('uf-textarea', UfTextarea);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'uf-textarea': UfTextarea;\n }\n}\n",
|
|
900
900
|
"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-control);\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",
|
|
901
901
|
"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. Defaults to `--uf-radius-sm`.\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, var(--uf-radius-sm));\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"
|
|
902
902
|
},
|
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 1.0.0-rc.
|
|
8
|
+
Unframed 1.0.0-rc.4: 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
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Unframed 1.0.0-rc.
|
|
1
|
+
# Unframed 1.0.0-rc.4 components
|
|
2
2
|
|
|
3
3
|
## Accordion
|
|
4
4
|
|
|
@@ -1946,7 +1946,7 @@ Errors appear after the user edits the field or tries to submit.
|
|
|
1946
1946
|
| `placeholder` | | `string \| undefined` | | Placeholder text. |
|
|
1947
1947
|
| `size` | | `FieldSize` | `'md'` | Size of the field. |
|
|
1948
1948
|
| `readonly` | | `boolean` | `false` | Makes the field read-only. |
|
|
1949
|
-
| `autocomplete` | | `AutoFill \| undefined` | | Native `autocomplete` hint. |
|
|
1949
|
+
| `autocomplete` | | `AutoFill \| (string & {}) \| undefined` | | Native `autocomplete` hint: `email`, `nickname`, `shipping street-address`. Any HTML autofill token works. |
|
|
1950
1950
|
| `inputmode` | | `string \| undefined` | | Native `inputmode` hint for virtual keyboards. |
|
|
1951
1951
|
| `pattern` | | `string \| undefined` | | Regex the value must match. |
|
|
1952
1952
|
| `min` | | `string \| undefined` | | Minimum value, for number and date types. |
|
|
@@ -2690,7 +2690,7 @@ Built on the native `<select>`: write plain `<option>` and `<optgroup>` children
|
|
|
2690
2690
|
| `hint` | | `string \| undefined` | | Help text below the field. |
|
|
2691
2691
|
| `placeholder` | | `string \| undefined` | | Text shown while nothing is selected. |
|
|
2692
2692
|
| `size` | | `FieldSize` | `'md'` | Size of the field. |
|
|
2693
|
-
| `autocomplete` | | `AutoFill \| undefined` | | Native `autocomplete` hint. |
|
|
2693
|
+
| `autocomplete` | | `AutoFill \| (string & {}) \| undefined` | | Native `autocomplete` hint: `email`, `nickname`, `shipping street-address`. Any HTML autofill token works. |
|
|
2694
2694
|
| `name` | | `string` | `''` | Name submitted with the form. |
|
|
2695
2695
|
| `disabled` | | `boolean` | `false` | Disables the control. |
|
|
2696
2696
|
| `required` | | `boolean` | `false` | Makes the control required for form submission. |
|
|
@@ -3277,7 +3277,7 @@ Tags: `<uf-textarea>`. Import: `import '@unframed/core/textarea';` (or `npx @unf
|
|
|
3277
3277
|
| `resize` | | `TextareaResize` | `'vertical'` | How the user can resize the field. `auto` grows with the content. |
|
|
3278
3278
|
| `size` | | `FieldSize` | `'md'` | Size of the field. |
|
|
3279
3279
|
| `readonly` | | `boolean` | `false` | Makes the field read-only. |
|
|
3280
|
-
| `autocomplete` | | `AutoFill \| undefined` | | Native `autocomplete` hint. |
|
|
3280
|
+
| `autocomplete` | | `AutoFill \| (string & {}) \| undefined` | | Native `autocomplete` hint: `email`, `nickname`, `shipping street-address`. Any HTML autofill token works. |
|
|
3281
3281
|
| `minlength` | | `number \| undefined` | | Minimum length. |
|
|
3282
3282
|
| `maxlength` | | `number \| undefined` | | Maximum length. |
|
|
3283
3283
|
| `name` | | `string` | `''` | Name submitted with the form. |
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Using Unframed 1.0.0-rc.
|
|
1
|
+
# Using Unframed 1.0.0-rc.4 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@1.0.0-rc.
|
|
72
|
-
<script type="module" src="https://cdn.jsdelivr.net/npm/@unframed/core@1.0.0-rc.
|
|
71
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@unframed/tokens@1.0.0-rc.4/dist/tokens.css" />
|
|
72
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/@unframed/core@1.0.0-rc.4/+esm"></script>
|
|
73
73
|
</head>
|
|
74
74
|
<body>
|
|
75
75
|
<uf-button variant="primary">It works</uf-button>
|