@slurp-ui/react 1.1.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +42 -0
- package/dist/Bloom/Bloom.js +3 -2
- package/dist/Bloom/Bloom.js.map +1 -1
- package/dist/Calendar/Calendar.d.ts +42 -0
- package/dist/Calendar/Calendar.js +178 -0
- package/dist/Calendar/Calendar.js.map +1 -0
- package/dist/Calendar/dates.d.ts +3 -0
- package/dist/Calendar/dates.js +46 -0
- package/dist/Calendar/dates.js.map +1 -0
- package/dist/Calendar/index.d.ts +3 -0
- package/dist/Calendar/index.js +2 -0
- package/dist/Carousel/Carousel.js +2 -0
- package/dist/Carousel/Carousel.js.map +1 -1
- package/dist/Choice/Choice.js +2 -0
- package/dist/Choice/Choice.js.map +1 -1
- package/dist/Code/Code.d.ts +38 -0
- package/dist/Code/Code.js +82 -0
- package/dist/Code/Code.js.map +1 -0
- package/dist/Code/index.d.ts +3 -0
- package/dist/Code/index.js +2 -0
- package/dist/Contents/Contents.d.ts +35 -0
- package/dist/Contents/Contents.js +63 -0
- package/dist/Contents/Contents.js.map +1 -0
- package/dist/Contents/index.d.ts +3 -0
- package/dist/Contents/index.js +2 -0
- package/dist/DateField/DateField.d.ts +29 -0
- package/dist/DateField/DateField.js +118 -0
- package/dist/DateField/DateField.js.map +1 -0
- package/dist/DateField/index.d.ts +3 -0
- package/dist/DateField/index.js +2 -0
- package/dist/Dialog/Dialog.js +73 -25
- package/dist/Dialog/Dialog.js.map +1 -1
- package/dist/Dock/Dock.d.ts +5 -0
- package/dist/Dock/Dock.js +13 -2
- package/dist/Dock/Dock.js.map +1 -1
- package/dist/ErrorSummary/ErrorSummary.d.ts +26 -0
- package/dist/ErrorSummary/ErrorSummary.js +68 -0
- package/dist/ErrorSummary/ErrorSummary.js.map +1 -0
- package/dist/ErrorSummary/index.d.ts +3 -0
- package/dist/ErrorSummary/index.js +2 -0
- package/dist/FileDrop/FileDrop.d.ts +34 -0
- package/dist/FileDrop/FileDrop.js +145 -0
- package/dist/FileDrop/FileDrop.js.map +1 -0
- package/dist/FileDrop/index.d.ts +3 -0
- package/dist/FileDrop/index.js +2 -0
- package/dist/Filters/Filters.js +2 -0
- package/dist/Filters/Filters.js.map +1 -1
- package/dist/Footer/Footer.d.ts +37 -0
- package/dist/Footer/Footer.js +63 -0
- package/dist/Footer/Footer.js.map +1 -0
- package/dist/Footer/index.d.ts +3 -0
- package/dist/Footer/index.js +2 -0
- package/dist/Hairline/Hairline.d.ts +16 -0
- package/dist/Hairline/Hairline.js +23 -0
- package/dist/Hairline/Hairline.js.map +1 -0
- package/dist/Hairline/index.d.ts +3 -0
- package/dist/Hairline/index.js +2 -0
- package/dist/Hint/Hint.js +20 -1
- package/dist/Hint/Hint.js.map +1 -1
- package/dist/Kbd/Kbd.d.ts +7 -0
- package/dist/Kbd/Kbd.js +20 -0
- package/dist/Kbd/Kbd.js.map +1 -0
- package/dist/Kbd/index.d.ts +3 -0
- package/dist/Kbd/index.js +2 -0
- package/dist/ListRow/ListRow.d.ts +5 -1
- package/dist/ListRow/ListRow.js +5 -1
- package/dist/ListRow/ListRow.js.map +1 -1
- package/dist/Media/Media.d.ts +28 -0
- package/dist/Media/Media.js +65 -0
- package/dist/Media/Media.js.map +1 -0
- package/dist/Media/index.d.ts +3 -0
- package/dist/Media/index.js +2 -0
- package/dist/Notice/Notice.js +2 -0
- package/dist/Notice/Notice.js.map +1 -1
- package/dist/NumberField/NumberField.d.ts +32 -0
- package/dist/NumberField/NumberField.js +126 -0
- package/dist/NumberField/NumberField.js.map +1 -0
- package/dist/NumberField/index.d.ts +3 -0
- package/dist/NumberField/index.js +2 -0
- package/dist/PageNav/PageNav.d.ts +25 -0
- package/dist/PageNav/PageNav.js +57 -0
- package/dist/PageNav/PageNav.js.map +1 -0
- package/dist/PageNav/index.d.ts +3 -0
- package/dist/PageNav/index.js +2 -0
- package/dist/Pages/Pages.js +2 -0
- package/dist/Pages/Pages.js.map +1 -1
- package/dist/PinField/PinField.d.ts +26 -0
- package/dist/PinField/PinField.js +73 -0
- package/dist/PinField/PinField.js.map +1 -0
- package/dist/PinField/index.d.ts +3 -0
- package/dist/PinField/index.js +2 -0
- package/dist/Prose/Prose.d.ts +15 -0
- package/dist/Prose/Prose.js +25 -0
- package/dist/Prose/Prose.js.map +1 -0
- package/dist/Prose/index.d.ts +3 -0
- package/dist/Prose/index.js +2 -0
- package/dist/Quote/Quote.d.ts +19 -0
- package/dist/Quote/Quote.js +52 -0
- package/dist/Quote/Quote.js.map +1 -0
- package/dist/Quote/index.d.ts +3 -0
- package/dist/Quote/index.js +2 -0
- package/dist/Rail/Rail.d.ts +37 -0
- package/dist/Rail/Rail.js +61 -0
- package/dist/Rail/Rail.js.map +1 -0
- package/dist/Rail/index.d.ts +3 -0
- package/dist/Rail/index.js +2 -0
- package/dist/Rating/Rating.js +2 -0
- package/dist/Rating/Rating.js.map +1 -1
- package/dist/Search/Search.js +2 -0
- package/dist/Search/Search.js.map +1 -1
- package/dist/SecretField/SecretField.d.ts +17 -0
- package/dist/SecretField/SecretField.js +59 -0
- package/dist/SecretField/SecretField.js.map +1 -0
- package/dist/SecretField/index.d.ts +3 -0
- package/dist/SecretField/index.js +2 -0
- package/dist/Settings/Settings.js +2 -0
- package/dist/Settings/Settings.js.map +1 -1
- package/dist/SkipLink/SkipLink.d.ts +22 -0
- package/dist/SkipLink/SkipLink.js +32 -0
- package/dist/SkipLink/SkipLink.js.map +1 -0
- package/dist/SkipLink/index.d.ts +3 -0
- package/dist/SkipLink/index.js +2 -0
- package/dist/SlurpProvider/SlurpProvider.d.ts +7 -1
- package/dist/SlurpProvider/SlurpProvider.js +14 -6
- package/dist/SlurpProvider/SlurpProvider.js.map +1 -1
- package/dist/Steps/Steps.js +2 -0
- package/dist/Steps/Steps.js.map +1 -1
- package/dist/Suggest/Suggest.js +2 -0
- package/dist/Suggest/Suggest.js.map +1 -1
- package/dist/Table/Table.js +2 -0
- package/dist/Table/Table.js.map +1 -1
- package/dist/Tag/Tag.d.ts +14 -0
- package/dist/Tag/Tag.js +26 -0
- package/dist/Tag/Tag.js.map +1 -0
- package/dist/Tag/index.d.ts +3 -0
- package/dist/Tag/index.js +2 -0
- package/dist/Toast/Toast.js +31 -7
- package/dist/Toast/Toast.js.map +1 -1
- package/dist/index.d.ts +45 -4
- package/dist/index.js +23 -1
- package/dist/internal/labels.js +12 -0
- package/dist/internal/labels.js.map +1 -0
- package/dist/lib/labels.d.ts +175 -0
- package/dist/lib/labels.js +116 -0
- package/dist/lib/labels.js.map +1 -0
- package/dist/lib/theme.d.ts +98 -3
- package/dist/lib/theme.js.map +1 -1
- package/dist/styles.css +1367 -111
- package/dist/tokens.css +9 -0
- package/dist/utils/focus.d.ts +1 -1
- package/dist/utils/focus.js +2 -2
- package/dist/utils/focus.js.map +1 -1
- package/dist/utils/index.d.ts +3 -1
- package/dist/utils/index.js +3 -1
- package/dist/utils/useClipboard.d.ts +14 -0
- package/dist/utils/useClipboard.js +30 -0
- package/dist/utils/useClipboard.js.map +1 -0
- package/dist/utils/useScrollSpy.d.ts +14 -0
- package/dist/utils/useScrollSpy.js +27 -0
- package/dist/utils/useScrollSpy.js.map +1 -0
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Suggest.js","names":[],"sources":["../../src/Suggest/Suggest.tsx"],"sourcesContent":["import { CheckIcon, ErrorIcon } from '@slurp-ui/icons';\nimport { cx } from '@slurp-ui/utils';\nimport {\n Fragment,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n type ChangeEvent,\n type ElementType,\n type FocusEvent,\n type KeyboardEvent,\n type MouseEvent,\n type ReactNode,\n} from 'react';\n\nimport { splitInputProps, type InputAttributes } from '../Field/Field';\nimport { useAnimationRoot } from '../internal/animation';\nimport { useCss, useParts, useThemeProps } from '../internal/styled';\nimport { matchesAll } from '../lib/layout';\nimport type { PartsProps, PolymorphicProps } from '../lib/polymorphic';\nimport { Mark } from '../Mark/Mark';\nimport { useControlled } from '../utils/useControlled';\nimport { useDismiss } from '../utils/useDismiss';\n\nexport interface SuggestOption<V extends string = string> {\n value: V;\n /** Text of the option, written into the field when chosen. */\n label: string;\n /** A second line (a brand, a category); also searched. */\n description?: string;\n disabled?: boolean;\n}\n\nexport interface SuggestLabels {\n /** Number of suggestions, announced politely while typing. */\n results: (count: number) => string;\n /** Shown in the list, and announced, when nothing matches. */\n empty: string;\n}\n\nexport const SUGGEST_LABELS: SuggestLabels = {\n results: (n) => (n === 1 ? '1 suggerimento' : `${n} suggerimenti`),\n empty: 'Nessun suggerimento',\n};\n\nexport interface SuggestOwnProps<V extends string = string>\n extends\n Omit<InputAttributes, 'type'>,\n PartsProps<'label' | 'control' | 'list' | 'option' | 'hint' | 'error'> {\n /** Visible label. */\n label: ReactNode;\n hint?: ReactNode;\n /** Error message: marks the field invalid. */\n error?: ReactNode;\n options: SuggestOption<V>[];\n /** The chosen option; null while the text matches none. */\n value?: V | null;\n defaultValue?: V | null;\n onValueChange?: (value: V | null) => void;\n /** The text in the field. */\n inputValue?: string;\n /** Default the label of the chosen option, else empty. */\n defaultInputValue?: string;\n onInputValueChange?: (text: string) => void;\n /**\n * Which options match the text. Default: every word of the text, in any order, ignoring case and accents, in the\n * label or the description. `false` when the app already filters `options` (results from a server).\n */\n filter?: ((option: SuggestOption<V>, text: string) => boolean) | false;\n /** Most suggestions listed. Default 8. */\n limit?: number;\n /** Lists the suggestions as soon as the field takes focus. Default false (they show while typing). */\n openOnFocus?: boolean;\n labels?: Partial<SuggestLabels>;\n}\n\nexport type SuggestProps<\n V extends string = string,\n E extends ElementType = 'div',\n> = PolymorphicProps<E, SuggestOwnProps<V>>;\n\nconst matches = (o: SuggestOption, text: string) =>\n matchesAll(o.description ? `${o.label} ${o.description}` : o.label, text);\n\n/**\n * Text field with suggestions (combobox): the field **becomes** the list, growing downward on one surface. Focus\n * stays in the field: arrows move through the suggestions, Enter chooses, Escape closes (then clears); matches are\n * marked in the options.\n */\nexport function Suggest<V extends string = string, E extends ElementType = 'div'>(\n props: SuggestProps<V, E>,\n) {\n const {\n as,\n css,\n className,\n label,\n hint,\n error,\n options,\n value: valueProp,\n defaultValue = null,\n onValueChange,\n inputValue,\n defaultInputValue,\n onInputValueChange,\n filter,\n limit = 8,\n openOnFocus = false,\n labels: labelsProp,\n parts,\n partProps,\n classNames,\n ...others\n } = useThemeProps('Suggest', props as unknown as SuggestProps);\n const labels = { ...SUGGEST_LABELS, ...labelsProp };\n const { input, root: rest } = splitInputProps(others);\n const { name, disabled, onKeyDown, onFocus, onBlur, ...inputRest } = input as InputAttributes;\n const [value, setValue] = useControlled<string | null>({\n value: valueProp,\n defaultValue,\n onChange: onValueChange as ((v: string | null) => void) | undefined,\n });\n const [text, setText] = useControlled({\n value: inputValue,\n defaultValue:\n defaultInputValue ??\n options.find((o) => o.value === (valueProp ?? defaultValue))?.label ??\n '',\n onChange: onInputValueChange,\n });\n const [open, setOpen] = useState(false);\n const [active, setActive] = useState(-1);\n const box = useRef<HTMLDivElement>(null);\n const id = useId();\n const inputId = `${id}-input`;\n const listId = `${id}-list`;\n const hintId = hint != null ? `${id}-hint` : undefined;\n const errorId = error != null && error !== false ? `${id}-error` : undefined;\n const Root = (as ?? 'div') as ElementType;\n const styled = useCss('Suggest', 'root', css);\n const { part, style } = useParts('Suggest', { parts, partProps, classNames });\n const root = useAnimationRoot(rest);\n\n const chosen = options.find((o) => o.value === value);\n // With the chosen option's own text in the field, every option is offered again.\n const query = chosen && text === chosen.label ? '' : text.trim();\n const found = useMemo(() => {\n const all =\n filter === false || !query ? options : options.filter((o) => (filter ?? matches)(o, query));\n return all.slice(0, Math.max(0, limit));\n }, [options, filter, query, limit]);\n // While the list closes it keeps the suggestions it showed, so they shrink away instead of changing.\n const [listed, setListed] = useState(found);\n if (open && listed !== found) setListed(found);\n\n const close = () => {\n setOpen(false);\n setActive(-1);\n };\n const dismiss = useDismiss({ ref: box, open, onDismiss: close });\n\n useEffect(() => {\n if (open && active >= 0)\n document.getElementById(`${listId}-${active}`)?.scrollIntoView?.({ block: 'nearest' });\n }, [open, active, listId]);\n\n /** Next enabled suggestion from `from` in direction `step`, wrapping; -1 when none. */\n const next = (from: number, step: 1 | -1) => {\n const n = found.length;\n for (let k = 1; k <= n; k++) {\n const i = (((from + step * k) % n) + n) % n;\n if (!found[i]?.disabled) return i;\n }\n return -1;\n };\n\n const choose = (o: SuggestOption) => {\n if (o.disabled) return;\n if (o.value !== value) setValue(o.value);\n if (o.label !== text) setText(o.label);\n close();\n };\n\n const keys = (e: KeyboardEvent<HTMLInputElement>) => {\n onKeyDown?.(e);\n if (e.defaultPrevented) return;\n if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {\n e.preventDefault();\n const step = e.key === 'ArrowDown' ? 1 : -1;\n if (!open) {\n setOpen(true);\n const at = found.findIndex((o) => o.value === value);\n setActive(e.altKey ? -1 : at >= 0 ? at : next(step === 1 ? -1 : 0, step));\n } else setActive(next(active < 0 && step === -1 ? 0 : active, step));\n } else if (e.key === 'Enter' && open && active >= 0) {\n e.preventDefault();\n const o = found[active];\n if (o) choose(o);\n } else if (e.key === 'Escape') {\n if (open) {\n e.preventDefault();\n e.stopPropagation();\n close();\n } else if (text) {\n e.preventDefault();\n setText('');\n if (value != null) setValue(null);\n }\n }\n };\n\n const showing = open && !disabled;\n const status =\n showing && query ? (found.length ? labels.results(found.length) : labels.empty) : '';\n\n return (\n <>\n {styled.style}\n {style}\n <Root\n className={cx('slurp-suggest', styled.className, className)}\n data-open={showing ? '' : undefined}\n data-invalid={errorId ? '' : undefined}\n data-disabled={disabled ? '' : undefined}\n {...root}\n >\n {part('label', 'label', {\n id: `${id}-label`,\n htmlFor: inputId,\n className: 'slurp-suggest-label',\n children: label,\n })}\n <div ref={box} className=\"slurp-suggest-box\" onBlur={dismiss.containerProps.onBlur}>\n <div className=\"slurp-suggest-surface\">\n {part('control', 'input', {\n ...inputRest,\n id: inputId,\n type: 'text',\n role: 'combobox',\n className: 'slurp-suggest-control',\n disabled,\n autoComplete: inputRest.autoComplete ?? 'off',\n 'aria-expanded': showing,\n 'aria-controls': listId,\n 'aria-autocomplete': 'list',\n 'aria-activedescendant': showing && active >= 0 ? `${listId}-${active}` : undefined,\n 'aria-invalid': errorId ? true : undefined,\n 'aria-describedby': cx(errorId, hintId) || undefined,\n value: text,\n onChange: (e: ChangeEvent<HTMLInputElement>) => {\n const v = e.target.value;\n setText(v);\n if (value != null && v !== chosen?.label) setValue(null);\n setOpen(true);\n setActive(-1);\n },\n onKeyDown: keys,\n onFocus: (e: FocusEvent<HTMLInputElement>) => {\n onFocus?.(e);\n if (openOnFocus) setOpen(true);\n },\n onBlur,\n onClick: () => {\n if (!open) setOpen(true);\n },\n })}\n <div className=\"slurp-suggest-clip\">\n {listed.length > 0 ? (\n part('list', 'ul', {\n id: listId,\n role: 'listbox',\n 'aria-labelledby': `${id}-label`,\n className: 'slurp-suggest-list',\n children: listed.map((o, i) => (\n <Fragment key={o.value}>\n {part('option', 'li', {\n id: `${listId}-${i}`,\n role: 'option',\n className: 'slurp-suggest-option',\n 'aria-selected': showing && i === active,\n 'aria-disabled': o.disabled || undefined,\n 'data-chosen': o.value === value ? '' : undefined,\n // Keep focus in the field.\n onMouseDown: (e: MouseEvent) => e.preventDefault(),\n onPointerMove: () => {\n if (!o.disabled && i !== active) setActive(i);\n },\n onClick: () => choose(o),\n children: (\n <>\n <span className=\"slurp-suggest-option-text\">\n <span className=\"slurp-suggest-option-label\">\n <Mark text={o.label} query={query} />\n </span>\n {o.description && (\n <span className=\"slurp-suggest-option-description\">\n <Mark text={o.description} query={query} />\n </span>\n )}\n </span>\n {o.value === value && (\n <span className=\"slurp-suggest-option-check\" aria-hidden=\"true\">\n <CheckIcon size={18} />\n </span>\n )}\n </>\n ),\n })}\n </Fragment>\n )),\n })\n ) : (\n <p id={listId} className=\"slurp-suggest-empty\">\n {labels.empty}\n </p>\n )}\n </div>\n </div>\n </div>\n {hintId &&\n part('hint', 'p', { id: hintId, className: 'slurp-suggest-hint', children: hint })}\n {errorId &&\n part('error', 'p', {\n id: errorId,\n className: 'slurp-suggest-error',\n children: (\n <>\n <ErrorIcon size={16} />\n <span>{error}</span>\n </>\n ),\n })}\n <span className=\"slurp-visually-hidden\" role=\"status\">\n {status}\n </span>\n {name && <input type=\"hidden\" name={name} value={value ?? ''} />}\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;AA0CA,MAAa,iBAAgC;CAC3C,UAAU,MAAO,MAAM,IAAI,mBAAmB,GAAG,EAAE;CACnD,OAAO;AACT;AAsCA,MAAM,WAAW,GAAkB,SACjC,WAAW,EAAE,cAAc,GAAG,EAAE,MAAM,GAAG,EAAE,gBAAgB,EAAE,OAAO,IAAI;;;;;;AAO1E,SAAgB,QACd,OACA;CACA,MAAM,EACJ,IACA,KACA,WACA,OACA,MACA,OACA,SACA,OAAO,WACP,eAAe,MACf,eACA,YACA,mBACA,oBACA,QACA,QAAQ,GACR,cAAc,OACd,QAAQ,YACR,OACA,WACA,YACA,GAAG,WACD,cAAc,WAAW,KAAgC;CAC7D,MAAM,SAAS;EAAE,GAAG;EAAgB,GAAG;CAAW;CAClD,MAAM,EAAE,OAAO,MAAM,SAAS,gBAAgB,MAAM;CACpD,MAAM,EAAE,MAAM,UAAU,WAAW,SAAS,QAAQ,GAAG,cAAc;CACrE,MAAM,CAAC,OAAO,YAAY,cAA6B;EACrD,OAAO;EACP;EACA,UAAU;CACZ,CAAC;CACD,MAAM,CAAC,MAAM,WAAW,cAAc;EACpC,OAAO;EACP,cACE,qBACA,QAAQ,MAAM,MAAM,EAAE,WAAW,aAAa,aAAa,CAAC,EAAE,SAC9D;EACF,UAAU;CACZ,CAAC;CACD,MAAM,CAAC,MAAM,WAAW,SAAS,KAAK;CACtC,MAAM,CAAC,QAAQ,aAAa,SAAS,EAAE;CACvC,MAAM,MAAM,OAAuB,IAAI;CACvC,MAAM,KAAK,MAAM;CACjB,MAAM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,oBAAC,SAAD;KAAO,MAAK;KAAe;KAAM,OAAO,SAAS;IAAK,CAAA;GAC3D;;CACN,EAAA,CAAA;AAEN"}
|
|
1
|
+
{"version":3,"file":"Suggest.js","names":[],"sources":["../../src/Suggest/Suggest.tsx"],"sourcesContent":["import { CheckIcon, ErrorIcon } from '@slurp-ui/icons';\nimport { cx } from '@slurp-ui/utils';\nimport {\n Fragment,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n type ChangeEvent,\n type ElementType,\n type FocusEvent,\n type KeyboardEvent,\n type MouseEvent,\n type ReactNode,\n} from 'react';\n\nimport { useLabels } from '../internal/labels';\nimport { splitInputProps, type InputAttributes } from '../Field/Field';\nimport { useAnimationRoot } from '../internal/animation';\nimport { useCss, useParts, useThemeProps } from '../internal/styled';\nimport { matchesAll } from '../lib/layout';\nimport type { PartsProps, PolymorphicProps } from '../lib/polymorphic';\nimport { Mark } from '../Mark/Mark';\nimport { useControlled } from '../utils/useControlled';\nimport { useDismiss } from '../utils/useDismiss';\n\nexport interface SuggestOption<V extends string = string> {\n value: V;\n /** Text of the option, written into the field when chosen. */\n label: string;\n /** A second line (a brand, a category); also searched. */\n description?: string;\n disabled?: boolean;\n}\n\nexport interface SuggestLabels {\n /** Number of suggestions, announced politely while typing. */\n results: (count: number) => string;\n /** Shown in the list, and announced, when nothing matches. */\n empty: string;\n}\n\nexport const SUGGEST_LABELS: SuggestLabels = {\n results: (n) => (n === 1 ? '1 suggerimento' : `${n} suggerimenti`),\n empty: 'Nessun suggerimento',\n};\n\nexport interface SuggestOwnProps<V extends string = string>\n extends\n Omit<InputAttributes, 'type'>,\n PartsProps<'label' | 'control' | 'list' | 'option' | 'hint' | 'error'> {\n /** Visible label. */\n label: ReactNode;\n hint?: ReactNode;\n /** Error message: marks the field invalid. */\n error?: ReactNode;\n options: SuggestOption<V>[];\n /** The chosen option; null while the text matches none. */\n value?: V | null;\n defaultValue?: V | null;\n onValueChange?: (value: V | null) => void;\n /** The text in the field. */\n inputValue?: string;\n /** Default the label of the chosen option, else empty. */\n defaultInputValue?: string;\n onInputValueChange?: (text: string) => void;\n /**\n * Which options match the text. Default: every word of the text, in any order, ignoring case and accents, in the\n * label or the description. `false` when the app already filters `options` (results from a server).\n */\n filter?: ((option: SuggestOption<V>, text: string) => boolean) | false;\n /** Most suggestions listed. Default 8. */\n limit?: number;\n /** Lists the suggestions as soon as the field takes focus. Default false (they show while typing). */\n openOnFocus?: boolean;\n labels?: Partial<SuggestLabels>;\n}\n\nexport type SuggestProps<\n V extends string = string,\n E extends ElementType = 'div',\n> = PolymorphicProps<E, SuggestOwnProps<V>>;\n\nconst matches = (o: SuggestOption, text: string) =>\n matchesAll(o.description ? `${o.label} ${o.description}` : o.label, text);\n\n/**\n * Text field with suggestions (combobox): the field **becomes** the list, growing downward on one surface. Focus\n * stays in the field: arrows move through the suggestions, Enter chooses, Escape closes (then clears); matches are\n * marked in the options.\n */\nexport function Suggest<V extends string = string, E extends ElementType = 'div'>(\n props: SuggestProps<V, E>,\n) {\n const {\n as,\n css,\n className,\n label,\n hint,\n error,\n options,\n value: valueProp,\n defaultValue = null,\n onValueChange,\n inputValue,\n defaultInputValue,\n onInputValueChange,\n filter,\n limit = 8,\n openOnFocus = false,\n labels: labelsProp,\n parts,\n partProps,\n classNames,\n ...others\n } = useThemeProps('Suggest', props as unknown as SuggestProps);\n const labels = { ...SUGGEST_LABELS, ...useLabels('Suggest'), ...labelsProp };\n const { input, root: rest } = splitInputProps(others);\n const { name, disabled, onKeyDown, onFocus, onBlur, ...inputRest } = input as InputAttributes;\n const [value, setValue] = useControlled<string | null>({\n value: valueProp,\n defaultValue,\n onChange: onValueChange as ((v: string | null) => void) | undefined,\n });\n const [text, setText] = useControlled({\n value: inputValue,\n defaultValue:\n defaultInputValue ??\n options.find((o) => o.value === (valueProp ?? defaultValue))?.label ??\n '',\n onChange: onInputValueChange,\n });\n const [open, setOpen] = useState(false);\n const [active, setActive] = useState(-1);\n const box = useRef<HTMLDivElement>(null);\n const id = useId();\n const inputId = `${id}-input`;\n const listId = `${id}-list`;\n const hintId = hint != null ? `${id}-hint` : undefined;\n const errorId = error != null && error !== false ? `${id}-error` : undefined;\n const Root = (as ?? 'div') as ElementType;\n const styled = useCss('Suggest', 'root', css);\n const { part, style } = useParts('Suggest', { parts, partProps, classNames });\n const root = useAnimationRoot(rest);\n\n const chosen = options.find((o) => o.value === value);\n // With the chosen option's own text in the field, every option is offered again.\n const query = chosen && text === chosen.label ? '' : text.trim();\n const found = useMemo(() => {\n const all =\n filter === false || !query ? options : options.filter((o) => (filter ?? matches)(o, query));\n return all.slice(0, Math.max(0, limit));\n }, [options, filter, query, limit]);\n // While the list closes it keeps the suggestions it showed, so they shrink away instead of changing.\n const [listed, setListed] = useState(found);\n if (open && listed !== found) setListed(found);\n\n const close = () => {\n setOpen(false);\n setActive(-1);\n };\n const dismiss = useDismiss({ ref: box, open, onDismiss: close });\n\n useEffect(() => {\n if (open && active >= 0)\n document.getElementById(`${listId}-${active}`)?.scrollIntoView?.({ block: 'nearest' });\n }, [open, active, listId]);\n\n /** Next enabled suggestion from `from` in direction `step`, wrapping; -1 when none. */\n const next = (from: number, step: 1 | -1) => {\n const n = found.length;\n for (let k = 1; k <= n; k++) {\n const i = (((from + step * k) % n) + n) % n;\n if (!found[i]?.disabled) return i;\n }\n return -1;\n };\n\n const choose = (o: SuggestOption) => {\n if (o.disabled) return;\n if (o.value !== value) setValue(o.value);\n if (o.label !== text) setText(o.label);\n close();\n };\n\n const keys = (e: KeyboardEvent<HTMLInputElement>) => {\n onKeyDown?.(e);\n if (e.defaultPrevented) return;\n if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {\n e.preventDefault();\n const step = e.key === 'ArrowDown' ? 1 : -1;\n if (!open) {\n setOpen(true);\n const at = found.findIndex((o) => o.value === value);\n setActive(e.altKey ? -1 : at >= 0 ? at : next(step === 1 ? -1 : 0, step));\n } else setActive(next(active < 0 && step === -1 ? 0 : active, step));\n } else if (e.key === 'Enter' && open && active >= 0) {\n e.preventDefault();\n const o = found[active];\n if (o) choose(o);\n } else if (e.key === 'Escape') {\n if (open) {\n e.preventDefault();\n e.stopPropagation();\n close();\n } else if (text) {\n e.preventDefault();\n setText('');\n if (value != null) setValue(null);\n }\n }\n };\n\n const showing = open && !disabled;\n const status =\n showing && query ? (found.length ? labels.results(found.length) : labels.empty) : '';\n\n return (\n <>\n {styled.style}\n {style}\n <Root\n className={cx('slurp-suggest', styled.className, className)}\n data-open={showing ? '' : undefined}\n data-invalid={errorId ? '' : undefined}\n data-disabled={disabled ? '' : undefined}\n {...root}\n >\n {part('label', 'label', {\n id: `${id}-label`,\n htmlFor: inputId,\n className: 'slurp-suggest-label',\n children: label,\n })}\n <div ref={box} className=\"slurp-suggest-box\" onBlur={dismiss.containerProps.onBlur}>\n <div className=\"slurp-suggest-surface\">\n {part('control', 'input', {\n ...inputRest,\n id: inputId,\n type: 'text',\n role: 'combobox',\n className: 'slurp-suggest-control',\n disabled,\n autoComplete: inputRest.autoComplete ?? 'off',\n 'aria-expanded': showing,\n 'aria-controls': listId,\n 'aria-autocomplete': 'list',\n 'aria-activedescendant': showing && active >= 0 ? `${listId}-${active}` : undefined,\n 'aria-invalid': errorId ? true : undefined,\n 'aria-describedby': cx(errorId, hintId) || undefined,\n value: text,\n onChange: (e: ChangeEvent<HTMLInputElement>) => {\n const v = e.target.value;\n setText(v);\n if (value != null && v !== chosen?.label) setValue(null);\n setOpen(true);\n setActive(-1);\n },\n onKeyDown: keys,\n onFocus: (e: FocusEvent<HTMLInputElement>) => {\n onFocus?.(e);\n if (openOnFocus) setOpen(true);\n },\n onBlur,\n onClick: () => {\n if (!open) setOpen(true);\n },\n })}\n <div className=\"slurp-suggest-clip\">\n {listed.length > 0 ? (\n part('list', 'ul', {\n id: listId,\n role: 'listbox',\n 'aria-labelledby': `${id}-label`,\n className: 'slurp-suggest-list',\n children: listed.map((o, i) => (\n <Fragment key={o.value}>\n {part('option', 'li', {\n id: `${listId}-${i}`,\n role: 'option',\n className: 'slurp-suggest-option',\n 'aria-selected': showing && i === active,\n 'aria-disabled': o.disabled || undefined,\n 'data-chosen': o.value === value ? '' : undefined,\n // Keep focus in the field.\n onMouseDown: (e: MouseEvent) => e.preventDefault(),\n onPointerMove: () => {\n if (!o.disabled && i !== active) setActive(i);\n },\n onClick: () => choose(o),\n children: (\n <>\n <span className=\"slurp-suggest-option-text\">\n <span className=\"slurp-suggest-option-label\">\n <Mark text={o.label} query={query} />\n </span>\n {o.description && (\n <span className=\"slurp-suggest-option-description\">\n <Mark text={o.description} query={query} />\n </span>\n )}\n </span>\n {o.value === value && (\n <span className=\"slurp-suggest-option-check\" aria-hidden=\"true\">\n <CheckIcon size={18} />\n </span>\n )}\n </>\n ),\n })}\n </Fragment>\n )),\n })\n ) : (\n <p id={listId} className=\"slurp-suggest-empty\">\n {labels.empty}\n </p>\n )}\n </div>\n </div>\n </div>\n {hintId &&\n part('hint', 'p', { id: hintId, className: 'slurp-suggest-hint', children: hint })}\n {errorId &&\n part('error', 'p', {\n id: errorId,\n className: 'slurp-suggest-error',\n children: (\n <>\n <ErrorIcon size={16} />\n <span>{error}</span>\n </>\n ),\n })}\n <span className=\"slurp-visually-hidden\" role=\"status\">\n {status}\n </span>\n {name && <input type=\"hidden\" name={name} value={value ?? ''} />}\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;AA2CA,MAAa,iBAAgC;CAC3C,UAAU,MAAO,MAAM,IAAI,mBAAmB,GAAG,EAAE;CACnD,OAAO;AACT;AAsCA,MAAM,WAAW,GAAkB,SACjC,WAAW,EAAE,cAAc,GAAG,EAAE,MAAM,GAAG,EAAE,gBAAgB,EAAE,OAAO,IAAI;;;;;;AAO1E,SAAgB,QACd,OACA;CACA,MAAM,EACJ,IACA,KACA,WACA,OACA,MACA,OACA,SACA,OAAO,WACP,eAAe,MACf,eACA,YACA,mBACA,oBACA,QACA,QAAQ,GACR,cAAc,OACd,QAAQ,YACR,OACA,WACA,YACA,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ACvD,UAAA,oBAAC,WAAD,EAAW,MAAM,GAAK,CAAA;SAClB,CAAA,CAER,EAAA,CAAA;QAEN,CAAC,EACO,GAlCK,EAAE,KAkCP,CACX;OACH,CAAC,IAED,oBAAC,KAAD;QAAG,IAAI;QAAQ,WAAU;QACtB,UAAA,OAAO;OACP,CAAA;MAEF,CAAA,CACF;;IACF,CAAA;IACJ,UACC,KAAK,QAAQ,KAAK;KAAE,IAAI;KAAQ,WAAW;KAAsB,UAAU;IAAK,CAAC;IAClF,WACC,KAAK,SAAS,KAAK;KACjB,IAAI;KACJ,WAAW;KACX,UACE,qBAAA,YAAA,EAAA,UAAA,CACE,oBAAC,WAAD,EAAW,MAAM,GAAK,CAAA,GACtB,oBAAC,QAAD,EAAA,UAAO,MAAY,CAAA,CACnB,EAAA,CAAA;IAEN,CAAC;IACH,oBAAC,QAAD;KAAM,WAAU;KAAwB,MAAK;KAC1C,UAAA;IACG,CAAA;IACL,QAAQ,oBAAC,SAAD;KAAO,MAAK;KAAe;KAAM,OAAO,SAAS;IAAK,CAAA;GAC3D;;CACN,EAAA,CAAA;AAEN"}
|
package/dist/Table/Table.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useTheme } from "../internal/context.js";
|
|
3
|
+
import { useLabels } from "../internal/labels.js";
|
|
3
4
|
import { cx } from "../utils/src/index.js";
|
|
4
5
|
import { useAnimationRoot } from "../internal/animation.js";
|
|
5
6
|
import { useCss, useParts, useThemeProps } from "../internal/styled.js";
|
|
@@ -18,6 +19,7 @@ function Table(props) {
|
|
|
18
19
|
const { as, css, className, caption, hideCaption = false, columns, rows, rowKey, sort: sortProp, defaultSort = null, onSortChange, manualSort = false, labels: labelsProp, parts, partProps, classNames, ...rest } = useThemeProps("Table", props);
|
|
19
20
|
const labels = {
|
|
20
21
|
...TABLE_LABELS,
|
|
22
|
+
...useLabels("Table"),
|
|
21
23
|
...labelsProp
|
|
22
24
|
};
|
|
23
25
|
const [sort, setSort] = useControlled({
|
package/dist/Table/Table.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Table.js","names":[],"sources":["../../src/Table/Table.tsx"],"sourcesContent":["import { ArrowDownIcon, ArrowUpIcon, SortIcon } from '@slurp-ui/icons';\nimport { cx } from '@slurp-ui/utils';\nimport { useId, useMemo, type ElementType, type Key, type ReactNode } from 'react';\n\nimport { useTheme } from '../internal/context';\nimport { useAnimationRoot } from '../internal/animation';\nimport { useCss, useParts, useThemeProps } from '../internal/styled';\nimport type { PartsProps, PolymorphicProps } from '../lib/polymorphic';\nimport { useControlled } from '../utils/useControlled';\n\ntype Row = object;\n\nexport interface TableColumn<R extends Row = Row> {\n /** Identifies the column; also the field read when there is no `cell` or `sortValue`. */\n key: string;\n header: ReactNode;\n /** Content of a cell. Default the field `key` of the row. */\n cell?: (row: R, index: number) => ReactNode;\n /** `end` for numbers and prices (tabular figures). Default `start`. */\n align?: 'start' | 'center' | 'end';\n sortable?: boolean;\n /** Value compared when sorting. Default the field `key` of the row. */\n sortValue?: (row: R) => string | number | null | undefined;\n /** The cells of this column name their row (`th scope=\"row\"`): usually the first column. */\n rowHeader?: boolean;\n /** CSS width of the column. */\n width?: string | number;\n}\n\nexport interface TableSort {\n key: string;\n direction: 'ascending' | 'descending';\n}\n\nexport interface TableLabels {\n /** Shown in place of the rows when there are none. */\n empty: string;\n}\n\nexport const TABLE_LABELS: TableLabels = { empty: 'Nessun elemento' };\n\nexport interface TableOwnProps<R extends Row = Row> extends PartsProps<'table' | 'caption'> {\n /** Title of the table: names it and its scroll region. Hide it with `hideCaption` when a heading already says it. */\n caption: ReactNode;\n hideCaption?: boolean;\n columns: TableColumn<R>[];\n rows: R[];\n /** Stable key of a row. Default its index. */\n rowKey?: (row: R, index: number) => Key;\n sort?: TableSort | null;\n defaultSort?: TableSort | null;\n onSortChange?: (sort: TableSort) => void;\n /** The rows are already sorted (by a server): the table only reports `onSortChange`. */\n manualSort?: boolean;\n labels?: Partial<TableLabels>;\n}\n\nexport type TableProps<R extends Row = Row, E extends ElementType = 'div'> = PolymorphicProps<\n E,\n TableOwnProps<R>\n>;\n\nconst field = (row: Row, key: string): unknown => (row as Record<string, unknown>)[key];\n\n/**\n * A plain data table, without a frame: hairlines between rows, numbers aligned at the end. Sortable headers are\n * buttons and the sorted column carries `aria-sort`. Wide tables scroll inside a named, focusable region.\n */\nexport function Table<R extends Row = Row, E extends ElementType = 'div'>(props: TableProps<R, E>) {\n const {\n as,\n css,\n className,\n caption,\n hideCaption = false,\n columns,\n rows,\n rowKey,\n sort: sortProp,\n defaultSort = null,\n onSortChange,\n manualSort = false,\n labels: labelsProp,\n parts,\n partProps,\n classNames,\n ...rest\n } = useThemeProps('Table', props as unknown as TableProps);\n const labels = { ...TABLE_LABELS, ...labelsProp };\n const [sort, setSort] = useControlled<TableSort | null>({\n value: sortProp,\n defaultValue: defaultSort,\n onChange: onSortChange as ((s: TableSort | null) => void) | undefined,\n });\n const { locale } = useTheme();\n const captionId = useId();\n const Root = (as ?? 'div') as ElementType;\n const styled = useCss('Table', 'root', css);\n const { part, style } = useParts('Table', { parts, partProps, classNames });\n const root = useAnimationRoot(rest);\n\n const sorted = useMemo(() => {\n const column = sort && columns.find((c) => c.key === sort.key);\n if (manualSort || !sort || !column) return rows;\n const collator = new Intl.Collator(locale, { numeric: true, sensitivity: 'base' });\n const read = column.sortValue ?? ((r: Row) => field(r, column.key) as string | number);\n const sign = sort.direction === 'ascending' ? 1 : -1;\n // Empty values last whatever the direction; a stable sort keeps ties in their order.\n return [...rows].sort((a, b) => {\n const x = read(a);\n const y = read(b);\n if (x == null || x === '') return y == null || y === '' ? 0 : 1;\n if (y == null || y === '') return -1;\n const d =\n typeof x === 'number' && typeof y === 'number'\n ? x - y\n : collator.compare(String(x), String(y));\n return d * sign;\n });\n }, [rows, columns, sort, manualSort, locale]);\n\n const toggle = (key: string) =>\n setSort({\n key,\n direction: sort?.key === key && sort.direction === 'ascending' ? 'descending' : 'ascending',\n });\n\n return (\n <>\n {styled.style}\n {style}\n <Root\n className={cx('slurp-table', styled.className, className)}\n role=\"region\"\n aria-labelledby={captionId}\n tabIndex={0}\n {...root}\n >\n {part('table', 'table', {\n className: 'slurp-table-table',\n children: (\n <>\n {part('caption', 'caption', {\n id: captionId,\n className: cx('slurp-table-caption', hideCaption && 'slurp-visually-hidden'),\n children: caption,\n })}\n {columns.some((c) => c.width != null) && (\n <colgroup>\n {columns.map((c) => (\n <col key={c.key} style={c.width != null ? { width: c.width } : undefined} />\n ))}\n </colgroup>\n )}\n <thead>\n <tr>\n {columns.map((c) => {\n const on = sort?.key === c.key ? sort.direction : undefined;\n return (\n <th\n key={c.key}\n scope=\"col\"\n className=\"slurp-table-head\"\n data-align={c.align ?? 'start'}\n aria-sort={on}\n >\n {c.sortable ? (\n <button\n type=\"button\"\n className=\"slurp-table-sort\"\n data-sorted={on ? '' : undefined}\n onClick={() => toggle(c.key)}\n >\n <span>{c.header}</span>\n <span className=\"slurp-table-sort-icon\" aria-hidden=\"true\">\n {on === 'ascending' ? (\n <ArrowUpIcon size={16} />\n ) : on === 'descending' ? (\n <ArrowDownIcon size={16} />\n ) : (\n <SortIcon size={16} />\n )}\n </span>\n </button>\n ) : (\n c.header\n )}\n </th>\n );\n })}\n </tr>\n </thead>\n <tbody>\n {sorted.length === 0 ? (\n <tr>\n <td className=\"slurp-table-empty\" colSpan={columns.length}>\n {labels.empty}\n </td>\n </tr>\n ) : (\n sorted.map((row, i) => (\n <tr key={rowKey ? rowKey(row as R, i) : i} className=\"slurp-table-row\">\n {columns.map((c) => {\n const Cell = c.rowHeader ? 'th' : 'td';\n const content = c.cell\n ? c.cell(row as R, i)\n : (field(row, c.key) as ReactNode);\n return (\n <Cell\n key={c.key}\n scope={c.rowHeader ? 'row' : undefined}\n className=\"slurp-table-cell\"\n data-align={c.align ?? 'start'}\n >\n {content}\n </Cell>\n );\n })}\n </tr>\n ))\n )}\n </tbody>\n </>\n ),\n })}\n </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OAAa,CAAA,GACtB,oBAAC,QAAD;SAAM,WAAU;SAAwB,eAAY;SACjD,UAAA,OAAO,cACN,oBAAC,aAAD,EAAa,MAAM,GAAK,CAAA,IACtB,OAAO,eACT,oBAAC,eAAD,EAAe,MAAM,GAAK,CAAA,IAE1B,oBAAC,UAAD,EAAU,MAAM,GAAK,CAAA;QAEnB,CAAA,CACA;OAER,CAAA,IAAA,EAAE;MAEF,GA3BG,EAAE,GA2BL;KAER,CAAC,EACC,CAAA,EACC,CAAA;KACP,oBAAC,SAAD,EAAA,UACG,OAAO,WAAW,IACjB,oBAAC,MAAD,EAAA,UACE,oBAAC,MAAD;MAAI,WAAU;MAAoB,SAAS,QAAQ;MAChD,UAAA,OAAO;KACN,CAAA,EACF,CAAA,IAEJ,OAAO,KAAK,KAAK,MACf,oBAAC,MAAD;MAA2C,WAAU;MAClD,UAAA,QAAQ,KAAK,MAAM;OAClB,MAAM,OAAO,EAAE,YAAY,OAAO;OAClC,MAAM,UAAU,EAAE,OACd,EAAE,KAAK,KAAU,CAAC,IACjB,MAAM,KAAK,EAAE,GAAG;OACrB,OACE,oBAAC,MAAD;QAEE,OAAO,EAAE,YAAY,QAAQ,KAAA;QAC7B,WAAU;QACV,cAAY,EAAE,SAAS;QAEtB,UAAA;OACG,GANC,EAAE,GAMH;MAEV,CAAC;KACC,GAjBK,SAAS,OAAO,KAAU,CAAC,IAAI,CAiBpC,CACL,EAEE,CAAA;IACP,EAAA,CAAA;GAEN,CAAC;EACG,CAAA;CACN,EAAA,CAAA;AAEN"}
|
|
1
|
+
{"version":3,"file":"Table.js","names":[],"sources":["../../src/Table/Table.tsx"],"sourcesContent":["import { ArrowDownIcon, ArrowUpIcon, SortIcon } from '@slurp-ui/icons';\nimport { cx } from '@slurp-ui/utils';\nimport { useId, useMemo, type ElementType, type Key, type ReactNode } from 'react';\n\nimport { useLabels } from '../internal/labels';\nimport { useTheme } from '../internal/context';\nimport { useAnimationRoot } from '../internal/animation';\nimport { useCss, useParts, useThemeProps } from '../internal/styled';\nimport type { PartsProps, PolymorphicProps } from '../lib/polymorphic';\nimport { useControlled } from '../utils/useControlled';\n\ntype Row = object;\n\nexport interface TableColumn<R extends Row = Row> {\n /** Identifies the column; also the field read when there is no `cell` or `sortValue`. */\n key: string;\n header: ReactNode;\n /** Content of a cell. Default the field `key` of the row. */\n cell?: (row: R, index: number) => ReactNode;\n /** `end` for numbers and prices (tabular figures). Default `start`. */\n align?: 'start' | 'center' | 'end';\n sortable?: boolean;\n /** Value compared when sorting. Default the field `key` of the row. */\n sortValue?: (row: R) => string | number | null | undefined;\n /** The cells of this column name their row (`th scope=\"row\"`): usually the first column. */\n rowHeader?: boolean;\n /** CSS width of the column. */\n width?: string | number;\n}\n\nexport interface TableSort {\n key: string;\n direction: 'ascending' | 'descending';\n}\n\nexport interface TableLabels {\n /** Shown in place of the rows when there are none. */\n empty: string;\n}\n\nexport const TABLE_LABELS: TableLabels = { empty: 'Nessun elemento' };\n\nexport interface TableOwnProps<R extends Row = Row> extends PartsProps<'table' | 'caption'> {\n /** Title of the table: names it and its scroll region. Hide it with `hideCaption` when a heading already says it. */\n caption: ReactNode;\n hideCaption?: boolean;\n columns: TableColumn<R>[];\n rows: R[];\n /** Stable key of a row. Default its index. */\n rowKey?: (row: R, index: number) => Key;\n sort?: TableSort | null;\n defaultSort?: TableSort | null;\n onSortChange?: (sort: TableSort) => void;\n /** The rows are already sorted (by a server): the table only reports `onSortChange`. */\n manualSort?: boolean;\n labels?: Partial<TableLabels>;\n}\n\nexport type TableProps<R extends Row = Row, E extends ElementType = 'div'> = PolymorphicProps<\n E,\n TableOwnProps<R>\n>;\n\nconst field = (row: Row, key: string): unknown => (row as Record<string, unknown>)[key];\n\n/**\n * A plain data table, without a frame: hairlines between rows, numbers aligned at the end. Sortable headers are\n * buttons and the sorted column carries `aria-sort`. Wide tables scroll inside a named, focusable region.\n */\nexport function Table<R extends Row = Row, E extends ElementType = 'div'>(props: TableProps<R, E>) {\n const {\n as,\n css,\n className,\n caption,\n hideCaption = false,\n columns,\n rows,\n rowKey,\n sort: sortProp,\n defaultSort = null,\n onSortChange,\n manualSort = false,\n labels: labelsProp,\n parts,\n partProps,\n classNames,\n ...rest\n } = useThemeProps('Table', props as unknown as TableProps);\n const labels = { ...TABLE_LABELS, ...useLabels('Table'), ...labelsProp };\n const [sort, setSort] = useControlled<TableSort | null>({\n value: sortProp,\n defaultValue: defaultSort,\n onChange: onSortChange as ((s: TableSort | null) => void) | undefined,\n });\n const { locale } = useTheme();\n const captionId = useId();\n const Root = (as ?? 'div') as ElementType;\n const styled = useCss('Table', 'root', css);\n const { part, style } = useParts('Table', { parts, partProps, classNames });\n const root = useAnimationRoot(rest);\n\n const sorted = useMemo(() => {\n const column = sort && columns.find((c) => c.key === sort.key);\n if (manualSort || !sort || !column) return rows;\n const collator = new Intl.Collator(locale, { numeric: true, sensitivity: 'base' });\n const read = column.sortValue ?? ((r: Row) => field(r, column.key) as string | number);\n const sign = sort.direction === 'ascending' ? 1 : -1;\n // Empty values last whatever the direction; a stable sort keeps ties in their order.\n return [...rows].sort((a, b) => {\n const x = read(a);\n const y = read(b);\n if (x == null || x === '') return y == null || y === '' ? 0 : 1;\n if (y == null || y === '') return -1;\n const d =\n typeof x === 'number' && typeof y === 'number'\n ? x - y\n : collator.compare(String(x), String(y));\n return d * sign;\n });\n }, [rows, columns, sort, manualSort, locale]);\n\n const toggle = (key: string) =>\n setSort({\n key,\n direction: sort?.key === key && sort.direction === 'ascending' ? 'descending' : 'ascending',\n });\n\n return (\n <>\n {styled.style}\n {style}\n <Root\n className={cx('slurp-table', styled.className, className)}\n role=\"region\"\n aria-labelledby={captionId}\n tabIndex={0}\n {...root}\n >\n {part('table', 'table', {\n className: 'slurp-table-table',\n children: (\n <>\n {part('caption', 'caption', {\n id: captionId,\n className: cx('slurp-table-caption', hideCaption && 'slurp-visually-hidden'),\n children: caption,\n })}\n {columns.some((c) => c.width != null) && (\n <colgroup>\n {columns.map((c) => (\n <col key={c.key} style={c.width != null ? { width: c.width } : undefined} />\n ))}\n </colgroup>\n )}\n <thead>\n <tr>\n {columns.map((c) => {\n const on = sort?.key === c.key ? sort.direction : undefined;\n return (\n <th\n key={c.key}\n scope=\"col\"\n className=\"slurp-table-head\"\n data-align={c.align ?? 'start'}\n aria-sort={on}\n >\n {c.sortable ? (\n <button\n type=\"button\"\n className=\"slurp-table-sort\"\n data-sorted={on ? '' : undefined}\n onClick={() => toggle(c.key)}\n >\n <span>{c.header}</span>\n <span className=\"slurp-table-sort-icon\" aria-hidden=\"true\">\n {on === 'ascending' ? (\n <ArrowUpIcon size={16} />\n ) : on === 'descending' ? (\n <ArrowDownIcon size={16} />\n ) : (\n <SortIcon size={16} />\n )}\n </span>\n </button>\n ) : (\n c.header\n )}\n </th>\n );\n })}\n </tr>\n </thead>\n <tbody>\n {sorted.length === 0 ? (\n <tr>\n <td className=\"slurp-table-empty\" colSpan={columns.length}>\n {labels.empty}\n </td>\n </tr>\n ) : (\n sorted.map((row, i) => (\n <tr key={rowKey ? rowKey(row as R, i) : i} className=\"slurp-table-row\">\n {columns.map((c) => {\n const Cell = c.rowHeader ? 'th' : 'td';\n const content = c.cell\n ? c.cell(row as R, i)\n : (field(row, c.key) as ReactNode);\n return (\n <Cell\n key={c.key}\n scope={c.rowHeader ? 'row' : undefined}\n className=\"slurp-table-cell\"\n data-align={c.align ?? 'start'}\n >\n {content}\n </Cell>\n );\n })}\n </tr>\n ))\n )}\n </tbody>\n </>\n ),\n })}\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;AAwCA,MAAa,eAA4B,EAAE,OAAO,kBAAkB;AAuBpE,MAAM,SAAS,KAAU,QAA0B,IAAgC;;;;;AAMnF,SAAgB,MAA0D,OAAyB;CACjG,MAAM,EACJ,IACA,KACA,WACA,SACA,cAAc,OACd,SACA,MACA,QACA,MAAM,UACN,cAAc,MACd,cACA,aAAa,OACb,QAAQ,YACR,OACA,WACA,YACA,GAAG,SACD,cAAc,SAAS,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BL;KAER,CAAC,EACC,CAAA,EACC,CAAA;KACP,oBAAC,SAAD,EAAA,UACG,OAAO,WAAW,IACjB,oBAAC,MAAD,EAAA,UACE,oBAAC,MAAD;MAAI,WAAU;MAAoB,SAAS,QAAQ;MAChD,UAAA,OAAO;KACN,CAAA,EACF,CAAA,IAEJ,OAAO,KAAK,KAAK,MACf,oBAAC,MAAD;MAA2C,WAAU;MAClD,UAAA,QAAQ,KAAK,MAAM;OAClB,MAAM,OAAO,EAAE,YAAY,OAAO;OAClC,MAAM,UAAU,EAAE,OACd,EAAE,KAAK,KAAU,CAAC,IACjB,MAAM,KAAK,EAAE,GAAG;OACrB,OACE,oBAAC,MAAD;QAEE,OAAO,EAAE,YAAY,QAAQ,KAAA;QAC7B,WAAU;QACV,cAAY,EAAE,SAAS;QAEtB,UAAA;OACG,GANC,EAAE,GAMH;MAEV,CAAC;KACC,GAjBK,SAAS,OAAO,KAAU,CAAC,IAAI,CAiBpC,CACL,EAEE,CAAA;IACP,EAAA,CAAA;GAEN,CAAC;EACG,CAAA;CACN,EAAA,CAAA;AAEN"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
import { PolymorphicProps } from "../lib/polymorphic.js";
|
|
3
|
+
import { ElementType, ReactNode } from "react";
|
|
4
|
+
export interface TagOwnProps {
|
|
5
|
+
/** Default `accent`. Status tones add a dot in their colour; the word says the state, never the colour alone. */
|
|
6
|
+
tone?: 'accent' | 'neutral' | 'success' | 'warning' | 'danger';
|
|
7
|
+
/** A decorative icon before the text. */
|
|
8
|
+
icon?: ReactNode;
|
|
9
|
+
children?: ReactNode;
|
|
10
|
+
}
|
|
11
|
+
export type TagProps<E extends ElementType = 'span'> = PolymorphicProps<E, TagOwnProps>;
|
|
12
|
+
/** A static label for a state or a category ("Nuovo", "Bozza", "Verificato"). Not interactive: use Chip to toggle. */
|
|
13
|
+
export declare function Tag<E extends ElementType = 'span'>(props: TagProps<E>): import("react").JSX.Element;
|
|
14
|
+
//# sourceMappingURL=Tag.d.ts.map
|
package/dist/Tag/Tag.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cx } from "../utils/src/index.js";
|
|
3
|
+
import { useAnimationRoot } from "../internal/animation.js";
|
|
4
|
+
import { useCss, useThemeProps } from "../internal/styled.js";
|
|
5
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
// src/Tag/Tag.tsx
|
|
7
|
+
/** A static label for a state or a category ("Nuovo", "Bozza", "Verificato"). Not interactive: use Chip to toggle. */
|
|
8
|
+
function Tag(props) {
|
|
9
|
+
const { as, css, className, tone = "accent", icon, children, ...rest } = useThemeProps("Tag", props);
|
|
10
|
+
const Root = as ?? "span";
|
|
11
|
+
const styled = useCss("Tag", "root", css);
|
|
12
|
+
const root = useAnimationRoot(rest);
|
|
13
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [styled.style, /* @__PURE__ */ jsxs(Root, {
|
|
14
|
+
className: cx("slurp-tag", styled.className, className),
|
|
15
|
+
"data-tone": tone,
|
|
16
|
+
...root,
|
|
17
|
+
children: [icon != null && /* @__PURE__ */ jsx("span", {
|
|
18
|
+
className: "slurp-tag-icon",
|
|
19
|
+
"aria-hidden": "true",
|
|
20
|
+
children: icon
|
|
21
|
+
}), children]
|
|
22
|
+
})] });
|
|
23
|
+
}
|
|
24
|
+
export { Tag };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=Tag.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tag.js","names":[],"sources":["../../src/Tag/Tag.tsx"],"sourcesContent":["import { cx } from '@slurp-ui/utils';\nimport type { ElementType, ReactNode } from 'react';\n\nimport { useAnimationRoot } from '../internal/animation';\nimport { useCss, useThemeProps } from '../internal/styled';\nimport type { PolymorphicProps } from '../lib/polymorphic';\n\nexport interface TagOwnProps {\n /** Default `accent`. Status tones add a dot in their colour; the word says the state, never the colour alone. */\n tone?: 'accent' | 'neutral' | 'success' | 'warning' | 'danger';\n /** A decorative icon before the text. */\n icon?: ReactNode;\n children?: ReactNode;\n}\n\nexport type TagProps<E extends ElementType = 'span'> = PolymorphicProps<E, TagOwnProps>;\n\n/** A static label for a state or a category (\"Nuovo\", \"Bozza\", \"Verificato\"). Not interactive: use Chip to toggle. */\nexport function Tag<E extends ElementType = 'span'>(props: TagProps<E>) {\n const {\n as,\n css,\n className,\n tone = 'accent',\n icon,\n children,\n ...rest\n } = useThemeProps('Tag', props as TagProps);\n const Root = (as ?? 'span') as ElementType;\n const styled = useCss('Tag', 'root', css);\n const root = useAnimationRoot(rest);\n return (\n <>\n {styled.style}\n <Root className={cx('slurp-tag', styled.className, className)} data-tone={tone} {...root}>\n {icon != null && (\n <span className=\"slurp-tag-icon\" aria-hidden=\"true\">\n {icon}\n </span>\n )}\n {children}\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;;AAkBA,SAAgB,IAAoC,OAAoB;CACtE,MAAM,EACJ,IACA,KACA,WACA,OAAO,UACP,MACA,UACA,GAAG,SACD,cAAc,OAAO,KAAiB;CAC1C,MAAM,OAAQ,MAAM;CACpB,MAAM,SAAS,OAAO,OAAO,QAAQ,GAAG;CACxC,MAAM,OAAO,iBAAiB,IAAI;CAClC,OACE,qBAAA,UAAA,EAAA,UAAA,CACG,OAAO,OACR,qBAAC,MAAD;EAAM,WAAW,GAAG,aAAa,OAAO,WAAW,SAAS;EAAG,aAAW;EAAM,GAAI;EAApF,UAAA,CACG,QAAQ,QACP,oBAAC,QAAD;GAAM,WAAU;GAAiB,eAAY;GAC1C,UAAA;EACG,CAAA,GAEP,QACG;CACN,CAAA,CAAA,EAAA,CAAA;AAEN"}
|
package/dist/Toast/Toast.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { useLabels } from "../internal/labels.js";
|
|
2
3
|
import { cx } from "../utils/src/index.js";
|
|
3
4
|
import { Button } from "../Button/Button.js";
|
|
4
5
|
import { Bubble } from "../Bubble/Bubble.js";
|
|
5
|
-
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
6
|
+
import { createContext, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
6
7
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
8
|
import { CloseIcon, ErrorIcon, InfoIcon, SuccessIcon, WarningIcon } from "@slurp-ui/icons";
|
|
8
9
|
// src/Toast/Toast.tsx
|
|
10
|
+
/** Longest way out (ms): the removal never waits longer, even when no transition runs. */
|
|
11
|
+
const LEAVE_MS = 320;
|
|
9
12
|
const TOAST_LABELS = {
|
|
10
13
|
region: "Notifiche",
|
|
11
14
|
dismiss: "Chiudi notifica"
|
|
@@ -24,11 +27,16 @@ const ICONS = {
|
|
|
24
27
|
function ToastProvider({ children, labels: labelsProp, limit = 3 }) {
|
|
25
28
|
const labels = {
|
|
26
29
|
...TOAST_LABELS,
|
|
30
|
+
...useLabels("Toast"),
|
|
27
31
|
...labelsProp
|
|
28
32
|
};
|
|
29
33
|
const [items, setItems] = useState([]);
|
|
30
34
|
const next = useRef(1);
|
|
31
|
-
const
|
|
35
|
+
const remove = useCallback((id) => setItems((all) => all.filter((t) => t.id !== id)), []);
|
|
36
|
+
const dismiss = useCallback((id) => setItems((all) => all.map((t) => t.id === id ? {
|
|
37
|
+
...t,
|
|
38
|
+
leaving: true
|
|
39
|
+
} : t)), []);
|
|
32
40
|
const toast = useCallback((options) => {
|
|
33
41
|
const id = next.current++;
|
|
34
42
|
setItems((all) => [...all, {
|
|
@@ -53,33 +61,49 @@ function ToastProvider({ children, labels: labelsProp, limit = 3 }) {
|
|
|
53
61
|
children: items.map((t) => /* @__PURE__ */ jsx(ToastItem, {
|
|
54
62
|
entry: t,
|
|
55
63
|
onDismiss: () => dismiss(t.id),
|
|
64
|
+
onLeft: () => remove(t.id),
|
|
56
65
|
dismissLabel: labels.dismiss
|
|
57
66
|
}, t.id))
|
|
58
67
|
})
|
|
59
68
|
})]
|
|
60
69
|
});
|
|
61
70
|
}
|
|
62
|
-
function ToastItem({ entry, onDismiss, dismissLabel }) {
|
|
63
|
-
const { title, description, tone = "neutral", action, duration = 5e3 } = entry;
|
|
64
|
-
const
|
|
71
|
+
function ToastItem({ entry, onDismiss, onLeft, dismissLabel }) {
|
|
72
|
+
const { title, description, tone = "neutral", action, duration = 5e3, leaving } = entry;
|
|
73
|
+
const item = useRef(null);
|
|
65
74
|
const left = useRef(duration);
|
|
66
75
|
const latest = useRef(onDismiss);
|
|
76
|
+
const gone = useRef(onLeft);
|
|
67
77
|
useEffect(() => {
|
|
68
78
|
latest.current = onDismiss;
|
|
79
|
+
gone.current = onLeft;
|
|
69
80
|
});
|
|
81
|
+
useLayoutEffect(() => {
|
|
82
|
+
const el = item.current;
|
|
83
|
+
if (!leaving || !el) return;
|
|
84
|
+
el.style.height = `${el.offsetHeight}px`;
|
|
85
|
+
el.offsetHeight;
|
|
86
|
+
el.dataset.leaving = "";
|
|
87
|
+
el.style.removeProperty("height");
|
|
88
|
+
const t = setTimeout(() => gone.current(), LEAVE_MS);
|
|
89
|
+
return () => clearTimeout(t);
|
|
90
|
+
}, [leaving]);
|
|
91
|
+
const [paused, setPaused] = useState(false);
|
|
70
92
|
useEffect(() => {
|
|
71
|
-
if (paused || !Number.isFinite(left.current)) return;
|
|
93
|
+
if (leaving || paused || !Number.isFinite(left.current)) return;
|
|
72
94
|
const started = Date.now();
|
|
73
95
|
const t = setTimeout(() => latest.current(), left.current);
|
|
74
96
|
return () => {
|
|
75
97
|
clearTimeout(t);
|
|
76
98
|
left.current -= Date.now() - started;
|
|
77
99
|
};
|
|
78
|
-
}, [paused]);
|
|
100
|
+
}, [paused, leaving]);
|
|
79
101
|
const Icon = ICONS[tone];
|
|
80
102
|
return /* @__PURE__ */ jsxs("li", {
|
|
103
|
+
ref: item,
|
|
81
104
|
className: "slurp-toast",
|
|
82
105
|
"data-tone": tone,
|
|
106
|
+
inert: leaving || void 0,
|
|
83
107
|
onPointerEnter: () => setPaused(true),
|
|
84
108
|
onPointerLeave: () => setPaused(false),
|
|
85
109
|
onFocus: () => setPaused(true),
|
package/dist/Toast/Toast.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Toast.js","names":[],"sources":["../../src/Toast/Toast.tsx"],"sourcesContent":["import { CloseIcon, ErrorIcon, InfoIcon, SuccessIcon, WarningIcon } from '@slurp-ui/icons';\nimport { cx } from '@slurp-ui/utils';\nimport {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n type ReactNode,\n} from 'react';\n\nimport { Bubble } from '../Bubble/Bubble';\nimport { Button } from '../Button/Button';\nimport type { StatusTone } from '../Notice/Notice';\n\nexport interface ToastOptions {\n title: ReactNode;\n description?: ReactNode;\n /** Default `neutral`: icon + text, never colour alone. */\n tone?: StatusTone;\n /** One action (\"Annulla\"). */\n action?: { label: string; onClick: () => void };\n /** ms before it goes away; paused while hovered or focused. `Infinity` keeps it. Default 5000. */\n duration?: number;\n}\n\ninterface ToastEntry extends ToastOptions {\n id: number;\n}\n\nexport interface ToastLabels {\n /** Name of the region that holds the toasts. */\n region: string;\n /** Name of each close button. */\n dismiss: string;\n}\n\nexport const TOAST_LABELS: ToastLabels = { region: 'Notifiche', dismiss: 'Chiudi notifica' };\n\ninterface ToastApi {\n /** Shows a toast; returns its id. */\n toast: (options: ToastOptions) => number;\n dismiss: (id: number) => void;\n}\n\nconst ToastContext = createContext<ToastApi | null>(null);\n\nexport interface ToastProviderProps {\n children?: ReactNode;\n labels?: Partial<ToastLabels>;\n /** At most this many on screen; the oldest go first. Default 3. */\n limit?: number;\n}\n\nconst ICONS = { neutral: InfoIcon, success: SuccessIcon, warning: WarningIcon, danger: ErrorIcon };\n\n/**\n * Short confirmations at the bottom of the screen, above the Dock (`--slurp-toast-offset`). The list is a polite live\n * region, present from the start so new toasts are announced.\n */\nexport function ToastProvider({ children, labels: labelsProp, limit = 3 }: ToastProviderProps) {\n const labels = { ...TOAST_LABELS, ...labelsProp };\n const [items, setItems] = useState<ToastEntry[]>([]);\n const next = useRef(1);\n const dismiss = useCallback(\n (id: number) => setItems((all) => all.
|
|
1
|
+
{"version":3,"file":"Toast.js","names":[],"sources":["../../src/Toast/Toast.tsx"],"sourcesContent":["import { CloseIcon, ErrorIcon, InfoIcon, SuccessIcon, WarningIcon } from '@slurp-ui/icons';\nimport { cx } from '@slurp-ui/utils';\nimport {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n type ReactNode,\n} from 'react';\n\nimport { useLabels } from '../internal/labels';\nimport { Bubble } from '../Bubble/Bubble';\nimport { Button } from '../Button/Button';\nimport type { StatusTone } from '../Notice/Notice';\n\nexport interface ToastOptions {\n title: ReactNode;\n description?: ReactNode;\n /** Default `neutral`: icon + text, never colour alone. */\n tone?: StatusTone;\n /** One action (\"Annulla\"). */\n action?: { label: string; onClick: () => void };\n /** ms before it goes away; paused while hovered or focused. `Infinity` keeps it. Default 5000. */\n duration?: number;\n}\n\ninterface ToastEntry extends ToastOptions {\n id: number;\n /** Dismissed: it plays its way out, then leaves the list. */\n leaving?: boolean;\n}\n\n/** Longest way out (ms): the removal never waits longer, even when no transition runs. */\nconst LEAVE_MS = 320;\n\nexport interface ToastLabels {\n /** Name of the region that holds the toasts. */\n region: string;\n /** Name of each close button. */\n dismiss: string;\n}\n\nexport const TOAST_LABELS: ToastLabels = { region: 'Notifiche', dismiss: 'Chiudi notifica' };\n\ninterface ToastApi {\n /** Shows a toast; returns its id. */\n toast: (options: ToastOptions) => number;\n dismiss: (id: number) => void;\n}\n\nconst ToastContext = createContext<ToastApi | null>(null);\n\nexport interface ToastProviderProps {\n children?: ReactNode;\n labels?: Partial<ToastLabels>;\n /** At most this many on screen; the oldest go first. Default 3. */\n limit?: number;\n}\n\nconst ICONS = { neutral: InfoIcon, success: SuccessIcon, warning: WarningIcon, danger: ErrorIcon };\n\n/**\n * Short confirmations at the bottom of the screen, above the Dock (`--slurp-toast-offset`). The list is a polite live\n * region, present from the start so new toasts are announced.\n */\nexport function ToastProvider({ children, labels: labelsProp, limit = 3 }: ToastProviderProps) {\n const labels = { ...TOAST_LABELS, ...useLabels('Toast'), ...labelsProp };\n const [items, setItems] = useState<ToastEntry[]>([]);\n const next = useRef(1);\n const remove = useCallback((id: number) => setItems((all) => all.filter((t) => t.id !== id)), []);\n // Dismissing marks the toast as leaving; it removes itself once its exit has played.\n const dismiss = useCallback(\n (id: number) => setItems((all) => all.map((t) => (t.id === id ? { ...t, leaving: true } : t))),\n [],\n );\n const toast = useCallback(\n (options: ToastOptions) => {\n const id = next.current++;\n setItems((all) => [...all, { ...options, id }].slice(-limit));\n return id;\n },\n [limit],\n );\n const api = useMemo(() => ({ toast, dismiss }), [toast, dismiss]);\n return (\n <ToastContext value={api}>\n {children}\n <section className=\"slurp-toasts\" aria-label={labels.region}>\n <ol aria-live=\"polite\" aria-relevant=\"additions text\" className=\"slurp-toasts-list\">\n {items.map((t) => (\n <ToastItem\n key={t.id}\n entry={t}\n onDismiss={() => dismiss(t.id)}\n onLeft={() => remove(t.id)}\n dismissLabel={labels.dismiss}\n />\n ))}\n </ol>\n </section>\n </ToastContext>\n );\n}\n\nfunction ToastItem({\n entry,\n onDismiss,\n onLeft,\n dismissLabel,\n}: {\n entry: ToastEntry;\n onDismiss: () => void;\n onLeft: () => void;\n dismissLabel: string;\n}) {\n const { title, description, tone = 'neutral', action, duration = 5000, leaving } = entry;\n const item = useRef<HTMLLIElement>(null);\n const left = useRef(duration);\n const latest = useRef(onDismiss);\n const gone = useRef(onLeft);\n useEffect(() => {\n latest.current = onDismiss;\n gone.current = onLeft;\n });\n\n // The way out: fix the height, then let CSS fade it and close the gap (data-leaving); remove it afterwards.\n useLayoutEffect(() => {\n const el = item.current;\n if (!leaving || !el) return;\n // From a fixed height, so it can transition to 0 (height: auto cannot).\n el.style.height = `${el.offsetHeight}px`;\n void el.offsetHeight;\n el.dataset.leaving = '';\n el.style.removeProperty('height');\n const t = setTimeout(() => gone.current(), LEAVE_MS);\n return () => clearTimeout(t);\n }, [leaving]);\n\n const [paused, setPaused] = useState(false);\n\n useEffect(() => {\n if (leaving || paused || !Number.isFinite(left.current)) return;\n const started = Date.now();\n const t = setTimeout(() => latest.current(), left.current);\n return () => {\n clearTimeout(t);\n left.current -= Date.now() - started;\n };\n }, [paused, leaving]);\n\n const Icon = ICONS[tone];\n return (\n <li\n ref={item}\n className=\"slurp-toast\"\n data-tone={tone}\n inert={leaving || undefined}\n onPointerEnter={() => setPaused(true)}\n onPointerLeave={() => setPaused(false)}\n onFocus={() => setPaused(true)}\n onBlur={(e) => {\n if (!e.currentTarget.contains(e.relatedTarget)) setPaused(false);\n }}\n >\n <span className=\"slurp-toast-icon\" aria-hidden=\"true\">\n <Icon size={22} />\n </span>\n <div className=\"slurp-toast-text\">\n <p className=\"slurp-toast-title\">{title}</p>\n {description != null && <p className=\"slurp-toast-description\">{description}</p>}\n </div>\n {action && (\n <Button\n appearance=\"plain\"\n size=\"sm\"\n onClick={() => {\n action.onClick();\n onDismiss();\n }}\n >\n {action.label}\n </Button>\n )}\n <Bubble\n label={dismissLabel}\n size=\"sm\"\n className={cx('slurp-toast-dismiss')}\n onClick={onDismiss}\n >\n <CloseIcon size={18} />\n </Bubble>\n </li>\n );\n}\n\n/** `toast(options)` and `dismiss(id)`, from the nearest ToastProvider. */\nexport function useToast(): ToastApi {\n const api = useContext(ToastContext);\n if (!api) throw new Error('Slurp: useToast() needs a <ToastProvider> above it.');\n return api;\n}\n"],"mappings":";;;;;;;;;;AAqCA,MAAM,WAAW;AASjB,MAAa,eAA4B;CAAE,QAAQ;CAAa,SAAS;AAAkB;AAQ3F,MAAM,eAAe,cAA+B,IAAI;AASxD,MAAM,QAAQ;CAAE,SAAS;CAAU,SAAS;CAAa,SAAS;CAAa,QAAQ;AAAU;;;;;AAMjG,SAAgB,cAAc,EAAE,UAAU,QAAQ,Y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AAQ,oBAAC,KAAD;KAAG,WAAU;KAA2B,UAAA;IAAe,CAAA,CAC5E;;GACJ,UACC,oBAAC,QAAD;IACE,YAAW;IACX,MAAK;IACL,eAAe;KACb,OAAO,QAAQ;KACf,UAAU;IACZ;IAEC,UAAA,OAAO;GACF,CAAA;GAEV,oBAAC,QAAD;IACE,OAAO;IACP,MAAK;IACL,WAAW,GAAG,qBAAqB;IACnC,SAAS;IAET,UAAA,oBAAC,WAAD,EAAW,MAAM,GAAK,CAAA;GAChB,CAAA;EACN;;AAER;;AAGA,SAAgB,WAAqB;CACnC,MAAM,MAAM,WAAW,YAAY;CACnC,IAAI,CAAC,KAAK,MAAM,IAAI,MAAM,qDAAqD;CAC/E,OAAO;AACT"}
|
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ import { Appearance, Button, ButtonProps, ButtonTone, ControlSize } from "./Butt
|
|
|
14
14
|
import { Bubble, BubbleProps } from "./Bubble/Bubble.js";
|
|
15
15
|
import "./Bubble/index.js";
|
|
16
16
|
import "./Button/index.js";
|
|
17
|
+
import { CALENDAR_LABELS, Calendar, CalendarLabels, CalendarProps, CalendarValue, DateRange } from "./Calendar/Calendar.js";
|
|
18
|
+
import "./Calendar/index.js";
|
|
17
19
|
import { Card, CardProps } from "./Card/Card.js";
|
|
18
20
|
import "./Card/index.js";
|
|
19
21
|
import { CAROUSEL_LABELS, Carousel, CarouselLabels, CarouselProps } from "./Carousel/Carousel.js";
|
|
@@ -26,49 +28,79 @@ import { Chip, ChipProps } from "./Chip/Chip.js";
|
|
|
26
28
|
import "./Chip/index.js";
|
|
27
29
|
import { CHOICE_LABELS, Choice, ChoiceLabels, ChoiceOption, ChoiceProps } from "./Choice/Choice.js";
|
|
28
30
|
import "./Choice/index.js";
|
|
31
|
+
import { CODE_LABELS, Code, CodeLabels, CodeProps } from "./Code/Code.js";
|
|
32
|
+
import "./Code/index.js";
|
|
33
|
+
import { CONTENTS_LABELS, Contents, ContentsItem, ContentsLabels, ContentsProps } from "./Contents/Contents.js";
|
|
34
|
+
import "./Contents/index.js";
|
|
29
35
|
import { Count, CountProps } from "./Count/Count.js";
|
|
30
36
|
import "./Count/index.js";
|
|
37
|
+
import { DATEFIELD_LABELS, DateField, DateFieldLabels, DateFieldProps } from "./DateField/DateField.js";
|
|
38
|
+
import "./DateField/index.js";
|
|
31
39
|
import { DIALOG_LABELS, Dialog, DialogLabels, DialogProps } from "./Dialog/Dialog.js";
|
|
32
40
|
import "./Dialog/index.js";
|
|
33
41
|
import { DOCK_LABELS, Dock, DockActionProps, DockBackProps, DockCrumbProps, DockCrumbsProps, DockLabels, DockProps, DockSearchProps } from "./Dock/Dock.js";
|
|
34
42
|
import "./Dock/index.js";
|
|
35
43
|
import { Empty, EmptyProps } from "./Empty/Empty.js";
|
|
36
44
|
import "./Empty/index.js";
|
|
45
|
+
import { ERRORSUMMARY_LABELS, ErrorSummary, ErrorSummaryItem, ErrorSummaryLabels, ErrorSummaryProps } from "./ErrorSummary/ErrorSummary.js";
|
|
46
|
+
import "./ErrorSummary/index.js";
|
|
37
47
|
import { Fact, FactProps } from "./Fact/Fact.js";
|
|
38
48
|
import "./Fact/index.js";
|
|
39
49
|
import { Field, FieldProps } from "./Field/Field.js";
|
|
40
50
|
import "./Field/index.js";
|
|
51
|
+
import { FILEDROP_LABELS, FileDrop, FileDropLabels, FileDropProps } from "./FileDrop/FileDrop.js";
|
|
52
|
+
import "./FileDrop/index.js";
|
|
41
53
|
import { FILTERS_LABELS, Filters, FiltersGroupProps, FiltersLabels, FiltersProps } from "./Filters/Filters.js";
|
|
42
54
|
import "./Filters/index.js";
|
|
43
55
|
import { Flow, FlowProps } from "./Flow/Flow.js";
|
|
44
56
|
import "./Flow/index.js";
|
|
45
57
|
import { Fold, FoldProps } from "./Fold/Fold.js";
|
|
46
58
|
import "./Fold/index.js";
|
|
59
|
+
import { Footer, FooterBottom, FooterGroup, FooterGroupProps, FooterLink, FooterLinkProps, FooterProps } from "./Footer/Footer.js";
|
|
60
|
+
import "./Footer/index.js";
|
|
47
61
|
import { Frame, FrameProps } from "./Frame/Frame.js";
|
|
48
62
|
import "./Frame/index.js";
|
|
49
63
|
import { Ground } from "./Ground/Ground.js";
|
|
64
|
+
import { Hairline, HairlineProps } from "./Hairline/Hairline.js";
|
|
65
|
+
import "./Hairline/index.js";
|
|
50
66
|
import { Hint, HintProps } from "./Hint/Hint.js";
|
|
51
67
|
import "./Hint/index.js";
|
|
68
|
+
import { Kbd, KbdProps } from "./Kbd/Kbd.js";
|
|
69
|
+
import "./Kbd/index.js";
|
|
52
70
|
import { Link, LinkProps } from "./Link/Link.js";
|
|
53
71
|
import "./Link/index.js";
|
|
54
72
|
import { List, ListProps, ListRow, ListRowProps } from "./ListRow/ListRow.js";
|
|
55
73
|
import "./ListRow/index.js";
|
|
56
74
|
import { Mark, MarkProps } from "./Mark/Mark.js";
|
|
57
75
|
import "./Mark/index.js";
|
|
76
|
+
import { Media, MediaProps } from "./Media/Media.js";
|
|
77
|
+
import "./Media/index.js";
|
|
58
78
|
import { Menu, MenuItem, MenuItemProps, MenuProps } from "./Menu/Menu.js";
|
|
59
79
|
import "./Menu/index.js";
|
|
60
80
|
import { NOTICE_LABELS, Notice, NoticeLabels, NoticeProps, StatusTone } from "./Notice/Notice.js";
|
|
61
81
|
import "./Notice/index.js";
|
|
82
|
+
import { NUMBERFIELD_LABELS, NumberField, NumberFieldLabels, NumberFieldProps } from "./NumberField/NumberField.js";
|
|
83
|
+
import "./NumberField/index.js";
|
|
84
|
+
import { PAGENAV_LABELS, PageNav, PageNavLabels, PageNavProps, PageNavTarget } from "./PageNav/PageNav.js";
|
|
85
|
+
import "./PageNav/index.js";
|
|
62
86
|
import { PAGES_LABELS, PageItem, Pages, PagesLabels, PagesProps, pageItems } from "./Pages/Pages.js";
|
|
63
87
|
import "./Pages/index.js";
|
|
88
|
+
import { PinField, PinFieldProps } from "./PinField/PinField.js";
|
|
89
|
+
import "./PinField/index.js";
|
|
64
90
|
import { Placeholder, PlaceholderProps } from "./Placeholder/Placeholder.js";
|
|
65
91
|
import "./Placeholder/index.js";
|
|
66
92
|
import { Portal, PortalProps } from "./Portal/Portal.js";
|
|
67
93
|
import "./Portal/index.js";
|
|
68
94
|
import { Progress, ProgressProps } from "./Progress/Progress.js";
|
|
69
95
|
import "./Progress/index.js";
|
|
96
|
+
import { Prose, ProseProps } from "./Prose/Prose.js";
|
|
97
|
+
import "./Prose/index.js";
|
|
98
|
+
import { Quote, QuoteProps } from "./Quote/Quote.js";
|
|
99
|
+
import "./Quote/index.js";
|
|
70
100
|
import { Radio, RadioGroup, RadioGroupProps, RadioProps } from "./Radio/Radio.js";
|
|
71
101
|
import "./Radio/index.js";
|
|
102
|
+
import { Rail, RailGroup, RailGroupProps, RailLink, RailLinkProps, RailProps } from "./Rail/Rail.js";
|
|
103
|
+
import "./Rail/index.js";
|
|
72
104
|
import { Range, RangeProps } from "./Range/Range.js";
|
|
73
105
|
import "./Range/index.js";
|
|
74
106
|
import { RATING_LABELS, Rating, RatingLabels, RatingProps } from "./Rating/Rating.js";
|
|
@@ -79,6 +111,8 @@ import { Score, ScoreProps } from "./Score/Score.js";
|
|
|
79
111
|
import "./Score/index.js";
|
|
80
112
|
import { SEARCH_LABELS, Search, SearchLabels, SearchProps } from "./Search/Search.js";
|
|
81
113
|
import "./Search/index.js";
|
|
114
|
+
import { SECRETFIELD_LABELS, SecretField, SecretFieldLabels, SecretFieldProps } from "./SecretField/SecretField.js";
|
|
115
|
+
import "./SecretField/index.js";
|
|
82
116
|
import { Segmented, SegmentedOption, SegmentedProps } from "./Segmented/Segmented.js";
|
|
83
117
|
import "./Segmented/index.js";
|
|
84
118
|
import { SETTINGS_LABELS, Settings, SettingsLabels, SettingsLanguage, SettingsProps } from "./Settings/Settings.js";
|
|
@@ -87,16 +121,21 @@ import { Sheet, SheetProps } from "./Sheet/Sheet.js";
|
|
|
87
121
|
import "./Sheet/index.js";
|
|
88
122
|
import { Shelf, ShelfProps } from "./Shelf/Shelf.js";
|
|
89
123
|
import "./Shelf/index.js";
|
|
90
|
-
import {
|
|
91
|
-
import
|
|
124
|
+
import { SKIPLINK_LABELS, SkipLink, SkipLinkLabels, SkipLinkProps } from "./SkipLink/SkipLink.js";
|
|
125
|
+
import "./SkipLink/index.js";
|
|
92
126
|
import { STEPS_LABELS, StepItem, Steps, StepsLabels, StepsProps } from "./Steps/Steps.js";
|
|
93
127
|
import { SUGGEST_LABELS, Suggest, SuggestLabels, SuggestOption, SuggestProps } from "./Suggest/Suggest.js";
|
|
94
128
|
import { TABLE_LABELS, Table, TableColumn, TableLabels, TableProps, TableSort } from "./Table/Table.js";
|
|
129
|
+
import { TOAST_LABELS, ToastLabels, ToastOptions, ToastProvider, ToastProviderProps, useToast } from "./Toast/Toast.js";
|
|
130
|
+
import { LabelsInput, SlurpLabels, labelsEn, labelsIt } from "./lib/labels.js";
|
|
131
|
+
import { Stage, StageProps } from "./Stage/Stage.js";
|
|
132
|
+
import { Tile, TileProps } from "./Tile/Tile.js";
|
|
95
133
|
import { Surface, SurfaceProps } from "./Surface/Surface.js";
|
|
96
134
|
import { Swatch, SwatchGroup, SwatchGroupProps, SwatchOption, SwatchProps } from "./Swatch/Swatch.js";
|
|
97
135
|
import { Switch, SwitchProps } from "./Switch/Switch.js";
|
|
98
136
|
import { TabItem, Tabs, TabsProps } from "./Tabs/Tabs.js";
|
|
99
137
|
import { Text, TextProps, TextTone } from "./Text/Text.js";
|
|
138
|
+
import { Tag, TagProps } from "./Tag/Tag.js";
|
|
100
139
|
import { AccentInput, ColorSchemeMode, ComponentsConfig, DEFAULT_STORAGE_KEY, MotionOptions, ResolvedColorScheme, Theme, ThemeOptions, TokenOverrides, createTheme } from "./lib/theme.js";
|
|
101
140
|
import { SlurpProvider, SlurpProviderProps } from "./SlurpProvider/SlurpProvider.js";
|
|
102
141
|
import { ColorSchemeScript, ColorSchemeScriptProps } from "./SlurpProvider/ColorSchemeScript.js";
|
|
@@ -110,9 +149,9 @@ import "./Swatch/index.js";
|
|
|
110
149
|
import "./Switch/index.js";
|
|
111
150
|
import "./Table/index.js";
|
|
112
151
|
import "./Tabs/index.js";
|
|
152
|
+
import "./Tag/index.js";
|
|
113
153
|
import "./Text/index.js";
|
|
114
154
|
import "./Tile/index.js";
|
|
115
|
-
import { TOAST_LABELS, ToastLabels, ToastOptions, ToastProvider, ToastProviderProps, useToast } from "./Toast/Toast.js";
|
|
116
155
|
import "./Toast/index.js";
|
|
117
156
|
import { VisuallyHidden, VisuallyHiddenProps } from "./VisuallyHidden/VisuallyHidden.js";
|
|
118
157
|
import "./VisuallyHidden/index.js";
|
|
@@ -129,5 +168,7 @@ import { useForkRef } from "./utils/useForkRef.js";
|
|
|
129
168
|
import { COMPACT_QUERY, useMediaQuery } from "./utils/useMediaQuery.js";
|
|
130
169
|
import { RovingFocusOptions, useRovingFocus } from "./utils/useRovingFocus.js";
|
|
131
170
|
import { FindInPage, focusHit, useFindInPage } from "./utils/useFindInPage.js";
|
|
171
|
+
import { useClipboard } from "./utils/useClipboard.js";
|
|
172
|
+
import { useScrollSpy } from "./utils/useScrollSpy.js";
|
|
132
173
|
import "./utils/index.js";
|
|
133
|
-
export { type AccentInput, AccentScope, type AccentScopeProps, AnimationGroup, type AnimationGroupProps, type AnimationProps, type Appearance, Avatar, type AvatarProps, type BaseProps, Bento, type BentoItem, type BentoProps, type BentoSpan, Bloom, type BloomPlacement, type BloomProps, Bubble, type BubbleProps, Button, type ButtonProps, type ButtonTone, CAROUSEL_LABELS, CHOICE_LABELS, COMPACT_QUERY, CONTRAST_MIN, Card, type CardProps, Carousel, type CarouselLabels, type CarouselProps, Cell, type CellProps, Checkbox, type CheckboxProps, Chip, type ChipProps, Choice, type ChoiceLabels, type ChoiceOption, type ChoiceProps, type ColorSchemeMode, ColorSchemeScript, type ColorSchemeScriptProps, type ColorSchemeState, type ColorValue, type ComponentsConfig, type ContentRef, type ControlSize, type ControlledOptions, Count, type CountProps, type CrumbEnd, DEFAULT_STORAGE_KEY, DIALOG_LABELS, DOCK_LABELS, Dialog, type DialogLabels, type DialogProps, type DismissOptions, Dock, type DockActionProps, type DockBackProps, type DockCrumbProps, type DockCrumbsProps, type DockLabels, type DockProps, type DockSearchProps, Empty, type EmptyProps, FILTERS_LABELS, FOCUSABLE, Fact, type FactProps, Field, type FieldProps, Filters, type FiltersGroupProps, type FiltersLabels, type FiltersProps, type FindInPage, Flow, type FlowProps, Fold, type FoldProps, Frame, type FrameProps, Ground, Hint, type HintProps, Link, type LinkProps, List, type ListProps, ListRow, type ListRowProps, Mark, type MarkProps, type MaybeResponsive, Menu, MenuItem, type MenuItemProps, type MenuProps, type MotionOptions, type MoveFocusOptions, NOTICE_LABELS, Notice, type NoticeLabels, type NoticeProps, PAGES_LABELS, type PageItem, Pages, type PagesLabels, type PagesProps, Placeholder, type PlaceholderProps, type PolymorphicProps, Portal, type PortalProps, Progress, type ProgressProps, RATING_LABELS, Radio, RadioGroup, type RadioGroupProps, type RadioProps, type RadiusValue, Range, type RangeProps, Rating, type RatingLabels, type RatingProps, type ResolvedColorScheme, type Responsive, ResultRow, type ResultRowProps, type RovingFocusOptions, SEARCH_LABELS, SETTINGS_LABELS, STEPS_LABELS, SUGGEST_LABELS, Score, type ScoreProps, Search, type SearchLabels, type SearchProps, Segmented, type SegmentedOption, type SegmentedProps, Settings, type SettingsLabels, type SettingsLanguage, type SettingsProps, Sheet, type SheetProps, Shelf, type ShelfProps, type SlurpControls, type SlurpCss, type SlurpEnterOptions, type SlurpNavigate, type SlurpNavigateOptions, SlurpProvider, type SlurpProviderProps, type SpaceValue, Stage, type StageProps, type StatusTone, type StepItem, Steps, type StepsLabels, type StepsProps, Suggest, type SuggestLabels, type SuggestOption, type SuggestProps, Surface, type SurfaceProps, Swatch, SwatchGroup, type SwatchGroupProps, type SwatchOption, type SwatchProps, Switch, type SwitchProps, TABLE_LABELS, TOAST_LABELS, type TabItem, Table, type TableColumn, type TableLabels, type TableProps, type TableSort, Tabs, type TabsProps, Text, type TextProps, type TextTone, type Theme, type ThemeOptions, Tile, type TileProps, type ToastLabels, type ToastOptions, ToastProvider, type ToastProviderProps, type TokenOverrides, VisuallyHidden, type VisuallyHiddenProps, alpha, bentoLayout, contrast, createTheme, crumbPath, focusFirst, focusHit, matchRanges, matchesAll, meetsContrast, moveFocus, normalizeText, onColor, pageItems, useAnimationTarget, useColorScheme, useControlled, useDismiss, useFindInPage, useForkRef, useMediaQuery, useRovingFocus, useSlurp, useSlurpEnter, useSlurpNavigate, useTheme, useToast, vivid };
|
|
174
|
+
export { type AccentInput, AccentScope, type AccentScopeProps, AnimationGroup, type AnimationGroupProps, type AnimationProps, type Appearance, Avatar, type AvatarProps, type BaseProps, Bento, type BentoItem, type BentoProps, type BentoSpan, Bloom, type BloomPlacement, type BloomProps, Bubble, type BubbleProps, Button, type ButtonProps, type ButtonTone, CALENDAR_LABELS, CAROUSEL_LABELS, CHOICE_LABELS, CODE_LABELS, COMPACT_QUERY, CONTENTS_LABELS, CONTRAST_MIN, Calendar, type CalendarLabels, type CalendarProps, type CalendarValue, Card, type CardProps, Carousel, type CarouselLabels, type CarouselProps, Cell, type CellProps, Checkbox, type CheckboxProps, Chip, type ChipProps, Choice, type ChoiceLabels, type ChoiceOption, type ChoiceProps, Code, type CodeLabels, type CodeProps, type ColorSchemeMode, ColorSchemeScript, type ColorSchemeScriptProps, type ColorSchemeState, type ColorValue, type ComponentsConfig, type ContentRef, Contents, type ContentsItem, type ContentsLabels, type ContentsProps, type ControlSize, type ControlledOptions, Count, type CountProps, type CrumbEnd, DATEFIELD_LABELS, DEFAULT_STORAGE_KEY, DIALOG_LABELS, DOCK_LABELS, DateField, type DateFieldLabels, type DateFieldProps, type DateRange, Dialog, type DialogLabels, type DialogProps, type DismissOptions, Dock, type DockActionProps, type DockBackProps, type DockCrumbProps, type DockCrumbsProps, type DockLabels, type DockProps, type DockSearchProps, ERRORSUMMARY_LABELS, Empty, type EmptyProps, ErrorSummary, type ErrorSummaryItem, type ErrorSummaryLabels, type ErrorSummaryProps, FILEDROP_LABELS, FILTERS_LABELS, FOCUSABLE, Fact, type FactProps, Field, type FieldProps, FileDrop, type FileDropLabels, type FileDropProps, Filters, type FiltersGroupProps, type FiltersLabels, type FiltersProps, type FindInPage, Flow, type FlowProps, Fold, type FoldProps, Footer, FooterBottom, FooterGroup, type FooterGroupProps, FooterLink, type FooterLinkProps, type FooterProps, Frame, type FrameProps, Ground, Hairline, type HairlineProps, Hint, type HintProps, Kbd, type KbdProps, type LabelsInput, Link, type LinkProps, List, type ListProps, ListRow, type ListRowProps, Mark, type MarkProps, type MaybeResponsive, Media, type MediaProps, Menu, MenuItem, type MenuItemProps, type MenuProps, type MotionOptions, type MoveFocusOptions, NOTICE_LABELS, NUMBERFIELD_LABELS, Notice, type NoticeLabels, type NoticeProps, NumberField, type NumberFieldLabels, type NumberFieldProps, PAGENAV_LABELS, PAGES_LABELS, type PageItem, PageNav, type PageNavLabels, type PageNavProps, type PageNavTarget, Pages, type PagesLabels, type PagesProps, PinField, type PinFieldProps, Placeholder, type PlaceholderProps, type PolymorphicProps, Portal, type PortalProps, Progress, type ProgressProps, Prose, type ProseProps, Quote, type QuoteProps, RATING_LABELS, Radio, RadioGroup, type RadioGroupProps, type RadioProps, type RadiusValue, Rail, RailGroup, type RailGroupProps, RailLink, type RailLinkProps, type RailProps, Range, type RangeProps, Rating, type RatingLabels, type RatingProps, type ResolvedColorScheme, type Responsive, ResultRow, type ResultRowProps, type RovingFocusOptions, SEARCH_LABELS, SECRETFIELD_LABELS, SETTINGS_LABELS, SKIPLINK_LABELS, STEPS_LABELS, SUGGEST_LABELS, Score, type ScoreProps, Search, type SearchLabels, type SearchProps, SecretField, type SecretFieldLabels, type SecretFieldProps, Segmented, type SegmentedOption, type SegmentedProps, Settings, type SettingsLabels, type SettingsLanguage, type SettingsProps, Sheet, type SheetProps, Shelf, type ShelfProps, SkipLink, type SkipLinkLabels, type SkipLinkProps, type SlurpControls, type SlurpCss, type SlurpEnterOptions, type SlurpLabels, type SlurpNavigate, type SlurpNavigateOptions, SlurpProvider, type SlurpProviderProps, type SpaceValue, Stage, type StageProps, type StatusTone, type StepItem, Steps, type StepsLabels, type StepsProps, Suggest, type SuggestLabels, type SuggestOption, type SuggestProps, Surface, type SurfaceProps, Swatch, SwatchGroup, type SwatchGroupProps, type SwatchOption, type SwatchProps, Switch, type SwitchProps, TABLE_LABELS, TOAST_LABELS, type TabItem, Table, type TableColumn, type TableLabels, type TableProps, type TableSort, Tabs, type TabsProps, Tag, type TagProps, Text, type TextProps, type TextTone, type Theme, type ThemeOptions, Tile, type TileProps, type ToastLabels, type ToastOptions, ToastProvider, type ToastProviderProps, type TokenOverrides, VisuallyHidden, type VisuallyHiddenProps, alpha, bentoLayout, contrast, createTheme, crumbPath, focusFirst, focusHit, labelsEn, labelsIt, matchRanges, matchesAll, meetsContrast, moveFocus, normalizeText, onColor, pageItems, useAnimationTarget, useClipboard, useColorScheme, useControlled, useDismiss, useFindInPage, useForkRef, useMediaQuery, useRovingFocus, useScrollSpy, useSlurp, useSlurpEnter, useSlurpNavigate, useTheme, useToast, vivid };
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { CONTRAST_MIN, alpha, contrast, meetsContrast, onColor, vivid } from "./lib/color.js";
|
|
3
3
|
import { DEFAULT_STORAGE_KEY, createTheme } from "./lib/theme.js";
|
|
4
4
|
import { useColorScheme, useTheme } from "./internal/context.js";
|
|
5
|
+
import { labelsEn, labelsIt } from "./lib/labels.js";
|
|
5
6
|
import { SlurpProvider } from "./SlurpProvider/SlurpProvider.js";
|
|
6
7
|
import { ColorSchemeScript } from "./SlurpProvider/ColorSchemeScript.js";
|
|
7
8
|
import { AnimationGroup } from "./motion/AnimationGroup.js";
|
|
@@ -60,6 +61,27 @@ import { ResultRow } from "./ResultRow/ResultRow.js";
|
|
|
60
61
|
import { Mark } from "./Mark/Mark.js";
|
|
61
62
|
import { Empty } from "./Empty/Empty.js";
|
|
62
63
|
import { Link } from "./Link/Link.js";
|
|
64
|
+
import { CALENDAR_LABELS, Calendar } from "./Calendar/Calendar.js";
|
|
65
|
+
import { DATEFIELD_LABELS, DateField } from "./DateField/DateField.js";
|
|
66
|
+
import { FILEDROP_LABELS, FileDrop } from "./FileDrop/FileDrop.js";
|
|
67
|
+
import { ERRORSUMMARY_LABELS, ErrorSummary } from "./ErrorSummary/ErrorSummary.js";
|
|
68
|
+
import { PinField } from "./PinField/PinField.js";
|
|
69
|
+
import { NUMBERFIELD_LABELS, NumberField } from "./NumberField/NumberField.js";
|
|
70
|
+
import { SECRETFIELD_LABELS, SecretField } from "./SecretField/SecretField.js";
|
|
71
|
+
import { Footer, FooterBottom, FooterGroup, FooterLink } from "./Footer/Footer.js";
|
|
72
|
+
import { Media } from "./Media/Media.js";
|
|
73
|
+
import { Quote } from "./Quote/Quote.js";
|
|
74
|
+
import { Kbd } from "./Kbd/Kbd.js";
|
|
75
|
+
import { Tag } from "./Tag/Tag.js";
|
|
76
|
+
import { Hairline } from "./Hairline/Hairline.js";
|
|
77
|
+
import { SKIPLINK_LABELS, SkipLink } from "./SkipLink/SkipLink.js";
|
|
78
|
+
import { Prose } from "./Prose/Prose.js";
|
|
79
|
+
import { useClipboard } from "./utils/useClipboard.js";
|
|
80
|
+
import { CODE_LABELS, Code } from "./Code/Code.js";
|
|
81
|
+
import { useScrollSpy } from "./utils/useScrollSpy.js";
|
|
82
|
+
import { CONTENTS_LABELS, Contents } from "./Contents/Contents.js";
|
|
83
|
+
import { Rail, RailGroup, RailLink } from "./Rail/Rail.js";
|
|
84
|
+
import { PAGENAV_LABELS, PageNav } from "./PageNav/PageNav.js";
|
|
63
85
|
import { crumbPath } from "./lib/crumb.js";
|
|
64
86
|
import { COMPACT_QUERY, useMediaQuery } from "./utils/useMediaQuery.js";
|
|
65
87
|
import { DOCK_LABELS, Dock } from "./Dock/Dock.js";
|
|
@@ -72,4 +94,4 @@ import { RATING_LABELS, Rating } from "./Rating/Rating.js";
|
|
|
72
94
|
import { TABLE_LABELS, Table } from "./Table/Table.js";
|
|
73
95
|
import { CAROUSEL_LABELS, Carousel } from "./Carousel/Carousel.js";
|
|
74
96
|
import { focusHit, useFindInPage } from "./utils/useFindInPage.js";
|
|
75
|
-
export { AccentScope, AnimationGroup, Avatar, Bento, Bloom, Bubble, Button, CAROUSEL_LABELS, CHOICE_LABELS, COMPACT_QUERY, CONTRAST_MIN, Card, Carousel, Cell, Checkbox, Chip, Choice, ColorSchemeScript, Count, DEFAULT_STORAGE_KEY, DIALOG_LABELS, DOCK_LABELS, Dialog, Dock, Empty, FILTERS_LABELS, FOCUSABLE, Fact, Field, Filters, Flow, Fold, Frame, Ground, Hint, Link, List, ListRow, Mark, Menu, MenuItem, NOTICE_LABELS, Notice, PAGES_LABELS, Pages, Placeholder, Portal, Progress, RATING_LABELS, Radio, RadioGroup, Range, Rating, ResultRow, SEARCH_LABELS, SETTINGS_LABELS, STEPS_LABELS, SUGGEST_LABELS, Score, Search, Segmented, Settings, Sheet, Shelf, SlurpProvider, Stage, Steps, Suggest, Surface, Swatch, SwatchGroup, Switch, TABLE_LABELS, TOAST_LABELS, Table, Tabs, Text, Tile, ToastProvider, VisuallyHidden, alpha, bentoLayout, contrast, createTheme, crumbPath, focusFirst, focusHit, matchRanges, matchesAll, meetsContrast, moveFocus, normalizeText, onColor, pageItems, useAnimationTarget, useColorScheme, useControlled, useDismiss, useFindInPage, useForkRef, useMediaQuery, useRovingFocus, useSlurp, useSlurpEnter, useSlurpNavigate, useTheme, useToast, vivid };
|
|
97
|
+
export { AccentScope, AnimationGroup, Avatar, Bento, Bloom, Bubble, Button, CALENDAR_LABELS, CAROUSEL_LABELS, CHOICE_LABELS, CODE_LABELS, COMPACT_QUERY, CONTENTS_LABELS, CONTRAST_MIN, Calendar, Card, Carousel, Cell, Checkbox, Chip, Choice, Code, ColorSchemeScript, Contents, Count, DATEFIELD_LABELS, DEFAULT_STORAGE_KEY, DIALOG_LABELS, DOCK_LABELS, DateField, Dialog, Dock, ERRORSUMMARY_LABELS, Empty, ErrorSummary, FILEDROP_LABELS, FILTERS_LABELS, FOCUSABLE, Fact, Field, FileDrop, Filters, Flow, Fold, Footer, FooterBottom, FooterGroup, FooterLink, Frame, Ground, Hairline, Hint, Kbd, Link, List, ListRow, Mark, Media, Menu, MenuItem, NOTICE_LABELS, NUMBERFIELD_LABELS, Notice, NumberField, PAGENAV_LABELS, PAGES_LABELS, PageNav, Pages, PinField, Placeholder, Portal, Progress, Prose, Quote, RATING_LABELS, Radio, RadioGroup, Rail, RailGroup, RailLink, Range, Rating, ResultRow, SEARCH_LABELS, SECRETFIELD_LABELS, SETTINGS_LABELS, SKIPLINK_LABELS, STEPS_LABELS, SUGGEST_LABELS, Score, Search, SecretField, Segmented, Settings, Sheet, Shelf, SkipLink, SlurpProvider, Stage, Steps, Suggest, Surface, Swatch, SwatchGroup, Switch, TABLE_LABELS, TOAST_LABELS, Table, Tabs, Tag, Text, Tile, ToastProvider, VisuallyHidden, alpha, bentoLayout, contrast, createTheme, crumbPath, focusFirst, focusHit, labelsEn, labelsIt, matchRanges, matchesAll, meetsContrast, moveFocus, normalizeText, onColor, pageItems, useAnimationTarget, useClipboard, useColorScheme, useControlled, useDismiss, useFindInPage, useForkRef, useMediaQuery, useRovingFocus, useScrollSpy, useSlurp, useSlurpEnter, useSlurpNavigate, useTheme, useToast, vivid };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
// src/internal/labels.ts
|
|
4
|
+
/** Texts set by the nearest SlurpProvider with `labels` (none: the components' Italian defaults). */
|
|
5
|
+
const LabelsContext = createContext({});
|
|
6
|
+
/** This component's texts from the provider; spread between its defaults and its own `labels` prop. */
|
|
7
|
+
function useLabels(name) {
|
|
8
|
+
return useContext(LabelsContext)[name] ?? {};
|
|
9
|
+
}
|
|
10
|
+
export { LabelsContext, useLabels };
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=labels.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"labels.js","names":[],"sources":["../../src/internal/labels.ts"],"sourcesContent":["import { createContext, useContext } from 'react';\n\nimport type { SlurpLabels } from '../lib/labels';\n\n/** Texts set by the nearest SlurpProvider with `labels` (none: the components' Italian defaults). */\nexport const LabelsContext = createContext<SlurpLabels>({});\n\n/** This component's texts from the provider; spread between its defaults and its own `labels` prop. */\nexport function useLabels<K extends keyof SlurpLabels>(name: K): NonNullable<SlurpLabels[K]> {\n return (useContext(LabelsContext)[name] ?? {}) as NonNullable<SlurpLabels[K]>;\n}\n"],"mappings":";;;;AAKA,MAAa,gBAAgB,cAA2B,CAAC,CAAC;;AAG1D,SAAgB,UAAuC,MAAsC;CAC3F,OAAQ,WAAW,aAAa,CAAC,CAAC,SAAS,CAAC;AAC9C"}
|