@namroodinc/liquid-editorial 0.6.4 → 0.6.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +58 -1
- package/UPGRADING.md +88 -0
- package/dist/chunks/{Avatar-C1q2AUD-.js → Avatar-BtblwihO.js} +2 -2
- package/dist/chunks/{Avatar-C1q2AUD-.js.map → Avatar-BtblwihO.js.map} +1 -1
- package/dist/chunks/{Avatar-BTKqaJLP.cjs → Avatar-C9ublbzK.cjs} +2 -2
- package/dist/chunks/{Avatar-BTKqaJLP.cjs.map → Avatar-C9ublbzK.cjs.map} +1 -1
- package/dist/chunks/ColourField-BqhYB4ZE.cjs +2 -0
- package/dist/chunks/ColourField-BqhYB4ZE.cjs.map +1 -0
- package/dist/chunks/{ColourField-BwDb7ydB.js → ColourField-DXGpNP08.js} +6 -2
- package/dist/chunks/ColourField-DXGpNP08.js.map +1 -0
- package/dist/chunks/DatePicker-01sor8iD.cjs +2 -0
- package/dist/chunks/DatePicker-01sor8iD.cjs.map +1 -0
- package/dist/chunks/{DatePicker-C1zcScC3.js → DatePicker-DJAqXUDJ.js} +2 -2
- package/dist/chunks/DatePicker-DJAqXUDJ.js.map +1 -0
- package/dist/chunks/{FormEditor-Dd44EMp_.cjs → FormEditor-BbsvbufQ.cjs} +2 -2
- package/dist/chunks/{FormEditor-Dd44EMp_.cjs.map → FormEditor-BbsvbufQ.cjs.map} +1 -1
- package/dist/chunks/{FormEditor-C4PJu7ZF.js → FormEditor-C5XtP-N7.js} +3 -3
- package/dist/chunks/{FormEditor-C4PJu7ZF.js.map → FormEditor-C5XtP-N7.js.map} +1 -1
- package/dist/chunks/Message-CaX8Y1Xb.js +74 -0
- package/dist/chunks/Message-CaX8Y1Xb.js.map +1 -0
- package/dist/chunks/Message-DU31JAb3.cjs +2 -0
- package/dist/chunks/Message-DU31JAb3.cjs.map +1 -0
- package/dist/chunks/{useTooltip-D6cJji8v.js → useTooltip-C5gvEoYk.js} +2 -1
- package/dist/chunks/{useTooltip-D6cJji8v.js.map → useTooltip-C5gvEoYk.js.map} +1 -1
- package/dist/chunks/{useTooltip-CCf79zE9.cjs → useTooltip-bTE_a2Xn.cjs} +2 -2
- package/dist/chunks/{useTooltip-CCf79zE9.cjs.map → useTooltip-bTE_a2Xn.cjs.map} +1 -1
- package/dist/components/Avatar/index.cjs +1 -1
- package/dist/components/Avatar/index.js +1 -1
- package/dist/components/Banner/index.cjs +2 -0
- package/dist/components/Banner/index.cjs.map +1 -0
- package/dist/components/Banner/index.d.cts +6 -0
- package/dist/components/Banner/index.d.cts.map +1 -0
- package/dist/components/Banner/index.d.ts +6 -0
- package/dist/components/Banner/index.d.ts.map +1 -0
- package/dist/components/Banner/index.js +18 -0
- package/dist/components/Banner/index.js.map +1 -0
- package/dist/components/Banner/style.css +6 -0
- package/dist/components/ColourField/index.cjs +1 -1
- package/dist/components/ColourField/index.js +1 -1
- package/dist/components/DatePicker/index.cjs +1 -1
- package/dist/components/DatePicker/index.js +1 -1
- package/dist/components/Drawer/index.cjs +1 -1
- package/dist/components/Drawer/index.cjs.map +1 -1
- package/dist/components/Drawer/index.js +5 -1
- package/dist/components/Drawer/index.js.map +1 -1
- package/dist/components/FormEditor/index.cjs +1 -1
- package/dist/components/FormEditor/index.js +1 -1
- package/dist/components/Menu/index.cjs +1 -1
- package/dist/components/Menu/index.cjs.map +1 -1
- package/dist/components/Menu/index.js +1 -1
- package/dist/components/Menu/index.js.map +1 -1
- package/dist/components/Modal/index.cjs +1 -1
- package/dist/components/Modal/index.cjs.map +1 -1
- package/dist/components/Modal/index.js +5 -1
- package/dist/components/Modal/index.js.map +1 -1
- package/dist/components/Popover/style.css +2 -1
- package/dist/components/Popover/useTooltip.d.cts.map +1 -1
- package/dist/components/Popover/useTooltip.d.ts.map +1 -1
- package/dist/components/Select/index.cjs +1 -1
- package/dist/components/Select/index.cjs.map +1 -1
- package/dist/components/Select/index.js +1 -1
- package/dist/components/Select/index.js.map +1 -1
- package/dist/components/Table/index.cjs +1 -1
- package/dist/components/Table/index.cjs.map +1 -1
- package/dist/components/Table/index.js +1 -1
- package/dist/components/Table/index.js.map +1 -1
- package/dist/components/Time/index.cjs +1 -1
- package/dist/components/Time/index.js +1 -1
- package/dist/components/Toast/index.cjs +1 -1
- package/dist/components/Toast/index.cjs.map +1 -1
- package/dist/components/Toast/index.d.cts.map +1 -1
- package/dist/components/Toast/index.d.ts.map +1 -1
- package/dist/components/Toast/index.js +35 -60
- package/dist/components/Toast/index.js.map +1 -1
- package/dist/components/Toast/style.css +5 -50
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -13
- package/dist/internal/Message.d.cts +23 -0
- package/dist/internal/Message.d.cts.map +1 -0
- package/dist/internal/Message.d.ts +23 -0
- package/dist/internal/Message.d.ts.map +1 -0
- package/dist/message.css +122 -0
- package/dist/styles.css +2 -0
- package/dist/tokens.css +36 -12
- package/package.json +1 -1
- package/dist/chunks/ColourField-Bk5O632x.cjs +0 -2
- package/dist/chunks/ColourField-Bk5O632x.cjs.map +0 -1
- package/dist/chunks/ColourField-BwDb7ydB.js.map +0 -1
- package/dist/chunks/DatePicker-BVsloqVY.cjs +0 -2
- package/dist/chunks/DatePicker-BVsloqVY.cjs.map +0 -1
- package/dist/chunks/DatePicker-C1zcScC3.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["Icon","cx","parts","Select","forwardRef","ariaInvalid","rest","internal","setInternal","useState","defaultValue","current","value","isOpen","setOpen","activeIndex","setActiveIndex","rootRef","useRef","triggerRef","listRef","listId","useId","effectiveDisabled","isDisabled","disabled","isVisible","selected","options","option","enabled","commit","useCallback","next","onValueChange","useEffect","index","onPointerDown","target","event","step","order","o","delta","handleListKeyDown","pick","handleKeyDown","Button","node","ref","required","isInvalid","className","onClick","open","onKeyDown","placeholder","Popover","menuPlacement"],"sources":["../../../src/components/Select/index.tsx"],"sourcesContent":["import {\n forwardRef,\n useCallback,\n useEffect,\n useId,\n useRef,\n useState,\n type ButtonHTMLAttributes,\n} from \"react\";\nimport { Icon } from \"../Icon\";\nimport { Button } from \"../Button\";\nimport { Popover, type PopoverPlacement } from \"../Popover\";\nimport type { FieldSize } from \"../Field\";\nimport \"../Field/style.css\";\nimport \"./style.css\";\n\nfunction cx(...parts: (string | undefined | false)[]) {\n return parts.filter(Boolean).join(\" \");\n}\n\nexport interface SelectOption {\n value: string;\n label: string;\n /** Secondary line under the label. */\n description?: string;\n isDisabled?: boolean;\n}\n\nexport interface SelectProps extends Omit<\n ButtonHTMLAttributes<HTMLButtonElement>,\n \"value\" | \"defaultValue\" | \"onChange\"\n> {\n required?: boolean;\n options: SelectOption[];\n /** Controlled value. Leave undefined to let the select hold its own. */\n value?: string;\n defaultValue?: string;\n onValueChange?: (value: string) => void;\n placeholder?: string;\n size?: FieldSize;\n isDisabled?: boolean;\n isInvalid?: boolean;\n /** Preferred side of the menu; flips when space requires it. */\n menuPlacement?: PopoverPlacement;\n}\n\n/**\n * One value out of a known list. Wears the field skin, opens a listbox: arrows\n * walk the options, Enter commits, Escape closes without changing anything.\n */\nexport const Select = forwardRef<HTMLButtonElement, SelectProps>(function Select(\n {\n options,\n value,\n defaultValue,\n onValueChange,\n placeholder = \"Select an option\",\n size = \"md\",\n isDisabled = false,\n isInvalid = false,\n \"aria-invalid\": ariaInvalid,\n required,\n menuPlacement = \"bottom\",\n className,\n disabled,\n onClick,\n onKeyDown,\n ...rest\n },\n ref,\n) {\n const [internal, setInternal] = useState(defaultValue ?? \"\");\n const current = value ?? internal;\n const [isOpen, setOpen] = useState(false);\n const [activeIndex, setActiveIndex] = useState(0);\n const rootRef = useRef<HTMLDivElement | null>(null);\n const triggerRef = useRef<HTMLButtonElement | null>(null);\n const listRef = useRef<HTMLDivElement | null>(null);\n const listId = useId();\n const effectiveDisabled = isDisabled || disabled;\n const isVisible = isOpen && !effectiveDisabled;\n\n const selected = options.find((option) => option.value === current);\n const enabled = options.filter((option) => !option.isDisabled);\n\n const commit = useCallback(\n (next: string) => {\n if (value === undefined) {\n setInternal(next);\n }\n onValueChange?.(next);\n setOpen(false);\n },\n [onValueChange, value],\n );\n\n useEffect(() => {\n if (!isVisible) {\n return;\n }\n const index = options.findIndex((option) => option.value === current && !option.isDisabled);\n setActiveIndex(index < 0 ? options.indexOf(enabled[0]!) : index);\n const onPointerDown = (event: MouseEvent) => {\n const target = event.target as Node;\n if (!rootRef.current?.contains(target) && !listRef.current?.contains(target)) {\n setOpen(false);\n }\n };\n document.addEventListener(\"mousedown\", onPointerDown);\n return () => document.removeEventListener(\"mousedown\", onPointerDown);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isVisible]);\n\n useEffect(() => {\n if (!isVisible) {\n return;\n }\n const activeOption =\n listRef.current?.querySelectorAll<HTMLElement>(\"[role='option']\")[activeIndex];\n activeOption?.scrollIntoView({ block: \"nearest\" });\n }, [activeIndex, isVisible]);\n\n const step = (delta: number) => {\n const order = options\n .map((option, index) => ({ option, index }))\n .filter((o) => !o.option.isDisabled);\n if (order.length === 0) {\n return;\n }\n const at = order.findIndex((o) => o.index === activeIndex);\n const next = order[(at + delta + order.length) % order.length]!;\n setActiveIndex(next.index);\n };\n\n const handleListKeyDown = (event: React.KeyboardEvent) => {\n switch (event.key) {\n case \"Escape\":\n // Claims Escape so an enclosing Drawer stays open.\n event.preventDefault();\n setOpen(false);\n triggerRef.current?.focus();\n break;\n case \"Tab\":\n setOpen(false);\n break;\n case \"ArrowDown\":\n case \"ArrowUp\":\n event.preventDefault();\n step(event.key === \"ArrowDown\" ? 1 : -1);\n break;\n case \"Home\":\n case \"End\": {\n event.preventDefault();\n const pick = event.key === \"Home\" ? enabled[0] : enabled[enabled.length - 1];\n if (pick) {\n setActiveIndex(options.indexOf(pick));\n }\n break;\n }\n case \"Enter\":\n case \" \": {\n event.preventDefault();\n const option = options[activeIndex];\n if (option && !option.isDisabled) {\n commit(option.value);\n }\n break;\n }\n }\n };\n\n const handleKeyDown = (event: React.KeyboardEvent) => {\n if (effectiveDisabled) {\n return;\n }\n if (isVisible) {\n handleListKeyDown(event);\n } else if ([\"ArrowDown\", \"ArrowUp\", \"Enter\", \" \"].includes(event.key)) {\n event.preventDefault();\n setOpen(true);\n }\n };\n\n return (\n <div\n className=\"ds-select-root\"\n ref={rootRef}\n >\n <Button\n ref={(node) => {\n triggerRef.current = node;\n if (typeof ref === \"function\") {\n ref(node);\n } else if (ref) {\n ref.current = node;\n }\n }}\n size={size}\n role=\"combobox\"\n aria-required={required || undefined}\n aria-haspopup=\"listbox\"\n aria-expanded={isVisible}\n aria-controls={isVisible ? listId : undefined}\n aria-activedescendant={\n isVisible && options[activeIndex] && !options[activeIndex].isDisabled\n ? `${listId}-option-${activeIndex}`\n : undefined\n }\n aria-invalid={isInvalid || ariaInvalid || undefined}\n isDisabled={effectiveDisabled}\n data-placeholder={selected ? undefined : \"\"}\n className={cx(\"ds-field-skin\", \"ds-select\", className)}\n onClick={(event) => {\n onClick?.(event);\n if (!event.defaultPrevented) {\n setOpen((open) => !open);\n }\n }}\n onKeyDown={(event) => {\n onKeyDown?.(event);\n if (!event.defaultPrevented) {\n handleKeyDown(event);\n }\n }}\n {...rest}\n >\n <span className=\"ds-select__value\">{selected ? selected.label : placeholder}</span>\n <Icon\n name=\"chevron-down\"\n size={16}\n className=\"ds-select__chevron\"\n />\n </Button>\n <Popover\n anchorRef={triggerRef}\n isOpen={isVisible}\n align=\"start\"\n placement={menuPlacement}\n matchAnchorWidth\n panelRef={listRef}\n id={listId}\n role=\"listbox\"\n aria-label={rest[\"aria-labelledby\"] ? undefined : (rest[\"aria-label\"] ?? placeholder)}\n aria-labelledby={rest[\"aria-labelledby\"]}\n className=\"ds-surface-raised ds-select__menu\"\n >\n <div\n onKeyDown={handleKeyDown}\n onPointerDown={(event) => event.preventDefault()}\n >\n {options.map((option, index) => (\n <Button\n key={option.value}\n variant={index === activeIndex ? \"active\" : \"simple\"}\n size=\"sm\"\n isDisabled={option.isDisabled}\n tabIndex={-1}\n id={`${listId}-option-${index}`}\n role=\"option\"\n aria-selected={option.value === current}\n aria-disabled={option.isDisabled || undefined}\n data-active={index === activeIndex || undefined}\n className=\"ds-select__option\"\n onMouseEnter={() => !option.isDisabled && setActiveIndex(index)}\n onClick={() => {\n if (!option.isDisabled) {\n commit(option.value);\n triggerRef.current?.focus();\n }\n }}\n >\n <span className=\"ds-select__option-body\">\n <span className=\"ds-select__option-label\">{option.label}</span>\n {option.description && (\n <span className=\"ds-select__option-description\">{option.description}</span>\n )}\n </span>\n {option.value === current && (\n <Icon\n name=\"check\"\n size={16}\n />\n )}\n </Button>\n ))}\n </div>\n </Popover>\n </div>\n );\n});\n"],"mappings":";;;;;;;AAgBA,SAASC,EAAG,GAAGC,GAAuC;CACpD,OAAOA,EAAM,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG;AACvC;AAgCA,IAAaC,IAASC,EAA2C,SAC/D,EACE,YACA,UACA,iBACA,kBACA,iBAAc,oBACd,UAAO,MACP,gBAAa,IACb,eAAY,IACZ,gBAAgBC,GAChB,aACA,mBAAgB,UAChB,cACA,aACA,YACA,cACA,GAAGC,KAEL,GACA;CACA,IAAM,CAACC,GAAUC,KAAeC,EAASC,KAAgB,EAAE,GACrDC,IAAUC,KAASL,GACnB,CAACM,GAAQC,KAAWL,EAAS,EAAK,GAClC,CAACM,GAAaC,KAAkBP,EAAS,CAAC,GAC1CQ,IAAUC,EAA8B,IAAI,GAC5CC,IAAaD,EAAiC,IAAI,GAClDE,IAAUF,EAA8B,IAAI,GAC5CG,IAASC,EAAM,GACfC,IAAoBC,KAAcC,GAClCC,IAAYb,KAAU,CAACU,GAEvBI,IAAWC,EAAQ,MAAM,MAAWC,EAAO,UAAUlB,CAAO,GAC5DmB,IAAUF,EAAQ,QAAQ,MAAW,CAACC,EAAO,UAAU,GAEvDE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,KAChB,kBAACX,GAAD;MACE,MAAK;MACL,MAAM;KACP,CAAA,CAEG;IA/BD,GAAA6B,EAAO,KA+BN,CACT;GACE,CAAA;EACE,CAAA,CACN;;AAET,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["Icon","cx","parts","Select","forwardRef","ariaInvalid","rest","internal","setInternal","useState","defaultValue","current","value","isOpen","setOpen","activeIndex","setActiveIndex","rootRef","useRef","triggerRef","listRef","listId","useId","effectiveDisabled","isDisabled","disabled","isVisible","selected","options","option","enabled","commit","useCallback","next","onValueChange","useEffect","index","onPointerDown","target","event","step","order","o","delta","handleListKeyDown","pick","handleKeyDown","Button","node","ref","required","isInvalid","className","onClick","open","onKeyDown","placeholder","Popover","menuPlacement"],"sources":["../../../src/components/Select/index.tsx"],"sourcesContent":["import {\n forwardRef,\n useCallback,\n useEffect,\n useId,\n useRef,\n useState,\n type ButtonHTMLAttributes,\n} from \"react\";\nimport { Icon } from \"../Icon\";\nimport { Button } from \"../Button\";\nimport { Popover, type PopoverPlacement } from \"../Popover\";\nimport type { FieldSize } from \"../Field\";\nimport \"../Field/style.css\";\nimport \"./style.css\";\n\nfunction cx(...parts: (string | undefined | false)[]) {\n return parts.filter(Boolean).join(\" \");\n}\n\nexport interface SelectOption {\n value: string;\n label: string;\n /** Secondary line under the label. */\n description?: string;\n isDisabled?: boolean;\n}\n\nexport interface SelectProps extends Omit<\n ButtonHTMLAttributes<HTMLButtonElement>,\n \"value\" | \"defaultValue\" | \"onChange\"\n> {\n required?: boolean;\n options: SelectOption[];\n /** Controlled value. Leave undefined to let the select hold its own. */\n value?: string;\n defaultValue?: string;\n onValueChange?: (value: string) => void;\n placeholder?: string;\n size?: FieldSize;\n isDisabled?: boolean;\n isInvalid?: boolean;\n /** Preferred side of the menu; flips when space requires it. */\n menuPlacement?: PopoverPlacement;\n}\n\n/**\n * One value out of a known list. Wears the field skin, opens a listbox: arrows\n * walk the options, Enter commits, Escape closes without changing anything.\n */\nexport const Select = forwardRef<HTMLButtonElement, SelectProps>(function Select(\n {\n options,\n value,\n defaultValue,\n onValueChange,\n placeholder = \"Select an option\",\n size = \"md\",\n isDisabled = false,\n isInvalid = false,\n \"aria-invalid\": ariaInvalid,\n required,\n menuPlacement = \"bottom\",\n className,\n disabled,\n onClick,\n onKeyDown,\n ...rest\n },\n ref,\n) {\n const [internal, setInternal] = useState(defaultValue ?? \"\");\n const current = value ?? internal;\n const [isOpen, setOpen] = useState(false);\n const [activeIndex, setActiveIndex] = useState(0);\n const rootRef = useRef<HTMLDivElement | null>(null);\n const triggerRef = useRef<HTMLButtonElement | null>(null);\n const listRef = useRef<HTMLDivElement | null>(null);\n const listId = useId();\n const effectiveDisabled = isDisabled || disabled;\n const isVisible = isOpen && !effectiveDisabled;\n\n const selected = options.find((option) => option.value === current);\n const enabled = options.filter((option) => !option.isDisabled);\n\n const commit = useCallback(\n (next: string) => {\n if (value === undefined) {\n setInternal(next);\n }\n onValueChange?.(next);\n setOpen(false);\n },\n [onValueChange, value],\n );\n\n useEffect(() => {\n if (!isVisible) {\n return;\n }\n const index = options.findIndex((option) => option.value === current && !option.isDisabled);\n setActiveIndex(index < 0 ? options.indexOf(enabled[0]!) : index);\n const onPointerDown = (event: MouseEvent) => {\n const target = event.target as Node;\n if (!rootRef.current?.contains(target) && !listRef.current?.contains(target)) {\n setOpen(false);\n }\n };\n document.addEventListener(\"mousedown\", onPointerDown);\n return () => document.removeEventListener(\"mousedown\", onPointerDown);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isVisible]);\n\n useEffect(() => {\n if (!isVisible) {\n return;\n }\n const activeOption =\n listRef.current?.querySelectorAll<HTMLElement>(\"[role='option']\")[activeIndex];\n activeOption?.scrollIntoView({ block: \"nearest\" });\n }, [activeIndex, isVisible]);\n\n const step = (delta: number) => {\n const order = options\n .map((option, index) => ({ option, index }))\n .filter((o) => !o.option.isDisabled);\n if (order.length === 0) {\n return;\n }\n const at = order.findIndex((o) => o.index === activeIndex);\n const next = order[(at + delta + order.length) % order.length]!;\n setActiveIndex(next.index);\n };\n\n const handleListKeyDown = (event: React.KeyboardEvent) => {\n switch (event.key) {\n case \"Escape\":\n // Claims Escape so an enclosing Drawer stays open.\n event.preventDefault();\n setOpen(false);\n triggerRef.current?.focus();\n break;\n case \"Tab\":\n setOpen(false);\n break;\n case \"ArrowDown\":\n case \"ArrowUp\":\n event.preventDefault();\n step(event.key === \"ArrowDown\" ? 1 : -1);\n break;\n case \"Home\":\n case \"End\": {\n event.preventDefault();\n const pick = event.key === \"Home\" ? enabled[0] : enabled[enabled.length - 1];\n if (pick) {\n setActiveIndex(options.indexOf(pick));\n }\n break;\n }\n case \"Enter\":\n case \" \": {\n event.preventDefault();\n const option = options[activeIndex];\n if (option && !option.isDisabled) {\n commit(option.value);\n }\n break;\n }\n }\n };\n\n const handleKeyDown = (event: React.KeyboardEvent) => {\n if (effectiveDisabled) {\n return;\n }\n if (isVisible) {\n handleListKeyDown(event);\n } else if ([\"ArrowDown\", \"ArrowUp\", \"Enter\", \" \"].includes(event.key)) {\n event.preventDefault();\n setOpen(true);\n }\n };\n\n return (\n <div\n className=\"ds-select-root\"\n ref={rootRef}\n >\n <Button\n ref={(node) => {\n triggerRef.current = node;\n if (typeof ref === \"function\") {\n ref(node);\n } else if (ref) {\n ref.current = node;\n }\n }}\n size={size}\n role=\"combobox\"\n aria-required={required || undefined}\n aria-haspopup=\"listbox\"\n aria-expanded={isVisible}\n aria-controls={isVisible ? listId : undefined}\n aria-activedescendant={\n isVisible && options[activeIndex] && !options[activeIndex].isDisabled\n ? `${listId}-option-${activeIndex}`\n : undefined\n }\n aria-invalid={isInvalid || ariaInvalid || undefined}\n isDisabled={effectiveDisabled}\n data-placeholder={selected ? undefined : \"\"}\n className={cx(\"ds-field-skin\", \"ds-select\", className)}\n onClick={(event) => {\n onClick?.(event);\n if (!event.defaultPrevented) {\n setOpen((open) => !open);\n }\n }}\n onKeyDown={(event) => {\n onKeyDown?.(event);\n if (!event.defaultPrevented) {\n handleKeyDown(event);\n }\n }}\n {...rest}\n >\n <span className=\"ds-select__value\">{selected ? selected.label : placeholder}</span>\n <Icon\n name=\"chevron-down\"\n size={16}\n className=\"ds-select__chevron\"\n />\n </Button>\n <Popover\n anchorRef={triggerRef}\n isOpen={isVisible}\n align=\"start\"\n placement={menuPlacement}\n matchAnchorWidth\n panelRef={listRef}\n id={listId}\n role=\"listbox\"\n aria-label={rest[\"aria-labelledby\"] ? undefined : (rest[\"aria-label\"] ?? placeholder)}\n aria-labelledby={rest[\"aria-labelledby\"]}\n className=\"ds-surface-raised ds-field-surface ds-select__menu\"\n >\n <div\n onKeyDown={handleKeyDown}\n onPointerDown={(event) => event.preventDefault()}\n >\n {options.map((option, index) => (\n <Button\n key={option.value}\n variant={index === activeIndex ? \"active\" : \"simple\"}\n size=\"sm\"\n isDisabled={option.isDisabled}\n tabIndex={-1}\n id={`${listId}-option-${index}`}\n role=\"option\"\n aria-selected={option.value === current}\n aria-disabled={option.isDisabled || undefined}\n data-active={index === activeIndex || undefined}\n className=\"ds-select__option\"\n onMouseEnter={() => !option.isDisabled && setActiveIndex(index)}\n onClick={() => {\n if (!option.isDisabled) {\n commit(option.value);\n triggerRef.current?.focus();\n }\n }}\n >\n <span className=\"ds-select__option-body\">\n <span className=\"ds-select__option-label\">{option.label}</span>\n {option.description && (\n <span className=\"ds-select__option-description\">{option.description}</span>\n )}\n </span>\n {option.value === current && (\n <Icon\n name=\"check\"\n size={16}\n />\n )}\n </Button>\n ))}\n </div>\n </Popover>\n </div>\n );\n});\n"],"mappings":";;;;;;;AAgBA,SAASC,EAAG,GAAGC,GAAuC;CACpD,OAAOA,EAAM,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG;AACvC;AAgCA,IAAaC,IAASC,EAA2C,SAC/D,EACE,YACA,UACA,iBACA,kBACA,iBAAc,oBACd,UAAO,MACP,gBAAa,IACb,eAAY,IACZ,gBAAgBC,GAChB,aACA,mBAAgB,UAChB,cACA,aACA,YACA,cACA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AAekB,EAAO,cAAc,KAAA;KACpC,eAAaO,MAAUrB,KAAe,KAAA;KACtC,WAAU;KACV,oBAAoB,CAACc,EAAO,cAAcb,EAAeoB,CAAK;KAC9D,eAAe;MACb,AAAKP,EAAO,eACVE,EAAOF,EAAO,KAAK,GACnBV,EAAW,SAAS,MAAM;KAE9B;KAlBF,UAAA,CAoBE,kBAAC,QAAD;MAAM,WAAU;MAAhB,UAAA,CACE,kBAAC,QAAD;OAAM,WAAU;OAA2B,UAAAU,EAAO;MAAY,CAAA,GAC7DA,EAAO,eACN,kBAAC,QAAD;OAAM,WAAU;OAAiC,UAAAA,EAAO;MAAkB,CAAA,CAExE;KACL,CAAA,GAAAA,EAAO,UAAUlB,KAChB,kBAACX,GAAD;MACE,MAAK;MACL,MAAM;KACP,CAAA,CAEG;IA/BD,GAAA6B,EAAO,KA+BN,CACT;GACE,CAAA;EACE,CAAA,CACN;;AAET,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../chunks/Icon-WOhlu6Rp.cjs");let t=require("react"),n=require("react/jsx-runtime");function r(...e){return e.filter(Boolean).join(` `)}var i=(0,t.forwardRef)(function({className:e,children:t,...i},a){return(0,n.jsx)(`div`,{ref:a,className:r(`ds-table-frame`,e),...i,children:t})}),a=(0,t.forwardRef)(function({start:e,end:t,className:i,...a},o){return(0,n.jsxs)(`div`,{ref:o,className:r(`ds-table-toolbar`,i),...a,children:[(0,n.jsx)(`div`,{className:`ds-table-toolbar__group`,children:e}),(0,n.jsx)(`div`,{className:`ds-table-toolbar__group`,children:t})]})});function o(e){return t.Children.toArray(e).some(e=>(0,t.isValidElement)(e)&&(e.type!==t.Fragment||o(e.props.children)))}var s=(0,t.createContext)({emptyMessage:`No data found.`}),c=(0,t.forwardRef)(function({emptyMessage:e=`No data found.`,isEmpty:t,className:i,children:a,...o},c){return(0,n.jsx)(s.Provider,{value:{emptyMessage:e,isEmpty:t},children:(0,n.jsx)(`div`,{className:`ds-table-frame__scroll`,children:(0,n.jsx)(`table`,{...o,ref:c,className:r(`ds-table`,i),children:a})})})}),l=(0,t.forwardRef)(function({className:e,...t},r){return(0,n.jsx)(`thead`,{ref:r,className:e,...t})}),u=(0,t.forwardRef)(function({className:e,children:r,...i},a){let{emptyMessage:c,isEmpty:l}=(0,t.useContext)(s);return(0,n.jsx)(`tbody`,{ref:a,className:e,...i,children:l??!o(r)?(0,n.jsx)(d,{children:(0,n.jsx)(p,{colSpan:1e3,className:`ds-table__empty-cell`,children:(0,n.jsx)(m,{title:c,role:`status`})})}):r})}),d=(0,t.forwardRef)(function({isSelected:e=!1,isInteractive:t=!1,className:r,...i},a){return(0,n.jsx)(`tr`,{ref:a,"data-selected":e||void 0,"data-interactive":t||void 0,tabIndex:t?0:void 0,className:r,...i})}),f=(0,t.forwardRef)(function({align:e=`start`,width:t=`auto`,className:r,...i},a){return(0,n.jsx)(`th`,{ref:a,scope:`col`,"data-align":e,"data-width":t,className:r,...i})}),p=(0,t.forwardRef)(function({align:e=`start`,width:t=`auto`,emphasis:r=`default`,className:i,...a},o){return(0,n.jsx)(`td`,{ref:o,"data-align":e,"data-width":t,"data-emphasis":r==="default"?void 0:r,className:i,...a})}),m=(0,t.forwardRef)(function({icon:t=`info`,title:i=`No data found.`,description:a,action:o,className:s,...c},l){return(0,n.jsxs)(`div`,{ref:l,className:r(`ds-table-empty`,s),...c,children:[(0,n.jsx)(e.t,{name:t,size:24}),(0,n.jsx)(`span`,{style:{color:`var(--color-text)`,fontWeight:`var(--font-weight-bold)`},children:i}),a&&(0,n.jsx)(`span`,{children:a}),o]})});exports.Table=c,exports.TableBody=u,exports.TableCell=p,exports.TableEmpty=m,exports.TableFrame=i,exports.TableHead=l,exports.TableHeaderCell=f,exports.TableRow=d,exports.TableToolbar=a;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../chunks/Icon-WOhlu6Rp.cjs");let t=require("react"),n=require("react/jsx-runtime");function r(...e){return e.filter(Boolean).join(` `)}var i=(0,t.forwardRef)(function({className:e,children:t,...i},a){return(0,n.jsx)(`div`,{ref:a,className:r(`ds-table-frame`,`ds-field-surface`,e),...i,children:t})}),a=(0,t.forwardRef)(function({start:e,end:t,className:i,...a},o){return(0,n.jsxs)(`div`,{ref:o,className:r(`ds-table-toolbar`,i),...a,children:[(0,n.jsx)(`div`,{className:`ds-table-toolbar__group`,children:e}),(0,n.jsx)(`div`,{className:`ds-table-toolbar__group`,children:t})]})});function o(e){return t.Children.toArray(e).some(e=>(0,t.isValidElement)(e)&&(e.type!==t.Fragment||o(e.props.children)))}var s=(0,t.createContext)({emptyMessage:`No data found.`}),c=(0,t.forwardRef)(function({emptyMessage:e=`No data found.`,isEmpty:t,className:i,children:a,...o},c){return(0,n.jsx)(s.Provider,{value:{emptyMessage:e,isEmpty:t},children:(0,n.jsx)(`div`,{className:`ds-table-frame__scroll`,children:(0,n.jsx)(`table`,{...o,ref:c,className:r(`ds-table`,i),children:a})})})}),l=(0,t.forwardRef)(function({className:e,...t},r){return(0,n.jsx)(`thead`,{ref:r,className:e,...t})}),u=(0,t.forwardRef)(function({className:e,children:r,...i},a){let{emptyMessage:c,isEmpty:l}=(0,t.useContext)(s);return(0,n.jsx)(`tbody`,{ref:a,className:e,...i,children:l??!o(r)?(0,n.jsx)(d,{children:(0,n.jsx)(p,{colSpan:1e3,className:`ds-table__empty-cell`,children:(0,n.jsx)(m,{title:c,role:`status`})})}):r})}),d=(0,t.forwardRef)(function({isSelected:e=!1,isInteractive:t=!1,className:r,...i},a){return(0,n.jsx)(`tr`,{ref:a,"data-selected":e||void 0,"data-interactive":t||void 0,tabIndex:t?0:void 0,className:r,...i})}),f=(0,t.forwardRef)(function({align:e=`start`,width:t=`auto`,className:r,...i},a){return(0,n.jsx)(`th`,{ref:a,scope:`col`,"data-align":e,"data-width":t,className:r,...i})}),p=(0,t.forwardRef)(function({align:e=`start`,width:t=`auto`,emphasis:r=`default`,className:i,...a},o){return(0,n.jsx)(`td`,{ref:o,"data-align":e,"data-width":t,"data-emphasis":r==="default"?void 0:r,className:i,...a})}),m=(0,t.forwardRef)(function({icon:t=`info`,title:i=`No data found.`,description:a,action:o,className:s,...c},l){return(0,n.jsxs)(`div`,{ref:l,className:r(`ds-table-empty`,s),...c,children:[(0,n.jsx)(e.t,{name:t,size:24}),(0,n.jsx)(`span`,{style:{color:`var(--color-text)`,fontWeight:`var(--font-weight-bold)`},children:i}),a&&(0,n.jsx)(`span`,{children:a}),o]})});exports.Table=c,exports.TableBody=u,exports.TableCell=p,exports.TableEmpty=m,exports.TableFrame=i,exports.TableHead=l,exports.TableHeaderCell=f,exports.TableRow=d,exports.TableToolbar=a;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["forwardRef","Children","isValidElement","Fragment","createContext","useContext","Icon","require_Icon","react","react_jsx_runtime","cx","parts","TableFrame","rest","className","TableToolbar","start","end","hasBodyContent","children","child","TableContext","Table","TableHead","TableBody","isEmpty","TableRow","TableCell","TableEmpty","emptyMessage","isSelected","isInteractive","TableHeaderCell","align","width","emphasis","icon","title","description","action"],"sources":["../../../src/components/Table/index.tsx"],"sourcesContent":["import {\n Children,\n Fragment,\n createContext,\n forwardRef,\n isValidElement,\n useContext,\n type HTMLAttributes,\n type ReactNode,\n type TableHTMLAttributes,\n type TdHTMLAttributes,\n type ThHTMLAttributes,\n} from \"react\";\nimport { Icon } from \"../Icon\";\nimport type { IconName } from \"../Icon/icons\";\nimport \"./style.css\";\n\nfunction cx(...parts: (string | undefined | false)[]) {\n return parts.filter(Boolean).join(\" \");\n}\n\nexport interface TableFrameProps extends HTMLAttributes<HTMLDivElement> {\n children?: ReactNode;\n}\n\n/** The 3px collection frame every table, list and board sits inside. */\nexport const TableFrame = forwardRef<HTMLDivElement, TableFrameProps>(function TableFrame(\n { className, children, ...rest },\n ref,\n) {\n return (\n <div\n ref={ref}\n className={cx(\"ds-table-frame\", className)}\n {...rest}\n >\n {children}\n </div>\n );\n});\n\nexport interface TableToolbarProps extends HTMLAttributes<HTMLDivElement> {\n /** Left side — usually a select-all checkbox, a title and a count badge. */\n start?: ReactNode;\n /** Right side — filters and the one primary action. */\n end?: ReactNode;\n}\n\n/** The band above the rules: selection, title, count, filters, primary action. */\nexport const TableToolbar = forwardRef<HTMLDivElement, TableToolbarProps>(function TableToolbar(\n { start, end, className, ...rest },\n ref,\n) {\n return (\n <div\n ref={ref}\n className={cx(\"ds-table-toolbar\", className)}\n {...rest}\n >\n <div className=\"ds-table-toolbar__group\">{start}</div>\n <div className=\"ds-table-toolbar__group\">{end}</div>\n </div>\n );\n});\n\nexport interface TableProps extends TableHTMLAttributes<HTMLTableElement> {\n /** Message shown when a body has no rows. */\n emptyMessage?: string;\n /** Override empty-child detection when rows are rendered by custom components. */\n isEmpty?: boolean;\n children?: ReactNode;\n}\n\nfunction hasBodyContent(children: ReactNode): boolean {\n return Children.toArray(children).some(\n (child) =>\n isValidElement<{ children?: ReactNode }>(child) &&\n (child.type !== Fragment || hasBodyContent(child.props.children)),\n );\n}\n\nconst TableContext = createContext<{\n emptyMessage: string;\n isEmpty?: boolean;\n}>({ emptyMessage: \"No data found.\" });\n\n/** The rules layer. Always render it inside a `TableFrame`. */\nexport const Table = forwardRef<HTMLTableElement, TableProps>(function Table(\n { emptyMessage = \"No data found.\", isEmpty, className, children, ...rest },\n ref,\n) {\n return (\n <TableContext.Provider value={{ emptyMessage, isEmpty }}>\n <div className=\"ds-table-frame__scroll\">\n <table\n {...rest}\n ref={ref}\n className={cx(\"ds-table\", className)}\n >\n {children}\n </table>\n </div>\n </TableContext.Provider>\n );\n});\n\nexport const TableHead = forwardRef<\n HTMLTableSectionElement,\n HTMLAttributes<HTMLTableSectionElement>\n>(function TableHead({ className, ...rest }, ref) {\n return (\n <thead\n ref={ref}\n className={className}\n {...rest}\n />\n );\n});\n\nexport const TableBody = forwardRef<\n HTMLTableSectionElement,\n HTMLAttributes<HTMLTableSectionElement>\n>(function TableBody({ className, children, ...rest }, ref) {\n const { emptyMessage, isEmpty } = useContext(TableContext);\n return (\n <tbody\n ref={ref}\n className={className}\n {...rest}\n >\n {(isEmpty ?? !hasBodyContent(children)) ? (\n <TableRow>\n {/* HTML's maximum span covers the row without inspecting columns. */}\n <TableCell\n colSpan={1000}\n className=\"ds-table__empty-cell\"\n >\n <TableEmpty\n title={emptyMessage}\n role=\"status\"\n />\n </TableCell>\n </TableRow>\n ) : (\n children\n )}\n </tbody>\n );\n});\n\nexport interface TableRowProps extends HTMLAttributes<HTMLTableRowElement> {\n /** Paints the soft fill and the solid rail. Never changes the row's size. */\n isSelected?: boolean;\n /** Marks the row clickable: hover fill plus a pointer cursor. */\n isInteractive?: boolean;\n}\n\nexport const TableRow = forwardRef<HTMLTableRowElement, TableRowProps>(function TableRow(\n { isSelected = false, isInteractive = false, className, ...rest },\n ref,\n) {\n return (\n <tr\n ref={ref}\n data-selected={isSelected || undefined}\n data-interactive={isInteractive || undefined}\n tabIndex={isInteractive ? 0 : undefined}\n className={className}\n {...rest}\n />\n );\n});\n\nexport type TableAlign = \"start\" | \"end\";\nexport type TableCellWidth = \"auto\" | \"control\";\n\nexport interface TableHeaderCellProps extends Omit<\n ThHTMLAttributes<HTMLTableCellElement>,\n \"align\"\n> {\n align?: TableAlign;\n width?: TableCellWidth;\n}\n\nexport const TableHeaderCell = forwardRef<HTMLTableCellElement, TableHeaderCellProps>(\n function TableHeaderCell({ align = \"start\", width = \"auto\", className, ...rest }, ref) {\n return (\n <th\n ref={ref}\n scope=\"col\"\n data-align={align}\n data-width={width}\n className={className}\n {...rest}\n />\n );\n },\n);\n\nexport type TableCellEmphasis = \"default\" | \"primary\" | \"muted\";\n\nexport interface TableCellProps extends Omit<TdHTMLAttributes<HTMLTableCellElement>, \"align\"> {\n align?: TableAlign;\n width?: TableCellWidth;\n /** `primary` is the row's identity cell — one per row, never two. */\n emphasis?: TableCellEmphasis;\n}\n\nexport const TableCell = forwardRef<HTMLTableCellElement, TableCellProps>(function TableCell(\n { align = \"start\", width = \"auto\", emphasis = \"default\", className, ...rest },\n ref,\n) {\n return (\n <td\n ref={ref}\n data-align={align}\n data-width={width}\n data-emphasis={emphasis === \"default\" ? undefined : emphasis}\n className={className}\n {...rest}\n />\n );\n});\n\nexport interface TableEmptyProps extends HTMLAttributes<HTMLDivElement> {\n icon?: IconName;\n title?: string;\n description?: string;\n /** One action at most — the thing that ends the empty state. */\n action?: ReactNode;\n}\n\n/** What the frame shows when the collection has no rows. */\nexport const TableEmpty = forwardRef<HTMLDivElement, TableEmptyProps>(function TableEmpty(\n { icon = \"info\", title = \"No data found.\", description, action, className, ...rest },\n ref,\n) {\n return (\n <div\n ref={ref}\n className={cx(\"ds-table-empty\", className)}\n {...rest}\n >\n <Icon\n name={icon}\n size={24}\n />\n <span style={{ color: \"var(--color-text)\", fontWeight: \"var(--font-weight-bold)\" }}>\n {title}\n </span>\n {description && <span>{description}</span>}\n {action}\n </div>\n );\n});\n"],"mappings":"A,2KAiBA,SAASU,EAAG,GAAGC,EAAuC,CACpD,OAAOA,EAAM,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG,CACvC,CAOA,IAAaC,GAAA,EAAaZ,EAAAA,WAAAA,CAA4C,SACpE,CAAE,YAAW,WAAU,GAAGa,GAC1B,EACA,CACA,OACE,EAAAJ,EAAA,IAAA,CAAC,MAAD,CACO,MACL,UAAWC,EAAG,iBAAkBI,CAAS,EACzC,GAAID,EAEH,UACE,CAAA,CAET,CAAC,EAUYE,GAAA,EAAef,EAAAA,WAAAA,CAA8C,SACxE,CAAE,QAAO,MAAK,YAAW,GAAGa,GAC5B,EACA,CACA,OACE,EAAAJ,EAAA,KAAA,CAAC,MAAD,CACO,MACL,UAAWC,EAAG,mBAAoBI,CAAS,EAC3C,GAAID,EAHN,SAAA,EAKE,EAAAJ,EAAA,IAAA,CAAC,MAAD,CAAK,UAAU,0BAA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GAAID,EAHN,SAAA,EAKE,EAAAJ,EAAA,IAAA,CAACH,EAAAA,EAAD,CACE,KAAM8B,EACN,KAAM,EACP,CAAA,GACD,EAAA3B,EAAA,IAAA,CAAC,OAAD,CAAM,MAAO,CAAE,MAAO,oBAAqB,WAAY,yBAA0B,EAC9E,SAAA4B,CACG,CAAA,EACLC,IAAe,EAAA7B,EAAA,IAAA,CAAC,OAAD,CAAA,SAAO6B,CAAkB,CAAA,EACxCC,CACE,C,EAET,CAAC,E"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["forwardRef","Children","isValidElement","Fragment","createContext","useContext","Icon","require_Icon","react","react_jsx_runtime","cx","parts","TableFrame","rest","className","TableToolbar","start","end","hasBodyContent","children","child","TableContext","Table","TableHead","TableBody","isEmpty","TableRow","TableCell","TableEmpty","emptyMessage","isSelected","isInteractive","TableHeaderCell","align","width","emphasis","icon","title","description","action"],"sources":["../../../src/components/Table/index.tsx"],"sourcesContent":["import {\n Children,\n Fragment,\n createContext,\n forwardRef,\n isValidElement,\n useContext,\n type HTMLAttributes,\n type ReactNode,\n type TableHTMLAttributes,\n type TdHTMLAttributes,\n type ThHTMLAttributes,\n} from \"react\";\nimport { Icon } from \"../Icon\";\nimport type { IconName } from \"../Icon/icons\";\nimport \"./style.css\";\n\nfunction cx(...parts: (string | undefined | false)[]) {\n return parts.filter(Boolean).join(\" \");\n}\n\nexport interface TableFrameProps extends HTMLAttributes<HTMLDivElement> {\n children?: ReactNode;\n}\n\n/** The 3px collection frame every table, list and board sits inside. */\nexport const TableFrame = forwardRef<HTMLDivElement, TableFrameProps>(function TableFrame(\n { className, children, ...rest },\n ref,\n) {\n return (\n <div\n ref={ref}\n className={cx(\"ds-table-frame\", \"ds-field-surface\", className)}\n {...rest}\n >\n {children}\n </div>\n );\n});\n\nexport interface TableToolbarProps extends HTMLAttributes<HTMLDivElement> {\n /** Left side — usually a select-all checkbox, a title and a count badge. */\n start?: ReactNode;\n /** Right side — filters and the one primary action. */\n end?: ReactNode;\n}\n\n/** The band above the rules: selection, title, count, filters, primary action. */\nexport const TableToolbar = forwardRef<HTMLDivElement, TableToolbarProps>(function TableToolbar(\n { start, end, className, ...rest },\n ref,\n) {\n return (\n <div\n ref={ref}\n className={cx(\"ds-table-toolbar\", className)}\n {...rest}\n >\n <div className=\"ds-table-toolbar__group\">{start}</div>\n <div className=\"ds-table-toolbar__group\">{end}</div>\n </div>\n );\n});\n\nexport interface TableProps extends TableHTMLAttributes<HTMLTableElement> {\n /** Message shown when a body has no rows. */\n emptyMessage?: string;\n /** Override empty-child detection when rows are rendered by custom components. */\n isEmpty?: boolean;\n children?: ReactNode;\n}\n\nfunction hasBodyContent(children: ReactNode): boolean {\n return Children.toArray(children).some(\n (child) =>\n isValidElement<{ children?: ReactNode }>(child) &&\n (child.type !== Fragment || hasBodyContent(child.props.children)),\n );\n}\n\nconst TableContext = createContext<{\n emptyMessage: string;\n isEmpty?: boolean;\n}>({ emptyMessage: \"No data found.\" });\n\n/** The rules layer. Always render it inside a `TableFrame`. */\nexport const Table = forwardRef<HTMLTableElement, TableProps>(function Table(\n { emptyMessage = \"No data found.\", isEmpty, className, children, ...rest },\n ref,\n) {\n return (\n <TableContext.Provider value={{ emptyMessage, isEmpty }}>\n <div className=\"ds-table-frame__scroll\">\n <table\n {...rest}\n ref={ref}\n className={cx(\"ds-table\", className)}\n >\n {children}\n </table>\n </div>\n </TableContext.Provider>\n );\n});\n\nexport const TableHead = forwardRef<\n HTMLTableSectionElement,\n HTMLAttributes<HTMLTableSectionElement>\n>(function TableHead({ className, ...rest }, ref) {\n return (\n <thead\n ref={ref}\n className={className}\n {...rest}\n />\n );\n});\n\nexport const TableBody = forwardRef<\n HTMLTableSectionElement,\n HTMLAttributes<HTMLTableSectionElement>\n>(function TableBody({ className, children, ...rest }, ref) {\n const { emptyMessage, isEmpty } = useContext(TableContext);\n return (\n <tbody\n ref={ref}\n className={className}\n {...rest}\n >\n {(isEmpty ?? !hasBodyContent(children)) ? (\n <TableRow>\n {/* HTML's maximum span covers the row without inspecting columns. */}\n <TableCell\n colSpan={1000}\n className=\"ds-table__empty-cell\"\n >\n <TableEmpty\n title={emptyMessage}\n role=\"status\"\n />\n </TableCell>\n </TableRow>\n ) : (\n children\n )}\n </tbody>\n );\n});\n\nexport interface TableRowProps extends HTMLAttributes<HTMLTableRowElement> {\n /** Paints the soft fill and the solid rail. Never changes the row's size. */\n isSelected?: boolean;\n /** Marks the row clickable: hover fill plus a pointer cursor. */\n isInteractive?: boolean;\n}\n\nexport const TableRow = forwardRef<HTMLTableRowElement, TableRowProps>(function TableRow(\n { isSelected = false, isInteractive = false, className, ...rest },\n ref,\n) {\n return (\n <tr\n ref={ref}\n data-selected={isSelected || undefined}\n data-interactive={isInteractive || undefined}\n tabIndex={isInteractive ? 0 : undefined}\n className={className}\n {...rest}\n />\n );\n});\n\nexport type TableAlign = \"start\" | \"end\";\nexport type TableCellWidth = \"auto\" | \"control\";\n\nexport interface TableHeaderCellProps extends Omit<\n ThHTMLAttributes<HTMLTableCellElement>,\n \"align\"\n> {\n align?: TableAlign;\n width?: TableCellWidth;\n}\n\nexport const TableHeaderCell = forwardRef<HTMLTableCellElement, TableHeaderCellProps>(\n function TableHeaderCell({ align = \"start\", width = \"auto\", className, ...rest }, ref) {\n return (\n <th\n ref={ref}\n scope=\"col\"\n data-align={align}\n data-width={width}\n className={className}\n {...rest}\n />\n );\n },\n);\n\nexport type TableCellEmphasis = \"default\" | \"primary\" | \"muted\";\n\nexport interface TableCellProps extends Omit<TdHTMLAttributes<HTMLTableCellElement>, \"align\"> {\n align?: TableAlign;\n width?: TableCellWidth;\n /** `primary` is the row's identity cell — one per row, never two. */\n emphasis?: TableCellEmphasis;\n}\n\nexport const TableCell = forwardRef<HTMLTableCellElement, TableCellProps>(function TableCell(\n { align = \"start\", width = \"auto\", emphasis = \"default\", className, ...rest },\n ref,\n) {\n return (\n <td\n ref={ref}\n data-align={align}\n data-width={width}\n data-emphasis={emphasis === \"default\" ? undefined : emphasis}\n className={className}\n {...rest}\n />\n );\n});\n\nexport interface TableEmptyProps extends HTMLAttributes<HTMLDivElement> {\n icon?: IconName;\n title?: string;\n description?: string;\n /** One action at most — the thing that ends the empty state. */\n action?: ReactNode;\n}\n\n/** What the frame shows when the collection has no rows. */\nexport const TableEmpty = forwardRef<HTMLDivElement, TableEmptyProps>(function TableEmpty(\n { icon = \"info\", title = \"No data found.\", description, action, className, ...rest },\n ref,\n) {\n return (\n <div\n ref={ref}\n className={cx(\"ds-table-empty\", className)}\n {...rest}\n >\n <Icon\n name={icon}\n size={24}\n />\n <span style={{ color: \"var(--color-text)\", fontWeight: \"var(--font-weight-bold)\" }}>\n {title}\n </span>\n {description && <span>{description}</span>}\n {action}\n </div>\n );\n});\n"],"mappings":"A,2KAiBA,SAASU,EAAG,GAAGC,EAAuC,CACpD,OAAOA,EAAM,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG,CACvC,CAOA,IAAaC,GAAA,EAAaZ,EAAAA,WAAAA,CAA4C,SACpE,CAAE,YAAW,WAAU,GAAGa,GAC1B,EACA,CACA,OACE,EAAAJ,EAAA,IAAA,CAAC,MAAD,CACO,MACL,UAAWC,EAAG,iBAAkB,mBAAoBI,CAAS,EAC7D,GAAID,EAEH,UACE,CAAA,CAET,CAAC,EAUYE,GAAA,EAAef,EAAAA,WAAAA,CAA8C,SACxE,CAAE,QAAO,MAAK,YAAW,GAAGa,GAC5B,EACA,CACA,OACE,EAAAJ,EAAA,KAAA,CAAC,MAAD,CACO,MACL,UAAWC,EAAG,mBAAoBI,CAAS,EAC3C,GAAID,EAHN,SAAA,EAKE,EAAAJ,EAAA,IAAA,CAAC,MAAD,CAAK,UAAU,0BAA2B,SAAAO,CAAW,CAAA,GACrD,EAAAP,EAAA,IAAA,CAAC,MAAD,CAAK,UAAU,0BAA2B,SAAAQ,CAAS,CAAA,CAChD,C,EAET,CAAC,EAUD,SAASC,EAAe,EAA8B,CACpD,OAAOjB,EAAAA,SAAS,QAAQkB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B,EAC9E,SAAA4B,CACG,CAAA,EACLC,IAAe,EAAA7B,EAAA,IAAA,CAAC,OAAD,CAAA,SAAO6B,CAAkB,CAAA,EACxCC,CACE,C,EAET,CAAC,E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["Icon","cx","parts","TableFrame","forwardRef","rest","className","TableToolbar","start","end","hasBodyContent","Children","children","isValidElement","child","Fragment","TableContext","createContext","Table","TableHead","TableBody","useContext","isEmpty","TableRow","TableCell","TableEmpty","emptyMessage","isSelected","isInteractive","TableHeaderCell","align","width","emphasis","icon","title","description","action"],"sources":["../../../src/components/Table/index.tsx"],"sourcesContent":["import {\n Children,\n Fragment,\n createContext,\n forwardRef,\n isValidElement,\n useContext,\n type HTMLAttributes,\n type ReactNode,\n type TableHTMLAttributes,\n type TdHTMLAttributes,\n type ThHTMLAttributes,\n} from \"react\";\nimport { Icon } from \"../Icon\";\nimport type { IconName } from \"../Icon/icons\";\nimport \"./style.css\";\n\nfunction cx(...parts: (string | undefined | false)[]) {\n return parts.filter(Boolean).join(\" \");\n}\n\nexport interface TableFrameProps extends HTMLAttributes<HTMLDivElement> {\n children?: ReactNode;\n}\n\n/** The 3px collection frame every table, list and board sits inside. */\nexport const TableFrame = forwardRef<HTMLDivElement, TableFrameProps>(function TableFrame(\n { className, children, ...rest },\n ref,\n) {\n return (\n <div\n ref={ref}\n className={cx(\"ds-table-frame\", className)}\n {...rest}\n >\n {children}\n </div>\n );\n});\n\nexport interface TableToolbarProps extends HTMLAttributes<HTMLDivElement> {\n /** Left side — usually a select-all checkbox, a title and a count badge. */\n start?: ReactNode;\n /** Right side — filters and the one primary action. */\n end?: ReactNode;\n}\n\n/** The band above the rules: selection, title, count, filters, primary action. */\nexport const TableToolbar = forwardRef<HTMLDivElement, TableToolbarProps>(function TableToolbar(\n { start, end, className, ...rest },\n ref,\n) {\n return (\n <div\n ref={ref}\n className={cx(\"ds-table-toolbar\", className)}\n {...rest}\n >\n <div className=\"ds-table-toolbar__group\">{start}</div>\n <div className=\"ds-table-toolbar__group\">{end}</div>\n </div>\n );\n});\n\nexport interface TableProps extends TableHTMLAttributes<HTMLTableElement> {\n /** Message shown when a body has no rows. */\n emptyMessage?: string;\n /** Override empty-child detection when rows are rendered by custom components. */\n isEmpty?: boolean;\n children?: ReactNode;\n}\n\nfunction hasBodyContent(children: ReactNode): boolean {\n return Children.toArray(children).some(\n (child) =>\n isValidElement<{ children?: ReactNode }>(child) &&\n (child.type !== Fragment || hasBodyContent(child.props.children)),\n );\n}\n\nconst TableContext = createContext<{\n emptyMessage: string;\n isEmpty?: boolean;\n}>({ emptyMessage: \"No data found.\" });\n\n/** The rules layer. Always render it inside a `TableFrame`. */\nexport const Table = forwardRef<HTMLTableElement, TableProps>(function Table(\n { emptyMessage = \"No data found.\", isEmpty, className, children, ...rest },\n ref,\n) {\n return (\n <TableContext.Provider value={{ emptyMessage, isEmpty }}>\n <div className=\"ds-table-frame__scroll\">\n <table\n {...rest}\n ref={ref}\n className={cx(\"ds-table\", className)}\n >\n {children}\n </table>\n </div>\n </TableContext.Provider>\n );\n});\n\nexport const TableHead = forwardRef<\n HTMLTableSectionElement,\n HTMLAttributes<HTMLTableSectionElement>\n>(function TableHead({ className, ...rest }, ref) {\n return (\n <thead\n ref={ref}\n className={className}\n {...rest}\n />\n );\n});\n\nexport const TableBody = forwardRef<\n HTMLTableSectionElement,\n HTMLAttributes<HTMLTableSectionElement>\n>(function TableBody({ className, children, ...rest }, ref) {\n const { emptyMessage, isEmpty } = useContext(TableContext);\n return (\n <tbody\n ref={ref}\n className={className}\n {...rest}\n >\n {(isEmpty ?? !hasBodyContent(children)) ? (\n <TableRow>\n {/* HTML's maximum span covers the row without inspecting columns. */}\n <TableCell\n colSpan={1000}\n className=\"ds-table__empty-cell\"\n >\n <TableEmpty\n title={emptyMessage}\n role=\"status\"\n />\n </TableCell>\n </TableRow>\n ) : (\n children\n )}\n </tbody>\n );\n});\n\nexport interface TableRowProps extends HTMLAttributes<HTMLTableRowElement> {\n /** Paints the soft fill and the solid rail. Never changes the row's size. */\n isSelected?: boolean;\n /** Marks the row clickable: hover fill plus a pointer cursor. */\n isInteractive?: boolean;\n}\n\nexport const TableRow = forwardRef<HTMLTableRowElement, TableRowProps>(function TableRow(\n { isSelected = false, isInteractive = false, className, ...rest },\n ref,\n) {\n return (\n <tr\n ref={ref}\n data-selected={isSelected || undefined}\n data-interactive={isInteractive || undefined}\n tabIndex={isInteractive ? 0 : undefined}\n className={className}\n {...rest}\n />\n );\n});\n\nexport type TableAlign = \"start\" | \"end\";\nexport type TableCellWidth = \"auto\" | \"control\";\n\nexport interface TableHeaderCellProps extends Omit<\n ThHTMLAttributes<HTMLTableCellElement>,\n \"align\"\n> {\n align?: TableAlign;\n width?: TableCellWidth;\n}\n\nexport const TableHeaderCell = forwardRef<HTMLTableCellElement, TableHeaderCellProps>(\n function TableHeaderCell({ align = \"start\", width = \"auto\", className, ...rest }, ref) {\n return (\n <th\n ref={ref}\n scope=\"col\"\n data-align={align}\n data-width={width}\n className={className}\n {...rest}\n />\n );\n },\n);\n\nexport type TableCellEmphasis = \"default\" | \"primary\" | \"muted\";\n\nexport interface TableCellProps extends Omit<TdHTMLAttributes<HTMLTableCellElement>, \"align\"> {\n align?: TableAlign;\n width?: TableCellWidth;\n /** `primary` is the row's identity cell — one per row, never two. */\n emphasis?: TableCellEmphasis;\n}\n\nexport const TableCell = forwardRef<HTMLTableCellElement, TableCellProps>(function TableCell(\n { align = \"start\", width = \"auto\", emphasis = \"default\", className, ...rest },\n ref,\n) {\n return (\n <td\n ref={ref}\n data-align={align}\n data-width={width}\n data-emphasis={emphasis === \"default\" ? undefined : emphasis}\n className={className}\n {...rest}\n />\n );\n});\n\nexport interface TableEmptyProps extends HTMLAttributes<HTMLDivElement> {\n icon?: IconName;\n title?: string;\n description?: string;\n /** One action at most — the thing that ends the empty state. */\n action?: ReactNode;\n}\n\n/** What the frame shows when the collection has no rows. */\nexport const TableEmpty = forwardRef<HTMLDivElement, TableEmptyProps>(function TableEmpty(\n { icon = \"info\", title = \"No data found.\", description, action, className, ...rest },\n ref,\n) {\n return (\n <div\n ref={ref}\n className={cx(\"ds-table-empty\", className)}\n {...rest}\n >\n <Icon\n name={icon}\n size={24}\n />\n <span style={{ color: \"var(--color-text)\", fontWeight: \"var(--font-weight-bold)\" }}>\n {title}\n </span>\n {description && <span>{description}</span>}\n {action}\n </div>\n );\n});\n"],"mappings":";;;;AAiBA,SAASC,EAAG,GAAGC,GAAuC;CACpD,OAAOA,EAAM,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG;AACvC;AAOA,IAAaC,IAAaC,EAA4C,SACpE,EAAE,cAAW,aAAU,GAAGC,KAC1B,GACA;CACA,OACE,kBAAC,OAAD;EACO;EACL,WAAWJ,EAAG,
|
|
1
|
+
{"version":3,"file":"index.js","names":["Icon","cx","parts","TableFrame","forwardRef","rest","className","TableToolbar","start","end","hasBodyContent","Children","children","isValidElement","child","Fragment","TableContext","createContext","Table","TableHead","TableBody","useContext","isEmpty","TableRow","TableCell","TableEmpty","emptyMessage","isSelected","isInteractive","TableHeaderCell","align","width","emphasis","icon","title","description","action"],"sources":["../../../src/components/Table/index.tsx"],"sourcesContent":["import {\n Children,\n Fragment,\n createContext,\n forwardRef,\n isValidElement,\n useContext,\n type HTMLAttributes,\n type ReactNode,\n type TableHTMLAttributes,\n type TdHTMLAttributes,\n type ThHTMLAttributes,\n} from \"react\";\nimport { Icon } from \"../Icon\";\nimport type { IconName } from \"../Icon/icons\";\nimport \"./style.css\";\n\nfunction cx(...parts: (string | undefined | false)[]) {\n return parts.filter(Boolean).join(\" \");\n}\n\nexport interface TableFrameProps extends HTMLAttributes<HTMLDivElement> {\n children?: ReactNode;\n}\n\n/** The 3px collection frame every table, list and board sits inside. */\nexport const TableFrame = forwardRef<HTMLDivElement, TableFrameProps>(function TableFrame(\n { className, children, ...rest },\n ref,\n) {\n return (\n <div\n ref={ref}\n className={cx(\"ds-table-frame\", \"ds-field-surface\", className)}\n {...rest}\n >\n {children}\n </div>\n );\n});\n\nexport interface TableToolbarProps extends HTMLAttributes<HTMLDivElement> {\n /** Left side — usually a select-all checkbox, a title and a count badge. */\n start?: ReactNode;\n /** Right side — filters and the one primary action. */\n end?: ReactNode;\n}\n\n/** The band above the rules: selection, title, count, filters, primary action. */\nexport const TableToolbar = forwardRef<HTMLDivElement, TableToolbarProps>(function TableToolbar(\n { start, end, className, ...rest },\n ref,\n) {\n return (\n <div\n ref={ref}\n className={cx(\"ds-table-toolbar\", className)}\n {...rest}\n >\n <div className=\"ds-table-toolbar__group\">{start}</div>\n <div className=\"ds-table-toolbar__group\">{end}</div>\n </div>\n );\n});\n\nexport interface TableProps extends TableHTMLAttributes<HTMLTableElement> {\n /** Message shown when a body has no rows. */\n emptyMessage?: string;\n /** Override empty-child detection when rows are rendered by custom components. */\n isEmpty?: boolean;\n children?: ReactNode;\n}\n\nfunction hasBodyContent(children: ReactNode): boolean {\n return Children.toArray(children).some(\n (child) =>\n isValidElement<{ children?: ReactNode }>(child) &&\n (child.type !== Fragment || hasBodyContent(child.props.children)),\n );\n}\n\nconst TableContext = createContext<{\n emptyMessage: string;\n isEmpty?: boolean;\n}>({ emptyMessage: \"No data found.\" });\n\n/** The rules layer. Always render it inside a `TableFrame`. */\nexport const Table = forwardRef<HTMLTableElement, TableProps>(function Table(\n { emptyMessage = \"No data found.\", isEmpty, className, children, ...rest },\n ref,\n) {\n return (\n <TableContext.Provider value={{ emptyMessage, isEmpty }}>\n <div className=\"ds-table-frame__scroll\">\n <table\n {...rest}\n ref={ref}\n className={cx(\"ds-table\", className)}\n >\n {children}\n </table>\n </div>\n </TableContext.Provider>\n );\n});\n\nexport const TableHead = forwardRef<\n HTMLTableSectionElement,\n HTMLAttributes<HTMLTableSectionElement>\n>(function TableHead({ className, ...rest }, ref) {\n return (\n <thead\n ref={ref}\n className={className}\n {...rest}\n />\n );\n});\n\nexport const TableBody = forwardRef<\n HTMLTableSectionElement,\n HTMLAttributes<HTMLTableSectionElement>\n>(function TableBody({ className, children, ...rest }, ref) {\n const { emptyMessage, isEmpty } = useContext(TableContext);\n return (\n <tbody\n ref={ref}\n className={className}\n {...rest}\n >\n {(isEmpty ?? !hasBodyContent(children)) ? (\n <TableRow>\n {/* HTML's maximum span covers the row without inspecting columns. */}\n <TableCell\n colSpan={1000}\n className=\"ds-table__empty-cell\"\n >\n <TableEmpty\n title={emptyMessage}\n role=\"status\"\n />\n </TableCell>\n </TableRow>\n ) : (\n children\n )}\n </tbody>\n );\n});\n\nexport interface TableRowProps extends HTMLAttributes<HTMLTableRowElement> {\n /** Paints the soft fill and the solid rail. Never changes the row's size. */\n isSelected?: boolean;\n /** Marks the row clickable: hover fill plus a pointer cursor. */\n isInteractive?: boolean;\n}\n\nexport const TableRow = forwardRef<HTMLTableRowElement, TableRowProps>(function TableRow(\n { isSelected = false, isInteractive = false, className, ...rest },\n ref,\n) {\n return (\n <tr\n ref={ref}\n data-selected={isSelected || undefined}\n data-interactive={isInteractive || undefined}\n tabIndex={isInteractive ? 0 : undefined}\n className={className}\n {...rest}\n />\n );\n});\n\nexport type TableAlign = \"start\" | \"end\";\nexport type TableCellWidth = \"auto\" | \"control\";\n\nexport interface TableHeaderCellProps extends Omit<\n ThHTMLAttributes<HTMLTableCellElement>,\n \"align\"\n> {\n align?: TableAlign;\n width?: TableCellWidth;\n}\n\nexport const TableHeaderCell = forwardRef<HTMLTableCellElement, TableHeaderCellProps>(\n function TableHeaderCell({ align = \"start\", width = \"auto\", className, ...rest }, ref) {\n return (\n <th\n ref={ref}\n scope=\"col\"\n data-align={align}\n data-width={width}\n className={className}\n {...rest}\n />\n );\n },\n);\n\nexport type TableCellEmphasis = \"default\" | \"primary\" | \"muted\";\n\nexport interface TableCellProps extends Omit<TdHTMLAttributes<HTMLTableCellElement>, \"align\"> {\n align?: TableAlign;\n width?: TableCellWidth;\n /** `primary` is the row's identity cell — one per row, never two. */\n emphasis?: TableCellEmphasis;\n}\n\nexport const TableCell = forwardRef<HTMLTableCellElement, TableCellProps>(function TableCell(\n { align = \"start\", width = \"auto\", emphasis = \"default\", className, ...rest },\n ref,\n) {\n return (\n <td\n ref={ref}\n data-align={align}\n data-width={width}\n data-emphasis={emphasis === \"default\" ? undefined : emphasis}\n className={className}\n {...rest}\n />\n );\n});\n\nexport interface TableEmptyProps extends HTMLAttributes<HTMLDivElement> {\n icon?: IconName;\n title?: string;\n description?: string;\n /** One action at most — the thing that ends the empty state. */\n action?: ReactNode;\n}\n\n/** What the frame shows when the collection has no rows. */\nexport const TableEmpty = forwardRef<HTMLDivElement, TableEmptyProps>(function TableEmpty(\n { icon = \"info\", title = \"No data found.\", description, action, className, ...rest },\n ref,\n) {\n return (\n <div\n ref={ref}\n className={cx(\"ds-table-empty\", className)}\n {...rest}\n >\n <Icon\n name={icon}\n size={24}\n />\n <span style={{ color: \"var(--color-text)\", fontWeight: \"var(--font-weight-bold)\" }}>\n {title}\n </span>\n {description && <span>{description}</span>}\n {action}\n </div>\n );\n});\n"],"mappings":";;;;AAiBA,SAASC,EAAG,GAAGC,GAAuC;CACpD,OAAOA,EAAM,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG;AACvC;AAOA,IAAaC,IAAaC,EAA4C,SACpE,EAAE,cAAW,aAAU,GAAGC,KAC1B,GACA;CACA,OACE,kBAAC,OAAD;EACO;EACL,WAAWJ,EAAG,kBAAkB,oBAAoBK,CAAS;EAC7D,GAAID;EAEH;CACE,CAAA;AAET,CAAC,GAUYE,IAAeH,EAA8C,SACxE,EAAE,UAAO,QAAK,cAAW,GAAGC,KAC5B,GACA;CACA,OACE,kBAAC,OAAD;EACO;EACL,WAAWJ,EAAG,oBAAoBK,CAAS;EAC3C,GAAID;EAHN,UAAA,CAKE,kBAAC,OAAD;GAAK,WAAU;GAA2B,UAAAG;EAAW,CAAA,GACrD,kBAAC,OAAD;GAAK,WAAU;GAA2B,UAAAC;EAAS,CAAA,CAChD;;AAET,CAAC;AAUD,SAASC,EA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EACnB;EACX,GAAIvB;CACL,CAAA;AAEL,CAAC,GAaYwB,IAAkBzB,EAC7B,SAAyB,EAAE,WAAQ,SAAS,WAAQ,QAAQ,cAAW,GAAGC,KAAQ,GAAK;CACrF,OACE,kBAAC,MAAD;EACO;EACL,OAAM;EACN,cAAYyB;EACZ,cAAYC;EACD;EACX,GAAI1B;CACL,CAAA;AAEL,CACF,GAWamB,IAAYpB,EAAiD,SACxE,EAAE,WAAQ,SAAS,WAAQ,QAAQ,cAAW,WAAW,cAAW,GAAGC,KACvE,GACA;CACA,OACE,kBAAC,MAAD;EACO;EACL,cAAYyB;EACZ,cAAYC;EACZ,iBAAeC,MAAa,YAAY,KAAA,IAAYA;EACzC;EACX,GAAI3B;CACL,CAAA;AAEL,CAAC,GAWYoB,IAAarB,EAA4C,SACpE,EAAE,UAAO,QAAQ,WAAQ,kBAAkB,gBAAa,WAAQ,cAAW,GAAGC,KAC9E,GACA;CACA,OACE,kBAAC,OAAD;EACO;EACL,WAAWJ,EAAG,kBAAkBK,CAAS;EACzC,GAAID;EAHN,UAAA;GAKE,kBAACL,GAAD;IACE,MAAMiC;IACN,MAAM;GACP,CAAA;GACD,kBAAC,QAAD;IAAM,OAAO;KAAE,OAAO;KAAqB,YAAY;IAA0B;IAC9E,UAAAC;GACG,CAAA;GACLC,KAAe,kBAAC,QAAD,EAAA,UAAOA,EAAkB,CAAA;GACxCC;EACE;;AAET,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../chunks/mergeRefs-Bc3qS0Tt.cjs"),t=require("../../chunks/useTooltip-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../chunks/mergeRefs-Bc3qS0Tt.cjs"),t=require("../../chunks/useTooltip-bTE_a2Xn.cjs");let n=require("react"),r=require("react/jsx-runtime");function i(...e){return e.filter(Boolean).join(` `)}var a=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],o=6e4,s=60*o,c=24*s,l=7*c;function u(e){return String(e).padStart(2,`0`)}function d(e,t={}){let{hasYear:n=!0}=t,r=`${e.getDate()} ${a[e.getMonth()]}`;return n?`${r} ${e.getFullYear()}`:r}function f(e,t={}){let{hasTimeZone:n=!0}=t,r=`${d(e)}, ${u(e.getHours())}:${u(e.getMinutes())}`;if(!n)return r;let i=new Intl.DateTimeFormat(void 0,{timeZoneName:`short`}).formatToParts(e).find(e=>e.type===`timeZoneName`)?.value;return i?`${r} ${i}`:r}function p(e,t=new Date){let n=t.getTime()-e.getTime();if(n<0)return d(e,{hasYear:e.getFullYear()!==t.getFullYear()});if(n<o)return`Just now`;if(n<s)return`${Math.floor(n/o)}m ago`;if(n<c)return`${Math.floor(n/s)}h ago`;if(n<l){let e=Math.floor(n/c);return`${e} ${e===1?`day`:`days`} ago`}return d(e,{hasYear:e.getFullYear()!==t.getFullYear()})}var m=(0,n.forwardRef)(function({value:a,format:o=`auto`,hasTooltip:s=!0,hasTimeZone:c=!0,now:l,refreshInterval:u=3e4,className:m,tabIndex:h,title:g,onMouseEnter:_,onMouseLeave:v,onFocus:y,onBlur:b,"aria-describedby":x,...S},C){let w=a instanceof Date?a:new Date(a),T=!Number.isNaN(w.getTime()),[,E]=(0,n.useState)(0);(0,n.useEffect)(()=>{if(o===`absolute`||l)return;let e=window.setInterval(()=>E(e=>e+1),u);return()=>window.clearInterval(e)},[o,l,u]);let D=T?o===`absolute`?d(w):p(w,l??new Date):``,O=T?f(w,{hasTimeZone:c}):``,k=T&&s&&D!==O,{anchorRef:A,description:j,triggerProps:M,panel:N}=t.t(k&&O,{className:`ds-time-tooltip`}),P=(0,n.useMemo)(()=>e.t(A,C),[A,C]);return T?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(`time`,{ref:P,dateTime:w.toISOString(),suppressHydrationWarning:!0,className:i(`ds-time`,!k&&`ds-time--plain`,m),tabIndex:h??(k?0:void 0),"aria-describedby":[x,j].filter(Boolean).join(` `)||void 0,title:g??(k?void 0:O),...M({onMouseEnter:_,onMouseLeave:v,onFocus:y,onBlur:b}),...S,children:D}),N]}):null});exports.Time=m,exports.formatAbsoluteDate=d,exports.formatAbsoluteTime=f,exports.formatRelativeTime=p;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as e } from "../../chunks/mergeRefs-DGM402mE.js";
|
|
2
|
-
import { t } from "../../chunks/useTooltip-
|
|
2
|
+
import { t } from "../../chunks/useTooltip-C5gvEoYk.js";
|
|
3
3
|
import { forwardRef as n, useEffect as r, useMemo as i, useState as a } from "react";
|
|
4
4
|
import { Fragment as o, jsx as s, jsxs as c } from "react/jsx-runtime";
|
|
5
5
|
//#region src/components/Time/index.tsx
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../chunks/
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../chunks/Message-DU31JAb3.cjs");let t=require("react"),n=require("react/jsx-runtime");var r=(0,t.forwardRef)(function({tone:t=`neutral`,title:r,description:i,onDismiss:a,role:o=`status`,className:s,...c},l){return(0,n.jsx)(e.t,{...c,ref:l,role:o,tone:t,title:r,appearance:`floating`,icon:`auto`,onDismiss:a,classPrefix:`ds-toast`,dismissLabel:`Dismiss notification`,className:[`ds-toast`,s].filter(Boolean).join(` `),children:i})}),i=(0,t.createContext)(null);function a({children:e}){let[r,a]=(0,t.useState)([]),s=(0,t.useRef)(0),c=(0,t.useCallback)(e=>{a(t=>t.filter(t=>t.id!==e))},[]),l=(0,t.useCallback)(e=>{a(t=>[...t,{...e,id:s.current++}])},[]),u=(0,t.useMemo)(()=>({toast:l,dismiss:c}),[l,c]);return(0,n.jsxs)(i.Provider,{value:u,children:[e,(0,n.jsx)(o,{items:r,onDismiss:c})]})}function o({items:e,onDismiss:t}){return e.length===0?null:(0,n.jsx)(`div`,{className:`ds-toast-region`,role:`region`,"aria-label":`Notifications`,children:e.map(e=>(0,n.jsx)(s,{item:e,onDismiss:t},e.id))})}function s({item:e,onDismiss:i}){return(0,t.useEffect)(()=>{let t=window.setTimeout(()=>i(e.id),e.duration??5e3);return()=>window.clearTimeout(t)},[e,i]),(0,n.jsx)(r,{tone:e.tone,title:e.title,description:e.description,onDismiss:()=>i(e.id)})}function c(){let e=(0,t.useContext)(i);if(!e)throw Error(`useToast must be used inside a <ToastProvider>.`);return e}exports.Toast=r,exports.ToastProvider=a,exports.useToast=c;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["forwardRef","
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["forwardRef","Message","createContext","useState","useRef","useCallback","useMemo","useContext","require_Message","react","react_jsx_runtime","Toast","rest","className","description","ToastContext","ToastProvider","items","setItems","nextId","dismiss","current","item","id","toast","options","value","children","ToastRegion","TimedToast","timer","onDismiss","useToast","context"],"sources":["../../../src/components/Toast/index.tsx"],"sourcesContent":["import {\n createContext,\n forwardRef,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n type HTMLAttributes,\n type ReactNode,\n} from \"react\";\nimport { Message } from \"../../internal/Message\";\nimport \"./style.css\";\n\nexport type ToastTone = \"neutral\" | \"info\" | \"success\" | \"warning\" | \"danger\";\n\nexport interface ToastProps extends HTMLAttributes<HTMLDivElement> {\n tone?: ToastTone;\n title: string;\n description?: string;\n /** Renders a dismiss button. Omit for a toast that only times out. */\n onDismiss?: () => void;\n}\n\n/** One fact about something that already happened. Never a question. */\nexport const Toast = forwardRef<HTMLDivElement, ToastProps>(function Toast(\n { tone = \"neutral\", title, description, onDismiss, role = \"status\", className, ...rest },\n ref,\n) {\n return (\n <Message\n {...rest}\n ref={ref}\n role={role}\n tone={tone}\n title={title}\n appearance=\"floating\"\n icon=\"auto\"\n onDismiss={onDismiss}\n classPrefix=\"ds-toast\"\n dismissLabel=\"Dismiss notification\"\n className={[\"ds-toast\", className].filter(Boolean).join(\" \")}\n >\n {description}\n </Message>\n );\n});\n\nexport interface ToastOptions {\n tone?: ToastTone;\n title: string;\n description?: string;\n /** Milliseconds before it dismisses itself. Defaults to `--toast-duration`. */\n duration?: number;\n}\n\ninterface ToastRecord extends ToastOptions {\n id: number;\n}\n\ninterface ToastContextValue {\n toast: (options: ToastOptions) => void;\n dismiss: (id: number) => void;\n}\n\nconst ToastContext = createContext<ToastContextValue | null>(null);\n\nexport interface ToastProviderProps {\n children: ReactNode;\n}\n\n/** Mount once, near the root. Everything below it can call `useToast()`. */\nexport function ToastProvider({ children }: ToastProviderProps) {\n const [items, setItems] = useState<ToastRecord[]>([]);\n const nextId = useRef(0);\n\n const dismiss = useCallback((id: number) => {\n setItems((current) => current.filter((item) => item.id !== id));\n }, []);\n\n const toast = useCallback((options: ToastOptions) => {\n setItems((current) => [...current, { ...options, id: nextId.current++ }]);\n }, []);\n\n const value = useMemo(() => ({ toast, dismiss }), [toast, dismiss]);\n\n return (\n <ToastContext.Provider value={value}>\n {children}\n <ToastRegion\n items={items}\n onDismiss={dismiss}\n />\n </ToastContext.Provider>\n );\n}\n\nfunction ToastRegion({\n items,\n onDismiss,\n}: {\n items: ToastRecord[];\n onDismiss: (id: number) => void;\n}) {\n if (items.length === 0) {\n return null;\n }\n return (\n <div\n className=\"ds-toast-region\"\n role=\"region\"\n aria-label=\"Notifications\"\n >\n {items.map((item) => (\n <TimedToast\n key={item.id}\n item={item}\n onDismiss={onDismiss}\n />\n ))}\n </div>\n );\n}\n\nfunction TimedToast({ item, onDismiss }: { item: ToastRecord; onDismiss: (id: number) => void }) {\n useEffect(() => {\n const timer = window.setTimeout(() => onDismiss(item.id), item.duration ?? 5000);\n return () => window.clearTimeout(timer);\n }, [item, onDismiss]);\n\n return (\n <Toast\n tone={item.tone}\n title={item.title}\n description={item.description}\n onDismiss={() => onDismiss(item.id)}\n />\n );\n}\n\nexport function useToast(): ToastContextValue {\n const context = useContext(ToastContext);\n if (!context) {\n throw new Error(\"useToast must be used inside a <ToastProvider>.\");\n }\n return context;\n}\n"],"mappings":"A,8KA0BA,IAAaW,GAAA,EAAQX,EAAAA,WAAAA,CAAuC,SAC1D,CAAE,OAAO,UAAW,QAAO,cAAa,YAAW,OAAO,SAAU,YAAW,GAAGY,GAClF,EACA,CACA,OACE,EAAAF,EAAA,IAAA,CAACT,EAAAA,EAAD,CACE,GAAIW,EACC,MACC,OACA,OACC,QACP,WAAW,WACX,KAAK,OACM,YACX,YAAY,WACZ,aAAa,uBACb,UAAW,CAAC,WAAYC,CAAS,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG,EAE1D,SAAAC,CACM,CAAA,CAEb,CAAC,EAmBKC,GAAA,EAAeb,EAAAA,cAAAA,CAAwC,IAAI,EAOjE,SAAgBc,EAAc,CAAE,YAAgC,CAC9D,GAAM,CAACC,EAAOC,IAAA,EAAYf,EAAAA,SAAAA,CAAwB,CAAC,CAAC,EAC9CgB,GAAA,EAASf,EAAAA,OAAAA,CAAO,CAAC,EAEjBgB,GAAA,EAAUf,EAAAA,YAAAA,CAAa,GAAe,CAC1Ca,EAAU,GAAYG,EAAQ,OAAQ,GAASC,EAAK,KAAOC,CAAE,CAAC,CAChE,EAAG,CAAC,CAAC,EAECC,GAAA,EAAQnB,EAAAA,YAAAA,CAAa,GAA0B,CACnDa,EAAU,GAAY,CAAC,GAAGG,EAAS,CAAE,GAAGI,EAAS,GAAI,EAAO,SAAU,CAAC,CAAC,CAC1E,EAAG,CAAC,CAAC,EAECC,GAAA,EAAQpB,EAAAA,QAAAA,MAAe,CAAE,QAAO,SAAQ,GAAI,CAACkB,EAAOJ,CAAO,CAAC,EAElE,OACE,EAAAV,EAAA,KAAA,CAACK,EAAa,SAAd,CAA8B,QAA9B,SAAA,CACGY,GACD,EAAAjB,EAAA,IAAA,CAACkB,EAAD,CACS,QACP,UAAWR,CACZ,CAAA,CACoB,C,EAE3B,CAEA,SAASQ,EAAY,CACnB,QACA,aAIC,CAID,OAHIX,EAAM,SAAW,EACZ,MAGP,EAAAP,EAAA,IAAA,CAAC,MAAD,CACE,UAAU,kBACV,KAAK,SACL,aAAW,gBAEV,SAAAO,EAAM,IAAK,IACV,EAAAP,EAAA,IAAA,CAACmB,EAAD,CAEQ,OACK,WACZ,EAHMP,EAAK,EAGX,CACF,CACE,CAAA,CAET,CAEA,SAASO,EAAW,CAAE,OAAM,aAAqE,CAM/F,OALA,EAAApB,EAAA,UAAA,KAAgB,CACd,IAAMqB,EAAQ,OAAO,eAAiBC,EAAUT,EAAK,EAAE,EAAGA,EAAK,UAAY,GAAI,EAC/E,UAAa,OAAO,aAAaQ,CAAK,CACxC,EAAG,CAACR,EAAMS,CAAS,CAAC,GAGlB,EAAArB,EAAA,IAAA,CAACC,EAAD,CACE,KAAMW,EAAK,KACX,MAAOA,EAAK,MACZ,YAAaA,EAAK,YAClB,cAAiBS,EAAUT,EAAK,EAAE,CACnC,CAAA,CAEL,CAEA,SAAgBU,GAA8B,CAC5C,IAAMC,GAAA,EAAU1B,EAAAA,WAAAA,CAAWQ,CAAY,EACvC,GAAI,CAACkB,EACH,MAAU,MAAM,iDAAiD,EAEnE,OAAOA,CACT,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/components/Toast/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EASL,KAAK,cAAc,EACnB,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/components/Toast/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EASL,KAAK,cAAc,EACnB,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAEf,OAAO,aAAa,CAAC;AAErB,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAC;AAE9E,MAAM,WAAW,UAAW,SAAQ,cAAc,CAAC,cAAc,CAAC;IAChE,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sEAAsE;IACtE,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;CACxB;AAED,wEAAwE;AACxE,eAAO,MAAM,KAAK,uGAqBhB,CAAC;AAEH,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAMD,UAAU,iBAAiB;IACzB,KAAK,EAAE,CAAC,OAAO,EAAE,YAAY,KAAK,IAAI,CAAC;IACvC,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;CAC/B;AAID,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,4EAA4E;AAC5E,wBAAgB,aAAa,CAAC,EAAE,QAAQ,EAAE,EAAE,kBAAkB,+BAuB7D;AA6CD,wBAAgB,QAAQ,IAAI,iBAAiB,CAM5C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Toast/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EASL,KAAK,cAAc,EACnB,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Toast/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EASL,KAAK,cAAc,EACnB,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAEf,OAAO,aAAa,CAAC;AAErB,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAC;AAE9E,MAAM,WAAW,UAAW,SAAQ,cAAc,CAAC,cAAc,CAAC;IAChE,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sEAAsE;IACtE,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;CACxB;AAED,wEAAwE;AACxE,eAAO,MAAM,KAAK,uGAqBhB,CAAC;AAEH,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAMD,UAAU,iBAAiB;IACzB,KAAK,EAAE,CAAC,OAAO,EAAE,YAAY,KAAK,IAAI,CAAC;IACvC,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;CAC/B;AAID,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,4EAA4E;AAC5E,wBAAgB,aAAa,CAAC,EAAE,QAAQ,EAAE,EAAE,kBAAkB,+BAuB7D;AA6CD,wBAAgB,QAAQ,IAAI,iBAAiB,CAM5C"}
|
|
@@ -1,96 +1,71 @@
|
|
|
1
|
-
import { t as e } from "../../chunks/
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { jsx as u, jsxs as d } from "react/jsx-runtime";
|
|
1
|
+
import { t as e } from "../../chunks/Message-CaX8Y1Xb.js";
|
|
2
|
+
import { createContext as t, forwardRef as n, useCallback as r, useContext as i, useEffect as a, useMemo as o, useRef as s, useState as c } from "react";
|
|
3
|
+
import { jsx as l, jsxs as u } from "react/jsx-runtime";
|
|
5
4
|
//#region src/components/Toast/index.tsx
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
success: "check",
|
|
10
|
-
warning: "alert-triangle",
|
|
11
|
-
danger: "alert-triangle"
|
|
12
|
-
}, p = r(function({ tone: n = "neutral", title: r, description: i, onDismiss: a, className: o, ...s }, c) {
|
|
13
|
-
return /* @__PURE__ */ d("div", {
|
|
5
|
+
var d = n(function({ tone: t = "neutral", title: n, description: r, onDismiss: i, role: a = "status", className: o, ...s }, c) {
|
|
6
|
+
return /* @__PURE__ */ l(e, {
|
|
7
|
+
...s,
|
|
14
8
|
ref: c,
|
|
15
|
-
role:
|
|
16
|
-
|
|
9
|
+
role: a,
|
|
10
|
+
tone: t,
|
|
11
|
+
title: n,
|
|
12
|
+
appearance: "floating",
|
|
13
|
+
icon: "auto",
|
|
14
|
+
onDismiss: i,
|
|
15
|
+
classPrefix: "ds-toast",
|
|
16
|
+
dismissLabel: "Dismiss notification",
|
|
17
17
|
className: ["ds-toast", o].filter(Boolean).join(" "),
|
|
18
|
-
|
|
19
|
-
children: [
|
|
20
|
-
/* @__PURE__ */ u(e, {
|
|
21
|
-
name: f[n],
|
|
22
|
-
size: 20,
|
|
23
|
-
className: "ds-toast__icon"
|
|
24
|
-
}),
|
|
25
|
-
/* @__PURE__ */ d("div", {
|
|
26
|
-
className: "ds-toast__body",
|
|
27
|
-
children: [/* @__PURE__ */ u("span", {
|
|
28
|
-
className: "ds-toast__title",
|
|
29
|
-
children: r
|
|
30
|
-
}), i && /* @__PURE__ */ u("span", {
|
|
31
|
-
className: "ds-toast__description",
|
|
32
|
-
children: i
|
|
33
|
-
})]
|
|
34
|
-
}),
|
|
35
|
-
a && /* @__PURE__ */ u(t, {
|
|
36
|
-
variant: "simple",
|
|
37
|
-
size: "sm",
|
|
38
|
-
isIconOnly: !0,
|
|
39
|
-
iconStart: "x",
|
|
40
|
-
"aria-label": "Dismiss notification",
|
|
41
|
-
onClick: a
|
|
42
|
-
})
|
|
43
|
-
]
|
|
18
|
+
children: r
|
|
44
19
|
});
|
|
45
|
-
}),
|
|
46
|
-
function
|
|
47
|
-
let [t, n] =
|
|
20
|
+
}), f = t(null);
|
|
21
|
+
function p({ children: e }) {
|
|
22
|
+
let [t, n] = c([]), i = s(0), a = r((e) => {
|
|
48
23
|
n((t) => t.filter((t) => t.id !== e));
|
|
49
|
-
}, []),
|
|
24
|
+
}, []), d = r((e) => {
|
|
50
25
|
n((t) => [...t, {
|
|
51
26
|
...e,
|
|
52
|
-
id:
|
|
27
|
+
id: i.current++
|
|
53
28
|
}]);
|
|
54
|
-
}, []),
|
|
55
|
-
toast:
|
|
29
|
+
}, []), p = o(() => ({
|
|
30
|
+
toast: d,
|
|
56
31
|
dismiss: a
|
|
57
|
-
}), [
|
|
58
|
-
return /* @__PURE__ */
|
|
59
|
-
value:
|
|
60
|
-
children: [e, /* @__PURE__ */
|
|
32
|
+
}), [d, a]);
|
|
33
|
+
return /* @__PURE__ */ u(f.Provider, {
|
|
34
|
+
value: p,
|
|
35
|
+
children: [e, /* @__PURE__ */ l(m, {
|
|
61
36
|
items: t,
|
|
62
37
|
onDismiss: a
|
|
63
38
|
})]
|
|
64
39
|
});
|
|
65
40
|
}
|
|
66
|
-
function
|
|
67
|
-
return e.length === 0 ? null : /* @__PURE__ */
|
|
41
|
+
function m({ items: e, onDismiss: t }) {
|
|
42
|
+
return e.length === 0 ? null : /* @__PURE__ */ l("div", {
|
|
68
43
|
className: "ds-toast-region",
|
|
69
44
|
role: "region",
|
|
70
45
|
"aria-label": "Notifications",
|
|
71
|
-
children: e.map((e) => /* @__PURE__ */
|
|
46
|
+
children: e.map((e) => /* @__PURE__ */ l(h, {
|
|
72
47
|
item: e,
|
|
73
48
|
onDismiss: t
|
|
74
49
|
}, e.id))
|
|
75
50
|
});
|
|
76
51
|
}
|
|
77
|
-
function
|
|
78
|
-
return
|
|
52
|
+
function h({ item: e, onDismiss: t }) {
|
|
53
|
+
return a(() => {
|
|
79
54
|
let n = window.setTimeout(() => t(e.id), e.duration ?? 5e3);
|
|
80
55
|
return () => window.clearTimeout(n);
|
|
81
|
-
}, [e, t]), /* @__PURE__ */
|
|
56
|
+
}, [e, t]), /* @__PURE__ */ l(d, {
|
|
82
57
|
tone: e.tone,
|
|
83
58
|
title: e.title,
|
|
84
59
|
description: e.description,
|
|
85
60
|
onDismiss: () => t(e.id)
|
|
86
61
|
});
|
|
87
62
|
}
|
|
88
|
-
function
|
|
89
|
-
let e =
|
|
63
|
+
function g() {
|
|
64
|
+
let e = i(f);
|
|
90
65
|
if (!e) throw Error("useToast must be used inside a <ToastProvider>.");
|
|
91
66
|
return e;
|
|
92
67
|
}
|
|
93
68
|
//#endregion
|
|
94
|
-
export {
|
|
69
|
+
export { d as Toast, p as ToastProvider, g as useToast };
|
|
95
70
|
|
|
96
71
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["
|
|
1
|
+
{"version":3,"file":"index.js","names":["Message","Toast","forwardRef","rest","className","description","ToastContext","createContext","ToastProvider","items","setItems","useState","nextId","useRef","dismiss","useCallback","current","item","id","toast","options","value","useMemo","children","ToastRegion","TimedToast","useEffect","timer","onDismiss","useToast","context","useContext"],"sources":["../../../src/components/Toast/index.tsx"],"sourcesContent":["import {\n createContext,\n forwardRef,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n type HTMLAttributes,\n type ReactNode,\n} from \"react\";\nimport { Message } from \"../../internal/Message\";\nimport \"./style.css\";\n\nexport type ToastTone = \"neutral\" | \"info\" | \"success\" | \"warning\" | \"danger\";\n\nexport interface ToastProps extends HTMLAttributes<HTMLDivElement> {\n tone?: ToastTone;\n title: string;\n description?: string;\n /** Renders a dismiss button. Omit for a toast that only times out. */\n onDismiss?: () => void;\n}\n\n/** One fact about something that already happened. Never a question. */\nexport const Toast = forwardRef<HTMLDivElement, ToastProps>(function Toast(\n { tone = \"neutral\", title, description, onDismiss, role = \"status\", className, ...rest },\n ref,\n) {\n return (\n <Message\n {...rest}\n ref={ref}\n role={role}\n tone={tone}\n title={title}\n appearance=\"floating\"\n icon=\"auto\"\n onDismiss={onDismiss}\n classPrefix=\"ds-toast\"\n dismissLabel=\"Dismiss notification\"\n className={[\"ds-toast\", className].filter(Boolean).join(\" \")}\n >\n {description}\n </Message>\n );\n});\n\nexport interface ToastOptions {\n tone?: ToastTone;\n title: string;\n description?: string;\n /** Milliseconds before it dismisses itself. Defaults to `--toast-duration`. */\n duration?: number;\n}\n\ninterface ToastRecord extends ToastOptions {\n id: number;\n}\n\ninterface ToastContextValue {\n toast: (options: ToastOptions) => void;\n dismiss: (id: number) => void;\n}\n\nconst ToastContext = createContext<ToastContextValue | null>(null);\n\nexport interface ToastProviderProps {\n children: ReactNode;\n}\n\n/** Mount once, near the root. Everything below it can call `useToast()`. */\nexport function ToastProvider({ children }: ToastProviderProps) {\n const [items, setItems] = useState<ToastRecord[]>([]);\n const nextId = useRef(0);\n\n const dismiss = useCallback((id: number) => {\n setItems((current) => current.filter((item) => item.id !== id));\n }, []);\n\n const toast = useCallback((options: ToastOptions) => {\n setItems((current) => [...current, { ...options, id: nextId.current++ }]);\n }, []);\n\n const value = useMemo(() => ({ toast, dismiss }), [toast, dismiss]);\n\n return (\n <ToastContext.Provider value={value}>\n {children}\n <ToastRegion\n items={items}\n onDismiss={dismiss}\n />\n </ToastContext.Provider>\n );\n}\n\nfunction ToastRegion({\n items,\n onDismiss,\n}: {\n items: ToastRecord[];\n onDismiss: (id: number) => void;\n}) {\n if (items.length === 0) {\n return null;\n }\n return (\n <div\n className=\"ds-toast-region\"\n role=\"region\"\n aria-label=\"Notifications\"\n >\n {items.map((item) => (\n <TimedToast\n key={item.id}\n item={item}\n onDismiss={onDismiss}\n />\n ))}\n </div>\n );\n}\n\nfunction TimedToast({ item, onDismiss }: { item: ToastRecord; onDismiss: (id: number) => void }) {\n useEffect(() => {\n const timer = window.setTimeout(() => onDismiss(item.id), item.duration ?? 5000);\n return () => window.clearTimeout(timer);\n }, [item, onDismiss]);\n\n return (\n <Toast\n tone={item.tone}\n title={item.title}\n description={item.description}\n onDismiss={() => onDismiss(item.id)}\n />\n );\n}\n\nexport function useToast(): ToastContextValue {\n const context = useContext(ToastContext);\n if (!context) {\n throw new Error(\"useToast must be used inside a <ToastProvider>.\");\n }\n return context;\n}\n"],"mappings":";;;;AA0BA,IAAaC,IAAQC,EAAuC,SAC1D,EAAE,UAAO,WAAW,UAAO,gBAAa,cAAW,UAAO,UAAU,cAAW,GAAGC,KAClF,GACA;CACA,OACE,kBAACH,GAAD;EACE,GAAIG;EACC;EACC;EACA;EACC;EACP,YAAW;EACX,MAAK;EACM;EACX,aAAY;EACZ,cAAa;EACb,WAAW,CAAC,YAAYC,CAAS,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG;EAE1D,UAAAC;CACM,CAAA;AAEb,CAAC,GAmBKC,IAAeC,EAAwC,IAAI;AAOjE,SAAgBC,EAAc,EAAE,eAAgC;CAC9D,IAAM,CAACC,GAAOC,KAAYC,EAAwB,CAAC,CAAC,GAC9CC,IAASC,EAAO,CAAC,GAEjBC,IAAUC,GAAa,MAAe;EAC1C,GAAU,MAAYC,EAAQ,QAAQ,MAASC,EAAK,OAAOC,CAAE,CAAC;CAChE,GAAG,CAAC,CAAC,GAECC,IAAQJ,GAAa,MAA0B;EACnD,GAAU,MAAY,CAAC,GAAGC,GAAS;GAAE,GAAGI;GAAS,IAAI,EAAO;EAAU,CAAC,CAAC;CAC1E,GAAG,CAAC,CAAC,GAECC,IAAQC,SAAe;EAAE;EAAO;CAAQ,IAAI,CAACH,GAAOL,CAAO,CAAC;CAElE,OACE,kBAACR,EAAa,UAAd;EAA8B;EAA9B,UAAA,CACGiB,GACD,kBAACC,GAAD;GACS;GACP,WAAWV;EACZ,CAAA,CACoB;;AAE3B;AAEA,SAASU,EAAY,EACnB,UACA,gBAIC;CAID,OAHIf,EAAM,WAAW,IACZ,OAGP,kBAAC,OAAD;EACE,WAAU;EACV,MAAK;EACL,cAAW;EAEV,UAAAA,EAAM,KAAK,MACV,kBAACgB,GAAD;GAEQ;GACK;EACZ,GAHMR,EAAK,EAGX,CACF;CACE,CAAA;AAET;AAEA,SAASQ,EAAW,EAAE,SAAM,gBAAqE;CAM/F,OALAC,QAAgB;EACd,IAAMC,IAAQ,OAAO,iBAAiBC,EAAUX,EAAK,EAAE,GAAGA,EAAK,YAAY,GAAI;EAC/E,aAAa,OAAO,aAAaU,CAAK;CACxC,GAAG,CAACV,GAAMW,CAAS,CAAC,GAGlB,kBAAC3B,GAAD;EACE,MAAMgB,EAAK;EACX,OAAOA,EAAK;EACZ,aAAaA,EAAK;EAClB,iBAAiBW,EAAUX,EAAK,EAAE;CACnC,CAAA;AAEL;AAEA,SAAgBY,IAA8B;CAC5C,IAAMC,IAAUC,EAAWzB,CAAY;CACvC,IAAI,CAACwB,GACH,MAAU,MAAM,iDAAiD;CAEnE,OAAOA;AACT"}
|
|
@@ -10,61 +10,16 @@
|
|
|
10
10
|
inline-size: min(var(--toast-width), calc(100vw - var(--space-8)));
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
/* --toast-tone stays the public recolouring hook for the edge and icon. The
|
|
14
|
+
* shared floating styles read it through --message-accent, which they never
|
|
15
|
+
* declare, so the result does not depend on stylesheet order. */
|
|
13
16
|
.ds-toast {
|
|
14
|
-
--
|
|
15
|
-
--
|
|
17
|
+
--toast-tone: var(--message-ink-strong);
|
|
18
|
+
--message-accent: var(--toast-tone);
|
|
16
19
|
|
|
17
|
-
display: flex;
|
|
18
|
-
align-items: start;
|
|
19
|
-
gap: var(--space-3);
|
|
20
|
-
padding: var(--space-4);
|
|
21
|
-
background: var(--color-surface-raised);
|
|
22
|
-
border: var(--control-border-width) solid var(--toast-tone);
|
|
23
|
-
border-radius: var(--radius-md);
|
|
24
|
-
box-shadow: var(--shadow-lg);
|
|
25
20
|
animation: ds-toast-in var(--duration-panel) var(--ease-panel);
|
|
26
21
|
}
|
|
27
22
|
|
|
28
|
-
.ds-toast[data-tone="success"] {
|
|
29
|
-
--toast-tone: var(--color-success);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
.ds-toast[data-tone="warning"] {
|
|
33
|
-
--toast-tone: var(--color-warning);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
.ds-toast[data-tone="danger"] {
|
|
37
|
-
--toast-tone: var(--color-danger);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
.ds-toast[data-tone="info"] {
|
|
41
|
-
--toast-tone: var(--color-primary);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
.ds-toast__icon {
|
|
45
|
-
color: var(--toast-tone);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
.ds-toast__body {
|
|
49
|
-
display: flex;
|
|
50
|
-
flex-direction: column;
|
|
51
|
-
gap: var(--space-1);
|
|
52
|
-
flex: 1;
|
|
53
|
-
min-inline-size: 0;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
.ds-toast__title {
|
|
57
|
-
font-size: var(--font-size-sm);
|
|
58
|
-
font-weight: var(--font-weight-bold);
|
|
59
|
-
line-height: var(--line-height-tight);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
.ds-toast__description {
|
|
63
|
-
color: var(--color-text-muted);
|
|
64
|
-
font-size: var(--font-size-sm);
|
|
65
|
-
line-height: var(--line-height-body);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
23
|
@keyframes ds-toast-in {
|
|
69
24
|
from {
|
|
70
25
|
opacity: 0;
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./chunks/Icon-WOhlu6Rp.cjs"),t=require("./components/Button/index.cjs"),n=require("./components/Drawer/index.cjs"),r=require("./components/SideNav/index.cjs"),i=require("./components/TopNav/index.cjs"),a=require("./components/AppShell/index.cjs"),o=require("./components/ButtonGroup/index.cjs"),s=require("./components/Badge/index.cjs"),c=require("./components/Field/index.cjs"),l=require("./components/Modal/index.cjs"),u=require("./components/TextField/index.cjs"),d=require("./chunks/RichTextEditor-Ddk7qaqg.cjs"),f=require("./components/Container/index.cjs"),p=require("./components/FieldAffix/index.cjs"),m=require("./components/SearchField/index.cjs"),h=require("./components/SortableList/index.cjs"),g=require("./components/EntryPicker/index.cjs"),_=require("./components/NumberField/index.cjs"),v=require("./components/Popover/index.cjs"),y=require("./components/Select/index.cjs"),b=require("./components/Switch/index.cjs"),x=require("./chunks/ColourField-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./chunks/Icon-WOhlu6Rp.cjs"),t=require("./components/Button/index.cjs"),n=require("./components/Drawer/index.cjs"),r=require("./components/SideNav/index.cjs"),i=require("./components/TopNav/index.cjs"),a=require("./components/AppShell/index.cjs"),o=require("./components/ButtonGroup/index.cjs"),s=require("./components/Badge/index.cjs"),c=require("./components/Field/index.cjs"),l=require("./components/Modal/index.cjs"),u=require("./components/TextField/index.cjs"),d=require("./chunks/RichTextEditor-Ddk7qaqg.cjs"),f=require("./components/Container/index.cjs"),p=require("./components/FieldAffix/index.cjs"),m=require("./components/SearchField/index.cjs"),h=require("./components/SortableList/index.cjs"),g=require("./components/EntryPicker/index.cjs"),_=require("./components/NumberField/index.cjs"),v=require("./components/Popover/index.cjs"),y=require("./components/Select/index.cjs"),b=require("./components/Switch/index.cjs"),x=require("./chunks/ColourField-BqhYB4ZE.cjs"),S=require("./chunks/Slider-k8weRl34.cjs"),C=require("./chunks/DatePicker-01sor8iD.cjs"),w=require("./components/TagsInput/index.cjs"),T=require("./components/Grid/index.cjs"),E=require("./components/Choice/index.cjs"),D=require("./components/SelectionCard/index.cjs"),O=require("./chunks/FormEditor-BbsvbufQ.cjs"),k=require("./chunks/Board-CUt4j2-8.cjs"),A=require("./chunks/Avatar-C9ublbzK.cjs"),j=require("./components/Table/index.cjs"),M=require("./components/Menu/index.cjs"),N=require("./components/Toast/index.cjs"),P=require("./components/Banner/index.cjs"),F=require("./components/Skeleton/index.cjs"),I=require("./components/SubNav/index.cjs"),L=require("./components/Stepper/index.cjs"),R=require("./components/AssetCard/index.cjs"),z=require("./components/AssetGrid/index.cjs"),B=require("./components/ImageCropper/index.cjs"),V=require("./components/Time/index.cjs"),H=require("./components/Pagination/index.cjs"),U=require("./components/EditLayout/index.cjs");exports.AppShell=a.AppShell,exports.AssetCard=R.AssetCard,exports.AssetTile=R.AssetCard,exports.AssetCardSkeleton=R.AssetCardSkeleton,exports.AssetTileSkeleton=R.AssetCardSkeleton,exports.AssetGrid=z.AssetGrid,exports.AssetGridEmpty=z.AssetGridEmpty,exports.Avatar=A.t,exports.AvatarGroup=A.n,exports.Badge=s.Badge,exports.Banner=P.Banner,exports.Board=k.t,exports.BoardCard=k.n,exports.BoardColumn=k.r,exports.Button=t.Button,exports.ButtonGroup=o.ButtonGroup,exports.Calendar=C.t,exports.Checkbox=E.Checkbox,exports.CheckboxCard=D.CheckboxCard,exports.ChoiceGroup=E.ChoiceGroup,exports.ColourField=x.t,exports.ColourPanel=x.n,exports.Container=f.Container,exports.DateField=C.n,exports.DateRangeField=C.r,exports.Drawer=n.Drawer,exports.EditLayout=U.EditLayout,exports.EntryPicker=g.EntryPicker,exports.Field=c.Field,exports.FieldAffix=p.FieldAffix,exports.FormEditor=O.t,exports.Grid=T.Grid,exports.GridItem=T.GridItem,exports.Icon=e.t,exports.ImageCropper=B.ImageCropper,exports.Menu=M.Menu,exports.MenuItem=M.MenuItem,exports.MenuLabel=M.MenuLabel,exports.MenuSeparator=M.MenuSeparator,exports.Modal=l.Modal,exports.NumberField=_.NumberField,exports.NumberRangeField=_.NumberRangeField,exports.Pagination=H.Pagination,exports.Popover=v.Popover,exports.Radio=E.Radio,exports.RadioCard=D.RadioCard,exports.RangeSlider=S.t,exports.RichTextEditor=d.t,exports.SearchField=m.SearchField,exports.Select=y.Select,exports.SelectionCardGroup=D.SelectionCardGroup,exports.SideNav=r.SideNav,exports.SideNavFooter=r.SideNavFooter,exports.SideNavHeader=r.SideNavHeader,exports.SideNavItem=r.SideNavItem,exports.SideNavSection=r.SideNavSection,exports.Skeleton=F.Skeleton,exports.SkeletonText=F.SkeletonText,exports.Slider=S.n,exports.SortableList=h.SortableList,exports.SortableListItem=h.SortableListItem,exports.Stack=T.Stack,exports.Stepper=L.Stepper,exports.SubNav=I.SubNav,exports.SubNavButton=I.SubNavButton,exports.SubNavItem=I.SubNavItem,exports.Switch=b.Switch,exports.Table=j.Table,exports.TableBody=j.TableBody,exports.TableCell=j.TableCell,exports.TableEmpty=j.TableEmpty,exports.TableFrame=j.TableFrame,exports.TableHead=j.TableHead,exports.TableHeaderCell=j.TableHeaderCell,exports.TableRow=j.TableRow,exports.TableToolbar=j.TableToolbar,exports.TagsInput=w.TagsInput,exports.TextArea=u.TextArea,exports.TextField=u.TextField,exports.Time=V.Time,exports.Toast=N.Toast,exports.ToastProvider=N.ToastProvider,exports.TopNav=i.TopNav,exports.TopNavItem=i.TopNavItem,exports.cropToBlob=B.cropToBlob,exports.formatAbsoluteDate=V.formatAbsoluteDate,exports.formatAbsoluteTime=V.formatAbsoluteTime,exports.formatIsoDate=C.i,exports.formatRelativeTime=V.formatRelativeTime,exports.iconNames=e.n,exports.icons=e.r,exports.useSideNavCollapsed=r.useSideNavCollapsed,exports.useToast=N.useToast,exports.validateFormValues=O.n;
|
package/dist/index.d.cts
CHANGED
|
@@ -36,6 +36,8 @@ export { Modal } from "./components/Modal/index.cjs";
|
|
|
36
36
|
export type { ModalProps, ModalSize } from "./components/Modal/index.cjs";
|
|
37
37
|
export { Toast, ToastProvider, useToast } from "./components/Toast/index.cjs";
|
|
38
38
|
export type { ToastProps, ToastTone, ToastOptions, ToastProviderProps } from "./components/Toast/index.cjs";
|
|
39
|
+
export { Banner } from "./components/Banner/index.cjs";
|
|
40
|
+
export type { BannerProps, BannerTone } from "./components/Banner/index.cjs";
|
|
39
41
|
export { Skeleton, SkeletonText } from "./components/Skeleton/index.cjs";
|
|
40
42
|
export type { SkeletonProps, SkeletonTextProps, SkeletonShape } from "./components/Skeleton/index.cjs";
|
|
41
43
|
export { SideNav, SideNavHeader, SideNavSection, SideNavItem, SideNavFooter, useSideNavCollapsed, } from "./components/SideNav/index.cjs";
|