@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.
- package/dist/accordion/index.js +1 -1
- package/dist/accordion/index.js.map +1 -1
- package/dist/accordion/index.mjs +1 -1
- package/dist/accordion/index.mjs.map +1 -1
- package/dist/alert-dialog/index.js +1 -1
- package/dist/alert-dialog/index.js.map +1 -1
- package/dist/alert-dialog/index.mjs +1 -1
- package/dist/alert-dialog/index.mjs.map +1 -1
- package/dist/avatar/index.js +1 -1
- package/dist/avatar/index.js.map +1 -1
- package/dist/avatar/index.mjs +17 -17
- package/dist/avatar/index.mjs.map +1 -1
- package/dist/button/index.js +1 -1
- package/dist/button/index.mjs +1 -1
- package/dist/{button-BtuAr9qV.mjs → button-CNabSkd_.mjs} +2 -2
- package/dist/{button-BtuAr9qV.mjs.map → button-CNabSkd_.mjs.map} +1 -1
- package/dist/{button-BaJmiSYq.js → button-Tv2N8_24.js} +2 -2
- package/dist/{button-BaJmiSYq.js.map → button-Tv2N8_24.js.map} +1 -1
- package/dist/card/index.js +1 -1
- package/dist/card/index.js.map +1 -1
- package/dist/card/index.mjs +1 -1
- package/dist/card/index.mjs.map +1 -1
- package/dist/carousel/index.js +1 -1
- package/dist/carousel/index.js.map +1 -1
- package/dist/carousel/index.mjs +2 -2
- package/dist/carousel/index.mjs.map +1 -1
- package/dist/checkbox/index.js +1 -1
- package/dist/checkbox/index.mjs +1 -1
- package/dist/{checkbox-xsURzANi.mjs → checkbox-CbMh-21q.mjs} +2 -2
- package/dist/{checkbox-xsURzANi.mjs.map → checkbox-CbMh-21q.mjs.map} +1 -1
- package/dist/{checkbox-DjwbAH09.js → checkbox-hVGRiWC_.js} +2 -2
- package/dist/{checkbox-DjwbAH09.js.map → checkbox-hVGRiWC_.js.map} +1 -1
- package/dist/chip/index.js +1 -1
- package/dist/chip/index.js.map +1 -1
- package/dist/chip/index.mjs +1 -1
- package/dist/chip/index.mjs.map +1 -1
- package/dist/circular-meter/index.js +1 -1
- package/dist/circular-meter/index.js.map +1 -1
- package/dist/circular-meter/index.mjs +28 -28
- package/dist/circular-meter/index.mjs.map +1 -1
- package/dist/combobox/index.js +1 -1
- package/dist/combobox/index.js.map +1 -1
- package/dist/combobox/index.mjs +10 -13
- package/dist/combobox/index.mjs.map +1 -1
- package/dist/dialog/index.js +1 -1
- package/dist/dialog/index.js.map +1 -1
- package/dist/dialog/index.mjs +2 -2
- package/dist/dialog/index.mjs.map +1 -1
- package/dist/drawer/index.js +1 -1
- package/dist/drawer/index.js.map +1 -1
- package/dist/drawer/index.mjs +2 -2
- package/dist/drawer/index.mjs.map +1 -1
- package/dist/dropdown/index.js +1 -1
- package/dist/dropdown/index.js.map +1 -1
- package/dist/dropdown/index.mjs +9 -12
- package/dist/dropdown/index.mjs.map +1 -1
- package/dist/file-upload/index.js +1 -1
- package/dist/file-upload/index.js.map +1 -1
- package/dist/file-upload/index.mjs +5 -5
- package/dist/file-upload/index.mjs.map +1 -1
- package/dist/form-field/index.js +1 -1
- package/dist/form-field/index.mjs +1 -1
- package/dist/form-field-BCqHBvWN.js +2 -0
- package/dist/form-field-BCqHBvWN.js.map +1 -0
- package/dist/{form-field-CV5dzt-I.mjs → form-field-ByLHXtzx.mjs} +27 -27
- package/dist/form-field-ByLHXtzx.mjs.map +1 -0
- package/dist/icon-button/index.js +1 -1
- package/dist/icon-button/index.mjs +1 -1
- package/dist/icon-button-CTe0v0g7.js +2 -0
- package/dist/{icon-button-BSVlcyAO.js.map → icon-button-CTe0v0g7.js.map} +1 -1
- package/dist/{icon-button-XyQSaVPL.mjs → icon-button-DVbKK2_a.mjs} +3 -3
- package/dist/{icon-button-XyQSaVPL.mjs.map → icon-button-DVbKK2_a.mjs.map} +1 -1
- package/dist/input/index.js +1 -1
- package/dist/input/index.mjs +1 -1
- package/dist/{input-CJOeEIbx.mjs → input-BxuTPD5-.mjs} +6 -6
- package/dist/input-BxuTPD5-.mjs.map +1 -0
- package/dist/input-DIGSkxbh.js +2 -0
- package/dist/input-DIGSkxbh.js.map +1 -0
- package/dist/input-otp/index.js +1 -1
- package/dist/input-otp/index.js.map +1 -1
- package/dist/input-otp/index.mjs +27 -17
- package/dist/input-otp/index.mjs.map +1 -1
- package/dist/menu/index.js +1 -1
- package/dist/menu/index.js.map +1 -1
- package/dist/menu/index.mjs +1 -1
- package/dist/menu/index.mjs.map +1 -1
- package/dist/meter/index.js +1 -1
- package/dist/meter/index.js.map +1 -1
- package/dist/meter/index.mjs +17 -17
- package/dist/meter/index.mjs.map +1 -1
- package/dist/pagination/index.js +1 -1
- package/dist/pagination/index.js.map +1 -1
- package/dist/pagination/index.mjs +3 -3
- package/dist/pagination/index.mjs.map +1 -1
- package/dist/popover/index.js +1 -1
- package/dist/popover/index.mjs +1 -1
- package/dist/{popover-CSmCERcL.mjs → popover-83FABwMs.mjs} +3 -3
- package/dist/popover-83FABwMs.mjs.map +1 -0
- package/dist/popover-Daknmg_Z.js +2 -0
- package/dist/popover-Daknmg_Z.js.map +1 -0
- package/dist/progress/index.js +1 -1
- package/dist/progress/index.mjs +1 -1
- package/dist/{progress-C-Zs94G2.mjs → progress-BfpWgeE1.mjs} +2 -2
- package/dist/{progress-C-Zs94G2.mjs.map → progress-BfpWgeE1.mjs.map} +1 -1
- package/dist/{progress-DaQt4olK.js → progress-DBD2FiQ1.js} +2 -2
- package/dist/{progress-DaQt4olK.js.map → progress-DBD2FiQ1.js.map} +1 -1
- package/dist/progress-tracker/index.js +1 -1
- package/dist/progress-tracker/index.js.map +1 -1
- package/dist/progress-tracker/index.mjs +4 -4
- package/dist/progress-tracker/index.mjs.map +1 -1
- package/dist/radio-group/index.js +1 -1
- package/dist/radio-group/index.js.map +1 -1
- package/dist/radio-group/index.mjs +5 -8
- package/dist/radio-group/index.mjs.map +1 -1
- package/dist/rating/index.js +1 -1
- package/dist/rating/index.mjs +1 -1
- package/dist/rating-display/index.js +1 -1
- package/dist/rating-display/index.js.map +1 -1
- package/dist/rating-display/index.mjs +1 -1
- package/dist/rating-display/index.mjs.map +1 -1
- package/dist/scrolling-list/index.js +1 -1
- package/dist/scrolling-list/index.js.map +1 -1
- package/dist/scrolling-list/index.mjs +17 -17
- package/dist/scrolling-list/index.mjs.map +1 -1
- package/dist/segmented-control/index.js +1 -1
- package/dist/segmented-control/index.js.map +1 -1
- package/dist/segmented-control/index.mjs +1 -1
- package/dist/segmented-control/index.mjs.map +1 -1
- package/dist/segmented-gauge/index.js +1 -1
- package/dist/segmented-gauge/index.js.map +1 -1
- package/dist/segmented-gauge/index.mjs +1 -1
- package/dist/segmented-gauge/index.mjs.map +1 -1
- package/dist/select/index.js +1 -1
- package/dist/select/index.js.map +1 -1
- package/dist/select/index.mjs +2 -2
- package/dist/select/index.mjs.map +1 -1
- package/dist/slider/index.js +1 -1
- package/dist/slider/index.js.map +1 -1
- package/dist/slider/index.mjs +2 -2
- package/dist/slider/index.mjs.map +1 -1
- package/dist/stepper/index.js +1 -1
- package/dist/stepper/index.js.map +1 -1
- package/dist/stepper/index.mjs +3 -3
- package/dist/stepper/index.mjs.map +1 -1
- package/dist/table/index.js +1 -1
- package/dist/table/index.js.map +1 -1
- package/dist/table/index.mjs +36 -36
- package/dist/table/index.mjs.map +1 -1
- package/dist/tabs/index.js +1 -1
- package/dist/tabs/index.js.map +1 -1
- package/dist/tabs/index.mjs +16 -16
- package/dist/tabs/index.mjs.map +1 -1
- package/dist/tag/index.js +1 -1
- package/dist/tag/index.js.map +1 -1
- package/dist/tag/index.mjs +1 -1
- package/dist/tag/index.mjs.map +1 -1
- package/dist/textarea/index.js +1 -1
- package/dist/textarea/index.js.map +1 -1
- package/dist/textarea/index.mjs +2 -2
- package/dist/textarea/index.mjs.map +1 -1
- package/dist/toast/index.js +1 -1
- package/dist/toast/index.mjs +2 -2
- package/package.json +5 -5
- package/dist/form-field-CV5dzt-I.mjs.map +0 -1
- package/dist/form-field-CYGgse45.js +0 -2
- package/dist/form-field-CYGgse45.js.map +0 -1
- package/dist/icon-button-BSVlcyAO.js +0 -2
- package/dist/input-CJOeEIbx.mjs.map +0 -1
- package/dist/input-Dv436NKY.js +0 -2
- package/dist/input-Dv436NKY.js.map +0 -1
- package/dist/popover-CSmCERcL.mjs.map +0 -1
- package/dist/popover-CsCB_Fgs.js +0 -2
- package/dist/popover-CsCB_Fgs.js.map +0 -1
package/dist/meter/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/meter/MeterContext.tsx","../../src/meter/Meter.tsx","../../src/meter/MeterLabel.tsx","../../src/meter/MeterTrack.styles.ts","../../src/meter/useIntersectionAnimation.ts","../../src/meter/MeterTrack.tsx","../../src/meter/MeterValue.tsx","../../src/meter/index.ts"],"sourcesContent":["import { createContext, useContext } from 'react'\n\nimport { MeterIndicatorStylesProps } from './MeterTrack.styles'\n\nexport interface MeterContextValue {\n value: number\n max: number\n min: number\n intent: MeterIndicatorStylesProps['intent']\n shape: 'square' | 'rounded'\n onLabelId: (id?: string) => void\n}\n\nexport const MeterContext = createContext<MeterContextValue | null>(null)\n\nexport const ID_PREFIX = ':meter'\n\nexport const useMeter = () => {\n const context = useContext(MeterContext)\n\n if (!context) {\n throw new Error('useMeter must be used within a Meter provider')\n }\n\n return context\n}\n","import { Meter as BaseMeter } from '@base-ui/react/meter'\nimport { cx } from 'class-variance-authority'\nimport { ComponentProps, PropsWithChildren, Ref, useMemo, useState } from 'react'\n\nimport { MeterContext } from './MeterContext'\nimport { MeterIndicatorStylesProps } from './MeterTrack.styles'\n\nexport interface MeterProps\n extends\n Omit<ComponentProps<typeof BaseMeter.Root>, 'render'>,\n Pick<MeterIndicatorStylesProps, 'intent'> {\n /**\n * Shape of the meter track and indicator.\n */\n shape?: 'square' | 'rounded'\n /**\n * Change the default rendered element for the one passed as a child, merging their props and behavior.\n */\n asChild?: boolean\n ref?: Ref<HTMLDivElement>\n}\n\nexport const Meter = ({\n className,\n value,\n max = 100,\n min = 0,\n shape = 'rounded',\n intent = 'support',\n children,\n ref,\n ...others\n}: PropsWithChildren<MeterProps>) => {\n const [labelId, setLabelId] = useState<string>()\n\n const contextValue = useMemo(() => {\n return {\n value: value ?? 0,\n max,\n min,\n intent,\n shape,\n onLabelId: setLabelId,\n }\n }, [max, min, value, intent, shape, setLabelId])\n\n return (\n <MeterContext.Provider value={contextValue}>\n <BaseMeter.Root\n data-spark-component=\"meter\"\n ref={ref}\n className={cx(\n 'gap-y-sm gap-x-md focus-visible:u-outline box-border grid grid-cols-[1fr_auto]',\n className\n )}\n value={value}\n max={max}\n min={min}\n aria-labelledby={labelId}\n {...others}\n >\n {children}\n </BaseMeter.Root>\n </MeterContext.Provider>\n )\n}\n\nMeter.displayName = 'Meter'\n","import { Meter as BaseMeter } from '@base-ui/react/meter'\nimport { useMergeRefs } from '@spark-ui/hooks/use-merge-refs'\nimport { ComponentProps, useCallback, useId } from 'react'\n\nimport { ID_PREFIX, useMeter } from './MeterContext'\n\nexport type MeterLabelProps = Omit<ComponentProps<typeof BaseMeter.Label>, 'render'>\n\n/**\n * The label of the meter, announced to assistive technology. Renders a <span> element.\n */\nexport const MeterLabel = ({\n id: idProp,\n children,\n ref: forwardedRef,\n ...others\n}: MeterLabelProps) => {\n const internalID = `${ID_PREFIX}-label-${useId()}`\n const id = idProp || internalID\n\n const { onLabelId } = useMeter()\n const rootRef = useCallback(\n (el: HTMLSpanElement) => {\n onLabelId(el ? id : undefined)\n },\n [id, onLabelId]\n )\n const ref = useMergeRefs(forwardedRef, rootRef)\n\n return (\n <BaseMeter.Label\n data-spark-component=\"meter-label\"\n id={id}\n className=\"default:text-body-1-highlight text-on-surface\"\n ref={ref}\n {...others}\n >\n {children}\n </BaseMeter.Label>\n )\n}\n\nMeterLabel.displayName = 'Meter.Label'\n","import { cva, VariantProps } from 'class-variance-authority'\n\nexport const meterTrackStyles = cva([\n 'relative col-span-2',\n 'h-sz-8 w-full',\n 'transform-gpu overflow-hidden',\n 'bg-on-background/dim-4',\n])\n\nexport type MeterTrackStylesProps = VariantProps<typeof meterTrackStyles>\n\nexport const meterIndicatorStyles = cva(\n ['size-full', 'ease-standard transition-[width] duration-700', 'motion-reduce:transition-none'],\n {\n variants: {\n /**\n * Color scheme of the meter component.\n */\n intent: {\n main: ['bg-main'],\n support: ['bg-support'],\n success: ['bg-success'],\n alert: ['bg-alert'],\n danger: ['bg-error'],\n info: ['bg-info'],\n },\n /**\n * Shape of the meter component.\n */\n shape: {\n square: [],\n rounded: ['rounded-sm'],\n },\n },\n }\n)\n\nexport type MeterIndicatorStylesProps = VariantProps<typeof meterIndicatorStyles>\n","import { RefObject, useEffect, useRef } from 'react'\n\nexport interface UseIntersectionAnimationOptions {\n /**\n * The threshold at which the callback should be triggered.\n * A value of 0 means as soon as any part of the element is visible.\n * A value of 1 means the entire element must be visible.\n * @default 0.1\n */\n threshold?: number\n /**\n * The root margin for the Intersection Observer.\n * This can be used to trigger the animation before the element enters the viewport.\n * @default undefined\n */\n rootMargin?: string\n}\n\n/**\n * Hook to trigger an animation callback when an element enters the viewport.\n * The callback is only triggered once, when the element first becomes visible.\n *\n * @param elementRef - Reference to the element to observe\n * @param onIntersect - Callback to execute when the element enters the viewport\n * @param options - Configuration options for the Intersection Observer\n * @returns Whether the animation has been triggered\n */\nexport function useIntersectionAnimation(\n elementRef: RefObject<Element | null>,\n onIntersect: () => void,\n options: UseIntersectionAnimationOptions = {}\n): boolean {\n const { threshold = 0.1, rootMargin } = options\n const hasTriggeredRef = useRef(false)\n const callbackRef = useRef(onIntersect)\n\n // Keep callback ref up to date\n useEffect(() => {\n callbackRef.current = onIntersect\n }, [onIntersect])\n\n useEffect(() => {\n const element = elementRef.current\n if (!element || hasTriggeredRef.current) return\n\n const observer = new IntersectionObserver(\n entries => {\n entries.forEach(entry => {\n if (entry.isIntersecting && !hasTriggeredRef.current) {\n // Use requestAnimationFrame to ensure the callback runs at the right time\n requestAnimationFrame(() => {\n if (!hasTriggeredRef.current) {\n hasTriggeredRef.current = true\n callbackRef.current()\n // Disconnect observer after callback is triggered (only trigger once)\n observer.disconnect()\n }\n })\n }\n })\n },\n {\n threshold,\n rootMargin,\n }\n )\n\n observer.observe(element)\n\n return () => {\n observer.disconnect()\n }\n }, [elementRef, threshold, rootMargin])\n\n return hasTriggeredRef.current\n}\n","import { Meter as BaseMeter } from '@base-ui/react/meter'\nimport { cx } from 'class-variance-authority'\nimport { ComponentProps, useRef, useState } from 'react'\n\nimport { useMeter } from './MeterContext'\nimport { meterIndicatorStyles, meterTrackStyles } from './MeterTrack.styles'\nimport { useIntersectionAnimation } from './useIntersectionAnimation'\n\nexport type MeterTrackProps = Omit<ComponentProps<typeof BaseMeter.Track>, 'render'>\n\n/**\n * The track of the meter showing progress. Renders a <div> element.\n */\nexport const MeterTrack = ({ className, ...others }: MeterTrackProps) => {\n const { value, max, min, intent, shape } = useMeter()\n const percentage = ((value - min) / (max - min)) * 100\n const trackRef = useRef<HTMLDivElement>(null)\n const [hasAnimated, setHasAnimated] = useState(false)\n\n // Trigger animation when component enters viewport\n useIntersectionAnimation(trackRef, () => {\n setHasAnimated(true)\n })\n\n return (\n <BaseMeter.Track\n ref={trackRef}\n data-spark-component=\"meter-track\"\n className={cx(meterTrackStyles(), { 'rounded-sm': shape === 'rounded' }, className)}\n {...others}\n >\n <BaseMeter.Indicator\n data-spark-component=\"meter-indicator\"\n className={meterIndicatorStyles({ intent, shape })}\n style={{\n width: hasAnimated ? `${percentage}%` : '0%',\n }}\n />\n </BaseMeter.Track>\n )\n}\n\nMeterTrack.displayName = 'Meter.Track'\n","import { Meter as BaseMeter } from '@base-ui/react/meter'\nimport { cx } from 'class-variance-authority'\nimport { ComponentProps, ReactNode } from 'react'\n\nexport type MeterValueProps = Omit<\n ComponentProps<typeof BaseMeter.Value>,\n 'render' | 'children'\n> & {\n children?: ((formattedValue: string, value: number) => ReactNode) | null | undefined\n}\n\n/**\n * The value display of the meter. Renders a <span> element.\n */\nexport const MeterValue = ({ className, children, ...others }: MeterValueProps) => {\n return (\n <BaseMeter.Value\n data-spark-component=\"meter-value\"\n className={cx('default:text-body-1 text-on-surface', 'col-start-2 text-right', className)}\n {...others}\n >\n {children}\n </BaseMeter.Value>\n )\n}\n\nMeterValue.displayName = 'Meter.Value'\n","import { Meter as Root } from './Meter'\nimport { MeterLabel } from './MeterLabel'\nimport { MeterTrack } from './MeterTrack'\nimport { MeterValue } from './MeterValue'\n\n/**\n * A horizontal progress indicator that displays a scalar measurement within a known range.\n */\nexport const Meter: typeof Root & {\n Label: typeof MeterLabel\n Track: typeof MeterTrack\n Value: typeof MeterValue\n} = Object.assign(Root, {\n Label: MeterLabel,\n Track: MeterTrack,\n Value: MeterValue,\n})\n\nMeter.displayName = 'Meter'\nMeterLabel.displayName = 'Meter.Label'\nMeterTrack.displayName = 'Meter.Track'\nMeterValue.displayName = 'Meter.Value'\n\nexport { type MeterProps } from './Meter'\nexport { type MeterLabelProps } from './MeterLabel'\nexport { type MeterTrackProps } from './MeterTrack'\nexport { type MeterValueProps } from './MeterValue'\n"],"mappings":"6QAaA,IAAa,GAAA,EAAA,EAAA,eAAuD,KAAK,CAE5D,EAAY,SAEZ,MAAiB,CAC5B,IAAM,GAAA,EAAA,EAAA,YAAqB,EAAa,CAExC,GAAI,CAAC,EACH,MAAU,MAAM,gDAAgD,CAGlE,OAAO,GCFI,GAAS,CACpB,YACA,QACA,MAAM,IACN,MAAM,EACN,QAAQ,UACR,SAAS,UACT,WACA,MACA,GAAG,KACgC,CACnC,GAAM,CAAC,EAAS,IAAA,EAAA,EAAA,WAAgC,CAE1C,GAAA,EAAA,EAAA,cACG,CACL,MAAO,GAAS,EAChB,MACA,MACA,SACA,QACA,UAAW,EACZ,EACA,CAAC,EAAK,EAAK,EAAO,EAAQ,EAAO,EAAW,CAAC,CAEhD,OACE,EAAA,EAAA,KAAC,EAAa,SAAd,CAAuB,MAAO,YAC5B,EAAA,EAAA,KAAC,EAAA,MAAU,KAAX,CACE,uBAAqB,QA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AO,EAAM,CACtB,MAAO,EACP,MAAO,EACP,MAAO,EACR,CAAC,CAEF,EAAM,YAAc,QACpB,EAAW,YAAc,cACzB,EAAW,YAAc,cACzB,EAAW,YAAc"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/meter/MeterContext.tsx","../../src/meter/Meter.tsx","../../src/meter/MeterLabel.tsx","../../src/meter/MeterTrack.styles.ts","../../src/meter/useIntersectionAnimation.ts","../../src/meter/MeterTrack.tsx","../../src/meter/MeterValue.tsx","../../src/meter/index.ts"],"sourcesContent":["import { createContext, useContext } from 'react'\n\nimport { MeterIndicatorStylesProps } from './MeterTrack.styles'\n\nexport interface MeterContextValue {\n value: number\n max: number\n min: number\n intent: MeterIndicatorStylesProps['intent']\n shape: 'square' | 'rounded'\n onLabelId: (id?: string) => void\n}\n\nexport const MeterContext = createContext<MeterContextValue | null>(null)\n\nexport const ID_PREFIX = ':meter'\n\nexport const useMeter = () => {\n const context = useContext(MeterContext)\n\n if (!context) {\n throw new Error('useMeter must be used within a Meter provider')\n }\n\n return context\n}\n","import { Meter as BaseMeter } from '@base-ui/react/meter'\nimport { cx } from 'class-variance-authority'\nimport { ComponentProps, PropsWithChildren, Ref, useMemo, useState } from 'react'\n\nimport { MeterContext } from './MeterContext'\nimport { MeterIndicatorStylesProps } from './MeterTrack.styles'\n\nexport interface MeterProps\n extends\n Omit<ComponentProps<typeof BaseMeter.Root>, 'render'>,\n Pick<MeterIndicatorStylesProps, 'intent'> {\n /**\n * Shape of the meter track and indicator.\n */\n shape?: 'square' | 'rounded'\n /**\n * Change the default rendered element for the one passed as a child, merging their props and behavior.\n */\n asChild?: boolean\n ref?: Ref<HTMLDivElement>\n}\n\nexport const Meter = ({\n className,\n value,\n max = 100,\n min = 0,\n shape = 'rounded',\n intent = 'support',\n children,\n ref,\n ...others\n}: PropsWithChildren<MeterProps>) => {\n const [labelId, setLabelId] = useState<string>()\n\n const contextValue = useMemo(() => {\n return {\n value: value ?? 0,\n max,\n min,\n intent,\n shape,\n onLabelId: setLabelId,\n }\n }, [max, min, value, intent, shape, setLabelId])\n\n return (\n <MeterContext value={contextValue}>\n <BaseMeter.Root\n data-spark-component=\"meter\"\n ref={ref}\n className={cx(\n 'gap-y-sm gap-x-md focus-visible:u-outline box-border grid grid-cols-[1fr_auto]',\n className\n )}\n value={value}\n max={max}\n min={min}\n aria-labelledby={labelId}\n {...others}\n >\n {children}\n </BaseMeter.Root>\n </MeterContext>\n )\n}\n\nMeter.displayName = 'Meter'\n","import { Meter as BaseMeter } from '@base-ui/react/meter'\nimport { useMergeRefs } from '@spark-ui/hooks/use-merge-refs'\nimport { ComponentProps, useCallback, useId } from 'react'\n\nimport { ID_PREFIX, useMeter } from './MeterContext'\n\nexport type MeterLabelProps = Omit<ComponentProps<typeof BaseMeter.Label>, 'render'>\n\n/**\n * The label of the meter, announced to assistive technology. Renders a <span> element.\n */\nexport const MeterLabel = ({\n id: idProp,\n children,\n ref: forwardedRef,\n ...others\n}: MeterLabelProps) => {\n const internalID = `${ID_PREFIX}-label-${useId()}`\n const id = idProp || internalID\n\n const { onLabelId } = useMeter()\n const rootRef = useCallback(\n (el: HTMLSpanElement) => {\n onLabelId(el ? id : undefined)\n },\n [id, onLabelId]\n )\n const ref = useMergeRefs(forwardedRef, rootRef)\n\n return (\n <BaseMeter.Label\n data-spark-component=\"meter-label\"\n id={id}\n className=\"default:text-body-1-highlight text-on-surface\"\n ref={ref}\n {...others}\n >\n {children}\n </BaseMeter.Label>\n )\n}\n\nMeterLabel.displayName = 'Meter.Label'\n","import { cva, VariantProps } from 'class-variance-authority'\n\nexport const meterTrackStyles = cva([\n 'relative col-span-2',\n 'h-sz-8 w-full',\n 'transform-gpu overflow-hidden',\n 'bg-on-background/dim-4',\n])\n\nexport type MeterTrackStylesProps = VariantProps<typeof meterTrackStyles>\n\nexport const meterIndicatorStyles = cva(\n ['size-full', 'ease-standard transition-[width] duration-700', 'motion-reduce:transition-none'],\n {\n variants: {\n /**\n * Color scheme of the meter component.\n */\n intent: {\n main: ['bg-main'],\n support: ['bg-support'],\n success: ['bg-success'],\n alert: ['bg-alert'],\n danger: ['bg-error'],\n info: ['bg-info'],\n },\n /**\n * Shape of the meter component.\n */\n shape: {\n square: [],\n rounded: ['rounded-sm'],\n },\n },\n }\n)\n\nexport type MeterIndicatorStylesProps = VariantProps<typeof meterIndicatorStyles>\n","import { RefObject, useEffect, useRef } from 'react'\n\nexport interface UseIntersectionAnimationOptions {\n /**\n * The threshold at which the callback should be triggered.\n * A value of 0 means as soon as any part of the element is visible.\n * A value of 1 means the entire element must be visible.\n * @default 0.1\n */\n threshold?: number\n /**\n * The root margin for the Intersection Observer.\n * This can be used to trigger the animation before the element enters the viewport.\n * @default undefined\n */\n rootMargin?: string\n}\n\n/**\n * Hook to trigger an animation callback when an element enters the viewport.\n * The callback is only triggered once, when the element first becomes visible.\n *\n * @param elementRef - Reference to the element to observe\n * @param onIntersect - Callback to execute when the element enters the viewport\n * @param options - Configuration options for the Intersection Observer\n * @returns Whether the animation has been triggered\n */\nexport function useIntersectionAnimation(\n elementRef: RefObject<Element | null>,\n onIntersect: () => void,\n options: UseIntersectionAnimationOptions = {}\n): boolean {\n const { threshold = 0.1, rootMargin } = options\n const hasTriggeredRef = useRef(false)\n const callbackRef = useRef(onIntersect)\n\n // Keep callback ref up to date\n useEffect(() => {\n callbackRef.current = onIntersect\n }, [onIntersect])\n\n useEffect(() => {\n const element = elementRef.current\n if (!element || hasTriggeredRef.current) return\n\n const observer = new IntersectionObserver(\n entries => {\n entries.forEach(entry => {\n if (entry.isIntersecting && !hasTriggeredRef.current) {\n // Use requestAnimationFrame to ensure the callback runs at the right time\n requestAnimationFrame(() => {\n if (!hasTriggeredRef.current) {\n hasTriggeredRef.current = true\n callbackRef.current()\n // Disconnect observer after callback is triggered (only trigger once)\n observer.disconnect()\n }\n })\n }\n })\n },\n {\n threshold,\n rootMargin,\n }\n )\n\n observer.observe(element)\n\n return () => {\n observer.disconnect()\n }\n }, [elementRef, threshold, rootMargin])\n\n return hasTriggeredRef.current\n}\n","import { Meter as BaseMeter } from '@base-ui/react/meter'\nimport { cx } from 'class-variance-authority'\nimport { ComponentProps, useRef, useState } from 'react'\n\nimport { useMeter } from './MeterContext'\nimport { meterIndicatorStyles, meterTrackStyles } from './MeterTrack.styles'\nimport { useIntersectionAnimation } from './useIntersectionAnimation'\n\nexport type MeterTrackProps = Omit<ComponentProps<typeof BaseMeter.Track>, 'render'>\n\n/**\n * The track of the meter showing progress. Renders a <div> element.\n */\nexport const MeterTrack = ({ className, ...others }: MeterTrackProps) => {\n const { value, max, min, intent, shape } = useMeter()\n const percentage = ((value - min) / (max - min)) * 100\n const trackRef = useRef<HTMLDivElement>(null)\n const [hasAnimated, setHasAnimated] = useState(false)\n\n // Trigger animation when component enters viewport\n useIntersectionAnimation(trackRef, () => {\n setHasAnimated(true)\n })\n\n return (\n <BaseMeter.Track\n ref={trackRef}\n data-spark-component=\"meter-track\"\n className={cx(meterTrackStyles(), { 'rounded-sm': shape === 'rounded' }, className)}\n {...others}\n >\n <BaseMeter.Indicator\n data-spark-component=\"meter-indicator\"\n className={meterIndicatorStyles({ intent, shape })}\n style={{\n width: hasAnimated ? `${percentage}%` : '0%',\n }}\n />\n </BaseMeter.Track>\n )\n}\n\nMeterTrack.displayName = 'Meter.Track'\n","import { Meter as BaseMeter } from '@base-ui/react/meter'\nimport { cx } from 'class-variance-authority'\nimport { ComponentProps, ReactNode } from 'react'\n\nexport type MeterValueProps = Omit<\n ComponentProps<typeof BaseMeter.Value>,\n 'render' | 'children'\n> & {\n children?: ((formattedValue: string, value: number) => ReactNode) | null | undefined\n}\n\n/**\n * The value display of the meter. Renders a <span> element.\n */\nexport const MeterValue = ({ className, children, ...others }: MeterValueProps) => {\n return (\n <BaseMeter.Value\n data-spark-component=\"meter-value\"\n className={cx('default:text-body-1 text-on-surface', 'col-start-2 text-right', className)}\n {...others}\n >\n {children}\n </BaseMeter.Value>\n )\n}\n\nMeterValue.displayName = 'Meter.Value'\n","import { Meter as Root } from './Meter'\nimport { MeterLabel } from './MeterLabel'\nimport { MeterTrack } from './MeterTrack'\nimport { MeterValue } from './MeterValue'\n\n/**\n * A horizontal progress indicator that displays a scalar measurement within a known range.\n */\nexport const Meter: typeof Root & {\n Label: typeof MeterLabel\n Track: typeof MeterTrack\n Value: typeof MeterValue\n} = Object.assign(Root, {\n Label: MeterLabel,\n Track: MeterTrack,\n Value: MeterValue,\n})\n\nMeter.displayName = 'Meter'\nMeterLabel.displayName = 'Meter.Label'\nMeterTrack.displayName = 'Meter.Track'\nMeterValue.displayName = 'Meter.Value'\n\nexport { type MeterProps } from './Meter'\nexport { type MeterLabelProps } from './MeterLabel'\nexport { type MeterTrackProps } from './MeterTrack'\nexport { type MeterValueProps } from './MeterValue'\n"],"mappings":"6QAaA,IAAa,GAAA,EAAA,EAAA,eAAuD,KAAK,CAE5D,EAAY,SAEZ,MAAiB,CAC5B,IAAM,GAAA,EAAA,EAAA,YAAqB,EAAa,CAExC,GAAI,CAAC,EACH,MAAU,MAAM,gDAAgD,CAGlE,OAAO,GCFI,GAAS,CACpB,YACA,QACA,MAAM,IACN,MAAM,EACN,QAAQ,UACR,SAAS,UACT,WACA,MACA,GAAG,KACgC,CACnC,GAAM,CAAC,EAAS,IAAA,EAAA,EAAA,WAAgC,CAahD,OACE,EAAA,EAAA,KAAC,EAAD,CAAc,OAAA,EAAA,EAAA,cAXP,CACL,MAAO,GAAS,EAChB,MACA,MACA,SACA,QACA,UAAW,EACZ,EACA,CAAC,EAAK,EAAK,EAAO,EAAQ,EAAO,EAAW,CAAC,WAI5C,EAAA,EAAA,KAAC,EAAA,MAAU,KAAX,CACE,uBAAqB,QAChB,MACL,WAAA,EAAA,EAAA,IACE,iFACA,EACD,CACM,QACF,MACA,MACL,kBAAiB,EACjB,GAAI,EAEH,WACc,CAAA,CACJ,CAAA,EAInB,EAAM,YAAc,QCxDpB,IAAa,GAAc,CACzB,GAAI,EACJ,WACA,IAAK,E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= n(null), m = ":meter", h = () => {
|
|
|
9
9
|
if (!e) throw Error("useMeter must be used within a Meter provider");
|
|
10
10
|
return e;
|
|
11
11
|
}, g = ({ className: e, value: n, max: r = 100, min: i = 0, shape: a = "rounded", intent: o = "support", children: c, ref: d, ...m }) => {
|
|
12
|
-
let [h, g] = l()
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
12
|
+
let [h, g] = l();
|
|
13
|
+
return /* @__PURE__ */ u(p, {
|
|
14
|
+
value: s(() => ({
|
|
15
|
+
value: n ?? 0,
|
|
16
|
+
max: r,
|
|
17
|
+
min: i,
|
|
18
|
+
intent: o,
|
|
19
|
+
shape: a,
|
|
20
|
+
onLabelId: g
|
|
21
|
+
}), [
|
|
22
|
+
r,
|
|
23
|
+
i,
|
|
24
|
+
n,
|
|
25
|
+
o,
|
|
26
|
+
a,
|
|
27
|
+
g
|
|
28
|
+
]),
|
|
29
29
|
children: /* @__PURE__ */ u(f.Root, {
|
|
30
30
|
"data-spark-component": "meter",
|
|
31
31
|
ref: d,
|
package/dist/meter/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/meter/MeterContext.tsx","../../src/meter/Meter.tsx","../../src/meter/MeterLabel.tsx","../../src/meter/MeterTrack.styles.ts","../../src/meter/useIntersectionAnimation.ts","../../src/meter/MeterTrack.tsx","../../src/meter/MeterValue.tsx","../../src/meter/index.ts"],"sourcesContent":["import { createContext, useContext } from 'react'\n\nimport { MeterIndicatorStylesProps } from './MeterTrack.styles'\n\nexport interface MeterContextValue {\n value: number\n max: number\n min: number\n intent: MeterIndicatorStylesProps['intent']\n shape: 'square' | 'rounded'\n onLabelId: (id?: string) => void\n}\n\nexport const MeterContext = createContext<MeterContextValue | null>(null)\n\nexport const ID_PREFIX = ':meter'\n\nexport const useMeter = () => {\n const context = useContext(MeterContext)\n\n if (!context) {\n throw new Error('useMeter must be used within a Meter provider')\n }\n\n return context\n}\n","import { Meter as BaseMeter } from '@base-ui/react/meter'\nimport { cx } from 'class-variance-authority'\nimport { ComponentProps, PropsWithChildren, Ref, useMemo, useState } from 'react'\n\nimport { MeterContext } from './MeterContext'\nimport { MeterIndicatorStylesProps } from './MeterTrack.styles'\n\nexport interface MeterProps\n extends\n Omit<ComponentProps<typeof BaseMeter.Root>, 'render'>,\n Pick<MeterIndicatorStylesProps, 'intent'> {\n /**\n * Shape of the meter track and indicator.\n */\n shape?: 'square' | 'rounded'\n /**\n * Change the default rendered element for the one passed as a child, merging their props and behavior.\n */\n asChild?: boolean\n ref?: Ref<HTMLDivElement>\n}\n\nexport const Meter = ({\n className,\n value,\n max = 100,\n min = 0,\n shape = 'rounded',\n intent = 'support',\n children,\n ref,\n ...others\n}: PropsWithChildren<MeterProps>) => {\n const [labelId, setLabelId] = useState<string>()\n\n const contextValue = useMemo(() => {\n return {\n value: value ?? 0,\n max,\n min,\n intent,\n shape,\n onLabelId: setLabelId,\n }\n }, [max, min, value, intent, shape, setLabelId])\n\n return (\n <MeterContext.Provider value={contextValue}>\n <BaseMeter.Root\n data-spark-component=\"meter\"\n ref={ref}\n className={cx(\n 'gap-y-sm gap-x-md focus-visible:u-outline box-border grid grid-cols-[1fr_auto]',\n className\n )}\n value={value}\n max={max}\n min={min}\n aria-labelledby={labelId}\n {...others}\n >\n {children}\n </BaseMeter.Root>\n </MeterContext.Provider>\n )\n}\n\nMeter.displayName = 'Meter'\n","import { Meter as BaseMeter } from '@base-ui/react/meter'\nimport { useMergeRefs } from '@spark-ui/hooks/use-merge-refs'\nimport { ComponentProps, useCallback, useId } from 'react'\n\nimport { ID_PREFIX, useMeter } from './MeterContext'\n\nexport type MeterLabelProps = Omit<ComponentProps<typeof BaseMeter.Label>, 'render'>\n\n/**\n * The label of the meter, announced to assistive technology. Renders a <span> element.\n */\nexport const MeterLabel = ({\n id: idProp,\n children,\n ref: forwardedRef,\n ...others\n}: MeterLabelProps) => {\n const internalID = `${ID_PREFIX}-label-${useId()}`\n const id = idProp || internalID\n\n const { onLabelId } = useMeter()\n const rootRef = useCallback(\n (el: HTMLSpanElement) => {\n onLabelId(el ? id : undefined)\n },\n [id, onLabelId]\n )\n const ref = useMergeRefs(forwardedRef, rootRef)\n\n return (\n <BaseMeter.Label\n data-spark-component=\"meter-label\"\n id={id}\n className=\"default:text-body-1-highlight text-on-surface\"\n ref={ref}\n {...others}\n >\n {children}\n </BaseMeter.Label>\n )\n}\n\nMeterLabel.displayName = 'Meter.Label'\n","import { cva, VariantProps } from 'class-variance-authority'\n\nexport const meterTrackStyles = cva([\n 'relative col-span-2',\n 'h-sz-8 w-full',\n 'transform-gpu overflow-hidden',\n 'bg-on-background/dim-4',\n])\n\nexport type MeterTrackStylesProps = VariantProps<typeof meterTrackStyles>\n\nexport const meterIndicatorStyles = cva(\n ['size-full', 'ease-standard transition-[width] duration-700', 'motion-reduce:transition-none'],\n {\n variants: {\n /**\n * Color scheme of the meter component.\n */\n intent: {\n main: ['bg-main'],\n support: ['bg-support'],\n success: ['bg-success'],\n alert: ['bg-alert'],\n danger: ['bg-error'],\n info: ['bg-info'],\n },\n /**\n * Shape of the meter component.\n */\n shape: {\n square: [],\n rounded: ['rounded-sm'],\n },\n },\n }\n)\n\nexport type MeterIndicatorStylesProps = VariantProps<typeof meterIndicatorStyles>\n","import { RefObject, useEffect, useRef } from 'react'\n\nexport interface UseIntersectionAnimationOptions {\n /**\n * The threshold at which the callback should be triggered.\n * A value of 0 means as soon as any part of the element is visible.\n * A value of 1 means the entire element must be visible.\n * @default 0.1\n */\n threshold?: number\n /**\n * The root margin for the Intersection Observer.\n * This can be used to trigger the animation before the element enters the viewport.\n * @default undefined\n */\n rootMargin?: string\n}\n\n/**\n * Hook to trigger an animation callback when an element enters the viewport.\n * The callback is only triggered once, when the element first becomes visible.\n *\n * @param elementRef - Reference to the element to observe\n * @param onIntersect - Callback to execute when the element enters the viewport\n * @param options - Configuration options for the Intersection Observer\n * @returns Whether the animation has been triggered\n */\nexport function useIntersectionAnimation(\n elementRef: RefObject<Element | null>,\n onIntersect: () => void,\n options: UseIntersectionAnimationOptions = {}\n): boolean {\n const { threshold = 0.1, rootMargin } = options\n const hasTriggeredRef = useRef(false)\n const callbackRef = useRef(onIntersect)\n\n // Keep callback ref up to date\n useEffect(() => {\n callbackRef.current = onIntersect\n }, [onIntersect])\n\n useEffect(() => {\n const element = elementRef.current\n if (!element || hasTriggeredRef.current) return\n\n const observer = new IntersectionObserver(\n entries => {\n entries.forEach(entry => {\n if (entry.isIntersecting && !hasTriggeredRef.current) {\n // Use requestAnimationFrame to ensure the callback runs at the right time\n requestAnimationFrame(() => {\n if (!hasTriggeredRef.current) {\n hasTriggeredRef.current = true\n callbackRef.current()\n // Disconnect observer after callback is triggered (only trigger once)\n observer.disconnect()\n }\n })\n }\n })\n },\n {\n threshold,\n rootMargin,\n }\n )\n\n observer.observe(element)\n\n return () => {\n observer.disconnect()\n }\n }, [elementRef, threshold, rootMargin])\n\n return hasTriggeredRef.current\n}\n","import { Meter as BaseMeter } from '@base-ui/react/meter'\nimport { cx } from 'class-variance-authority'\nimport { ComponentProps, useRef, useState } from 'react'\n\nimport { useMeter } from './MeterContext'\nimport { meterIndicatorStyles, meterTrackStyles } from './MeterTrack.styles'\nimport { useIntersectionAnimation } from './useIntersectionAnimation'\n\nexport type MeterTrackProps = Omit<ComponentProps<typeof BaseMeter.Track>, 'render'>\n\n/**\n * The track of the meter showing progress. Renders a <div> element.\n */\nexport const MeterTrack = ({ className, ...others }: MeterTrackProps) => {\n const { value, max, min, intent, shape } = useMeter()\n const percentage = ((value - min) / (max - min)) * 100\n const trackRef = useRef<HTMLDivElement>(null)\n const [hasAnimated, setHasAnimated] = useState(false)\n\n // Trigger animation when component enters viewport\n useIntersectionAnimation(trackRef, () => {\n setHasAnimated(true)\n })\n\n return (\n <BaseMeter.Track\n ref={trackRef}\n data-spark-component=\"meter-track\"\n className={cx(meterTrackStyles(), { 'rounded-sm': shape === 'rounded' }, className)}\n {...others}\n >\n <BaseMeter.Indicator\n data-spark-component=\"meter-indicator\"\n className={meterIndicatorStyles({ intent, shape })}\n style={{\n width: hasAnimated ? `${percentage}%` : '0%',\n }}\n />\n </BaseMeter.Track>\n )\n}\n\nMeterTrack.displayName = 'Meter.Track'\n","import { Meter as BaseMeter } from '@base-ui/react/meter'\nimport { cx } from 'class-variance-authority'\nimport { ComponentProps, ReactNode } from 'react'\n\nexport type MeterValueProps = Omit<\n ComponentProps<typeof BaseMeter.Value>,\n 'render' | 'children'\n> & {\n children?: ((formattedValue: string, value: number) => ReactNode) | null | undefined\n}\n\n/**\n * The value display of the meter. Renders a <span> element.\n */\nexport const MeterValue = ({ className, children, ...others }: MeterValueProps) => {\n return (\n <BaseMeter.Value\n data-spark-component=\"meter-value\"\n className={cx('default:text-body-1 text-on-surface', 'col-start-2 text-right', className)}\n {...others}\n >\n {children}\n </BaseMeter.Value>\n )\n}\n\nMeterValue.displayName = 'Meter.Value'\n","import { Meter as Root } from './Meter'\nimport { MeterLabel } from './MeterLabel'\nimport { MeterTrack } from './MeterTrack'\nimport { MeterValue } from './MeterValue'\n\n/**\n * A horizontal progress indicator that displays a scalar measurement within a known range.\n */\nexport const Meter: typeof Root & {\n Label: typeof MeterLabel\n Track: typeof MeterTrack\n Value: typeof MeterValue\n} = Object.assign(Root, {\n Label: MeterLabel,\n Track: MeterTrack,\n Value: MeterValue,\n})\n\nMeter.displayName = 'Meter'\nMeterLabel.displayName = 'Meter.Label'\nMeterTrack.displayName = 'Meter.Track'\nMeterValue.displayName = 'Meter.Value'\n\nexport { type MeterProps } from './Meter'\nexport { type MeterLabelProps } from './MeterLabel'\nexport { type MeterTrackProps } from './MeterTrack'\nexport { type MeterValueProps } from './MeterValue'\n"],"m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AO,EACL,OAAO,IAAc,GAAG,EAAW,KAAK,MACzC;GACD,CAAA;EACc,CAAA;;AAItB,EAAW,cAAc;;;AC5BzB,IAAa,KAAc,EAAE,cAAW,aAAU,GAAG,QAEjD,kBAAC,EAAU,OAAX;CACE,wBAAqB;CACrB,WAAW,EAAG,uCAAuC,0BAA0B,EAAU;CACzF,GAAI;CAEH;CACe,CAAA;AAItB,EAAW,cAAc;;;AClBzB,IAAa,IAIT,OAAO,OAAO,GAAM;CACtB,OAAO;CACP,OAAO;CACP,OAAO;CACR,CAAC;AAEF,EAAM,cAAc,SACpB,EAAW,cAAc,eACzB,EAAW,cAAc,eACzB,EAAW,cAAc"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/meter/MeterContext.tsx","../../src/meter/Meter.tsx","../../src/meter/MeterLabel.tsx","../../src/meter/MeterTrack.styles.ts","../../src/meter/useIntersectionAnimation.ts","../../src/meter/MeterTrack.tsx","../../src/meter/MeterValue.tsx","../../src/meter/index.ts"],"sourcesContent":["import { createContext, useContext } from 'react'\n\nimport { MeterIndicatorStylesProps } from './MeterTrack.styles'\n\nexport interface MeterContextValue {\n value: number\n max: number\n min: number\n intent: MeterIndicatorStylesProps['intent']\n shape: 'square' | 'rounded'\n onLabelId: (id?: string) => void\n}\n\nexport const MeterContext = createContext<MeterContextValue | null>(null)\n\nexport const ID_PREFIX = ':meter'\n\nexport const useMeter = () => {\n const context = useContext(MeterContext)\n\n if (!context) {\n throw new Error('useMeter must be used within a Meter provider')\n }\n\n return context\n}\n","import { Meter as BaseMeter } from '@base-ui/react/meter'\nimport { cx } from 'class-variance-authority'\nimport { ComponentProps, PropsWithChildren, Ref, useMemo, useState } from 'react'\n\nimport { MeterContext } from './MeterContext'\nimport { MeterIndicatorStylesProps } from './MeterTrack.styles'\n\nexport interface MeterProps\n extends\n Omit<ComponentProps<typeof BaseMeter.Root>, 'render'>,\n Pick<MeterIndicatorStylesProps, 'intent'> {\n /**\n * Shape of the meter track and indicator.\n */\n shape?: 'square' | 'rounded'\n /**\n * Change the default rendered element for the one passed as a child, merging their props and behavior.\n */\n asChild?: boolean\n ref?: Ref<HTMLDivElement>\n}\n\nexport const Meter = ({\n className,\n value,\n max = 100,\n min = 0,\n shape = 'rounded',\n intent = 'support',\n children,\n ref,\n ...others\n}: PropsWithChildren<MeterProps>) => {\n const [labelId, setLabelId] = useState<string>()\n\n const contextValue = useMemo(() => {\n return {\n value: value ?? 0,\n max,\n min,\n intent,\n shape,\n onLabelId: setLabelId,\n }\n }, [max, min, value, intent, shape, setLabelId])\n\n return (\n <MeterContext value={contextValue}>\n <BaseMeter.Root\n data-spark-component=\"meter\"\n ref={ref}\n className={cx(\n 'gap-y-sm gap-x-md focus-visible:u-outline box-border grid grid-cols-[1fr_auto]',\n className\n )}\n value={value}\n max={max}\n min={min}\n aria-labelledby={labelId}\n {...others}\n >\n {children}\n </BaseMeter.Root>\n </MeterContext>\n )\n}\n\nMeter.displayName = 'Meter'\n","import { Meter as BaseMeter } from '@base-ui/react/meter'\nimport { useMergeRefs } from '@spark-ui/hooks/use-merge-refs'\nimport { ComponentProps, useCallback, useId } from 'react'\n\nimport { ID_PREFIX, useMeter } from './MeterContext'\n\nexport type MeterLabelProps = Omit<ComponentProps<typeof BaseMeter.Label>, 'render'>\n\n/**\n * The label of the meter, announced to assistive technology. Renders a <span> element.\n */\nexport const MeterLabel = ({\n id: idProp,\n children,\n ref: forwardedRef,\n ...others\n}: MeterLabelProps) => {\n const internalID = `${ID_PREFIX}-label-${useId()}`\n const id = idProp || internalID\n\n const { onLabelId } = useMeter()\n const rootRef = useCallback(\n (el: HTMLSpanElement) => {\n onLabelId(el ? id : undefined)\n },\n [id, onLabelId]\n )\n const ref = useMergeRefs(forwardedRef, rootRef)\n\n return (\n <BaseMeter.Label\n data-spark-component=\"meter-label\"\n id={id}\n className=\"default:text-body-1-highlight text-on-surface\"\n ref={ref}\n {...others}\n >\n {children}\n </BaseMeter.Label>\n )\n}\n\nMeterLabel.displayName = 'Meter.Label'\n","import { cva, VariantProps } from 'class-variance-authority'\n\nexport const meterTrackStyles = cva([\n 'relative col-span-2',\n 'h-sz-8 w-full',\n 'transform-gpu overflow-hidden',\n 'bg-on-background/dim-4',\n])\n\nexport type MeterTrackStylesProps = VariantProps<typeof meterTrackStyles>\n\nexport const meterIndicatorStyles = cva(\n ['size-full', 'ease-standard transition-[width] duration-700', 'motion-reduce:transition-none'],\n {\n variants: {\n /**\n * Color scheme of the meter component.\n */\n intent: {\n main: ['bg-main'],\n support: ['bg-support'],\n success: ['bg-success'],\n alert: ['bg-alert'],\n danger: ['bg-error'],\n info: ['bg-info'],\n },\n /**\n * Shape of the meter component.\n */\n shape: {\n square: [],\n rounded: ['rounded-sm'],\n },\n },\n }\n)\n\nexport type MeterIndicatorStylesProps = VariantProps<typeof meterIndicatorStyles>\n","import { RefObject, useEffect, useRef } from 'react'\n\nexport interface UseIntersectionAnimationOptions {\n /**\n * The threshold at which the callback should be triggered.\n * A value of 0 means as soon as any part of the element is visible.\n * A value of 1 means the entire element must be visible.\n * @default 0.1\n */\n threshold?: number\n /**\n * The root margin for the Intersection Observer.\n * This can be used to trigger the animation before the element enters the viewport.\n * @default undefined\n */\n rootMargin?: string\n}\n\n/**\n * Hook to trigger an animation callback when an element enters the viewport.\n * The callback is only triggered once, when the element first becomes visible.\n *\n * @param elementRef - Reference to the element to observe\n * @param onIntersect - Callback to execute when the element enters the viewport\n * @param options - Configuration options for the Intersection Observer\n * @returns Whether the animation has been triggered\n */\nexport function useIntersectionAnimation(\n elementRef: RefObject<Element | null>,\n onIntersect: () => void,\n options: UseIntersectionAnimationOptions = {}\n): boolean {\n const { threshold = 0.1, rootMargin } = options\n const hasTriggeredRef = useRef(false)\n const callbackRef = useRef(onIntersect)\n\n // Keep callback ref up to date\n useEffect(() => {\n callbackRef.current = onIntersect\n }, [onIntersect])\n\n useEffect(() => {\n const element = elementRef.current\n if (!element || hasTriggeredRef.current) return\n\n const observer = new IntersectionObserver(\n entries => {\n entries.forEach(entry => {\n if (entry.isIntersecting && !hasTriggeredRef.current) {\n // Use requestAnimationFrame to ensure the callback runs at the right time\n requestAnimationFrame(() => {\n if (!hasTriggeredRef.current) {\n hasTriggeredRef.current = true\n callbackRef.current()\n // Disconnect observer after callback is triggered (only trigger once)\n observer.disconnect()\n }\n })\n }\n })\n },\n {\n threshold,\n rootMargin,\n }\n )\n\n observer.observe(element)\n\n return () => {\n observer.disconnect()\n }\n }, [elementRef, threshold, rootMargin])\n\n return hasTriggeredRef.current\n}\n","import { Meter as BaseMeter } from '@base-ui/react/meter'\nimport { cx } from 'class-variance-authority'\nimport { ComponentProps, useRef, useState } from 'react'\n\nimport { useMeter } from './MeterContext'\nimport { meterIndicatorStyles, meterTrackStyles } from './MeterTrack.styles'\nimport { useIntersectionAnimation } from './useIntersectionAnimation'\n\nexport type MeterTrackProps = Omit<ComponentProps<typeof BaseMeter.Track>, 'render'>\n\n/**\n * The track of the meter showing progress. Renders a <div> element.\n */\nexport const MeterTrack = ({ className, ...others }: MeterTrackProps) => {\n const { value, max, min, intent, shape } = useMeter()\n const percentage = ((value - min) / (max - min)) * 100\n const trackRef = useRef<HTMLDivElement>(null)\n const [hasAnimated, setHasAnimated] = useState(false)\n\n // Trigger animation when component enters viewport\n useIntersectionAnimation(trackRef, () => {\n setHasAnimated(true)\n })\n\n return (\n <BaseMeter.Track\n ref={trackRef}\n data-spark-component=\"meter-track\"\n className={cx(meterTrackStyles(), { 'rounded-sm': shape === 'rounded' }, className)}\n {...others}\n >\n <BaseMeter.Indicator\n data-spark-component=\"meter-indicator\"\n className={meterIndicatorStyles({ intent, shape })}\n style={{\n width: hasAnimated ? `${percentage}%` : '0%',\n }}\n />\n </BaseMeter.Track>\n )\n}\n\nMeterTrack.displayName = 'Meter.Track'\n","import { Meter as BaseMeter } from '@base-ui/react/meter'\nimport { cx } from 'class-variance-authority'\nimport { ComponentProps, ReactNode } from 'react'\n\nexport type MeterValueProps = Omit<\n ComponentProps<typeof BaseMeter.Value>,\n 'render' | 'children'\n> & {\n children?: ((formattedValue: string, value: number) => ReactNode) | null | undefined\n}\n\n/**\n * The value display of the meter. Renders a <span> element.\n */\nexport const MeterValue = ({ className, children, ...others }: MeterValueProps) => {\n return (\n <BaseMeter.Value\n data-spark-component=\"meter-value\"\n className={cx('default:text-body-1 text-on-surface', 'col-start-2 text-right', className)}\n {...others}\n >\n {children}\n </BaseMeter.Value>\n )\n}\n\nMeterValue.displayName = 'Meter.Value'\n","import { Meter as Root } from './Meter'\nimport { MeterLabel } from './MeterLabel'\nimport { MeterTrack } from './MeterTrack'\nimport { MeterValue } from './MeterValue'\n\n/**\n * A horizontal progress indicator that displays a scalar measurement within a known range.\n */\nexport const Meter: typeof Root & {\n Label: typeof MeterLabel\n Track: typeof MeterTrack\n Value: typeof MeterValue\n} = Object.assign(Root, {\n Label: MeterLabel,\n Track: MeterTrack,\n Value: MeterValue,\n})\n\nMeter.displayName = 'Meter'\nMeterLabel.displayName = 'Meter.Label'\nMeterTrack.displayName = 'Meter.Track'\nMeterValue.displayName = 'Meter.Value'\n\nexport { type MeterProps } from './Meter'\nexport { type MeterLabelProps } from './MeterLabel'\nexport { type MeterTrackProps } from './MeterTrack'\nexport { type MeterValueProps } from './MeterValue'\n"],"mappings":";;;;;;AAaA,IAAa,IAAe,EAAwC,KAAK,EAE5D,IAAY,UAEZ,UAAiB;CAC5B,IAAM,IAAU,EAAW,EAAa;AAExC,KAAI,CAAC,EACH,OAAU,MAAM,gDAAgD;AAGlE,QAAO;GCFI,KAAS,EACpB,cACA,UACA,SAAM,KACN,SAAM,GACN,WAAQ,WACR,YAAS,WACT,aACA,QACA,GAAG,QACgC;CACnC,IAAM,CAAC,GAAS,KAAc,GAAkB;AAahD,QACE,kBAAC,GAAD;EAAc,OAZK,SACZ;GACL,OAAO,KAAS;GAChB;GACA;GACA;GACA;GACA,WAAW;GACZ,GACA;GAAC;GAAK;GAAK;GAAO;GAAQ;GAAO;GAAW,CAAC;Y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@@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../chunk-C91j1N6u.js`),t=require(`../icon-CRPcdgYp.js`),n=require(`../button-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../chunk-C91j1N6u.js`),t=require(`../icon-CRPcdgYp.js`),n=require(`../button-Tv2N8_24.js`),r=require(`../icon-button-CTe0v0g7.js`);let i=require(`class-variance-authority`),a=require(`react`),o=require(`react/jsx-runtime`),s=require(`@spark-ui/icons/ArrowVerticalRight`),c=require(`@spark-ui/icons/ArrowVerticalLeft`),l=require(`@zag-js/pagination`);l=e.t(l);let u=require(`@zag-js/react`),d=require(`@spark-ui/icons/ArrowDoubleLeft`),f=require(`@spark-ui/icons/ArrowDoubleRight`);function p(e,t,n){let r=(n-1)/2,i=Math.max(0,t-r),a=Math.min(e.length,t+r+1);return a-i<n&&(i=Math.max(0,Math.min(i,e.length-n)),a=Math.min(e.length,i+n)),e.slice(i,a)}var m=(0,a.createContext)(null),h=({children:e,count:t,visiblePageItems:n=7,pageSize:r,page:i,onPageChange:s,noEllipsis:c,type:d=`link`})=>{let f=c?1/0:Math.max(0,Math.floor((n-5)/2)),h=(0,a.useId)(),g=(0,u.useMachine)(l.machine,{id:h,count:t,siblingCount:f,pageSize:r,page:i,onPageChange:s,type:d}),_=l.connect(g,u.normalizeProps),v=c?p(_.pages,_.page-1,n):_.pages;return(0,o.jsx)(m,{value:{type:d,pagination:{..._,pages:v,getFirstPageTriggerProps:()=>({..._.getPrevTriggerProps(),id:`${_.getRootProps().id}:first`,"data-part":`first-page-trigger`,onClick:_.goToFirstPage}),getLastPageTriggerProps:()=>({..._.getNextTriggerProps(),id:`${_.getRootProps().id}:last`,"data-part":`last-page-trigger`,onClick:_.goToLastPage})}},children:e})},g=()=>{let e=(0,a.useContext)(m);if(!e)throw Error(`usePagination must be used within a Pagination provider`);return e},_=({children:e,visiblePageItems:t=5,type:n=`link`,noEllipsis:r=!1,className:i,...a})=>(0,o.jsx)(h,{visiblePageItems:t,noEllipsis:r,type:n,...a,children:(0,o.jsx)(v,{className:i,children:e})}),v=({children:e,className:t})=>{let{pagination:n}=g();return(0,o.jsx)(`nav`,{"data-spark-component":`pagination`,...n.getRootProps(),className:t,children:(0,o.jsx)(`ul`,{className:`gap-md flex flex-wrap`,children:e})})};_.displayName=`Pagination`;var y=({children:e,index:t,className:n,ref:r,...a})=>{let{pagination:s}=g();return(0,o.jsx)(`li`,{children:(0,o.jsx)(`span`,{"data-spark-component":`pagination-ellipsis`,ref:r,...(0,u.mergeProps)(s.getEllipsisProps({index:t}),{className:(0,i.cx)(`flex size-sz-44 items-center justify-center`,n),...a}),children:e||`…`})})};y.displayName=`Pagination.Ellipsis`;var b=({children:e,className:n,href:i,ref:a,...s})=>{let{pagination:c,type:l}=g(),f=c.getFirstPageTriggerProps(),p=l===`link`&&f[`data-disabled`]===``,m=(0,u.mergeProps)(f,{"data-spark-component":`pagination-first-page-trigger`,intent:`support`,design:`contrast`,...s,className:n,...p&&{disabled:!0,role:`link`,"aria-disabled":!0}}),h=e||(0,o.jsx)(t.t,{children:(0,o.jsx)(d.ArrowDoubleLeft,{})});return(0,o.jsx)(`li`,{children:i?(0,o.jsx)(r.t,{ref:a,...m,asChild:!0,children:(0,o.jsx)(`a`,{href:p?void 0:i,children:h})}):(0,o.jsx)(r.t,{ref:a,...m,children:h})})};b.displayName=`Pagination.FirstPageTrigger`;function x({children:e,value:t,className:r,href:a,ref:s,...c}){let{pagination:l}=g(),d=l.getItemProps({type:`page`,value:t}),f=(0,u.mergeProps)(d,{"data-spark-component":`pagination-item`,intent:`support`,design:d[`aria-current`]===`page`?`filled`:`contrast`,className:(0,i.cx)(`size-sz-44`,r),...c});return(0,o.jsx)(`li`,{children:a?(0,o.jsx)(n.t,{ref:s,...f,asChild:!0,children:(0,o.jsx)(`a`,{href:a,children:e||t})}):(0,o.jsx)(n.t,{ref:s,...f,children:e||t})})}x.displayName=`Pagination.Item`;var S=({children:e,className:n,href:i,ref:a,...s})=>{let{pagination:c,type:l}=g(),d=c.getLastPageTriggerProps(),p=l===`link`&&d[`data-disabled`]===``,m=(0,u.mergeProps)(d,{"data-spark-component":`pagination-last-page-trigger`,intent:`support`,design:`contrast`,...s,className:n,...p&&{disabled:!0,role:`link`,"aria-disabled":!0}}),h=e||(0,o.jsx)(t.t,{children:(0,o.jsx)(f.ArrowDoubleRight,{})});return(0,o.jsx)(`li`,{children:i?(0,o.jsx)(r.t,{ref:a,...m,asChild:!0,children:(0,o.jsx)(`a`,{href:p?void 0:i,children:h})}):(0,o.jsx)(r.t,{ref:a,...m,children:h})})};S.displayName=`Pagination.LastPageTrigger`;var C=({children:e,className:n,href:i,ref:a,...c})=>{let{pagination:l,type:d}=g(),f=l.getNextTriggerProps(),p=d===`link`&&f[`data-disabled`]===``,m=(0,u.mergeProps)(f,{"data-spark-component":`pagination-next-trigger`,intent:`support`,design:`contrast`,...c,className:n,...p&&{disabled:!0,role:`link`,"aria-disabled":!0}}),h=e||(0,o.jsx)(t.t,{children:(0,o.jsx)(s.ArrowVerticalRight,{})});return(0,o.jsx)(`li`,{children:i?(0,o.jsx)(r.t,{ref:a,...m,asChild:!0,children:(0,o.jsx)(`a`,{href:p?void 0:i,children:h})}):(0,o.jsx)(r.t,{ref:a,...m,children:h})})};C.displayName=`Pagination.NextTrigger`;var w=({children:e})=>{let{pagination:t}=g();return e(t)};w.displayName=`Pagination.Pages`;var T=({children:e,className:n,href:i,ref:a,...s})=>{let{pagination:l,type:d}=g(),f=l.getPrevTriggerProps(),p=d===`link`&&f[`data-disabled`]===``,m=(0,u.mergeProps)(f,{"data-spark-component":`pagination-prev-trigger`,intent:`support`,design:`contrast`,...s,className:n,...p&&{disabled:!0,role:`link`,"aria-disabled":!0}}),h=e||(0,o.jsx)(t.t,{children:(0,o.jsx)(c.ArrowVerticalLeft,{})});return(0,o.jsx)(`li`,{children:i?(0,o.jsx)(r.t,{ref:a,...m,asChild:!0,children:(0,o.jsx)(`a`,{href:p?void 0:i,children:h})}):(0,o.jsx)(r.t,{ref:a,...m,children:h})})};T.displayName=`Pagination.PrevTrigger`;var E=Object.assign(_,{PrevTrigger:T,NextTrigger:C,Pages:w,Item:x,Ellipsis:y,FirstPageTrigger:b,LastPageTrigger:S});E.displayName=`Pagination`,T.displayName=`Pagination.PrevTrigger`,C.displayName=`Pagination.NextTrigger`,w.displayName=`Pagination.Pages`,x.displayName=`Pagination.Item`,y.displayName=`Pagination.Ellipsis`,b.displayName=`Pagination.FirstPageTrigger`,S.displayName=`Pagination.LastPageTrigger`,exports.Pagination=E;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/pagination/utils.ts","../../src/pagination/PaginationContext.tsx","../../src/pagination/Pagination.tsx","../../src/pagination/PaginationEllipsis.tsx","../../src/pagination/PaginationFirstPageTrigger.tsx","../../src/pagination/PaginationItem.tsx","../../src/pagination/PaginationLastPageTrigger.tsx","../../src/pagination/PaginationNextTrigger.tsx","../../src/pagination/PaginationPages.tsx","../../src/pagination/PaginationPrevTrigger.tsx","../../src/pagination/index.ts"],"sourcesContent":["export function sliceArrayWithIndex(arr: any[], index: number, length: number) {\n const relativeElements = (length - 1) / 2\n\n let start = Math.max(0, index - relativeElements)\n let end = Math.min(arr.length, index + relativeElements + 1)\n\n if (end - start < length) {\n start = Math.max(0, Math.min(start, arr.length - length))\n end = Math.min(arr.length, start + length)\n }\n\n return arr.slice(start, end)\n}\n","import * as pagination from '@zag-js/pagination'\nimport { normalizeProps, type PropTypes, useMachine } from '@zag-js/react'\nimport { createContext, type ReactNode, useContext, useId } from 'react'\n\nimport { sliceArrayWithIndex } from './utils'\n\nexport interface PaginationContextState<T extends PropTypes = PropTypes> {\n type: pagination.Props['type']\n pagination: pagination.Api<T> & {\n getFirstPageTriggerProps: () => ReturnType<pagination.Api<T>['getPrevTriggerProps']> & {\n 'data-part': string\n onClick: () => void\n }\n getLastPageTriggerProps: () => ReturnType<pagination.Api<T>['getNextTriggerProps']> & {\n 'data-part': string\n onClick: () => void\n }\n }\n}\n\nconst PaginationContext = createContext<PaginationContextState | null>(null)\n\nexport interface PaginationProviderProps {\n children: ReactNode\n /**\n * Total number of data items available across all pages.\n */\n count: number\n /**\n * Maximum amount of items displayed on a single page.\n */\n pageSize: number\n /**\n * Number of visible pages (or ellipsis) between previous and next page triggers.\n */\n visiblePageItems?: number\n /**\n * The current page (active page)\n */\n page?: pagination.Props['page']\n /**\n * If your pagination contains buttons instead of links, set `type` to `button`, extra attributes will be applied on page items for a11y.\n */\n type?: pagination.Props['type']\n onPageChange?: pagination.Props['onPageChange']\n noEllipsis?: boolean\n}\n\nexport const PaginationProvider = ({\n children,\n count,\n visiblePageItems = 7,\n pageSize,\n page,\n onPageChange,\n noEllipsis,\n type = 'link',\n}: PaginationProviderProps) => {\n /**\n * Here `Infinity` is used because we apply a custom slice ourselves to manage the \"no ellipsis\" version.\n * It means Zag won't filter out any page item, allowing us to apply our own slicing logic.\n */\n const siblingCount = noEllipsis ? Infinity : Math.max(0, Math.floor((visiblePageItems - 5) / 2))\n\n const id = useId()\n\n const service = useMachine(pagination.machine, {\n id,\n count,\n siblingCount,\n pageSize,\n page,\n onPageChange,\n type,\n })\n\n const api = pagination.connect(service, normalizeProps)\n const pages = noEllipsis\n ? sliceArrayWithIndex(api.pages, api.page - 1, visiblePageItems)\n : api.pages\n\n return (\n <PaginationContext.Provider\n value={{\n type,\n pagination: {\n ...api,\n pages,\n // Extending ZagJS anatomy\n getFirstPageTriggerProps: () => {\n return {\n ...api.getPrevTriggerProps(),\n id: `${api.getRootProps().id}:first`,\n 'data-part': 'first-page-trigger',\n onClick: api.goToFirstPage,\n }\n },\n getLastPageTriggerProps: () => {\n return {\n ...api.getNextTriggerProps(),\n id: `${api.getRootProps().id}:last`,\n 'data-part': 'last-page-trigger',\n onClick: api.goToLastPage,\n }\n },\n },\n }}\n >\n {children}\n </PaginationContext.Provider>\n )\n}\n\nexport const usePagination = () => {\n const context = useContext(PaginationContext)\n\n if (!context) {\n throw Error('usePagination must be used within a Pagination provider')\n }\n\n return context\n}\n","import { ReactNode } from 'react'\n\nimport {\n PaginationProvider,\n type PaginationProviderProps,\n usePagination,\n} from './PaginationContext'\n\nexport type PaginationProps = PaginationProviderProps & { className?: string }\n\nexport const Pagination = ({\n children,\n visiblePageItems = 5,\n type = 'link',\n noEllipsis = false,\n className,\n ...rest\n}: PaginationProps) => {\n return (\n <PaginationProvider\n visiblePageItems={visiblePageItems}\n noEllipsis={noEllipsis}\n type={type}\n {...rest}\n >\n <PaginationWrapper className={className}>{children}</PaginationWrapper>\n </PaginationProvider>\n )\n}\n\nconst PaginationWrapper = ({\n children,\n className,\n}: {\n children: ReactNode\n className?: string\n}) => {\n const { pagination } = usePagination()\n\n const props = pagination.getRootProps()\n\n return (\n <nav data-spark-component=\"pagination\" {...props} className={className}>\n <ul className=\"gap-md flex flex-wrap\">{children}</ul>\n </nav>\n )\n}\n\nPagination.displayName = 'Pagination'\n","import { mergeProps } from '@zag-js/react'\nimport { cx } from 'class-variance-authority'\nimport { type ComponentPropsWithRef } from 'react'\n\nimport { usePagination } from './PaginationContext'\n\ninterface EllipsisProps extends ComponentPropsWithRef<'span'> {\n index: number\n}\n\n/**\n * An ellipsis indicating skipped pages. Renders a <span> element.\n */\n\nexport const Ellipsis = ({ children, index, className, ref, ...rest }: EllipsisProps) => {\n const { pagination } = usePagination()\n const apiProps = pagination.getEllipsisProps({ index })\n const localProps = {\n className: cx('flex size-sz-44 items-center justify-center', className),\n ...rest,\n }\n\n const mergedProps = mergeProps(apiProps, localProps)\n\n return (\n <li>\n <span data-spark-component=\"pagination-ellipsis\" ref={ref} {...mergedProps}>\n {children || '\\u2026'}\n </span>\n </li>\n )\n}\n\nEllipsis.displayName = 'Pagination.Ellipsis'\n","import { ArrowDoubleLeft } from '@spark-ui/icons/ArrowDoubleLeft'\nimport { mergeProps } from '@zag-js/react'\nimport { ComponentPropsWithoutRef, Ref } from 'react'\n\nimport { Icon } from '../icon'\nimport { IconButton } from '../icon-button'\nimport { usePagination } from './PaginationContext'\n\ntype AnchorProps = ComponentPropsWithoutRef<'a'> & {\n href: string\n asChild?: never\n}\n\ntype ButtonProps = ComponentPropsWithoutRef<'button'> & {\n /**\n * Change the component to the HTML tag or custom component of the only child.\n * Unavailable for anchor items (with `href` prop) since the component will already be rendered as an anchor element.\n */\n asChild?: boolean\n href?: never\n}\n\nexport type FirstPageTriggerProps = (AnchorProps | ButtonProps) & {\n 'aria-label': string\n ref?: Ref<HTMLButtonElement>\n}\n\n/**\n * A button that navigates to the first page. Renders a <button> element.\n */\n\nexport const FirstPageTrigger = ({\n children,\n className,\n href,\n ref,\n ...props\n}: FirstPageTriggerProps) => {\n const { pagination, type } = usePagination()\n\n // ZagJS props\n const apiProps = pagination.getFirstPageTriggerProps()\n\n const shouldDisableLink =\n type === 'link' &&\n (apiProps as typeof apiProps & { 'data-disabled'?: string })['data-disabled'] === ''\n\n // Locally managed props\n const localProps = {\n 'data-spark-component': 'pagination-first-page-trigger',\n intent: 'support',\n design: 'contrast',\n ...props,\n className,\n ...(shouldDisableLink && {\n disabled: true,\n role: 'link',\n 'aria-disabled': true,\n }),\n }\n\n // We know 'aria-label' is included in props\n type WithAriaLabel = Omit<typeof apiProps, 'aria-label'> & { 'aria-label': string }\n\n const mergedProps = mergeProps(\n apiProps,\n localProps as unknown as typeof apiProps\n ) as WithAriaLabel\n\n const content = children || (\n <Icon>\n <ArrowDoubleLeft />\n </Icon>\n )\n\n return (\n <li>\n {href ? (\n <IconButton ref={ref} {...mergedProps} asChild>\n <a href={shouldDisableLink ? undefined : href}>{content}</a>\n </IconButton>\n ) : (\n <IconButton ref={ref} {...mergedProps}>\n {content}\n </IconButton>\n )}\n </li>\n )\n}\n\nFirstPageTrigger.displayName = 'Pagination.FirstPageTrigger'\n","import { mergeProps } from '@zag-js/react'\nimport { cx } from 'class-variance-authority'\nimport { ComponentPropsWithoutRef, ReactElement, Ref } from 'react'\n\nimport { Button } from '../button'\nimport { usePagination } from './PaginationContext'\n\ntype AnchorProps = ComponentPropsWithoutRef<'a'> & {\n href: string\n asChild?: never\n}\n\ntype ButtonProps = ComponentPropsWithoutRef<'button'> & {\n /**\n * Change the component to the HTML tag or custom component of the only child.\n * Unavailable for anchor items (with `href` prop) since the component will already be rendered as an anchor element.\n */\n asChild?: boolean\n href?: never\n}\n\nexport type ItemProps = (AnchorProps | ButtonProps) & {\n 'aria-label': string\n value: number\n ref?: Ref<HTMLButtonElement>\n}\n\n/**\n * A numbered page item.\n * Should be used within `Pagination.Pages` to ensure proper functionality and accessibility.\n *\n * Can be rendered as an anchor or a button :\n * - Set a `href` prop to render the item as an anchor element.\n * - When using `href`, the `asChild` prop isn’t available since the component will already be rendered as an anchor element.\n */\nexport function Item({ children, value, className, href, ref, ...props }: ItemProps): ReactElement {\n const { pagination } = usePagination()\n\n // ZagJS props\n const apiProps = pagination.getItemProps({ type: 'page', value })\n\n // Locally managed props\n const localProps = {\n 'data-spark-component': 'pagination-item',\n intent: 'support',\n design: apiProps['aria-current'] === 'page' ? 'filled' : 'contrast',\n className: cx('size-sz-44', className),\n ...props,\n }\n\n const mergedProps = mergeProps(apiProps, localProps)\n\n return (\n <li>\n {href ? (\n <Button ref={ref} {...mergedProps} asChild>\n <a href={href}>{children || value}</a>\n </Button>\n ) : (\n <Button ref={ref} {...mergedProps}>\n {children || value}\n </Button>\n )}\n </li>\n )\n}\n\nItem.displayName = 'Pagination.Item'\n","import { ArrowDoubleRight } from '@spark-ui/icons/ArrowDoubleRight'\nimport { mergeProps } from '@zag-js/react'\nimport { ComponentPropsWithoutRef, Ref } from 'react'\n\nimport { Icon } from '../icon'\nimport { IconButton } from '../icon-button'\nimport { usePagination } from './PaginationContext'\n\ntype AnchorProps = ComponentPropsWithoutRef<'a'> & {\n href: string\n asChild?: never\n}\n\ntype ButtonProps = ComponentPropsWithoutRef<'button'> & {\n /**\n * Change the component to the HTML tag or custom component of the only child.\n * Unavailable for anchor items (with `href` prop) since the component will already be rendered as an anchor element.\n */\n asChild?: boolean\n href?: never\n}\n\nexport type LastPageTriggerProps = (AnchorProps | ButtonProps) & {\n 'aria-label': string\n ref?: Ref<HTMLButtonElement>\n}\n\n/**\n * A button that navigates to the last page. Renders a <button> element.\n */\n\nexport const LastPageTrigger = ({\n children,\n className,\n href,\n ref,\n ...props\n}: LastPageTriggerProps) => {\n const { pagination, type } = usePagination()\n\n // ZagJS props\n const apiProps = pagination.getLastPageTriggerProps()\n\n const shouldDisableLink =\n type === 'link' &&\n (apiProps as typeof apiProps & { 'data-disabled'?: string })['data-disabled'] === ''\n\n // Locally managed props\n const localProps = {\n 'data-spark-component': 'pagination-last-page-trigger',\n intent: 'support',\n design: 'contrast',\n ...props,\n className,\n ...(shouldDisableLink && {\n disabled: true,\n role: 'link',\n 'aria-disabled': true,\n }),\n }\n\n // We know 'aria-label' is included in props\n type WithAriaLabel = Omit<typeof apiProps, 'aria-label'> & { 'aria-label': string }\n\n const mergedProps = mergeProps(\n apiProps,\n localProps as unknown as typeof apiProps\n ) as WithAriaLabel\n\n const content = children || (\n <Icon>\n <ArrowDoubleRight />\n </Icon>\n )\n\n return (\n <li>\n {href ? (\n <IconButton ref={ref} {...mergedProps} asChild>\n <a href={shouldDisableLink ? undefined : href}>{content}</a>\n </IconButton>\n ) : (\n <IconButton ref={ref} {...mergedProps}>\n {content}\n </IconButton>\n )}\n </li>\n )\n}\n\nLastPageTrigger.displayName = 'Pagination.LastPageTrigger'\n","import { ArrowVerticalRight } from '@spark-ui/icons/ArrowVerticalRight'\nimport { mergeProps } from '@zag-js/react'\nimport { ComponentPropsWithoutRef, Ref } from 'react'\n\nimport { Icon } from '../icon'\nimport { IconButton } from '../icon-button'\nimport { usePagination } from './PaginationContext'\n\ntype AnchorProps = ComponentPropsWithoutRef<'a'> & {\n href: string\n asChild?: never\n}\n\ntype ButtonProps = ComponentPropsWithoutRef<'button'> & {\n /**\n * Change the component to the HTML tag or custom component of the only child.\n * Unavailable for anchor items (with `href` prop) since the component will already be rendered as an anchor element.\n */\n asChild?: boolean\n href?: never\n}\n\nexport type NextTriggerProps = (AnchorProps | ButtonProps) & {\n 'aria-label': string\n ref?: Ref<HTMLButtonElement>\n}\n\n/**\n * A button that navigates to the next page. Renders a <button> element.\n */\n\nexport const NextTrigger = ({ children, className, href, ref, ...props }: NextTriggerProps) => {\n const { pagination, type } = usePagination()\n\n // ZagJS props\n const apiProps = pagination.getNextTriggerProps()\n\n const shouldDisableLink =\n type === 'link' &&\n (apiProps as typeof apiProps & { 'data-disabled'?: string })['data-disabled'] === ''\n\n // Locally managed props\n const localProps = {\n 'data-spark-component': 'pagination-next-trigger',\n intent: 'support',\n design: 'contrast',\n ...props,\n className,\n ...(shouldDisableLink && {\n disabled: true,\n role: 'link',\n 'aria-disabled': true,\n }),\n }\n\n // We know 'aria-label' is included in props\n type WithAriaLabel = Omit<typeof apiProps, 'aria-label'> & { 'aria-label': string }\n\n const mergedProps = mergeProps(\n apiProps,\n localProps as unknown as typeof apiProps\n ) as WithAriaLabel\n\n const content = children || (\n <Icon>\n <ArrowVerticalRight />\n </Icon>\n )\n\n return (\n <li>\n {href ? (\n <IconButton ref={ref} {...mergedProps} asChild>\n <a href={shouldDisableLink ? undefined : href}>{content}</a>\n </IconButton>\n ) : (\n <IconButton ref={ref} {...mergedProps}>\n {content}\n </IconButton>\n )}\n </li>\n )\n}\n\nNextTrigger.displayName = 'Pagination.NextTrigger'\n","import * as pagination from '@zag-js/pagination'\nimport { ReactNode } from 'react'\n\nimport { usePagination } from './PaginationContext'\n\n// Extract the 'page' type element from the pagination API's 'pages' array.\ntype PageItem = Extract<pagination.Api['pages'][number], { type: 'page' }>\n\n// Define a type that conditionally tweaks the pagination API\n// based on the generic T parameter.\ntype TweakedPaginationApi<T extends 'noEllipsis' | ''> = Omit<pagination.Api, 'pages'> & {\n pages: T extends 'noEllipsis' ? PageItem[] : pagination.Api['pages']\n}\n\ninterface PagesProps<T extends 'noEllipsis' | ''> {\n children: (pagination: TweakedPaginationApi<T>) => ReactNode\n}\n\n/**\n * Container for page number buttons. Renders a <div> element.\n */\n\nexport const Pages = <T extends 'noEllipsis' | '' = ''>({ children }: PagesProps<T>) => {\n const { pagination } = usePagination()\n\n return children(pagination as TweakedPaginationApi<T>)\n}\n\nPages.displayName = 'Pagination.Pages'\n","import { ArrowVerticalLeft } from '@spark-ui/icons/ArrowVerticalLeft'\nimport { mergeProps } from '@zag-js/react'\nimport { ComponentPropsWithoutRef, Ref } from 'react'\n\nimport { Icon } from '../icon'\nimport { IconButton } from '../icon-button'\nimport { usePagination } from './PaginationContext'\n\ntype AnchorProps = ComponentPropsWithoutRef<'a'> & {\n href: string\n asChild?: never\n}\n\ntype ButtonProps = ComponentPropsWithoutRef<'button'> & {\n /**\n * Change the component to the HTML tag or custom component of the only child.\n * Unavailable for anchor items (with `href` prop) since the component will already be rendered as an anchor element.\n */\n asChild?: boolean\n href?: never\n}\n\nexport type PrevTriggerProps = (AnchorProps | ButtonProps) & {\n 'aria-label': string\n ref?: Ref<HTMLButtonElement>\n}\n\n/**\n * A button that navigates to the previous page. Renders a <button> element.\n */\n\nexport const PrevTrigger = ({ children, className, href, ref, ...props }: PrevTriggerProps) => {\n const { pagination, type } = usePagination()\n\n // ZagJS props\n const apiProps = pagination.getPrevTriggerProps()\n\n const shouldDisableLink =\n type === 'link' &&\n (apiProps as typeof apiProps & { 'data-disabled'?: string })['data-disabled'] === ''\n\n // Locally managed props\n const localProps = {\n 'data-spark-component': 'pagination-prev-trigger',\n intent: 'support',\n design: 'contrast',\n ...props,\n className,\n ...(shouldDisableLink && {\n disabled: true,\n role: 'link',\n 'aria-disabled': true,\n }),\n }\n\n // We know 'aria-label' is included in props\n type WithAriaLabel = Omit<typeof apiProps, 'aria-label'> & { 'aria-label': string }\n\n const mergedProps = mergeProps(\n apiProps,\n localProps as unknown as typeof apiProps\n ) as WithAriaLabel\n\n const content = children || (\n <Icon>\n <ArrowVerticalLeft />\n </Icon>\n )\n\n return (\n <li>\n {href ? (\n <IconButton ref={ref} {...mergedProps} asChild>\n <a href={shouldDisableLink ? undefined : href}>{content}</a>\n </IconButton>\n ) : (\n <IconButton ref={ref} {...mergedProps}>\n {content}\n </IconButton>\n )}\n </li>\n )\n}\n\nPrevTrigger.displayName = 'Pagination.PrevTrigger'\n","import type { FC } from 'react'\n\nimport { Pagination as Root, type PaginationProps } from './Pagination'\nimport { Ellipsis } from './PaginationEllipsis'\nimport { FirstPageTrigger } from './PaginationFirstPageTrigger'\nimport { Item } from './PaginationItem'\nimport { LastPageTrigger } from './PaginationLastPageTrigger'\nimport { NextTrigger } from './PaginationNextTrigger'\nimport { Pages } from './PaginationPages'\nimport { PrevTrigger } from './PaginationPrevTrigger'\n\n/**\n * A navigation component that allows users to navigate through multiple pages of content.\n */\nexport const Pagination: FC<PaginationProps> & {\n PrevTrigger: typeof PrevTrigger\n NextTrigger: typeof NextTrigger\n Pages: typeof Pages\n Item: typeof Item\n Ellipsis: typeof Ellipsis\n FirstPageTrigger: typeof FirstPageTrigger\n LastPageTrigger: typeof LastPageTrigger\n} = Object.assign(Root, {\n PrevTrigger,\n NextTrigger,\n Pages,\n Item,\n Ellipsis,\n FirstPageTrigger,\n LastPageTrigger,\n})\n\nPagination.displayName = 'Pagination'\n\nPrevTrigger.displayName = 'Pagination.PrevTrigger'\nNextTrigger.displayName = 'Pagination.NextTrigger'\nPages.displayName = 'Pagination.Pages'\nItem.displayName = 'Pagination.Item'\nEllipsis.displayName = 'Pagination.Ellipsis'\nFirstPageTrigger.displayName = 'Pagination.FirstPageTrigger'\nLastPageTrigger.displayName = 'Pagination.LastPageTrigger'\n"],"mappings":"qjBAAA,SAAgB,EAAoB,EAAY,EAAe,EAAgB,CAC7E,IAAM,GAAoB,EAAS,GAAK,EAEpC,EAAQ,KAAK,IAAI,EAAG,EAAQ,EAAiB,CAC7C,EAAM,KAAK,I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AsC,EAGxD,EAAM,YAAc,mBCGpB,IAAa,GAAe,CAAE,WAAU,YAAW,OAAM,MAAK,GAAG,KAA8B,CAC7F,GAAM,CAAE,aAAY,QAAS,GAAe,CAGtC,EAAW,EAAW,qBAAqB,CAE3C,EACJ,IAAS,QACR,EAA4D,mBAAqB,GAmB9E,GAAA,EAAA,EAAA,YACJ,EAjBiB,CACjB,uBAAwB,0BACxB,OAAQ,UACR,OAAQ,WACR,GAAG,EACH,YACA,GAAI,GAAqB,CACvB,SAAU,GACV,KAAM,OACN,gBAAiB,GAClB,CACF,CAQA,CAEK,EAAU,IACd,EAAA,EAAA,KAAC,EAAA,EAAD,CAAA,UACE,EAAA,EAAA,KAAC,EAAA,kBAAD,EAAqB,CAAA,CAChB,CAAA,CAGT,OACE,EAAA,EAAA,KAAC,KAAD,CAAA,SACG,GACC,EAAA,EAAA,KAAC,EAAA,EAAD,CAAiB,MAAK,GAAI,EAAa,QAAA,aACrC,EAAA,EAAA,KAAC,IAAD,CAAG,KAAM,EAAoB,IAAA,GAAY,WAAO,EAAY,CAAA,CACjD,CAAA,EAEb,EAAA,EAAA,KAAC,EAAA,EAAD,CAAiB,MAAK,GAAI,WACvB,EACU,CAAA,CAEZ,CAAA,EAIT,EAAY,YAAc,yBCtE1B,IAAa,EAQT,OAAO,OAAO,EAAM,CACtB,cACA,cACA,QACA,OACA,WACA,mBACA,kBACD,CAAC,CAEF,EAAW,YAAc,aAEzB,EAAY,YAAc,yBAC1B,EAAY,YAAc,yBAC1B,EAAM,YAAc,mBACpB,EAAK,YAAc,kBACnB,EAAS,YAAc,sBACvB,EAAiB,YAAc,8BAC/B,EAAgB,YAAc"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/pagination/utils.ts","../../src/pagination/PaginationContext.tsx","../../src/pagination/Pagination.tsx","../../src/pagination/PaginationEllipsis.tsx","../../src/pagination/PaginationFirstPageTrigger.tsx","../../src/pagination/PaginationItem.tsx","../../src/pagination/PaginationLastPageTrigger.tsx","../../src/pagination/PaginationNextTrigger.tsx","../../src/pagination/PaginationPages.tsx","../../src/pagination/PaginationPrevTrigger.tsx","../../src/pagination/index.ts"],"sourcesContent":["export function sliceArrayWithIndex(arr: any[], index: number, length: number) {\n const relativeElements = (length - 1) / 2\n\n let start = Math.max(0, index - relativeElements)\n let end = Math.min(arr.length, index + relativeElements + 1)\n\n if (end - start < length) {\n start = Math.max(0, Math.min(start, arr.length - length))\n end = Math.min(arr.length, start + length)\n }\n\n return arr.slice(start, end)\n}\n","import * as pagination from '@zag-js/pagination'\nimport { normalizeProps, type PropTypes, useMachine } from '@zag-js/react'\nimport { createContext, type ReactNode, useContext, useId } from 'react'\n\nimport { sliceArrayWithIndex } from './utils'\n\nexport interface PaginationContextState<T extends PropTypes = PropTypes> {\n type: pagination.Props['type']\n pagination: pagination.Api<T> & {\n getFirstPageTriggerProps: () => ReturnType<pagination.Api<T>['getPrevTriggerProps']> & {\n 'data-part': string\n onClick: () => void\n }\n getLastPageTriggerProps: () => ReturnType<pagination.Api<T>['getNextTriggerProps']> & {\n 'data-part': string\n onClick: () => void\n }\n }\n}\n\nconst PaginationContext = createContext<PaginationContextState | null>(null)\n\nexport interface PaginationProviderProps {\n children: ReactNode\n /**\n * Total number of data items available across all pages.\n */\n count: number\n /**\n * Maximum amount of items displayed on a single page.\n */\n pageSize: number\n /**\n * Number of visible pages (or ellipsis) between previous and next page triggers.\n */\n visiblePageItems?: number\n /**\n * The current page (active page)\n */\n page?: pagination.Props['page']\n /**\n * If your pagination contains buttons instead of links, set `type` to `button`, extra attributes will be applied on page items for a11y.\n */\n type?: pagination.Props['type']\n onPageChange?: pagination.Props['onPageChange']\n noEllipsis?: boolean\n}\n\nexport const PaginationProvider = ({\n children,\n count,\n visiblePageItems = 7,\n pageSize,\n page,\n onPageChange,\n noEllipsis,\n type = 'link',\n}: PaginationProviderProps) => {\n /**\n * Here `Infinity` is used because we apply a custom slice ourselves to manage the \"no ellipsis\" version.\n * It means Zag won't filter out any page item, allowing us to apply our own slicing logic.\n */\n const siblingCount = noEllipsis ? Infinity : Math.max(0, Math.floor((visiblePageItems - 5) / 2))\n\n const id = useId()\n\n const service = useMachine(pagination.machine, {\n id,\n count,\n siblingCount,\n pageSize,\n page,\n onPageChange,\n type,\n })\n\n const api = pagination.connect(service, normalizeProps)\n const pages = noEllipsis\n ? sliceArrayWithIndex(api.pages, api.page - 1, visiblePageItems)\n : api.pages\n\n return (\n <PaginationContext\n value={{\n type,\n pagination: {\n ...api,\n pages,\n // Extending ZagJS anatomy\n getFirstPageTriggerProps: () => {\n return {\n ...api.getPrevTriggerProps(),\n id: `${api.getRootProps().id}:first`,\n 'data-part': 'first-page-trigger',\n onClick: api.goToFirstPage,\n }\n },\n getLastPageTriggerProps: () => {\n return {\n ...api.getNextTriggerProps(),\n id: `${api.getRootProps().id}:last`,\n 'data-part': 'last-page-trigger',\n onClick: api.goToLastPage,\n }\n },\n },\n }}\n >\n {children}\n </PaginationContext>\n )\n}\n\nexport const usePagination = () => {\n const context = useContext(PaginationContext)\n\n if (!context) {\n throw Error('usePagination must be used within a Pagination provider')\n }\n\n return context\n}\n","import { ReactNode } from 'react'\n\nimport {\n PaginationProvider,\n type PaginationProviderProps,\n usePagination,\n} from './PaginationContext'\n\nexport type PaginationProps = PaginationProviderProps & { className?: string }\n\nexport const Pagination = ({\n children,\n visiblePageItems = 5,\n type = 'link',\n noEllipsis = false,\n className,\n ...rest\n}: PaginationProps) => {\n return (\n <PaginationProvider\n visiblePageItems={visiblePageItems}\n noEllipsis={noEllipsis}\n type={type}\n {...rest}\n >\n <PaginationWrapper className={className}>{children}</PaginationWrapper>\n </PaginationProvider>\n )\n}\n\nconst PaginationWrapper = ({\n children,\n className,\n}: {\n children: ReactNode\n className?: string\n}) => {\n const { pagination } = usePagination()\n\n const props = pagination.getRootProps()\n\n return (\n <nav data-spark-component=\"pagination\" {...props} className={className}>\n <ul className=\"gap-md flex flex-wrap\">{children}</ul>\n </nav>\n )\n}\n\nPagination.displayName = 'Pagination'\n","import { mergeProps } from '@zag-js/react'\nimport { cx } from 'class-variance-authority'\nimport { type ComponentPropsWithRef } from 'react'\n\nimport { usePagination } from './PaginationContext'\n\ninterface EllipsisProps extends ComponentPropsWithRef<'span'> {\n index: number\n}\n\n/**\n * An ellipsis indicating skipped pages. Renders a <span> element.\n */\n\nexport const Ellipsis = ({ children, index, className, ref, ...rest }: EllipsisProps) => {\n const { pagination } = usePagination()\n const apiProps = pagination.getEllipsisProps({ index })\n const localProps = {\n className: cx('flex size-sz-44 items-center justify-center', className),\n ...rest,\n }\n\n const mergedProps = mergeProps(apiProps, localProps)\n\n return (\n <li>\n <span data-spark-component=\"pagination-ellipsis\" ref={ref} {...mergedProps}>\n {children || '\\u2026'}\n </span>\n </li>\n )\n}\n\nEllipsis.displayName = 'Pagination.Ellipsis'\n","import { ArrowDoubleLeft } from '@spark-ui/icons/ArrowDoubleLeft'\nimport { mergeProps } from '@zag-js/react'\nimport { ComponentPropsWithoutRef, Ref } from 'react'\n\nimport { Icon } from '../icon'\nimport { IconButton } from '../icon-button'\nimport { usePagination } from './PaginationContext'\n\ntype AnchorProps = ComponentPropsWithoutRef<'a'> & {\n href: string\n asChild?: never\n}\n\ntype ButtonProps = ComponentPropsWithoutRef<'button'> & {\n /**\n * Change the component to the HTML tag or custom component of the only child.\n * Unavailable for anchor items (with `href` prop) since the component will already be rendered as an anchor element.\n */\n asChild?: boolean\n href?: never\n}\n\nexport type FirstPageTriggerProps = (AnchorProps | ButtonProps) & {\n 'aria-label': string\n ref?: Ref<HTMLButtonElement>\n}\n\n/**\n * A button that navigates to the first page. Renders a <button> element.\n */\n\nexport const FirstPageTrigger = ({\n children,\n className,\n href,\n ref,\n ...props\n}: FirstPageTriggerProps) => {\n const { pagination, type } = usePagination()\n\n // ZagJS props\n const apiProps = pagination.getFirstPageTriggerProps()\n\n const shouldDisableLink =\n type === 'link' &&\n (apiProps as typeof apiProps & { 'data-disabled'?: string })['data-disabled'] === ''\n\n // Locally managed props\n const localProps = {\n 'data-spark-component': 'pagination-first-page-trigger',\n intent: 'support',\n design: 'contrast',\n ...props,\n className,\n ...(shouldDisableLink && {\n disabled: true,\n role: 'link',\n 'aria-disabled': true,\n }),\n }\n\n // We know 'aria-label' is included in props\n type WithAriaLabel = Omit<typeof apiProps, 'aria-label'> & { 'aria-label': string }\n\n const mergedProps = mergeProps(\n apiProps,\n localProps as unknown as typeof apiProps\n ) as WithAriaLabel\n\n const content = children || (\n <Icon>\n <ArrowDoubleLeft />\n </Icon>\n )\n\n return (\n <li>\n {href ? (\n <IconButton ref={ref} {...mergedProps} asChild>\n <a href={shouldDisableLink ? undefined : href}>{content}</a>\n </IconButton>\n ) : (\n <IconButton ref={ref} {...mergedProps}>\n {content}\n </IconButton>\n )}\n </li>\n )\n}\n\nFirstPageTrigger.displayName = 'Pagination.FirstPageTrigger'\n","import { mergeProps } from '@zag-js/react'\nimport { cx } from 'class-variance-authority'\nimport { ComponentPropsWithoutRef, ReactElement, Ref } from 'react'\n\nimport { Button } from '../button'\nimport { usePagination } from './PaginationContext'\n\ntype AnchorProps = ComponentPropsWithoutRef<'a'> & {\n href: string\n asChild?: never\n}\n\ntype ButtonProps = ComponentPropsWithoutRef<'button'> & {\n /**\n * Change the component to the HTML tag or custom component of the only child.\n * Unavailable for anchor items (with `href` prop) since the component will already be rendered as an anchor element.\n */\n asChild?: boolean\n href?: never\n}\n\nexport type ItemProps = (AnchorProps | ButtonProps) & {\n 'aria-label': string\n value: number\n ref?: Ref<HTMLButtonElement>\n}\n\n/**\n * A numbered page item.\n * Should be used within `Pagination.Pages` to ensure proper functionality and accessibility.\n *\n * Can be rendered as an anchor or a button :\n * - Set a `href` prop to render the item as an anchor element.\n * - When using `href`, the `asChild` prop isn’t available since the component will already be rendered as an anchor element.\n */\nexport function Item({ children, value, className, href, ref, ...props }: ItemProps): ReactElement {\n const { pagination } = usePagination()\n\n // ZagJS props\n const apiProps = pagination.getItemProps({ type: 'page', value })\n\n // Locally managed props\n const localProps = {\n 'data-spark-component': 'pagination-item',\n intent: 'support',\n design: apiProps['aria-current'] === 'page' ? 'filled' : 'contrast',\n className: cx('size-sz-44', className),\n ...props,\n }\n\n const mergedProps = mergeProps(apiProps, localProps)\n\n return (\n <li>\n {href ? (\n <Button ref={ref} {...mergedProps} asChild>\n <a href={href}>{children || value}</a>\n </Button>\n ) : (\n <Button ref={ref} {...mergedProps}>\n {children || value}\n </Button>\n )}\n </li>\n )\n}\n\nItem.displayName = 'Pagination.Item'\n","import { ArrowDoubleRight } from '@spark-ui/icons/ArrowDoubleRight'\nimport { mergeProps } from '@zag-js/react'\nimport { ComponentPropsWithoutRef, Ref } from 'react'\n\nimport { Icon } from '../icon'\nimport { IconButton } from '../icon-button'\nimport { usePagination } from './PaginationContext'\n\ntype AnchorProps = ComponentPropsWithoutRef<'a'> & {\n href: string\n asChild?: never\n}\n\ntype ButtonProps = ComponentPropsWithoutRef<'button'> & {\n /**\n * Change the component to the HTML tag or custom component of the only child.\n * Unavailable for anchor items (with `href` prop) since the component will already be rendered as an anchor element.\n */\n asChild?: boolean\n href?: never\n}\n\nexport type LastPageTriggerProps = (AnchorProps | ButtonProps) & {\n 'aria-label': string\n ref?: Ref<HTMLButtonElement>\n}\n\n/**\n * A button that navigates to the last page. Renders a <button> element.\n */\n\nexport const LastPageTrigger = ({\n children,\n className,\n href,\n ref,\n ...props\n}: LastPageTriggerProps) => {\n const { pagination, type } = usePagination()\n\n // ZagJS props\n const apiProps = pagination.getLastPageTriggerProps()\n\n const shouldDisableLink =\n type === 'link' &&\n (apiProps as typeof apiProps & { 'data-disabled'?: string })['data-disabled'] === ''\n\n // Locally managed props\n const localProps = {\n 'data-spark-component': 'pagination-last-page-trigger',\n intent: 'support',\n design: 'contrast',\n ...props,\n className,\n ...(shouldDisableLink && {\n disabled: true,\n role: 'link',\n 'aria-disabled': true,\n }),\n }\n\n // We know 'aria-label' is included in props\n type WithAriaLabel = Omit<typeof apiProps, 'aria-label'> & { 'aria-label': string }\n\n const mergedProps = mergeProps(\n apiProps,\n localProps as unknown as typeof apiProps\n ) as WithAriaLabel\n\n const content = children || (\n <Icon>\n <ArrowDoubleRight />\n </Icon>\n )\n\n return (\n <li>\n {href ? (\n <IconButton ref={ref} {...mergedProps} asChild>\n <a href={shouldDisableLink ? undefined : href}>{content}</a>\n </IconButton>\n ) : (\n <IconButton ref={ref} {...mergedProps}>\n {content}\n </IconButton>\n )}\n </li>\n )\n}\n\nLastPageTrigger.displayName = 'Pagination.LastPageTrigger'\n","import { ArrowVerticalRight } from '@spark-ui/icons/ArrowVerticalRight'\nimport { mergeProps } from '@zag-js/react'\nimport { ComponentPropsWithoutRef, Ref } from 'react'\n\nimport { Icon } from '../icon'\nimport { IconButton } from '../icon-button'\nimport { usePagination } from './PaginationContext'\n\ntype AnchorProps = ComponentPropsWithoutRef<'a'> & {\n href: string\n asChild?: never\n}\n\ntype ButtonProps = ComponentPropsWithoutRef<'button'> & {\n /**\n * Change the component to the HTML tag or custom component of the only child.\n * Unavailable for anchor items (with `href` prop) since the component will already be rendered as an anchor element.\n */\n asChild?: boolean\n href?: never\n}\n\nexport type NextTriggerProps = (AnchorProps | ButtonProps) & {\n 'aria-label': string\n ref?: Ref<HTMLButtonElement>\n}\n\n/**\n * A button that navigates to the next page. Renders a <button> element.\n */\n\nexport const NextTrigger = ({ children, className, href, ref, ...props }: NextTriggerProps) => {\n const { pagination, type } = usePagination()\n\n // ZagJS props\n const apiProps = pagination.getNextTriggerProps()\n\n const shouldDisableLink =\n type === 'link' &&\n (apiProps as typeof apiProps & { 'data-disabled'?: string })['data-disabled'] === ''\n\n // Locally managed props\n const localProps = {\n 'data-spark-component': 'pagination-next-trigger',\n intent: 'support',\n design: 'contrast',\n ...props,\n className,\n ...(shouldDisableLink && {\n disabled: true,\n role: 'link',\n 'aria-disabled': true,\n }),\n }\n\n // We know 'aria-label' is included in props\n type WithAriaLabel = Omit<typeof apiProps, 'aria-label'> & { 'aria-label': string }\n\n const mergedProps = mergeProps(\n apiProps,\n localProps as unknown as typeof apiProps\n ) as WithAriaLabel\n\n const content = children || (\n <Icon>\n <ArrowVerticalRight />\n </Icon>\n )\n\n return (\n <li>\n {href ? (\n <IconButton ref={ref} {...mergedProps} asChild>\n <a href={shouldDisableLink ? undefined : href}>{content}</a>\n </IconButton>\n ) : (\n <IconButton ref={ref} {...mergedProps}>\n {content}\n </IconButton>\n )}\n </li>\n )\n}\n\nNextTrigger.displayName = 'Pagination.NextTrigger'\n","import * as pagination from '@zag-js/pagination'\nimport { ReactNode } from 'react'\n\nimport { usePagination } from './PaginationContext'\n\n// Extract the 'page' type element from the pagination API's 'pages' array.\ntype PageItem = Extract<pagination.Api['pages'][number], { type: 'page' }>\n\n// Define a type that conditionally tweaks the pagination API\n// based on the generic T parameter.\ntype TweakedPaginationApi<T extends 'noEllipsis' | ''> = Omit<pagination.Api, 'pages'> & {\n pages: T extends 'noEllipsis' ? PageItem[] : pagination.Api['pages']\n}\n\ninterface PagesProps<T extends 'noEllipsis' | ''> {\n children: (pagination: TweakedPaginationApi<T>) => ReactNode\n}\n\n/**\n * Container for page number buttons. Renders a <div> element.\n */\n\nexport const Pages = <T extends 'noEllipsis' | '' = ''>({ children }: PagesProps<T>) => {\n const { pagination } = usePagination()\n\n return children(pagination as TweakedPaginationApi<T>)\n}\n\nPages.displayName = 'Pagination.Pages'\n","import { ArrowVerticalLeft } from '@spark-ui/icons/ArrowVerticalLeft'\nimport { mergeProps } from '@zag-js/react'\nimport { ComponentPropsWithoutRef, Ref } from 'react'\n\nimport { Icon } from '../icon'\nimport { IconButton } from '../icon-button'\nimport { usePagination } from './PaginationContext'\n\ntype AnchorProps = ComponentPropsWithoutRef<'a'> & {\n href: string\n asChild?: never\n}\n\ntype ButtonProps = ComponentPropsWithoutRef<'button'> & {\n /**\n * Change the component to the HTML tag or custom component of the only child.\n * Unavailable for anchor items (with `href` prop) since the component will already be rendered as an anchor element.\n */\n asChild?: boolean\n href?: never\n}\n\nexport type PrevTriggerProps = (AnchorProps | ButtonProps) & {\n 'aria-label': string\n ref?: Ref<HTMLButtonElement>\n}\n\n/**\n * A button that navigates to the previous page. Renders a <button> element.\n */\n\nexport const PrevTrigger = ({ children, className, href, ref, ...props }: PrevTriggerProps) => {\n const { pagination, type } = usePagination()\n\n // ZagJS props\n const apiProps = pagination.getPrevTriggerProps()\n\n const shouldDisableLink =\n type === 'link' &&\n (apiProps as typeof apiProps & { 'data-disabled'?: string })['data-disabled'] === ''\n\n // Locally managed props\n const localProps = {\n 'data-spark-component': 'pagination-prev-trigger',\n intent: 'support',\n design: 'contrast',\n ...props,\n className,\n ...(shouldDisableLink && {\n disabled: true,\n role: 'link',\n 'aria-disabled': true,\n }),\n }\n\n // We know 'aria-label' is included in props\n type WithAriaLabel = Omit<typeof apiProps, 'aria-label'> & { 'aria-label': string }\n\n const mergedProps = mergeProps(\n apiProps,\n localProps as unknown as typeof apiProps\n ) as WithAriaLabel\n\n const content = children || (\n <Icon>\n <ArrowVerticalLeft />\n </Icon>\n )\n\n return (\n <li>\n {href ? (\n <IconButton ref={ref} {...mergedProps} asChild>\n <a href={shouldDisableLink ? undefined : href}>{content}</a>\n </IconButton>\n ) : (\n <IconButton ref={ref} {...mergedProps}>\n {content}\n </IconButton>\n )}\n </li>\n )\n}\n\nPrevTrigger.displayName = 'Pagination.PrevTrigger'\n","import type { FC } from 'react'\n\nimport { Pagination as Root, type PaginationProps } from './Pagination'\nimport { Ellipsis } from './PaginationEllipsis'\nimport { FirstPageTrigger } from './PaginationFirstPageTrigger'\nimport { Item } from './PaginationItem'\nimport { LastPageTrigger } from './PaginationLastPageTrigger'\nimport { NextTrigger } from './PaginationNextTrigger'\nimport { Pages } from './PaginationPages'\nimport { PrevTrigger } from './PaginationPrevTrigger'\n\n/**\n * A navigation component that allows users to navigate through multiple pages of content.\n */\nexport const Pagination: FC<PaginationProps> & {\n PrevTrigger: typeof PrevTrigger\n NextTrigger: typeof NextTrigger\n Pages: typeof Pages\n Item: typeof Item\n Ellipsis: typeof Ellipsis\n FirstPageTrigger: typeof FirstPageTrigger\n LastPageTrigger: typeof LastPageTrigger\n} = Object.assign(Root, {\n PrevTrigger,\n NextTrigger,\n Pages,\n Item,\n Ellipsis,\n FirstPageTrigger,\n LastPageTrigger,\n})\n\nPagination.displayName = 'Pagination'\n\nPrevTrigger.displayName = 'Pagination.PrevTrigger'\nNextTrigger.displayName = 'Pagination.NextTrigger'\nPages.displayName = 'Pagination.Pages'\nItem.displayName = 'Pagination.Item'\nEllipsis.displayName = 'Pagination.Ellipsis'\nFirstPageTrigger.displayName = 'Pagination.FirstPageTrigger'\nLastPageTrigger.displayName = 'Pagination.LastPageTrigger'\n"],"mappings":"qjBAAA,SAAgB,EAAoB,EAAY,EAAe,EAAgB,CAC7E,IAAM,GAAoB,EAAS,GAAK,EAEpC,EAAQ,KAAK,IAAI,EAAG,EAAQ,EAAiB,CAC7C,EAAM,KAAK,IAAI,EAAI,OAAQ,EAAQ,EAAmB,EAAE,CAO5D,OALI,EAAM,EAAQ,IAChB,EAAQ,KAAK,IAAI,EAAG,KAAK,IAAI,EAAO,EAAI,OAAS,EAAO,CAAC,CACzD,EAAM,KAAK,IAAI,EAAI,OAAQ,EAAQ,EAAO,EAGrC,EAAI,MAAM,EAAO,EAAI,CCS9B,IAAM,GAAA,EAAA,EAAA,eAAiE,KAAK,CA4B/D,GAAsB,CACjC,WACA,QACA,mBAAmB,EACnB,WACA,OACA,eACA,aACA,OAAO,UACsB,CAK7B,IAAM,EAAe,EAAa,IAAW,KAAK,IAAI,EAAG,KAAK,OAAO,EAAmB,GAAK,EAAE,CAAC,CAE1F,GAAA,EAAA,EAAA,QAAY,CAEZ,GAAA,EAAA,EAAA,YAAqB,EAAW,QAAS,CAC7C,KACA,QACA,eACA,WACA,OACA,eACA,OACD,CAAC,CAEI,EAAM,EAAW,QAAQ,EAAS,EAAA,eAAe,CACjD,EAAQ,EACV,EAAoB,EAAI,MAAO,EAAI,KAAO,EAAG,EAA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AA,CACjD,CAAA,EAEb,EAAA,EAAA,KAAC,EAAA,EAAD,CAAiB,MAAK,GAAI,WACvB,EACU,CAAA,CAEZ,CAAA,EAIT,EAAY,YAAc,yBCtE1B,IAAa,EAQT,OAAO,OAAO,EAAM,CACtB,cACA,cACA,QACA,OACA,WACA,mBACA,kBACD,CAAC,CAEF,EAAW,YAAc,aAEzB,EAAY,YAAc,yBAC1B,EAAY,YAAc,yBAC1B,EAAM,YAAc,mBACpB,EAAK,YAAc,kBACnB,EAAS,YAAc,sBACvB,EAAiB,YAAc,8BAC/B,EAAgB,YAAc"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as e } from "../icon-D05Uqh8_.mjs";
|
|
2
|
-
import { t } from "../button-
|
|
3
|
-
import { t as n } from "../icon-button-
|
|
2
|
+
import { t } from "../button-CNabSkd_.mjs";
|
|
3
|
+
import { t as n } from "../icon-button-DVbKK2_a.mjs";
|
|
4
4
|
import { cx as r } from "class-variance-authority";
|
|
5
5
|
import { createContext as i, useContext as a, useId as o } from "react";
|
|
6
6
|
import { jsx as s } from "react/jsx-runtime";
|
|
@@ -27,7 +27,7 @@ var _ = i(null), v = ({ children: e, count: t, visiblePageItems: n = 7, pageSize
|
|
|
27
27
|
onPageChange: a,
|
|
28
28
|
type: l
|
|
29
29
|
}), v = u.connect(h, f), y = c ? g(v.pages, v.page - 1, n) : v.pages;
|
|
30
|
-
return /* @__PURE__ */ s(_
|
|
30
|
+
return /* @__PURE__ */ s(_, {
|
|
31
31
|
value: {
|
|
32
32
|
type: l,
|
|
33
33
|
pagination: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/pagination/utils.ts","../../src/pagination/PaginationContext.tsx","../../src/pagination/Pagination.tsx","../../src/pagination/PaginationEllipsis.tsx","../../src/pagination/PaginationFirstPageTrigger.tsx","../../src/pagination/PaginationItem.tsx","../../src/pagination/PaginationLastPageTrigger.tsx","../../src/pagination/PaginationNextTrigger.tsx","../../src/pagination/PaginationPages.tsx","../../src/pagination/PaginationPrevTrigger.tsx","../../src/pagination/index.ts"],"sourcesContent":["export function sliceArrayWithIndex(arr: any[], index: number, length: number) {\n const relativeElements = (length - 1) / 2\n\n let start = Math.max(0, index - relativeElements)\n let end = Math.min(arr.length, index + relativeElements + 1)\n\n if (end - start < length) {\n start = Math.max(0, Math.min(start, arr.length - length))\n end = Math.min(arr.length, start + length)\n }\n\n return arr.slice(start, end)\n}\n","import * as pagination from '@zag-js/pagination'\nimport { normalizeProps, type PropTypes, useMachine } from '@zag-js/react'\nimport { createContext, type ReactNode, useContext, useId } from 'react'\n\nimport { sliceArrayWithIndex } from './utils'\n\nexport interface PaginationContextState<T extends PropTypes = PropTypes> {\n type: pagination.Props['type']\n pagination: pagination.Api<T> & {\n getFirstPageTriggerProps: () => ReturnType<pagination.Api<T>['getPrevTriggerProps']> & {\n 'data-part': string\n onClick: () => void\n }\n getLastPageTriggerProps: () => ReturnType<pagination.Api<T>['getNextTriggerProps']> & {\n 'data-part': string\n onClick: () => void\n }\n }\n}\n\nconst PaginationContext = createContext<PaginationContextState | null>(null)\n\nexport interface PaginationProviderProps {\n children: ReactNode\n /**\n * Total number of data items available across all pages.\n */\n count: number\n /**\n * Maximum amount of items displayed on a single page.\n */\n pageSize: number\n /**\n * Number of visible pages (or ellipsis) between previous and next page triggers.\n */\n visiblePageItems?: number\n /**\n * The current page (active page)\n */\n page?: pagination.Props['page']\n /**\n * If your pagination contains buttons instead of links, set `type` to `button`, extra attributes will be applied on page items for a11y.\n */\n type?: pagination.Props['type']\n onPageChange?: pagination.Props['onPageChange']\n noEllipsis?: boolean\n}\n\nexport const PaginationProvider = ({\n children,\n count,\n visiblePageItems = 7,\n pageSize,\n page,\n onPageChange,\n noEllipsis,\n type = 'link',\n}: PaginationProviderProps) => {\n /**\n * Here `Infinity` is used because we apply a custom slice ourselves to manage the \"no ellipsis\" version.\n * It means Zag won't filter out any page item, allowing us to apply our own slicing logic.\n */\n const siblingCount = noEllipsis ? Infinity : Math.max(0, Math.floor((visiblePageItems - 5) / 2))\n\n const id = useId()\n\n const service = useMachine(pagination.machine, {\n id,\n count,\n siblingCount,\n pageSize,\n page,\n onPageChange,\n type,\n })\n\n const api = pagination.connect(service, normalizeProps)\n const pages = noEllipsis\n ? sliceArrayWithIndex(api.pages, api.page - 1, visiblePageItems)\n : api.pages\n\n return (\n <PaginationContext.Provider\n value={{\n type,\n pagination: {\n ...api,\n pages,\n // Extending ZagJS anatomy\n getFirstPageTriggerProps: () => {\n return {\n ...api.getPrevTriggerProps(),\n id: `${api.getRootProps().id}:first`,\n 'data-part': 'first-page-trigger',\n onClick: api.goToFirstPage,\n }\n },\n getLastPageTriggerProps: () => {\n return {\n ...api.getNextTriggerProps(),\n id: `${api.getRootProps().id}:last`,\n 'data-part': 'last-page-trigger',\n onClick: api.goToLastPage,\n }\n },\n },\n }}\n >\n {children}\n </PaginationContext.Provider>\n )\n}\n\nexport const usePagination = () => {\n const context = useContext(PaginationContext)\n\n if (!context) {\n throw Error('usePagination must be used within a Pagination provider')\n }\n\n return context\n}\n","import { ReactNode } from 'react'\n\nimport {\n PaginationProvider,\n type PaginationProviderProps,\n usePagination,\n} from './PaginationContext'\n\nexport type PaginationProps = PaginationProviderProps & { className?: string }\n\nexport const Pagination = ({\n children,\n visiblePageItems = 5,\n type = 'link',\n noEllipsis = false,\n className,\n ...rest\n}: PaginationProps) => {\n return (\n <PaginationProvider\n visiblePageItems={visiblePageItems}\n noEllipsis={noEllipsis}\n type={type}\n {...rest}\n >\n <PaginationWrapper className={className}>{children}</PaginationWrapper>\n </PaginationProvider>\n )\n}\n\nconst PaginationWrapper = ({\n children,\n className,\n}: {\n children: ReactNode\n className?: string\n}) => {\n const { pagination } = usePagination()\n\n const props = pagination.getRootProps()\n\n return (\n <nav data-spark-component=\"pagination\" {...props} className={className}>\n <ul className=\"gap-md flex flex-wrap\">{children}</ul>\n </nav>\n )\n}\n\nPagination.displayName = 'Pagination'\n","import { mergeProps } from '@zag-js/react'\nimport { cx } from 'class-variance-authority'\nimport { type ComponentPropsWithRef } from 'react'\n\nimport { usePagination } from './PaginationContext'\n\ninterface EllipsisProps extends ComponentPropsWithRef<'span'> {\n index: number\n}\n\n/**\n * An ellipsis indicating skipped pages. Renders a <span> element.\n */\n\nexport const Ellipsis = ({ children, index, className, ref, ...rest }: EllipsisProps) => {\n const { pagination } = usePagination()\n const apiProps = pagination.getEllipsisProps({ index })\n const localProps = {\n className: cx('flex size-sz-44 items-center justify-center', className),\n ...rest,\n }\n\n const mergedProps = mergeProps(apiProps, localProps)\n\n return (\n <li>\n <span data-spark-component=\"pagination-ellipsis\" ref={ref} {...mergedProps}>\n {children || '\\u2026'}\n </span>\n </li>\n )\n}\n\nEllipsis.displayName = 'Pagination.Ellipsis'\n","import { ArrowDoubleLeft } from '@spark-ui/icons/ArrowDoubleLeft'\nimport { mergeProps } from '@zag-js/react'\nimport { ComponentPropsWithoutRef, Ref } from 'react'\n\nimport { Icon } from '../icon'\nimport { IconButton } from '../icon-button'\nimport { usePagination } from './PaginationContext'\n\ntype AnchorProps = ComponentPropsWithoutRef<'a'> & {\n href: string\n asChild?: never\n}\n\ntype ButtonProps = ComponentPropsWithoutRef<'button'> & {\n /**\n * Change the component to the HTML tag or custom component of the only child.\n * Unavailable for anchor items (with `href` prop) since the component will already be rendered as an anchor element.\n */\n asChild?: boolean\n href?: never\n}\n\nexport type FirstPageTriggerProps = (AnchorProps | ButtonProps) & {\n 'aria-label': string\n ref?: Ref<HTMLButtonElement>\n}\n\n/**\n * A button that navigates to the first page. Renders a <button> element.\n */\n\nexport const FirstPageTrigger = ({\n children,\n className,\n href,\n ref,\n ...props\n}: FirstPageTriggerProps) => {\n const { pagination, type } = usePagination()\n\n // ZagJS props\n const apiProps = pagination.getFirstPageTriggerProps()\n\n const shouldDisableLink =\n type === 'link' &&\n (apiProps as typeof apiProps & { 'data-disabled'?: string })['data-disabled'] === ''\n\n // Locally managed props\n const localProps = {\n 'data-spark-component': 'pagination-first-page-trigger',\n intent: 'support',\n design: 'contrast',\n ...props,\n className,\n ...(shouldDisableLink && {\n disabled: true,\n role: 'link',\n 'aria-disabled': true,\n }),\n }\n\n // We know 'aria-label' is included in props\n type WithAriaLabel = Omit<typeof apiProps, 'aria-label'> & { 'aria-label': string }\n\n const mergedProps = mergeProps(\n apiProps,\n localProps as unknown as typeof apiProps\n ) as WithAriaLabel\n\n const content = children || (\n <Icon>\n <ArrowDoubleLeft />\n </Icon>\n )\n\n return (\n <li>\n {href ? (\n <IconButton ref={ref} {...mergedProps} asChild>\n <a href={shouldDisableLink ? undefined : href}>{content}</a>\n </IconButton>\n ) : (\n <IconButton ref={ref} {...mergedProps}>\n {content}\n </IconButton>\n )}\n </li>\n )\n}\n\nFirstPageTrigger.displayName = 'Pagination.FirstPageTrigger'\n","import { mergeProps } from '@zag-js/react'\nimport { cx } from 'class-variance-authority'\nimport { ComponentPropsWithoutRef, ReactElement, Ref } from 'react'\n\nimport { Button } from '../button'\nimport { usePagination } from './PaginationContext'\n\ntype AnchorProps = ComponentPropsWithoutRef<'a'> & {\n href: string\n asChild?: never\n}\n\ntype ButtonProps = ComponentPropsWithoutRef<'button'> & {\n /**\n * Change the component to the HTML tag or custom component of the only child.\n * Unavailable for anchor items (with `href` prop) since the component will already be rendered as an anchor element.\n */\n asChild?: boolean\n href?: never\n}\n\nexport type ItemProps = (AnchorProps | ButtonProps) & {\n 'aria-label': string\n value: number\n ref?: Ref<HTMLButtonElement>\n}\n\n/**\n * A numbered page item.\n * Should be used within `Pagination.Pages` to ensure proper functionality and accessibility.\n *\n * Can be rendered as an anchor or a button :\n * - Set a `href` prop to render the item as an anchor element.\n * - When using `href`, the `asChild` prop isn’t available since the component will already be rendered as an anchor element.\n */\nexport function Item({ children, value, className, href, ref, ...props }: ItemProps): ReactElement {\n const { pagination } = usePagination()\n\n // ZagJS props\n const apiProps = pagination.getItemProps({ type: 'page', value })\n\n // Locally managed props\n const localProps = {\n 'data-spark-component': 'pagination-item',\n intent: 'support',\n design: apiProps['aria-current'] === 'page' ? 'filled' : 'contrast',\n className: cx('size-sz-44', className),\n ...props,\n }\n\n const mergedProps = mergeProps(apiProps, localProps)\n\n return (\n <li>\n {href ? (\n <Button ref={ref} {...mergedProps} asChild>\n <a href={href}>{children || value}</a>\n </Button>\n ) : (\n <Button ref={ref} {...mergedProps}>\n {children || value}\n </Button>\n )}\n </li>\n )\n}\n\nItem.displayName = 'Pagination.Item'\n","import { ArrowDoubleRight } from '@spark-ui/icons/ArrowDoubleRight'\nimport { mergeProps } from '@zag-js/react'\nimport { ComponentPropsWithoutRef, Ref } from 'react'\n\nimport { Icon } from '../icon'\nimport { IconButton } from '../icon-button'\nimport { usePagination } from './PaginationContext'\n\ntype AnchorProps = ComponentPropsWithoutRef<'a'> & {\n href: string\n asChild?: never\n}\n\ntype ButtonProps = ComponentPropsWithoutRef<'button'> & {\n /**\n * Change the component to the HTML tag or custom component of the only child.\n * Unavailable for anchor items (with `href` prop) since the component will already be rendered as an anchor element.\n */\n asChild?: boolean\n href?: never\n}\n\nexport type LastPageTriggerProps = (AnchorProps | ButtonProps) & {\n 'aria-label': string\n ref?: Ref<HTMLButtonElement>\n}\n\n/**\n * A button that navigates to the last page. Renders a <button> element.\n */\n\nexport const LastPageTrigger = ({\n children,\n className,\n href,\n ref,\n ...props\n}: LastPageTriggerProps) => {\n const { pagination, type } = usePagination()\n\n // ZagJS props\n const apiProps = pagination.getLastPageTriggerProps()\n\n const shouldDisableLink =\n type === 'link' &&\n (apiProps as typeof apiProps & { 'data-disabled'?: string })['data-disabled'] === ''\n\n // Locally managed props\n const localProps = {\n 'data-spark-component': 'pagination-last-page-trigger',\n intent: 'support',\n design: 'contrast',\n ...props,\n className,\n ...(shouldDisableLink && {\n disabled: true,\n role: 'link',\n 'aria-disabled': true,\n }),\n }\n\n // We know 'aria-label' is included in props\n type WithAriaLabel = Omit<typeof apiProps, 'aria-label'> & { 'aria-label': string }\n\n const mergedProps = mergeProps(\n apiProps,\n localProps as unknown as typeof apiProps\n ) as WithAriaLabel\n\n const content = children || (\n <Icon>\n <ArrowDoubleRight />\n </Icon>\n )\n\n return (\n <li>\n {href ? (\n <IconButton ref={ref} {...mergedProps} asChild>\n <a href={shouldDisableLink ? undefined : href}>{content}</a>\n </IconButton>\n ) : (\n <IconButton ref={ref} {...mergedProps}>\n {content}\n </IconButton>\n )}\n </li>\n )\n}\n\nLastPageTrigger.displayName = 'Pagination.LastPageTrigger'\n","import { ArrowVerticalRight } from '@spark-ui/icons/ArrowVerticalRight'\nimport { mergeProps } from '@zag-js/react'\nimport { ComponentPropsWithoutRef, Ref } from 'react'\n\nimport { Icon } from '../icon'\nimport { IconButton } from '../icon-button'\nimport { usePagination } from './PaginationContext'\n\ntype AnchorProps = ComponentPropsWithoutRef<'a'> & {\n href: string\n asChild?: never\n}\n\ntype ButtonProps = ComponentPropsWithoutRef<'button'> & {\n /**\n * Change the component to the HTML tag or custom component of the only child.\n * Unavailable for anchor items (with `href` prop) since the component will already be rendered as an anchor element.\n */\n asChild?: boolean\n href?: never\n}\n\nexport type NextTriggerProps = (AnchorProps | ButtonProps) & {\n 'aria-label': string\n ref?: Ref<HTMLButtonElement>\n}\n\n/**\n * A button that navigates to the next page. Renders a <button> element.\n */\n\nexport const NextTrigger = ({ children, className, href, ref, ...props }: NextTriggerProps) => {\n const { pagination, type } = usePagination()\n\n // ZagJS props\n const apiProps = pagination.getNextTriggerProps()\n\n const shouldDisableLink =\n type === 'link' &&\n (apiProps as typeof apiProps & { 'data-disabled'?: string })['data-disabled'] === ''\n\n // Locally managed props\n const localProps = {\n 'data-spark-component': 'pagination-next-trigger',\n intent: 'support',\n design: 'contrast',\n ...props,\n className,\n ...(shouldDisableLink && {\n disabled: true,\n role: 'link',\n 'aria-disabled': true,\n }),\n }\n\n // We know 'aria-label' is included in props\n type WithAriaLabel = Omit<typeof apiProps, 'aria-label'> & { 'aria-label': string }\n\n const mergedProps = mergeProps(\n apiProps,\n localProps as unknown as typeof apiProps\n ) as WithAriaLabel\n\n const content = children || (\n <Icon>\n <ArrowVerticalRight />\n </Icon>\n )\n\n return (\n <li>\n {href ? (\n <IconButton ref={ref} {...mergedProps} asChild>\n <a href={shouldDisableLink ? undefined : href}>{content}</a>\n </IconButton>\n ) : (\n <IconButton ref={ref} {...mergedProps}>\n {content}\n </IconButton>\n )}\n </li>\n )\n}\n\nNextTrigger.displayName = 'Pagination.NextTrigger'\n","import * as pagination from '@zag-js/pagination'\nimport { ReactNode } from 'react'\n\nimport { usePagination } from './PaginationContext'\n\n// Extract the 'page' type element from the pagination API's 'pages' array.\ntype PageItem = Extract<pagination.Api['pages'][number], { type: 'page' }>\n\n// Define a type that conditionally tweaks the pagination API\n// based on the generic T parameter.\ntype TweakedPaginationApi<T extends 'noEllipsis' | ''> = Omit<pagination.Api, 'pages'> & {\n pages: T extends 'noEllipsis' ? PageItem[] : pagination.Api['pages']\n}\n\ninterface PagesProps<T extends 'noEllipsis' | ''> {\n children: (pagination: TweakedPaginationApi<T>) => ReactNode\n}\n\n/**\n * Container for page number buttons. Renders a <div> element.\n */\n\nexport const Pages = <T extends 'noEllipsis' | '' = ''>({ children }: PagesProps<T>) => {\n const { pagination } = usePagination()\n\n return children(pagination as TweakedPaginationApi<T>)\n}\n\nPages.displayName = 'Pagination.Pages'\n","import { ArrowVerticalLeft } from '@spark-ui/icons/ArrowVerticalLeft'\nimport { mergeProps } from '@zag-js/react'\nimport { ComponentPropsWithoutRef, Ref } from 'react'\n\nimport { Icon } from '../icon'\nimport { IconButton } from '../icon-button'\nimport { usePagination } from './PaginationContext'\n\ntype AnchorProps = ComponentPropsWithoutRef<'a'> & {\n href: string\n asChild?: never\n}\n\ntype ButtonProps = ComponentPropsWithoutRef<'button'> & {\n /**\n * Change the component to the HTML tag or custom component of the only child.\n * Unavailable for anchor items (with `href` prop) since the component will already be rendered as an anchor element.\n */\n asChild?: boolean\n href?: never\n}\n\nexport type PrevTriggerProps = (AnchorProps | ButtonProps) & {\n 'aria-label': string\n ref?: Ref<HTMLButtonElement>\n}\n\n/**\n * A button that navigates to the previous page. Renders a <button> element.\n */\n\nexport const PrevTrigger = ({ children, className, href, ref, ...props }: PrevTriggerProps) => {\n const { pagination, type } = usePagination()\n\n // ZagJS props\n const apiProps = pagination.getPrevTriggerProps()\n\n const shouldDisableLink =\n type === 'link' &&\n (apiProps as typeof apiProps & { 'data-disabled'?: string })['data-disabled'] === ''\n\n // Locally managed props\n const localProps = {\n 'data-spark-component': 'pagination-prev-trigger',\n intent: 'support',\n design: 'contrast',\n ...props,\n className,\n ...(shouldDisableLink && {\n disabled: true,\n role: 'link',\n 'aria-disabled': true,\n }),\n }\n\n // We know 'aria-label' is included in props\n type WithAriaLabel = Omit<typeof apiProps, 'aria-label'> & { 'aria-label': string }\n\n const mergedProps = mergeProps(\n apiProps,\n localProps as unknown as typeof apiProps\n ) as WithAriaLabel\n\n const content = children || (\n <Icon>\n <ArrowVerticalLeft />\n </Icon>\n )\n\n return (\n <li>\n {href ? (\n <IconButton ref={ref} {...mergedProps} asChild>\n <a href={shouldDisableLink ? undefined : href}>{content}</a>\n </IconButton>\n ) : (\n <IconButton ref={ref} {...mergedProps}>\n {content}\n </IconButton>\n )}\n </li>\n )\n}\n\nPrevTrigger.displayName = 'Pagination.PrevTrigger'\n","import type { FC } from 'react'\n\nimport { Pagination as Root, type PaginationProps } from './Pagination'\nimport { Ellipsis } from './PaginationEllipsis'\nimport { FirstPageTrigger } from './PaginationFirstPageTrigger'\nimport { Item } from './PaginationItem'\nimport { LastPageTrigger } from './PaginationLastPageTrigger'\nimport { NextTrigger } from './PaginationNextTrigger'\nimport { Pages } from './PaginationPages'\nimport { PrevTrigger } from './PaginationPrevTrigger'\n\n/**\n * A navigation component that allows users to navigate through multiple pages of content.\n */\nexport const Pagination: FC<PaginationProps> & {\n PrevTrigger: typeof PrevTrigger\n NextTrigger: typeof NextTrigger\n Pages: typeof Pages\n Item: typeof Item\n Ellipsis: typeof Ellipsis\n FirstPageTrigger: typeof FirstPageTrigger\n LastPageTrigger: typeof LastPageTrigger\n} = Object.assign(Root, {\n PrevTrigger,\n NextTrigger,\n Pages,\n Item,\n Ellipsis,\n FirstPageTrigger,\n LastPageTrigger,\n})\n\nPagination.displayName = 'Pagination'\n\nPrevTrigger.displayName = 'Pagination.PrevTrigger'\nNextTrigger.displayName = 'Pagination.NextTrigger'\nPages.displayName = 'Pagination.Pages'\nItem.displayName = 'Pagination.Item'\nEllipsis.displayName = 'Pagination.Ellipsis'\nFirstPageTrigger.displayName = 'Pagination.FirstPageTrigger'\nLastPageTrigger.displayName = 'Pagination.LastPageTrigger'\n"],"mappings":";;;;;;;;;;;;;AAAA,SAAgB,EAAoB,GAAY,GAAe,GAAgB;CAC7E,IAAM,KAAoB,IAAS,KAAK,GAEpC,IAAQ,KAAK,IAAI,GAAG,IAAQ,EAAiB,EAC7C,IAAM,KAAK,IAAI,EAAI,QAAQ,IAAQ,IAAmB,EAAE;AAO5D,QALI,IAAM,IAAQ,MAChB,IAAQ,KAAK,IAAI,GAAG,KAAK,IAAI,GAAO,EAAI,SAAS,EAAO,CAAC,EACzD,IAAM,KAAK,IAAI,EAAI,QAAQ,IAAQ,EAAO,GAGrC,EAAI,MAAM,GAAO,EAAI;;;;ACS9B,IAAM,IAAoB,EAA6C,KAAK,EA4B/D,KAAsB,EACjC,aACA,UACA,sBAAmB,GACnB,aACA,SACA,iBACA,eACA,UAAO,aACsB;CAK7B,IAAM,IAAe,IAAa,WAAW,KAAK,IAAI,GAAG,KAAK,OAAO,IAAmB,KAAK,EAAE,CAAC,EAE1F,IAAK,GAAO,EAEZ,IAAU,EAAW,EAAW,SAAS;EAC7C;EACA;EACA;EACA;EACA;EACA;EACA;EACD,CAAC,EAEI,IAAM,EAAW,QAAQ,GAAS,EAAe,EACjD,IAAQ,IACV,EAAoB,EAAI,OAAO,EAAI,OAAO,GAAG,EAAiB,GAC9D,EAAI;AAER,QACE,kBAAC,EAAkB,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F,IAAM,EAAE,kBAAe,GAAe;AAEtC,QAAO,EAAS,EAAsC;;AAGxD,EAAM,cAAc;;;ACGpB,IAAa,KAAe,EAAE,aAAU,cAAW,SAAM,QAAK,GAAG,QAA8B;CAC7F,IAAM,EAAE,eAAY,YAAS,GAAe,EAGtC,IAAW,EAAW,qBAAqB,EAE3C,IACJ,MAAS,UACR,EAA4D,qBAAqB,IAmB9E,IAAc,EAClB,GAjBiB;EACjB,wBAAwB;EACxB,QAAQ;EACR,QAAQ;EACR,GAAG;EACH;EACA,GAAI,KAAqB;GACvB,UAAU;GACV,MAAM;GACN,iBAAiB;GAClB;EACF,CAQA,EAEK,IAAU,KACd,kBAAC,GAAD,EAAA,UACE,kBAAC,GAAD,EAAqB,CAAA,EAChB,CAAA;AAGT,QACE,kBAAC,MAAD,EAAA,UACG,IACC,kBAAC,GAAD;EAAiB;EAAK,GAAI;EAAa,SAAA;YACrC,kBAAC,KAAD;GAAG,MAAM,IAAoB,KAAA,IAAY;aAAO;GAAY,CAAA;EACjD,CAAA,GAEb,kBAAC,GAAD;EAAiB;EAAK,GAAI;YACvB;EACU,CAAA,EAEZ,CAAA;;AAIT,EAAY,cAAc;;;ACtE1B,IAAa,IAQT,OAAO,OAAO,GAAM;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,EAAW,cAAc,cAEzB,EAAY,cAAc,0BAC1B,EAAY,cAAc,0BAC1B,EAAM,cAAc,oBACpB,EAAK,cAAc,mBACnB,EAAS,cAAc,uBACvB,EAAiB,cAAc,+BAC/B,EAAgB,cAAc"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/pagination/utils.ts","../../src/pagination/PaginationContext.tsx","../../src/pagination/Pagination.tsx","../../src/pagination/PaginationEllipsis.tsx","../../src/pagination/PaginationFirstPageTrigger.tsx","../../src/pagination/PaginationItem.tsx","../../src/pagination/PaginationLastPageTrigger.tsx","../../src/pagination/PaginationNextTrigger.tsx","../../src/pagination/PaginationPages.tsx","../../src/pagination/PaginationPrevTrigger.tsx","../../src/pagination/index.ts"],"sourcesContent":["export function sliceArrayWithIndex(arr: any[], index: number, length: number) {\n const relativeElements = (length - 1) / 2\n\n let start = Math.max(0, index - relativeElements)\n let end = Math.min(arr.length, index + relativeElements + 1)\n\n if (end - start < length) {\n start = Math.max(0, Math.min(start, arr.length - length))\n end = Math.min(arr.length, start + length)\n }\n\n return arr.slice(start, end)\n}\n","import * as pagination from '@zag-js/pagination'\nimport { normalizeProps, type PropTypes, useMachine } from '@zag-js/react'\nimport { createContext, type ReactNode, useContext, useId } from 'react'\n\nimport { sliceArrayWithIndex } from './utils'\n\nexport interface PaginationContextState<T extends PropTypes = PropTypes> {\n type: pagination.Props['type']\n pagination: pagination.Api<T> & {\n getFirstPageTriggerProps: () => ReturnType<pagination.Api<T>['getPrevTriggerProps']> & {\n 'data-part': string\n onClick: () => void\n }\n getLastPageTriggerProps: () => ReturnType<pagination.Api<T>['getNextTriggerProps']> & {\n 'data-part': string\n onClick: () => void\n }\n }\n}\n\nconst PaginationContext = createContext<PaginationContextState | null>(null)\n\nexport interface PaginationProviderProps {\n children: ReactNode\n /**\n * Total number of data items available across all pages.\n */\n count: number\n /**\n * Maximum amount of items displayed on a single page.\n */\n pageSize: number\n /**\n * Number of visible pages (or ellipsis) between previous and next page triggers.\n */\n visiblePageItems?: number\n /**\n * The current page (active page)\n */\n page?: pagination.Props['page']\n /**\n * If your pagination contains buttons instead of links, set `type` to `button`, extra attributes will be applied on page items for a11y.\n */\n type?: pagination.Props['type']\n onPageChange?: pagination.Props['onPageChange']\n noEllipsis?: boolean\n}\n\nexport const PaginationProvider = ({\n children,\n count,\n visiblePageItems = 7,\n pageSize,\n page,\n onPageChange,\n noEllipsis,\n type = 'link',\n}: PaginationProviderProps) => {\n /**\n * Here `Infinity` is used because we apply a custom slice ourselves to manage the \"no ellipsis\" version.\n * It means Zag won't filter out any page item, allowing us to apply our own slicing logic.\n */\n const siblingCount = noEllipsis ? Infinity : Math.max(0, Math.floor((visiblePageItems - 5) / 2))\n\n const id = useId()\n\n const service = useMachine(pagination.machine, {\n id,\n count,\n siblingCount,\n pageSize,\n page,\n onPageChange,\n type,\n })\n\n const api = pagination.connect(service, normalizeProps)\n const pages = noEllipsis\n ? sliceArrayWithIndex(api.pages, api.page - 1, visiblePageItems)\n : api.pages\n\n return (\n <PaginationContext\n value={{\n type,\n pagination: {\n ...api,\n pages,\n // Extending ZagJS anatomy\n getFirstPageTriggerProps: () => {\n return {\n ...api.getPrevTriggerProps(),\n id: `${api.getRootProps().id}:first`,\n 'data-part': 'first-page-trigger',\n onClick: api.goToFirstPage,\n }\n },\n getLastPageTriggerProps: () => {\n return {\n ...api.getNextTriggerProps(),\n id: `${api.getRootProps().id}:last`,\n 'data-part': 'last-page-trigger',\n onClick: api.goToLastPage,\n }\n },\n },\n }}\n >\n {children}\n </PaginationContext>\n )\n}\n\nexport const usePagination = () => {\n const context = useContext(PaginationContext)\n\n if (!context) {\n throw Error('usePagination must be used within a Pagination provider')\n }\n\n return context\n}\n","import { ReactNode } from 'react'\n\nimport {\n PaginationProvider,\n type PaginationProviderProps,\n usePagination,\n} from './PaginationContext'\n\nexport type PaginationProps = PaginationProviderProps & { className?: string }\n\nexport const Pagination = ({\n children,\n visiblePageItems = 5,\n type = 'link',\n noEllipsis = false,\n className,\n ...rest\n}: PaginationProps) => {\n return (\n <PaginationProvider\n visiblePageItems={visiblePageItems}\n noEllipsis={noEllipsis}\n type={type}\n {...rest}\n >\n <PaginationWrapper className={className}>{children}</PaginationWrapper>\n </PaginationProvider>\n )\n}\n\nconst PaginationWrapper = ({\n children,\n className,\n}: {\n children: ReactNode\n className?: string\n}) => {\n const { pagination } = usePagination()\n\n const props = pagination.getRootProps()\n\n return (\n <nav data-spark-component=\"pagination\" {...props} className={className}>\n <ul className=\"gap-md flex flex-wrap\">{children}</ul>\n </nav>\n )\n}\n\nPagination.displayName = 'Pagination'\n","import { mergeProps } from '@zag-js/react'\nimport { cx } from 'class-variance-authority'\nimport { type ComponentPropsWithRef } from 'react'\n\nimport { usePagination } from './PaginationContext'\n\ninterface EllipsisProps extends ComponentPropsWithRef<'span'> {\n index: number\n}\n\n/**\n * An ellipsis indicating skipped pages. Renders a <span> element.\n */\n\nexport const Ellipsis = ({ children, index, className, ref, ...rest }: EllipsisProps) => {\n const { pagination } = usePagination()\n const apiProps = pagination.getEllipsisProps({ index })\n const localProps = {\n className: cx('flex size-sz-44 items-center justify-center', className),\n ...rest,\n }\n\n const mergedProps = mergeProps(apiProps, localProps)\n\n return (\n <li>\n <span data-spark-component=\"pagination-ellipsis\" ref={ref} {...mergedProps}>\n {children || '\\u2026'}\n </span>\n </li>\n )\n}\n\nEllipsis.displayName = 'Pagination.Ellipsis'\n","import { ArrowDoubleLeft } from '@spark-ui/icons/ArrowDoubleLeft'\nimport { mergeProps } from '@zag-js/react'\nimport { ComponentPropsWithoutRef, Ref } from 'react'\n\nimport { Icon } from '../icon'\nimport { IconButton } from '../icon-button'\nimport { usePagination } from './PaginationContext'\n\ntype AnchorProps = ComponentPropsWithoutRef<'a'> & {\n href: string\n asChild?: never\n}\n\ntype ButtonProps = ComponentPropsWithoutRef<'button'> & {\n /**\n * Change the component to the HTML tag or custom component of the only child.\n * Unavailable for anchor items (with `href` prop) since the component will already be rendered as an anchor element.\n */\n asChild?: boolean\n href?: never\n}\n\nexport type FirstPageTriggerProps = (AnchorProps | ButtonProps) & {\n 'aria-label': string\n ref?: Ref<HTMLButtonElement>\n}\n\n/**\n * A button that navigates to the first page. Renders a <button> element.\n */\n\nexport const FirstPageTrigger = ({\n children,\n className,\n href,\n ref,\n ...props\n}: FirstPageTriggerProps) => {\n const { pagination, type } = usePagination()\n\n // ZagJS props\n const apiProps = pagination.getFirstPageTriggerProps()\n\n const shouldDisableLink =\n type === 'link' &&\n (apiProps as typeof apiProps & { 'data-disabled'?: string })['data-disabled'] === ''\n\n // Locally managed props\n const localProps = {\n 'data-spark-component': 'pagination-first-page-trigger',\n intent: 'support',\n design: 'contrast',\n ...props,\n className,\n ...(shouldDisableLink && {\n disabled: true,\n role: 'link',\n 'aria-disabled': true,\n }),\n }\n\n // We know 'aria-label' is included in props\n type WithAriaLabel = Omit<typeof apiProps, 'aria-label'> & { 'aria-label': string }\n\n const mergedProps = mergeProps(\n apiProps,\n localProps as unknown as typeof apiProps\n ) as WithAriaLabel\n\n const content = children || (\n <Icon>\n <ArrowDoubleLeft />\n </Icon>\n )\n\n return (\n <li>\n {href ? (\n <IconButton ref={ref} {...mergedProps} asChild>\n <a href={shouldDisableLink ? undefined : href}>{content}</a>\n </IconButton>\n ) : (\n <IconButton ref={ref} {...mergedProps}>\n {content}\n </IconButton>\n )}\n </li>\n )\n}\n\nFirstPageTrigger.displayName = 'Pagination.FirstPageTrigger'\n","import { mergeProps } from '@zag-js/react'\nimport { cx } from 'class-variance-authority'\nimport { ComponentPropsWithoutRef, ReactElement, Ref } from 'react'\n\nimport { Button } from '../button'\nimport { usePagination } from './PaginationContext'\n\ntype AnchorProps = ComponentPropsWithoutRef<'a'> & {\n href: string\n asChild?: never\n}\n\ntype ButtonProps = ComponentPropsWithoutRef<'button'> & {\n /**\n * Change the component to the HTML tag or custom component of the only child.\n * Unavailable for anchor items (with `href` prop) since the component will already be rendered as an anchor element.\n */\n asChild?: boolean\n href?: never\n}\n\nexport type ItemProps = (AnchorProps | ButtonProps) & {\n 'aria-label': string\n value: number\n ref?: Ref<HTMLButtonElement>\n}\n\n/**\n * A numbered page item.\n * Should be used within `Pagination.Pages` to ensure proper functionality and accessibility.\n *\n * Can be rendered as an anchor or a button :\n * - Set a `href` prop to render the item as an anchor element.\n * - When using `href`, the `asChild` prop isn’t available since the component will already be rendered as an anchor element.\n */\nexport function Item({ children, value, className, href, ref, ...props }: ItemProps): ReactElement {\n const { pagination } = usePagination()\n\n // ZagJS props\n const apiProps = pagination.getItemProps({ type: 'page', value })\n\n // Locally managed props\n const localProps = {\n 'data-spark-component': 'pagination-item',\n intent: 'support',\n design: apiProps['aria-current'] === 'page' ? 'filled' : 'contrast',\n className: cx('size-sz-44', className),\n ...props,\n }\n\n const mergedProps = mergeProps(apiProps, localProps)\n\n return (\n <li>\n {href ? (\n <Button ref={ref} {...mergedProps} asChild>\n <a href={href}>{children || value}</a>\n </Button>\n ) : (\n <Button ref={ref} {...mergedProps}>\n {children || value}\n </Button>\n )}\n </li>\n )\n}\n\nItem.displayName = 'Pagination.Item'\n","import { ArrowDoubleRight } from '@spark-ui/icons/ArrowDoubleRight'\nimport { mergeProps } from '@zag-js/react'\nimport { ComponentPropsWithoutRef, Ref } from 'react'\n\nimport { Icon } from '../icon'\nimport { IconButton } from '../icon-button'\nimport { usePagination } from './PaginationContext'\n\ntype AnchorProps = ComponentPropsWithoutRef<'a'> & {\n href: string\n asChild?: never\n}\n\ntype ButtonProps = ComponentPropsWithoutRef<'button'> & {\n /**\n * Change the component to the HTML tag or custom component of the only child.\n * Unavailable for anchor items (with `href` prop) since the component will already be rendered as an anchor element.\n */\n asChild?: boolean\n href?: never\n}\n\nexport type LastPageTriggerProps = (AnchorProps | ButtonProps) & {\n 'aria-label': string\n ref?: Ref<HTMLButtonElement>\n}\n\n/**\n * A button that navigates to the last page. Renders a <button> element.\n */\n\nexport const LastPageTrigger = ({\n children,\n className,\n href,\n ref,\n ...props\n}: LastPageTriggerProps) => {\n const { pagination, type } = usePagination()\n\n // ZagJS props\n const apiProps = pagination.getLastPageTriggerProps()\n\n const shouldDisableLink =\n type === 'link' &&\n (apiProps as typeof apiProps & { 'data-disabled'?: string })['data-disabled'] === ''\n\n // Locally managed props\n const localProps = {\n 'data-spark-component': 'pagination-last-page-trigger',\n intent: 'support',\n design: 'contrast',\n ...props,\n className,\n ...(shouldDisableLink && {\n disabled: true,\n role: 'link',\n 'aria-disabled': true,\n }),\n }\n\n // We know 'aria-label' is included in props\n type WithAriaLabel = Omit<typeof apiProps, 'aria-label'> & { 'aria-label': string }\n\n const mergedProps = mergeProps(\n apiProps,\n localProps as unknown as typeof apiProps\n ) as WithAriaLabel\n\n const content = children || (\n <Icon>\n <ArrowDoubleRight />\n </Icon>\n )\n\n return (\n <li>\n {href ? (\n <IconButton ref={ref} {...mergedProps} asChild>\n <a href={shouldDisableLink ? undefined : href}>{content}</a>\n </IconButton>\n ) : (\n <IconButton ref={ref} {...mergedProps}>\n {content}\n </IconButton>\n )}\n </li>\n )\n}\n\nLastPageTrigger.displayName = 'Pagination.LastPageTrigger'\n","import { ArrowVerticalRight } from '@spark-ui/icons/ArrowVerticalRight'\nimport { mergeProps } from '@zag-js/react'\nimport { ComponentPropsWithoutRef, Ref } from 'react'\n\nimport { Icon } from '../icon'\nimport { IconButton } from '../icon-button'\nimport { usePagination } from './PaginationContext'\n\ntype AnchorProps = ComponentPropsWithoutRef<'a'> & {\n href: string\n asChild?: never\n}\n\ntype ButtonProps = ComponentPropsWithoutRef<'button'> & {\n /**\n * Change the component to the HTML tag or custom component of the only child.\n * Unavailable for anchor items (with `href` prop) since the component will already be rendered as an anchor element.\n */\n asChild?: boolean\n href?: never\n}\n\nexport type NextTriggerProps = (AnchorProps | ButtonProps) & {\n 'aria-label': string\n ref?: Ref<HTMLButtonElement>\n}\n\n/**\n * A button that navigates to the next page. Renders a <button> element.\n */\n\nexport const NextTrigger = ({ children, className, href, ref, ...props }: NextTriggerProps) => {\n const { pagination, type } = usePagination()\n\n // ZagJS props\n const apiProps = pagination.getNextTriggerProps()\n\n const shouldDisableLink =\n type === 'link' &&\n (apiProps as typeof apiProps & { 'data-disabled'?: string })['data-disabled'] === ''\n\n // Locally managed props\n const localProps = {\n 'data-spark-component': 'pagination-next-trigger',\n intent: 'support',\n design: 'contrast',\n ...props,\n className,\n ...(shouldDisableLink && {\n disabled: true,\n role: 'link',\n 'aria-disabled': true,\n }),\n }\n\n // We know 'aria-label' is included in props\n type WithAriaLabel = Omit<typeof apiProps, 'aria-label'> & { 'aria-label': string }\n\n const mergedProps = mergeProps(\n apiProps,\n localProps as unknown as typeof apiProps\n ) as WithAriaLabel\n\n const content = children || (\n <Icon>\n <ArrowVerticalRight />\n </Icon>\n )\n\n return (\n <li>\n {href ? (\n <IconButton ref={ref} {...mergedProps} asChild>\n <a href={shouldDisableLink ? undefined : href}>{content}</a>\n </IconButton>\n ) : (\n <IconButton ref={ref} {...mergedProps}>\n {content}\n </IconButton>\n )}\n </li>\n )\n}\n\nNextTrigger.displayName = 'Pagination.NextTrigger'\n","import * as pagination from '@zag-js/pagination'\nimport { ReactNode } from 'react'\n\nimport { usePagination } from './PaginationContext'\n\n// Extract the 'page' type element from the pagination API's 'pages' array.\ntype PageItem = Extract<pagination.Api['pages'][number], { type: 'page' }>\n\n// Define a type that conditionally tweaks the pagination API\n// based on the generic T parameter.\ntype TweakedPaginationApi<T extends 'noEllipsis' | ''> = Omit<pagination.Api, 'pages'> & {\n pages: T extends 'noEllipsis' ? PageItem[] : pagination.Api['pages']\n}\n\ninterface PagesProps<T extends 'noEllipsis' | ''> {\n children: (pagination: TweakedPaginationApi<T>) => ReactNode\n}\n\n/**\n * Container for page number buttons. Renders a <div> element.\n */\n\nexport const Pages = <T extends 'noEllipsis' | '' = ''>({ children }: PagesProps<T>) => {\n const { pagination } = usePagination()\n\n return children(pagination as TweakedPaginationApi<T>)\n}\n\nPages.displayName = 'Pagination.Pages'\n","import { ArrowVerticalLeft } from '@spark-ui/icons/ArrowVerticalLeft'\nimport { mergeProps } from '@zag-js/react'\nimport { ComponentPropsWithoutRef, Ref } from 'react'\n\nimport { Icon } from '../icon'\nimport { IconButton } from '../icon-button'\nimport { usePagination } from './PaginationContext'\n\ntype AnchorProps = ComponentPropsWithoutRef<'a'> & {\n href: string\n asChild?: never\n}\n\ntype ButtonProps = ComponentPropsWithoutRef<'button'> & {\n /**\n * Change the component to the HTML tag or custom component of the only child.\n * Unavailable for anchor items (with `href` prop) since the component will already be rendered as an anchor element.\n */\n asChild?: boolean\n href?: never\n}\n\nexport type PrevTriggerProps = (AnchorProps | ButtonProps) & {\n 'aria-label': string\n ref?: Ref<HTMLButtonElement>\n}\n\n/**\n * A button that navigates to the previous page. Renders a <button> element.\n */\n\nexport const PrevTrigger = ({ children, className, href, ref, ...props }: PrevTriggerProps) => {\n const { pagination, type } = usePagination()\n\n // ZagJS props\n const apiProps = pagination.getPrevTriggerProps()\n\n const shouldDisableLink =\n type === 'link' &&\n (apiProps as typeof apiProps & { 'data-disabled'?: string })['data-disabled'] === ''\n\n // Locally managed props\n const localProps = {\n 'data-spark-component': 'pagination-prev-trigger',\n intent: 'support',\n design: 'contrast',\n ...props,\n className,\n ...(shouldDisableLink && {\n disabled: true,\n role: 'link',\n 'aria-disabled': true,\n }),\n }\n\n // We know 'aria-label' is included in props\n type WithAriaLabel = Omit<typeof apiProps, 'aria-label'> & { 'aria-label': string }\n\n const mergedProps = mergeProps(\n apiProps,\n localProps as unknown as typeof apiProps\n ) as WithAriaLabel\n\n const content = children || (\n <Icon>\n <ArrowVerticalLeft />\n </Icon>\n )\n\n return (\n <li>\n {href ? (\n <IconButton ref={ref} {...mergedProps} asChild>\n <a href={shouldDisableLink ? undefined : href}>{content}</a>\n </IconButton>\n ) : (\n <IconButton ref={ref} {...mergedProps}>\n {content}\n </IconButton>\n )}\n </li>\n )\n}\n\nPrevTrigger.displayName = 'Pagination.PrevTrigger'\n","import type { FC } from 'react'\n\nimport { Pagination as Root, type PaginationProps } from './Pagination'\nimport { Ellipsis } from './PaginationEllipsis'\nimport { FirstPageTrigger } from './PaginationFirstPageTrigger'\nimport { Item } from './PaginationItem'\nimport { LastPageTrigger } from './PaginationLastPageTrigger'\nimport { NextTrigger } from './PaginationNextTrigger'\nimport { Pages } from './PaginationPages'\nimport { PrevTrigger } from './PaginationPrevTrigger'\n\n/**\n * A navigation component that allows users to navigate through multiple pages of content.\n */\nexport const Pagination: FC<PaginationProps> & {\n PrevTrigger: typeof PrevTrigger\n NextTrigger: typeof NextTrigger\n Pages: typeof Pages\n Item: typeof Item\n Ellipsis: typeof Ellipsis\n FirstPageTrigger: typeof FirstPageTrigger\n LastPageTrigger: typeof LastPageTrigger\n} = Object.assign(Root, {\n PrevTrigger,\n NextTrigger,\n Pages,\n Item,\n Ellipsis,\n FirstPageTrigger,\n LastPageTrigger,\n})\n\nPagination.displayName = 'Pagination'\n\nPrevTrigger.displayName = 'Pagination.PrevTrigger'\nNextTrigger.displayName = 'Pagination.NextTrigger'\nPages.displayName = 'Pagination.Pages'\nItem.displayName = 'Pagination.Item'\nEllipsis.displayName = 'Pagination.Ellipsis'\nFirstPageTrigger.displayName = 'Pagination.FirstPageTrigger'\nLastPageTrigger.displayName = 'Pagination.LastPageTrigger'\n"],"mappings":";;;;;;;;;;;;;AAAA,SAAgB,EAAoB,GAAY,GAAe,GAAgB;CAC7E,IAAM,KAAoB,IAAS,KAAK,GAEpC,IAAQ,KAAK,IAAI,GAAG,IAAQ,EAAiB,EAC7C,IAAM,KAAK,IAAI,EAAI,QAAQ,IAAQ,IAAmB,EAAE;AAO5D,QALI,IAAM,IAAQ,MAChB,IAAQ,KAAK,IAAI,GAAG,KAAK,IAAI,GAAO,EAAI,SAAS,EAAO,CAAC,EACzD,IAAM,KAAK,IAAI,EAAI,QAAQ,IAAQ,EAAO,GAGrC,EAAI,MAAM,GAAO,EAAI;;;;ACS9B,IAAM,IAAoB,EAA6C,KAAK,EA4B/D,KAAsB,EACjC,aACA,UACA,sBAAmB,GACnB,aACA,SACA,iBACA,eACA,UAAO,aACsB;CAK7B,IAAM,IAAe,IAAa,WAAW,KAAK,IAAI,GAAG,KAAK,OAAO,IAAmB,KAAK,EAAE,CAAC,EAE1F,IAAK,GAAO,EAEZ,IAAU,EAAW,EAAW,SAAS;EAC7C;EACA;EACA;EACA;EACA;EACA;EACA;EACD,CAAC,EAEI,IAAM,EAAW,QAAQ,GAAS,EAAe,EACjD,IAAQ,IACV,EAAoB,EAAI,OAAO,EAAI,OAAO,GAAG,EAAiB,GAC9D,EAAI;AAER,QACE,kBAAC,GAAD;EACE,OAAO;GACL;GACA,YAAY;IACV,GAA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S,EAAsC;;AAGxD,EAAM,cAAc;;;ACGpB,IAAa,KAAe,EAAE,aAAU,cAAW,SAAM,QAAK,GAAG,QAA8B;CAC7F,IAAM,EAAE,eAAY,YAAS,GAAe,EAGtC,IAAW,EAAW,qBAAqB,EAE3C,IACJ,MAAS,UACR,EAA4D,qBAAqB,IAmB9E,IAAc,EAClB,GAjBiB;EACjB,wBAAwB;EACxB,QAAQ;EACR,QAAQ;EACR,GAAG;EACH;EACA,GAAI,KAAqB;GACvB,UAAU;GACV,MAAM;GACN,iBAAiB;GAClB;EACF,CAQA,EAEK,IAAU,KACd,kBAAC,GAAD,EAAA,UACE,kBAAC,GAAD,EAAqB,CAAA,EAChB,CAAA;AAGT,QACE,kBAAC,MAAD,EAAA,UACG,IACC,kBAAC,GAAD;EAAiB;EAAK,GAAI;EAAa,SAAA;YACrC,kBAAC,KAAD;GAAG,MAAM,IAAoB,KAAA,IAAY;aAAO;GAAY,CAAA;EACjD,CAAA,GAEb,kBAAC,GAAD;EAAiB;EAAK,GAAI;YACvB;EACU,CAAA,EAEZ,CAAA;;AAIT,EAAY,cAAc;;;ACtE1B,IAAa,IAQT,OAAO,OAAO,GAAM;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,EAAW,cAAc,cAEzB,EAAY,cAAc,0BAC1B,EAAY,cAAc,0BAC1B,EAAM,cAAc,oBACpB,EAAK,cAAc,mBACnB,EAAS,cAAc,uBACvB,EAAiB,cAAc,+BAC/B,EAAgB,cAAc"}
|
package/dist/popover/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../popover-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../popover-Daknmg_Z.js`);exports.Popover=e.t;
|
package/dist/popover/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as e } from "../popover-
|
|
1
|
+
import { t as e } from "../popover-83FABwMs.mjs";
|
|
2
2
|
export { e as Popover };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as e } from "./icon-D05Uqh8_.mjs";
|
|
2
|
-
import { t } from "./icon-button-
|
|
2
|
+
import { t } from "./icon-button-DVbKK2_a.mjs";
|
|
3
3
|
import { cva as n, cx as r } from "class-variance-authority";
|
|
4
4
|
import { createContext as i, useContext as a, useId as o, useLayoutEffect as s, useState as c } from "react";
|
|
5
5
|
import { Popover as l } from "radix-ui";
|
|
@@ -8,7 +8,7 @@ import { Close as d } from "@spark-ui/icons/Close";
|
|
|
8
8
|
//#region src/popover/PopoverContext.tsx
|
|
9
9
|
var f = i(null), p = ":popover", m = ({ children: e, intent: t }) => {
|
|
10
10
|
let [n, r] = c(null);
|
|
11
|
-
return /* @__PURE__ */ u(f
|
|
11
|
+
return /* @__PURE__ */ u(f, {
|
|
12
12
|
value: {
|
|
13
13
|
headerId: n,
|
|
14
14
|
setHeaderId: r,
|
|
@@ -208,4 +208,4 @@ T.displayName = "Popover", _.displayName = "Popover.Anchor", v.displayName = "Po
|
|
|
208
208
|
//#endregion
|
|
209
209
|
export { T as t };
|
|
210
210
|
|
|
211
|
-
//# sourceMappingURL=popover-
|
|
211
|
+
//# sourceMappingURL=popover-83FABwMs.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"popover-83FABwMs.mjs","names":[],"sources":["../src/popover/PopoverContext.tsx","../src/popover/Popover.tsx","../src/popover/PopoverAnchor.tsx","../src/popover/PopoverArrow.tsx","../src/popover/PopoverCloseButton.tsx","../src/popover/PopoverContent.styles.ts","../src/popover/PopoverContent.tsx","../src/popover/PopoverHeader.tsx","../src/popover/PopoverPortal.tsx","../src/popover/PopoverTrigger.tsx","../src/popover/index.ts"],"sourcesContent":["import { createContext, type ReactNode, useContext, useState } from 'react'\n\ntype HeaderId = string | null\n\nexport type PopoverIntent =\n | 'surface'\n | 'main'\n | 'support'\n | 'accent'\n | 'success'\n | 'alert'\n | 'danger'\n | 'info'\n | 'neutral'\nexport interface PopoverContextState {\n headerId: HeaderId\n setHeaderId: (id: HeaderId) => void\n intent: PopoverIntent\n}\n\nconst PopoverContext = createContext<PopoverContextState | null>(null)\n\nexport const ID_PREFIX = ':popover'\n\nexport const PopoverProvider = ({\n children,\n intent,\n}: {\n children: ReactNode\n intent: PopoverIntent\n}) => {\n const [headerId, setHeaderId] = useState<HeaderId>(null)\n\n return (\n <PopoverContext\n value={{\n headerId,\n setHeaderId,\n intent,\n }}\n >\n {children}\n </PopoverContext>\n )\n}\n\nexport const usePopover = () => {\n const context = useContext(PopoverContext)\n\n if (!context) {\n throw Error('usePopover must be used within a Popover provider')\n }\n\n return context\n}\n","import { Popover as RadixPopover } from 'radix-ui'\n\nimport { type PopoverIntent, PopoverProvider } from './PopoverContext'\n\nexport type PopoverProps = RadixPopover.PopoverProps & {\n intent?: PopoverIntent\n}\n\nexport const Popover = ({ children, intent = 'surface', modal = false, ...rest }: PopoverProps) => {\n return (\n <PopoverProvider intent={intent}>\n <RadixPopover.Root data-spark-component=\"popover\" modal={modal} {...rest}>\n {children}\n </RadixPopover.Root>\n </PopoverProvider>\n )\n}\n\nPopover.displayName = 'Popover'\n","import { Popover as RadixPopover } from 'radix-ui'\nimport { Ref } from 'react'\n\nexport type AnchorProps = RadixPopover.PopoverAnchorProps & {\n ref?: Ref<HTMLDivElement>\n}\n\n/**\n * The anchor element for positioning the popover. Renders a <div> element.\n */\n\nexport const Anchor = ({ asChild = false, children, ref, ...rest }: AnchorProps) => (\n <RadixPopover.Anchor data-spark-component=\"popover-anchor\" ref={ref} asChild={asChild} {...rest}>\n {children}\n </RadixPopover.Anchor>\n)\n\nAnchor.displayName = 'Popover.Anchor'\n","import { cva } from 'class-variance-authority'\nimport { Popover as RadixPopover } from 'radix-ui'\nimport { Ref } from 'react'\n\nimport { usePopover } from './PopoverContext'\n\nexport type ArrowProps = RadixPopover.PopoverArrowProps & {\n ref?: Ref<SVGSVGElement>\n}\n\n/**\n * An arrow pointing to the anchor element. Renders an <svg> element.\n */\n\nexport const Arrow = ({\n asChild = false,\n width = 16,\n height = 8,\n className,\n ref,\n ...rest\n}: ArrowProps) => {\n const { intent } = usePopover()\n\n /**\n * This is necessary to override a Radix UI behaviour.\n * Radix hides the arrow when the Popover is too misaligned from its trigger element.\n */\n const styles = cva('visible', {\n variants: {\n intent: {\n surface: 'fill-surface',\n main: 'fill-main-container',\n support: 'fill-support-container',\n accent: 'fill-accent-container',\n success: 'fill-success-container',\n alert: 'fill-alert-container',\n danger: 'fill-error-container',\n info: 'fill-info-container',\n neutral: 'fill-neutral-container',\n },\n },\n defaultVariants: {\n intent: 'surface',\n },\n })\n\n return (\n <RadixPopover.Arrow\n data-spark-component=\"popover-arrow\"\n ref={ref}\n className={styles({ intent, className })}\n asChild={asChild}\n width={width}\n height={height}\n {...rest}\n />\n )\n}\n\nArrow.displayName = 'Popover.Arrow'\n","import { Close as CloseSVG } from '@spark-ui/icons/Close'\nimport { cx } from 'class-variance-authority'\nimport { Popover as RadixPopover } from 'radix-ui'\nimport { Ref } from 'react'\n\nimport { Icon } from '../icon'\nimport { IconButton } from '../icon-button'\n\nexport type CloseButtonProps = RadixPopover.PopoverCloseProps & {\n 'aria-label': string\n ref?: Ref<HTMLButtonElement>\n}\n\n/**\n * A button that closes the popover. Renders a <button> element.\n */\n\nexport const CloseButton = ({\n 'aria-label': ariaLabel,\n className,\n ref,\n ...rest\n}: CloseButtonProps) => {\n return (\n <RadixPopover.Close\n data-spark-component=\"popover-close-button\"\n ref={ref}\n className={cx('right-lg top-md absolute', className)}\n asChild\n {...rest}\n >\n <IconButton size=\"sm\" intent=\"neutral\" design=\"ghost\" aria-label={ariaLabel}>\n <Icon>\n <CloseSVG />\n </Icon>\n </IconButton>\n </RadixPopover.Close>\n )\n}\n\nCloseButton.displayName = 'Popover.CloseButton'\n","import { cva, VariantProps } from 'class-variance-authority'\n\nexport const styles = cva(\n [\n 'rounded-md',\n 'shadow-sm',\n 'focus-visible:outline-hidden focus-visible:u-outline',\n 'max-h-(--radix-popper-available-height) overflow-y-auto',\n ],\n {\n variants: {\n intent: {\n surface: 'bg-surface text-on-surface',\n main: 'bg-main-container text-on-main-container',\n support: 'bg-support-container text-on-support-container',\n accent: 'bg-accent-container text-on-accent-container',\n success: 'bg-success-container text-on-success-container',\n alert: 'bg-alert-container text-on-alert-container',\n danger: 'bg-error-container text-on-error-container',\n info: 'bg-info-container text-on-info-container',\n neutral: 'bg-neutral-container text-on-neutral-container',\n },\n matchTriggerWidth: {\n true: 'w-(--radix-popper-anchor-width)',\n },\n enforceBoundaries: {\n true: ['max-w-(--radix-popper-available-width)'],\n },\n\n inset: {\n true: 'overflow-hidden',\n false: 'p-lg',\n },\n elevation: {\n dropdown: 'z-dropdown',\n popover: 'z-popover',\n },\n },\n compoundVariants: [\n {\n inset: false,\n /**\n * When there is a close button, padding to the right side must be adjusted to avoid content overlapping with it.\n */\n class: 'has-data-[spark-component=popover-close-button]:pr-3xl',\n },\n {\n enforceBoundaries: false,\n matchTriggerWidth: false,\n class: 'max-w-[min(var(--spacing-sz-384),100vw)]',\n },\n ],\n defaultVariants: {\n matchTriggerWidth: false,\n enforceBoundaries: false,\n inset: false,\n intent: 'surface',\n elevation: 'popover',\n },\n }\n)\n\nexport type StylesProps = VariantProps<typeof styles>\n","import { Popover as RadixPopover } from 'radix-ui'\nimport { Ref } from 'react'\n\nimport { styles, type StylesProps } from './PopoverContent.styles'\nimport { usePopover } from './PopoverContext'\n\nexport type ContentProps = RadixPopover.PopoverContentProps &\n StylesProps & {\n ref?: Ref<HTMLDivElement>\n }\n\n/**\n * The popup element containing popover content. Renders a <div> element.\n */\n\nexport const Content = ({\n // Spark props\n className,\n children,\n matchTriggerWidth = false,\n // Radix props\n align = 'center',\n arrowPadding = 16, // In order not to overlap the arrow on the rounded corners of the popover.\n asChild = false,\n avoidCollisions = true,\n 'aria-labelledby': ariaLabelledBy,\n collisionBoundary,\n collisionPadding = 0,\n hideWhenDetached = false,\n side = 'bottom',\n sideOffset = 8,\n sticky = 'partial',\n inset = false,\n elevation = 'popover',\n ref,\n ...rest\n}: ContentProps) => {\n const { headerId, intent } = usePopover()\n\n return (\n <RadixPopover.Content\n aria-labelledby={headerId || ariaLabelledBy}\n className={styles({\n enforceBoundaries: !!collisionBoundary,\n matchTriggerWidth,\n inset,\n elevation,\n intent,\n className,\n })}\n data-spark-component=\"popover-content\"\n ref={ref}\n {...{\n align,\n arrowPadding,\n asChild,\n avoidCollisions,\n collisionBoundary,\n collisionPadding,\n hideWhenDetached,\n side,\n sideOffset,\n sticky,\n }}\n {...rest}\n >\n {children}\n </RadixPopover.Content>\n )\n}\n\nContent.displayName = 'Popover.Content'\n","import { cx } from 'class-variance-authority'\nimport { type ReactNode, Ref, useId, useLayoutEffect } from 'react'\n\nimport { ID_PREFIX, usePopover } from './PopoverContext'\n\nexport interface HeaderProps {\n children: ReactNode\n className?: string\n ref?: Ref<HTMLDivElement>\n}\n\n/**\n * The header section of the popover. Renders a <header> element.\n */\n\nexport const Header = ({ children, className, ref, ...rest }: HeaderProps) => {\n const id = `${ID_PREFIX}-header-${useId()}`\n const { setHeaderId } = usePopover()\n\n useLayoutEffect(() => {\n setHeaderId(id)\n\n return () => setHeaderId(null)\n }, [id, setHeaderId])\n\n return (\n <header id={id} ref={ref} className={cx('mb-md text-headline-2', className)} {...rest}>\n {children}\n </header>\n )\n}\n\nHeader.displayName = 'Popover.Header'\n","import { Popover as RadixPopover } from 'radix-ui'\nimport { ReactElement } from 'react'\n\nexport type PortalProps = RadixPopover.PopoverPortalProps\n\n/**\n * A portal that renders the popover in a different part of the DOM. Renders a <div> element.\n */\n\nexport const Portal = ({ children, ...rest }: PortalProps): ReactElement => (\n <RadixPopover.Portal {...rest}>{children}</RadixPopover.Portal>\n)\n\nPortal.displayName = 'Popover.Portal'\n","import { Popover as RadixPopover } from 'radix-ui'\nimport { Ref } from 'react'\n\nexport type TriggerProps = RadixPopover.PopoverTriggerProps & {\n ref?: Ref<HTMLButtonElement>\n}\n\n/**\n * A button that opens the popover. Renders a <button> element.\n */\n\nexport const Trigger = ({ asChild = false, children, ref, ...rest }: TriggerProps) => (\n <RadixPopover.Trigger\n data-spark-component=\"popover-trigger\"\n ref={ref}\n asChild={asChild}\n {...rest}\n >\n {children}\n </RadixPopover.Trigger>\n)\n\nTrigger.displayName = 'Popover.Trigger'\n","import { Popover as Root } from './Popover'\nimport { Anchor } from './PopoverAnchor'\nimport { Arrow } from './PopoverArrow'\nimport { CloseButton } from './PopoverCloseButton'\nimport { Content } from './PopoverContent'\nimport { Header } from './PopoverHeader'\nimport { Portal } from './PopoverPortal'\nimport { Trigger } from './PopoverTrigger'\n\n/**\n * A floating container that displays additional content when triggered, positioned relative to its trigger element.\n */\nexport const Popover: typeof Root & {\n Anchor: typeof Anchor\n Arrow: typeof Arrow\n CloseButton: typeof CloseButton\n Content: typeof Content\n Header: typeof Header\n Portal: typeof Portal\n Trigger: typeof Trigger\n} = Object.assign(Root, {\n Anchor,\n Arrow,\n CloseButton,\n Content,\n Header,\n Portal,\n Trigger,\n})\n\nPopover.displayName = 'Popover'\nAnchor.displayName = 'Popover.Anchor'\nArrow.displayName = 'Popover.Arrow'\nCloseButton.displayName = 'Popover.CloseButton'\nContent.displayName = 'Popover.Content'\nHeader.displayName = 'Popover.Header'\nPortal.displayName = 'Popover.Portal'\nTrigger.displayName = 'Popover.Trigger'\n"],"mappings":";;;;;;;;AAoBA,IAAM,IAAiB,EAA0C,KAAK,EAEzD,IAAY,YAEZ,KAAmB,EAC9B,aACA,gBAII;CACJ,IAAM,CAAC,GAAU,KAAe,EAAmB,KAAK;AAExD,QACE,kBAAC,GAAD;EACE,OAAO;GACL;GACA;GACA;GACD;EAEA;EACc,CAAA;GAIR,UAAmB;CAC9B,IAAM,IAAU,EAAW,EAAe;AAE1C,KAAI,CAAC,EACH,OAAM,MAAM,oDAAoD;AAGlE,QAAO;GC7CI,KAAW,EAAE,aAAU,YAA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A;;AAIb,EAAO,cAAc;;;ACvBrB,IAAa,KAAU,EAAE,aAAU,GAAG,QACpC,kBAAC,EAAa,QAAd;CAAqB,GAAI;CAAO;CAA+B,CAAA;AAGjE,EAAO,cAAc;;;ACFrB,IAAa,KAAW,EAAE,aAAU,IAAO,aAAU,QAAK,GAAG,QAC3D,kBAAC,EAAa,SAAd;CACE,wBAAqB;CAChB;CACI;CACT,GAAI;CAEH;CACoB,CAAA;AAGzB,EAAQ,cAAc;;;ACVtB,IAAa,IAQT,OAAO,OAAO,GAAM;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,EAAQ,cAAc,WACtB,EAAO,cAAc,kBACrB,EAAM,cAAc,iBACpB,EAAY,cAAc,uBAC1B,EAAQ,cAAc,mBACtB,EAAO,cAAc,kBACrB,EAAO,cAAc,kBACrB,EAAQ,cAAc"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
require(`./chunk-C91j1N6u.js`);const e=require(`./icon-CRPcdgYp.js`),t=require(`./icon-button-CTe0v0g7.js`);let n=require(`class-variance-authority`),r=require(`react`),i=require(`radix-ui`),a=require(`react/jsx-runtime`),o=require(`@spark-ui/icons/Close`);var s=(0,r.createContext)(null),c=`:popover`,l=({children:e,intent:t})=>{let[n,i]=(0,r.useState)(null);return(0,a.jsx)(s,{value:{headerId:n,setHeaderId:i,intent:t},children:e})},u=()=>{let e=(0,r.useContext)(s);if(!e)throw Error(`usePopover must be used within a Popover provider`);return e},d=({children:e,intent:t=`surface`,modal:n=!1,...r})=>(0,a.jsx)(l,{intent:t,children:(0,a.jsx)(i.Popover.Root,{"data-spark-component":`popover`,modal:n,...r,children:e})});d.displayName=`Popover`;var f=({asChild:e=!1,children:t,ref:n,...r})=>(0,a.jsx)(i.Popover.Anchor,{"data-spark-component":`popover-anchor`,ref:n,asChild:e,...r,children:t});f.displayName=`Popover.Anchor`;var p=({asChild:e=!1,width:t=16,height:r=8,className:o,ref:s,...c})=>{let{intent:l}=u(),d=(0,n.cva)(`visible`,{variants:{intent:{surface:`fill-surface`,main:`fill-main-container`,support:`fill-support-container`,accent:`fill-accent-container`,success:`fill-success-container`,alert:`fill-alert-container`,danger:`fill-error-container`,info:`fill-info-container`,neutral:`fill-neutral-container`}},defaultVariants:{intent:`surface`}});return(0,a.jsx)(i.Popover.Arrow,{"data-spark-component":`popover-arrow`,ref:s,className:d({intent:l,className:o}),asChild:e,width:t,height:r,...c})};p.displayName=`Popover.Arrow`;var m=({"aria-label":r,className:s,ref:c,...l})=>(0,a.jsx)(i.Popover.Close,{"data-spark-component":`popover-close-button`,ref:c,className:(0,n.cx)(`right-lg top-md absolute`,s),asChild:!0,...l,children:(0,a.jsx)(t.t,{size:`sm`,intent:`neutral`,design:`ghost`,"aria-label":r,children:(0,a.jsx)(e.t,{children:(0,a.jsx)(o.Close,{})})})});m.displayName=`Popover.CloseButton`;var h=(0,n.cva)([`rounded-md`,`shadow-sm`,`focus-visible:outline-hidden focus-visible:u-outline`,`max-h-(--radix-popper-available-height) overflow-y-auto`],{variants:{intent:{surface:`bg-surface text-on-surface`,main:`bg-main-container text-on-main-container`,support:`bg-support-container text-on-support-container`,accent:`bg-accent-container text-on-accent-container`,success:`bg-success-container text-on-success-container`,alert:`bg-alert-container text-on-alert-container`,danger:`bg-error-container text-on-error-container`,info:`bg-info-container text-on-info-container`,neutral:`bg-neutral-container text-on-neutral-container`},matchTriggerWidth:{true:`w-(--radix-popper-anchor-width)`},enforceBoundaries:{true:[`max-w-(--radix-popper-available-width)`]},inset:{true:`overflow-hidden`,false:`p-lg`},elevation:{dropdown:`z-dropdown`,popover:`z-popover`}},compoundVariants:[{inset:!1,class:`has-data-[spark-component=popover-close-button]:pr-3xl`},{enforceBoundaries:!1,matchTriggerWidth:!1,class:`max-w-[min(var(--spacing-sz-384),100vw)]`}],defaultVariants:{matchTriggerWidth:!1,enforceBoundaries:!1,inset:!1,intent:`surface`,elevation:`popover`}}),g=({className:e,children:t,matchTriggerWidth:n=!1,align:r=`center`,arrowPadding:o=16,asChild:s=!1,avoidCollisions:c=!0,"aria-labelledby":l,collisionBoundary:d,collisionPadding:f=0,hideWhenDetached:p=!1,side:m=`bottom`,sideOffset:g=8,sticky:_=`partial`,inset:v=!1,elevation:y=`popover`,ref:b,...x})=>{let{headerId:S,intent:C}=u();return(0,a.jsx)(i.Popover.Content,{"aria-labelledby":S||l,className:h({enforceBoundaries:!!d,matchTriggerWidth:n,inset:v,elevation:y,intent:C,className:e}),"data-spark-component":`popover-content`,ref:b,align:r,arrowPadding:o,asChild:s,avoidCollisions:c,collisionBoundary:d,collisionPadding:f,hideWhenDetached:p,side:m,sideOffset:g,sticky:_,...x,children:t})};g.displayName=`Popover.Content`;var _=({children:e,className:t,ref:i,...o})=>{let s=`${c}-header-${(0,r.useId)()}`,{setHeaderId:l}=u();return(0,r.useLayoutEffect)(()=>(l(s),()=>l(null)),[s,l]),(0,a.jsx)(`header`,{id:s,ref:i,className:(0,n.cx)(`mb-md text-headline-2`,t),...o,children:e})};_.displayName=`Popover.Header`;var v=({children:e,...t})=>(0,a.jsx)(i.Popover.Portal,{...t,children:e});v.displayName=`Popover.Portal`;var y=({asChild:e=!1,children:t,ref:n,...r})=>(0,a.jsx)(i.Popover.Trigger,{"data-spark-component":`popover-trigger`,ref:n,asChild:e,...r,children:t});y.displayName=`Popover.Trigger`;var b=Object.assign(d,{Anchor:f,Arrow:p,CloseButton:m,Content:g,Header:_,Portal:v,Trigger:y});b.displayName=`Popover`,f.displayName=`Popover.Anchor`,p.displayName=`Popover.Arrow`,m.displayName=`Popover.CloseButton`,g.displayName=`Popover.Content`,_.displayName=`Popover.Header`,v.displayName=`Popover.Portal`,y.displayName=`Popover.Trigger`,Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return b}});
|
|
2
|
+
//# sourceMappingURL=popover-Daknmg_Z.js.map
|