@spark-ui/components 17.10.5-beta.0 → 17.11.1

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.
Files changed (173) hide show
  1. package/dist/accordion/index.js +1 -1
  2. package/dist/accordion/index.js.map +1 -1
  3. package/dist/accordion/index.mjs +1 -1
  4. package/dist/accordion/index.mjs.map +1 -1
  5. package/dist/alert-dialog/index.js +1 -1
  6. package/dist/alert-dialog/index.js.map +1 -1
  7. package/dist/alert-dialog/index.mjs +1 -1
  8. package/dist/alert-dialog/index.mjs.map +1 -1
  9. package/dist/avatar/index.js +1 -1
  10. package/dist/avatar/index.js.map +1 -1
  11. package/dist/avatar/index.mjs +17 -17
  12. package/dist/avatar/index.mjs.map +1 -1
  13. package/dist/button/index.js +1 -1
  14. package/dist/button/index.mjs +1 -1
  15. package/dist/{button-BtuAr9qV.mjs → button-CNabSkd_.mjs} +2 -2
  16. package/dist/{button-BtuAr9qV.mjs.map → button-CNabSkd_.mjs.map} +1 -1
  17. package/dist/{button-BaJmiSYq.js → button-Tv2N8_24.js} +2 -2
  18. package/dist/{button-BaJmiSYq.js.map → button-Tv2N8_24.js.map} +1 -1
  19. package/dist/card/index.js +1 -1
  20. package/dist/card/index.js.map +1 -1
  21. package/dist/card/index.mjs +1 -1
  22. package/dist/card/index.mjs.map +1 -1
  23. package/dist/carousel/index.js +1 -1
  24. package/dist/carousel/index.js.map +1 -1
  25. package/dist/carousel/index.mjs +2 -2
  26. package/dist/carousel/index.mjs.map +1 -1
  27. package/dist/checkbox/index.js +1 -1
  28. package/dist/checkbox/index.mjs +1 -1
  29. package/dist/{checkbox-xsURzANi.mjs → checkbox-CbMh-21q.mjs} +2 -2
  30. package/dist/{checkbox-xsURzANi.mjs.map → checkbox-CbMh-21q.mjs.map} +1 -1
  31. package/dist/{checkbox-DjwbAH09.js → checkbox-hVGRiWC_.js} +2 -2
  32. package/dist/{checkbox-DjwbAH09.js.map → checkbox-hVGRiWC_.js.map} +1 -1
  33. package/dist/chip/index.js +1 -1
  34. package/dist/chip/index.js.map +1 -1
  35. package/dist/chip/index.mjs +1 -1
  36. package/dist/chip/index.mjs.map +1 -1
  37. package/dist/circular-meter/index.js +1 -1
  38. package/dist/circular-meter/index.js.map +1 -1
  39. package/dist/circular-meter/index.mjs +28 -28
  40. package/dist/circular-meter/index.mjs.map +1 -1
  41. package/dist/combobox/index.js +1 -1
  42. package/dist/combobox/index.js.map +1 -1
  43. package/dist/combobox/index.mjs +10 -13
  44. package/dist/combobox/index.mjs.map +1 -1
  45. package/dist/dialog/index.js +1 -1
  46. package/dist/dialog/index.js.map +1 -1
  47. package/dist/dialog/index.mjs +2 -2
  48. package/dist/dialog/index.mjs.map +1 -1
  49. package/dist/drawer/index.js +1 -1
  50. package/dist/drawer/index.js.map +1 -1
  51. package/dist/drawer/index.mjs +2 -2
  52. package/dist/drawer/index.mjs.map +1 -1
  53. package/dist/dropdown/index.js +1 -1
  54. package/dist/dropdown/index.js.map +1 -1
  55. package/dist/dropdown/index.mjs +9 -12
  56. package/dist/dropdown/index.mjs.map +1 -1
  57. package/dist/file-upload/index.js +1 -1
  58. package/dist/file-upload/index.js.map +1 -1
  59. package/dist/file-upload/index.mjs +5 -5
  60. package/dist/file-upload/index.mjs.map +1 -1
  61. package/dist/form-field/index.js +1 -1
  62. package/dist/form-field/index.mjs +1 -1
  63. package/dist/form-field-BCqHBvWN.js +2 -0
  64. package/dist/form-field-BCqHBvWN.js.map +1 -0
  65. package/dist/{form-field-CV5dzt-I.mjs → form-field-ByLHXtzx.mjs} +27 -27
  66. package/dist/form-field-ByLHXtzx.mjs.map +1 -0
  67. package/dist/icon-button/index.js +1 -1
  68. package/dist/icon-button/index.mjs +1 -1
  69. package/dist/icon-button-CTe0v0g7.js +2 -0
  70. package/dist/{icon-button-BSVlcyAO.js.map → icon-button-CTe0v0g7.js.map} +1 -1
  71. package/dist/{icon-button-XyQSaVPL.mjs → icon-button-DVbKK2_a.mjs} +3 -3
  72. package/dist/{icon-button-XyQSaVPL.mjs.map → icon-button-DVbKK2_a.mjs.map} +1 -1
  73. package/dist/input/index.js +1 -1
  74. package/dist/input/index.mjs +1 -1
  75. package/dist/{input-CJOeEIbx.mjs → input-BxuTPD5-.mjs} +6 -6
  76. package/dist/input-BxuTPD5-.mjs.map +1 -0
  77. package/dist/input-DIGSkxbh.js +2 -0
  78. package/dist/input-DIGSkxbh.js.map +1 -0
  79. package/dist/input-otp/index.js +1 -1
  80. package/dist/input-otp/index.js.map +1 -1
  81. package/dist/input-otp/index.mjs +27 -17
  82. package/dist/input-otp/index.mjs.map +1 -1
  83. package/dist/menu/index.js +1 -1
  84. package/dist/menu/index.js.map +1 -1
  85. package/dist/menu/index.mjs +1 -1
  86. package/dist/menu/index.mjs.map +1 -1
  87. package/dist/meter/index.js +1 -1
  88. package/dist/meter/index.js.map +1 -1
  89. package/dist/meter/index.mjs +17 -17
  90. package/dist/meter/index.mjs.map +1 -1
  91. package/dist/pagination/index.js +1 -1
  92. package/dist/pagination/index.js.map +1 -1
  93. package/dist/pagination/index.mjs +3 -3
  94. package/dist/pagination/index.mjs.map +1 -1
  95. package/dist/popover/index.js +1 -1
  96. package/dist/popover/index.mjs +1 -1
  97. package/dist/{popover-CSmCERcL.mjs → popover-83FABwMs.mjs} +3 -3
  98. package/dist/popover-83FABwMs.mjs.map +1 -0
  99. package/dist/popover-Daknmg_Z.js +2 -0
  100. package/dist/popover-Daknmg_Z.js.map +1 -0
  101. package/dist/progress/index.js +1 -1
  102. package/dist/progress/index.mjs +1 -1
  103. package/dist/{progress-C-Zs94G2.mjs → progress-BfpWgeE1.mjs} +2 -2
  104. package/dist/{progress-C-Zs94G2.mjs.map → progress-BfpWgeE1.mjs.map} +1 -1
  105. package/dist/{progress-DaQt4olK.js → progress-DBD2FiQ1.js} +2 -2
  106. package/dist/{progress-DaQt4olK.js.map → progress-DBD2FiQ1.js.map} +1 -1
  107. package/dist/progress-tracker/index.js +1 -1
  108. package/dist/progress-tracker/index.js.map +1 -1
  109. package/dist/progress-tracker/index.mjs +4 -4
  110. package/dist/progress-tracker/index.mjs.map +1 -1
  111. package/dist/radio-group/index.js +1 -1
  112. package/dist/radio-group/index.js.map +1 -1
  113. package/dist/radio-group/index.mjs +5 -8
  114. package/dist/radio-group/index.mjs.map +1 -1
  115. package/dist/rating/index.js +1 -1
  116. package/dist/rating/index.mjs +1 -1
  117. package/dist/rating-display/index.js +1 -1
  118. package/dist/rating-display/index.js.map +1 -1
  119. package/dist/rating-display/index.mjs +1 -1
  120. package/dist/rating-display/index.mjs.map +1 -1
  121. package/dist/scrolling-list/index.js +1 -1
  122. package/dist/scrolling-list/index.js.map +1 -1
  123. package/dist/scrolling-list/index.mjs +17 -17
  124. package/dist/scrolling-list/index.mjs.map +1 -1
  125. package/dist/segmented-control/index.js +1 -1
  126. package/dist/segmented-control/index.js.map +1 -1
  127. package/dist/segmented-control/index.mjs +1 -1
  128. package/dist/segmented-control/index.mjs.map +1 -1
  129. package/dist/segmented-gauge/index.js +1 -1
  130. package/dist/segmented-gauge/index.js.map +1 -1
  131. package/dist/segmented-gauge/index.mjs +1 -1
  132. package/dist/segmented-gauge/index.mjs.map +1 -1
  133. package/dist/select/index.js +1 -1
  134. package/dist/select/index.js.map +1 -1
  135. package/dist/select/index.mjs +2 -2
  136. package/dist/select/index.mjs.map +1 -1
  137. package/dist/slider/index.js +1 -1
  138. package/dist/slider/index.js.map +1 -1
  139. package/dist/slider/index.mjs +2 -2
  140. package/dist/slider/index.mjs.map +1 -1
  141. package/dist/stepper/index.js +1 -1
  142. package/dist/stepper/index.js.map +1 -1
  143. package/dist/stepper/index.mjs +3 -3
  144. package/dist/stepper/index.mjs.map +1 -1
  145. package/dist/table/index.js +1 -1
  146. package/dist/table/index.js.map +1 -1
  147. package/dist/table/index.mjs +36 -36
  148. package/dist/table/index.mjs.map +1 -1
  149. package/dist/tabs/index.js +1 -1
  150. package/dist/tabs/index.js.map +1 -1
  151. package/dist/tabs/index.mjs +16 -16
  152. package/dist/tabs/index.mjs.map +1 -1
  153. package/dist/tag/index.js +1 -1
  154. package/dist/tag/index.js.map +1 -1
  155. package/dist/tag/index.mjs +1 -1
  156. package/dist/tag/index.mjs.map +1 -1
  157. package/dist/textarea/index.js +1 -1
  158. package/dist/textarea/index.js.map +1 -1
  159. package/dist/textarea/index.mjs +2 -2
  160. package/dist/textarea/index.mjs.map +1 -1
  161. package/dist/toast/index.js +1 -1
  162. package/dist/toast/index.mjs +2 -2
  163. package/package.json +5 -5
  164. package/dist/form-field-CV5dzt-I.mjs.map +0 -1
  165. package/dist/form-field-CYGgse45.js +0 -2
  166. package/dist/form-field-CYGgse45.js.map +0 -1
  167. package/dist/icon-button-BSVlcyAO.js +0 -2
  168. package/dist/input-CJOeEIbx.mjs.map +0 -1
  169. package/dist/input-Dv436NKY.js +0 -2
  170. package/dist/input-Dv436NKY.js.map +0 -1
  171. package/dist/popover-CSmCERcL.mjs.map +0 -1
  172. package/dist/popover-CsCB_Fgs.js +0 -2
  173. package/dist/popover-CsCB_Fgs.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/scrolling-list/ScrollingList.tsx","../../src/scrolling-list/ScrollingListControls.tsx","../../src/scrolling-list/useFocusWithinScroll.tsx","../../src/scrolling-list/ScrollingListItem.tsx","../../src/scrolling-list/ScrollingListItems.tsx","../../src/scrolling-list/ScrollingListNextButton.tsx","../../src/scrolling-list/ScrollingListPrevButton.tsx","../../src/scrolling-list/ScrollingListSkipButton.tsx","../../src/scrolling-list/index.ts"],"sourcesContent":["import { ScrollOverflow, useScrollOverflow } from '@spark-ui/hooks/use-scroll-overflow'\nimport { cx } from 'class-variance-authority'\nimport {\n ComponentPropsWithRef,\n createContext,\n ReactNode,\n RefObject,\n useCallback,\n useEffect,\n useLayoutEffect,\n useRef,\n} from 'react'\nimport { SnapCarouselResult, useSnapCarousel } from 'react-snap-carousel'\n\ntype SnapType = 'mandatory' | 'proximity' | 'none'\ntype ScrollBehavior = 'smooth' | 'instant'\ntype SnapStop = 'normal' | 'always'\n\ninterface Props extends ComponentPropsWithRef<'div'> {\n /**\n * CSS scroll snap behavior.\n * - `mandatory` to force snapping on each \"page\".\n * - `proximity` to force snapping only when scroll position is near the edge of a \"page\". Behavior can change depending on each browser.\n * - `none` to disabled scroll snapping.\n */\n snapType?: SnapType\n /**\n * Defines whether or not the scroll container is allowed to \"pass over\" possible snap positions.\n */\n snapStop?: SnapStop\n scrollBehavior?: ScrollBehavior\n /**\n * Add a fade effect to indicate content overflow.\n */\n withFade?: boolean\n children?: ReactNode\n /**\n * When `true`, allow previous and next buttons to be used when reaching the edges of the list.\n */\n loop?: boolean\n /**\n * Space (in pixels) between items.\n */\n gap?: number\n /**\n * Offset (in pixels) of the left of the optimal viewing region of the list.\n */\n scrollPadding?: number\n className?: string\n}\n\ninterface ScrollingListContextState extends SnapCarouselResult {\n snapType: SnapType\n snapStop: SnapStop\n scrollBehavior: ScrollBehavior\n visibleItemsRange: readonly [number, number]\n loop: boolean\n gap: number\n withFade: boolean\n scrollPadding: number\n scrollAreaRef: RefObject<HTMLDivElement | null>\n overflow: ScrollOverflow\n skipKeyboardNavigation: () => void\n}\n\nexport const ScrollingListContext = createContext<ScrollingListContextState>(\n null as unknown as ScrollingListContextState\n)\n\nexport const ScrollingList = ({\n snapType = 'none',\n snapStop = 'normal',\n scrollBehavior = 'smooth',\n loop = false,\n gap = 16,\n withFade = false,\n scrollPadding = 0,\n children,\n className,\n ...rest\n}: Props) => {\n const scrollAreaRef = useRef<HTMLDivElement>(null)\n const skipAnchorRef = useRef<HTMLButtonElement>(null)\n\n const snapCarouselAPI = useSnapCarousel()\n\n const { overflow, refresh: refreshOverflow } = useScrollOverflow(scrollAreaRef, {\n precisionTreshold: 1,\n })\n\n const { activePageIndex, pages, refresh } = snapCarouselAPI\n\n const visibleItems = pages[activePageIndex] as number[]\n\n const visibleItemsRange = visibleItems\n ? ([visibleItems[0]! + 1, visibleItems[visibleItems.length - 1]! + 1] as const)\n : ([0, 0] as const)\n\n // Force refresh of the carousel API when children change\n const forceRefresh = useCallback(() => {\n if (refresh && scrollAreaRef.current) {\n // Small delay to ensure DOM is updated\n setTimeout(() => {\n refresh()\n }, 0)\n }\n }, [refresh])\n\n useEffect(() => {\n forceRefresh()\n }, [children, forceRefresh])\n\n useLayoutEffect(() => {\n if (scrollAreaRef.current) {\n // Use requestAnimationFrame to ensure proper timing with the render cycle\n // This prevents race conditions that occur when the console is closed\n requestAnimationFrame(() => {\n refreshOverflow()\n })\n }\n }, [children, refreshOverflow])\n\n const skipKeyboardNavigation = () => {\n skipAnchorRef.current?.focus()\n }\n\n const ctxValue: ScrollingListContextState = {\n ...snapCarouselAPI,\n snapType,\n snapStop,\n skipKeyboardNavigation,\n scrollBehavior,\n visibleItemsRange,\n loop,\n gap,\n withFade,\n scrollPadding,\n scrollAreaRef,\n overflow,\n }\n\n return (\n <ScrollingListContext.Provider value={ctxValue}>\n <div\n data-spark-component=\"scrolling-list\"\n className={cx(\n 'gap-lg group/scrolling-list relative flex flex-col default:w-full',\n className\n )}\n {...rest}\n >\n {children}\n </div>\n <span ref={skipAnchorRef} className=\"size-0 overflow-hidden\" tabIndex={-1} />\n </ScrollingListContext.Provider>\n )\n}\n\nScrollingList.displayName = 'ScrollingList'\n","import { cx } from 'class-variance-authority'\nimport { ComponentPropsWithoutRef, CSSProperties, ReactNode } from 'react'\n\ninterface ScrollingListControls extends ComponentPropsWithoutRef<'div'> {\n /**\n * Visibility behavior of the control buttons:\n * - `always`: buttons are always visible.\n * - `hover`: buttons only appear on hover.\n *\n * a11y: `hover` is dangerous for accessibility as it disabled controls for touch screen users.\n * When using it, you must provide an alternative control outside of the list to replace them.\n */\n visibility?: 'hover' | 'always'\n children: ReactNode\n}\n\n/** Container for navigation controls (previous/next buttons) of the scrolling list. Renders a <div> element. */\nexport const ScrollingListControls = ({\n children,\n visibility = 'always',\n className,\n ...rest\n}: ScrollingListControls) => {\n return (\n <div\n data-spark-component=\"scrolling-list-controls\"\n className={cx(\n 'default:px-md pointer-events-none absolute inset-0 flex flex-row items-center justify-between overflow-hidden',\n className\n )}\n style={\n {\n '--scrolling-list-controls-opacity': visibility === 'hover' ? '0' : '1',\n } as CSSProperties\n }\n data-orientation=\"horizontal\"\n {...rest}\n >\n {children}\n </div>\n )\n}\n\nScrollingListControls.displayName = 'ScrollingList.Controls'\n","import { RefObject, useEffect, useState } from 'react'\n\nexport function useFocusWithinScroll<T extends HTMLElement | null>(\n ref: RefObject<T>, // The container to detect focus within\n scrollRef: RefObject<HTMLDivElement | null> // The scrollable container\n) {\n const [isFocusWithin, setIsFocusWithin] = useState(false)\n\n useEffect(() => {\n const handleFocusIn = (event: FocusEvent) => {\n setIsFocusWithin(true)\n\n const focusedElement = event.target as HTMLElement\n const scrollContainer = scrollRef.current\n\n if (focusedElement && scrollContainer) {\n const focusRect = focusedElement.getBoundingClientRect()\n const scrollRect = scrollContainer.getBoundingClientRect()\n\n // Check if the focused element is fully visible inside the scroll container\n const isFullyVisible =\n focusRect.left >= scrollRect.left &&\n focusRect.right <= scrollRect.right &&\n focusRect.top >= scrollRect.top &&\n focusRect.bottom <= scrollRect.bottom\n\n if (!isFullyVisible) {\n focusedElement.scrollIntoView({ behavior: 'smooth', inline: 'center', block: 'nearest' })\n }\n }\n }\n\n const handleFocusOut = (event: FocusEvent) => {\n if (ref.current && !ref.current.contains(event.relatedTarget as Node)) {\n setIsFocusWithin(false)\n }\n }\n\n const node = ref.current\n if (node) {\n node.addEventListener('focusin', handleFocusIn)\n node.addEventListener('focusout', handleFocusOut)\n }\n\n return () => {\n if (node) {\n node.removeEventListener('focusin', handleFocusIn)\n node.removeEventListener('focusout', handleFocusOut)\n }\n }\n }, [ref, scrollRef])\n\n return isFocusWithin\n}\n","import { cx } from 'class-variance-authority'\nimport { ComponentPropsWithoutRef, ReactNode, useContext, useRef } from 'react'\n\nimport { Slot } from '../slot'\nimport { ScrollingListContext } from './ScrollingList'\nimport { useFocusWithinScroll } from './useFocusWithinScroll'\n\nexport interface ScrollingListItemProps extends ComponentPropsWithoutRef<'div'> {\n /**\n * Change the default rendered element for the one passed as a child, merging their props and behavior.\n */\n asChild?: boolean\n children?: ReactNode\n /**\n * DO NOT USE. This prop is automatically managed by the parent ScrollingList.ListItems\n */\n index?: number\n className?: string\n}\n\n/** A single item in the scrolling list. Renders a <div> element. */\nexport const ScrollingListItem = ({\n asChild = false,\n children,\n index = 0,\n className = '',\n ...rest\n}: ScrollingListItemProps) => {\n const ctx = useContext(ScrollingListContext)\n const itemRef = useRef<HTMLDivElement>(null)\n\n const isSnapPoint = ctx.snapPointIndexes.has(index)\n\n useFocusWithinScroll(itemRef, ctx.scrollAreaRef)\n\n const Component = asChild ? Slot : 'div'\n\n return (\n <Component\n data-spark-component=\"scrolling-list-item\"\n role=\"listitem\"\n ref={itemRef}\n className={cx(\n 'default:w-auto default:shrink-0',\n {\n 'snap-start': isSnapPoint,\n 'snap-normal': isSnapPoint && ctx.snapStop === 'normal',\n 'snap-always': isSnapPoint && ctx.snapStop === 'always',\n },\n className\n )}\n {...rest}\n >\n {children}\n </Component>\n )\n}\n\nScrollingListItem.displayName = 'ScrollingList.Item'\n","import { cx } from 'class-variance-authority'\nimport {\n Children,\n cloneElement,\n ComponentPropsWithRef,\n CSSProperties,\n isValidElement,\n KeyboardEvent,\n ReactNode,\n Ref,\n RefObject,\n useContext,\n} from 'react'\n\nimport { ScrollingListContext } from './ScrollingList'\nimport { ScrollingListItemProps } from './ScrollingListItem'\n\ninterface Props extends ComponentPropsWithRef<'div'> {\n children?: ReactNode\n className?: string\n}\n\nexport function mergeRefs<T>(...refs: (Ref<T> | undefined | null)[]): Ref<T> {\n return (value: T | null) => {\n refs.forEach(ref => {\n if (typeof ref === 'function') {\n ref(value)\n } else if (ref && typeof ref === 'object' && 'current' in ref) {\n ;(ref as RefObject<T | null>).current = value\n }\n })\n }\n}\n\n/** The scrollable container for the list items. Renders a <div> element. */\nexport const ScrollingListItems = ({ children, ref, className = '', ...rest }: Props) => {\n const ctx = useContext(ScrollingListContext)\n\n const snapConfig = {\n mandatory: 'x mandatory',\n proximity: 'x proximity',\n none: 'none',\n }\n\n const handleLeftArrow = (event: KeyboardEvent<HTMLDivElement>) => {\n if (!ctx.loop && !ctx.hasPrevPage) return\n\n event.preventDefault()\n ctx.goTo(ctx.hasPrevPage ? ctx.activePageIndex - 1 : ctx.pages.length - 1, {\n behavior: ctx.scrollBehavior,\n })\n }\n\n const handleRightArrow = (event: KeyboardEvent<HTMLDivElement>) => {\n if (!ctx.loop && !ctx.hasNextPage) return\n\n event.preventDefault()\n ctx.goTo(ctx.hasNextPage ? ctx.activePageIndex + 1 : 0, { behavior: ctx.scrollBehavior })\n }\n\n const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n if (event.key === 'ArrowLeft') {\n handleLeftArrow(event)\n }\n\n if (event.key === 'ArrowRight') {\n handleRightArrow(event)\n }\n }\n\n interface CustomCSSProperties extends CSSProperties {\n '--scrolling-list-gap'?: string\n '--scrolling-list-px'?: string\n }\n\n const inlineStyles: CustomCSSProperties = {\n scrollSnapType: snapConfig[ctx.snapType],\n scrollPaddingInline: 'var(--scrolling-list-px)',\n '--scrolling-list-px': `${ctx.scrollPadding}px`,\n '--scrolling-list-gap': `${ctx.gap}px`,\n ...(ctx.withFade && {\n maskImage:\n 'linear-gradient(to right, rgba(0, 0, 0, 0), rgba(0, 0, 0, 1) 44px, rgba(0, 0, 0, 1) calc(100% - 44px), rgba(0, 0, 0, 0))',\n maskSize: `calc(100% + ${ctx.overflow.left ? '0px' : '44px'} + ${ctx.overflow.right ? '0px' : '44px'}) 100%`,\n maskPosition: `${ctx.overflow.left ? '0px' : '-44px'} 0`,\n }),\n }\n\n return (\n <div\n data-spark-component=\"scrolling-list-items\"\n id=\"scrolling-list-items\"\n role=\"list\"\n className={cx(\n 'relative transition-all duration-300',\n 'u-no-scrollbar overflow-x-auto scroll-smooth',\n 'w-full gap-(--scrolling-list-gap) default:flex default:flex-row',\n 'focus-visible:u-outline',\n className\n )}\n ref={mergeRefs<HTMLDivElement>(ctx.scrollAreaRef, ctx.scrollRef, ref)}\n style={inlineStyles}\n onKeyDown={handleKeyDown}\n {...rest}\n >\n {Children.map(children, (child, index) =>\n isValidElement<ScrollingListItemProps>(child) ? cloneElement(child, { index }) : child\n )}\n </div>\n )\n}\n\nScrollingListItems.displayName = 'ScrollingList.Items'\n","import { ArrowVerticalRight } from '@spark-ui/icons/ArrowVerticalRight'\nimport { cx } from 'class-variance-authority'\nimport { useContext } from 'react'\n\nimport { Icon } from '../icon'\nimport { IconButton, IconButtonProps } from '../icon-button'\nimport { ScrollingListContext } from './ScrollingList'\n\n/** A button to scroll to the next page of items. Renders a <button> element. */\nexport const ScrollingListNextButton = ({ 'aria-label': ariaLabel, ...rest }: IconButtonProps) => {\n const ctx = useContext(ScrollingListContext)\n\n const handleNextPage = () => {\n if (ctx.hasNextPage) {\n ctx.next({ behavior: ctx.scrollBehavior })\n } else {\n ctx.goTo(0, { behavior: ctx.scrollBehavior })\n }\n }\n\n const listHasOverflow = ctx.overflow.left || ctx.overflow.right\n const isDisabled = !listHasOverflow || (!ctx.loop && !ctx.overflow.right)\n\n return (\n <IconButton\n data-spark-component=\"scrolling-list-next-button\"\n size=\"sm\"\n intent=\"surface\"\n design=\"filled\"\n className={cx(\n 'pointer-events-auto opacity-(--scrolling-list-controls-opacity) shadow-sm disabled:invisible',\n 'group-hover/scrolling-list:opacity-none focus-visible:opacity-none'\n )}\n onClick={handleNextPage}\n disabled={isDisabled}\n aria-label={ariaLabel}\n aria-controls=\"scrolling-list-items\"\n {...rest}\n >\n <Icon>\n <ArrowVerticalRight />\n </Icon>\n </IconButton>\n )\n}\n\nScrollingListNextButton.displayName = 'ScrollingList.NextButton'\n","import { ArrowVerticalLeft } from '@spark-ui/icons/ArrowVerticalLeft'\nimport { cx } from 'class-variance-authority'\nimport { useContext } from 'react'\n\nimport { Icon } from '../icon'\nimport { IconButton, IconButtonProps } from '../icon-button'\nimport { ScrollingListContext } from './ScrollingList'\n\n/** A button to scroll to the previous page of items. Renders a <button> element. */\nexport const ScrollingListPrevButton = ({\n 'aria-label': ariaLabel,\n\n ...rest\n}: IconButtonProps) => {\n const ctx = useContext(ScrollingListContext)\n\n const handlePrevPage = () => {\n const shouldSnapFirstPage =\n ctx.activePageIndex === 0 && (ctx.scrollAreaRef.current?.scrollLeft || 0) > 0\n\n if (shouldSnapFirstPage) {\n ctx.goTo(0, { behavior: ctx.scrollBehavior })\n } else if (ctx.hasPrevPage) {\n ctx.prev({ behavior: ctx.scrollBehavior })\n } else {\n ctx.goTo(ctx.pages.length - 1, { behavior: ctx.scrollBehavior })\n }\n }\n\n const listHasOverflow = ctx.overflow.left || ctx.overflow.right\n const isDisabled = !listHasOverflow || (!ctx.loop && !ctx.overflow.left)\n\n return (\n <IconButton\n data-spark-component=\"scrolling-list-prev-button\"\n size=\"sm\"\n intent=\"surface\"\n design=\"filled\"\n className={cx(\n 'pointer-events-auto opacity-(--scrolling-list-controls-opacity) shadow-sm disabled:invisible',\n 'group-hover/scrolling-list:opacity-none focus-visible:opacity-none'\n )}\n onClick={handlePrevPage}\n disabled={isDisabled}\n aria-label={ariaLabel}\n aria-controls=\"scrolling-list-items\"\n {...rest}\n >\n <Icon>\n <ArrowVerticalLeft />\n </Icon>\n </IconButton>\n )\n}\n\nScrollingListPrevButton.displayName = 'ScrollingList.PrevButton'\n","import { cx } from 'class-variance-authority'\nimport { ComponentPropsWithoutRef, useContext } from 'react'\n\nimport { Button } from '../button'\nimport { ScrollingListContext } from './ScrollingList'\n\ninterface Props extends ComponentPropsWithoutRef<'button'> {\n children: string\n}\n\n/** A button to skip keyboard navigation, improving accessibility. Renders a <button> element. */\nexport const ScrollingListSkipButton = ({ children, ...rest }: Props) => {\n const ctx = useContext(ScrollingListContext)\n\n return (\n <Button\n type=\"button\"\n design=\"tinted\"\n intent=\"surface\"\n tabIndex={0}\n className={cx(\n 'z-raised absolute top-1/2 left-0 -translate-y-1/2',\n 'not-focus-visible:pointer-events-none not-focus-visible:size-0 not-focus-visible:opacity-0'\n )}\n onClick={ctx.skipKeyboardNavigation}\n {...rest}\n >\n {children}\n </Button>\n )\n}\n\nScrollingListSkipButton.displayName = 'ScrollingList.SkipButton'\n","import { ScrollingList as Root } from './ScrollingList'\nimport { ScrollingListControls as Controls } from './ScrollingListControls'\nimport { ScrollingListItem as Item } from './ScrollingListItem'\nimport { ScrollingListItems as Items } from './ScrollingListItems'\nimport { ScrollingListNextButton as NextButton } from './ScrollingListNextButton'\nimport { ScrollingListPrevButton as PrevButton } from './ScrollingListPrevButton'\nimport { ScrollingListSkipButton as SkipButton } from './ScrollingListSkipButton'\n\n/**\n * A horizontal scrollable list component with optional snap points and navigation controls.\n */\nexport const ScrollingList: typeof Root & {\n Controls: typeof Controls\n NextButton: typeof NextButton\n PrevButton: typeof PrevButton\n Item: typeof Item\n Items: typeof Items\n SkipButton: typeof SkipButton\n} = Object.assign(Root, {\n Controls,\n NextButton,\n PrevButton,\n Item,\n Items,\n SkipButton,\n})\n\nScrollingList.displayName = 'ScrollingList'\n"],"mappings":"ggBAiEA,IAAa,GAAA,EAAA,EAAA,eACX,KACD,CAEY,GAAiB,CAC5B,WAAW,OACX,WAAW,SACX,iBAAiB,SACjB,OAAO,GACP,MAAM,GACN,WAAW,GACX,gBAAgB,EAChB,WACA,YACA,GAAG,KACQ,CACX,IAAM,GAAA,EAAA,EAAA,QAAuC,KAAK,CAC5C,GAAA,EAAA,EAAA,QAA0C,KAAK,CAE/C,GAAA,EAAA,EAAA,kBAAmC,CAEnC,CAAE,WAAU,QAAS,IAAA,EAAA,EAAA,mBAAsC,EAAe,CAC9E,kBAAmB,EACpB,CAAC,CAEI,CAAE,kBAAiB,QAAO,WAAY,EAEtC,EAAe,EAAM,GAErB,EAAoB,EACrB,CAAC,EAAa,GAAM,EAAG,EAAa,EAAa,OAAS,GAAM,EAAE,CAClE,CAAC,EAAG,EAAE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S,EACT,SAAU,EACV,aAAY,EACZ,gBAAc,uBACd,GAAI,YAEJ,EAAA,EAAA,KAAC,EAAA,EAAD,CAAA,UACE,EAAA,EAAA,KAAC,EAAA,kBAAD,EAAqB,CAAA,CAChB,CAAA,CACI,CAAA,EAIjB,EAAwB,YAAc,2BC5CtC,IAAa,GAA2B,CAAE,WAAU,GAAG,KAAkB,CACvE,IAAM,GAAA,EAAA,EAAA,YAAiB,EAAqB,CAE5C,OACE,EAAA,EAAA,KAAC,EAAA,EAAD,CACE,KAAK,SACL,OAAO,SACP,OAAO,UACP,SAAU,EACV,WAAA,EAAA,EAAA,IACE,oDACA,6FACD,CACD,QAAS,EAAI,uBACb,GAAI,EAEH,WACM,CAAA,EAIb,EAAwB,YAAc,2BCrBtC,IAAa,EAOT,OAAO,OAAO,EAAM,CACtB,SAAA,EACA,WAAA,EACA,WAAA,EACA,KAAA,EACA,MAAA,EACA,WAAA,EACD,CAAC,CAEF,EAAc,YAAc"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/scrolling-list/ScrollingList.tsx","../../src/scrolling-list/ScrollingListControls.tsx","../../src/scrolling-list/useFocusWithinScroll.tsx","../../src/scrolling-list/ScrollingListItem.tsx","../../src/scrolling-list/ScrollingListItems.tsx","../../src/scrolling-list/ScrollingListNextButton.tsx","../../src/scrolling-list/ScrollingListPrevButton.tsx","../../src/scrolling-list/ScrollingListSkipButton.tsx","../../src/scrolling-list/index.ts"],"sourcesContent":["import { ScrollOverflow, useScrollOverflow } from '@spark-ui/hooks/use-scroll-overflow'\nimport { cx } from 'class-variance-authority'\nimport {\n ComponentPropsWithRef,\n createContext,\n ReactNode,\n RefObject,\n useCallback,\n useEffect,\n useLayoutEffect,\n useRef,\n} from 'react'\nimport { SnapCarouselResult, useSnapCarousel } from 'react-snap-carousel'\n\ntype SnapType = 'mandatory' | 'proximity' | 'none'\ntype ScrollBehavior = 'smooth' | 'instant'\ntype SnapStop = 'normal' | 'always'\n\ninterface Props extends ComponentPropsWithRef<'div'> {\n /**\n * CSS scroll snap behavior.\n * - `mandatory` to force snapping on each \"page\".\n * - `proximity` to force snapping only when scroll position is near the edge of a \"page\". Behavior can change depending on each browser.\n * - `none` to disabled scroll snapping.\n */\n snapType?: SnapType\n /**\n * Defines whether or not the scroll container is allowed to \"pass over\" possible snap positions.\n */\n snapStop?: SnapStop\n scrollBehavior?: ScrollBehavior\n /**\n * Add a fade effect to indicate content overflow.\n */\n withFade?: boolean\n children?: ReactNode\n /**\n * When `true`, allow previous and next buttons to be used when reaching the edges of the list.\n */\n loop?: boolean\n /**\n * Space (in pixels) between items.\n */\n gap?: number\n /**\n * Offset (in pixels) of the left of the optimal viewing region of the list.\n */\n scrollPadding?: number\n className?: string\n}\n\ninterface ScrollingListContextState extends SnapCarouselResult {\n snapType: SnapType\n snapStop: SnapStop\n scrollBehavior: ScrollBehavior\n visibleItemsRange: readonly [number, number]\n loop: boolean\n gap: number\n withFade: boolean\n scrollPadding: number\n scrollAreaRef: RefObject<HTMLDivElement | null>\n overflow: ScrollOverflow\n skipKeyboardNavigation: () => void\n}\n\nexport const ScrollingListContext = createContext<ScrollingListContextState>(\n null as unknown as ScrollingListContextState\n)\n\nexport const ScrollingList = ({\n snapType = 'none',\n snapStop = 'normal',\n scrollBehavior = 'smooth',\n loop = false,\n gap = 16,\n withFade = false,\n scrollPadding = 0,\n children,\n className,\n ...rest\n}: Props) => {\n const scrollAreaRef = useRef<HTMLDivElement>(null)\n const skipAnchorRef = useRef<HTMLButtonElement>(null)\n\n const snapCarouselAPI = useSnapCarousel()\n\n const { overflow, refresh: refreshOverflow } = useScrollOverflow(scrollAreaRef, {\n precisionTreshold: 1,\n })\n\n const { activePageIndex, pages, refresh } = snapCarouselAPI\n\n const visibleItems = pages[activePageIndex] as number[]\n\n const visibleItemsRange = visibleItems\n ? ([visibleItems[0]! + 1, visibleItems[visibleItems.length - 1]! + 1] as const)\n : ([0, 0] as const)\n\n // Force refresh of the carousel API when children change\n const forceRefresh = useCallback(() => {\n if (refresh && scrollAreaRef.current) {\n // Small delay to ensure DOM is updated\n setTimeout(() => {\n refresh()\n }, 0)\n }\n }, [refresh])\n\n useEffect(() => {\n forceRefresh()\n }, [children, forceRefresh])\n\n useLayoutEffect(() => {\n if (scrollAreaRef.current) {\n // Use requestAnimationFrame to ensure proper timing with the render cycle\n // This prevents race conditions that occur when the console is closed\n requestAnimationFrame(() => {\n refreshOverflow()\n })\n }\n }, [children, refreshOverflow])\n\n const skipKeyboardNavigation = () => {\n skipAnchorRef.current?.focus()\n }\n\n const ctxValue: ScrollingListContextState = {\n ...snapCarouselAPI,\n snapType,\n snapStop,\n skipKeyboardNavigation,\n scrollBehavior,\n visibleItemsRange,\n loop,\n gap,\n withFade,\n scrollPadding,\n scrollAreaRef,\n overflow,\n }\n\n return (\n <ScrollingListContext value={ctxValue}>\n <div\n data-spark-component=\"scrolling-list\"\n className={cx(\n 'gap-lg group/scrolling-list relative flex flex-col default:w-full',\n className\n )}\n {...rest}\n >\n {children}\n </div>\n <span ref={skipAnchorRef} className=\"size-0 overflow-hidden\" tabIndex={-1} />\n </ScrollingListContext>\n )\n}\n\nScrollingList.displayName = 'ScrollingList'\n","import { cx } from 'class-variance-authority'\nimport { ComponentPropsWithoutRef, CSSProperties, ReactNode } from 'react'\n\ninterface ScrollingListControls extends ComponentPropsWithoutRef<'div'> {\n /**\n * Visibility behavior of the control buttons:\n * - `always`: buttons are always visible.\n * - `hover`: buttons only appear on hover.\n *\n * a11y: `hover` is dangerous for accessibility as it disabled controls for touch screen users.\n * When using it, you must provide an alternative control outside of the list to replace them.\n */\n visibility?: 'hover' | 'always'\n children: ReactNode\n}\n\n/** Container for navigation controls (previous/next buttons) of the scrolling list. Renders a <div> element. */\nexport const ScrollingListControls = ({\n children,\n visibility = 'always',\n className,\n ...rest\n}: ScrollingListControls) => {\n return (\n <div\n data-spark-component=\"scrolling-list-controls\"\n className={cx(\n 'default:px-md pointer-events-none absolute inset-0 flex flex-row items-center justify-between overflow-hidden',\n className\n )}\n style={\n {\n '--scrolling-list-controls-opacity': visibility === 'hover' ? '0' : '1',\n } as CSSProperties\n }\n data-orientation=\"horizontal\"\n {...rest}\n >\n {children}\n </div>\n )\n}\n\nScrollingListControls.displayName = 'ScrollingList.Controls'\n","import { RefObject, useEffect, useState } from 'react'\n\nexport function useFocusWithinScroll<T extends HTMLElement | null>(\n ref: RefObject<T>, // The container to detect focus within\n scrollRef: RefObject<HTMLDivElement | null> // The scrollable container\n) {\n const [isFocusWithin, setIsFocusWithin] = useState(false)\n\n useEffect(() => {\n const handleFocusIn = (event: FocusEvent) => {\n setIsFocusWithin(true)\n\n const focusedElement = event.target as HTMLElement\n const scrollContainer = scrollRef.current\n\n if (focusedElement && scrollContainer) {\n const focusRect = focusedElement.getBoundingClientRect()\n const scrollRect = scrollContainer.getBoundingClientRect()\n\n // Check if the focused element is fully visible inside the scroll container\n const isFullyVisible =\n focusRect.left >= scrollRect.left &&\n focusRect.right <= scrollRect.right &&\n focusRect.top >= scrollRect.top &&\n focusRect.bottom <= scrollRect.bottom\n\n if (!isFullyVisible) {\n focusedElement.scrollIntoView({ behavior: 'smooth', inline: 'center', block: 'nearest' })\n }\n }\n }\n\n const handleFocusOut = (event: FocusEvent) => {\n if (ref.current && !ref.current.contains(event.relatedTarget as Node)) {\n setIsFocusWithin(false)\n }\n }\n\n const node = ref.current\n if (node) {\n node.addEventListener('focusin', handleFocusIn)\n node.addEventListener('focusout', handleFocusOut)\n }\n\n return () => {\n if (node) {\n node.removeEventListener('focusin', handleFocusIn)\n node.removeEventListener('focusout', handleFocusOut)\n }\n }\n }, [ref, scrollRef])\n\n return isFocusWithin\n}\n","import { cx } from 'class-variance-authority'\nimport { ComponentPropsWithoutRef, ReactNode, useContext, useRef } from 'react'\n\nimport { Slot } from '../slot'\nimport { ScrollingListContext } from './ScrollingList'\nimport { useFocusWithinScroll } from './useFocusWithinScroll'\n\nexport interface ScrollingListItemProps extends ComponentPropsWithoutRef<'div'> {\n /**\n * Change the default rendered element for the one passed as a child, merging their props and behavior.\n */\n asChild?: boolean\n children?: ReactNode\n /**\n * DO NOT USE. This prop is automatically managed by the parent ScrollingList.ListItems\n */\n index?: number\n className?: string\n}\n\n/** A single item in the scrolling list. Renders a <div> element. */\nexport const ScrollingListItem = ({\n asChild = false,\n children,\n index = 0,\n className = '',\n ...rest\n}: ScrollingListItemProps) => {\n const ctx = useContext(ScrollingListContext)\n const itemRef = useRef<HTMLDivElement>(null)\n\n const isSnapPoint = ctx.snapPointIndexes.has(index)\n\n useFocusWithinScroll(itemRef, ctx.scrollAreaRef)\n\n const Component = asChild ? Slot : 'div'\n\n return (\n <Component\n data-spark-component=\"scrolling-list-item\"\n role=\"listitem\"\n ref={itemRef}\n className={cx(\n 'default:w-auto default:shrink-0',\n {\n 'snap-start': isSnapPoint,\n 'snap-normal': isSnapPoint && ctx.snapStop === 'normal',\n 'snap-always': isSnapPoint && ctx.snapStop === 'always',\n },\n className\n )}\n {...rest}\n >\n {children}\n </Component>\n )\n}\n\nScrollingListItem.displayName = 'ScrollingList.Item'\n","import { cx } from 'class-variance-authority'\nimport {\n Children,\n cloneElement,\n ComponentPropsWithRef,\n CSSProperties,\n isValidElement,\n KeyboardEvent,\n ReactNode,\n Ref,\n RefObject,\n useContext,\n} from 'react'\n\nimport { ScrollingListContext } from './ScrollingList'\nimport { ScrollingListItemProps } from './ScrollingListItem'\n\ninterface Props extends ComponentPropsWithRef<'div'> {\n children?: ReactNode\n className?: string\n}\n\nexport function mergeRefs<T>(...refs: (Ref<T> | undefined | null)[]): Ref<T> {\n return (value: T | null) => {\n refs.forEach(ref => {\n if (typeof ref === 'function') {\n ref(value)\n } else if (ref && typeof ref === 'object' && 'current' in ref) {\n ;(ref as RefObject<T | null>).current = value\n }\n })\n }\n}\n\n/** The scrollable container for the list items. Renders a <div> element. */\nexport const ScrollingListItems = ({ children, ref, className = '', ...rest }: Props) => {\n const ctx = useContext(ScrollingListContext)\n\n const snapConfig = {\n mandatory: 'x mandatory',\n proximity: 'x proximity',\n none: 'none',\n }\n\n const handleLeftArrow = (event: KeyboardEvent<HTMLDivElement>) => {\n if (!ctx.loop && !ctx.hasPrevPage) return\n\n event.preventDefault()\n ctx.goTo(ctx.hasPrevPage ? ctx.activePageIndex - 1 : ctx.pages.length - 1, {\n behavior: ctx.scrollBehavior,\n })\n }\n\n const handleRightArrow = (event: KeyboardEvent<HTMLDivElement>) => {\n if (!ctx.loop && !ctx.hasNextPage) return\n\n event.preventDefault()\n ctx.goTo(ctx.hasNextPage ? ctx.activePageIndex + 1 : 0, { behavior: ctx.scrollBehavior })\n }\n\n const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n if (event.key === 'ArrowLeft') {\n handleLeftArrow(event)\n }\n\n if (event.key === 'ArrowRight') {\n handleRightArrow(event)\n }\n }\n\n interface CustomCSSProperties extends CSSProperties {\n '--scrolling-list-gap'?: string\n '--scrolling-list-px'?: string\n }\n\n const inlineStyles: CustomCSSProperties = {\n scrollSnapType: snapConfig[ctx.snapType],\n scrollPaddingInline: 'var(--scrolling-list-px)',\n '--scrolling-list-px': `${ctx.scrollPadding}px`,\n '--scrolling-list-gap': `${ctx.gap}px`,\n ...(ctx.withFade && {\n maskImage:\n 'linear-gradient(to right, rgba(0, 0, 0, 0), rgba(0, 0, 0, 1) 44px, rgba(0, 0, 0, 1) calc(100% - 44px), rgba(0, 0, 0, 0))',\n maskSize: `calc(100% + ${ctx.overflow.left ? '0px' : '44px'} + ${ctx.overflow.right ? '0px' : '44px'}) 100%`,\n maskPosition: `${ctx.overflow.left ? '0px' : '-44px'} 0`,\n }),\n }\n\n return (\n <div\n data-spark-component=\"scrolling-list-items\"\n id=\"scrolling-list-items\"\n role=\"list\"\n className={cx(\n 'relative transition-all duration-300',\n 'u-no-scrollbar overflow-x-auto scroll-smooth',\n 'w-full gap-(--scrolling-list-gap) default:flex default:flex-row',\n 'focus-visible:u-outline',\n className\n )}\n ref={mergeRefs<HTMLDivElement>(ctx.scrollAreaRef, ctx.scrollRef, ref)}\n style={inlineStyles}\n onKeyDown={handleKeyDown}\n {...rest}\n >\n {Children.map(children, (child, index) =>\n isValidElement<ScrollingListItemProps>(child) ? cloneElement(child, { index }) : child\n )}\n </div>\n )\n}\n\nScrollingListItems.displayName = 'ScrollingList.Items'\n","import { ArrowVerticalRight } from '@spark-ui/icons/ArrowVerticalRight'\nimport { cx } from 'class-variance-authority'\nimport { useContext } from 'react'\n\nimport { Icon } from '../icon'\nimport { IconButton, IconButtonProps } from '../icon-button'\nimport { ScrollingListContext } from './ScrollingList'\n\n/** A button to scroll to the next page of items. Renders a <button> element. */\nexport const ScrollingListNextButton = ({ 'aria-label': ariaLabel, ...rest }: IconButtonProps) => {\n const ctx = useContext(ScrollingListContext)\n\n const handleNextPage = () => {\n if (ctx.hasNextPage) {\n ctx.next({ behavior: ctx.scrollBehavior })\n } else {\n ctx.goTo(0, { behavior: ctx.scrollBehavior })\n }\n }\n\n const listHasOverflow = ctx.overflow.left || ctx.overflow.right\n const isDisabled = !listHasOverflow || (!ctx.loop && !ctx.overflow.right)\n\n return (\n <IconButton\n data-spark-component=\"scrolling-list-next-button\"\n size=\"sm\"\n intent=\"surface\"\n design=\"filled\"\n className={cx(\n 'pointer-events-auto opacity-(--scrolling-list-controls-opacity) shadow-sm disabled:invisible',\n 'group-hover/scrolling-list:opacity-none focus-visible:opacity-none'\n )}\n onClick={handleNextPage}\n disabled={isDisabled}\n aria-label={ariaLabel}\n aria-controls=\"scrolling-list-items\"\n {...rest}\n >\n <Icon>\n <ArrowVerticalRight />\n </Icon>\n </IconButton>\n )\n}\n\nScrollingListNextButton.displayName = 'ScrollingList.NextButton'\n","import { ArrowVerticalLeft } from '@spark-ui/icons/ArrowVerticalLeft'\nimport { cx } from 'class-variance-authority'\nimport { useContext } from 'react'\n\nimport { Icon } from '../icon'\nimport { IconButton, IconButtonProps } from '../icon-button'\nimport { ScrollingListContext } from './ScrollingList'\n\n/** A button to scroll to the previous page of items. Renders a <button> element. */\nexport const ScrollingListPrevButton = ({\n 'aria-label': ariaLabel,\n\n ...rest\n}: IconButtonProps) => {\n const ctx = useContext(ScrollingListContext)\n\n const handlePrevPage = () => {\n const shouldSnapFirstPage =\n ctx.activePageIndex === 0 && (ctx.scrollAreaRef.current?.scrollLeft || 0) > 0\n\n if (shouldSnapFirstPage) {\n ctx.goTo(0, { behavior: ctx.scrollBehavior })\n } else if (ctx.hasPrevPage) {\n ctx.prev({ behavior: ctx.scrollBehavior })\n } else {\n ctx.goTo(ctx.pages.length - 1, { behavior: ctx.scrollBehavior })\n }\n }\n\n const listHasOverflow = ctx.overflow.left || ctx.overflow.right\n const isDisabled = !listHasOverflow || (!ctx.loop && !ctx.overflow.left)\n\n return (\n <IconButton\n data-spark-component=\"scrolling-list-prev-button\"\n size=\"sm\"\n intent=\"surface\"\n design=\"filled\"\n className={cx(\n 'pointer-events-auto opacity-(--scrolling-list-controls-opacity) shadow-sm disabled:invisible',\n 'group-hover/scrolling-list:opacity-none focus-visible:opacity-none'\n )}\n onClick={handlePrevPage}\n disabled={isDisabled}\n aria-label={ariaLabel}\n aria-controls=\"scrolling-list-items\"\n {...rest}\n >\n <Icon>\n <ArrowVerticalLeft />\n </Icon>\n </IconButton>\n )\n}\n\nScrollingListPrevButton.displayName = 'ScrollingList.PrevButton'\n","import { cx } from 'class-variance-authority'\nimport { ComponentPropsWithoutRef, useContext } from 'react'\n\nimport { Button } from '../button'\nimport { ScrollingListContext } from './ScrollingList'\n\ninterface Props extends ComponentPropsWithoutRef<'button'> {\n children: string\n}\n\n/** A button to skip keyboard navigation, improving accessibility. Renders a <button> element. */\nexport const ScrollingListSkipButton = ({ children, ...rest }: Props) => {\n const ctx = useContext(ScrollingListContext)\n\n return (\n <Button\n type=\"button\"\n design=\"tinted\"\n intent=\"surface\"\n tabIndex={0}\n className={cx(\n 'z-raised absolute top-1/2 left-0 -translate-y-1/2',\n 'not-focus-visible:pointer-events-none not-focus-visible:size-0 not-focus-visible:opacity-0'\n )}\n onClick={ctx.skipKeyboardNavigation}\n {...rest}\n >\n {children}\n </Button>\n )\n}\n\nScrollingListSkipButton.displayName = 'ScrollingList.SkipButton'\n","import { ScrollingList as Root } from './ScrollingList'\nimport { ScrollingListControls as Controls } from './ScrollingListControls'\nimport { ScrollingListItem as Item } from './ScrollingListItem'\nimport { ScrollingListItems as Items } from './ScrollingListItems'\nimport { ScrollingListNextButton as NextButton } from './ScrollingListNextButton'\nimport { ScrollingListPrevButton as PrevButton } from './ScrollingListPrevButton'\nimport { ScrollingListSkipButton as SkipButton } from './ScrollingListSkipButton'\n\n/**\n * A horizontal scrollable list component with optional snap points and navigation controls.\n */\nexport const ScrollingList: typeof Root & {\n Controls: typeof Controls\n NextButton: typeof NextButton\n PrevButton: typeof PrevButton\n Item: typeof Item\n Items: typeof Items\n SkipButton: typeof SkipButton\n} = Object.assign(Root, {\n Controls,\n NextButton,\n PrevButton,\n Item,\n Items,\n SkipButton,\n})\n\nScrollingList.displayName = 'ScrollingList'\n"],"mappings":"ggBAiEA,IAAa,GAAA,EAAA,EAAA,eACX,KACD,CAEY,GAAiB,CAC5B,WAAW,OACX,WAAW,SACX,iBAAiB,SACjB,OAAO,GACP,MAAM,GACN,WAAW,GACX,gBAAgB,EAChB,WACA,YACA,GAAG,KACQ,CACX,IAAM,GAAA,EAAA,EAAA,QAAuC,KAAK,CAC5C,GAAA,EAAA,EAAA,QAA0C,KAAK,CAE/C,GAAA,EAAA,EAAA,kBAAmC,CAEnC,CAAE,WAAU,QAAS,IAAA,EAAA,EAAA,mBAAsC,EAAe,CAC9E,kBAAmB,EACpB,CAAC,CAEI,CAAE,kBAAiB,QAAO,WAAY,EAEtC,EAAe,EAAM,GAErB,EAAoB,EACrB,CAAC,EAAa,GAAM,EAAG,EAAa,EAAa,OAAS,GAAM,EAAE,CAClE,CAAC,EAAG,EAAE,CAGL,GAAA,EAAA,EAAA,iBAAiC,CACjC,GAAW,EAAc,SAE3B,eAAiB,CACf,GAAS,EACR,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A,EAAA,KAAC,EAAA,kBAAD,EAAqB,CAAA,CAChB,CAAA,CACI,CAAA,EAIjB,EAAwB,YAAc,2BC5CtC,IAAa,GAA2B,CAAE,WAAU,GAAG,KAAkB,CACvE,IAAM,GAAA,EAAA,EAAA,YAAiB,EAAqB,CAE5C,OACE,EAAA,EAAA,KAAC,EAAA,EAAD,CACE,KAAK,SACL,OAAO,SACP,OAAO,UACP,SAAU,EACV,WAAA,EAAA,EAAA,IACE,oDACA,6FACD,CACD,QAAS,EAAI,uBACb,GAAI,EAEH,WACM,CAAA,EAIb,EAAwB,YAAc,2BCrBtC,IAAa,EAOT,OAAO,OAAO,EAAM,CACtB,SAAA,EACA,WAAA,EACA,WAAA,EACA,KAAA,EACA,MAAA,EACA,WAAA,EACD,CAAC,CAEF,EAAc,YAAc"}
@@ -1,7 +1,7 @@
1
1
  import { Slot as e } from "../slot/index.mjs";
2
2
  import { t } from "../icon-D05Uqh8_.mjs";
3
- import { t as n } from "../button-BtuAr9qV.mjs";
4
- import { t as r } from "../icon-button-XyQSaVPL.mjs";
3
+ import { t as n } from "../button-CNabSkd_.mjs";
4
+ import { t as r } from "../icon-button-DVbKK2_a.mjs";
5
5
  import { cx as i } from "class-variance-authority";
6
6
  import { Children as a, cloneElement as o, createContext as s, isValidElement as c, useCallback as l, useContext as u, useEffect as d, useLayoutEffect as f, useRef as p, useState as m } from "react";
7
7
  import { jsx as h, jsxs as g } from "react/jsx-runtime";
@@ -25,22 +25,22 @@ var x = s(null), S = ({ snapType: e = "none", snapStop: t = "normal", scrollBeha
25
25
  }, [c, w]);
26
26
  let j = () => {
27
27
  y.current?.focus();
28
- }, M = {
29
- ...S,
30
- snapType: e,
31
- snapStop: t,
32
- skipKeyboardNavigation: j,
33
- scrollBehavior: n,
34
- visibleItemsRange: k,
35
- loop: r,
36
- gap: a,
37
- withFade: o,
38
- scrollPadding: s,
39
- scrollAreaRef: v,
40
- overflow: C
41
28
  };
42
- return /* @__PURE__ */ g(x.Provider, {
43
- value: M,
29
+ return /* @__PURE__ */ g(x, {
30
+ value: {
31
+ ...S,
32
+ snapType: e,
33
+ snapStop: t,
34
+ skipKeyboardNavigation: j,
35
+ scrollBehavior: n,
36
+ visibleItemsRange: k,
37
+ loop: r,
38
+ gap: a,
39
+ withFade: o,
40
+ scrollPadding: s,
41
+ scrollAreaRef: v,
42
+ overflow: C
43
+ },
44
44
  children: [/* @__PURE__ */ h("div", {
45
45
  "data-spark-component": "scrolling-list",
46
46
  className: i("gap-lg group/scrolling-list relative flex flex-col default:w-full", u),
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../src/scrolling-list/ScrollingList.tsx","../../src/scrolling-list/ScrollingListControls.tsx","../../src/scrolling-list/useFocusWithinScroll.tsx","../../src/scrolling-list/ScrollingListItem.tsx","../../src/scrolling-list/ScrollingListItems.tsx","../../src/scrolling-list/ScrollingListNextButton.tsx","../../src/scrolling-list/ScrollingListPrevButton.tsx","../../src/scrolling-list/ScrollingListSkipButton.tsx","../../src/scrolling-list/index.ts"],"sourcesContent":["import { ScrollOverflow, useScrollOverflow } from '@spark-ui/hooks/use-scroll-overflow'\nimport { cx } from 'class-variance-authority'\nimport {\n ComponentPropsWithRef,\n createContext,\n ReactNode,\n RefObject,\n useCallback,\n useEffect,\n useLayoutEffect,\n useRef,\n} from 'react'\nimport { SnapCarouselResult, useSnapCarousel } from 'react-snap-carousel'\n\ntype SnapType = 'mandatory' | 'proximity' | 'none'\ntype ScrollBehavior = 'smooth' | 'instant'\ntype SnapStop = 'normal' | 'always'\n\ninterface Props extends ComponentPropsWithRef<'div'> {\n /**\n * CSS scroll snap behavior.\n * - `mandatory` to force snapping on each \"page\".\n * - `proximity` to force snapping only when scroll position is near the edge of a \"page\". Behavior can change depending on each browser.\n * - `none` to disabled scroll snapping.\n */\n snapType?: SnapType\n /**\n * Defines whether or not the scroll container is allowed to \"pass over\" possible snap positions.\n */\n snapStop?: SnapStop\n scrollBehavior?: ScrollBehavior\n /**\n * Add a fade effect to indicate content overflow.\n */\n withFade?: boolean\n children?: ReactNode\n /**\n * When `true`, allow previous and next buttons to be used when reaching the edges of the list.\n */\n loop?: boolean\n /**\n * Space (in pixels) between items.\n */\n gap?: number\n /**\n * Offset (in pixels) of the left of the optimal viewing region of the list.\n */\n scrollPadding?: number\n className?: string\n}\n\ninterface ScrollingListContextState extends SnapCarouselResult {\n snapType: SnapType\n snapStop: SnapStop\n scrollBehavior: ScrollBehavior\n visibleItemsRange: readonly [number, number]\n loop: boolean\n gap: number\n withFade: boolean\n scrollPadding: number\n scrollAreaRef: RefObject<HTMLDivElement | null>\n overflow: ScrollOverflow\n skipKeyboardNavigation: () => void\n}\n\nexport const ScrollingListContext = createContext<ScrollingListContextState>(\n null as unknown as ScrollingListContextState\n)\n\nexport const ScrollingList = ({\n snapType = 'none',\n snapStop = 'normal',\n scrollBehavior = 'smooth',\n loop = false,\n gap = 16,\n withFade = false,\n scrollPadding = 0,\n children,\n className,\n ...rest\n}: Props) => {\n const scrollAreaRef = useRef<HTMLDivElement>(null)\n const skipAnchorRef = useRef<HTMLButtonElement>(null)\n\n const snapCarouselAPI = useSnapCarousel()\n\n const { overflow, refresh: refreshOverflow } = useScrollOverflow(scrollAreaRef, {\n precisionTreshold: 1,\n })\n\n const { activePageIndex, pages, refresh } = snapCarouselAPI\n\n const visibleItems = pages[activePageIndex] as number[]\n\n const visibleItemsRange = visibleItems\n ? ([visibleItems[0]! + 1, visibleItems[visibleItems.length - 1]! + 1] as const)\n : ([0, 0] as const)\n\n // Force refresh of the carousel API when children change\n const forceRefresh = useCallback(() => {\n if (refresh && scrollAreaRef.current) {\n // Small delay to ensure DOM is updated\n setTimeout(() => {\n refresh()\n }, 0)\n }\n }, [refresh])\n\n useEffect(() => {\n forceRefresh()\n }, [children, forceRefresh])\n\n useLayoutEffect(() => {\n if (scrollAreaRef.current) {\n // Use requestAnimationFrame to ensure proper timing with the render cycle\n // This prevents race conditions that occur when the console is closed\n requestAnimationFrame(() => {\n refreshOverflow()\n })\n }\n }, [children, refreshOverflow])\n\n const skipKeyboardNavigation = () => {\n skipAnchorRef.current?.focus()\n }\n\n const ctxValue: ScrollingListContextState = {\n ...snapCarouselAPI,\n snapType,\n snapStop,\n skipKeyboardNavigation,\n scrollBehavior,\n visibleItemsRange,\n loop,\n gap,\n withFade,\n scrollPadding,\n scrollAreaRef,\n overflow,\n }\n\n return (\n <ScrollingListContext.Provider value={ctxValue}>\n <div\n data-spark-component=\"scrolling-list\"\n className={cx(\n 'gap-lg group/scrolling-list relative flex flex-col default:w-full',\n className\n )}\n {...rest}\n >\n {children}\n </div>\n <span ref={skipAnchorRef} className=\"size-0 overflow-hidden\" tabIndex={-1} />\n </ScrollingListContext.Provider>\n )\n}\n\nScrollingList.displayName = 'ScrollingList'\n","import { cx } from 'class-variance-authority'\nimport { ComponentPropsWithoutRef, CSSProperties, ReactNode } from 'react'\n\ninterface ScrollingListControls extends ComponentPropsWithoutRef<'div'> {\n /**\n * Visibility behavior of the control buttons:\n * - `always`: buttons are always visible.\n * - `hover`: buttons only appear on hover.\n *\n * a11y: `hover` is dangerous for accessibility as it disabled controls for touch screen users.\n * When using it, you must provide an alternative control outside of the list to replace them.\n */\n visibility?: 'hover' | 'always'\n children: ReactNode\n}\n\n/** Container for navigation controls (previous/next buttons) of the scrolling list. Renders a <div> element. */\nexport const ScrollingListControls = ({\n children,\n visibility = 'always',\n className,\n ...rest\n}: ScrollingListControls) => {\n return (\n <div\n data-spark-component=\"scrolling-list-controls\"\n className={cx(\n 'default:px-md pointer-events-none absolute inset-0 flex flex-row items-center justify-between overflow-hidden',\n className\n )}\n style={\n {\n '--scrolling-list-controls-opacity': visibility === 'hover' ? '0' : '1',\n } as CSSProperties\n }\n data-orientation=\"horizontal\"\n {...rest}\n >\n {children}\n </div>\n )\n}\n\nScrollingListControls.displayName = 'ScrollingList.Controls'\n","import { RefObject, useEffect, useState } from 'react'\n\nexport function useFocusWithinScroll<T extends HTMLElement | null>(\n ref: RefObject<T>, // The container to detect focus within\n scrollRef: RefObject<HTMLDivElement | null> // The scrollable container\n) {\n const [isFocusWithin, setIsFocusWithin] = useState(false)\n\n useEffect(() => {\n const handleFocusIn = (event: FocusEvent) => {\n setIsFocusWithin(true)\n\n const focusedElement = event.target as HTMLElement\n const scrollContainer = scrollRef.current\n\n if (focusedElement && scrollContainer) {\n const focusRect = focusedElement.getBoundingClientRect()\n const scrollRect = scrollContainer.getBoundingClientRect()\n\n // Check if the focused element is fully visible inside the scroll container\n const isFullyVisible =\n focusRect.left >= scrollRect.left &&\n focusRect.right <= scrollRect.right &&\n focusRect.top >= scrollRect.top &&\n focusRect.bottom <= scrollRect.bottom\n\n if (!isFullyVisible) {\n focusedElement.scrollIntoView({ behavior: 'smooth', inline: 'center', block: 'nearest' })\n }\n }\n }\n\n const handleFocusOut = (event: FocusEvent) => {\n if (ref.current && !ref.current.contains(event.relatedTarget as Node)) {\n setIsFocusWithin(false)\n }\n }\n\n const node = ref.current\n if (node) {\n node.addEventListener('focusin', handleFocusIn)\n node.addEventListener('focusout', handleFocusOut)\n }\n\n return () => {\n if (node) {\n node.removeEventListener('focusin', handleFocusIn)\n node.removeEventListener('focusout', handleFocusOut)\n }\n }\n }, [ref, scrollRef])\n\n return isFocusWithin\n}\n","import { cx } from 'class-variance-authority'\nimport { ComponentPropsWithoutRef, ReactNode, useContext, useRef } from 'react'\n\nimport { Slot } from '../slot'\nimport { ScrollingListContext } from './ScrollingList'\nimport { useFocusWithinScroll } from './useFocusWithinScroll'\n\nexport interface ScrollingListItemProps extends ComponentPropsWithoutRef<'div'> {\n /**\n * Change the default rendered element for the one passed as a child, merging their props and behavior.\n */\n asChild?: boolean\n children?: ReactNode\n /**\n * DO NOT USE. This prop is automatically managed by the parent ScrollingList.ListItems\n */\n index?: number\n className?: string\n}\n\n/** A single item in the scrolling list. Renders a <div> element. */\nexport const ScrollingListItem = ({\n asChild = false,\n children,\n index = 0,\n className = '',\n ...rest\n}: ScrollingListItemProps) => {\n const ctx = useContext(ScrollingListContext)\n const itemRef = useRef<HTMLDivElement>(null)\n\n const isSnapPoint = ctx.snapPointIndexes.has(index)\n\n useFocusWithinScroll(itemRef, ctx.scrollAreaRef)\n\n const Component = asChild ? Slot : 'div'\n\n return (\n <Component\n data-spark-component=\"scrolling-list-item\"\n role=\"listitem\"\n ref={itemRef}\n className={cx(\n 'default:w-auto default:shrink-0',\n {\n 'snap-start': isSnapPoint,\n 'snap-normal': isSnapPoint && ctx.snapStop === 'normal',\n 'snap-always': isSnapPoint && ctx.snapStop === 'always',\n },\n className\n )}\n {...rest}\n >\n {children}\n </Component>\n )\n}\n\nScrollingListItem.displayName = 'ScrollingList.Item'\n","import { cx } from 'class-variance-authority'\nimport {\n Children,\n cloneElement,\n ComponentPropsWithRef,\n CSSProperties,\n isValidElement,\n KeyboardEvent,\n ReactNode,\n Ref,\n RefObject,\n useContext,\n} from 'react'\n\nimport { ScrollingListContext } from './ScrollingList'\nimport { ScrollingListItemProps } from './ScrollingListItem'\n\ninterface Props extends ComponentPropsWithRef<'div'> {\n children?: ReactNode\n className?: string\n}\n\nexport function mergeRefs<T>(...refs: (Ref<T> | undefined | null)[]): Ref<T> {\n return (value: T | null) => {\n refs.forEach(ref => {\n if (typeof ref === 'function') {\n ref(value)\n } else if (ref && typeof ref === 'object' && 'current' in ref) {\n ;(ref as RefObject<T | null>).current = value\n }\n })\n }\n}\n\n/** The scrollable container for the list items. Renders a <div> element. */\nexport const ScrollingListItems = ({ children, ref, className = '', ...rest }: Props) => {\n const ctx = useContext(ScrollingListContext)\n\n const snapConfig = {\n mandatory: 'x mandatory',\n proximity: 'x proximity',\n none: 'none',\n }\n\n const handleLeftArrow = (event: KeyboardEvent<HTMLDivElement>) => {\n if (!ctx.loop && !ctx.hasPrevPage) return\n\n event.preventDefault()\n ctx.goTo(ctx.hasPrevPage ? ctx.activePageIndex - 1 : ctx.pages.length - 1, {\n behavior: ctx.scrollBehavior,\n })\n }\n\n const handleRightArrow = (event: KeyboardEvent<HTMLDivElement>) => {\n if (!ctx.loop && !ctx.hasNextPage) return\n\n event.preventDefault()\n ctx.goTo(ctx.hasNextPage ? ctx.activePageIndex + 1 : 0, { behavior: ctx.scrollBehavior })\n }\n\n const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n if (event.key === 'ArrowLeft') {\n handleLeftArrow(event)\n }\n\n if (event.key === 'ArrowRight') {\n handleRightArrow(event)\n }\n }\n\n interface CustomCSSProperties extends CSSProperties {\n '--scrolling-list-gap'?: string\n '--scrolling-list-px'?: string\n }\n\n const inlineStyles: CustomCSSProperties = {\n scrollSnapType: snapConfig[ctx.snapType],\n scrollPaddingInline: 'var(--scrolling-list-px)',\n '--scrolling-list-px': `${ctx.scrollPadding}px`,\n '--scrolling-list-gap': `${ctx.gap}px`,\n ...(ctx.withFade && {\n maskImage:\n 'linear-gradient(to right, rgba(0, 0, 0, 0), rgba(0, 0, 0, 1) 44px, rgba(0, 0, 0, 1) calc(100% - 44px), rgba(0, 0, 0, 0))',\n maskSize: `calc(100% + ${ctx.overflow.left ? '0px' : '44px'} + ${ctx.overflow.right ? '0px' : '44px'}) 100%`,\n maskPosition: `${ctx.overflow.left ? '0px' : '-44px'} 0`,\n }),\n }\n\n return (\n <div\n data-spark-component=\"scrolling-list-items\"\n id=\"scrolling-list-items\"\n role=\"list\"\n className={cx(\n 'relative transition-all duration-300',\n 'u-no-scrollbar overflow-x-auto scroll-smooth',\n 'w-full gap-(--scrolling-list-gap) default:flex default:flex-row',\n 'focus-visible:u-outline',\n className\n )}\n ref={mergeRefs<HTMLDivElement>(ctx.scrollAreaRef, ctx.scrollRef, ref)}\n style={inlineStyles}\n onKeyDown={handleKeyDown}\n {...rest}\n >\n {Children.map(children, (child, index) =>\n isValidElement<ScrollingListItemProps>(child) ? cloneElement(child, { index }) : child\n )}\n </div>\n )\n}\n\nScrollingListItems.displayName = 'ScrollingList.Items'\n","import { ArrowVerticalRight } from '@spark-ui/icons/ArrowVerticalRight'\nimport { cx } from 'class-variance-authority'\nimport { useContext } from 'react'\n\nimport { Icon } from '../icon'\nimport { IconButton, IconButtonProps } from '../icon-button'\nimport { ScrollingListContext } from './ScrollingList'\n\n/** A button to scroll to the next page of items. Renders a <button> element. */\nexport const ScrollingListNextButton = ({ 'aria-label': ariaLabel, ...rest }: IconButtonProps) => {\n const ctx = useContext(ScrollingListContext)\n\n const handleNextPage = () => {\n if (ctx.hasNextPage) {\n ctx.next({ behavior: ctx.scrollBehavior })\n } else {\n ctx.goTo(0, { behavior: ctx.scrollBehavior })\n }\n }\n\n const listHasOverflow = ctx.overflow.left || ctx.overflow.right\n const isDisabled = !listHasOverflow || (!ctx.loop && !ctx.overflow.right)\n\n return (\n <IconButton\n data-spark-component=\"scrolling-list-next-button\"\n size=\"sm\"\n intent=\"surface\"\n design=\"filled\"\n className={cx(\n 'pointer-events-auto opacity-(--scrolling-list-controls-opacity) shadow-sm disabled:invisible',\n 'group-hover/scrolling-list:opacity-none focus-visible:opacity-none'\n )}\n onClick={handleNextPage}\n disabled={isDisabled}\n aria-label={ariaLabel}\n aria-controls=\"scrolling-list-items\"\n {...rest}\n >\n <Icon>\n <ArrowVerticalRight />\n </Icon>\n </IconButton>\n )\n}\n\nScrollingListNextButton.displayName = 'ScrollingList.NextButton'\n","import { ArrowVerticalLeft } from '@spark-ui/icons/ArrowVerticalLeft'\nimport { cx } from 'class-variance-authority'\nimport { useContext } from 'react'\n\nimport { Icon } from '../icon'\nimport { IconButton, IconButtonProps } from '../icon-button'\nimport { ScrollingListContext } from './ScrollingList'\n\n/** A button to scroll to the previous page of items. Renders a <button> element. */\nexport const ScrollingListPrevButton = ({\n 'aria-label': ariaLabel,\n\n ...rest\n}: IconButtonProps) => {\n const ctx = useContext(ScrollingListContext)\n\n const handlePrevPage = () => {\n const shouldSnapFirstPage =\n ctx.activePageIndex === 0 && (ctx.scrollAreaRef.current?.scrollLeft || 0) > 0\n\n if (shouldSnapFirstPage) {\n ctx.goTo(0, { behavior: ctx.scrollBehavior })\n } else if (ctx.hasPrevPage) {\n ctx.prev({ behavior: ctx.scrollBehavior })\n } else {\n ctx.goTo(ctx.pages.length - 1, { behavior: ctx.scrollBehavior })\n }\n }\n\n const listHasOverflow = ctx.overflow.left || ctx.overflow.right\n const isDisabled = !listHasOverflow || (!ctx.loop && !ctx.overflow.left)\n\n return (\n <IconButton\n data-spark-component=\"scrolling-list-prev-button\"\n size=\"sm\"\n intent=\"surface\"\n design=\"filled\"\n className={cx(\n 'pointer-events-auto opacity-(--scrolling-list-controls-opacity) shadow-sm disabled:invisible',\n 'group-hover/scrolling-list:opacity-none focus-visible:opacity-none'\n )}\n onClick={handlePrevPage}\n disabled={isDisabled}\n aria-label={ariaLabel}\n aria-controls=\"scrolling-list-items\"\n {...rest}\n >\n <Icon>\n <ArrowVerticalLeft />\n </Icon>\n </IconButton>\n )\n}\n\nScrollingListPrevButton.displayName = 'ScrollingList.PrevButton'\n","import { cx } from 'class-variance-authority'\nimport { ComponentPropsWithoutRef, useContext } from 'react'\n\nimport { Button } from '../button'\nimport { ScrollingListContext } from './ScrollingList'\n\ninterface Props extends ComponentPropsWithoutRef<'button'> {\n children: string\n}\n\n/** A button to skip keyboard navigation, improving accessibility. Renders a <button> element. */\nexport const ScrollingListSkipButton = ({ children, ...rest }: Props) => {\n const ctx = useContext(ScrollingListContext)\n\n return (\n <Button\n type=\"button\"\n design=\"tinted\"\n intent=\"surface\"\n tabIndex={0}\n className={cx(\n 'z-raised absolute top-1/2 left-0 -translate-y-1/2',\n 'not-focus-visible:pointer-events-none not-focus-visible:size-0 not-focus-visible:opacity-0'\n )}\n onClick={ctx.skipKeyboardNavigation}\n {...rest}\n >\n {children}\n </Button>\n )\n}\n\nScrollingListSkipButton.displayName = 'ScrollingList.SkipButton'\n","import { ScrollingList as Root } from './ScrollingList'\nimport { ScrollingListControls as Controls } from './ScrollingListControls'\nimport { ScrollingListItem as Item } from './ScrollingListItem'\nimport { ScrollingListItems as Items } from './ScrollingListItems'\nimport { ScrollingListNextButton as NextButton } from './ScrollingListNextButton'\nimport { ScrollingListPrevButton as PrevButton } from './ScrollingListPrevButton'\nimport { ScrollingListSkipButton as SkipButton } from './ScrollingListSkipButton'\n\n/**\n * A horizontal scrollable list component with optional snap points and navigation controls.\n */\nexport const ScrollingList: typeof Root & {\n Controls: typeof Controls\n NextButton: typeof NextButton\n PrevButton: typeof PrevButton\n Item: typeof Item\n Items: typeof Items\n SkipButton: typeof SkipButton\n} = Object.assign(Root, {\n Controls,\n NextButton,\n PrevButton,\n Item,\n Items,\n SkipButton,\n})\n\nScrollingList.displayName = 'ScrollingList'\n"],"mappings":";;;;;;;;;;;;AAiEA,IAAa,IAAuB,EAClC,KACD,EAEY,KAAiB,EAC5B,cAAW,QACX,cAAW,UACX,oBAAiB,UACjB,UAAO,IACP,SAAM,IACN,cAAW,IACX,mBAAgB,GAChB,aACA,cACA,GAAG,QACQ;CACX,IAAM,IAAgB,EAAuB,KAAK,EAC5C,IAAgB,EAA0B,KAAK,EAE/C,IAAkB,GAAiB,EAEnC,EAAE,aAAU,SAAS,MAAoB,EAAkB,GAAe,EAC9E,mBAAmB,GACpB,CAAC,EAEI,EAAE,oBAAiB,UAAO,eAAY,GAEtC,IAAe,EAAM,IAErB,IAAoB,IACrB,CAAC,EAAa,KAAM,GAAG,EAAa,EAAa,SAAS,KAAM,EAAE,GAClE,CAAC,GAAG,EAAE,EAGL,IAAe,QAAkB;AACrC,EAAI,KAAW,EAAc,WAE3B,iBAAiB;AACf,MAAS;KACR,EAAE;IAEN,CAAC,EAAQ,CAAC;AAMb,CAJA,QAAgB;AACd,KAAc;IACb,CAAC,GAAU,EAAa,CAAC,EAE5B,QAAsB;AACpB,EAAI,EAAc,WAGhB,4BAA4B;AAC1B,MAAiB;IACjB;IAEH,CAAC,GAAU,EAAgB,CAAC;CAE/B,IAAM,UAA+B;AACnC,IAAc,SAAS,OAAO;IAG1B,IAAsC;EAC1C,GAAG;EACH;EACA;EACA;EACA;EACA;EACA;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jB,EAAwB,cAAc;;;ACrCtC,IAAa,KAA2B,EACtC,cAAc,GAEd,GAAG,QACkB;CACrB,IAAM,IAAM,EAAW,EAAqB,EAEtC,UAAuB;AAI3B,EAFE,EAAI,oBAAoB,MAAM,EAAI,cAAc,SAAS,cAAc,KAAK,IAG5E,EAAI,KAAK,GAAG,EAAE,UAAU,EAAI,gBAAgB,CAAC,GACpC,EAAI,cACb,EAAI,KAAK,EAAE,UAAU,EAAI,gBAAgB,CAAC,GAE1C,EAAI,KAAK,EAAI,MAAM,SAAS,GAAG,EAAE,UAAU,EAAI,gBAAgB,CAAC;IAK9D,IAAa,EADK,EAAI,SAAS,QAAQ,EAAI,SAAS,UAClB,CAAC,EAAI,QAAQ,CAAC,EAAI,SAAS;AAEnE,QACE,kBAAC,GAAD;EACE,wBAAqB;EACrB,MAAK;EACL,QAAO;EACP,QAAO;EACP,WAAW,EACT,gGACA,qEACD;EACD,SAAS;EACT,UAAU;EACV,cAAY;EACZ,iBAAc;EACd,GAAI;YAEJ,kBAAC,GAAD,EAAA,UACE,kBAAC,GAAD,EAAqB,CAAA,EAChB,CAAA;EACI,CAAA;;AAIjB,EAAwB,cAAc;;;AC5CtC,IAAa,KAA2B,EAAE,aAAU,GAAG,QAAkB;CACvE,IAAM,IAAM,EAAW,EAAqB;AAE5C,QACE,kBAAC,GAAD;EACE,MAAK;EACL,QAAO;EACP,QAAO;EACP,UAAU;EACV,WAAW,EACT,qDACA,6FACD;EACD,SAAS,EAAI;EACb,GAAI;EAEH;EACM,CAAA;;AAIb,EAAwB,cAAc;;;ACrBtC,IAAa,IAOT,OAAO,OAAO,GAAM;CACtB,UAAA;CACA,YAAA;CACA,YAAA;CACA,MAAA;CACA,OAAA;CACA,YAAA;CACD,CAAC;AAEF,EAAc,cAAc"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/scrolling-list/ScrollingList.tsx","../../src/scrolling-list/ScrollingListControls.tsx","../../src/scrolling-list/useFocusWithinScroll.tsx","../../src/scrolling-list/ScrollingListItem.tsx","../../src/scrolling-list/ScrollingListItems.tsx","../../src/scrolling-list/ScrollingListNextButton.tsx","../../src/scrolling-list/ScrollingListPrevButton.tsx","../../src/scrolling-list/ScrollingListSkipButton.tsx","../../src/scrolling-list/index.ts"],"sourcesContent":["import { ScrollOverflow, useScrollOverflow } from '@spark-ui/hooks/use-scroll-overflow'\nimport { cx } from 'class-variance-authority'\nimport {\n ComponentPropsWithRef,\n createContext,\n ReactNode,\n RefObject,\n useCallback,\n useEffect,\n useLayoutEffect,\n useRef,\n} from 'react'\nimport { SnapCarouselResult, useSnapCarousel } from 'react-snap-carousel'\n\ntype SnapType = 'mandatory' | 'proximity' | 'none'\ntype ScrollBehavior = 'smooth' | 'instant'\ntype SnapStop = 'normal' | 'always'\n\ninterface Props extends ComponentPropsWithRef<'div'> {\n /**\n * CSS scroll snap behavior.\n * - `mandatory` to force snapping on each \"page\".\n * - `proximity` to force snapping only when scroll position is near the edge of a \"page\". Behavior can change depending on each browser.\n * - `none` to disabled scroll snapping.\n */\n snapType?: SnapType\n /**\n * Defines whether or not the scroll container is allowed to \"pass over\" possible snap positions.\n */\n snapStop?: SnapStop\n scrollBehavior?: ScrollBehavior\n /**\n * Add a fade effect to indicate content overflow.\n */\n withFade?: boolean\n children?: ReactNode\n /**\n * When `true`, allow previous and next buttons to be used when reaching the edges of the list.\n */\n loop?: boolean\n /**\n * Space (in pixels) between items.\n */\n gap?: number\n /**\n * Offset (in pixels) of the left of the optimal viewing region of the list.\n */\n scrollPadding?: number\n className?: string\n}\n\ninterface ScrollingListContextState extends SnapCarouselResult {\n snapType: SnapType\n snapStop: SnapStop\n scrollBehavior: ScrollBehavior\n visibleItemsRange: readonly [number, number]\n loop: boolean\n gap: number\n withFade: boolean\n scrollPadding: number\n scrollAreaRef: RefObject<HTMLDivElement | null>\n overflow: ScrollOverflow\n skipKeyboardNavigation: () => void\n}\n\nexport const ScrollingListContext = createContext<ScrollingListContextState>(\n null as unknown as ScrollingListContextState\n)\n\nexport const ScrollingList = ({\n snapType = 'none',\n snapStop = 'normal',\n scrollBehavior = 'smooth',\n loop = false,\n gap = 16,\n withFade = false,\n scrollPadding = 0,\n children,\n className,\n ...rest\n}: Props) => {\n const scrollAreaRef = useRef<HTMLDivElement>(null)\n const skipAnchorRef = useRef<HTMLButtonElement>(null)\n\n const snapCarouselAPI = useSnapCarousel()\n\n const { overflow, refresh: refreshOverflow } = useScrollOverflow(scrollAreaRef, {\n precisionTreshold: 1,\n })\n\n const { activePageIndex, pages, refresh } = snapCarouselAPI\n\n const visibleItems = pages[activePageIndex] as number[]\n\n const visibleItemsRange = visibleItems\n ? ([visibleItems[0]! + 1, visibleItems[visibleItems.length - 1]! + 1] as const)\n : ([0, 0] as const)\n\n // Force refresh of the carousel API when children change\n const forceRefresh = useCallback(() => {\n if (refresh && scrollAreaRef.current) {\n // Small delay to ensure DOM is updated\n setTimeout(() => {\n refresh()\n }, 0)\n }\n }, [refresh])\n\n useEffect(() => {\n forceRefresh()\n }, [children, forceRefresh])\n\n useLayoutEffect(() => {\n if (scrollAreaRef.current) {\n // Use requestAnimationFrame to ensure proper timing with the render cycle\n // This prevents race conditions that occur when the console is closed\n requestAnimationFrame(() => {\n refreshOverflow()\n })\n }\n }, [children, refreshOverflow])\n\n const skipKeyboardNavigation = () => {\n skipAnchorRef.current?.focus()\n }\n\n const ctxValue: ScrollingListContextState = {\n ...snapCarouselAPI,\n snapType,\n snapStop,\n skipKeyboardNavigation,\n scrollBehavior,\n visibleItemsRange,\n loop,\n gap,\n withFade,\n scrollPadding,\n scrollAreaRef,\n overflow,\n }\n\n return (\n <ScrollingListContext value={ctxValue}>\n <div\n data-spark-component=\"scrolling-list\"\n className={cx(\n 'gap-lg group/scrolling-list relative flex flex-col default:w-full',\n className\n )}\n {...rest}\n >\n {children}\n </div>\n <span ref={skipAnchorRef} className=\"size-0 overflow-hidden\" tabIndex={-1} />\n </ScrollingListContext>\n )\n}\n\nScrollingList.displayName = 'ScrollingList'\n","import { cx } from 'class-variance-authority'\nimport { ComponentPropsWithoutRef, CSSProperties, ReactNode } from 'react'\n\ninterface ScrollingListControls extends ComponentPropsWithoutRef<'div'> {\n /**\n * Visibility behavior of the control buttons:\n * - `always`: buttons are always visible.\n * - `hover`: buttons only appear on hover.\n *\n * a11y: `hover` is dangerous for accessibility as it disabled controls for touch screen users.\n * When using it, you must provide an alternative control outside of the list to replace them.\n */\n visibility?: 'hover' | 'always'\n children: ReactNode\n}\n\n/** Container for navigation controls (previous/next buttons) of the scrolling list. Renders a <div> element. */\nexport const ScrollingListControls = ({\n children,\n visibility = 'always',\n className,\n ...rest\n}: ScrollingListControls) => {\n return (\n <div\n data-spark-component=\"scrolling-list-controls\"\n className={cx(\n 'default:px-md pointer-events-none absolute inset-0 flex flex-row items-center justify-between overflow-hidden',\n className\n )}\n style={\n {\n '--scrolling-list-controls-opacity': visibility === 'hover' ? '0' : '1',\n } as CSSProperties\n }\n data-orientation=\"horizontal\"\n {...rest}\n >\n {children}\n </div>\n )\n}\n\nScrollingListControls.displayName = 'ScrollingList.Controls'\n","import { RefObject, useEffect, useState } from 'react'\n\nexport function useFocusWithinScroll<T extends HTMLElement | null>(\n ref: RefObject<T>, // The container to detect focus within\n scrollRef: RefObject<HTMLDivElement | null> // The scrollable container\n) {\n const [isFocusWithin, setIsFocusWithin] = useState(false)\n\n useEffect(() => {\n const handleFocusIn = (event: FocusEvent) => {\n setIsFocusWithin(true)\n\n const focusedElement = event.target as HTMLElement\n const scrollContainer = scrollRef.current\n\n if (focusedElement && scrollContainer) {\n const focusRect = focusedElement.getBoundingClientRect()\n const scrollRect = scrollContainer.getBoundingClientRect()\n\n // Check if the focused element is fully visible inside the scroll container\n const isFullyVisible =\n focusRect.left >= scrollRect.left &&\n focusRect.right <= scrollRect.right &&\n focusRect.top >= scrollRect.top &&\n focusRect.bottom <= scrollRect.bottom\n\n if (!isFullyVisible) {\n focusedElement.scrollIntoView({ behavior: 'smooth', inline: 'center', block: 'nearest' })\n }\n }\n }\n\n const handleFocusOut = (event: FocusEvent) => {\n if (ref.current && !ref.current.contains(event.relatedTarget as Node)) {\n setIsFocusWithin(false)\n }\n }\n\n const node = ref.current\n if (node) {\n node.addEventListener('focusin', handleFocusIn)\n node.addEventListener('focusout', handleFocusOut)\n }\n\n return () => {\n if (node) {\n node.removeEventListener('focusin', handleFocusIn)\n node.removeEventListener('focusout', handleFocusOut)\n }\n }\n }, [ref, scrollRef])\n\n return isFocusWithin\n}\n","import { cx } from 'class-variance-authority'\nimport { ComponentPropsWithoutRef, ReactNode, useContext, useRef } from 'react'\n\nimport { Slot } from '../slot'\nimport { ScrollingListContext } from './ScrollingList'\nimport { useFocusWithinScroll } from './useFocusWithinScroll'\n\nexport interface ScrollingListItemProps extends ComponentPropsWithoutRef<'div'> {\n /**\n * Change the default rendered element for the one passed as a child, merging their props and behavior.\n */\n asChild?: boolean\n children?: ReactNode\n /**\n * DO NOT USE. This prop is automatically managed by the parent ScrollingList.ListItems\n */\n index?: number\n className?: string\n}\n\n/** A single item in the scrolling list. Renders a <div> element. */\nexport const ScrollingListItem = ({\n asChild = false,\n children,\n index = 0,\n className = '',\n ...rest\n}: ScrollingListItemProps) => {\n const ctx = useContext(ScrollingListContext)\n const itemRef = useRef<HTMLDivElement>(null)\n\n const isSnapPoint = ctx.snapPointIndexes.has(index)\n\n useFocusWithinScroll(itemRef, ctx.scrollAreaRef)\n\n const Component = asChild ? Slot : 'div'\n\n return (\n <Component\n data-spark-component=\"scrolling-list-item\"\n role=\"listitem\"\n ref={itemRef}\n className={cx(\n 'default:w-auto default:shrink-0',\n {\n 'snap-start': isSnapPoint,\n 'snap-normal': isSnapPoint && ctx.snapStop === 'normal',\n 'snap-always': isSnapPoint && ctx.snapStop === 'always',\n },\n className\n )}\n {...rest}\n >\n {children}\n </Component>\n )\n}\n\nScrollingListItem.displayName = 'ScrollingList.Item'\n","import { cx } from 'class-variance-authority'\nimport {\n Children,\n cloneElement,\n ComponentPropsWithRef,\n CSSProperties,\n isValidElement,\n KeyboardEvent,\n ReactNode,\n Ref,\n RefObject,\n useContext,\n} from 'react'\n\nimport { ScrollingListContext } from './ScrollingList'\nimport { ScrollingListItemProps } from './ScrollingListItem'\n\ninterface Props extends ComponentPropsWithRef<'div'> {\n children?: ReactNode\n className?: string\n}\n\nexport function mergeRefs<T>(...refs: (Ref<T> | undefined | null)[]): Ref<T> {\n return (value: T | null) => {\n refs.forEach(ref => {\n if (typeof ref === 'function') {\n ref(value)\n } else if (ref && typeof ref === 'object' && 'current' in ref) {\n ;(ref as RefObject<T | null>).current = value\n }\n })\n }\n}\n\n/** The scrollable container for the list items. Renders a <div> element. */\nexport const ScrollingListItems = ({ children, ref, className = '', ...rest }: Props) => {\n const ctx = useContext(ScrollingListContext)\n\n const snapConfig = {\n mandatory: 'x mandatory',\n proximity: 'x proximity',\n none: 'none',\n }\n\n const handleLeftArrow = (event: KeyboardEvent<HTMLDivElement>) => {\n if (!ctx.loop && !ctx.hasPrevPage) return\n\n event.preventDefault()\n ctx.goTo(ctx.hasPrevPage ? ctx.activePageIndex - 1 : ctx.pages.length - 1, {\n behavior: ctx.scrollBehavior,\n })\n }\n\n const handleRightArrow = (event: KeyboardEvent<HTMLDivElement>) => {\n if (!ctx.loop && !ctx.hasNextPage) return\n\n event.preventDefault()\n ctx.goTo(ctx.hasNextPage ? ctx.activePageIndex + 1 : 0, { behavior: ctx.scrollBehavior })\n }\n\n const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n if (event.key === 'ArrowLeft') {\n handleLeftArrow(event)\n }\n\n if (event.key === 'ArrowRight') {\n handleRightArrow(event)\n }\n }\n\n interface CustomCSSProperties extends CSSProperties {\n '--scrolling-list-gap'?: string\n '--scrolling-list-px'?: string\n }\n\n const inlineStyles: CustomCSSProperties = {\n scrollSnapType: snapConfig[ctx.snapType],\n scrollPaddingInline: 'var(--scrolling-list-px)',\n '--scrolling-list-px': `${ctx.scrollPadding}px`,\n '--scrolling-list-gap': `${ctx.gap}px`,\n ...(ctx.withFade && {\n maskImage:\n 'linear-gradient(to right, rgba(0, 0, 0, 0), rgba(0, 0, 0, 1) 44px, rgba(0, 0, 0, 1) calc(100% - 44px), rgba(0, 0, 0, 0))',\n maskSize: `calc(100% + ${ctx.overflow.left ? '0px' : '44px'} + ${ctx.overflow.right ? '0px' : '44px'}) 100%`,\n maskPosition: `${ctx.overflow.left ? '0px' : '-44px'} 0`,\n }),\n }\n\n return (\n <div\n data-spark-component=\"scrolling-list-items\"\n id=\"scrolling-list-items\"\n role=\"list\"\n className={cx(\n 'relative transition-all duration-300',\n 'u-no-scrollbar overflow-x-auto scroll-smooth',\n 'w-full gap-(--scrolling-list-gap) default:flex default:flex-row',\n 'focus-visible:u-outline',\n className\n )}\n ref={mergeRefs<HTMLDivElement>(ctx.scrollAreaRef, ctx.scrollRef, ref)}\n style={inlineStyles}\n onKeyDown={handleKeyDown}\n {...rest}\n >\n {Children.map(children, (child, index) =>\n isValidElement<ScrollingListItemProps>(child) ? cloneElement(child, { index }) : child\n )}\n </div>\n )\n}\n\nScrollingListItems.displayName = 'ScrollingList.Items'\n","import { ArrowVerticalRight } from '@spark-ui/icons/ArrowVerticalRight'\nimport { cx } from 'class-variance-authority'\nimport { useContext } from 'react'\n\nimport { Icon } from '../icon'\nimport { IconButton, IconButtonProps } from '../icon-button'\nimport { ScrollingListContext } from './ScrollingList'\n\n/** A button to scroll to the next page of items. Renders a <button> element. */\nexport const ScrollingListNextButton = ({ 'aria-label': ariaLabel, ...rest }: IconButtonProps) => {\n const ctx = useContext(ScrollingListContext)\n\n const handleNextPage = () => {\n if (ctx.hasNextPage) {\n ctx.next({ behavior: ctx.scrollBehavior })\n } else {\n ctx.goTo(0, { behavior: ctx.scrollBehavior })\n }\n }\n\n const listHasOverflow = ctx.overflow.left || ctx.overflow.right\n const isDisabled = !listHasOverflow || (!ctx.loop && !ctx.overflow.right)\n\n return (\n <IconButton\n data-spark-component=\"scrolling-list-next-button\"\n size=\"sm\"\n intent=\"surface\"\n design=\"filled\"\n className={cx(\n 'pointer-events-auto opacity-(--scrolling-list-controls-opacity) shadow-sm disabled:invisible',\n 'group-hover/scrolling-list:opacity-none focus-visible:opacity-none'\n )}\n onClick={handleNextPage}\n disabled={isDisabled}\n aria-label={ariaLabel}\n aria-controls=\"scrolling-list-items\"\n {...rest}\n >\n <Icon>\n <ArrowVerticalRight />\n </Icon>\n </IconButton>\n )\n}\n\nScrollingListNextButton.displayName = 'ScrollingList.NextButton'\n","import { ArrowVerticalLeft } from '@spark-ui/icons/ArrowVerticalLeft'\nimport { cx } from 'class-variance-authority'\nimport { useContext } from 'react'\n\nimport { Icon } from '../icon'\nimport { IconButton, IconButtonProps } from '../icon-button'\nimport { ScrollingListContext } from './ScrollingList'\n\n/** A button to scroll to the previous page of items. Renders a <button> element. */\nexport const ScrollingListPrevButton = ({\n 'aria-label': ariaLabel,\n\n ...rest\n}: IconButtonProps) => {\n const ctx = useContext(ScrollingListContext)\n\n const handlePrevPage = () => {\n const shouldSnapFirstPage =\n ctx.activePageIndex === 0 && (ctx.scrollAreaRef.current?.scrollLeft || 0) > 0\n\n if (shouldSnapFirstPage) {\n ctx.goTo(0, { behavior: ctx.scrollBehavior })\n } else if (ctx.hasPrevPage) {\n ctx.prev({ behavior: ctx.scrollBehavior })\n } else {\n ctx.goTo(ctx.pages.length - 1, { behavior: ctx.scrollBehavior })\n }\n }\n\n const listHasOverflow = ctx.overflow.left || ctx.overflow.right\n const isDisabled = !listHasOverflow || (!ctx.loop && !ctx.overflow.left)\n\n return (\n <IconButton\n data-spark-component=\"scrolling-list-prev-button\"\n size=\"sm\"\n intent=\"surface\"\n design=\"filled\"\n className={cx(\n 'pointer-events-auto opacity-(--scrolling-list-controls-opacity) shadow-sm disabled:invisible',\n 'group-hover/scrolling-list:opacity-none focus-visible:opacity-none'\n )}\n onClick={handlePrevPage}\n disabled={isDisabled}\n aria-label={ariaLabel}\n aria-controls=\"scrolling-list-items\"\n {...rest}\n >\n <Icon>\n <ArrowVerticalLeft />\n </Icon>\n </IconButton>\n )\n}\n\nScrollingListPrevButton.displayName = 'ScrollingList.PrevButton'\n","import { cx } from 'class-variance-authority'\nimport { ComponentPropsWithoutRef, useContext } from 'react'\n\nimport { Button } from '../button'\nimport { ScrollingListContext } from './ScrollingList'\n\ninterface Props extends ComponentPropsWithoutRef<'button'> {\n children: string\n}\n\n/** A button to skip keyboard navigation, improving accessibility. Renders a <button> element. */\nexport const ScrollingListSkipButton = ({ children, ...rest }: Props) => {\n const ctx = useContext(ScrollingListContext)\n\n return (\n <Button\n type=\"button\"\n design=\"tinted\"\n intent=\"surface\"\n tabIndex={0}\n className={cx(\n 'z-raised absolute top-1/2 left-0 -translate-y-1/2',\n 'not-focus-visible:pointer-events-none not-focus-visible:size-0 not-focus-visible:opacity-0'\n )}\n onClick={ctx.skipKeyboardNavigation}\n {...rest}\n >\n {children}\n </Button>\n )\n}\n\nScrollingListSkipButton.displayName = 'ScrollingList.SkipButton'\n","import { ScrollingList as Root } from './ScrollingList'\nimport { ScrollingListControls as Controls } from './ScrollingListControls'\nimport { ScrollingListItem as Item } from './ScrollingListItem'\nimport { ScrollingListItems as Items } from './ScrollingListItems'\nimport { ScrollingListNextButton as NextButton } from './ScrollingListNextButton'\nimport { ScrollingListPrevButton as PrevButton } from './ScrollingListPrevButton'\nimport { ScrollingListSkipButton as SkipButton } from './ScrollingListSkipButton'\n\n/**\n * A horizontal scrollable list component with optional snap points and navigation controls.\n */\nexport const ScrollingList: typeof Root & {\n Controls: typeof Controls\n NextButton: typeof NextButton\n PrevButton: typeof PrevButton\n Item: typeof Item\n Items: typeof Items\n SkipButton: typeof SkipButton\n} = Object.assign(Root, {\n Controls,\n NextButton,\n PrevButton,\n Item,\n Items,\n SkipButton,\n})\n\nScrollingList.displayName = 'ScrollingList'\n"],"mappings":";;;;;;;;;;;;AAiEA,IAAa,IAAuB,EAClC,KACD,EAEY,KAAiB,EAC5B,cAAW,QACX,cAAW,UACX,oBAAiB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;EACrB,MAAK;EACL,QAAO;EACP,QAAO;EACP,WAAW,EACT,gGACA,qEACD;EACD,SAAS;EACT,UAAU;EACV,cAAY;EACZ,iBAAc;EACd,GAAI;YAEJ,kBAAC,GAAD,EAAA,UACE,kBAAC,GAAD,EAAqB,CAAA,EAChB,CAAA;EACI,CAAA;;AAIjB,EAAwB,cAAc;;;AC5CtC,IAAa,KAA2B,EAAE,aAAU,GAAG,QAAkB;CACvE,IAAM,IAAM,EAAW,EAAqB;AAE5C,QACE,kBAAC,GAAD;EACE,MAAK;EACL,QAAO;EACP,QAAO;EACP,UAAU;EACV,WAAW,EACT,qDACA,6FACD;EACD,SAAS,EAAI;EACb,GAAI;EAEH;EACM,CAAA;;AAIb,EAAwB,cAAc;;;ACrBtC,IAAa,IAOT,OAAO,OAAO,GAAM;CACtB,UAAA;CACA,YAAA;CACA,YAAA;CACA,MAAA;CACA,OAAA;CACA,YAAA;CACD,CAAC;AAEF,EAAc,cAAc"}
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../chunk-C91j1N6u.js`);let e=require(`class-variance-authority`),t=require(`react`),n=require(`react/jsx-runtime`),r=require(`@spark-ui/hooks/use-merge-refs`),i=require(`@spark-ui/components/form-field`),a=require(`@base-ui/react/radio-group`),o=require(`@base-ui/react/radio`);var s=(0,e.cva)([`default:self-start`,`group inline-grid grid-flow-col auto-cols-fr`,`relative items-stretch min-w-max`,`rounded-xl p-sm`,`bg-surface border-sm border-outline`]),c=(0,e.cva)([`relative z-raised min-h-sz-44 focus-visible:outline-none`,`flex flex-none items-center justify-center gap-md`,`default:px-lg default:py-md`,`rounded-[20px]`,`cursor-pointer select-none`,`font-medium`,`transition-colors duration-150`,`outline-none`,`focus-visible:u-outline`,`data-disabled:cursor-not-allowed data-disabled:opacity-dim-3`,`data-checked:text-on-support-container`,`data-checked:[&>[data-spark-segmented-control-text]]:[text-shadow:0.35px_0_currentColor,-0.35px_0_currentColor]`]),l=(0,e.cva)([`absolute z-base`,`rounded-[20px]`,`bg-support-container border-md border-support`,`group-has-focus-visible:border-focus`,`transition-[left,top,width,height] duration-200 ease-in-out`,`pointer-events-none`]),u=(0,t.createContext)({}),d=()=>{let e=(0,t.useContext)(u);if(!e)throw Error(`useSegmentedControlContext must be used within a SegmentedControlContext Provider`);return e},f=e=>{let n=null;return t.Children.forEach(e,e=>{n===null&&(0,t.isValidElement)(e)&&typeof e.props.value==`string`&&(n=e.props.value)}),n},p=({value:e,defaultValue:o,onValueChange:c,className:l,children:d,ref:p,...m})=>{let h=(0,t.useRef)(null),g=(0,r.useMergeRefs)(h,p),_=f(d),v=e!==void 0,[y,b]=(0,t.useState)(()=>o??_),x=v?e??null:y,S=e=>{let t=e;v||b(t),c?.(t)},{labelId:C,description:w,isRequired:T,isInvalid:E,name:D}=(0,i.useFormFieldControl)();return(0,n.jsx)(u.Provider,{value:{checkedValue:x,containerRef:h},children:(0,n.jsx)(a.RadioGroup,{ref:g,value:v?e:void 0,defaultValue:v?void 0:o??_??void 0,onValueChange:S,"data-spark-component":`segmented-control`,className:s({className:l}),"aria-labelledby":C,"aria-describedby":w,"aria-required":T||void 0,"aria-invalid":E||void 0,name:D,...m,children:d})})};p.displayName=`SegmentedControl`;var m=({className:e,ref:r,...i})=>{let{checkedValue:a,containerRef:o}=d(),[s,c]=(0,t.useState)(null),u=(0,t.useMemo)(()=>a?`[data-value="${CSS.escape(a)}"]`:null,[a]);if((0,t.useEffect)(()=>{let e=o.current;if(!e)return;let t=u?e.querySelector(u):null,n=()=>{let e=o.current;if(!e||!u){c(null);return}let t=e.querySelector(u);if(!t){c(null);return}let n=e.getBoundingClientRect(),r=t.getBoundingClientRect(),i=t.offsetWidth>0?r.width/t.offsetWidth:1,a=t.offsetHeight>0?r.height/t.offsetHeight:1;c({left:(r.left-n.left)/i-e.clientLeft,top:(r.top-n.top)/a-e.clientTop,width:r.width/i,height:r.height/a})};n();let r=typeof ResizeObserver<`u`?new ResizeObserver(()=>{n()}):null;return r?.observe(e),t&&r?.observe(t),window.addEventListener(`resize`,n,{passive:!0}),window.visualViewport?.addEventListener(`resize`,n,{passive:!0}),()=>{r?.disconnect(),window.removeEventListener(`resize`,n),window.visualViewport?.removeEventListener(`resize`,n)}},[o,u]),!s)return null;let f={left:s.left,top:s.top,width:s.width,height:s.height};return(0,n.jsx)(`span`,{ref:r,"data-spark-component":`segmented-control-indicator`,"aria-hidden":!0,className:l({className:e}),style:f,...i})};m.displayName=`SegmentedControl.Indicator`;var h=({value:e,disabled:r=!1,children:i,className:a,ref:s,...l})=>{let u=t.Children.toArray(i).map((e,t)=>typeof e==`string`||typeof e==`number`?(0,n.jsx)(`span`,{"data-spark-segmented-control-text":!0,children:e},`text-${t}`):e);return(0,n.jsx)(o.Radio.Root,{ref:s,"data-spark-component":`segmented-control-item`,"data-value":e,value:e,disabled:r,className:c({className:a}),...l,children:u})};h.displayName=`SegmentedControl.Item`;var g=Object.assign(p,{Item:h,Indicator:m});g.displayName=`SegmentedControl`,h.displayName=`SegmentedControl.Item`,m.displayName=`SegmentedControl.Indicator`,exports.SegmentedControl=g;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../chunk-C91j1N6u.js`);let e=require(`class-variance-authority`),t=require(`react`),n=require(`react/jsx-runtime`),r=require(`@spark-ui/hooks/use-merge-refs`),i=require(`@spark-ui/components/form-field`),a=require(`@base-ui/react/radio-group`),o=require(`@base-ui/react/radio`);var s=(0,e.cva)([`default:self-start`,`group inline-grid grid-flow-col auto-cols-fr`,`relative items-stretch min-w-max`,`rounded-xl p-sm`,`bg-surface border-sm border-outline`]),c=(0,e.cva)([`relative z-raised min-h-sz-44 focus-visible:outline-none`,`flex flex-none items-center justify-center gap-md`,`default:px-lg default:py-md`,`rounded-[20px]`,`cursor-pointer select-none`,`font-medium`,`transition-colors duration-150`,`outline-none`,`focus-visible:u-outline`,`data-disabled:cursor-not-allowed data-disabled:opacity-dim-3`,`data-checked:text-on-support-container`,`data-checked:[&>[data-spark-segmented-control-text]]:[text-shadow:0.35px_0_currentColor,-0.35px_0_currentColor]`]),l=(0,e.cva)([`absolute z-base`,`rounded-[20px]`,`bg-support-container border-md border-support`,`group-has-focus-visible:border-focus`,`transition-[left,top,width,height] duration-200 ease-in-out`,`pointer-events-none`]),u=(0,t.createContext)({}),d=()=>{let e=(0,t.useContext)(u);if(!e)throw Error(`useSegmentedControlContext must be used within a SegmentedControlContext Provider`);return e},f=e=>{let n=null;return t.Children.forEach(e,e=>{n===null&&(0,t.isValidElement)(e)&&typeof e.props.value==`string`&&(n=e.props.value)}),n},p=({value:e,defaultValue:o,onValueChange:c,className:l,children:d,ref:p,...m})=>{let h=(0,t.useRef)(null),g=(0,r.useMergeRefs)(h,p),_=f(d),v=e!==void 0,[y,b]=(0,t.useState)(()=>o??_),x=v?e??null:y,S=e=>{let t=e;v||b(t),c?.(t)},{labelId:C,description:w,isRequired:T,isInvalid:E,name:D}=(0,i.useFormFieldControl)();return(0,n.jsx)(u,{value:{checkedValue:x,containerRef:h},children:(0,n.jsx)(a.RadioGroup,{ref:g,value:v?e:void 0,defaultValue:v?void 0:o??_??void 0,onValueChange:S,"data-spark-component":`segmented-control`,className:s({className:l}),"aria-labelledby":C,"aria-describedby":w,"aria-required":T||void 0,"aria-invalid":E||void 0,name:D,...m,children:d})})};p.displayName=`SegmentedControl`;var m=({className:e,ref:r,...i})=>{let{checkedValue:a,containerRef:o}=d(),[s,c]=(0,t.useState)(null),u=(0,t.useMemo)(()=>a?`[data-value="${CSS.escape(a)}"]`:null,[a]);if((0,t.useEffect)(()=>{let e=o.current;if(!e)return;let t=u?e.querySelector(u):null,n=()=>{let e=o.current;if(!e||!u){c(null);return}let t=e.querySelector(u);if(!t){c(null);return}let n=e.getBoundingClientRect(),r=t.getBoundingClientRect(),i=t.offsetWidth>0?r.width/t.offsetWidth:1,a=t.offsetHeight>0?r.height/t.offsetHeight:1;c({left:(r.left-n.left)/i-e.clientLeft,top:(r.top-n.top)/a-e.clientTop,width:r.width/i,height:r.height/a})};n();let r=typeof ResizeObserver<`u`?new ResizeObserver(()=>{n()}):null;return r?.observe(e),t&&r?.observe(t),window.addEventListener(`resize`,n,{passive:!0}),window.visualViewport?.addEventListener(`resize`,n,{passive:!0}),()=>{r?.disconnect(),window.removeEventListener(`resize`,n),window.visualViewport?.removeEventListener(`resize`,n)}},[o,u]),!s)return null;let f={left:s.left,top:s.top,width:s.width,height:s.height};return(0,n.jsx)(`span`,{ref:r,"data-spark-component":`segmented-control-indicator`,"aria-hidden":!0,className:l({className:e}),style:f,...i})};m.displayName=`SegmentedControl.Indicator`;var h=({value:e,disabled:r=!1,children:i,className:a,ref:s,...l})=>{let u=t.Children.toArray(i).map((e,t)=>typeof e==`string`||typeof e==`number`?(0,n.jsx)(`span`,{"data-spark-segmented-control-text":!0,children:e},`text-${t}`):e);return(0,n.jsx)(o.Radio.Root,{ref:s,"data-spark-component":`segmented-control-item`,"data-value":e,value:e,disabled:r,className:c({className:a}),...l,children:u})};h.displayName=`SegmentedControl.Item`;var g=Object.assign(p,{Item:h,Indicator:m});g.displayName=`SegmentedControl`,h.displayName=`SegmentedControl.Item`,m.displayName=`SegmentedControl.Indicator`,exports.SegmentedControl=g;
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/segmented-control/SegmentedControl.styles.ts","../../src/segmented-control/SegmentedControlContext.tsx","../../src/segmented-control/SegmentedControl.tsx","../../src/segmented-control/SegmentedControlIndicator.tsx","../../src/segmented-control/SegmentedControlItem.tsx","../../src/segmented-control/index.ts"],"sourcesContent":["import { cva, VariantProps } from 'class-variance-authority'\n\nexport const rootStyles = cva([\n 'default:self-start',\n 'group inline-grid grid-flow-col auto-cols-fr',\n 'relative items-stretch min-w-max',\n 'rounded-xl p-sm',\n 'bg-surface border-sm border-outline',\n])\n\nexport const itemStyles = cva([\n 'relative z-raised min-h-sz-44 focus-visible:outline-none',\n 'flex flex-none items-center justify-center gap-md',\n 'default:px-lg default:py-md',\n 'rounded-[20px]',\n 'cursor-pointer select-none',\n 'font-medium',\n 'transition-colors duration-150',\n 'outline-none',\n 'focus-visible:u-outline',\n 'data-disabled:cursor-not-allowed data-disabled:opacity-dim-3',\n 'data-checked:text-on-support-container',\n // Avoid layout shift: simulate \"bold\" without changing font metrics.\n // Apply only to wrapped text nodes (not arbitrary nested JSX like Tag).\n 'data-checked:[&>[data-spark-segmented-control-text]]:[text-shadow:0.35px_0_currentColor,-0.35px_0_currentColor]',\n])\n\nexport const indicatorStyles = cva([\n 'absolute z-base',\n 'rounded-[20px]',\n 'bg-support-container border-md border-support',\n 'group-has-focus-visible:border-focus',\n 'transition-[left,top,width,height] duration-200 ease-in-out',\n 'pointer-events-none',\n])\n\nexport type SegmentedControlStylesProps = VariantProps<typeof itemStyles>\n","import { createContext, RefObject, useContext } from 'react'\n\nexport interface SegmentedControlContextInterface {\n checkedValue: string | null\n containerRef: RefObject<HTMLDivElement | null>\n}\n\nexport const SegmentedControlContext = createContext<SegmentedControlContextInterface>(\n {} as SegmentedControlContextInterface\n)\n\nexport const useSegmentedControlContext = () => {\n const context = useContext(SegmentedControlContext)\n\n if (!context) {\n throw Error('useSegmentedControlContext must be used within a SegmentedControlContext Provider')\n }\n\n return context\n}\n","import { RadioGroup } from '@base-ui/react/radio-group'\nimport { useFormFieldControl } from '@spark-ui/components/form-field'\nimport { useMergeRefs } from '@spark-ui/hooks/use-merge-refs'\nimport { Children, type ComponentProps, isValidElement, Ref, useRef, useState } from 'react'\n\nimport type { SegmentedControlStylesProps } from './SegmentedControl.styles'\nimport { rootStyles } from './SegmentedControl.styles'\nimport { SegmentedControlContext } from './SegmentedControlContext'\n\nexport interface SegmentedControlProps\n extends\n Omit<ComponentProps<typeof RadioGroup>, 'value' | 'defaultValue' | 'onValueChange'>,\n SegmentedControlStylesProps {\n /**\n * The controlled selected value.\n */\n value?: string\n /**\n * The uncontrolled default selected value.\n */\n defaultValue?: string\n /**\n * Callback fired when the selected value changes.\n */\n onValueChange?: (value: string) => void\n ref?: Ref<HTMLDivElement>\n}\n\nconst getFirstItemValue = (children: React.ReactNode): string | null => {\n let firstValue: string | null = null\n\n Children.forEach(children, child => {\n if (firstValue !== null) return\n if (isValidElement(child) && typeof (child.props as { value?: string }).value === 'string') {\n firstValue = (child.props as { value: string }).value\n }\n })\n\n return firstValue\n}\n\nexport const SegmentedControl = ({\n value,\n defaultValue,\n onValueChange,\n className,\n children,\n ref,\n ...rest\n}: SegmentedControlProps) => {\n const containerRef = useRef<HTMLDivElement | null>(null)\n const mergedRef = useMergeRefs(containerRef, ref)\n\n const firstValue = getFirstItemValue(children)\n\n const isControlled = value !== undefined\n const [internalValue, setInternalValue] = useState<string | null>(\n () => defaultValue ?? firstValue\n )\n const checkedValue = isControlled ? (value ?? null) : internalValue\n\n const handleValueChange = (newValue: unknown) => {\n const next = newValue as string\n\n if (!isControlled) {\n setInternalValue(next)\n }\n\n onValueChange?.(next)\n }\n\n const { labelId, description, isRequired, isInvalid, name } = useFormFieldControl()\n\n return (\n <SegmentedControlContext.Provider\n value={{\n checkedValue,\n containerRef,\n }}\n >\n <RadioGroup\n ref={mergedRef}\n value={isControlled ? value : undefined}\n defaultValue={!isControlled ? (defaultValue ?? firstValue ?? undefined) : undefined}\n onValueChange={handleValueChange}\n data-spark-component=\"segmented-control\"\n className={rootStyles({ className })}\n aria-labelledby={labelId}\n aria-describedby={description}\n aria-required={isRequired || undefined}\n aria-invalid={isInvalid || undefined}\n name={name}\n {...rest}\n >\n {children}\n </RadioGroup>\n </SegmentedControlContext.Provider>\n )\n}\n\nSegmentedControl.displayName = 'SegmentedControl'\n","import { type ComponentProps, type CSSProperties, Ref, useEffect, useMemo, useState } from 'react'\n\nimport { indicatorStyles } from './SegmentedControl.styles'\nimport { useSegmentedControlContext } from './SegmentedControlContext'\n\ninterface IndicatorRect {\n left: number\n top: number\n width: number\n height: number\n}\n\nexport interface SegmentedControlIndicatorProps extends ComponentProps<'span'> {\n ref?: Ref<HTMLSpanElement>\n}\n\n/** The visual indicator that highlights the selected item. Renders a <span> element. */\nexport const SegmentedControlIndicator = ({\n className,\n ref,\n ...rest\n}: SegmentedControlIndicatorProps) => {\n const { checkedValue, containerRef } = useSegmentedControlContext()\n const [rect, setRect] = useState<IndicatorRect | null>(null)\n\n const selector = useMemo(\n () => (checkedValue ? `[data-value=\"${CSS.escape(checkedValue)}\"]` : null),\n [checkedValue]\n )\n\n useEffect(() => {\n const container = containerRef.current\n\n if (!container) {\n return\n }\n\n const selectedItem = selector ? container.querySelector<HTMLElement>(selector) : null\n\n const update = () => {\n const currentContainer = containerRef.current\n if (!currentContainer || !selector) {\n setRect(null)\n\n return\n }\n\n const currentSelected = currentContainer.querySelector<HTMLElement>(selector)\n if (!currentSelected) {\n setRect(null)\n\n return\n }\n\n const containerRect = currentContainer.getBoundingClientRect()\n const itemRect = currentSelected.getBoundingClientRect()\n\n // Storybook canvas \"zoom\" can be implemented via `transform: scale()`.\n // In that case, `getBoundingClientRect()` returns *scaled* values, but CSS positioning/sizing\n // expects unscaled layout pixels. We infer the scale factor from offset sizes and normalize.\n const scaleX =\n currentSelected.offsetWidth > 0 ? itemRect.width / currentSelected.offsetWidth : 1\n const scaleY =\n currentSelected.offsetHeight > 0 ? itemRect.height / currentSelected.offsetHeight : 1\n\n // `getBoundingClientRect()` is border-box; absolute positioning is relative to the padding box.\n setRect({\n left: (itemRect.left - containerRect.left) / scaleX - currentContainer.clientLeft,\n top: (itemRect.top - containerRect.top) / scaleY - currentContainer.clientTop,\n width: itemRect.width / scaleX,\n height: itemRect.height / scaleY,\n })\n }\n\n update()\n\n const ro =\n typeof ResizeObserver !== 'undefined'\n ? new ResizeObserver(() => {\n update()\n })\n : null\n\n ro?.observe(container)\n if (selectedItem) ro?.observe(selectedItem)\n\n window.addEventListener('resize', update, { passive: true })\n window.visualViewport?.addEventListener('resize', update, { passive: true })\n\n return () => {\n ro?.disconnect()\n window.removeEventListener('resize', update)\n window.visualViewport?.removeEventListener('resize', update)\n }\n }, [containerRef, selector])\n\n if (!rect) return null\n\n const style: CSSProperties = {\n left: rect.left,\n top: rect.top,\n width: rect.width,\n height: rect.height,\n }\n\n return (\n <span\n ref={ref}\n data-spark-component=\"segmented-control-indicator\"\n aria-hidden\n className={indicatorStyles({ className })}\n style={style}\n {...rest}\n />\n )\n}\n\nSegmentedControlIndicator.displayName = 'SegmentedControl.Indicator'\n","import { Radio } from '@base-ui/react/radio'\nimport { Children, type ComponentProps, Ref } from 'react'\n\nimport { itemStyles } from './SegmentedControl.styles'\n\nexport interface SegmentedControlItemProps extends Omit<\n ComponentProps<typeof Radio.Root>,\n 'value'\n> {\n /**\n * A unique value that identifies this item within the segmented control.\n */\n value: string\n /**\n * When true, prevents the user from interacting with this item.\n * @default false\n */\n disabled?: boolean\n ref?: Ref<HTMLElement>\n}\n\n/** A selectable item in the segmented control. Renders a <button> element. */\nexport const SegmentedControlItem = ({\n value,\n disabled = false,\n children,\n className,\n ref,\n ...rest\n}: SegmentedControlItemProps) => {\n const content = Children.toArray(children).map((child, index) => {\n if (typeof child === 'string' || typeof child === 'number') {\n return (\n <span key={`text-${index}`} data-spark-segmented-control-text>\n {child}\n </span>\n )\n }\n\n return child\n })\n\n return (\n <Radio.Root\n ref={ref}\n data-spark-component=\"segmented-control-item\"\n data-value={value}\n value={value}\n disabled={disabled}\n className={itemStyles({ className })}\n {...rest}\n >\n {content}\n </Radio.Root>\n )\n}\n\nSegmentedControlItem.displayName = 'SegmentedControl.Item'\n","import { SegmentedControl as Root } from './SegmentedControl'\nimport { SegmentedControlIndicator as Indicator } from './SegmentedControlIndicator'\nimport { SegmentedControlItem as Item } from './SegmentedControlItem'\n\n/**\n * A set of toggle buttons that allows users to select a single option from a group of related choices.\n */\nexport const SegmentedControl: typeof Root & {\n Item: typeof Item\n Indicator: typeof Indicator\n} = Object.assign(Root, {\n Item,\n Indicator,\n})\n\nSegmentedControl.displayName = 'SegmentedControl'\nItem.displayName = 'SegmentedControl.Item'\nIndicator.displayName = 'SegmentedControl.Indicator'\n\nexport type { SegmentedControlProps } from './SegmentedControl'\nexport type { SegmentedControlItemProps } from './SegmentedControlItem'\nexport type { SegmentedControlIndicatorProps } from './SegmentedControlIndicator'\n"],"mappings":"kWAEA,IAAa,GAAA,EAAA,EAAA,KAAiB,CAC5B,qBACA,+CACA,mCACA,kBACA,sCACD,CAAC,CAEW,GAAA,EAAA,EAAA,KAAiB,CAC5B,2DACA,oDACA,8BACA,iBACA,6BACA,cACA,iCACA,eACA,0BACA,+DACA,yCAGA,kHACD,CAAC,CAEW,GAAA,EAAA,EAAA,KAAsB,CACjC,kBACA,iBACA,gDACA,uCACA,8DACA,sBACD,CAAC,CC3BW,GAAA,EAAA,EAAA,eACX,EAAE,CACH,CAEY,MAAmC,CAC9C,IAAM,GAAA,EAAA,EAAA,YAAqB,EAAwB,CAEnD,GAAI,CAAC,EACH,MAAM,MAAM,oFAAoF,CAGlG,OAAO,GCUH,EAAqB,GAA6C,CACtE,IAAI,EAA4B,KAShC,OAPA,EAAA,SAAS,QAAQ,EAAU,GAAS,CAC9B,IAAe,OACnB,EAAA,EAAA,gBAAmB,EAAM,EAAI,OAAQ,EAAM,MAA6B,OAAU,WAChF,EAAc,EAAM,MAA4B,QAElD,CAEK,GAGI,GAAoB,CAC/B,QACA,eACA,gBACA,YACA,WACA,MACA,GAAG,KACwB,CAC3B,IAAM,GAAA,EAAA,EAAA,QAA6C,KAAK,CAClD,GAAA,EAAA,EAAA,cAAyB,EAAc,EAAI,CAE3C,EAAa,EAAkB,EAAS,CAExC,EAAe,IAAU,IAAA,GACzB,CAAC,EAAe,IAAA,EAAA,EAAA,cACd,GAAgB,EACvB,CACK,EAAe,EAAgB,GAAS,KAAQ,EAEhD,EAAqB,GAAsB,CAC/C,IAAM,EAAO,EAER,GACH,EAAiB,EAAK,CAGxB,IAAgB,EAAK,EAGjB,CAAE,UAAS,cAAa,aAAY,YAAW,SAAA,EAAA,EAAA,s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OAAO,EAAM,CACtB,KAAA,EACA,UAAA,EACD,CAAC,CAEF,EAAiB,YAAc,mBAC/B,EAAK,YAAc,wBACnB,EAAU,YAAc"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/segmented-control/SegmentedControl.styles.ts","../../src/segmented-control/SegmentedControlContext.tsx","../../src/segmented-control/SegmentedControl.tsx","../../src/segmented-control/SegmentedControlIndicator.tsx","../../src/segmented-control/SegmentedControlItem.tsx","../../src/segmented-control/index.ts"],"sourcesContent":["import { cva, VariantProps } from 'class-variance-authority'\n\nexport const rootStyles = cva([\n 'default:self-start',\n 'group inline-grid grid-flow-col auto-cols-fr',\n 'relative items-stretch min-w-max',\n 'rounded-xl p-sm',\n 'bg-surface border-sm border-outline',\n])\n\nexport const itemStyles = cva([\n 'relative z-raised min-h-sz-44 focus-visible:outline-none',\n 'flex flex-none items-center justify-center gap-md',\n 'default:px-lg default:py-md',\n 'rounded-[20px]',\n 'cursor-pointer select-none',\n 'font-medium',\n 'transition-colors duration-150',\n 'outline-none',\n 'focus-visible:u-outline',\n 'data-disabled:cursor-not-allowed data-disabled:opacity-dim-3',\n 'data-checked:text-on-support-container',\n // Avoid layout shift: simulate \"bold\" without changing font metrics.\n // Apply only to wrapped text nodes (not arbitrary nested JSX like Tag).\n 'data-checked:[&>[data-spark-segmented-control-text]]:[text-shadow:0.35px_0_currentColor,-0.35px_0_currentColor]',\n])\n\nexport const indicatorStyles = cva([\n 'absolute z-base',\n 'rounded-[20px]',\n 'bg-support-container border-md border-support',\n 'group-has-focus-visible:border-focus',\n 'transition-[left,top,width,height] duration-200 ease-in-out',\n 'pointer-events-none',\n])\n\nexport type SegmentedControlStylesProps = VariantProps<typeof itemStyles>\n","import { createContext, RefObject, useContext } from 'react'\n\nexport interface SegmentedControlContextInterface {\n checkedValue: string | null\n containerRef: RefObject<HTMLDivElement | null>\n}\n\nexport const SegmentedControlContext = createContext<SegmentedControlContextInterface>(\n {} as SegmentedControlContextInterface\n)\n\nexport const useSegmentedControlContext = () => {\n const context = useContext(SegmentedControlContext)\n\n if (!context) {\n throw Error('useSegmentedControlContext must be used within a SegmentedControlContext Provider')\n }\n\n return context\n}\n","import { RadioGroup } from '@base-ui/react/radio-group'\nimport { useFormFieldControl } from '@spark-ui/components/form-field'\nimport { useMergeRefs } from '@spark-ui/hooks/use-merge-refs'\nimport { Children, type ComponentProps, isValidElement, Ref, useRef, useState } from 'react'\n\nimport type { SegmentedControlStylesProps } from './SegmentedControl.styles'\nimport { rootStyles } from './SegmentedControl.styles'\nimport { SegmentedControlContext } from './SegmentedControlContext'\n\nexport interface SegmentedControlProps\n extends\n Omit<ComponentProps<typeof RadioGroup>, 'value' | 'defaultValue' | 'onValueChange'>,\n SegmentedControlStylesProps {\n /**\n * The controlled selected value.\n */\n value?: string\n /**\n * The uncontrolled default selected value.\n */\n defaultValue?: string\n /**\n * Callback fired when the selected value changes.\n */\n onValueChange?: (value: string) => void\n ref?: Ref<HTMLDivElement>\n}\n\nconst getFirstItemValue = (children: React.ReactNode): string | null => {\n let firstValue: string | null = null\n\n Children.forEach(children, child => {\n if (firstValue !== null) return\n if (isValidElement(child) && typeof (child.props as { value?: string }).value === 'string') {\n firstValue = (child.props as { value: string }).value\n }\n })\n\n return firstValue\n}\n\nexport const SegmentedControl = ({\n value,\n defaultValue,\n onValueChange,\n className,\n children,\n ref,\n ...rest\n}: SegmentedControlProps) => {\n const containerRef = useRef<HTMLDivElement | null>(null)\n const mergedRef = useMergeRefs(containerRef, ref)\n\n const firstValue = getFirstItemValue(children)\n\n const isControlled = value !== undefined\n const [internalValue, setInternalValue] = useState<string | null>(\n () => defaultValue ?? firstValue\n )\n const checkedValue = isControlled ? (value ?? null) : internalValue\n\n const handleValueChange = (newValue: unknown) => {\n const next = newValue as string\n\n if (!isControlled) {\n setInternalValue(next)\n }\n\n onValueChange?.(next)\n }\n\n const { labelId, description, isRequired, isInvalid, name } = useFormFieldControl()\n\n return (\n <SegmentedControlContext\n value={{\n checkedValue,\n containerRef,\n }}\n >\n <RadioGroup\n ref={mergedRef}\n value={isControlled ? value : undefined}\n defaultValue={!isControlled ? (defaultValue ?? firstValue ?? undefined) : undefined}\n onValueChange={handleValueChange}\n data-spark-component=\"segmented-control\"\n className={rootStyles({ className })}\n aria-labelledby={labelId}\n aria-describedby={description}\n aria-required={isRequired || undefined}\n aria-invalid={isInvalid || undefined}\n name={name}\n {...rest}\n >\n {children}\n </RadioGroup>\n </SegmentedControlContext>\n )\n}\n\nSegmentedControl.displayName = 'SegmentedControl'\n","import { type ComponentProps, type CSSProperties, Ref, useEffect, useMemo, useState } from 'react'\n\nimport { indicatorStyles } from './SegmentedControl.styles'\nimport { useSegmentedControlContext } from './SegmentedControlContext'\n\ninterface IndicatorRect {\n left: number\n top: number\n width: number\n height: number\n}\n\nexport interface SegmentedControlIndicatorProps extends ComponentProps<'span'> {\n ref?: Ref<HTMLSpanElement>\n}\n\n/** The visual indicator that highlights the selected item. Renders a <span> element. */\nexport const SegmentedControlIndicator = ({\n className,\n ref,\n ...rest\n}: SegmentedControlIndicatorProps) => {\n const { checkedValue, containerRef } = useSegmentedControlContext()\n const [rect, setRect] = useState<IndicatorRect | null>(null)\n\n const selector = useMemo(\n () => (checkedValue ? `[data-value=\"${CSS.escape(checkedValue)}\"]` : null),\n [checkedValue]\n )\n\n useEffect(() => {\n const container = containerRef.current\n\n if (!container) {\n return\n }\n\n const selectedItem = selector ? container.querySelector<HTMLElement>(selector) : null\n\n const update = () => {\n const currentContainer = containerRef.current\n if (!currentContainer || !selector) {\n setRect(null)\n\n return\n }\n\n const currentSelected = currentContainer.querySelector<HTMLElement>(selector)\n if (!currentSelected) {\n setRect(null)\n\n return\n }\n\n const containerRect = currentContainer.getBoundingClientRect()\n const itemRect = currentSelected.getBoundingClientRect()\n\n // Storybook canvas \"zoom\" can be implemented via `transform: scale()`.\n // In that case, `getBoundingClientRect()` returns *scaled* values, but CSS positioning/sizing\n // expects unscaled layout pixels. We infer the scale factor from offset sizes and normalize.\n const scaleX =\n currentSelected.offsetWidth > 0 ? itemRect.width / currentSelected.offsetWidth : 1\n const scaleY =\n currentSelected.offsetHeight > 0 ? itemRect.height / currentSelected.offsetHeight : 1\n\n // `getBoundingClientRect()` is border-box; absolute positioning is relative to the padding box.\n setRect({\n left: (itemRect.left - containerRect.left) / scaleX - currentContainer.clientLeft,\n top: (itemRect.top - containerRect.top) / scaleY - currentContainer.clientTop,\n width: itemRect.width / scaleX,\n height: itemRect.height / scaleY,\n })\n }\n\n update()\n\n const ro =\n typeof ResizeObserver !== 'undefined'\n ? new ResizeObserver(() => {\n update()\n })\n : null\n\n ro?.observe(container)\n if (selectedItem) ro?.observe(selectedItem)\n\n window.addEventListener('resize', update, { passive: true })\n window.visualViewport?.addEventListener('resize', update, { passive: true })\n\n return () => {\n ro?.disconnect()\n window.removeEventListener('resize', update)\n window.visualViewport?.removeEventListener('resize', update)\n }\n }, [containerRef, selector])\n\n if (!rect) return null\n\n const style: CSSProperties = {\n left: rect.left,\n top: rect.top,\n width: rect.width,\n height: rect.height,\n }\n\n return (\n <span\n ref={ref}\n data-spark-component=\"segmented-control-indicator\"\n aria-hidden\n className={indicatorStyles({ className })}\n style={style}\n {...rest}\n />\n )\n}\n\nSegmentedControlIndicator.displayName = 'SegmentedControl.Indicator'\n","import { Radio } from '@base-ui/react/radio'\nimport { Children, type ComponentProps, Ref } from 'react'\n\nimport { itemStyles } from './SegmentedControl.styles'\n\nexport interface SegmentedControlItemProps extends Omit<\n ComponentProps<typeof Radio.Root>,\n 'value'\n> {\n /**\n * A unique value that identifies this item within the segmented control.\n */\n value: string\n /**\n * When true, prevents the user from interacting with this item.\n * @default false\n */\n disabled?: boolean\n ref?: Ref<HTMLElement>\n}\n\n/** A selectable item in the segmented control. Renders a <button> element. */\nexport const SegmentedControlItem = ({\n value,\n disabled = false,\n children,\n className,\n ref,\n ...rest\n}: SegmentedControlItemProps) => {\n const content = Children.toArray(children).map((child, index) => {\n if (typeof child === 'string' || typeof child === 'number') {\n return (\n <span key={`text-${index}`} data-spark-segmented-control-text>\n {child}\n </span>\n )\n }\n\n return child\n })\n\n return (\n <Radio.Root\n ref={ref}\n data-spark-component=\"segmented-control-item\"\n data-value={value}\n value={value}\n disabled={disabled}\n className={itemStyles({ className })}\n {...rest}\n >\n {content}\n </Radio.Root>\n )\n}\n\nSegmentedControlItem.displayName = 'SegmentedControl.Item'\n","import { SegmentedControl as Root } from './SegmentedControl'\nimport { SegmentedControlIndicator as Indicator } from './SegmentedControlIndicator'\nimport { SegmentedControlItem as Item } from './SegmentedControlItem'\n\n/**\n * A set of toggle buttons that allows users to select a single option from a group of related choices.\n */\nexport const SegmentedControl: typeof Root & {\n Item: typeof Item\n Indicator: typeof Indicator\n} = Object.assign(Root, {\n Item,\n Indicator,\n})\n\nSegmentedControl.displayName = 'SegmentedControl'\nItem.displayName = 'SegmentedControl.Item'\nIndicator.displayName = 'SegmentedControl.Indicator'\n\nexport type { SegmentedControlProps } from './SegmentedControl'\nexport type { SegmentedControlItemProps } from './SegmentedControlItem'\nexport type { SegmentedControlIndicatorProps } from './SegmentedControlIndicator'\n"],"mappings":"kWAEA,IAAa,GAAA,EAAA,EAAA,KAAiB,CAC5B,qBACA,+CACA,mCACA,kBACA,sCACD,CAAC,CAEW,GAAA,EAAA,EAAA,KAAiB,CAC5B,2DACA,oDACA,8BACA,iBACA,6BACA,cACA,iCACA,eACA,0BACA,+DACA,yCAGA,kHACD,CAAC,CAEW,GAAA,EAAA,EAAA,KAAsB,CACjC,kBACA,iBACA,gDACA,uCACA,8DACA,sBACD,CAAC,CC3BW,GAAA,EAAA,EAAA,eACX,EAAE,CACH,CAEY,MAAmC,CAC9C,IAAM,GAAA,EAAA,EAAA,YAAqB,EAAwB,CAEnD,GAAI,CAAC,EACH,MAAM,MAAM,oFAAoF,CAGlG,OAAO,GCUH,EAAqB,GAA6C,CACtE,IAAI,EAA4B,KAShC,OAPA,EAAA,SAAS,QAAQ,EAAU,GAAS,CAC9B,IAAe,OACn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AW,CAAC,CAClC,QACP,GAAI,EACJ,CAAA,EAIN,EAA0B,YAAc,6BC/FxC,IAAa,GAAwB,CACnC,QACA,WAAW,GACX,WACA,YACA,MACA,GAAG,KAC4B,CAC/B,IAAM,EAAU,EAAA,SAAS,QAAQ,EAAS,CAAC,KAAK,EAAO,IACjD,OAAO,GAAU,UAAY,OAAO,GAAU,UAE9C,EAAA,EAAA,KAAC,OAAD,CAA4B,oCAAA,YACzB,EACI,CAFI,QAAQ,IAEZ,CAIJ,EACP,CAEF,OACE,EAAA,EAAA,KAAC,EAAA,MAAM,KAAP,CACO,MACL,uBAAqB,yBACrB,aAAY,EACL,QACG,WACV,UAAW,EAAW,CAAE,YAAW,CAAC,CACpC,GAAI,WAEH,EACU,CAAA,EAIjB,EAAqB,YAAc,wBClDnC,IAAa,EAGT,OAAO,OAAO,EAAM,CACtB,KAAA,EACA,UAAA,EACD,CAAC,CAEF,EAAiB,YAAc,mBAC/B,EAAK,YAAc,wBACnB,EAAU,YAAc"}
@@ -46,7 +46,7 @@ var m = e([
46
46
  let t = e;
47
47
  v || x(t), n?.(t);
48
48
  }, { labelId: w, description: T, isRequired: E, isInvalid: D, name: O } = d();
49
- return /* @__PURE__ */ l(_.Provider, {
49
+ return /* @__PURE__ */ l(_, {
50
50
  value: {
51
51
  checkedValue: S,
52
52
  containerRef: p
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../src/segmented-control/SegmentedControl.styles.ts","../../src/segmented-control/SegmentedControlContext.tsx","../../src/segmented-control/SegmentedControl.tsx","../../src/segmented-control/SegmentedControlIndicator.tsx","../../src/segmented-control/SegmentedControlItem.tsx","../../src/segmented-control/index.ts"],"sourcesContent":["import { cva, VariantProps } from 'class-variance-authority'\n\nexport const rootStyles = cva([\n 'default:self-start',\n 'group inline-grid grid-flow-col auto-cols-fr',\n 'relative items-stretch min-w-max',\n 'rounded-xl p-sm',\n 'bg-surface border-sm border-outline',\n])\n\nexport const itemStyles = cva([\n 'relative z-raised min-h-sz-44 focus-visible:outline-none',\n 'flex flex-none items-center justify-center gap-md',\n 'default:px-lg default:py-md',\n 'rounded-[20px]',\n 'cursor-pointer select-none',\n 'font-medium',\n 'transition-colors duration-150',\n 'outline-none',\n 'focus-visible:u-outline',\n 'data-disabled:cursor-not-allowed data-disabled:opacity-dim-3',\n 'data-checked:text-on-support-container',\n // Avoid layout shift: simulate \"bold\" without changing font metrics.\n // Apply only to wrapped text nodes (not arbitrary nested JSX like Tag).\n 'data-checked:[&>[data-spark-segmented-control-text]]:[text-shadow:0.35px_0_currentColor,-0.35px_0_currentColor]',\n])\n\nexport const indicatorStyles = cva([\n 'absolute z-base',\n 'rounded-[20px]',\n 'bg-support-container border-md border-support',\n 'group-has-focus-visible:border-focus',\n 'transition-[left,top,width,height] duration-200 ease-in-out',\n 'pointer-events-none',\n])\n\nexport type SegmentedControlStylesProps = VariantProps<typeof itemStyles>\n","import { createContext, RefObject, useContext } from 'react'\n\nexport interface SegmentedControlContextInterface {\n checkedValue: string | null\n containerRef: RefObject<HTMLDivElement | null>\n}\n\nexport const SegmentedControlContext = createContext<SegmentedControlContextInterface>(\n {} as SegmentedControlContextInterface\n)\n\nexport const useSegmentedControlContext = () => {\n const context = useContext(SegmentedControlContext)\n\n if (!context) {\n throw Error('useSegmentedControlContext must be used within a SegmentedControlContext Provider')\n }\n\n return context\n}\n","import { RadioGroup } from '@base-ui/react/radio-group'\nimport { useFormFieldControl } from '@spark-ui/components/form-field'\nimport { useMergeRefs } from '@spark-ui/hooks/use-merge-refs'\nimport { Children, type ComponentProps, isValidElement, Ref, useRef, useState } from 'react'\n\nimport type { SegmentedControlStylesProps } from './SegmentedControl.styles'\nimport { rootStyles } from './SegmentedControl.styles'\nimport { SegmentedControlContext } from './SegmentedControlContext'\n\nexport interface SegmentedControlProps\n extends\n Omit<ComponentProps<typeof RadioGroup>, 'value' | 'defaultValue' | 'onValueChange'>,\n SegmentedControlStylesProps {\n /**\n * The controlled selected value.\n */\n value?: string\n /**\n * The uncontrolled default selected value.\n */\n defaultValue?: string\n /**\n * Callback fired when the selected value changes.\n */\n onValueChange?: (value: string) => void\n ref?: Ref<HTMLDivElement>\n}\n\nconst getFirstItemValue = (children: React.ReactNode): string | null => {\n let firstValue: string | null = null\n\n Children.forEach(children, child => {\n if (firstValue !== null) return\n if (isValidElement(child) && typeof (child.props as { value?: string }).value === 'string') {\n firstValue = (child.props as { value: string }).value\n }\n })\n\n return firstValue\n}\n\nexport const SegmentedControl = ({\n value,\n defaultValue,\n onValueChange,\n className,\n children,\n ref,\n ...rest\n}: SegmentedControlProps) => {\n const containerRef = useRef<HTMLDivElement | null>(null)\n const mergedRef = useMergeRefs(containerRef, ref)\n\n const firstValue = getFirstItemValue(children)\n\n const isControlled = value !== undefined\n const [internalValue, setInternalValue] = useState<string | null>(\n () => defaultValue ?? firstValue\n )\n const checkedValue = isControlled ? (value ?? null) : internalValue\n\n const handleValueChange = (newValue: unknown) => {\n const next = newValue as string\n\n if (!isControlled) {\n setInternalValue(next)\n }\n\n onValueChange?.(next)\n }\n\n const { labelId, description, isRequired, isInvalid, name } = useFormFieldControl()\n\n return (\n <SegmentedControlContext.Provider\n value={{\n checkedValue,\n containerRef,\n }}\n >\n <RadioGroup\n ref={mergedRef}\n value={isControlled ? value : undefined}\n defaultValue={!isControlled ? (defaultValue ?? firstValue ?? undefined) : undefined}\n onValueChange={handleValueChange}\n data-spark-component=\"segmented-control\"\n className={rootStyles({ className })}\n aria-labelledby={labelId}\n aria-describedby={description}\n aria-required={isRequired || undefined}\n aria-invalid={isInvalid || undefined}\n name={name}\n {...rest}\n >\n {children}\n </RadioGroup>\n </SegmentedControlContext.Provider>\n )\n}\n\nSegmentedControl.displayName = 'SegmentedControl'\n","import { type ComponentProps, type CSSProperties, Ref, useEffect, useMemo, useState } from 'react'\n\nimport { indicatorStyles } from './SegmentedControl.styles'\nimport { useSegmentedControlContext } from './SegmentedControlContext'\n\ninterface IndicatorRect {\n left: number\n top: number\n width: number\n height: number\n}\n\nexport interface SegmentedControlIndicatorProps extends ComponentProps<'span'> {\n ref?: Ref<HTMLSpanElement>\n}\n\n/** The visual indicator that highlights the selected item. Renders a <span> element. */\nexport const SegmentedControlIndicator = ({\n className,\n ref,\n ...rest\n}: SegmentedControlIndicatorProps) => {\n const { checkedValue, containerRef } = useSegmentedControlContext()\n const [rect, setRect] = useState<IndicatorRect | null>(null)\n\n const selector = useMemo(\n () => (checkedValue ? `[data-value=\"${CSS.escape(checkedValue)}\"]` : null),\n [checkedValue]\n )\n\n useEffect(() => {\n const container = containerRef.current\n\n if (!container) {\n return\n }\n\n const selectedItem = selector ? container.querySelector<HTMLElement>(selector) : null\n\n const update = () => {\n const currentContainer = containerRef.current\n if (!currentContainer || !selector) {\n setRect(null)\n\n return\n }\n\n const currentSelected = currentContainer.querySelector<HTMLElement>(selector)\n if (!currentSelected) {\n setRect(null)\n\n return\n }\n\n const containerRect = currentContainer.getBoundingClientRect()\n const itemRect = currentSelected.getBoundingClientRect()\n\n // Storybook canvas \"zoom\" can be implemented via `transform: scale()`.\n // In that case, `getBoundingClientRect()` returns *scaled* values, but CSS positioning/sizing\n // expects unscaled layout pixels. We infer the scale factor from offset sizes and normalize.\n const scaleX =\n currentSelected.offsetWidth > 0 ? itemRect.width / currentSelected.offsetWidth : 1\n const scaleY =\n currentSelected.offsetHeight > 0 ? itemRect.height / currentSelected.offsetHeight : 1\n\n // `getBoundingClientRect()` is border-box; absolute positioning is relative to the padding box.\n setRect({\n left: (itemRect.left - containerRect.left) / scaleX - currentContainer.clientLeft,\n top: (itemRect.top - containerRect.top) / scaleY - currentContainer.clientTop,\n width: itemRect.width / scaleX,\n height: itemRect.height / scaleY,\n })\n }\n\n update()\n\n const ro =\n typeof ResizeObserver !== 'undefined'\n ? new ResizeObserver(() => {\n update()\n })\n : null\n\n ro?.observe(container)\n if (selectedItem) ro?.observe(selectedItem)\n\n window.addEventListener('resize', update, { passive: true })\n window.visualViewport?.addEventListener('resize', update, { passive: true })\n\n return () => {\n ro?.disconnect()\n window.removeEventListener('resize', update)\n window.visualViewport?.removeEventListener('resize', update)\n }\n }, [containerRef, selector])\n\n if (!rect) return null\n\n const style: CSSProperties = {\n left: rect.left,\n top: rect.top,\n width: rect.width,\n height: rect.height,\n }\n\n return (\n <span\n ref={ref}\n data-spark-component=\"segmented-control-indicator\"\n aria-hidden\n className={indicatorStyles({ className })}\n style={style}\n {...rest}\n />\n )\n}\n\nSegmentedControlIndicator.displayName = 'SegmentedControl.Indicator'\n","import { Radio } from '@base-ui/react/radio'\nimport { Children, type ComponentProps, Ref } from 'react'\n\nimport { itemStyles } from './SegmentedControl.styles'\n\nexport interface SegmentedControlItemProps extends Omit<\n ComponentProps<typeof Radio.Root>,\n 'value'\n> {\n /**\n * A unique value that identifies this item within the segmented control.\n */\n value: string\n /**\n * When true, prevents the user from interacting with this item.\n * @default false\n */\n disabled?: boolean\n ref?: Ref<HTMLElement>\n}\n\n/** A selectable item in the segmented control. Renders a <button> element. */\nexport const SegmentedControlItem = ({\n value,\n disabled = false,\n children,\n className,\n ref,\n ...rest\n}: SegmentedControlItemProps) => {\n const content = Children.toArray(children).map((child, index) => {\n if (typeof child === 'string' || typeof child === 'number') {\n return (\n <span key={`text-${index}`} data-spark-segmented-control-text>\n {child}\n </span>\n )\n }\n\n return child\n })\n\n return (\n <Radio.Root\n ref={ref}\n data-spark-component=\"segmented-control-item\"\n data-value={value}\n value={value}\n disabled={disabled}\n className={itemStyles({ className })}\n {...rest}\n >\n {content}\n </Radio.Root>\n )\n}\n\nSegmentedControlItem.displayName = 'SegmentedControl.Item'\n","import { SegmentedControl as Root } from './SegmentedControl'\nimport { SegmentedControlIndicator as Indicator } from './SegmentedControlIndicator'\nimport { SegmentedControlItem as Item } from './SegmentedControlItem'\n\n/**\n * A set of toggle buttons that allows users to select a single option from a group of related choices.\n */\nexport const SegmentedControl: typeof Root & {\n Item: typeof Item\n Indicator: typeof Indicator\n} = Object.assign(Root, {\n Item,\n Indicator,\n})\n\nSegmentedControl.displayName = 'SegmentedControl'\nItem.displayName = 'SegmentedControl.Item'\nIndicator.displayName = 'SegmentedControl.Indicator'\n\nexport type { SegmentedControlProps } from './SegmentedControl'\nexport type { SegmentedControlItemProps } from './SegmentedControlItem'\nexport type { SegmentedControlIndicatorProps } from './SegmentedControlIndicator'\n"],"mappings":";;;;;;;;AAEA,IAAa,IAAa,EAAI;CAC5B;CACA;CACA;CACA;CACA;CACD,CAAC,EAEW,IAAa,EAAI;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAGA;CACD,CAAC,EAEW,IAAkB,EAAI;CACjC;CACA;CACA;CACA;CACA;CACA;CACD,CAAC,EC3BW,IAA0B,EACrC,EAAE,CACH,EAEY,UAAmC;CAC9C,IAAM,IAAU,EAAW,EAAwB;AAEnD,KAAI,CAAC,EACH,OAAM,MAAM,oFAAoF;AAGlG,QAAO;GCUH,KAAqB,MAA6C;CACtE,IAAI,IAA4B;AAShC,QAPA,EAAS,QAAQ,IAAU,MAAS;AAC9B,QAAe,QACf,EAAe,EAAM,IAAI,OAAQ,EAAM,MAA6B,SAAU,aAChF,IAAc,EAAM,MAA4B;GAElD,EAEK;GAGI,KAAoB,EAC/B,UACA,iBACA,kBACA,cACA,aACA,QACA,GAAG,QACwB;CAC3B,IAAM,IAAe,EAA8B,KAAK,EAClD,IAAY,EAAa,GAAc,EAAI,EAE3C,IAAa,EAAkB,EAAS,EAExC,IAAe,MAAU,KAAA,GACzB,CAAC,GAAe,KAAoB,QAClC,KAAgB,EACvB,EACK,IAAe,IAAgB,KAAS,OAAQ,GAEhD,KAAqB,MAAsB;EAC/C,IAAM,IAAO;AAMb,EAJK,KACH,EAAiB,EAAK,EAGxB,IAAgB,EAAK;IAGjB,EAAE,YAAS,gBAAa,eAAY,cAAW,YAAS,GAAqB;AAEnF,QACE,kBAAC,EAAwB,UAAzB;EACE,OAAO;GACL;GACA;GACD;YAED,kBAAC,GAAD;GACE,KAAK;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AAI,qBAAqB;AACvB,MAAQ;IACR,GACF;AAQN,SANA,GAAI,QAAQ,EAAU,EAClB,KAAc,GAAI,QAAQ,EAAa,EAE3C,OAAO,iBAAiB,UAAU,GAAQ,EAAE,SAAS,IAAM,CAAC,EAC5D,OAAO,gBAAgB,iBAAiB,UAAU,GAAQ,EAAE,SAAS,IAAM,CAAC,QAE/D;AAGX,GAFA,GAAI,YAAY,EAChB,OAAO,oBAAoB,UAAU,EAAO,EAC5C,OAAO,gBAAgB,oBAAoB,UAAU,EAAO;;IAE7D,CAAC,GAAc,EAAS,CAAC,EAExB,CAAC,EAAM,QAAO;CAElB,IAAM,IAAuB;EAC3B,MAAM,EAAK;EACX,KAAK,EAAK;EACV,OAAO,EAAK;EACZ,QAAQ,EAAK;EACd;AAED,QACE,kBAAC,QAAD;EACO;EACL,wBAAqB;EACrB,eAAA;EACA,WAAW,EAAgB,EAAE,cAAW,CAAC;EAClC;EACP,GAAI;EACJ,CAAA;;AAIN,EAA0B,cAAc;;;AC/FxC,IAAa,KAAwB,EACnC,UACA,cAAW,IACX,aACA,cACA,QACA,GAAG,QAC4B;CAC/B,IAAM,IAAU,EAAS,QAAQ,EAAS,CAAC,KAAK,GAAO,MACjD,OAAO,KAAU,YAAY,OAAO,KAAU,WAE9C,kBAAC,QAAD;EAA4B,qCAAA;YACzB;EACI,EAFI,QAAQ,IAEZ,GAIJ,EACP;AAEF,QACE,kBAAC,EAAM,MAAP;EACO;EACL,wBAAqB;EACrB,cAAY;EACL;EACG;EACV,WAAW,EAAW,EAAE,cAAW,CAAC;EACpC,GAAI;YAEH;EACU,CAAA;;AAIjB,EAAqB,cAAc;;;AClDnC,IAAa,IAGT,OAAO,OAAO,GAAM;CACtB,MAAA;CACA,WAAA;CACD,CAAC;AAEF,EAAiB,cAAc,oBAC/B,EAAK,cAAc,yBACnB,EAAU,cAAc"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/segmented-control/SegmentedControl.styles.ts","../../src/segmented-control/SegmentedControlContext.tsx","../../src/segmented-control/SegmentedControl.tsx","../../src/segmented-control/SegmentedControlIndicator.tsx","../../src/segmented-control/SegmentedControlItem.tsx","../../src/segmented-control/index.ts"],"sourcesContent":["import { cva, VariantProps } from 'class-variance-authority'\n\nexport const rootStyles = cva([\n 'default:self-start',\n 'group inline-grid grid-flow-col auto-cols-fr',\n 'relative items-stretch min-w-max',\n 'rounded-xl p-sm',\n 'bg-surface border-sm border-outline',\n])\n\nexport const itemStyles = cva([\n 'relative z-raised min-h-sz-44 focus-visible:outline-none',\n 'flex flex-none items-center justify-center gap-md',\n 'default:px-lg default:py-md',\n 'rounded-[20px]',\n 'cursor-pointer select-none',\n 'font-medium',\n 'transition-colors duration-150',\n 'outline-none',\n 'focus-visible:u-outline',\n 'data-disabled:cursor-not-allowed data-disabled:opacity-dim-3',\n 'data-checked:text-on-support-container',\n // Avoid layout shift: simulate \"bold\" without changing font metrics.\n // Apply only to wrapped text nodes (not arbitrary nested JSX like Tag).\n 'data-checked:[&>[data-spark-segmented-control-text]]:[text-shadow:0.35px_0_currentColor,-0.35px_0_currentColor]',\n])\n\nexport const indicatorStyles = cva([\n 'absolute z-base',\n 'rounded-[20px]',\n 'bg-support-container border-md border-support',\n 'group-has-focus-visible:border-focus',\n 'transition-[left,top,width,height] duration-200 ease-in-out',\n 'pointer-events-none',\n])\n\nexport type SegmentedControlStylesProps = VariantProps<typeof itemStyles>\n","import { createContext, RefObject, useContext } from 'react'\n\nexport interface SegmentedControlContextInterface {\n checkedValue: string | null\n containerRef: RefObject<HTMLDivElement | null>\n}\n\nexport const SegmentedControlContext = createContext<SegmentedControlContextInterface>(\n {} as SegmentedControlContextInterface\n)\n\nexport const useSegmentedControlContext = () => {\n const context = useContext(SegmentedControlContext)\n\n if (!context) {\n throw Error('useSegmentedControlContext must be used within a SegmentedControlContext Provider')\n }\n\n return context\n}\n","import { RadioGroup } from '@base-ui/react/radio-group'\nimport { useFormFieldControl } from '@spark-ui/components/form-field'\nimport { useMergeRefs } from '@spark-ui/hooks/use-merge-refs'\nimport { Children, type ComponentProps, isValidElement, Ref, useRef, useState } from 'react'\n\nimport type { SegmentedControlStylesProps } from './SegmentedControl.styles'\nimport { rootStyles } from './SegmentedControl.styles'\nimport { SegmentedControlContext } from './SegmentedControlContext'\n\nexport interface SegmentedControlProps\n extends\n Omit<ComponentProps<typeof RadioGroup>, 'value' | 'defaultValue' | 'onValueChange'>,\n SegmentedControlStylesProps {\n /**\n * The controlled selected value.\n */\n value?: string\n /**\n * The uncontrolled default selected value.\n */\n defaultValue?: string\n /**\n * Callback fired when the selected value changes.\n */\n onValueChange?: (value: string) => void\n ref?: Ref<HTMLDivElement>\n}\n\nconst getFirstItemValue = (children: React.ReactNode): string | null => {\n let firstValue: string | null = null\n\n Children.forEach(children, child => {\n if (firstValue !== null) return\n if (isValidElement(child) && typeof (child.props as { value?: string }).value === 'string') {\n firstValue = (child.props as { value: string }).value\n }\n })\n\n return firstValue\n}\n\nexport const SegmentedControl = ({\n value,\n defaultValue,\n onValueChange,\n className,\n children,\n ref,\n ...rest\n}: SegmentedControlProps) => {\n const containerRef = useRef<HTMLDivElement | null>(null)\n const mergedRef = useMergeRefs(containerRef, ref)\n\n const firstValue = getFirstItemValue(children)\n\n const isControlled = value !== undefined\n const [internalValue, setInternalValue] = useState<string | null>(\n () => defaultValue ?? firstValue\n )\n const checkedValue = isControlled ? (value ?? null) : internalValue\n\n const handleValueChange = (newValue: unknown) => {\n const next = newValue as string\n\n if (!isControlled) {\n setInternalValue(next)\n }\n\n onValueChange?.(next)\n }\n\n const { labelId, description, isRequired, isInvalid, name } = useFormFieldControl()\n\n return (\n <SegmentedControlContext\n value={{\n checkedValue,\n containerRef,\n }}\n >\n <RadioGroup\n ref={mergedRef}\n value={isControlled ? value : undefined}\n defaultValue={!isControlled ? (defaultValue ?? firstValue ?? undefined) : undefined}\n onValueChange={handleValueChange}\n data-spark-component=\"segmented-control\"\n className={rootStyles({ className })}\n aria-labelledby={labelId}\n aria-describedby={description}\n aria-required={isRequired || undefined}\n aria-invalid={isInvalid || undefined}\n name={name}\n {...rest}\n >\n {children}\n </RadioGroup>\n </SegmentedControlContext>\n )\n}\n\nSegmentedControl.displayName = 'SegmentedControl'\n","import { type ComponentProps, type CSSProperties, Ref, useEffect, useMemo, useState } from 'react'\n\nimport { indicatorStyles } from './SegmentedControl.styles'\nimport { useSegmentedControlContext } from './SegmentedControlContext'\n\ninterface IndicatorRect {\n left: number\n top: number\n width: number\n height: number\n}\n\nexport interface SegmentedControlIndicatorProps extends ComponentProps<'span'> {\n ref?: Ref<HTMLSpanElement>\n}\n\n/** The visual indicator that highlights the selected item. Renders a <span> element. */\nexport const SegmentedControlIndicator = ({\n className,\n ref,\n ...rest\n}: SegmentedControlIndicatorProps) => {\n const { checkedValue, containerRef } = useSegmentedControlContext()\n const [rect, setRect] = useState<IndicatorRect | null>(null)\n\n const selector = useMemo(\n () => (checkedValue ? `[data-value=\"${CSS.escape(checkedValue)}\"]` : null),\n [checkedValue]\n )\n\n useEffect(() => {\n const container = containerRef.current\n\n if (!container) {\n return\n }\n\n const selectedItem = selector ? container.querySelector<HTMLElement>(selector) : null\n\n const update = () => {\n const currentContainer = containerRef.current\n if (!currentContainer || !selector) {\n setRect(null)\n\n return\n }\n\n const currentSelected = currentContainer.querySelector<HTMLElement>(selector)\n if (!currentSelected) {\n setRect(null)\n\n return\n }\n\n const containerRect = currentContainer.getBoundingClientRect()\n const itemRect = currentSelected.getBoundingClientRect()\n\n // Storybook canvas \"zoom\" can be implemented via `transform: scale()`.\n // In that case, `getBoundingClientRect()` returns *scaled* values, but CSS positioning/sizing\n // expects unscaled layout pixels. We infer the scale factor from offset sizes and normalize.\n const scaleX =\n currentSelected.offsetWidth > 0 ? itemRect.width / currentSelected.offsetWidth : 1\n const scaleY =\n currentSelected.offsetHeight > 0 ? itemRect.height / currentSelected.offsetHeight : 1\n\n // `getBoundingClientRect()` is border-box; absolute positioning is relative to the padding box.\n setRect({\n left: (itemRect.left - containerRect.left) / scaleX - currentContainer.clientLeft,\n top: (itemRect.top - containerRect.top) / scaleY - currentContainer.clientTop,\n width: itemRect.width / scaleX,\n height: itemRect.height / scaleY,\n })\n }\n\n update()\n\n const ro =\n typeof ResizeObserver !== 'undefined'\n ? new ResizeObserver(() => {\n update()\n })\n : null\n\n ro?.observe(container)\n if (selectedItem) ro?.observe(selectedItem)\n\n window.addEventListener('resize', update, { passive: true })\n window.visualViewport?.addEventListener('resize', update, { passive: true })\n\n return () => {\n ro?.disconnect()\n window.removeEventListener('resize', update)\n window.visualViewport?.removeEventListener('resize', update)\n }\n }, [containerRef, selector])\n\n if (!rect) return null\n\n const style: CSSProperties = {\n left: rect.left,\n top: rect.top,\n width: rect.width,\n height: rect.height,\n }\n\n return (\n <span\n ref={ref}\n data-spark-component=\"segmented-control-indicator\"\n aria-hidden\n className={indicatorStyles({ className })}\n style={style}\n {...rest}\n />\n )\n}\n\nSegmentedControlIndicator.displayName = 'SegmentedControl.Indicator'\n","import { Radio } from '@base-ui/react/radio'\nimport { Children, type ComponentProps, Ref } from 'react'\n\nimport { itemStyles } from './SegmentedControl.styles'\n\nexport interface SegmentedControlItemProps extends Omit<\n ComponentProps<typeof Radio.Root>,\n 'value'\n> {\n /**\n * A unique value that identifies this item within the segmented control.\n */\n value: string\n /**\n * When true, prevents the user from interacting with this item.\n * @default false\n */\n disabled?: boolean\n ref?: Ref<HTMLElement>\n}\n\n/** A selectable item in the segmented control. Renders a <button> element. */\nexport const SegmentedControlItem = ({\n value,\n disabled = false,\n children,\n className,\n ref,\n ...rest\n}: SegmentedControlItemProps) => {\n const content = Children.toArray(children).map((child, index) => {\n if (typeof child === 'string' || typeof child === 'number') {\n return (\n <span key={`text-${index}`} data-spark-segmented-control-text>\n {child}\n </span>\n )\n }\n\n return child\n })\n\n return (\n <Radio.Root\n ref={ref}\n data-spark-component=\"segmented-control-item\"\n data-value={value}\n value={value}\n disabled={disabled}\n className={itemStyles({ className })}\n {...rest}\n >\n {content}\n </Radio.Root>\n )\n}\n\nSegmentedControlItem.displayName = 'SegmentedControl.Item'\n","import { SegmentedControl as Root } from './SegmentedControl'\nimport { SegmentedControlIndicator as Indicator } from './SegmentedControlIndicator'\nimport { SegmentedControlItem as Item } from './SegmentedControlItem'\n\n/**\n * A set of toggle buttons that allows users to select a single option from a group of related choices.\n */\nexport const SegmentedControl: typeof Root & {\n Item: typeof Item\n Indicator: typeof Indicator\n} = Object.assign(Root, {\n Item,\n Indicator,\n})\n\nSegmentedControl.displayName = 'SegmentedControl'\nItem.displayName = 'SegmentedControl.Item'\nIndicator.displayName = 'SegmentedControl.Indicator'\n\nexport type { SegmentedControlProps } from './SegmentedControl'\nexport type { SegmentedControlItemProps } from './SegmentedControlItem'\nexport type { SegmentedControlIndicatorProps } from './SegmentedControlIndicator'\n"],"mappings":";;;;;;;;AAEA,IAAa,IAAa,EAAI;CAC5B;CACA;CACA;CACA;CACA;CACD,CAAC,EAEW,IAAa,EAAI;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAGA;CACD,CAAC,EAEW,IAAkB,EAAI;CACjC;CACA;CACA;CACA;CACA;CACA;CACD,CAAC,EC3BW,IAA0B,EACrC,EAAE,CACH,EAEY,UAAmC;CAC9C,IAAM,IAAU,EAAW,EAAwB;AAEnD,KAAI,CAAC,EACH,OAAM,MAAM,oFAAoF;AAGlG,QAAO;GCUH,KAAqB,MAA6C;CACtE,IAAI,IAA4B;AAShC,QAPA,EAAS,QAAQ,IAAU,MAAS;AAC9B,QAAe,QACf,EAAe,EAAM,IAAI,OAAQ,EAAM,MAA6B,SAAU,aAChF,IAAc,EAAM,MAA4B;GAElD,EAEK;GAGI,KAAoB,EAC/B,UACA,iBACA,kBACA,cACA,aACA,QACA,GAAG,QACwB;CAC3B,IAAM,IAAe,EAA8B,KAAK,EAClD,IAAY,EAAa,GAAc,EAAI,EAE3C,IAAa,EAAkB,EAAS,EAExC,IAAe,MAAU,KAAA,GACzB,C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AW,EAAW,EAAE,cAAW,CAAC;EACpC,GAAI;YAEH;EACU,CAAA;;AAIjB,EAAqB,cAAc;;;AClDnC,IAAa,IAGT,OAAO,OAAO,GAAM;CACtB,MAAA;CACA,WAAA;CACD,CAAC;AAEF,EAAiB,cAAc,oBAC/B,EAAK,cAAc,yBACnB,EAAU,cAAc"}
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../chunk-C91j1N6u.js`);let e=require(`class-variance-authority`),t=require(`react`),n=require(`react/jsx-runtime`);var r=(0,t.createContext)(null),i=()=>{let e=(0,t.useContext)(r);if(!e)throw Error(`useSegmentedGaugeContext must be used within a SegmentedGauge provider`);return e},a=({className:t,children:r,ref:a,id:o,...s})=>{let{labelId:c}=i();return(0,n.jsx)(`span`,{"data-spark-component":`segmented-gauge-label`,"data-testid":`segmented-gauge-label`,ref:a,id:o||c,className:(0,e.cx)(`default:text-on-surface default:text-body-2`,t),...s,children:r})};a.displayName=`SegmentedGauge.Label`;var o=({index:r=0,className:a,children:o,ref:s,...c})=>{let{size:l,intent:u,customColor:d,currentIndex:f}=i(),p=f!==-1&&r<=f,m=f!==-1&&r===f,h=(0,t.useMemo)(()=>{if(d)return d;switch(u){case`main`:return`var(--color-main)`;case`support`:return`var(--color-support)`;case`accent`:return`var(--color-accent)`;case`success`:return`var(--color-success)`;case`alert`:return`var(--color-alert)`;case`danger`:return`var(--color-error)`;case`info`:return`var(--color-info)`;case`neutral`:return`var(--color-neutral)`;default:return`var(--color-neutral)`}},[u,d]),g=(0,e.cx)(`border-outline relative rounded-full`,{"h-sz-8 w-sz-24":l===`sm`,"h-sz-12 w-sz-36":l===`md`,"default:bg-[var(--gauge-color)]":p,"border-sm bg-surface":!p},a),_=(0,e.cx)(`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2`,`default:bg-surface default:rounded-full`,`border-[var(--gauge-color)]`,{"size-sz-12 border-md":l===`sm`,"size-sz-20 border-lg":l===`md`});return(0,n.jsxs)(`div`,{"data-spark-component":`segmented-gauge-segment`,"data-testid":`segmented-gauge-segment`,"data-active":p,"data-current":m,ref:s,style:{"--gauge-color":h},className:g,...c,children:[o,m&&(0,n.jsx)(`div`,{className:_,"aria-hidden":`true`})]})};o.displayName=`SegmentedGauge.Segment`;var s=({className:t,children:r,ref:i,...a})=>(0,n.jsx)(`div`,{"data-spark-component":`segmented-gauge-track`,ref:i,className:(0,e.cx)(`gap-sm relative flex rounded-full`,t),...a,children:r});s.displayName=`SegmentedGauge.Track`;var c=(e,t,n,r)=>{if(e==null)return-1;let i=Math.max(t,Math.min(n,e)),a=(n-t)/(r-1),o=(i-t)/a;return Math.max(0,Math.min(r-1,Math.round(o)))},l=({value:i,min:l,max:u,description:d,size:f=`md`,intent:p=`neutral`,customColor:m,id:h,"aria-label":g,className:_,ref:v,children:y,...b})=>{let x=u-l+1,S=(0,t.useMemo)(()=>c(i,l,u,x),[i,l,u,x]),C=(0,t.useId)(),w=(0,t.useId)(),T=h||w,E=(0,t.useMemo)(()=>Array.from({length:x},(e,t)=>({isActive:S!==-1&&t<=S,isCurrent:S!==-1&&t===S})),[x,S]),D=(0,t.useMemo)(()=>({value:i,min:l,max:u,segments:x,currentIndex:S,size:f,intent:p,customColor:m,labelId:C,gaugeId:T}),[i,l,u,x,S,f,p,m,C,T]),O=i==null?{role:`status`}:{role:`meter`,"aria-valuenow":i,"aria-valuemin":l,"aria-valuemax":u};return(0,n.jsx)(r.Provider,{value:D,children:(0,n.jsx)(`div`,{id:T,"data-spark-component":`segmented-gauge`,ref:v,className:(0,e.cx)(`gap-md flex flex-wrap items-center`,_),...O,"aria-labelledby":h?`${T}-label`:void 0,"aria-label":h?void 0:g,"aria-describedby":C,...b,children:y?y({segments:E,currentIndex:S}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(s,{children:E.map((e,t)=>(0,n.jsx)(o,{index:t},t))}),d&&(0,n.jsx)(a,{id:C,children:d})]})})})};l.displayName=`SegmentedGauge`;var u=Object.assign(l,{Track:s,Segment:o,Label:a});u.displayName=`SegmentedGauge`,s.displayName=`SegmentedGauge.Track`,o.displayName=`SegmentedGauge.Segment`,a.displayName=`SegmentedGauge.Label`,exports.SegmentedGauge=u;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../chunk-C91j1N6u.js`);let e=require(`class-variance-authority`),t=require(`react`),n=require(`react/jsx-runtime`);var r=(0,t.createContext)(null),i=()=>{let e=(0,t.useContext)(r);if(!e)throw Error(`useSegmentedGaugeContext must be used within a SegmentedGauge provider`);return e},a=({className:t,children:r,ref:a,id:o,...s})=>{let{labelId:c}=i();return(0,n.jsx)(`span`,{"data-spark-component":`segmented-gauge-label`,"data-testid":`segmented-gauge-label`,ref:a,id:o||c,className:(0,e.cx)(`default:text-on-surface default:text-body-2`,t),...s,children:r})};a.displayName=`SegmentedGauge.Label`;var o=({index:r=0,className:a,children:o,ref:s,...c})=>{let{size:l,intent:u,customColor:d,currentIndex:f}=i(),p=f!==-1&&r<=f,m=f!==-1&&r===f,h=(0,t.useMemo)(()=>{if(d)return d;switch(u){case`main`:return`var(--color-main)`;case`support`:return`var(--color-support)`;case`accent`:return`var(--color-accent)`;case`success`:return`var(--color-success)`;case`alert`:return`var(--color-alert)`;case`danger`:return`var(--color-error)`;case`info`:return`var(--color-info)`;case`neutral`:return`var(--color-neutral)`;default:return`var(--color-neutral)`}},[u,d]),g=(0,e.cx)(`border-outline relative rounded-full`,{"h-sz-8 w-sz-24":l===`sm`,"h-sz-12 w-sz-36":l===`md`,"default:bg-[var(--gauge-color)]":p,"border-sm bg-surface":!p},a),_=(0,e.cx)(`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2`,`default:bg-surface default:rounded-full`,`border-[var(--gauge-color)]`,{"size-sz-12 border-md":l===`sm`,"size-sz-20 border-lg":l===`md`});return(0,n.jsxs)(`div`,{"data-spark-component":`segmented-gauge-segment`,"data-testid":`segmented-gauge-segment`,"data-active":p,"data-current":m,ref:s,style:{"--gauge-color":h},className:g,...c,children:[o,m&&(0,n.jsx)(`div`,{className:_,"aria-hidden":`true`})]})};o.displayName=`SegmentedGauge.Segment`;var s=({className:t,children:r,ref:i,...a})=>(0,n.jsx)(`div`,{"data-spark-component":`segmented-gauge-track`,ref:i,className:(0,e.cx)(`gap-sm relative flex rounded-full`,t),...a,children:r});s.displayName=`SegmentedGauge.Track`;var c=(e,t,n,r)=>{if(e==null)return-1;let i=Math.max(t,Math.min(n,e)),a=(n-t)/(r-1),o=(i-t)/a;return Math.max(0,Math.min(r-1,Math.round(o)))},l=({value:i,min:l,max:u,description:d,size:f=`md`,intent:p=`neutral`,customColor:m,id:h,"aria-label":g,className:_,ref:v,children:y,...b})=>{let x=u-l+1,S=(0,t.useMemo)(()=>c(i,l,u,x),[i,l,u,x]),C=(0,t.useId)(),w=(0,t.useId)(),T=h||w,E=(0,t.useMemo)(()=>Array.from({length:x},(e,t)=>({isActive:S!==-1&&t<=S,isCurrent:S!==-1&&t===S})),[x,S]),D=(0,t.useMemo)(()=>({value:i,min:l,max:u,segments:x,currentIndex:S,size:f,intent:p,customColor:m,labelId:C,gaugeId:T}),[i,l,u,x,S,f,p,m,C,T]),O=i==null?{role:`status`}:{role:`meter`,"aria-valuenow":i,"aria-valuemin":l,"aria-valuemax":u};return(0,n.jsx)(r,{value:D,children:(0,n.jsx)(`div`,{id:T,"data-spark-component":`segmented-gauge`,ref:v,className:(0,e.cx)(`gap-md flex flex-wrap items-center`,_),...O,"aria-labelledby":h?`${T}-label`:void 0,"aria-label":h?void 0:g,"aria-describedby":C,...b,children:y?y({segments:E,currentIndex:S}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(s,{children:E.map((e,t)=>(0,n.jsx)(o,{index:t},t))}),d&&(0,n.jsx)(a,{id:C,children:d})]})})})};l.displayName=`SegmentedGauge`;var u=Object.assign(l,{Track:s,Segment:o,Label:a});u.displayName=`SegmentedGauge`,s.displayName=`SegmentedGauge.Track`,o.displayName=`SegmentedGauge.Segment`,a.displayName=`SegmentedGauge.Label`,exports.SegmentedGauge=u;
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/segmented-gauge/SegmentedGaugeContext.tsx","../../src/segmented-gauge/SegmentedGaugeLabel.tsx","../../src/segmented-gauge/SegmentedGaugeSegment.tsx","../../src/segmented-gauge/SegmentedGaugeTrack.tsx","../../src/segmented-gauge/SegmentedGauge.tsx","../../src/segmented-gauge/index.ts"],"sourcesContent":["import { createContext, useContext } from 'react'\n\nexport interface SegmentedGaugeContextValue {\n value?: number\n min: number\n max: number\n segments: number\n currentIndex: number\n size: 'sm' | 'md'\n intent: 'main' | 'support' | 'accent' | 'success' | 'alert' | 'danger' | 'info' | 'neutral'\n customColor?: string\n labelId: string\n gaugeId: string\n}\n\nexport const SegmentedGaugeContext = createContext<SegmentedGaugeContextValue | null>(null)\n\nexport const useSegmentedGaugeContext = () => {\n const context = useContext(SegmentedGaugeContext)\n\n if (!context) {\n throw new Error('useSegmentedGaugeContext must be used within a SegmentedGauge provider')\n }\n\n return context\n}\n","import { cx } from 'class-variance-authority'\nimport { ComponentProps, Ref } from 'react'\n\nimport { useSegmentedGaugeContext } from './SegmentedGaugeContext'\n\nexport interface SegmentedGaugeLabelProps extends ComponentProps<'span'> {\n ref?: Ref<HTMLSpanElement>\n id?: string\n}\n\n/** The text label for the gauge. Renders a <span> element. */\nexport const SegmentedGaugeLabel = ({\n className,\n children,\n ref,\n id,\n ...props\n}: SegmentedGaugeLabelProps) => {\n const { labelId } = useSegmentedGaugeContext()\n\n return (\n <span\n data-spark-component=\"segmented-gauge-label\"\n data-testid=\"segmented-gauge-label\"\n ref={ref}\n id={id || labelId}\n className={cx('default:text-on-surface default:text-body-2', className)}\n {...props}\n >\n {children}\n </span>\n )\n}\n\nSegmentedGaugeLabel.displayName = 'SegmentedGauge.Label'\n","import { cx } from 'class-variance-authority'\nimport { ComponentProps, Ref, useMemo } from 'react'\n\nimport { useSegmentedGaugeContext } from './SegmentedGaugeContext'\n\nexport interface SegmentedGaugeSegmentProps extends ComponentProps<'div'> {\n /**\n * Index of this segment (0-based)\n */\n index?: number\n ref?: Ref<HTMLDivElement>\n}\n\n/**\n * An individual segment in the gauge. Renders a <div> element.\n */\n\nexport const SegmentedGaugeSegment = ({\n index = 0,\n className,\n children,\n ref,\n ...props\n}: SegmentedGaugeSegmentProps) => {\n const { size, intent, customColor, currentIndex } = useSegmentedGaugeContext()\n\n // Calculate isActive and isCurrent from context and index\n const isActive = currentIndex !== -1 && index <= currentIndex\n const isCurrent = currentIndex !== -1 && index === currentIndex\n\n const gaugeColor = useMemo(() => {\n // If customColor is provided, use it\n if (customColor) {\n return customColor\n }\n\n // Handle predefined intents\n switch (intent) {\n case 'main':\n return 'var(--color-main)'\n case 'support':\n return 'var(--color-support)'\n case 'accent':\n return 'var(--color-accent)'\n case 'success':\n return 'var(--color-success)'\n case 'alert':\n return 'var(--color-alert)'\n case 'danger':\n return 'var(--color-error)'\n case 'info':\n return 'var(--color-info)'\n case 'neutral':\n return 'var(--color-neutral)'\n default:\n return 'var(--color-neutral)'\n }\n }, [intent, customColor])\n\n const segmentClasses = cx(\n 'border-outline relative rounded-full',\n {\n 'h-sz-8 w-sz-24': size === 'sm',\n 'h-sz-12 w-sz-36': size === 'md',\n 'default:bg-[var(--gauge-color)]': isActive,\n 'border-sm bg-surface': !isActive,\n },\n className\n )\n\n const indicatorClasses = cx(\n 'absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2',\n 'default:bg-surface default:rounded-full',\n 'border-[var(--gauge-color)]',\n {\n 'size-sz-12 border-md': size === 'sm',\n 'size-sz-20 border-lg': size === 'md',\n }\n )\n\n return (\n <div\n data-spark-component=\"segmented-gauge-segment\"\n data-testid=\"segmented-gauge-segment\"\n data-active={isActive}\n data-current={isCurrent}\n ref={ref}\n style={\n {\n '--gauge-color': gaugeColor,\n } as React.CSSProperties\n }\n className={segmentClasses}\n {...props}\n >\n {children}\n {isCurrent && <div className={indicatorClasses} aria-hidden=\"true\" />}\n </div>\n )\n}\n\nSegmentedGaugeSegment.displayName = 'SegmentedGauge.Segment'\n","import { cx } from 'class-variance-authority'\nimport { ComponentProps, Ref } from 'react'\n\nexport interface SegmentedGaugeTrackProps extends ComponentProps<'div'> {\n ref?: Ref<HTMLDivElement>\n}\n\n/** The container track for the gauge segments. Renders a <div> element. */\nexport const SegmentedGaugeTrack = ({\n className,\n children,\n ref,\n ...props\n}: SegmentedGaugeTrackProps) => {\n return (\n <div\n data-spark-component=\"segmented-gauge-track\"\n ref={ref}\n className={cx('gap-sm relative flex rounded-full', className)}\n {...props}\n >\n {children}\n </div>\n )\n}\n\nSegmentedGaugeTrack.displayName = 'SegmentedGauge.Track'\n","import { cx } from 'class-variance-authority'\nimport { Ref, useId, useMemo } from 'react'\n\nimport { SegmentedGaugeContext } from './SegmentedGaugeContext'\nimport { SegmentedGaugeLabel } from './SegmentedGaugeLabel'\nimport { SegmentedGaugeSegment } from './SegmentedGaugeSegment'\nimport { SegmentedGaugeTrack } from './SegmentedGaugeTrack'\n\nconst calculateCurrentIndex = (\n value: number | undefined,\n min: number,\n max: number,\n segments: number\n) => {\n // If value is undefined or null, no segment is active\n if (value == null) {\n return -1\n }\n const normalizedValue = Math.max(min, Math.min(max, value))\n const range = max - min\n const segmentSize = range / (segments - 1)\n const rawIndex = (normalizedValue - min) / segmentSize\n\n // Clamp the index to valid range\n return Math.max(0, Math.min(segments - 1, Math.round(rawIndex)))\n}\n\nexport interface SegmentedGaugeProps {\n /**\n * The current value of the gauge\n */\n value?: number\n /**\n * Minimum value of the gauge (aria-valuemin)\n */\n min: number\n /**\n * Maximum value of the gauge (aria-valuemax)\n */\n max: number\n /**\n * Description text for the gauge (aria-describedby)\n */\n description?: string\n /**\n * Size of the gauge\n */\n size?: 'sm' | 'md'\n /**\n * Intent of the gauge - predefined color intent\n */\n intent?: 'main' | 'support' | 'accent' | 'success' | 'alert' | 'danger' | 'info' | 'neutral'\n /**\n * Custom color for the gauge (hex, CSS variable, etc.)\n */\n customColor?: string\n /**\n * ID of the gauge element\n */\n id?: string\n /**\n * Accessible label for the gauge (required if no id is provided)\n */\n 'aria-label'?: string\n /**\n * Textual representation of the current value (aria-valuetext)\n * By default, percentage is used (e.g. \"33%\")\n */\n 'aria-valuetext'?: string\n /**\n * Additional CSS classes\n */\n className?: string\n /**\n * Ref to the root element\n */\n ref?: Ref<HTMLDivElement>\n /**\n * Children render prop for custom rendering\n */\n children?: (props: {\n segments: {\n isActive: boolean\n isCurrent: boolean\n }[]\n currentIndex: number\n }) => React.ReactNode\n}\n\nexport const SegmentedGauge = ({\n value,\n min,\n max,\n description,\n size = 'md',\n intent = 'neutral',\n customColor,\n id,\n 'aria-label': ariaLabel,\n className,\n ref,\n children,\n ...props\n}: SegmentedGaugeProps) => {\n // Calculate segments from min and max\n const segments = max - min + 1\n const currentIndex = useMemo(\n () => calculateCurrentIndex(value, min, max, segments),\n [value, min, max, segments]\n )\n\n // Generate unique IDs\n const internalLabelId = useId()\n const generatedId = useId()\n // Use provided id or generated one for the gauge element\n const gaugeId = id || generatedId\n\n const segmentsData = useMemo(() => {\n return Array.from({ length: segments }, (_, index) => ({\n isActive: currentIndex !== -1 && index <= currentIndex,\n isCurrent: currentIndex !== -1 && index === currentIndex,\n }))\n }, [segments, currentIndex])\n\n const contextValue = useMemo(\n () => ({\n value,\n min,\n max,\n segments,\n currentIndex,\n size,\n intent,\n customColor,\n labelId: internalLabelId,\n gaugeId,\n }),\n [value, min, max, segments, currentIndex, size, intent, customColor, internalLabelId, gaugeId]\n )\n\n /**\n * A `meter` role MUST have a value. If the value is not available, the component uses a `status` role instead.\n */\n const roleProps =\n value != null\n ? {\n role: 'meter',\n 'aria-valuenow': value,\n 'aria-valuemin': min,\n 'aria-valuemax': max,\n }\n : {\n role: 'status',\n }\n\n return (\n <SegmentedGaugeContext.Provider value={contextValue}>\n <div\n id={gaugeId}\n data-spark-component=\"segmented-gauge\"\n ref={ref}\n className={cx('gap-md flex flex-wrap items-center', className)}\n {...roleProps}\n aria-labelledby={id ? `${gaugeId}-label` : undefined}\n aria-label={!id ? ariaLabel : undefined}\n aria-describedby={internalLabelId}\n {...props}\n >\n {children ? (\n children({\n segments: segmentsData,\n currentIndex,\n })\n ) : (\n <>\n <SegmentedGaugeTrack>\n {segmentsData.map((_, index) => (\n <SegmentedGaugeSegment key={index} index={index} />\n ))}\n </SegmentedGaugeTrack>\n\n {description && (\n <SegmentedGaugeLabel id={internalLabelId}>{description}</SegmentedGaugeLabel>\n )}\n </>\n )}\n </div>\n </SegmentedGaugeContext.Provider>\n )\n}\n\nSegmentedGauge.displayName = 'SegmentedGauge'\n","import { SegmentedGauge as Root } from './SegmentedGauge'\nimport { SegmentedGaugeLabel } from './SegmentedGaugeLabel'\nimport { SegmentedGaugeSegment } from './SegmentedGaugeSegment'\nimport { SegmentedGaugeTrack } from './SegmentedGaugeTrack'\n\n/**\n * A visual indicator that displays a value using discrete segments within a defined range.\n */\nexport const SegmentedGauge: typeof Root & {\n Track: typeof SegmentedGaugeTrack\n Segment: typeof SegmentedGaugeSegment\n Label: typeof SegmentedGaugeLabel\n} = Object.assign(Root, {\n Track: SegmentedGaugeTrack,\n Segment: SegmentedGaugeSegment,\n Label: SegmentedGaugeLabel,\n})\n\nSegmentedGauge.displayName = 'SegmentedGauge'\nSegmentedGaugeTrack.displayName = 'SegmentedGauge.Track'\nSegmentedGaugeSegment.displayName = 'SegmentedGauge.Segment'\nSegmentedGaugeLabel.displayName = 'SegmentedGauge.Label'\n\nexport { type SegmentedGaugeProps } from './SegmentedGauge'\nexport { type SegmentedGaugeTrackProps } from './SegmentedGaugeTrack'\nexport { type SegmentedGaugeSegmentProps } from './SegmentedGaugeSegment'\nexport { type SegmentedGaugeLabelProps } from './SegmentedGaugeLabel'\n"],"mappings":"+LAeA,IAAa,GAAA,EAAA,EAAA,eAAyE,KAAK,CAE9E,MAAiC,CAC5C,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EAAQ,CAC/F,CAKK,EACJ,GAAS,KAOL,CACE,KAAM,SACP,CARD,CACE,KAAM,QACN,gBAAiB,EACjB,gBAAiB,EACjB,gBAAiB,EAClB,CAKP,OACE,EAAA,EAAA,KAAC,EAAsB,SAAvB,CAAgC,MAAO,YACrC,EAAA,EAAA,KAAC,MAAD,CACE,GAAI,EACJ,uBAAqB,kBAChB,MACL,WAAA,EAAA,EAAA,IAAc,qCAAsC,EAAU,CAC9D,GAAI,EACJ,kBAAiB,EAAK,GAAG,EAAQ,QAAU,IAAA,GAC3C,aAAa,EAAiB,IAAA,GAAZ,EAClB,mBAAkB,EAClB,GAAI,WAEH,EACC,EAAS,CACP,SAAU,EACV,eACD,CAAC,EAEF,EAAA,EAAA,MAAA,EAAA,SAAA,CAAA,SAAA,EACE,EAAA,EAAA,KAAC,EAAD,CAAA,SACG,EAAa,KAAK,EAAG,KACpB,EAAA,EAAA,KAAC,EAAD,CAA0C,QAAS,CAAvB,EAAuB,CACnD,CACkB,CAAA,CAErB,IACC,EAAA,EAAA,KAAC,EAAD,CAAqB,GAAI,WAAkB,EAAkC,CAAA,CAE9E,CAAA,CAAA,CAED,CAAA,CACyB,CAAA,EAIrC,EAAe,YAAc,iBCvL7B,IAAa,EAIT,OAAO,OAAO,EAAM,CACtB,MAAO,EACP,QAAS,EACT,MAAO,EACR,CAAC,CAEF,EAAe,YAAc,iBAC7B,EAAoB,YAAc,uBAClC,EAAsB,YAAc,yBACpC,EAAoB,YAAc"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/segmented-gauge/SegmentedGaugeContext.tsx","../../src/segmented-gauge/SegmentedGaugeLabel.tsx","../../src/segmented-gauge/SegmentedGaugeSegment.tsx","../../src/segmented-gauge/SegmentedGaugeTrack.tsx","../../src/segmented-gauge/SegmentedGauge.tsx","../../src/segmented-gauge/index.ts"],"sourcesContent":["import { createContext, useContext } from 'react'\n\nexport interface SegmentedGaugeContextValue {\n value?: number\n min: number\n max: number\n segments: number\n currentIndex: number\n size: 'sm' | 'md'\n intent: 'main' | 'support' | 'accent' | 'success' | 'alert' | 'danger' | 'info' | 'neutral'\n customColor?: string\n labelId: string\n gaugeId: string\n}\n\nexport const SegmentedGaugeContext = createContext<SegmentedGaugeContextValue | null>(null)\n\nexport const useSegmentedGaugeContext = () => {\n const context = useContext(SegmentedGaugeContext)\n\n if (!context) {\n throw new Error('useSegmentedGaugeContext must be used within a SegmentedGauge provider')\n }\n\n return context\n}\n","import { cx } from 'class-variance-authority'\nimport { ComponentProps, Ref } from 'react'\n\nimport { useSegmentedGaugeContext } from './SegmentedGaugeContext'\n\nexport interface SegmentedGaugeLabelProps extends ComponentProps<'span'> {\n ref?: Ref<HTMLSpanElement>\n id?: string\n}\n\n/** The text label for the gauge. Renders a <span> element. */\nexport const SegmentedGaugeLabel = ({\n className,\n children,\n ref,\n id,\n ...props\n}: SegmentedGaugeLabelProps) => {\n const { labelId } = useSegmentedGaugeContext()\n\n return (\n <span\n data-spark-component=\"segmented-gauge-label\"\n data-testid=\"segmented-gauge-label\"\n ref={ref}\n id={id || labelId}\n className={cx('default:text-on-surface default:text-body-2', className)}\n {...props}\n >\n {children}\n </span>\n )\n}\n\nSegmentedGaugeLabel.displayName = 'SegmentedGauge.Label'\n","import { cx } from 'class-variance-authority'\nimport { ComponentProps, Ref, useMemo } from 'react'\n\nimport { useSegmentedGaugeContext } from './SegmentedGaugeContext'\n\nexport interface SegmentedGaugeSegmentProps extends ComponentProps<'div'> {\n /**\n * Index of this segment (0-based)\n */\n index?: number\n ref?: Ref<HTMLDivElement>\n}\n\n/**\n * An individual segment in the gauge. Renders a <div> element.\n */\n\nexport const SegmentedGaugeSegment = ({\n index = 0,\n className,\n children,\n ref,\n ...props\n}: SegmentedGaugeSegmentProps) => {\n const { size, intent, customColor, currentIndex } = useSegmentedGaugeContext()\n\n // Calculate isActive and isCurrent from context and index\n const isActive = currentIndex !== -1 && index <= currentIndex\n const isCurrent = currentIndex !== -1 && index === currentIndex\n\n const gaugeColor = useMemo(() => {\n // If customColor is provided, use it\n if (customColor) {\n return customColor\n }\n\n // Handle predefined intents\n switch (intent) {\n case 'main':\n return 'var(--color-main)'\n case 'support':\n return 'var(--color-support)'\n case 'accent':\n return 'var(--color-accent)'\n case 'success':\n return 'var(--color-success)'\n case 'alert':\n return 'var(--color-alert)'\n case 'danger':\n return 'var(--color-error)'\n case 'info':\n return 'var(--color-info)'\n case 'neutral':\n return 'var(--color-neutral)'\n default:\n return 'var(--color-neutral)'\n }\n }, [intent, customColor])\n\n const segmentClasses = cx(\n 'border-outline relative rounded-full',\n {\n 'h-sz-8 w-sz-24': size === 'sm',\n 'h-sz-12 w-sz-36': size === 'md',\n 'default:bg-[var(--gauge-color)]': isActive,\n 'border-sm bg-surface': !isActive,\n },\n className\n )\n\n const indicatorClasses = cx(\n 'absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2',\n 'default:bg-surface default:rounded-full',\n 'border-[var(--gauge-color)]',\n {\n 'size-sz-12 border-md': size === 'sm',\n 'size-sz-20 border-lg': size === 'md',\n }\n )\n\n return (\n <div\n data-spark-component=\"segmented-gauge-segment\"\n data-testid=\"segmented-gauge-segment\"\n data-active={isActive}\n data-current={isCurrent}\n ref={ref}\n style={\n {\n '--gauge-color': gaugeColor,\n } as React.CSSProperties\n }\n className={segmentClasses}\n {...props}\n >\n {children}\n {isCurrent && <div className={indicatorClasses} aria-hidden=\"true\" />}\n </div>\n )\n}\n\nSegmentedGaugeSegment.displayName = 'SegmentedGauge.Segment'\n","import { cx } from 'class-variance-authority'\nimport { ComponentProps, Ref } from 'react'\n\nexport interface SegmentedGaugeTrackProps extends ComponentProps<'div'> {\n ref?: Ref<HTMLDivElement>\n}\n\n/** The container track for the gauge segments. Renders a <div> element. */\nexport const SegmentedGaugeTrack = ({\n className,\n children,\n ref,\n ...props\n}: SegmentedGaugeTrackProps) => {\n return (\n <div\n data-spark-component=\"segmented-gauge-track\"\n ref={ref}\n className={cx('gap-sm relative flex rounded-full', className)}\n {...props}\n >\n {children}\n </div>\n )\n}\n\nSegmentedGaugeTrack.displayName = 'SegmentedGauge.Track'\n","import { cx } from 'class-variance-authority'\nimport { Ref, useId, useMemo } from 'react'\n\nimport { SegmentedGaugeContext } from './SegmentedGaugeContext'\nimport { SegmentedGaugeLabel } from './SegmentedGaugeLabel'\nimport { SegmentedGaugeSegment } from './SegmentedGaugeSegment'\nimport { SegmentedGaugeTrack } from './SegmentedGaugeTrack'\n\nconst calculateCurrentIndex = (\n value: number | undefined,\n min: number,\n max: number,\n segments: number\n) => {\n // If value is undefined or null, no segment is active\n if (value == null) {\n return -1\n }\n const normalizedValue = Math.max(min, Math.min(max, value))\n const range = max - min\n const segmentSize = range / (segments - 1)\n const rawIndex = (normalizedValue - min) / segmentSize\n\n // Clamp the index to valid range\n return Math.max(0, Math.min(segments - 1, Math.round(rawIndex)))\n}\n\nexport interface SegmentedGaugeProps {\n /**\n * The current value of the gauge\n */\n value?: number\n /**\n * Minimum value of the gauge (aria-valuemin)\n */\n min: number\n /**\n * Maximum value of the gauge (aria-valuemax)\n */\n max: number\n /**\n * Description text for the gauge (aria-describedby)\n */\n description?: string\n /**\n * Size of the gauge\n */\n size?: 'sm' | 'md'\n /**\n * Intent of the gauge - predefined color intent\n */\n intent?: 'main' | 'support' | 'accent' | 'success' | 'alert' | 'danger' | 'info' | 'neutral'\n /**\n * Custom color for the gauge (hex, CSS variable, etc.)\n */\n customColor?: string\n /**\n * ID of the gauge element\n */\n id?: string\n /**\n * Accessible label for the gauge (required if no id is provided)\n */\n 'aria-label'?: string\n /**\n * Textual representation of the current value (aria-valuetext)\n * By default, percentage is used (e.g. \"33%\")\n */\n 'aria-valuetext'?: string\n /**\n * Additional CSS classes\n */\n className?: string\n /**\n * Ref to the root element\n */\n ref?: Ref<HTMLDivElement>\n /**\n * Children render prop for custom rendering\n */\n children?: (props: {\n segments: {\n isActive: boolean\n isCurrent: boolean\n }[]\n currentIndex: number\n }) => React.ReactNode\n}\n\nexport const SegmentedGauge = ({\n value,\n min,\n max,\n description,\n size = 'md',\n intent = 'neutral',\n customColor,\n id,\n 'aria-label': ariaLabel,\n className,\n ref,\n children,\n ...props\n}: SegmentedGaugeProps) => {\n // Calculate segments from min and max\n const segments = max - min + 1\n const currentIndex = useMemo(\n () => calculateCurrentIndex(value, min, max, segments),\n [value, min, max, segments]\n )\n\n // Generate unique IDs\n const internalLabelId = useId()\n const generatedId = useId()\n // Use provided id or generated one for the gauge element\n const gaugeId = id || generatedId\n\n const segmentsData = useMemo(() => {\n return Array.from({ length: segments }, (_, index) => ({\n isActive: currentIndex !== -1 && index <= currentIndex,\n isCurrent: currentIndex !== -1 && index === currentIndex,\n }))\n }, [segments, currentIndex])\n\n const contextValue = useMemo(\n () => ({\n value,\n min,\n max,\n segments,\n currentIndex,\n size,\n intent,\n customColor,\n labelId: internalLabelId,\n gaugeId,\n }),\n [value, min, max, segments, currentIndex, size, intent, customColor, internalLabelId, gaugeId]\n )\n\n /**\n * A `meter` role MUST have a value. If the value is not available, the component uses a `status` role instead.\n */\n const roleProps =\n value != null\n ? {\n role: 'meter',\n 'aria-valuenow': value,\n 'aria-valuemin': min,\n 'aria-valuemax': max,\n }\n : {\n role: 'status',\n }\n\n return (\n <SegmentedGaugeContext value={contextValue}>\n <div\n id={gaugeId}\n data-spark-component=\"segmented-gauge\"\n ref={ref}\n className={cx('gap-md flex flex-wrap items-center', className)}\n {...roleProps}\n aria-labelledby={id ? `${gaugeId}-label` : undefined}\n aria-label={!id ? ariaLabel : undefined}\n aria-describedby={internalLabelId}\n {...props}\n >\n {children ? (\n children({\n segments: segmentsData,\n currentIndex,\n })\n ) : (\n <>\n <SegmentedGaugeTrack>\n {segmentsData.map((_, index) => (\n <SegmentedGaugeSegment key={index} index={index} />\n ))}\n </SegmentedGaugeTrack>\n\n {description && (\n <SegmentedGaugeLabel id={internalLabelId}>{description}</SegmentedGaugeLabel>\n )}\n </>\n )}\n </div>\n </SegmentedGaugeContext>\n )\n}\n\nSegmentedGauge.displayName = 'SegmentedGauge'\n","import { SegmentedGauge as Root } from './SegmentedGauge'\nimport { SegmentedGaugeLabel } from './SegmentedGaugeLabel'\nimport { SegmentedGaugeSegment } from './SegmentedGaugeSegment'\nimport { SegmentedGaugeTrack } from './SegmentedGaugeTrack'\n\n/**\n * A visual indicator that displays a value using discrete segments within a defined range.\n */\nexport const SegmentedGauge: typeof Root & {\n Track: typeof SegmentedGaugeTrack\n Segment: typeof SegmentedGaugeSegment\n Label: typeof SegmentedGaugeLabel\n} = Object.assign(Root, {\n Track: SegmentedGaugeTrack,\n Segment: SegmentedGaugeSegment,\n Label: SegmentedGaugeLabel,\n})\n\nSegmentedGauge.displayName = 'SegmentedGauge'\nSegmentedGaugeTrack.displayName = 'SegmentedGauge.Track'\nSegmentedGaugeSegment.displayName = 'SegmentedGauge.Segment'\nSegmentedGaugeLabel.displayName = 'SegmentedGauge.Label'\n\nexport { type SegmentedGaugeProps } from './SegmentedGauge'\nexport { type SegmentedGaugeTrackProps } from './SegmentedGaugeTrack'\nexport { type SegmentedGaugeSegmentProps } from './SegmentedGaugeSegment'\nexport { type SegmentedGaugeLabelProps } from './SegmentedGaugeLabel'\n"],"mappings":"+LAeA,IAAa,GAAA,EAAA,EAAA,eAAyE,KAAK,CAE9E,MAAiC,CAC5C,IAAM,GAAA,EAAA,EAAA,YAAqB,EAAsB,CAEjD,GAAI,CAAC,EACH,MAAU,MAAM,yEAAyE,CAG3F,OAAO,GCbI,GAAuB,CAClC,YACA,WACA,MACA,KACA,GAAG,KAC2B,CAC9B,GAAM,CAAE,WAAY,GAA0B,CAE9C,OACE,EAAA,EAAA,KAAC,OAAD,CACE,uBAAqB,wBACrB,cAAY,wBACP,MACL,GAAI,GAAM,EACV,WAAA,EAAA,EAAA,IAAc,8CAA+C,EAAU,CACvE,GAAI,EAEH,WACI,CAAA,EAIX,EAAoB,YAAc,uBCjBlC,IAAa,GAAyB,CACpC,QAAQ,EACR,YACA,WACA,MACA,GAAG,KAC6B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eACD,CAAC,EAEF,EAAA,EAAA,MAAA,EAAA,SAAA,CAAA,SAAA,EACE,EAAA,EAAA,KAAC,EAAD,CAAA,SACG,EAAa,KAAK,EAAG,KACpB,EAAA,EAAA,KAAC,EAAD,CAA0C,QAAS,CAAvB,EAAuB,CACnD,CACkB,CAAA,CAErB,IACC,EAAA,EAAA,KAAC,EAAD,CAAqB,GAAI,WAAkB,EAAkC,CAAA,CAE9E,CAAA,CAAA,CAED,CAAA,CACgB,CAAA,EAI5B,EAAe,YAAc,iBCvL7B,IAAa,EAIT,OAAO,OAAO,EAAM,CACtB,MAAO,EACP,QAAS,EACT,MAAO,EACR,CAAC,CAEF,EAAe,YAAc,iBAC7B,EAAoB,YAAc,uBAClC,EAAsB,YAAc,yBACpC,EAAoB,YAAc"}
@@ -113,7 +113,7 @@ var p = (e, t, n, r) => {
113
113
  "aria-valuemin": n,
114
114
  "aria-valuemax": l
115
115
  };
116
- return /* @__PURE__ */ o(c.Provider, {
116
+ return /* @__PURE__ */ o(c, {
117
117
  value: A,
118
118
  children: /* @__PURE__ */ o("div", {
119
119
  id: O,