@fanvue/ui 3.26.1 → 3.28.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/dist/cjs/components/Button/Button.cjs +1 -1
- package/dist/cjs/components/Button/Button.cjs.map +1 -1
- package/dist/cjs/components/DropdownMenu/DropdownMenu.cjs +2 -0
- package/dist/cjs/components/DropdownMenu/DropdownMenu.cjs.map +1 -1
- package/dist/cjs/components/Icons/AddCircleIcon.cjs +81 -0
- package/dist/cjs/components/Icons/AddCircleIcon.cjs.map +1 -0
- package/dist/cjs/components/SegmentedControl/SegmentedControl.cjs +21 -13
- package/dist/cjs/components/SegmentedControl/SegmentedControl.cjs.map +1 -1
- package/dist/cjs/components/Tabs/TabsList.cjs +2 -7
- package/dist/cjs/components/Tabs/TabsList.cjs.map +1 -1
- package/dist/cjs/components/Tabs/TabsTrigger.cjs.map +1 -1
- package/dist/cjs/components/VoiceNote/VoiceNote.cjs +1 -68
- package/dist/cjs/components/VoiceNote/VoiceNote.cjs.map +1 -1
- package/dist/cjs/index.cjs +8 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/utils/audioWaveform.cjs +68 -0
- package/dist/cjs/utils/audioWaveform.cjs.map +1 -1
- package/dist/components/Button/Button.mjs +1 -1
- package/dist/components/Button/Button.mjs.map +1 -1
- package/dist/components/DropdownMenu/DropdownMenu.mjs +2 -0
- package/dist/components/DropdownMenu/DropdownMenu.mjs.map +1 -1
- package/dist/components/Icons/AddCircleIcon.mjs +64 -0
- package/dist/components/Icons/AddCircleIcon.mjs.map +1 -0
- package/dist/components/SegmentedControl/SegmentedControl.mjs +21 -13
- package/dist/components/SegmentedControl/SegmentedControl.mjs.map +1 -1
- package/dist/components/Tabs/TabsList.mjs +2 -7
- package/dist/components/Tabs/TabsList.mjs.map +1 -1
- package/dist/components/Tabs/TabsTrigger.mjs.map +1 -1
- package/dist/components/VoiceNote/VoiceNote.mjs +2 -69
- package/dist/components/VoiceNote/VoiceNote.mjs.map +1 -1
- package/dist/index.d.ts +80 -5
- package/dist/index.mjs +8 -0
- package/dist/index.mjs.map +1 -1
- package/dist/styles/theme.css +15 -15
- package/dist/utils/audioWaveform.mjs +68 -0
- package/dist/utils/audioWaveform.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SegmentedControl.cjs","sources":["../../../../src/components/SegmentedControl/SegmentedControl.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\n\n/** Height of the segmented control in pixels. */\nexport type SegmentedControlSize = \"32\" | \"40\" | \"48\";\n\n/**\n * Segment layout.\n * - `\"hug\"`: each segment is sized to its content.\n * - `\"fill\"`: the control spans the full width of its container and each segment grows equally.\n */\nexport type SegmentedControlVariant = \"hug\" | \"fill\";\n\n/**\n * Visual style of the control.\n * - `\"pill\"`: the container has a muted background and the selected segment shows a filled pill (default).\n * - `\"plain\"`: no container or selected-pill background; segments are bare content and selection is\n * communicated by color alone. Designed for icon-only toggles (e.g. a list/grid view switch).\n * - `\"brand\"`: like `\"pill\"`, but segments render their `icon` alongside the visible `label` and the\n * selected segment uses the brand-green pill. Designed for prominent toggles such as the\n * Home/Agent navigation switch.\n */\nexport type SegmentedControlAppearance = \"pill\" | \"plain\" | \"brand\";\n\n/** Describes one selectable segment. */\nexport interface SegmentedControlOption {\n /**\n * Display label for the segment. In `pill`/`plain` appearances, when `icon` is provided the\n * segment renders icon-only and this value becomes its accessible name (applied as `aria-label`)\n * instead of visible text. In the `brand` appearance the label is always rendered as visible text\n * (alongside the icon when present).\n */\n label: string;\n /** Value identifier returned via `onChange`. */\n value: string;\n /**\n * Icon to render for the segment. In `pill`/`plain` appearances the segment renders icon-only and\n * `label` becomes required as its accessible name (applied as `aria-label`, no visible text). In\n * the `brand` appearance the icon renders alongside the visible `label`. Required for every option\n * when `collapsible` is set, since the collapsed control shows the selected option's icon alone.\n */\n icon?: React.ReactNode;\n}\n\nexport interface SegmentedControlProps\n extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\"> {\n /** Height of the control in pixels. @default \"32\" */\n size?: SegmentedControlSize;\n /** Segment layout. @default \"hug\" */\n variant?: SegmentedControlVariant;\n /** Visual style of the control. @default \"pill\" */\n appearance?: SegmentedControlAppearance;\n /** The selectable segments. Designed for two or three mutually exclusive options. */\n options: SegmentedControlOption[];\n /** Currently selected value (controlled). */\n value?: string;\n /** Initially selected value (uncontrolled). Defaults to the first option. */\n defaultValue?: string;\n /** Callback fired when the selected value changes. */\n onChange?: (value: string) => void;\n /** Whether the control is disabled. @default false */\n disabled?: boolean;\n /**\n * When `true`, the control automatically collapses to a single icon-only toggle whenever its\n * container is too narrow to show every segment side by side, and expands again when the space\n * returns. Collapsed, it shows the currently-selected option's `icon`; clicking it (or pressing\n * Enter/Space) advances to the next option, wrapping around from the last back to the first.\n *\n * Only supported for the icon-bearing `\"plain\"` and `\"brand\"` appearances, and every option must\n * define an `icon` (there is nothing to show otherwise). Ignored, with a dev-time warning, when\n * those conditions are not met. @default false\n */\n collapsible?: boolean;\n}\n\n/** Padding and typography per size. Combined with the container's `p-1` these hit the 32/40/48px heights. */\nconst sizeClasses: Record<SegmentedControlSize, string> = {\n \"32\": \"px-2 py-1 typography-description-12px-semibold\",\n \"40\": \"px-3 py-1.75 typography-body-small-14px-semibold\",\n \"48\": \"px-4 py-2 typography-body-default-16px-semibold\",\n};\n\nfunction warnMissingAccessibleName(ariaLabel?: string, ariaLabelledBy?: string) {\n if (process.env.NODE_ENV !== \"production\") {\n if (!ariaLabel && !ariaLabelledBy) {\n console.warn(\n \"SegmentedControl: no accessible name provided. Pass an `aria-label` or `aria-labelledby` prop.\",\n );\n }\n }\n}\n\nfunction warnMissingOptionAccessibleName(options: SegmentedControlOption[]) {\n if (process.env.NODE_ENV !== \"production\") {\n for (const option of options) {\n if (option.icon && !option.label?.trim()) {\n console.warn(\n `SegmentedControl: icon-only segment \"${option.value}\" is missing a non-empty \\`label\\` to use as its accessible name.`,\n );\n }\n }\n }\n}\n\nfunction warnUnsupportedCollapsible(\n appearance: SegmentedControlAppearance,\n options: SegmentedControlOption[],\n) {\n if (process.env.NODE_ENV !== \"production\") {\n if (appearance === \"pill\") {\n console.warn(\n 'SegmentedControl: `collapsible` is only supported for the \"plain\" and \"brand\" appearances; ignoring it.',\n );\n } else if (!options.every((option) => option.icon)) {\n console.warn(\n \"SegmentedControl: `collapsible` requires every option to define an `icon`; ignoring it.\",\n );\n }\n }\n}\n\nfunction getSegmentClassName({\n appearance,\n size,\n variant,\n isSelected,\n disabled,\n}: {\n appearance: SegmentedControlAppearance;\n size: SegmentedControlSize;\n variant: SegmentedControlVariant;\n isSelected: boolean;\n disabled: boolean;\n}) {\n return cn(\n \"relative inline-flex min-w-0 cursor-pointer items-center justify-center rounded-full\",\n \"motion-safe:transition-colors motion-safe:duration-150 motion-safe:ease-in-out\",\n \"focus-visible:shadow-focus-ring focus-visible:outline-none\",\n variant === \"fill\" ? \"flex-1\" : \"shrink-0\",\n appearance === \"plain\"\n ? cn(\n // Padding + negative margin enlarge the hit target without changing the\n // visual footprint, which must stay glyph-only to match the design.\n \"-m-1 p-1\",\n isSelected ? \"text-icons-primary\" : \"text-icons-tertiary hover:text-icons-primary\",\n )\n : cn(\n sizeClasses[size],\n // brand renders icon + label together, so space them.\n appearance === \"brand\" && \"gap-1.5\",\n isSelected\n ? appearance === \"brand\"\n ? // Approximate brand-green pill using existing tokens; exact colours pending\n // dedicated navigation tokens (see ENG follow-up).\n \"bg-brand-primary-muted text-content-always-black shadow-sm ring-1 ring-brand-primary-default\"\n : \"bg-buttons-primary-default text-content-primary-inverted shadow-sm\"\n : \"text-content-primary hover:bg-buttons-switch-hover\",\n ),\n disabled && \"pointer-events-none\",\n );\n}\n\n/** Symmetric padding per size so the collapsed toggle is a square (a circle once `rounded-full`). */\nconst collapsedPaddingClasses: Record<SegmentedControlSize, string> = {\n \"32\": \"p-1\",\n \"40\": \"p-2\",\n \"48\": \"p-3\",\n};\n\n/**\n * Classes for the single button shown while the control is collapsed. Unlike an expanded segment\n * (which carries asymmetric `px`/`py` padding and so reads slightly wider than tall), the collapsed\n * toggle is forced to an `aspect-square` circle via symmetric padding and `rounded-full`, so the\n * icon-only control reads as a round button.\n */\nfunction getCollapsedButtonClassName({\n appearance,\n size,\n disabled,\n}: {\n appearance: SegmentedControlAppearance;\n size: SegmentedControlSize;\n disabled: boolean;\n}) {\n return cn(\n \"relative inline-flex aspect-square shrink-0 cursor-pointer items-center justify-center rounded-full\",\n \"motion-safe:transition-colors motion-safe:duration-150 motion-safe:ease-in-out\",\n \"focus-visible:shadow-focus-ring focus-visible:outline-none\",\n appearance === \"plain\"\n ? // Glyph-only: no pill, just the selected icon colour. The negative margin keeps the visual\n // footprint icon-sized while the padding enlarges the hit target.\n \"-m-1 p-1 text-icons-primary\"\n : cn(\n collapsedPaddingClasses[size],\n \"bg-brand-primary-muted text-content-always-black shadow-sm ring-1 ring-brand-primary-default\",\n ),\n disabled && \"pointer-events-none\",\n );\n}\n\n/**\n * Watches `rootRef`'s available width against the natural width of the fully expanded control\n * (measured from `measureRef`, an off-screen replica) and returns whether the control should\n * collapse. Comparing available space to a stable off-screen measurement — rather than to the\n * live control, which shrinks when it collapses — avoids the expand/collapse oscillation that a\n * self-referential measurement would cause. Returns `false` until both widths are measurable\n * (SSR, jsdom, or a zero-width layout), so the control renders expanded by default.\n */\nfunction useAutoCollapse(\n rootRef: React.RefObject<HTMLDivElement | null>,\n measureRef: React.RefObject<HTMLDivElement | null>,\n enabled: boolean,\n): boolean {\n const [collapsed, setCollapsed] = React.useState(false);\n\n React.useEffect(() => {\n if (!enabled) {\n setCollapsed(false);\n return;\n }\n const root = rootRef.current;\n const measure = measureRef.current;\n const parent = root?.parentElement;\n if (!root || !measure || !parent) return;\n\n const evaluate = () => {\n const available = parent.getBoundingClientRect().width;\n const required = measure.getBoundingClientRect().width;\n // Both unmeasured (SSR/jsdom/zero-width): leave the current state untouched.\n if (available <= 0 || required <= 0) return;\n setCollapsed(required > available);\n };\n\n evaluate();\n\n const observer = new ResizeObserver(evaluate);\n observer.observe(parent);\n observer.observe(measure);\n return () => observer.disconnect();\n }, [enabled, rootRef, measureRef]);\n\n return enabled && collapsed;\n}\n\n/**\n * A compact selector for choosing between two or three mutually exclusive\n * options where the choice affects the content immediately below it. Use\n * instead of tabs when the options are more like settings or filters than\n * navigation, such as toggling a list/grid view or a monthly/annual price.\n *\n * Rendered as a `radiogroup` with roving-tabindex keyboard navigation. Supports\n * both controlled and uncontrolled usage. With `collapsible`, the icon-bearing\n * `plain`/`brand` appearances shrink to a single cycling icon toggle when space\n * is tight (rendered as a `group` containing one button).\n *\n * @example\n * ```tsx\n * <SegmentedControl\n * options={[\n * { label: \"Net\", value: \"net\" },\n * { label: \"Gross\", value: \"gross\" },\n * ]}\n * value={amount}\n * onChange={setAmount}\n * aria-label=\"Amount type\"\n * />\n * ```\n *\n * @example Icon-only segments (e.g. a list/grid view toggle)\n * ```tsx\n * <SegmentedControl\n * appearance=\"plain\"\n * options={[\n * { label: \"List view\", value: \"list\", icon: <ListViewIcon size={16} /> },\n * { label: \"Grid view\", value: \"grid\", icon: <GridViewIcon size={16} /> },\n * ]}\n * value={view}\n * onChange={setView}\n * aria-label=\"View\"\n * />\n * ```\n *\n * @example Icon + label with the brand-green pill (e.g. the Home/Agent nav switch)\n * ```tsx\n * <SegmentedControl\n * appearance=\"brand\"\n * options={[\n * { label: \"Home\", value: \"home\", icon: <HomeIcon size={16} /> },\n * { label: \"Agent\", value: \"agent\", icon: <AIIcon size={16} /> },\n * ]}\n * value={mode}\n * onChange={setMode}\n * aria-label=\"Navigation mode\"\n * />\n * ```\n *\n * @example Collapses to a cycling icon toggle when the container is too narrow\n * ```tsx\n * <SegmentedControl\n * appearance=\"plain\"\n * collapsible\n * options={[\n * { label: \"List view\", value: \"list\", icon: <ListViewIcon size={16} /> },\n * { label: \"Grid view\", value: \"grid\", icon: <GridViewIcon size={16} /> },\n * ]}\n * value={view}\n * onChange={setView}\n * aria-label=\"View\"\n * />\n * ```\n */\nexport const SegmentedControl = React.forwardRef<HTMLDivElement, SegmentedControlProps>(\n (\n {\n className,\n size = \"32\",\n variant = \"hug\",\n appearance = \"pill\",\n options,\n value: controlledValue,\n defaultValue,\n onChange,\n disabled = false,\n collapsible = false,\n ...props\n },\n ref,\n ) => {\n warnMissingAccessibleName(props[\"aria-label\"], props[\"aria-labelledby\"]);\n warnMissingOptionAccessibleName(options);\n if (collapsible) warnUnsupportedCollapsible(appearance, options);\n\n // Tracks selection for uncontrolled usage; ignored when `value` prop is provided\n const [internalValue, setInternalValue] = React.useState(defaultValue ?? options[0]?.value);\n const isControlled = controlledValue !== undefined;\n const currentValue = isControlled ? controlledValue : internalValue;\n const anySelected = options.some((o) => o.value === currentValue);\n const buttonRefs = React.useRef<(HTMLButtonElement | null)[]>([]);\n\n // Collapsing only makes sense for icon-bearing appearances where every option has an icon\n // to show. Anything else falls back to the normal expanded control (a dev warning fires above).\n const canCollapse =\n collapsible &&\n (appearance === \"plain\" || appearance === \"brand\") &&\n options.every((option) => option.icon);\n\n const rootRef = React.useRef<HTMLDivElement | null>(null);\n const measureRef = React.useRef<HTMLDivElement | null>(null);\n const setRootRef = React.useCallback(\n (node: HTMLDivElement | null) => {\n rootRef.current = node;\n if (typeof ref === \"function\") ref(node);\n else if (ref) ref.current = node;\n },\n [ref],\n );\n const isCollapsed = useAutoCollapse(rootRef, measureRef, canCollapse);\n\n const handleSelect = (optionValue: string) => {\n if (disabled || optionValue === currentValue) return;\n if (!isControlled) {\n setInternalValue(optionValue);\n }\n onChange?.(optionValue);\n };\n\n const handleKeyDown = (e: React.KeyboardEvent, index: number) => {\n const nextIndex =\n e.key === \"ArrowRight\" || e.key === \"ArrowDown\"\n ? (index + 1) % options.length\n : e.key === \"ArrowLeft\" || e.key === \"ArrowUp\"\n ? (index - 1 + options.length) % options.length\n : null;\n if (nextIndex === null) return;\n e.preventDefault();\n const nextOption = options[nextIndex] as SegmentedControlOption;\n handleSelect(nextOption.value);\n buttonRefs.current[nextIndex]?.focus();\n };\n\n const renderSegment = (option: SegmentedControlOption, index: number) => {\n const isSelected = currentValue === option.value;\n // `brand` shows the label as visible text (with the icon); `pill`/`plain` render\n // icon-only when an icon is given, falling back to the label otherwise.\n const showLabelText = appearance === \"brand\" || !option.icon;\n return (\n // biome-ignore lint/a11y/useSemanticElements: native radio inputs only allow Tab-focus on the checked item; buttons with roving tabindex give full keyboard navigation\n <button\n key={option.value}\n ref={(el) => {\n buttonRefs.current[index] = el;\n }}\n type=\"button\"\n role=\"radio\"\n aria-checked={isSelected}\n tabIndex={isSelected || (!anySelected && index === 0) ? 0 : -1}\n disabled={disabled}\n aria-label={showLabelText ? undefined : option.label}\n onClick={() => handleSelect(option.value)}\n onKeyDown={(e) => handleKeyDown(e, index)}\n className={getSegmentClassName({ appearance, size, variant, isSelected, disabled })}\n >\n {option.icon && (\n <span className=\"flex shrink-0 items-center justify-center\" aria-hidden=\"true\">\n {option.icon}\n </span>\n )}\n {showLabelText && <span className=\"min-w-0 truncate\">{option.label}</span>}\n </button>\n );\n };\n\n // Off-screen replica of one segment used only to size the expanded control. Rendered as an\n // inert (disabled + `aria-hidden`) button with no `radio` semantics so it stays out of the\n // accessibility tree and tab order, and always with hug sizing so the replica reflects the\n // natural (uncompressed) width even under a `fill` layout.\n const renderMeasureSegment = (option: SegmentedControlOption) => {\n const showLabelText = appearance === \"brand\" || !option.icon;\n return (\n <button\n key={option.value}\n type=\"button\"\n disabled\n aria-hidden=\"true\"\n tabIndex={-1}\n className={getSegmentClassName({\n appearance,\n size,\n variant: \"hug\",\n isSelected: currentValue === option.value,\n disabled,\n })}\n >\n {option.icon && (\n <span className=\"flex shrink-0 items-center justify-center\" aria-hidden=\"true\">\n {option.icon}\n </span>\n )}\n {showLabelText && <span className=\"min-w-0 truncate\">{option.label}</span>}\n </button>\n );\n };\n\n // Collapsed: a single button showing the selected option's icon that cycles to the next\n // option on activation, wrapping from the last option back to the first.\n const selectedIndex = options.findIndex((option) => option.value === currentValue);\n const selectedOption = options[selectedIndex] ?? options[0];\n const handleCycle = () => {\n if (disabled || options.length === 0) return;\n const from = selectedIndex < 0 ? 0 : selectedIndex;\n const nextOption = options[(from + 1) % options.length] as SegmentedControlOption;\n handleSelect(nextOption.value);\n };\n\n return (\n <div\n ref={setRootRef}\n role={isCollapsed ? \"group\" : \"radiogroup\"}\n className={cn(\n \"relative items-center rounded-full\",\n variant === \"fill\" ? \"flex w-full\" : \"inline-flex\",\n appearance === \"plain\" ? \"gap-2\" : \"bg-surface-tertiary p-1\",\n disabled && \"cursor-not-allowed opacity-50\",\n className,\n )}\n {...props}\n >\n {isCollapsed && selectedOption ? (\n <button\n type=\"button\"\n disabled={disabled}\n aria-label={selectedOption.label}\n onClick={handleCycle}\n className={getCollapsedButtonClassName({ appearance, size, disabled })}\n >\n {selectedOption.icon && (\n <span className=\"flex shrink-0 items-center justify-center\" aria-hidden=\"true\">\n {selectedOption.icon}\n </span>\n )}\n </button>\n ) : (\n options.map((option, index) => renderSegment(option, index))\n )}\n\n {canCollapse && (\n // Off-screen replica of the fully expanded control. Kept in the DOM (out of flow, hidden\n // from AT and tab order) so its natural width is always measurable, whether the visible\n // control is currently expanded or collapsed.\n <div\n ref={measureRef}\n aria-hidden=\"true\"\n className={cn(\n \"pointer-events-none invisible absolute top-0 left-0 -z-10 flex items-center whitespace-nowrap rounded-full\",\n appearance === \"plain\" ? \"gap-2\" : \"bg-surface-tertiary p-1\",\n )}\n >\n {options.map((option) => renderMeasureSegment(option))}\n </div>\n )}\n </div>\n );\n },\n);\n\nSegmentedControl.displayName = \"SegmentedControl\";\n"],"names":["cn","React","jsxs","jsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA4EA,MAAM,cAAoD;AAAA,EACxD,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;AAEA,SAAS,0BAA0B,WAAoB,gBAAyB;AAC9E,MAAI,QAA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CAAC,WAAW,qBAAqB,MAAM,CAAC;AAAA,YAAA;AAAA,UAAA;AAAA,QACvD;AAAA,MAAA;AAAA,IAAA;AAAA,EAIR;AACF;AAEA,iBAAiB,cAAc;;"}
|
|
1
|
+
{"version":3,"file":"SegmentedControl.cjs","sources":["../../../../src/components/SegmentedControl/SegmentedControl.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\n\n/** Height of the segmented control in pixels. */\nexport type SegmentedControlSize = \"32\" | \"40\" | \"48\";\n\n/**\n * Segment layout.\n * - `\"hug\"`: each segment is sized to its content.\n * - `\"fill\"`: the control spans the full width of its container and each segment grows equally.\n */\nexport type SegmentedControlVariant = \"hug\" | \"fill\";\n\n/**\n * Visual style of the control.\n * - `\"pill\"`: the container has a muted background and the selected segment shows a filled pill (default).\n * - `\"plain\"`: no container or selected-pill background; segments are bare content and selection is\n * communicated by color alone. Designed for icon-only toggles (e.g. a list/grid view switch).\n * - `\"brand\"`: like `\"pill\"`, but segments render their `icon` alongside the visible `label` and the\n * selected segment uses the brand-green pill. Designed for prominent toggles such as the\n * Home/Agent navigation switch.\n */\nexport type SegmentedControlAppearance = \"pill\" | \"plain\" | \"brand\";\n\n/** Describes one selectable segment. */\nexport interface SegmentedControlOption {\n /**\n * Display label for the segment. In `pill`/`plain` appearances, when `icon` is provided the\n * segment renders icon-only and this value becomes its accessible name (applied as `aria-label`)\n * instead of visible text. In the `brand` appearance the label is always rendered as visible text\n * (alongside the icon when present).\n */\n label: string;\n /** Value identifier returned via `onChange`. */\n value: string;\n /**\n * Icon to render for the segment. In `pill`/`plain` appearances the segment renders icon-only and\n * `label` becomes required as its accessible name (applied as `aria-label`, no visible text). In\n * the `brand` appearance the icon renders alongside the visible `label`. Required for every option\n * when `collapsible` is set unless a `collapsedIcon` is given, since the collapsed control\n * otherwise shows the selected option's icon alone.\n */\n icon?: React.ReactNode;\n}\n\nexport interface SegmentedControlProps\n extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\"> {\n /** Height of the control in pixels. @default \"32\" */\n size?: SegmentedControlSize;\n /** Segment layout. @default \"hug\" */\n variant?: SegmentedControlVariant;\n /** Visual style of the control. @default \"pill\" */\n appearance?: SegmentedControlAppearance;\n /** The selectable segments. Designed for two or three mutually exclusive options. */\n options: SegmentedControlOption[];\n /** Currently selected value (controlled). */\n value?: string;\n /** Initially selected value (uncontrolled). Defaults to the first option. */\n defaultValue?: string;\n /** Callback fired when the selected value changes. */\n onChange?: (value: string) => void;\n /** Whether the control is disabled. @default false */\n disabled?: boolean;\n /**\n * When `true`, the control automatically collapses to a single icon-only toggle whenever its\n * container is too narrow to show every segment side by side, and expands again when the space\n * returns. Collapsed, it shows `collapsedIcon` when given and otherwise the currently-selected\n * option's `icon`; clicking it (or pressing Enter/Space) advances to the next option, wrapping\n * around from the last back to the first.\n *\n * Only supported for the icon-bearing `\"plain\"` and `\"brand\"` appearances, and every option must\n * define an `icon` unless `collapsedIcon` is given (there is nothing to show otherwise). Ignored,\n * with a dev-time warning, when those conditions are not met. @default false\n */\n collapsible?: boolean;\n /**\n * Single glyph for the collapsed toggle, replacing the selected option's icon. Use it when the\n * collapsed control should read as one switch affordance rather than as a preview of the current\n * selection — the collapsed navigation rail shows a repeat glyph this way. The button still\n * announces the selected option as its accessible name, so the current state stays available to\n * assistive tech. Only meaningful alongside `collapsible`.\n */\n collapsedIcon?: React.ReactNode;\n}\n\n/** Padding and typography per size. Combined with the container's `p-1` these hit the 32/40/48px heights. */\nconst sizeClasses: Record<SegmentedControlSize, string> = {\n \"32\": \"px-2 py-1 typography-description-12px-semibold\",\n \"40\": \"px-3 py-1.75 typography-body-small-14px-semibold\",\n \"48\": \"px-4 py-2 typography-body-default-16px-semibold\",\n};\n\nfunction warnMissingAccessibleName(ariaLabel?: string, ariaLabelledBy?: string) {\n if (process.env.NODE_ENV !== \"production\") {\n if (!ariaLabel && !ariaLabelledBy) {\n console.warn(\n \"SegmentedControl: no accessible name provided. Pass an `aria-label` or `aria-labelledby` prop.\",\n );\n }\n }\n}\n\nfunction warnMissingOptionAccessibleName(options: SegmentedControlOption[]) {\n if (process.env.NODE_ENV !== \"production\") {\n for (const option of options) {\n if (option.icon && !option.label?.trim()) {\n console.warn(\n `SegmentedControl: icon-only segment \"${option.value}\" is missing a non-empty \\`label\\` to use as its accessible name.`,\n );\n }\n }\n }\n}\n\nfunction warnUnsupportedCollapsible(\n appearance: SegmentedControlAppearance,\n options: SegmentedControlOption[],\n hasCollapsedIcon: boolean,\n) {\n if (process.env.NODE_ENV !== \"production\") {\n if (appearance === \"pill\") {\n console.warn(\n 'SegmentedControl: `collapsible` is only supported for the \"plain\" and \"brand\" appearances; ignoring it.',\n );\n } else if (!hasCollapsedIcon && !options.every((option) => option.icon)) {\n console.warn(\n \"SegmentedControl: `collapsible` requires every option to define an `icon`, or a `collapsedIcon` to show instead; ignoring it.\",\n );\n }\n }\n}\n\nfunction getSegmentClassName({\n appearance,\n size,\n variant,\n isSelected,\n disabled,\n}: {\n appearance: SegmentedControlAppearance;\n size: SegmentedControlSize;\n variant: SegmentedControlVariant;\n isSelected: boolean;\n disabled: boolean;\n}) {\n return cn(\n \"relative inline-flex min-w-0 cursor-pointer items-center justify-center rounded-full\",\n \"motion-safe:transition-colors motion-safe:duration-150 motion-safe:ease-in-out\",\n \"focus-visible:shadow-focus-ring focus-visible:outline-none\",\n variant === \"fill\" ? \"flex-1\" : \"shrink-0\",\n appearance === \"plain\"\n ? cn(\n // Padding + negative margin enlarge the hit target without changing the\n // visual footprint, which must stay glyph-only to match the design.\n \"-m-1 p-1\",\n isSelected ? \"text-icons-primary\" : \"text-icons-tertiary hover:text-icons-primary\",\n )\n : cn(\n sizeClasses[size],\n // brand renders icon + label together, so space them.\n appearance === \"brand\" && \"gap-1.5\",\n isSelected\n ? appearance === \"brand\"\n ? // Approximate brand-green pill using existing tokens; exact colours pending\n // dedicated navigation tokens (see ENG follow-up).\n \"bg-brand-primary-muted text-content-always-black shadow-sm ring-1 ring-brand-primary-default\"\n : \"bg-buttons-primary-default text-content-primary-inverted shadow-sm\"\n : \"text-content-primary hover:bg-buttons-switch-hover\",\n ),\n disabled && \"pointer-events-none\",\n );\n}\n\n/**\n * Footprint of the collapsed toggle per size. A fixed square keeps the collapsed control the same\n * height as the expanded one, whose height comes from the segment padding plus the container's\n * `p-1` — padding the collapsed button alone would fall short of it by that container padding.\n */\nconst collapsedSizeClasses: Record<SegmentedControlSize, string> = {\n \"32\": \"size-8\",\n \"40\": \"size-10\",\n \"48\": \"size-12\",\n};\n\n/**\n * Classes for the single button shown while the control is collapsed. Unlike an expanded segment\n * (which carries asymmetric `px`/`py` padding and so reads slightly wider than tall), the collapsed\n * toggle is forced to a square via a fixed footprint and `aspect-square`, so with `rounded-full` the\n * icon-only control reads as a round button.\n */\nfunction getCollapsedButtonClassName({\n appearance,\n size,\n disabled,\n}: {\n appearance: SegmentedControlAppearance;\n size: SegmentedControlSize;\n disabled: boolean;\n}) {\n return cn(\n \"relative inline-flex aspect-square shrink-0 cursor-pointer items-center justify-center rounded-full\",\n \"motion-safe:transition-colors motion-safe:duration-150 motion-safe:ease-in-out\",\n \"focus-visible:shadow-focus-ring focus-visible:outline-none\",\n appearance === \"plain\"\n ? // Glyph-only: no pill, just the selected icon colour. The negative margin keeps the visual\n // footprint icon-sized while the padding enlarges the hit target.\n \"-m-1 p-1 text-icons-primary\"\n : cn(\n collapsedSizeClasses[size],\n // Neutral circle rather than the brand pill: collapsed, the control is a switch\n // affordance, not a preview of the selected segment.\n \"bg-surface-secondary text-icons-primary hover:bg-buttons-switch-hover\",\n ),\n disabled && \"pointer-events-none\",\n );\n}\n\n/**\n * Watches `rootRef`'s available width against the natural width of the fully expanded control\n * (measured from `measureRef`, an off-screen replica) and returns whether the control should\n * collapse. Comparing available space to a stable off-screen measurement — rather than to the\n * live control, which shrinks when it collapses — avoids the expand/collapse oscillation that a\n * self-referential measurement would cause. Returns `false` until both widths are measurable\n * (SSR, jsdom, or a zero-width layout), so the control renders expanded by default.\n */\nfunction useAutoCollapse(\n rootRef: React.RefObject<HTMLDivElement | null>,\n measureRef: React.RefObject<HTMLDivElement | null>,\n enabled: boolean,\n): boolean {\n const [collapsed, setCollapsed] = React.useState(false);\n\n React.useEffect(() => {\n if (!enabled) {\n setCollapsed(false);\n return;\n }\n const root = rootRef.current;\n const measure = measureRef.current;\n const parent = root?.parentElement;\n if (!root || !measure || !parent) return;\n\n const evaluate = () => {\n const available = parent.getBoundingClientRect().width;\n const required = measure.getBoundingClientRect().width;\n // Both unmeasured (SSR/jsdom/zero-width): leave the current state untouched.\n if (available <= 0 || required <= 0) return;\n setCollapsed(required > available);\n };\n\n evaluate();\n\n const observer = new ResizeObserver(evaluate);\n observer.observe(parent);\n observer.observe(measure);\n return () => observer.disconnect();\n }, [enabled, rootRef, measureRef]);\n\n return enabled && collapsed;\n}\n\n/**\n * A compact selector for choosing between two or three mutually exclusive\n * options where the choice affects the content immediately below it. Use\n * instead of tabs when the options are more like settings or filters than\n * navigation, such as toggling a list/grid view or a monthly/annual price.\n *\n * Rendered as a `radiogroup` with roving-tabindex keyboard navigation. Supports\n * both controlled and uncontrolled usage. With `collapsible`, the icon-bearing\n * `plain`/`brand` appearances shrink to a single cycling icon toggle when space\n * is tight (rendered as a `group` containing one button).\n *\n * @example\n * ```tsx\n * <SegmentedControl\n * options={[\n * { label: \"Net\", value: \"net\" },\n * { label: \"Gross\", value: \"gross\" },\n * ]}\n * value={amount}\n * onChange={setAmount}\n * aria-label=\"Amount type\"\n * />\n * ```\n *\n * @example Icon-only segments (e.g. a list/grid view toggle)\n * ```tsx\n * <SegmentedControl\n * appearance=\"plain\"\n * options={[\n * { label: \"List view\", value: \"list\", icon: <ListViewIcon size={16} /> },\n * { label: \"Grid view\", value: \"grid\", icon: <GridViewIcon size={16} /> },\n * ]}\n * value={view}\n * onChange={setView}\n * aria-label=\"View\"\n * />\n * ```\n *\n * @example Icon + label with the brand-green pill (e.g. the Home/Agent nav switch)\n * ```tsx\n * <SegmentedControl\n * appearance=\"brand\"\n * options={[\n * { label: \"Home\", value: \"home\", icon: <HomeIcon size={16} /> },\n * { label: \"Agent\", value: \"agent\", icon: <AIIcon size={16} /> },\n * ]}\n * value={mode}\n * onChange={setMode}\n * aria-label=\"Navigation mode\"\n * />\n * ```\n *\n * @example Collapses to a cycling icon toggle when the container is too narrow\n * ```tsx\n * <SegmentedControl\n * appearance=\"plain\"\n * collapsible\n * options={[\n * { label: \"List view\", value: \"list\", icon: <ListViewIcon size={16} /> },\n * { label: \"Grid view\", value: \"grid\", icon: <GridViewIcon size={16} /> },\n * ]}\n * value={view}\n * onChange={setView}\n * aria-label=\"View\"\n * />\n * ```\n *\n * @example A collapsed toggle that shows one switch glyph instead of the selected icon\n * ```tsx\n * <SegmentedControl\n * appearance=\"brand\"\n * collapsible\n * collapsedIcon={<RepeatIcon size={16} />}\n * options={[\n * { label: \"Home\", value: \"home\", icon: <HomeIcon size={16} /> },\n * { label: \"Agent\", value: \"agent\", icon: <AIIcon size={16} filled /> },\n * ]}\n * value={mode}\n * onChange={setMode}\n * aria-label=\"Navigation mode\"\n * />\n * ```\n */\nexport const SegmentedControl = React.forwardRef<HTMLDivElement, SegmentedControlProps>(\n (\n {\n className,\n size = \"32\",\n variant = \"hug\",\n appearance = \"pill\",\n options,\n value: controlledValue,\n defaultValue,\n onChange,\n disabled = false,\n collapsible = false,\n collapsedIcon,\n ...props\n },\n ref,\n ) => {\n warnMissingAccessibleName(props[\"aria-label\"], props[\"aria-labelledby\"]);\n warnMissingOptionAccessibleName(options);\n if (collapsible) warnUnsupportedCollapsible(appearance, options, collapsedIcon !== undefined);\n\n // Tracks selection for uncontrolled usage; ignored when `value` prop is provided\n const [internalValue, setInternalValue] = React.useState(defaultValue ?? options[0]?.value);\n const isControlled = controlledValue !== undefined;\n const currentValue = isControlled ? controlledValue : internalValue;\n const anySelected = options.some((o) => o.value === currentValue);\n const buttonRefs = React.useRef<(HTMLButtonElement | null)[]>([]);\n\n // Collapsing only makes sense for icon-bearing appearances where there is a glyph to show:\n // either a `collapsedIcon` for every state, or an icon on every option. Anything else falls\n // back to the normal expanded control (a dev warning fires above).\n const canCollapse =\n collapsible &&\n (appearance === \"plain\" || appearance === \"brand\") &&\n (collapsedIcon !== undefined || options.every((option) => option.icon));\n\n const rootRef = React.useRef<HTMLDivElement | null>(null);\n const measureRef = React.useRef<HTMLDivElement | null>(null);\n const setRootRef = React.useCallback(\n (node: HTMLDivElement | null) => {\n rootRef.current = node;\n if (typeof ref === \"function\") ref(node);\n else if (ref) ref.current = node;\n },\n [ref],\n );\n const isCollapsed = useAutoCollapse(rootRef, measureRef, canCollapse);\n\n const handleSelect = (optionValue: string) => {\n if (disabled || optionValue === currentValue) return;\n if (!isControlled) {\n setInternalValue(optionValue);\n }\n onChange?.(optionValue);\n };\n\n const handleKeyDown = (e: React.KeyboardEvent, index: number) => {\n const nextIndex =\n e.key === \"ArrowRight\" || e.key === \"ArrowDown\"\n ? (index + 1) % options.length\n : e.key === \"ArrowLeft\" || e.key === \"ArrowUp\"\n ? (index - 1 + options.length) % options.length\n : null;\n if (nextIndex === null) return;\n e.preventDefault();\n const nextOption = options[nextIndex] as SegmentedControlOption;\n handleSelect(nextOption.value);\n buttonRefs.current[nextIndex]?.focus();\n };\n\n const renderSegment = (option: SegmentedControlOption, index: number) => {\n const isSelected = currentValue === option.value;\n // `brand` shows the label as visible text (with the icon); `pill`/`plain` render\n // icon-only when an icon is given, falling back to the label otherwise.\n const showLabelText = appearance === \"brand\" || !option.icon;\n return (\n // biome-ignore lint/a11y/useSemanticElements: native radio inputs only allow Tab-focus on the checked item; buttons with roving tabindex give full keyboard navigation\n <button\n key={option.value}\n ref={(el) => {\n buttonRefs.current[index] = el;\n }}\n type=\"button\"\n role=\"radio\"\n aria-checked={isSelected}\n tabIndex={isSelected || (!anySelected && index === 0) ? 0 : -1}\n disabled={disabled}\n aria-label={showLabelText ? undefined : option.label}\n onClick={() => handleSelect(option.value)}\n onKeyDown={(e) => handleKeyDown(e, index)}\n className={getSegmentClassName({ appearance, size, variant, isSelected, disabled })}\n >\n {option.icon && (\n <span className=\"flex shrink-0 items-center justify-center\" aria-hidden=\"true\">\n {option.icon}\n </span>\n )}\n {showLabelText && <span className=\"min-w-0 truncate\">{option.label}</span>}\n </button>\n );\n };\n\n // Off-screen replica of one segment used only to size the expanded control. Rendered as an\n // inert (disabled + `aria-hidden`) button with no `radio` semantics so it stays out of the\n // accessibility tree and tab order, and always with hug sizing so the replica reflects the\n // natural (uncompressed) width even under a `fill` layout.\n const renderMeasureSegment = (option: SegmentedControlOption) => {\n const showLabelText = appearance === \"brand\" || !option.icon;\n return (\n <button\n key={option.value}\n type=\"button\"\n disabled\n aria-hidden=\"true\"\n tabIndex={-1}\n className={getSegmentClassName({\n appearance,\n size,\n variant: \"hug\",\n isSelected: currentValue === option.value,\n disabled,\n })}\n >\n {option.icon && (\n <span className=\"flex shrink-0 items-center justify-center\" aria-hidden=\"true\">\n {option.icon}\n </span>\n )}\n {showLabelText && <span className=\"min-w-0 truncate\">{option.label}</span>}\n </button>\n );\n };\n\n // Collapsed: a single button showing the selected option's icon that cycles to the next\n // option on activation, wrapping from the last option back to the first.\n const selectedIndex = options.findIndex((option) => option.value === currentValue);\n const selectedOption = options[selectedIndex] ?? options[0];\n const handleCycle = () => {\n if (disabled || options.length === 0) return;\n const from = selectedIndex < 0 ? 0 : selectedIndex;\n const nextOption = options[(from + 1) % options.length] as SegmentedControlOption;\n handleSelect(nextOption.value);\n };\n\n return (\n <div\n ref={setRootRef}\n role={isCollapsed ? \"group\" : \"radiogroup\"}\n className={cn(\n \"relative items-center rounded-full\",\n variant === \"fill\" ? \"flex w-full\" : \"inline-flex\",\n isCollapsed\n ? // Collapsed, the toggle itself carries the surface, so the container drops its own\n // chrome and centres the button instead of pinning it to the start of a full-width\n // row — in a narrow rail that offset is the whole width of the column.\n \"justify-center\"\n : appearance === \"plain\"\n ? \"gap-2\"\n : \"bg-surface-tertiary p-1\",\n disabled && \"cursor-not-allowed opacity-50\",\n className,\n )}\n {...props}\n >\n {isCollapsed && selectedOption ? (\n <button\n type=\"button\"\n disabled={disabled}\n aria-label={selectedOption.label}\n onClick={handleCycle}\n className={getCollapsedButtonClassName({ appearance, size, disabled })}\n >\n {(collapsedIcon ?? selectedOption.icon) && (\n <span className=\"flex shrink-0 items-center justify-center\" aria-hidden=\"true\">\n {collapsedIcon ?? selectedOption.icon}\n </span>\n )}\n </button>\n ) : (\n options.map((option, index) => renderSegment(option, index))\n )}\n\n {canCollapse && (\n // Off-screen replica of the fully expanded control. Kept in the DOM (out of flow, hidden\n // from AT and tab order) so its natural width is always measurable, whether the visible\n // control is currently expanded or collapsed.\n <div\n ref={measureRef}\n aria-hidden=\"true\"\n className={cn(\n \"pointer-events-none invisible absolute top-0 left-0 -z-10 flex items-center whitespace-nowrap rounded-full\",\n appearance === \"plain\" ? \"gap-2\" : \"bg-surface-tertiary p-1\",\n )}\n >\n {options.map((option) => renderMeasureSegment(option))}\n </div>\n )}\n </div>\n );\n },\n);\n\nSegmentedControl.displayName = \"SegmentedControl\";\n"],"names":["cn","React","jsxs","jsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAsFA,MAAM,cAAoD;AAAA,EACxD,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;AAEA,SAAS,0BAA0B,WAAoB,gBAAyB;AAC9E,MAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,QAAI,CAAC,aAAa,CAAC,gBAAgB;AACjC,cAAQ;AAAA,QACN;AAAA,MAAA;AAAA,IAEJ;AAAA,EACF;AACF;AAEA,SAAS,gCAAgC,SAAmC;AAC1E,MAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,eAAW,UAAU,SAAS;AAC5B,UAAI,OAAO,QAAQ,CAAC,OAAO,OAAO,QAAQ;AACxC,gBAAQ;AAAA,UACN,wCAAwC,OAAO,KAAK;AAAA,QAAA;AAAA,MAExD;AAAA,IACF;AAAA,EACF;AACF;A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
73
|
} else {
|
|
74
74
|
indicator.style.background = "linear-gradient(90deg, var(--color-buttons-tertiary-default) 0%, var(--color-tab-active) 50%, var(--color-buttons-tertiary-default) 100%)";
|
|
75
|
-
const textSpan = activeTab.querySelector("span");
|
|
76
|
-
const target = textSpan ?? activeTab;
|
|
77
|
-
const textWidth = target.getBoundingClientRect().width;
|
|
78
|
-
const textOffsetInTab = target === activeTab ? 0 : target.getBoundingClientRect().left - activeTab.getBoundingClientRect().left;
|
|
79
|
-
const indicatorLeft = activeTab.offsetLeft + textOffsetInTab;
|
|
80
75
|
indicator.style.inset = "auto auto 0 0";
|
|
81
76
|
indicator.style.height = "1px";
|
|
82
|
-
indicator.style.width = `${
|
|
83
|
-
indicator.style.transform = `translateX(${
|
|
77
|
+
indicator.style.width = `${activeTab.offsetWidth}px`;
|
|
78
|
+
indicator.style.transform = `translateX(${activeTab.offsetLeft}px)`;
|
|
84
79
|
}
|
|
85
80
|
}, []);
|
|
86
81
|
const revealActiveTab = React__namespace.useCallback(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TabsList.cjs","sources":["../../../../src/components/Tabs/TabsList.tsx"],"sourcesContent":["import * as TabsPrimitive from \"@radix-ui/react-tabs\";\nimport * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\n\n/** Breakpoint values for responsive props. */\ntype Breakpoint = \"sm\" | \"md\" | \"lg\" | \"xl\";\n\nconst alignLeftClasses: Record<Breakpoint | \"always\", string> = {\n always: \"[&>[role=tab]]:flex-initial\",\n sm: \"[&>[role=tab]]:sm:flex-initial\",\n md: \"[&>[role=tab]]:md:flex-initial\",\n lg: \"[&>[role=tab]]:lg:flex-initial\",\n xl: \"[&>[role=tab]]:xl:flex-initial\",\n};\n\nfunction getLayoutClass(\n variant: \"fill\" | \"hug\" | undefined,\n fullWidth: boolean,\n alignLeft?: boolean | Breakpoint,\n): string {\n if (variant === \"hug\") return \"inline-flex\";\n if (variant === \"fill\") return \"flex w-full [&>[role=tab]]:flex-1\";\n\n if (!fullWidth) return \"inline-flex\";\n\n const base = \"flex w-full [&>[role=tab]]:flex-1\";\n if (alignLeft === true) return `${base} ${alignLeftClasses.always}`;\n if (typeof alignLeft === \"string\") return `${base} ${alignLeftClasses[alignLeft]}`;\n return base;\n}\n\n/** Props for the {@link TabsList} component. */\nexport type TabsListProps = React.ComponentPropsWithoutRef<typeof TabsPrimitive.List> & {\n /** When `true` (the default), the tab list spans the full width of its container and each tab grows equally. Set to `false` for inline sizing. */\n fullWidth?: boolean;\n /**\n * Controls tab alignment within a full-width container.\n * - `false` (default): tabs spread evenly\n * - `true`: tabs left-aligned, sized to content\n * - `\"md\"` (breakpoint): spread on mobile, left-aligned at breakpoint and up\n */\n alignLeft?: boolean | Breakpoint;\n /** Explicit layout variant. `\"hug\"` sizes the list to its content; `\"fill\"` stretches it full-width with equal-width tabs. Takes precedence over `fullWidth`/`alignLeft`. */\n variant?: \"fill\" | \"hug\";\n /**\n * Drops the leading padding on the first tab so its label sits flush with the\n * list's left edge, lining it up with page content above or below the bar\n * (a heading, for instance) rather than being indented by the tab's own\n * padding. Spacing between tabs is unaffected. Pair with `alignLeft` or\n * `variant=\"hug\"`. @default false\n */\n flushLeft?: boolean;\n /**\n * Scrolls the row horizontally when the tabs don't fit, instead of letting\n * them compress. By default a tab may shrink until its label ellipsises,\n * which on a narrow viewport can truncate every label at once; here each tab\n * keeps its natural width and the overflow scrolls. The scrollbar itself is\n * hidden — the clipped tab at the edge is the affordance.\n *\n * Because the tabs are content-sized, they no longer spread to fill the row:\n * a set that does fit sits left-aligned, as with `alignLeft`.\n *\n * Horizontal orientation only: a vertical list already grows downwards.\n * @default false\n */\n scrollable?: boolean;\n};\n\n/** Container for {@link TabsTrigger} elements. Renders a sliding active-tab indicator that animates between tabs. */\nexport const TabsList = React.forwardRef<\n React.ComponentRef<typeof TabsPrimitive.List>,\n TabsListProps\n>(\n (\n {\n className,\n children,\n fullWidth = true,\n alignLeft,\n variant,\n flushLeft = false,\n scrollable = false,\n ...props\n },\n ref,\n ) => {\n const innerRef = React.useRef<HTMLDivElement>(null);\n const indicatorRef = React.useRef<HTMLSpanElement>(null);\n\n React.useImperativeHandle(ref, () => innerRef.current as HTMLDivElement);\n\n const updateIndicator = React.useCallback(() => {\n const list = innerRef.current;\n const indicator = indicatorRef.current;\n if (!list || !indicator) return;\n\n const activeTab = list.querySelector<HTMLElement>('[data-state=\"active\"]');\n if (!activeTab) {\n indicator.style.opacity = \"0\";\n return;\n }\n\n const isVertical = list.dataset.orientation === \"vertical\";\n\n indicator.style.opacity = \"1\";\n\n if (isVertical) {\n indicator.style.background =\n \"linear-gradient(180deg, var(--color-buttons-tertiary-default) 0%, var(--color-tab-active) 50%, var(--color-buttons-tertiary-default) 100%)\";\n indicator.style.inset = `0 -1px auto auto`;\n indicator.style.width = \"1px\";\n indicator.style.height = `${activeTab.offsetHeight}px`;\n indicator.style.transform = `translateY(${activeTab.offsetTop}px)`;\n } else {\n indicator.style.background =\n \"linear-gradient(90deg, var(--color-buttons-tertiary-default) 0%, var(--color-tab-active) 50%, var(--color-buttons-tertiary-default) 100%)\";\n const textSpan = activeTab.querySelector(\"span\");\n const target = textSpan ?? activeTab;\n const textWidth = target.getBoundingClientRect().width;\n // Anchor to where the label actually sits, not to the tab's centre. The two\n // only coincide when the tab's horizontal padding is symmetric, which\n // `flushLeft` breaks by dropping `pl` on the first tab: the tab's centre then\n // sits `pr / 2` to the right of the label's. Measured as a difference of two\n // rects so it stays correct while a `scrollable` list is scrolled.\n const textOffsetInTab =\n target === activeTab\n ? 0\n : target.getBoundingClientRect().left - activeTab.getBoundingClientRect().left;\n const indicatorLeft = activeTab.offsetLeft + textOffsetInTab;\n indicator.style.inset = \"auto auto 0 0\";\n indicator.style.height = \"1px\";\n indicator.style.width = `${textWidth}px`;\n indicator.style.transform = `translateX(${indicatorLeft}px)`;\n }\n }, []);\n\n // Radix scrolls a tab into view when it takes focus, and mount is not focus, so\n // URL-driven state can land on a tab that is off to the right with nothing on\n // screen to say so: no indicator, and tab one showing as though it were active.\n // Assigns `scrollLeft` rather than calling `scrollIntoView`, which would also\n // scroll every ancestor and the page with it. Only ever scrolls further right, so\n // re-running it after the webfont settles corrects a short initial scroll without\n // yanking the row back from wherever the user has since dragged it.\n const revealActiveTab = React.useCallback(() => {\n const list = innerRef.current;\n if (!list || !scrollable || list.dataset.orientation === \"vertical\") return;\n const activeTab = list.querySelector<HTMLElement>('[data-state=\"active\"]');\n if (!activeTab) return;\n const overshoot = activeTab.offsetLeft + activeTab.offsetWidth - list.clientWidth;\n if (overshoot > list.scrollLeft) list.scrollLeft = overshoot;\n }, [scrollable]);\n\n React.useLayoutEffect(() => {\n const list = innerRef.current;\n const indicator = indicatorRef.current;\n if (!list || !indicator) return;\n\n indicator.style.transitionDuration = \"0s\";\n updateIndicator();\n indicator.getBoundingClientRect();\n indicator.style.transitionDuration = \"\";\n revealActiveTab();\n\n const mutationObserver = new MutationObserver(updateIndicator);\n mutationObserver.observe(list, {\n attributes: true,\n attributeFilter: [\"data-state\"],\n childList: true,\n subtree: true,\n });\n\n const resizeObserver = new ResizeObserver(updateIndicator);\n resizeObserver.observe(list);\n\n let cancelled = false;\n if (document.fonts?.status !== \"loaded\") {\n document.fonts?.ready.then(() => {\n if (cancelled) return;\n updateIndicator();\n // The tabs are wider once the real font is in, so the mount-time scroll can\n // fall short of the active tab. Recomputed here against the settled layout.\n revealActiveTab();\n });\n }\n\n return () => {\n cancelled = true;\n mutationObserver.disconnect();\n resizeObserver.disconnect();\n };\n }, [updateIndicator, revealActiveTab]);\n\n return (\n <TabsPrimitive.List\n ref={innerRef}\n className={cn(\n // `isolate` scopes the active indicator's `z-10` to a local stacking\n // context. Without it, `relative` alone creates no stacking context, so\n // the indicator escapes and paints above page chrome (e.g. the header).\n \"relative isolate\",\n getLayoutClass(variant, fullWidth, alignLeft),\n // Horizontal only: in the vertical orientation the leading padding is\n // the row's left inset, not a label offset, so zeroing it would pull\n // the first label out of line with the others.\n flushLeft && \"data-[orientation=horizontal]:[&>[role=tab]:first-child]:pl-0\",\n // `flex-none` is what stops the tabs compressing — without it they\n // share the row and never overflow, so there is nothing to scroll.\n // The scrollbar is hidden in both engines: Firefox reads\n // `scrollbar-width`, WebKit and Blink the pseudo-element.\n scrollable &&\n \"data-[orientation=horizontal]:overflow-x-auto data-[orientation=horizontal]:[scrollbar-width:none] data-[orientation=horizontal]:[&::-webkit-scrollbar]:hidden data-[orientation=horizontal]:[&>[role=tab]]:flex-none\",\n \"data-[orientation=horizontal]:items-center data-[orientation=horizontal]:shadow-[inset_0_-1px_0_0_var(--color-border-primary)]\",\n \"data-[orientation=vertical]:flex-col data-[orientation=vertical]:shadow-[inset_-1px_0_0_0_var(--color-border-primary)]\",\n className,\n )}\n {...props}\n >\n {children}\n <span\n ref={indicatorRef}\n aria-hidden\n className=\"pointer-events-none absolute z-10 rounded-full motion-safe:transition-[transform,width,height] motion-safe:duration-200 motion-safe:ease-in-out\"\n style={{ opacity: 0 }}\n />\n </TabsPrimitive.List>\n );\n },\n);\n\nTabsList.displayName = \"TabsList\";\n"],"names":["React","jsxs","TabsPrimitive","cn","jsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAOA,MAAM,mBAA0D;AAAA,EAC9D,QAAQ;AAAA,EACR,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AACN;AAEA,SAAS,eACP,SACA,WACA,WACQ;AACR,MAAI,YAAY,MAAO,QAAO;AAC9B,MAAI,YAAY,OAAQ,QAAO;AAE/B,MAAI,CAAC,UAAW,QAAO;AAEvB,QAAM,OAAO;AACb,MAAI,cAAc,KAAM,QAAO,GAAG,IAAI,IAAI,iBAAiB,MAAM;AACjE,MAAI,OAAO,cAAc,SAAU,QAAO,GAAG,IAAI,IAAI,iBAAiB,SAAS,CAAC;AAChF,SAAO;AACT;AAwCO,MAAM,WAAWA,iBAAM;AAAA,EAI5B,CACE;AAAA,IACE;AAAA,IACA;AA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;AAAA,UACA;AAAA,UACA;AAAA,QAAA;AAAA,QAED,GAAG;AAAA,QAEH,UAAA;AAAA,UAAA;AAAA,UACDC,2BAAAA;AAAAA,YAAC;AAAA,YAAA;AAAA,cACC,KAAK;AAAA,cACL,eAAW;AAAA,cACX,WAAU;AAAA,cACV,OAAO,EAAE,SAAS,EAAA;AAAA,YAAE;AAAA,UAAA;AAAA,QACtB;AAAA,MAAA;AAAA,IAAA;AAAA,EAGN;AACF;AAEA,SAAS,cAAc;;"}
|
|
1
|
+
{"version":3,"file":"TabsList.cjs","sources":["../../../../src/components/Tabs/TabsList.tsx"],"sourcesContent":["import * as TabsPrimitive from \"@radix-ui/react-tabs\";\nimport * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\n\n/** Breakpoint values for responsive props. */\ntype Breakpoint = \"sm\" | \"md\" | \"lg\" | \"xl\";\n\nconst alignLeftClasses: Record<Breakpoint | \"always\", string> = {\n always: \"[&>[role=tab]]:flex-initial\",\n sm: \"[&>[role=tab]]:sm:flex-initial\",\n md: \"[&>[role=tab]]:md:flex-initial\",\n lg: \"[&>[role=tab]]:lg:flex-initial\",\n xl: \"[&>[role=tab]]:xl:flex-initial\",\n};\n\nfunction getLayoutClass(\n variant: \"fill\" | \"hug\" | undefined,\n fullWidth: boolean,\n alignLeft?: boolean | Breakpoint,\n): string {\n if (variant === \"hug\") return \"inline-flex\";\n if (variant === \"fill\") return \"flex w-full [&>[role=tab]]:flex-1\";\n\n if (!fullWidth) return \"inline-flex\";\n\n const base = \"flex w-full [&>[role=tab]]:flex-1\";\n if (alignLeft === true) return `${base} ${alignLeftClasses.always}`;\n if (typeof alignLeft === \"string\") return `${base} ${alignLeftClasses[alignLeft]}`;\n return base;\n}\n\n/** Props for the {@link TabsList} component. */\nexport type TabsListProps = React.ComponentPropsWithoutRef<typeof TabsPrimitive.List> & {\n /** When `true` (the default), the tab list spans the full width of its container and each tab grows equally. Set to `false` for inline sizing. */\n fullWidth?: boolean;\n /**\n * Controls tab alignment within a full-width container.\n * - `false` (default): tabs spread evenly\n * - `true`: tabs left-aligned, sized to content\n * - `\"md\"` (breakpoint): spread on mobile, left-aligned at breakpoint and up\n */\n alignLeft?: boolean | Breakpoint;\n /** Explicit layout variant. `\"hug\"` sizes the list to its content; `\"fill\"` stretches it full-width with equal-width tabs. Takes precedence over `fullWidth`/`alignLeft`. */\n variant?: \"fill\" | \"hug\";\n /**\n * Drops the leading padding on the first tab so its label sits flush with the\n * list's left edge, lining it up with page content above or below the bar\n * (a heading, for instance) rather than being indented by the tab's own\n * padding. Spacing between tabs is unaffected. Pair with `alignLeft` or\n * `variant=\"hug\"`. @default false\n */\n flushLeft?: boolean;\n /**\n * Scrolls the row horizontally when the tabs don't fit, instead of letting\n * them compress. By default a tab may shrink until its label ellipsises,\n * which on a narrow viewport can truncate every label at once; here each tab\n * keeps its natural width and the overflow scrolls. The scrollbar itself is\n * hidden — the clipped tab at the edge is the affordance.\n *\n * Because the tabs are content-sized, they no longer spread to fill the row:\n * a set that does fit sits left-aligned, as with `alignLeft`.\n *\n * Horizontal orientation only: a vertical list already grows downwards.\n * @default false\n */\n scrollable?: boolean;\n};\n\n/** Container for {@link TabsTrigger} elements. Renders a sliding active-tab indicator that animates between tabs. */\nexport const TabsList = React.forwardRef<\n React.ComponentRef<typeof TabsPrimitive.List>,\n TabsListProps\n>(\n (\n {\n className,\n children,\n fullWidth = true,\n alignLeft,\n variant,\n flushLeft = false,\n scrollable = false,\n ...props\n },\n ref,\n ) => {\n const innerRef = React.useRef<HTMLDivElement>(null);\n const indicatorRef = React.useRef<HTMLSpanElement>(null);\n\n React.useImperativeHandle(ref, () => innerRef.current as HTMLDivElement);\n\n const updateIndicator = React.useCallback(() => {\n const list = innerRef.current;\n const indicator = indicatorRef.current;\n if (!list || !indicator) return;\n\n const activeTab = list.querySelector<HTMLElement>('[data-state=\"active\"]');\n if (!activeTab) {\n indicator.style.opacity = \"0\";\n return;\n }\n\n const isVertical = list.dataset.orientation === \"vertical\";\n\n indicator.style.opacity = \"1\";\n\n if (isVertical) {\n indicator.style.background =\n \"linear-gradient(180deg, var(--color-buttons-tertiary-default) 0%, var(--color-tab-active) 50%, var(--color-buttons-tertiary-default) 100%)\";\n indicator.style.inset = `0 -1px auto auto`;\n indicator.style.width = \"1px\";\n indicator.style.height = `${activeTab.offsetHeight}px`;\n indicator.style.transform = `translateY(${activeTab.offsetTop}px)`;\n } else {\n indicator.style.background =\n \"linear-gradient(90deg, var(--color-buttons-tertiary-default) 0%, var(--color-tab-active) 50%, var(--color-buttons-tertiary-default) 100%)\";\n indicator.style.inset = \"auto auto 0 0\";\n indicator.style.height = \"1px\";\n indicator.style.width = `${activeTab.offsetWidth}px`;\n indicator.style.transform = `translateX(${activeTab.offsetLeft}px)`;\n }\n }, []);\n\n // Radix scrolls a tab into view when it takes focus, and mount is not focus, so\n // URL-driven state can land on a tab that is off to the right with nothing on\n // screen to say so: no indicator, and tab one showing as though it were active.\n // Assigns `scrollLeft` rather than calling `scrollIntoView`, which would also\n // scroll every ancestor and the page with it. Only ever scrolls further right, so\n // re-running it after the webfont settles corrects a short initial scroll without\n // yanking the row back from wherever the user has since dragged it.\n const revealActiveTab = React.useCallback(() => {\n const list = innerRef.current;\n if (!list || !scrollable || list.dataset.orientation === \"vertical\") return;\n const activeTab = list.querySelector<HTMLElement>('[data-state=\"active\"]');\n if (!activeTab) return;\n const overshoot = activeTab.offsetLeft + activeTab.offsetWidth - list.clientWidth;\n if (overshoot > list.scrollLeft) list.scrollLeft = overshoot;\n }, [scrollable]);\n\n React.useLayoutEffect(() => {\n const list = innerRef.current;\n const indicator = indicatorRef.current;\n if (!list || !indicator) return;\n\n indicator.style.transitionDuration = \"0s\";\n updateIndicator();\n indicator.getBoundingClientRect();\n indicator.style.transitionDuration = \"\";\n revealActiveTab();\n\n const mutationObserver = new MutationObserver(updateIndicator);\n mutationObserver.observe(list, {\n attributes: true,\n attributeFilter: [\"data-state\"],\n childList: true,\n subtree: true,\n });\n\n const resizeObserver = new ResizeObserver(updateIndicator);\n resizeObserver.observe(list);\n\n let cancelled = false;\n if (document.fonts?.status !== \"loaded\") {\n document.fonts?.ready.then(() => {\n if (cancelled) return;\n updateIndicator();\n // The tabs are wider once the real font is in, so the mount-time scroll can\n // fall short of the active tab. Recomputed here against the settled layout.\n revealActiveTab();\n });\n }\n\n return () => {\n cancelled = true;\n mutationObserver.disconnect();\n resizeObserver.disconnect();\n };\n }, [updateIndicator, revealActiveTab]);\n\n return (\n <TabsPrimitive.List\n ref={innerRef}\n className={cn(\n // `isolate` scopes the active indicator's `z-10` to a local stacking\n // context. Without it, `relative` alone creates no stacking context, so\n // the indicator escapes and paints above page chrome (e.g. the header).\n \"relative isolate\",\n getLayoutClass(variant, fullWidth, alignLeft),\n // Horizontal only: in the vertical orientation the leading padding is\n // the row's left inset, not a label offset, so zeroing it would pull\n // the first label out of line with the others.\n flushLeft && \"data-[orientation=horizontal]:[&>[role=tab]:first-child]:pl-0\",\n // `flex-none` is what stops the tabs compressing — without it they\n // share the row and never overflow, so there is nothing to scroll.\n // The scrollbar is hidden in both engines: Firefox reads\n // `scrollbar-width`, WebKit and Blink the pseudo-element.\n scrollable &&\n \"data-[orientation=horizontal]:overflow-x-auto data-[orientation=horizontal]:[scrollbar-width:none] data-[orientation=horizontal]:[&::-webkit-scrollbar]:hidden data-[orientation=horizontal]:[&>[role=tab]]:flex-none\",\n \"data-[orientation=horizontal]:items-center data-[orientation=horizontal]:shadow-[inset_0_-1px_0_0_var(--color-border-primary)]\",\n \"data-[orientation=vertical]:flex-col data-[orientation=vertical]:shadow-[inset_-1px_0_0_0_var(--color-border-primary)]\",\n className,\n )}\n {...props}\n >\n {children}\n <span\n ref={indicatorRef}\n aria-hidden\n className=\"pointer-events-none absolute z-10 rounded-full motion-safe:transition-[transform,width,height] motion-safe:duration-200 motion-safe:ease-in-out\"\n style={{ opacity: 0 }}\n />\n </TabsPrimitive.List>\n );\n },\n);\n\nTabsList.displayName = \"TabsList\";\n"],"names":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;AACZ,yBAAiB,WAAA;AACjB,uBAAe,WAAA;AAAA,MACjB;AAAA,IACF,GAAG,CAAC,iBAAiB,eAAe,CAAC;AAErC,WACEC,2BAAAA;AAAAA,MAACC,yBAAc;AAAA,MAAd;AAAA,QACC,KAAK;AAAA,QACL,WAAWC,GAAAA;AAAAA;AAAAA;AAAAA;AAAAA,UAIT;AAAA,UACA,eAAe,SAAS,WAAW,SAAS;AAAA;AAAA;AAAA;AAAA,UAI5C,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA,UAKb,cACE;AAAA,UACF;AAAA,UACA;AAAA,UACA;AAAA,QAAA;AAAA,QAED,GAAG;AAAA,QAEH,UAAA;AAAA,UAAA;AAAA,UACDC,2BAAAA;AAAAA,YAAC;AAAA,YAAA;AAAA,cACC,KAAK;AAAA,cACL,eAAW;AAAA,cACX,WAAU;AAAA,cACV,OAAO,EAAE,SAAS,EAAA;AAAA,YAAE;AAAA,UAAA;AAAA,QACtB;AAAA,MAAA;AAAA,IAAA;AAAA,EAGN;AACF;AAEA,SAAS,cAAc;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TabsTrigger.cjs","sources":["../../../../src/components/Tabs/TabsTrigger.tsx"],"sourcesContent":["import * as TabsPrimitive from \"@radix-ui/react-tabs\";\nimport * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\n\n/** Props for the {@link TabsTrigger} button component. */\nexport type TabsTriggerProps = React.ComponentPropsWithoutRef<typeof TabsPrimitive.Trigger>;\n\n/**\n * An interactive tab that activates its associated {@link TabsContent} panel.\n *\n * Renders a `<button>` by default. Pass `asChild` to render the tab as another\n * element — e.g. a router link for navigation tabs (`<TabsTrigger asChild><Link\n * href=\"…\">…</Link></TabsTrigger>`). With `asChild` the child element becomes\n * the tab itself (receiving `role=\"tab\"` and focus management), so the tab\n * stays a single interactive control rather than nesting one inside the other.\n */\nexport const TabsTrigger = React.forwardRef<\n React.ComponentRef<typeof TabsPrimitive.Trigger>,\n TabsTriggerProps\n>(({ className, children, asChild, ...props }, ref) => {\n const label = <span className=\"min-w-0 truncate\">{children}</span>;\n\n // The `min-w-0 truncate` span keeps long labels ellipsised
|
|
1
|
+
{"version":3,"file":"TabsTrigger.cjs","sources":["../../../../src/components/Tabs/TabsTrigger.tsx"],"sourcesContent":["import * as TabsPrimitive from \"@radix-ui/react-tabs\";\nimport * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\n\n/** Props for the {@link TabsTrigger} button component. */\nexport type TabsTriggerProps = React.ComponentPropsWithoutRef<typeof TabsPrimitive.Trigger>;\n\n/**\n * An interactive tab that activates its associated {@link TabsContent} panel.\n *\n * Renders a `<button>` by default. Pass `asChild` to render the tab as another\n * element — e.g. a router link for navigation tabs (`<TabsTrigger asChild><Link\n * href=\"…\">…</Link></TabsTrigger>`). With `asChild` the child element becomes\n * the tab itself (receiving `role=\"tab\"` and focus management), so the tab\n * stays a single interactive control rather than nesting one inside the other.\n */\nexport const TabsTrigger = React.forwardRef<\n React.ComponentRef<typeof TabsPrimitive.Trigger>,\n TabsTriggerProps\n>(({ className, children, asChild, ...props }, ref) => {\n const label = <span className=\"min-w-0 truncate\">{children}</span>;\n\n // The `min-w-0 truncate` span keeps long labels ellipsised. With `asChild`\n // the consumer's element becomes the tab, so wrap *its* children in that\n // span (rather than wrapping the element) — the tab stays a single\n // interactive control (no nested link/button) while behaviour matches the\n // default button tab.\n const content =\n asChild && React.isValidElement(children)\n ? React.cloneElement(\n children,\n undefined,\n <span className=\"min-w-0 truncate\">\n {(children.props as { children?: React.ReactNode }).children}\n </span>,\n )\n : label;\n\n return (\n <TabsPrimitive.Trigger\n ref={ref}\n asChild={asChild}\n className={cn(\n \"inline-flex min-w-0 items-center justify-center\",\n \"typography-body-default-16px-semibold cursor-pointer\",\n \"motion-safe:transition-colors motion-safe:duration-150 motion-safe:ease-in-out\",\n \"data-[orientation=horizontal]:px-4 data-[orientation=horizontal]:py-3\",\n \"data-[orientation=vertical]:justify-start data-[orientation=vertical]:px-4 data-[orientation=vertical]:py-3\",\n \"data-[state=active]:text-content-primary\",\n \"data-[state=inactive]:text-content-tertiary\",\n \"data-[state=active]:hover:text-content-primary/70\",\n \"data-[state=inactive]:hover:text-content-primary\",\n \"data-[state=active]:active:text-content-primary/70\",\n \"data-[state=inactive]:active:text-content-primary\",\n \"data-disabled:pointer-events-none\",\n \"data-disabled:data-[state=active]:text-content-tertiary\",\n \"data-disabled:data-[state=inactive]:text-neutral-alphas-200\",\n \"focus-visible:shadow-focus-ring focus-visible:outline-none\",\n className,\n )}\n {...props}\n >\n {content}\n </TabsPrimitive.Trigger>\n );\n});\n\nTabsTrigger.displayName = \"TabsTrigger\";\n"],"names":["React","jsx","TabsPrimitive","cn"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAgBO,MAAM,cAAcA,iBAAM,WAG/B,CAAC,EAAE,WAAW,UAAU,SAAS,GAAG,MAAA,GAAS,QAAQ;AACrD,QAAM,QAAQC,2BAAAA,IAAC,QAAA,EAAK,WAAU,oBAAoB,UAAS;AAO3D,QAAM,UACJ,WAAWD,iBAAM,eAAe,QAAQ,IACpCA,iBAAM;AAAA,IACJ;AAAA,IACA;AAAA,mCACC,QAAA,EAAK,WAAU,oBACZ,UAAA,SAAS,MAAyC,SAAA,CACtD;AAAA,EAAA,IAEF;AAEN,SACEC,2BAAAA;AAAAA,IAACC,yBAAc;AAAA,IAAd;AAAA,MACC;AAAA,MACA;AAAA,MACA,WAAWC,GAAAA;AAAAA,QACT;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MAAA;AAAA,MAED,GAAG;AAAA,MAEH,UAAA;AAAA,IAAA;AAAA,EAAA;AAGP,CAAC;AAED,YAAY,cAAc;;"}
|
|
@@ -30,73 +30,6 @@ function _interopNamespaceDefault(e) {
|
|
|
30
30
|
return Object.freeze(n);
|
|
31
31
|
}
|
|
32
32
|
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
33
|
-
const DEFAULT_WAVEFORM = [
|
|
34
|
-
0.15,
|
|
35
|
-
0.46,
|
|
36
|
-
0.85,
|
|
37
|
-
0.23,
|
|
38
|
-
1,
|
|
39
|
-
0.85,
|
|
40
|
-
0.62,
|
|
41
|
-
0.62,
|
|
42
|
-
0.62,
|
|
43
|
-
0.85,
|
|
44
|
-
0.85,
|
|
45
|
-
0.62,
|
|
46
|
-
0.62,
|
|
47
|
-
1,
|
|
48
|
-
1,
|
|
49
|
-
0.62,
|
|
50
|
-
0.62,
|
|
51
|
-
0.62,
|
|
52
|
-
0.23,
|
|
53
|
-
0.23,
|
|
54
|
-
0.15,
|
|
55
|
-
0.46,
|
|
56
|
-
0.85,
|
|
57
|
-
0.23,
|
|
58
|
-
1,
|
|
59
|
-
0.46,
|
|
60
|
-
0.85,
|
|
61
|
-
0.62,
|
|
62
|
-
0.23,
|
|
63
|
-
0.23,
|
|
64
|
-
0.62,
|
|
65
|
-
0.62,
|
|
66
|
-
0.85,
|
|
67
|
-
0.85,
|
|
68
|
-
0.62,
|
|
69
|
-
0.62,
|
|
70
|
-
0.85,
|
|
71
|
-
1,
|
|
72
|
-
0.85,
|
|
73
|
-
1,
|
|
74
|
-
0.62,
|
|
75
|
-
0.62,
|
|
76
|
-
0.62,
|
|
77
|
-
0.23,
|
|
78
|
-
0.23,
|
|
79
|
-
0.62,
|
|
80
|
-
0.23,
|
|
81
|
-
0.23,
|
|
82
|
-
0.23,
|
|
83
|
-
0.62,
|
|
84
|
-
0.85,
|
|
85
|
-
0.62,
|
|
86
|
-
0.85,
|
|
87
|
-
1,
|
|
88
|
-
0.85,
|
|
89
|
-
0.85,
|
|
90
|
-
1,
|
|
91
|
-
0.85,
|
|
92
|
-
0.23,
|
|
93
|
-
0.23,
|
|
94
|
-
0.23,
|
|
95
|
-
0.46,
|
|
96
|
-
0.62,
|
|
97
|
-
0.23,
|
|
98
|
-
0.23
|
|
99
|
-
];
|
|
100
33
|
const MIN_BAR_HEIGHT = 4;
|
|
101
34
|
const MAX_BAR_HEIGHT = {
|
|
102
35
|
default: 26,
|
|
@@ -155,7 +88,7 @@ const VoiceNote = React__namespace.forwardRef(
|
|
|
155
88
|
className,
|
|
156
89
|
src,
|
|
157
90
|
duration,
|
|
158
|
-
waveform =
|
|
91
|
+
waveform = audioWaveform.DEFAULT_WAVEFORM_PEAKS,
|
|
159
92
|
variant = "default",
|
|
160
93
|
size = "default",
|
|
161
94
|
negative = false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VoiceNote.cjs","sources":["../../../../src/components/VoiceNote/VoiceNote.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { formatTime, resamplePeaks } from \"@/utils/audioWaveform\";\nimport { cn } from \"@/utils/cn\";\nimport { useAudioPlayback } from \"@/utils/useAudioPlayback\";\nimport { useFittedBarCount } from \"@/utils/useFittedBarCount\";\nimport { useWaveformPeaks } from \"@/utils/useWaveformPeaks\";\nimport { useWaveformSeek } from \"@/utils/useWaveformSeek\";\nimport { IconButton, type IconButtonSize } from \"../IconButton/IconButton\";\nimport { CloseIcon } from \"../Icons/CloseIcon\";\nimport { PauseIcon } from \"../Icons/PauseIcon\";\nimport { PlayIcon } from \"../Icons/PlayIcon\";\n\n/** Visual style of the waveform. */\nexport type VoiceNoteVariant = \"default\" | \"flat\";\n\n/** Size preset for the voice note. */\nexport type VoiceNoteSize = \"default\" | \"small\";\n\n/**\n * Default waveform amplitudes (0–1), taken from the Figma reference so the\n * resting state renders 1:1 when no `waveform` data (or `src`) is supplied.\n */\nconst DEFAULT_WAVEFORM = [\n 0.15, 0.46, 0.85, 0.23, 1, 0.85, 0.62, 0.62, 0.62, 0.85, 0.85, 0.62, 0.62, 1, 1, 0.62, 0.62, 0.62,\n 0.23, 0.23, 0.15, 0.46, 0.85, 0.23, 1, 0.46, 0.85, 0.62, 0.23, 0.23, 0.62, 0.62, 0.85, 0.85, 0.62,\n 0.62, 0.85, 1, 0.85, 1, 0.62, 0.62, 0.62, 0.23, 0.23, 0.62, 0.23, 0.23, 0.23, 0.62, 0.85, 0.62,\n 0.85, 1, 0.85, 0.85, 1, 0.85, 0.23, 0.23, 0.23, 0.46, 0.62, 0.23, 0.23,\n];\n\nconst MIN_BAR_HEIGHT = 4;\nconst MAX_BAR_HEIGHT: Record<VoiceNoteSize, number> = {\n default: 26,\n small: 16,\n};\n\nconst CONTROL_SIZE: Record<VoiceNoteSize, IconButtonSize> = {\n default: \"48\",\n small: \"32\",\n};\n\n/** Rendered width of a single waveform bar, in pixels (`w-1`). */\nconst BAR_WIDTH_PX = 4;\n/** Gap between waveform bars, in pixels (`gap-1`). */\nconst BAR_GAP_PX = 4;\n/** Bar count before the track is measured (SSR, jsdom, or zero-width layout). */\nconst DEFAULT_BAR_COUNT = 40;\n\nfunction activeBarClass(negative: boolean): string {\n return negative\n ? \"bg-messages-waveform-listening-negative-active\"\n : \"bg-messages-waveform-listening-active\";\n}\n\nfunction inactiveBarClass(negative: boolean): string {\n return negative\n ? \"bg-messages-waveform-listening-negative-inactive\"\n : \"bg-messages-waveform-listening-inactive\";\n}\n\nfunction restingBarClass(negative: boolean): string {\n return negative\n ? \"bg-messages-waveform-listening-negative-default\"\n : \"bg-messages-waveform-default\";\n}\n\ninterface WaveformBarsProps {\n bars: number[];\n variant: VoiceNoteVariant;\n size: VoiceNoteSize;\n negative: boolean;\n progress: number | undefined;\n}\n\nfunction WaveformBars({ bars, variant, size, negative, progress }: WaveformBarsProps) {\n const hasProgress = progress !== undefined;\n const activeCount = hasProgress ? Math.round(progress * bars.length) : 0;\n const maxBarHeight = MAX_BAR_HEIGHT[size];\n\n return (\n <>\n {bars.map((amplitude, index) => {\n const height =\n variant === \"flat\"\n ? MIN_BAR_HEIGHT\n : Math.max(MIN_BAR_HEIGHT, Math.round(amplitude * maxBarHeight));\n const colorClass = !hasProgress\n ? restingBarClass(negative)\n : index < activeCount\n ? activeBarClass(negative)\n : inactiveBarClass(negative);\n\n return (\n <span\n // biome-ignore lint/suspicious/noArrayIndexKey: bars are a fixed positional sequence\n key={index}\n className={cn(\"w-1 shrink-0 rounded-[2px]\", colorClass)}\n style={{ height }}\n />\n );\n })}\n </>\n );\n}\n\ninterface WaveformMetaProps {\n time: string | undefined;\n fileName: string | undefined;\n textColor: string;\n}\n\nfunction WaveformMeta({ time, fileName, textColor }: WaveformMetaProps) {\n return (\n <>\n {time && (\n <span className={cn(\"typography-body-small-14px-regular shrink-0\", textColor)}>{time}</span>\n )}\n {fileName && (\n <span\n className={cn(\n \"typography-body-small-14px-regular min-w-0 max-w-[50%] truncate\",\n textColor,\n )}\n >\n {fileName}\n </span>\n )}\n </>\n );\n}\n\nexport interface VoiceNoteProps\n extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onPlay\" | \"onPause\"> {\n /**\n * URL of the audio to play. When set, the component manages a real `<audio>`\n * element: it decodes the waveform, plays/pauses, tracks live progress and is\n * seekable — `waveform`/`progress` are derived automatically. Leave unset for\n * a presentational, fully-controlled voice note.\n */\n src?: string;\n /** Fallback total duration (seconds), used until the media's metadata loads. */\n duration?: number;\n /** Amplitude values (0–1), one per bar. Ignored when `src` is set. Falls back to a built-in pattern. */\n waveform?: number[];\n /** Visual style; `flat` renders a simplified dotted preview. @default \"default\" */\n variant?: VoiceNoteVariant;\n /** Size preset. @default \"default\" */\n size?: VoiceNoteSize;\n /** Dark-surface treatment for use on message bubbles. @default false */\n negative?: boolean;\n /**\n * Playback progress (0–1) for the presentational mode. When set, the waveform\n * splits into played/unplayed bars (the \"Listening\" state). Ignored when `src`\n * is set (progress comes from the media element).\n */\n progress?: number;\n /** Whether audio is playing (controlled) — toggles the play/pause icon. */\n playing?: boolean;\n /** Initial playing state (uncontrolled). @default false */\n defaultPlaying?: boolean;\n /** Called with the next playing state when the play/pause control is pressed. */\n onPlayPause?: (playing: boolean) => void;\n /** Called when audio playback reaches the end (only in `src` mode). */\n onEnded?: () => void;\n /** Timestamp or duration label, e.g. \"0:05\". Ignored when `src` is set (derived from the media). */\n time?: string;\n /** File name shown when the audio is an uploaded file rather than a voice note. */\n fileName?: string;\n /** Show the play/pause control. @default true */\n showControls?: boolean;\n /** Show the timestamp label. @default true */\n showTimestamp?: boolean;\n /** Show a remove button (calls {@link VoiceNoteProps.onRemove}). @default false */\n showRemove?: boolean;\n /** Called when the remove button is pressed. */\n onRemove?: () => void;\n /** Accessible name for the play/pause control. Defaults to \"Play\"/\"Pause\". */\n playButtonLabel?: string;\n /** Accessible name for the remove button. @default \"Remove\" */\n removeButtonLabel?: string;\n /** Accessible name for the whole player. @default \"Voice note\" */\n \"aria-label\"?: string;\n}\n\n/**\n * A voice-note audio player: a play/pause control, an amplitude waveform, and a\n * timestamp — for voice messages and audio attachments in a conversation.\n *\n * Two modes: pass `src` for a self-contained player that decodes the waveform,\n * plays real audio, tracks live progress and is seekable; or omit `src` and\n * drive it with `playing`/`progress` + `onPlayPause` for a presentational,\n * fully-controlled voice note. `flat` renders a compact dotted preview and\n * `negative` adapts it to dark message bubbles.\n *\n * @example\n * ```tsx\n * <VoiceNote src=\"https://example.com/note.mp3\" duration={5} />\n * <VoiceNote time=\"0:05\" progress={0.4} playing onPlayPause={toggle} />\n * ```\n */\nexport const VoiceNote = React.forwardRef<HTMLDivElement, VoiceNoteProps>(\n (\n {\n className,\n src,\n duration,\n waveform = DEFAULT_WAVEFORM,\n variant = \"default\",\n size = \"default\",\n negative = false,\n progress,\n playing,\n defaultPlaying = false,\n onPlayPause,\n onEnded,\n time,\n fileName,\n showControls = true,\n showTimestamp = true,\n showRemove = false,\n onRemove,\n playButtonLabel,\n removeButtonLabel = \"Remove\",\n \"aria-label\": ariaLabel = \"Voice note\",\n ...props\n },\n ref,\n ) => {\n const isPlayer = src !== undefined;\n\n const playback = useAudioPlayback({\n src,\n duration,\n playing,\n defaultPlaying,\n onEnded,\n onPlay: React.useCallback(() => onPlayPause?.(true), [onPlayPause]),\n onPause: React.useCallback(() => onPlayPause?.(false), [onPlayPause]),\n });\n const decodedPeaks = useWaveformPeaks(src);\n\n const [internalPlaying, setInternalPlaying] = React.useState(defaultPlaying);\n const isControlled = playing !== undefined;\n\n const trackRef = React.useRef<HTMLDivElement>(null);\n const fittedBarCount = useFittedBarCount(trackRef, {\n barWidthPx: BAR_WIDTH_PX,\n gapPx: BAR_GAP_PX,\n fallback: DEFAULT_BAR_COUNT,\n });\n const seekProps = useWaveformSeek({\n trackRef,\n displayDuration: playback.displayDuration,\n currentTime: playback.currentTime,\n seekTo: playback.seekTo,\n setSeeking: playback.setSeeking,\n });\n\n const isPlaying = isPlayer ? playback.isPlaying : (playing ?? internalPlaying);\n\n const handlePlayPause = () => {\n if (isPlayer) {\n playback.toggle();\n return;\n }\n const next = !isPlaying;\n if (!isControlled) setInternalPlaying(next);\n onPlayPause?.(next);\n };\n\n const bars = resamplePeaks(isPlayer ? decodedPeaks : waveform, fittedBarCount);\n const progressValue = isPlayer ? playback.progress : progress;\n const textColor = negative ? \"text-content-primary-inverted\" : \"text-content-primary\";\n\n const playerTime = playback.hasStarted ? playback.currentTime : playback.displayDuration;\n const displayTime = isPlayer ? formatTime(playerTime) : time;\n const controlLabel = playButtonLabel ?? (isPlaying ? \"Pause\" : \"Play\");\n const trackAria = isPlayer ? seekProps : ({ \"aria-hidden\": true } as const);\n\n return (\n // biome-ignore lint/a11y/useSemanticElements: <fieldset> would break the public HTMLDivElement ref/props API\n <div\n ref={ref}\n role=\"group\"\n aria-label={ariaLabel}\n className={cn(\"flex items-center gap-3\", size === \"small\" ? \"h-8\" : \"h-12\", className)}\n {...props}\n >\n {showControls && (\n <IconButton\n variant=\"secondary\"\n size={CONTROL_SIZE[size]}\n negative={negative}\n icon={isPlaying ? <PauseIcon /> : <PlayIcon />}\n aria-label={controlLabel}\n onClick={handlePlayPause}\n />\n )}\n\n <div\n ref={trackRef}\n data-testid=\"voice-note-waveform\"\n className={cn(\n \"flex h-full min-w-0 flex-1 items-center gap-1 overflow-hidden\",\n isPlayer &&\n \"cursor-pointer touch-none select-none focus-visible:shadow-focus-ring focus-visible:outline-none\",\n )}\n {...trackAria}\n >\n <WaveformBars\n bars={bars}\n variant={variant}\n size={size}\n negative={negative}\n progress={progressValue}\n />\n </div>\n\n <WaveformMeta\n time={showTimestamp ? displayTime : undefined}\n fileName={fileName}\n textColor={textColor}\n />\n\n {showRemove && (\n <IconButton\n variant=\"tertiary\"\n size={CONTROL_SIZE[size]}\n negative={negative}\n icon={<CloseIcon />}\n aria-label={removeButtonLabel}\n onClick={onRemove}\n />\n )}\n\n {isPlayer && (\n // biome-ignore lint/a11y/useMediaCaption: a UI voice note / short recording, not narrated content needing captions\n <audio\n ref={playback.audioRef}\n src={src}\n preload=\"metadata\"\n className=\"hidden\"\n onLoadedMetadata={playback.audioHandlers.onLoadedMetadata}\n onTimeUpdate={playback.audioHandlers.onTimeUpdate}\n onEnded={playback.audioHandlers.onEnded}\n />\n )}\n </div>\n );\n },\n);\n\nVoiceNote.displayName = \"VoiceNote\";\n"],"names":["jsx","Fragment","cn","jsxs","React","useAudioPlayback","useWaveformPeaks","useFittedBarCount","useWaveformSeek","resamplePeaks","formatTime","IconButton","PauseIcon","PlayIcon","CloseIcon"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAM,mBAAmB;AAAA,EACvB;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAG;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAG;AAAA,EAAG;AAAA,EAAM;AAAA,EAAM;AAAA,EAC7F;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAG;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA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EAIR;AACF;AAEA,UAAU,cAAc;;"}
|
|
1
|
+
{"version":3,"file":"VoiceNote.cjs","sources":["../../../../src/components/VoiceNote/VoiceNote.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { DEFAULT_WAVEFORM_PEAKS, formatTime, resamplePeaks } from \"@/utils/audioWaveform\";\nimport { cn } from \"@/utils/cn\";\nimport { useAudioPlayback } from \"@/utils/useAudioPlayback\";\nimport { useFittedBarCount } from \"@/utils/useFittedBarCount\";\nimport { useWaveformPeaks } from \"@/utils/useWaveformPeaks\";\nimport { useWaveformSeek } from \"@/utils/useWaveformSeek\";\nimport { IconButton, type IconButtonSize } from \"../IconButton/IconButton\";\nimport { CloseIcon } from \"../Icons/CloseIcon\";\nimport { PauseIcon } from \"../Icons/PauseIcon\";\nimport { PlayIcon } from \"../Icons/PlayIcon\";\n\n/** Visual style of the waveform. */\nexport type VoiceNoteVariant = \"default\" | \"flat\";\n\n/** Size preset for the voice note. */\nexport type VoiceNoteSize = \"default\" | \"small\";\n\nconst MIN_BAR_HEIGHT = 4;\nconst MAX_BAR_HEIGHT: Record<VoiceNoteSize, number> = {\n default: 26,\n small: 16,\n};\n\nconst CONTROL_SIZE: Record<VoiceNoteSize, IconButtonSize> = {\n default: \"48\",\n small: \"32\",\n};\n\n/** Rendered width of a single waveform bar, in pixels (`w-1`). */\nconst BAR_WIDTH_PX = 4;\n/** Gap between waveform bars, in pixels (`gap-1`). */\nconst BAR_GAP_PX = 4;\n/** Bar count before the track is measured (SSR, jsdom, or zero-width layout). */\nconst DEFAULT_BAR_COUNT = 40;\n\nfunction activeBarClass(negative: boolean): string {\n return negative\n ? \"bg-messages-waveform-listening-negative-active\"\n : \"bg-messages-waveform-listening-active\";\n}\n\nfunction inactiveBarClass(negative: boolean): string {\n return negative\n ? \"bg-messages-waveform-listening-negative-inactive\"\n : \"bg-messages-waveform-listening-inactive\";\n}\n\nfunction restingBarClass(negative: boolean): string {\n return negative\n ? \"bg-messages-waveform-listening-negative-default\"\n : \"bg-messages-waveform-default\";\n}\n\ninterface WaveformBarsProps {\n bars: number[];\n variant: VoiceNoteVariant;\n size: VoiceNoteSize;\n negative: boolean;\n progress: number | undefined;\n}\n\nfunction WaveformBars({ bars, variant, size, negative, progress }: WaveformBarsProps) {\n const hasProgress = progress !== undefined;\n const activeCount = hasProgress ? Math.round(progress * bars.length) : 0;\n const maxBarHeight = MAX_BAR_HEIGHT[size];\n\n return (\n <>\n {bars.map((amplitude, index) => {\n const height =\n variant === \"flat\"\n ? MIN_BAR_HEIGHT\n : Math.max(MIN_BAR_HEIGHT, Math.round(amplitude * maxBarHeight));\n const colorClass = !hasProgress\n ? restingBarClass(negative)\n : index < activeCount\n ? activeBarClass(negative)\n : inactiveBarClass(negative);\n\n return (\n <span\n // biome-ignore lint/suspicious/noArrayIndexKey: bars are a fixed positional sequence\n key={index}\n className={cn(\"w-1 shrink-0 rounded-[2px]\", colorClass)}\n style={{ height }}\n />\n );\n })}\n </>\n );\n}\n\ninterface WaveformMetaProps {\n time: string | undefined;\n fileName: string | undefined;\n textColor: string;\n}\n\nfunction WaveformMeta({ time, fileName, textColor }: WaveformMetaProps) {\n return (\n <>\n {time && (\n <span className={cn(\"typography-body-small-14px-regular shrink-0\", textColor)}>{time}</span>\n )}\n {fileName && (\n <span\n className={cn(\n \"typography-body-small-14px-regular min-w-0 max-w-[50%] truncate\",\n textColor,\n )}\n >\n {fileName}\n </span>\n )}\n </>\n );\n}\n\nexport interface VoiceNoteProps\n extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onPlay\" | \"onPause\"> {\n /**\n * URL of the audio to play. When set, the component manages a real `<audio>`\n * element: it decodes the waveform, plays/pauses, tracks live progress and is\n * seekable — `waveform`/`progress` are derived automatically. Leave unset for\n * a presentational, fully-controlled voice note.\n */\n src?: string;\n /** Fallback total duration (seconds), used until the media's metadata loads. */\n duration?: number;\n /** Amplitude values (0–1), one per bar. Ignored when `src` is set. Falls back to a built-in pattern. */\n waveform?: number[];\n /** Visual style; `flat` renders a simplified dotted preview. @default \"default\" */\n variant?: VoiceNoteVariant;\n /** Size preset. @default \"default\" */\n size?: VoiceNoteSize;\n /** Dark-surface treatment for use on message bubbles. @default false */\n negative?: boolean;\n /**\n * Playback progress (0–1) for the presentational mode. When set, the waveform\n * splits into played/unplayed bars (the \"Listening\" state). Ignored when `src`\n * is set (progress comes from the media element).\n */\n progress?: number;\n /** Whether audio is playing (controlled) — toggles the play/pause icon. */\n playing?: boolean;\n /** Initial playing state (uncontrolled). @default false */\n defaultPlaying?: boolean;\n /** Called with the next playing state when the play/pause control is pressed. */\n onPlayPause?: (playing: boolean) => void;\n /** Called when audio playback reaches the end (only in `src` mode). */\n onEnded?: () => void;\n /** Timestamp or duration label, e.g. \"0:05\". Ignored when `src` is set (derived from the media). */\n time?: string;\n /** File name shown when the audio is an uploaded file rather than a voice note. */\n fileName?: string;\n /** Show the play/pause control. @default true */\n showControls?: boolean;\n /** Show the timestamp label. @default true */\n showTimestamp?: boolean;\n /** Show a remove button (calls {@link VoiceNoteProps.onRemove}). @default false */\n showRemove?: boolean;\n /** Called when the remove button is pressed. */\n onRemove?: () => void;\n /** Accessible name for the play/pause control. Defaults to \"Play\"/\"Pause\". */\n playButtonLabel?: string;\n /** Accessible name for the remove button. @default \"Remove\" */\n removeButtonLabel?: string;\n /** Accessible name for the whole player. @default \"Voice note\" */\n \"aria-label\"?: string;\n}\n\n/**\n * A voice-note audio player: a play/pause control, an amplitude waveform, and a\n * timestamp — for voice messages and audio attachments in a conversation.\n *\n * Two modes: pass `src` for a self-contained player that decodes the waveform,\n * plays real audio, tracks live progress and is seekable; or omit `src` and\n * drive it with `playing`/`progress` + `onPlayPause` for a presentational,\n * fully-controlled voice note. `flat` renders a compact dotted preview and\n * `negative` adapts it to dark message bubbles.\n *\n * @example\n * ```tsx\n * <VoiceNote src=\"https://example.com/note.mp3\" duration={5} />\n * <VoiceNote time=\"0:05\" progress={0.4} playing onPlayPause={toggle} />\n * ```\n */\nexport const VoiceNote = React.forwardRef<HTMLDivElement, VoiceNoteProps>(\n (\n {\n className,\n src,\n duration,\n waveform = DEFAULT_WAVEFORM_PEAKS,\n variant = \"default\",\n size = \"default\",\n negative = false,\n progress,\n playing,\n defaultPlaying = false,\n onPlayPause,\n onEnded,\n time,\n fileName,\n showControls = true,\n showTimestamp = true,\n showRemove = false,\n onRemove,\n playButtonLabel,\n removeButtonLabel = \"Remove\",\n \"aria-label\": ariaLabel = \"Voice note\",\n ...props\n },\n ref,\n ) => {\n const isPlayer = src !== undefined;\n\n const playback = useAudioPlayback({\n src,\n duration,\n playing,\n defaultPlaying,\n onEnded,\n onPlay: React.useCallback(() => onPlayPause?.(true), [onPlayPause]),\n onPause: React.useCallback(() => onPlayPause?.(false), [onPlayPause]),\n });\n const decodedPeaks = useWaveformPeaks(src);\n\n const [internalPlaying, setInternalPlaying] = React.useState(defaultPlaying);\n const isControlled = playing !== undefined;\n\n const trackRef = React.useRef<HTMLDivElement>(null);\n const fittedBarCount = useFittedBarCount(trackRef, {\n barWidthPx: BAR_WIDTH_PX,\n gapPx: BAR_GAP_PX,\n fallback: DEFAULT_BAR_COUNT,\n });\n const seekProps = useWaveformSeek({\n trackRef,\n displayDuration: playback.displayDuration,\n currentTime: playback.currentTime,\n seekTo: playback.seekTo,\n setSeeking: playback.setSeeking,\n });\n\n const isPlaying = isPlayer ? playback.isPlaying : (playing ?? internalPlaying);\n\n const handlePlayPause = () => {\n if (isPlayer) {\n playback.toggle();\n return;\n }\n const next = !isPlaying;\n if (!isControlled) setInternalPlaying(next);\n onPlayPause?.(next);\n };\n\n const bars = resamplePeaks(isPlayer ? decodedPeaks : waveform, fittedBarCount);\n const progressValue = isPlayer ? playback.progress : progress;\n const textColor = negative ? \"text-content-primary-inverted\" : \"text-content-primary\";\n\n const playerTime = playback.hasStarted ? playback.currentTime : playback.displayDuration;\n const displayTime = isPlayer ? formatTime(playerTime) : time;\n const controlLabel = playButtonLabel ?? (isPlaying ? \"Pause\" : \"Play\");\n const trackAria = isPlayer ? seekProps : ({ \"aria-hidden\": true } as const);\n\n return (\n // biome-ignore lint/a11y/useSemanticElements: <fieldset> would break the public HTMLDivElement ref/props API\n <div\n ref={ref}\n role=\"group\"\n aria-label={ariaLabel}\n className={cn(\"flex items-center gap-3\", size === \"small\" ? \"h-8\" : \"h-12\", className)}\n {...props}\n >\n {showControls && (\n <IconButton\n variant=\"secondary\"\n size={CONTROL_SIZE[size]}\n negative={negative}\n icon={isPlaying ? <PauseIcon /> : <PlayIcon />}\n aria-label={controlLabel}\n onClick={handlePlayPause}\n />\n )}\n\n <div\n ref={trackRef}\n data-testid=\"voice-note-waveform\"\n className={cn(\n \"flex h-full min-w-0 flex-1 items-center gap-1 overflow-hidden\",\n isPlayer &&\n \"cursor-pointer touch-none select-none focus-visible:shadow-focus-ring focus-visible:outline-none\",\n )}\n {...trackAria}\n >\n <WaveformBars\n bars={bars}\n variant={variant}\n size={size}\n negative={negative}\n progress={progressValue}\n />\n </div>\n\n <WaveformMeta\n time={showTimestamp ? displayTime : undefined}\n fileName={fileName}\n textColor={textColor}\n />\n\n {showRemove && (\n <IconButton\n variant=\"tertiary\"\n size={CONTROL_SIZE[size]}\n negative={negative}\n icon={<CloseIcon />}\n aria-label={removeButtonLabel}\n onClick={onRemove}\n />\n )}\n\n {isPlayer && (\n // biome-ignore lint/a11y/useMediaCaption: a UI voice note / short recording, not narrated content needing captions\n <audio\n ref={playback.audioRef}\n src={src}\n preload=\"metadata\"\n className=\"hidden\"\n onLoadedMetadata={playback.audioHandlers.onLoadedMetadata}\n onTimeUpdate={playback.audioHandlers.onTimeUpdate}\n onEnded={playback.audioHandlers.onEnded}\n />\n )}\n </div>\n );\n },\n);\n\nVoiceNote.displayName = \"VoiceNote\";\n"],"names":["jsx","Fragment","cn","jsxs","React","DEFAULT_WAVEFORM_PEAKS","useAudioPlayback","useWaveformPeaks","useFittedBarCount","useWaveformSeek","resamplePeaks","formatTime","IconButton","PauseIcon","PlayIcon","CloseIcon"],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AA;AAAA,gBAEH,GAAG;AAAA,gBAEJ,UAAAF,2BAAAA;AAAAA,kBAAC;AAAA,kBAAA;AAAA,oBACC;AAAA,oBACA;AAAA,oBACA;AAAA,oBACA;AAAA,oBACA,UAAU;AAAA,kBAAA;AAAA,gBAAA;AAAA,cACZ;AAAA,YAAA;AAAA,YAGFA,2BAAAA;AAAAA,cAAC;AAAA,cAAA;AAAA,gBACC,MAAM,gBAAgB,cAAc;AAAA,gBACpC;AAAA,gBACA;AAAA,cAAA;AAAA,YAAA;AAAA,YAGD,cACCA,2BAAAA;AAAAA,cAACY,WAAAA;AAAAA,cAAA;AAAA,gBACC,SAAQ;AAAA,gBACR,MAAM,aAAa,IAAI;AAAA,gBACvB;AAAA,gBACA,qCAAOG,UAAAA,WAAA,EAAU;AAAA,gBACjB,cAAY;AAAA,gBACZ,SAAS;AAAA,cAAA;AAAA,YAAA;AAAA,YAIZ;AAAA,YAECf,2BAAAA;AAAAA,cAAC;AAAA,cAAA;AAAA,gBACC,KAAK,SAAS;AAAA,gBACd;AAAA,gBACA,SAAQ;AAAA,gBACR,WAAU;AAAA,gBACV,kBAAkB,SAAS,cAAc;AAAA,gBACzC,cAAc,SAAS,cAAc;AAAA,gBACrC,SAAS,SAAS,cAAc;AAAA,cAAA;AAAA,YAAA;AAAA,UAClC;AAAA,QAAA;AAAA,MAAA;AAAA;AAAA,EAIR;AACF;AAEA,UAAU,cAAc;;"}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -45,6 +45,7 @@ const EmptyState = require("./components/EmptyState/EmptyState.cjs");
|
|
|
45
45
|
const FanFollowerCount = require("./components/FanFollowerCount/FanFollowerCount.cjs");
|
|
46
46
|
const FloatingActionButton = require("./components/FloatingActionButton/FloatingActionButton.cjs");
|
|
47
47
|
const IconButton = require("./components/IconButton/IconButton.cjs");
|
|
48
|
+
const AddCircleIcon = require("./components/Icons/AddCircleIcon.cjs");
|
|
48
49
|
const AddIcon = require("./components/Icons/AddIcon.cjs");
|
|
49
50
|
const AffiliatesIcon = require("./components/Icons/AffiliatesIcon.cjs");
|
|
50
51
|
const AI2Icon = require("./components/Icons/AI2Icon.cjs");
|
|
@@ -267,8 +268,10 @@ const UserHandle = require("./components/UserHandle/UserHandle.cjs");
|
|
|
267
268
|
const UserItem = require("./components/UserItem/UserItem.cjs");
|
|
268
269
|
const UserItemTrailing = require("./components/UserItem/UserItemTrailing.cjs");
|
|
269
270
|
const VoiceNote = require("./components/VoiceNote/VoiceNote.cjs");
|
|
271
|
+
const audioWaveform = require("./utils/audioWaveform.cjs");
|
|
270
272
|
const cn = require("./utils/cn.cjs");
|
|
271
273
|
const getInitials = require("./utils/getInitials.cjs");
|
|
274
|
+
const useFittedBarCount = require("./utils/useFittedBarCount.cjs");
|
|
272
275
|
const useSuppressClickAfterDrag = require("./utils/useSuppressClickAfterDrag.cjs");
|
|
273
276
|
Object.defineProperty(exports, "Slot", {
|
|
274
277
|
enumerable: true,
|
|
@@ -361,6 +364,7 @@ exports.EmptyState = EmptyState.EmptyState;
|
|
|
361
364
|
exports.FanFollowerCount = FanFollowerCount.FanFollowerCount;
|
|
362
365
|
exports.FloatingActionButton = FloatingActionButton.FloatingActionButton;
|
|
363
366
|
exports.IconButton = IconButton.IconButton;
|
|
367
|
+
exports.AddCircleIcon = AddCircleIcon.AddCircleIcon;
|
|
364
368
|
exports.AddIcon = AddIcon.AddIcon;
|
|
365
369
|
exports.AffiliatesIcon = AffiliatesIcon.AffiliatesIcon;
|
|
366
370
|
exports.AI2Icon = AI2Icon.AI2Icon;
|
|
@@ -614,7 +618,11 @@ exports.UserHandle = UserHandle.UserHandle;
|
|
|
614
618
|
exports.UserItem = UserItem.UserItem;
|
|
615
619
|
exports.UserItemTrailing = UserItemTrailing.UserItemTrailing;
|
|
616
620
|
exports.VoiceNote = VoiceNote.VoiceNote;
|
|
621
|
+
exports.DEFAULT_WAVEFORM_PEAKS = audioWaveform.DEFAULT_WAVEFORM_PEAKS;
|
|
622
|
+
exports.formatTime = audioWaveform.formatTime;
|
|
623
|
+
exports.resamplePeaks = audioWaveform.resamplePeaks;
|
|
617
624
|
exports.cn = cn.cn;
|
|
618
625
|
exports.getInitials = getInitials.getInitials;
|
|
626
|
+
exports.useFittedBarCount = useFittedBarCount.useFittedBarCount;
|
|
619
627
|
exports.useSuppressClickAfterDrag = useSuppressClickAfterDrag.useSuppressClickAfterDrag;
|
|
620
628
|
//# sourceMappingURL=index.cjs.map
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -2,6 +2,73 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
4
4
|
const RAW_PEAK_COUNT = 128;
|
|
5
|
+
const DEFAULT_WAVEFORM_PEAKS = [
|
|
6
|
+
0.15,
|
|
7
|
+
0.46,
|
|
8
|
+
0.85,
|
|
9
|
+
0.23,
|
|
10
|
+
1,
|
|
11
|
+
0.85,
|
|
12
|
+
0.62,
|
|
13
|
+
0.62,
|
|
14
|
+
0.62,
|
|
15
|
+
0.85,
|
|
16
|
+
0.85,
|
|
17
|
+
0.62,
|
|
18
|
+
0.62,
|
|
19
|
+
1,
|
|
20
|
+
1,
|
|
21
|
+
0.62,
|
|
22
|
+
0.62,
|
|
23
|
+
0.62,
|
|
24
|
+
0.23,
|
|
25
|
+
0.23,
|
|
26
|
+
0.15,
|
|
27
|
+
0.46,
|
|
28
|
+
0.85,
|
|
29
|
+
0.23,
|
|
30
|
+
1,
|
|
31
|
+
0.46,
|
|
32
|
+
0.85,
|
|
33
|
+
0.62,
|
|
34
|
+
0.23,
|
|
35
|
+
0.23,
|
|
36
|
+
0.62,
|
|
37
|
+
0.62,
|
|
38
|
+
0.85,
|
|
39
|
+
0.85,
|
|
40
|
+
0.62,
|
|
41
|
+
0.62,
|
|
42
|
+
0.85,
|
|
43
|
+
1,
|
|
44
|
+
0.85,
|
|
45
|
+
1,
|
|
46
|
+
0.62,
|
|
47
|
+
0.62,
|
|
48
|
+
0.62,
|
|
49
|
+
0.23,
|
|
50
|
+
0.23,
|
|
51
|
+
0.62,
|
|
52
|
+
0.23,
|
|
53
|
+
0.23,
|
|
54
|
+
0.23,
|
|
55
|
+
0.62,
|
|
56
|
+
0.85,
|
|
57
|
+
0.62,
|
|
58
|
+
0.85,
|
|
59
|
+
1,
|
|
60
|
+
0.85,
|
|
61
|
+
0.85,
|
|
62
|
+
1,
|
|
63
|
+
0.85,
|
|
64
|
+
0.23,
|
|
65
|
+
0.23,
|
|
66
|
+
0.23,
|
|
67
|
+
0.46,
|
|
68
|
+
0.62,
|
|
69
|
+
0.23,
|
|
70
|
+
0.23
|
|
71
|
+
];
|
|
5
72
|
function formatTime(seconds) {
|
|
6
73
|
if (seconds === void 0 || !Number.isFinite(seconds)) return "--:--";
|
|
7
74
|
const totalSeconds = Math.max(0, Math.floor(seconds));
|
|
@@ -65,6 +132,7 @@ async function decodeAudioPeaks(src, signal) {
|
|
|
65
132
|
});
|
|
66
133
|
}
|
|
67
134
|
}
|
|
135
|
+
exports.DEFAULT_WAVEFORM_PEAKS = DEFAULT_WAVEFORM_PEAKS;
|
|
68
136
|
exports.RAW_PEAK_COUNT = RAW_PEAK_COUNT;
|
|
69
137
|
exports.computePeaksFromChannelData = computePeaksFromChannelData;
|
|
70
138
|
exports.createSeededRandom = createSeededRandom;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audioWaveform.cjs","sources":["../../../src/utils/audioWaveform.ts"],"sourcesContent":["/** Number of amplitude samples decoded/kept internally, resampled to the rendered bar count. */\nexport const RAW_PEAK_COUNT = 128;\n\n
|
|
1
|
+
{"version":3,"file":"audioWaveform.cjs","sources":["../../../src/utils/audioWaveform.ts"],"sourcesContent":["/** Number of amplitude samples decoded/kept internally, resampled to the rendered bar count. */\nexport const RAW_PEAK_COUNT = 128;\n\n/**\n * Waveform amplitudes (0–1) taken from the Figma reference, so a waveform with\n * no real peak data still renders 1:1 with the design. Used by\n * {@link VoiceNote} and available to consumers building their own waveform out\n * of {@link resamplePeaks} and {@link useFittedBarCount}.\n */\nexport const DEFAULT_WAVEFORM_PEAKS = [\n 0.15, 0.46, 0.85, 0.23, 1, 0.85, 0.62, 0.62, 0.62, 0.85, 0.85, 0.62, 0.62, 1, 1, 0.62, 0.62, 0.62,\n 0.23, 0.23, 0.15, 0.46, 0.85, 0.23, 1, 0.46, 0.85, 0.62, 0.23, 0.23, 0.62, 0.62, 0.85, 0.85, 0.62,\n 0.62, 0.85, 1, 0.85, 1, 0.62, 0.62, 0.62, 0.23, 0.23, 0.62, 0.23, 0.23, 0.23, 0.62, 0.85, 0.62,\n 0.85, 1, 0.85, 0.85, 1, 0.85, 0.23, 0.23, 0.23, 0.46, 0.62, 0.23, 0.23,\n];\n\n/**\n * Formats a duration in seconds as `m:ss`, or `--:--` when unknown. Matches the\n * timestamp {@link VoiceNote} renders, so waveforms built elsewhere read the\n * same.\n */\nexport function formatTime(seconds: number | undefined): string {\n if (seconds === undefined || !Number.isFinite(seconds)) return \"--:--\";\n const totalSeconds = Math.max(0, Math.floor(seconds));\n const minutes = Math.floor(totalSeconds / 60);\n const remainingSeconds = totalSeconds % 60;\n return `${minutes}:${String(remainingSeconds).padStart(2, \"0\")}`;\n}\n\n/** Deterministic 32-bit string hash (FNV-1a), used to seed the fallback waveform. */\nexport function hashString(value: string): number {\n let hash = 2166136261;\n for (let i = 0; i < value.length; i++) {\n hash ^= value.charCodeAt(i);\n hash = Math.imul(hash, 16777619);\n }\n return hash >>> 0;\n}\n\n/** Seeded PRNG (mulberry32) — deterministic across runs, unlike `Math.random`. */\nexport function createSeededRandom(seed: number): () => number {\n let state = seed;\n return () => {\n state = (state + 0x6d2b79f5) | 0;\n let t = Math.imul(state ^ (state >>> 15), 1 | state);\n t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;\n return ((t ^ (t >>> 14)) >>> 0) / 4294967296;\n };\n}\n\n/** Deterministic placeholder amplitudes used when audio can't be decoded (network/CORS/format failure). */\nexport function generateFallbackPeaks(src: string, count: number): number[] {\n const random = createSeededRandom(hashString(src));\n return Array.from({ length: count }, () => 0.2 + random() * 0.8);\n}\n\n/** Downsamples decoded PCM data to `count` peak (max-abs) amplitudes. */\nexport function computePeaksFromChannelData(channelData: Float32Array, count: number): number[] {\n const blockSize = Math.max(1, Math.floor(channelData.length / count));\n const peaks: number[] = [];\n for (let i = 0; i < count; i++) {\n const start = i * blockSize;\n let max = 0;\n for (let j = 0; j < blockSize && start + j < channelData.length; j++) {\n max = Math.max(max, Math.abs(channelData[start + j] ?? 0));\n }\n peaks.push(max);\n }\n return peaks;\n}\n\n/** Resamples a peaks array to `barCount` values (nearest-neighbour). */\nexport function resamplePeaks(peaks: number[], barCount: number): number[] {\n if (peaks.length === 0 || barCount <= 0) return [];\n const step = peaks.length / barCount;\n return Array.from(\n { length: barCount },\n (_, i) => peaks[Math.min(peaks.length - 1, Math.floor(i * step))] ?? 0,\n );\n}\n\n/** Decodes `src` via WebAudio and returns downsampled peak amplitudes. Throws on any failure. */\nexport async function decodeAudioPeaks(src: string, signal: AbortSignal): Promise<number[]> {\n const AudioContextCtor =\n window.AudioContext ??\n (window as unknown as { webkitAudioContext?: typeof AudioContext }).webkitAudioContext;\n if (!AudioContextCtor) throw new Error(\"WebAudio unsupported\");\n\n const response = await fetch(src, { signal });\n const arrayBuffer = await response.arrayBuffer();\n const audioContext = new AudioContextCtor();\n try {\n const audioBuffer = await audioContext.decodeAudioData(arrayBuffer);\n return computePeaksFromChannelData(audioBuffer.getChannelData(0), RAW_PEAK_COUNT);\n } finally {\n if (audioContext.state !== \"closed\") audioContext.close().catch(() => {});\n }\n}\n"],"names":[],"mappings":";;;AACO,MAAM,iBAAiB;AAQvB,MAAM,yBAAyB;AAAA,EACpC;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAG;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAG;AAAA,EAAG;AAAA,EAAM;AAAA,EAAM;AAAA,EAC7F;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAG;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAC7F;AAAA,EAAM;AAAA,EAAM;AAAA,EAAG;AAAA,EAAM;A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_CLASSES = {
|
|
|
81
81
|
disabled: DISABLED_FILL
|
|
82
82
|
},
|
|
83
83
|
ai: {
|
|
84
|
-
default: `border border-transparent text-content-
|
|
84
|
+
default: `border border-transparent text-content-primary shadow-ai-button-glow ${AI_GRADIENT}`,
|
|
85
85
|
disabled: DISABLED_FILL
|
|
86
86
|
},
|
|
87
87
|
link: {
|