@yamada-ui/react 2.3.5-dev-20261126021937 → 2.3.5-dev-20261126043909
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/carousel/use-carousel.cjs +1 -1
- package/dist/cjs/components/carousel/use-carousel.cjs.map +1 -1
- package/dist/cjs/components/chart/chart.cjs +29 -9
- package/dist/cjs/components/chart/chart.cjs.map +1 -1
- package/dist/cjs/components/chart/polar-chart.cjs +3 -3
- package/dist/cjs/components/chart/polar-chart.cjs.map +1 -1
- package/dist/cjs/components/dropzone/use-dropzone.cjs +1 -1
- package/dist/cjs/components/dropzone/use-dropzone.cjs.map +1 -1
- package/dist/cjs/components/file-input/use-file-input.cjs +1 -2
- package/dist/cjs/components/file-input/use-file-input.cjs.map +1 -1
- package/dist/cjs/components/infinite-scroll-area/use-infinite-scroll.cjs +4 -2
- package/dist/cjs/components/infinite-scroll-area/use-infinite-scroll.cjs.map +1 -1
- package/dist/cjs/components/loading/loading-provider.cjs +13 -23
- package/dist/cjs/components/loading/loading-provider.cjs.map +1 -1
- package/dist/cjs/components/marquee/use-marquee.cjs +1 -1
- package/dist/cjs/components/marquee/use-marquee.cjs.map +1 -1
- package/dist/cjs/components/menu/use-menu.cjs +7 -1
- package/dist/cjs/components/menu/use-menu.cjs.map +1 -1
- package/dist/cjs/components/native-popover/use-native-popover.cjs +1 -1
- package/dist/cjs/components/native-popover/use-native-popover.cjs.map +1 -1
- package/dist/cjs/components/notice/notice-provider.cjs +23 -23
- package/dist/cjs/components/notice/notice-provider.cjs.map +1 -1
- package/dist/cjs/components/notice/notice.cjs +4 -3
- package/dist/cjs/components/notice/notice.cjs.map +1 -1
- package/dist/cjs/components/popover/use-popover.cjs +1 -1
- package/dist/cjs/components/popover/use-popover.cjs.map +1 -1
- package/dist/cjs/components/sidebar/use-sidebar.cjs +2 -2
- package/dist/cjs/components/sidebar/use-sidebar.cjs.map +1 -1
- package/dist/cjs/components/textarea/use-textarea.cjs +1 -2
- package/dist/cjs/components/textarea/use-textarea.cjs.map +1 -1
- package/dist/cjs/components/tree/use-tree.cjs +2 -2
- package/dist/cjs/components/tree/use-tree.cjs.map +1 -1
- package/dist/cjs/utils/ref.cjs +8 -7
- package/dist/cjs/utils/ref.cjs.map +1 -1
- package/dist/esm/components/carousel/use-carousel.js +3 -3
- package/dist/esm/components/carousel/use-carousel.js.map +1 -1
- package/dist/esm/components/chart/chart.js +30 -10
- package/dist/esm/components/chart/chart.js.map +1 -1
- package/dist/esm/components/chart/polar-chart.js +3 -3
- package/dist/esm/components/chart/polar-chart.js.map +1 -1
- package/dist/esm/components/dropzone/use-dropzone.js +3 -3
- package/dist/esm/components/dropzone/use-dropzone.js.map +1 -1
- package/dist/esm/components/file-input/use-file-input.js +2 -3
- package/dist/esm/components/file-input/use-file-input.js.map +1 -1
- package/dist/esm/components/infinite-scroll-area/use-infinite-scroll.js +6 -4
- package/dist/esm/components/infinite-scroll-area/use-infinite-scroll.js.map +1 -1
- package/dist/esm/components/loading/loading-provider.js +14 -24
- package/dist/esm/components/loading/loading-provider.js.map +1 -1
- package/dist/esm/components/marquee/use-marquee.js +3 -3
- package/dist/esm/components/marquee/use-marquee.js.map +1 -1
- package/dist/esm/components/menu/use-menu.js +9 -3
- package/dist/esm/components/menu/use-menu.js.map +1 -1
- package/dist/esm/components/native-popover/use-native-popover.js +3 -3
- package/dist/esm/components/native-popover/use-native-popover.js.map +1 -1
- package/dist/esm/components/notice/notice-provider.js +24 -24
- package/dist/esm/components/notice/notice-provider.js.map +1 -1
- package/dist/esm/components/notice/notice.js +5 -4
- package/dist/esm/components/notice/notice.js.map +1 -1
- package/dist/esm/components/popover/use-popover.js +3 -3
- package/dist/esm/components/popover/use-popover.js.map +1 -1
- package/dist/esm/components/sidebar/use-sidebar.js +4 -4
- package/dist/esm/components/sidebar/use-sidebar.js.map +1 -1
- package/dist/esm/components/textarea/use-textarea.js +2 -3
- package/dist/esm/components/textarea/use-textarea.js.map +1 -1
- package/dist/esm/components/tree/use-tree.js +4 -4
- package/dist/esm/components/tree/use-tree.js.map +1 -1
- package/dist/esm/utils/ref.js +9 -8
- package/dist/esm/utils/ref.js.map +1 -1
- package/dist/types/components/autocomplete/autocomplete.style.d.ts +1 -1
- package/dist/types/components/calendar/calendar.style.d.ts +2 -2
- package/dist/types/components/carousel/carousel.style.d.ts +2 -2
- package/dist/types/components/chart/cartesian-chart.style.d.ts +1 -1
- package/dist/types/components/chart/chart.d.ts +3 -2
- package/dist/types/components/chart/polar-chart.style.d.ts +1 -1
- package/dist/types/components/checkbox-card/checkbox-card.d.ts +3 -3
- package/dist/types/components/checkbox-card/checkbox-card.style.d.ts +1 -1
- package/dist/types/components/color-picker/color-picker.style.d.ts +1 -1
- package/dist/types/components/color-selector/color-selector.style.d.ts +2 -2
- package/dist/types/components/drawer/drawer.style.d.ts +2 -2
- package/dist/types/components/editable/editable.d.ts +1 -1
- package/dist/types/components/editable/editable.style.d.ts +1 -1
- package/dist/types/components/empty-state/empty-state.style.d.ts +2 -2
- package/dist/types/components/file-button/use-file-button.d.ts +6 -2
- package/dist/types/components/file-input/file-input.style.d.ts +1 -1
- package/dist/types/components/file-input/use-file-input.d.ts +6 -2
- package/dist/types/components/modal/modal.style.d.ts +2 -2
- package/dist/types/components/notice/notice.style.d.ts +1 -1
- package/dist/types/components/number-input/number-input.style.d.ts +1 -1
- package/dist/types/components/radio-card/radio-card.d.ts +3 -3
- package/dist/types/components/radio-card/radio-card.style.d.ts +1 -1
- package/dist/types/components/reorder/reorder.style.d.ts +1 -1
- package/dist/types/components/resizable/resizable.style.d.ts +2 -2
- package/dist/types/components/select/select.style.d.ts +1 -1
- package/dist/types/components/steps/steps.style.d.ts +1 -1
- package/dist/types/components/tag/tag.style.d.ts +1 -1
- package/dist/types/components/timeline/timeline.d.ts +1 -1
- package/dist/types/components/timeline/timeline.style.d.ts +1 -1
- package/dist/types/hooks/use-clickable/index.d.ts +6 -2
- package/dist/types/providers/i18n-provider/i18n-provider.d.ts +1 -1
- package/dist/types/utils/ref.d.ts +9 -3
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-carousel.js","names":["createContext","isFunction","dataAttr","handlerAll"],"sources":["../../../../src/components/carousel/use-carousel.ts"],"sourcesContent":["\"use client\"\n\nimport type {\n EmblaCarouselType,\n EmblaOptionsType,\n EmblaPluginType,\n} from \"embla-carousel\"\nimport type { KeyboardEvent, RefObject } from \"react\"\nimport type {\n HTMLProps,\n Orientation,\n PropGetter,\n RequiredPropGetter,\n} from \"../../core\"\nimport type { FunctionOf } from \"../../utils\"\nimport useEmblaCarousel from \"embla-carousel-react\"\nimport { useCallback, useEffect, useRef, useState } from \"react\"\nimport { mergeProps } from \"../../core\"\nimport { useBoolean } from \"../../hooks/use-boolean\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport { useI18n } from \"../../providers/i18n-provider\"\nimport {\n assignRef,\n createContext,\n dataAttr,\n handlerAll,\n isFunction,\n mergeRefs,\n runKeyAction,\n useIds,\n useUpdateEffect,\n} from \"../../utils\"\n\ntype EmblaOptions = Required<EmblaOptionsType>\nexport type CarouselAlign = EmblaOptions[\"align\"]\nexport type CarouselContainScroll = EmblaOptions[\"containScroll\"]\nexport type CarouselInViewThreshold = EmblaOptions[\"inViewThreshold\"]\nexport type CarouselWatchDrag = EmblaOptions[\"watchDrag\"]\nexport type CarouselWatchResize = EmblaOptions[\"watchResize\"]\nexport type CarouselWatchSlides = EmblaOptions[\"watchSlides\"]\nexport type CarouselControl = EmblaCarouselType\nexport type CarouselPlugin = EmblaPluginType\n\nexport interface CarouselContext extends Omit<\n UseCarouselReturn,\n \"getRootProps\"\n> {}\n\nconst [CarouselContext, useCarouselContext] = createContext<CarouselContext>({\n name: \"CarouselContext\",\n})\n\nexport { CarouselContext, useCarouselContext }\n\nexport interface UseCarouselProps extends Omit<\n HTMLProps<\"section\">,\n \"onChange\"\n> {\n /**\n * The alignment of the carousel.\n *\n * @default 'center'\n */\n align?: CarouselAlign\n /**\n * If `true`, the carousel will be autoplay.\n *\n * @default false\n */\n autoplay?: boolean\n /**\n * Clear leading and trailing empty space that causes excessive scrolling.\n * Use trimSnaps to only use snap points that trigger scrolling or keepSnaps to keep them.\n *\n * @default false\n */\n containScroll?: CarouselContainScroll\n /**\n * Ref of the resizable item callback.\n */\n controlRef?: RefObject<CarouselControl | null>\n /**\n * The initial index of the carousel slide.\n *\n * @default 0\n */\n defaultIndex?: number\n /**\n * The number for the autoplay interval of the carousel.\n *\n * @default 4000\n */\n delay?: number\n /**\n * If `true`, momentum scrolling will be enabled.\n *\n * @default false\n */\n dragFree?: boolean\n /**\n * If `true`, carousel can be scrolled with mouse and touch interactions.\n *\n * @default true\n */\n draggable?: boolean\n /**\n * Set scroll duration when triggered by any of the API methods.\n * Higher numbers enables slower scrolling.\n * Drag interactions are not affected because duration is then determined by the drag force.\n *\n * @default 25\n */\n duration?: number\n /**\n * The index of the carousel slide.\n */\n index?: number\n /**\n * Choose a fraction representing the percentage portion of a slide that needs to be visible in order to be considered in view.\n *\n * @default 0\n */\n inViewThreshold?: CarouselInViewThreshold\n /**\n * If `true`, infinite looping.\n * Automatically falls back to false if slide content isn't enough to loop.\n *\n * @default true\n */\n loop?: boolean\n /**\n * The orientation of the carousel.\n *\n * @default 'horizontal'\n */\n orientation?: Orientation\n /**\n * Embla plugins to use.\n */\n plugins?: CarouselPlugin[]\n /**\n * If `true`, allow the carousel to skip scroll snaps if it's dragged vigorously.\n * Note that this option will be ignored if the dragFree option is set to true.\n *\n * @default false\n */\n skipSnaps?: boolean\n /**\n * The number of slides that should be scrolled with next or previous buttons.\n *\n * @default 1\n */\n slidesToScroll?: number\n /**\n * If `true`, autoplay will pause when the mouse entries over.\n *\n * @default true\n */\n stopMouseEnterAutoplay?: boolean\n /**\n * Enables for scrolling the carousel with mouse and touch interactions.\n * Set this to `false` to disable drag events or pass a custom callback to add your own drag logic.\n *\n * @default true\n */\n watchDrag?: CarouselWatchDrag\n /**\n * Embla automatically watches the container and slides for size changes and runs `reInit` when any size has changed.\n * Set this to `false` to disable this behaviour or pass a custom callback to add your own resize logic.\n *\n * @default true\n */\n watchResize?: CarouselWatchResize\n /**\n * Embla automatically watches the container for added and/or removed slides and runs `reInit` if needed.\n * Set this to `false` to disable this behaviour or pass a custom callback to add your own slides changed logic.\n *\n * @default true\n */\n watchSlides?: CarouselWatchSlides\n /**\n * The callback invoked when carousel slide selected.\n */\n onChange?: (index: number) => void\n /**\n * A callback that return the current scroll amount when the carousel is scrolled.\n */\n onScrollProgress?: (progress: number) => void\n}\n\nexport const useCarousel = ({\n id,\n align = \"center\",\n autoplay = false,\n containScroll = false,\n controlRef,\n defaultIndex = 0,\n delay = 4000,\n dragFree = false,\n draggable = true,\n duration = 25,\n index: indexProp,\n inViewThreshold = 0,\n loop = true,\n orientation = \"horizontal\",\n plugins = [],\n skipSnaps = false,\n slidesToScroll = 1,\n stopMouseEnterAutoplay = true,\n watchDrag = draggable,\n watchResize: watchResizeProp = true,\n watchSlides = true,\n onChange,\n onScrollProgress,\n ...rest\n}: UseCarouselProps = {}) => {\n const { t } = useI18n(\"carousel\")\n const [index, setIndex] = useControllableState({\n defaultValue: defaultIndex,\n value: indexProp,\n onChange,\n })\n const [rootId, listId] = useIds()\n const [hover, { off: onMouseLeave, on: onMouseEnter }] = useBoolean()\n const timeoutId = useRef<NodeJS.Timeout | null>(null)\n const indicatorMapRef = useRef<Map<number, HTMLButtonElement | null>>(\n new Map(),\n )\n const listRef = useRef<HTMLDivElement>(null)\n const horizontal = orientation === \"horizontal\"\n const axis = horizontal ? \"x\" : \"y\"\n const [snapCount, setSnapCount] = useState(0)\n const [total, setTotal] = useState(0)\n const watchResize = useCallback<FunctionOf<CarouselWatchResize>>(\n (methods, entries) => {\n const result = isFunction(watchResizeProp)\n ? watchResizeProp(methods, entries)\n : true\n const snapCount = methods.scrollSnapList().length\n const total = methods.slideNodes().length\n\n setSnapCount(snapCount)\n setTotal(total)\n\n return result\n },\n [watchResizeProp],\n )\n const [carouselRef, carousel] = useEmblaCarousel(\n {\n align,\n axis,\n container: listRef.current,\n containScroll,\n dragFree,\n duration,\n inViewThreshold,\n loop,\n skipSnaps,\n slidesToScroll,\n startIndex: defaultIndex,\n watchDrag,\n watchResize,\n watchSlides,\n },\n plugins,\n )\n\n id ??= rootId\n\n const onInit = useCallback((methods: CarouselControl) => {\n const snapCount = methods.scrollSnapList().length\n const total = methods.slideNodes().length\n\n setSnapCount(snapCount)\n setTotal(total)\n }, [])\n\n const onScroll = useCallback(() => {\n if (!carousel) return\n\n const progress = Math.round(\n Math.max(0, Math.min(1, carousel.scrollProgress())) * 100,\n )\n\n onScrollProgress?.(progress)\n }, [carousel, onScrollProgress])\n\n const onSelect = useCallback(() => {\n if (!carousel) return\n\n const index = carousel.selectedScrollSnap()\n\n setIndex(index)\n }, [carousel, setIndex])\n\n const onFocusIndicator = useCallback(\n (index: number) => {\n const el = indicatorMapRef.current.get(index)\n\n el?.focus()\n carousel?.scrollTo(index)\n },\n [carousel],\n )\n\n const onKeyDown = useCallback(\n (index: number) => (ev: KeyboardEvent<HTMLButtonElement>) => {\n const lastIndex = snapCount - 1\n\n runKeyAction(ev, {\n ArrowDown: () => {\n if (horizontal) return\n\n index = index === lastIndex ? 0 : index + 1\n\n onFocusIndicator(index)\n },\n ArrowLeft: () => {\n if (!horizontal) return\n\n index = index === 0 ? lastIndex : index - 1\n\n onFocusIndicator(index)\n },\n ArrowRight: () => {\n if (!horizontal) return\n\n index = index === lastIndex ? 0 : index + 1\n\n onFocusIndicator(index)\n },\n ArrowUp: () => {\n if (horizontal) return\n\n index = index === 0 ? lastIndex : index - 1\n\n onFocusIndicator(index)\n },\n End: () => {\n onFocusIndicator(lastIndex)\n },\n Home: () => {\n onFocusIndicator(0)\n },\n })\n },\n [snapCount, horizontal, onFocusIndicator],\n )\n\n assignRef(controlRef, carousel)\n\n useEffect(() => {\n if (carousel) {\n carousel.on(\"reInit\", onInit)\n carousel.on(\"select\", onSelect)\n carousel.on(\"scroll\", onScroll)\n\n onScroll()\n\n return () => {\n carousel.off(\"reInit\", onInit)\n carousel.off(\"select\", onSelect)\n carousel.off(\"scroll\", onScroll)\n }\n }\n }, [carousel, onInit, onScroll, onSelect])\n\n useEffect(() => {\n const stop = hover && stopMouseEnterAutoplay\n const last = !carousel?.canScrollNext()\n\n if (carousel && autoplay && !stop && !last) {\n timeoutId.current = setInterval(() => {\n carousel.scrollNext()\n }, delay)\n } else {\n if (timeoutId.current) clearInterval(timeoutId.current)\n\n timeoutId.current = null\n }\n\n return () => {\n if (timeoutId.current) clearInterval(timeoutId.current)\n }\n }, [autoplay, carousel, delay, hover, stopMouseEnterAutoplay])\n\n useUpdateEffect(() => {\n if (!carousel) return\n\n if (indexProp === undefined) return\n\n carousel.scrollTo(indexProp)\n }, [indexProp])\n\n useUpdateEffect(() => {\n if (!carousel) return\n\n carousel.reInit()\n }, [\n carousel,\n total,\n align,\n axis,\n containScroll,\n dragFree,\n duration,\n inViewThreshold,\n loop,\n skipSnaps,\n slidesToScroll,\n ])\n\n const getRootProps: PropGetter<\"section\"> = useCallback(\n ({ ref, ...props } = {}) =>\n mergeProps(\n {\n id,\n \"aria-roledescription\": \"carousel\",\n \"data-orientation\": orientation,\n },\n rest,\n {\n ref,\n onMouseEnter,\n onMouseLeave,\n },\n props,\n )(),\n [id, onMouseEnter, onMouseLeave, rest, orientation],\n )\n\n const getListProps: PropGetter = useCallback(\n ({ ref, ...props } = {}) => ({\n id: listId,\n \"aria-live\": autoplay ? \"off\" : \"polite\",\n \"data-orientation\": orientation,\n ...props,\n ref: mergeRefs(ref, listRef, carouselRef),\n }),\n [autoplay, listId, orientation, carouselRef],\n )\n\n const getItemProps: RequiredPropGetter<\"div\", { index: number }> =\n useCallback(\n ({ index: indexProp, ...props }) => {\n const page = indexProp + 1\n const selected = index === indexProp\n\n return {\n id: `${listId}-${indexProp}`,\n \"aria-label\": t(\"{page} of {total}\", { page, total }),\n \"aria-roledescription\": \"slide\",\n \"data-index\": indexProp.toString(),\n \"data-orientation\": orientation,\n \"data-selected\": dataAttr(selected),\n role: \"tabpanel\",\n ...props,\n }\n },\n [index, listId, total, orientation, t],\n )\n\n const getPrevTriggerProps: PropGetter<\"button\"> = useCallback(\n (props = {}) => ({\n \"aria-controls\": listId,\n \"aria-label\": t(\"Go to previous slide\"),\n \"data-orientation\": orientation,\n disabled: !carousel?.canScrollPrev(),\n ...props,\n onClick: handlerAll(props.onClick, () => carousel?.scrollPrev()),\n }),\n [carousel, listId, orientation, t],\n )\n\n const getNextTriggerProps: PropGetter<\"button\"> = useCallback(\n (props = {}) => ({\n \"aria-controls\": listId,\n \"aria-label\": t(\"Go to next slide\"),\n \"data-orientation\": orientation,\n disabled: !carousel?.canScrollNext(),\n ...props,\n onClick: handlerAll(props.onClick, () => carousel?.scrollNext()),\n }),\n [carousel, listId, orientation, t],\n )\n\n const getIndicatorsProps: PropGetter = useCallback(\n (props = {}) => ({\n \"aria-label\": t(\"Slides\"),\n \"aria-orientation\": orientation,\n role: \"tablist\",\n ...props,\n }),\n [orientation, t],\n )\n\n const getIndicatorProps: RequiredPropGetter<\"button\", { index: number }> =\n useCallback(\n ({ ref, index: indexProp, ...props }) => {\n const page = indexProp + 1\n const selected = index === indexProp\n\n return {\n type: \"button\" as const,\n \"aria-controls\": `${listId}-${indexProp}`,\n \"aria-label\": t(\"Go to {page} slide\", { page }),\n \"aria-selected\": selected,\n \"data-index\": indexProp.toString(),\n \"data-orientation\": orientation,\n \"data-selected\": dataAttr(selected),\n role: \"tab\",\n tabIndex: selected ? 0 : -1,\n ...props,\n ref: mergeRefs(ref, (node) => {\n indicatorMapRef.current.set(indexProp, node)\n }),\n onClick: handlerAll(props.onClick, () =>\n carousel?.scrollTo(indexProp),\n ),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown(indexProp)),\n }\n },\n [index, listId, t, orientation, onKeyDown, carousel],\n )\n\n return {\n carousel,\n index,\n setIndex,\n snapCount,\n total,\n getIndicatorProps,\n getIndicatorsProps,\n getItemProps,\n getListProps,\n getNextTriggerProps,\n getPrevTriggerProps,\n getRootProps,\n }\n}\n\nexport type UseCarouselReturn = ReturnType<typeof useCarousel>\n"],"mappings":";;;;;;;;;;;;;AAgDA,MAAM,CAAC,iBAAiB,sBAAsBA,gBAA+B,EAC3E,MAAM,kBACR,CAAC;AA4ID,MAAa,eAAe,EAC1B,IACA,QAAQ,UACR,WAAW,OACX,gBAAgB,OAChB,YACA,eAAe,GACf,QAAQ,KACR,WAAW,OACX,YAAY,MACZ,WAAW,IACX,OAAO,WACP,kBAAkB,GAClB,OAAO,MACP,cAAc,cACd,UAAU,CAAC,GACX,YAAY,OACZ,iBAAiB,GACjB,yBAAyB,MACzB,YAAY,WACZ,aAAa,kBAAkB,MAC/B,cAAc,MACd,UACA,kBACA,GAAG,SACiB,CAAC,MAAM;CAC3B,MAAM,EAAE,MAAM,QAAQ,UAAU;CAChC,MAAM,CAAC,OAAO,YAAY,qBAAqB;EAC7C,cAAc;EACd,OAAO;EACP;CACF,CAAC;CACD,MAAM,CAAC,QAAQ,UAAU,OAAO;CAChC,MAAM,CAAC,OAAO,EAAE,KAAK,cAAc,IAAI,kBAAkB,WAAW;CACpE,MAAM,YAAY,OAA8B,IAAI;CACpD,MAAM,kBAAkB,uBACtB,IAAI,IAAI,CACV;CACA,MAAM,UAAU,OAAuB,IAAI;CAC3C,MAAM,aAAa,gBAAgB;CACnC,MAAM,OAAO,aAAa,MAAM;CAChC,MAAM,CAAC,WAAW,gBAAgB,SAAS,CAAC;CAC5C,MAAM,CAAC,OAAO,YAAY,SAAS,CAAC;CACpC,MAAM,cAAc,aACjB,SAAS,YAAY;EACpB,MAAM,UAAA,GAASC,cAAAA,WAAAA,CAAW,eAAe,IACrC,gBAAgB,SAAS,OAAO,IAChC;EACJ,MAAM,YAAY,QAAQ,eAAe,CAAC,CAAC;EAC3C,MAAM,QAAQ,QAAQ,WAAW,CAAC,CAAC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AA,CAAW,MAAM,eAAe,UAAU,WAAW,CAAC;CACjE,IACA;EAAC;EAAU;EAAQ;EAAa;CAAC,CACnC;CAEA,MAAM,qBAAiC,aACpC,QAAQ,CAAC,OAAO;EACf,cAAc,EAAE,QAAQ;EACxB,oBAAoB;EACpB,MAAM;EACN,GAAG;CACL,IACA,CAAC,aAAa,CAAC,CACjB;CA+BA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA,mBAlCA,aACG,EAAE,KAAK,OAAO,WAAW,GAAG,YAAY;GACvC,MAAM,OAAO,YAAY;GACzB,MAAM,WAAW,UAAU;GAE3B,OAAO;IACL,MAAM;IACN,iBAAiB,GAAG,OAAO,GAAG;IAC9B,cAAc,EAAE,sBAAsB,EAAE,KAAK,CAAC;IAC9C,iBAAiB;IACjB,cAAc,UAAU,SAAS;IACjC,oBAAoB;IACpB,kBAAA,GAAiBD,cAAAA,SAAAA,CAAS,QAAQ;IAClC,MAAM;IACN,UAAU,WAAW,IAAI;IACzB,GAAG;IACH,KAAK,UAAU,MAAM,SAAS;KAC5B,gBAAgB,QAAQ,IAAI,WAAW,IAAI;IAC7C,CAAC;IACD,UAAA,GAASC,cAAAA,WAAAA,CAAW,MAAM,eACxB,UAAU,SAAS,SAAS,CAC9B;IACA,YAAA,GAAWA,cAAAA,WAAAA,CAAW,MAAM,WAAW,UAAU,SAAS,CAAC;GAC7D;EACF,GACA;GAAC;GAAO;GAAQ;GAAG;GAAa;GAAW;EAAQ,CASrC;EAChB;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"use-carousel.js","names":["createContext","isFunction","dataAttr","handlerAll"],"sources":["../../../../src/components/carousel/use-carousel.ts"],"sourcesContent":["\"use client\"\n\nimport type {\n EmblaCarouselType,\n EmblaOptionsType,\n EmblaPluginType,\n} from \"embla-carousel\"\nimport type { KeyboardEvent, RefObject } from \"react\"\nimport type {\n HTMLProps,\n Orientation,\n PropGetter,\n RequiredPropGetter,\n} from \"../../core\"\nimport type { FunctionOf } from \"../../utils\"\nimport useEmblaCarousel from \"embla-carousel-react\"\nimport {\n useCallback,\n useEffect,\n useImperativeHandle,\n useRef,\n useState,\n} from \"react\"\nimport { mergeProps } from \"../../core\"\nimport { useBoolean } from \"../../hooks/use-boolean\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport { useI18n } from \"../../providers/i18n-provider\"\nimport {\n createContext,\n dataAttr,\n handlerAll,\n isFunction,\n mergeRefs,\n runKeyAction,\n useIds,\n useUpdateEffect,\n} from \"../../utils\"\n\ntype EmblaOptions = Required<EmblaOptionsType>\nexport type CarouselAlign = EmblaOptions[\"align\"]\nexport type CarouselContainScroll = EmblaOptions[\"containScroll\"]\nexport type CarouselInViewThreshold = EmblaOptions[\"inViewThreshold\"]\nexport type CarouselWatchDrag = EmblaOptions[\"watchDrag\"]\nexport type CarouselWatchResize = EmblaOptions[\"watchResize\"]\nexport type CarouselWatchSlides = EmblaOptions[\"watchSlides\"]\nexport type CarouselControl = EmblaCarouselType\nexport type CarouselPlugin = EmblaPluginType\n\nexport interface CarouselContext extends Omit<\n UseCarouselReturn,\n \"getRootProps\"\n> {}\n\nconst [CarouselContext, useCarouselContext] = createContext<CarouselContext>({\n name: \"CarouselContext\",\n})\n\nexport { CarouselContext, useCarouselContext }\n\nexport interface UseCarouselProps extends Omit<\n HTMLProps<\"section\">,\n \"onChange\"\n> {\n /**\n * The alignment of the carousel.\n *\n * @default 'center'\n */\n align?: CarouselAlign\n /**\n * If `true`, the carousel will be autoplay.\n *\n * @default false\n */\n autoplay?: boolean\n /**\n * Clear leading and trailing empty space that causes excessive scrolling.\n * Use trimSnaps to only use snap points that trigger scrolling or keepSnaps to keep them.\n *\n * @default false\n */\n containScroll?: CarouselContainScroll\n /**\n * Ref of the resizable item callback.\n */\n controlRef?: RefObject<CarouselControl | null>\n /**\n * The initial index of the carousel slide.\n *\n * @default 0\n */\n defaultIndex?: number\n /**\n * The number for the autoplay interval of the carousel.\n *\n * @default 4000\n */\n delay?: number\n /**\n * If `true`, momentum scrolling will be enabled.\n *\n * @default false\n */\n dragFree?: boolean\n /**\n * If `true`, carousel can be scrolled with mouse and touch interactions.\n *\n * @default true\n */\n draggable?: boolean\n /**\n * Set scroll duration when triggered by any of the API methods.\n * Higher numbers enables slower scrolling.\n * Drag interactions are not affected because duration is then determined by the drag force.\n *\n * @default 25\n */\n duration?: number\n /**\n * The index of the carousel slide.\n */\n index?: number\n /**\n * Choose a fraction representing the percentage portion of a slide that needs to be visible in order to be considered in view.\n *\n * @default 0\n */\n inViewThreshold?: CarouselInViewThreshold\n /**\n * If `true`, infinite looping.\n * Automatically falls back to false if slide content isn't enough to loop.\n *\n * @default true\n */\n loop?: boolean\n /**\n * The orientation of the carousel.\n *\n * @default 'horizontal'\n */\n orientation?: Orientation\n /**\n * Embla plugins to use.\n */\n plugins?: CarouselPlugin[]\n /**\n * If `true`, allow the carousel to skip scroll snaps if it's dragged vigorously.\n * Note that this option will be ignored if the dragFree option is set to true.\n *\n * @default false\n */\n skipSnaps?: boolean\n /**\n * The number of slides that should be scrolled with next or previous buttons.\n *\n * @default 1\n */\n slidesToScroll?: number\n /**\n * If `true`, autoplay will pause when the mouse entries over.\n *\n * @default true\n */\n stopMouseEnterAutoplay?: boolean\n /**\n * Enables for scrolling the carousel with mouse and touch interactions.\n * Set this to `false` to disable drag events or pass a custom callback to add your own drag logic.\n *\n * @default true\n */\n watchDrag?: CarouselWatchDrag\n /**\n * Embla automatically watches the container and slides for size changes and runs `reInit` when any size has changed.\n * Set this to `false` to disable this behaviour or pass a custom callback to add your own resize logic.\n *\n * @default true\n */\n watchResize?: CarouselWatchResize\n /**\n * Embla automatically watches the container for added and/or removed slides and runs `reInit` if needed.\n * Set this to `false` to disable this behaviour or pass a custom callback to add your own slides changed logic.\n *\n * @default true\n */\n watchSlides?: CarouselWatchSlides\n /**\n * The callback invoked when carousel slide selected.\n */\n onChange?: (index: number) => void\n /**\n * A callback that return the current scroll amount when the carousel is scrolled.\n */\n onScrollProgress?: (progress: number) => void\n}\n\nexport const useCarousel = ({\n id,\n align = \"center\",\n autoplay = false,\n containScroll = false,\n controlRef,\n defaultIndex = 0,\n delay = 4000,\n dragFree = false,\n draggable = true,\n duration = 25,\n index: indexProp,\n inViewThreshold = 0,\n loop = true,\n orientation = \"horizontal\",\n plugins = [],\n skipSnaps = false,\n slidesToScroll = 1,\n stopMouseEnterAutoplay = true,\n watchDrag = draggable,\n watchResize: watchResizeProp = true,\n watchSlides = true,\n onChange,\n onScrollProgress,\n ...rest\n}: UseCarouselProps = {}) => {\n const { t } = useI18n(\"carousel\")\n const [index, setIndex] = useControllableState({\n defaultValue: defaultIndex,\n value: indexProp,\n onChange,\n })\n const [rootId, listId] = useIds()\n const [hover, { off: onMouseLeave, on: onMouseEnter }] = useBoolean()\n const timeoutId = useRef<NodeJS.Timeout | null>(null)\n const indicatorMapRef = useRef<Map<number, HTMLButtonElement | null>>(\n new Map(),\n )\n const listRef = useRef<HTMLDivElement>(null)\n const horizontal = orientation === \"horizontal\"\n const axis = horizontal ? \"x\" : \"y\"\n const [snapCount, setSnapCount] = useState(0)\n const [total, setTotal] = useState(0)\n const watchResize = useCallback<FunctionOf<CarouselWatchResize>>(\n (methods, entries) => {\n const result = isFunction(watchResizeProp)\n ? watchResizeProp(methods, entries)\n : true\n const snapCount = methods.scrollSnapList().length\n const total = methods.slideNodes().length\n\n setSnapCount(snapCount)\n setTotal(total)\n\n return result\n },\n [watchResizeProp],\n )\n const [carouselRef, carousel] = useEmblaCarousel(\n {\n align,\n axis,\n container: listRef.current,\n containScroll,\n dragFree,\n duration,\n inViewThreshold,\n loop,\n skipSnaps,\n slidesToScroll,\n startIndex: defaultIndex,\n watchDrag,\n watchResize,\n watchSlides,\n },\n plugins,\n )\n\n id ??= rootId\n\n const onInit = useCallback((methods: CarouselControl) => {\n const snapCount = methods.scrollSnapList().length\n const total = methods.slideNodes().length\n\n setSnapCount(snapCount)\n setTotal(total)\n }, [])\n\n const onScroll = useCallback(() => {\n if (!carousel) return\n\n const progress = Math.round(\n Math.max(0, Math.min(1, carousel.scrollProgress())) * 100,\n )\n\n onScrollProgress?.(progress)\n }, [carousel, onScrollProgress])\n\n const onSelect = useCallback(() => {\n if (!carousel) return\n\n const index = carousel.selectedScrollSnap()\n\n setIndex(index)\n }, [carousel, setIndex])\n\n const onFocusIndicator = useCallback(\n (index: number) => {\n const el = indicatorMapRef.current.get(index)\n\n el?.focus()\n carousel?.scrollTo(index)\n },\n [carousel],\n )\n\n const onKeyDown = useCallback(\n (index: number) => (ev: KeyboardEvent<HTMLButtonElement>) => {\n const lastIndex = snapCount - 1\n\n runKeyAction(ev, {\n ArrowDown: () => {\n if (horizontal) return\n\n index = index === lastIndex ? 0 : index + 1\n\n onFocusIndicator(index)\n },\n ArrowLeft: () => {\n if (!horizontal) return\n\n index = index === 0 ? lastIndex : index - 1\n\n onFocusIndicator(index)\n },\n ArrowRight: () => {\n if (!horizontal) return\n\n index = index === lastIndex ? 0 : index + 1\n\n onFocusIndicator(index)\n },\n ArrowUp: () => {\n if (horizontal) return\n\n index = index === 0 ? lastIndex : index - 1\n\n onFocusIndicator(index)\n },\n End: () => {\n onFocusIndicator(lastIndex)\n },\n Home: () => {\n onFocusIndicator(0)\n },\n })\n },\n [snapCount, horizontal, onFocusIndicator],\n )\n\n useImperativeHandle<CarouselControl | null, CarouselControl | null>(\n controlRef,\n () => carousel ?? null,\n [carousel],\n )\n\n useEffect(() => {\n if (carousel) {\n carousel.on(\"reInit\", onInit)\n carousel.on(\"select\", onSelect)\n carousel.on(\"scroll\", onScroll)\n\n onScroll()\n\n return () => {\n carousel.off(\"reInit\", onInit)\n carousel.off(\"select\", onSelect)\n carousel.off(\"scroll\", onScroll)\n }\n }\n }, [carousel, onInit, onScroll, onSelect])\n\n useEffect(() => {\n const stop = hover && stopMouseEnterAutoplay\n const last = !carousel?.canScrollNext()\n\n if (carousel && autoplay && !stop && !last) {\n timeoutId.current = setInterval(() => {\n carousel.scrollNext()\n }, delay)\n } else {\n if (timeoutId.current) clearInterval(timeoutId.current)\n\n timeoutId.current = null\n }\n\n return () => {\n if (timeoutId.current) clearInterval(timeoutId.current)\n }\n }, [autoplay, carousel, delay, hover, stopMouseEnterAutoplay])\n\n useUpdateEffect(() => {\n if (!carousel) return\n\n if (indexProp === undefined) return\n\n carousel.scrollTo(indexProp)\n }, [indexProp])\n\n useUpdateEffect(() => {\n if (!carousel) return\n\n carousel.reInit()\n }, [\n carousel,\n total,\n align,\n axis,\n containScroll,\n dragFree,\n duration,\n inViewThreshold,\n loop,\n skipSnaps,\n slidesToScroll,\n ])\n\n const getRootProps: PropGetter<\"section\"> = useCallback(\n ({ ref, ...props } = {}) =>\n mergeProps(\n {\n id,\n \"aria-roledescription\": \"carousel\",\n \"data-orientation\": orientation,\n },\n rest,\n {\n ref,\n onMouseEnter,\n onMouseLeave,\n },\n props,\n )(),\n [id, onMouseEnter, onMouseLeave, rest, orientation],\n )\n\n const getListProps: PropGetter = useCallback(\n ({ ref, ...props } = {}) => ({\n id: listId,\n \"aria-live\": autoplay ? \"off\" : \"polite\",\n \"data-orientation\": orientation,\n ...props,\n ref: mergeRefs(ref, listRef, carouselRef),\n }),\n [autoplay, listId, orientation, carouselRef],\n )\n\n const getItemProps: RequiredPropGetter<\"div\", { index: number }> =\n useCallback(\n ({ index: indexProp, ...props }) => {\n const page = indexProp + 1\n const selected = index === indexProp\n\n return {\n id: `${listId}-${indexProp}`,\n \"aria-label\": t(\"{page} of {total}\", { page, total }),\n \"aria-roledescription\": \"slide\",\n \"data-index\": indexProp.toString(),\n \"data-orientation\": orientation,\n \"data-selected\": dataAttr(selected),\n role: \"tabpanel\",\n ...props,\n }\n },\n [index, listId, total, orientation, t],\n )\n\n const getPrevTriggerProps: PropGetter<\"button\"> = useCallback(\n (props = {}) => ({\n \"aria-controls\": listId,\n \"aria-label\": t(\"Go to previous slide\"),\n \"data-orientation\": orientation,\n disabled: !carousel?.canScrollPrev(),\n ...props,\n onClick: handlerAll(props.onClick, () => carousel?.scrollPrev()),\n }),\n [carousel, listId, orientation, t],\n )\n\n const getNextTriggerProps: PropGetter<\"button\"> = useCallback(\n (props = {}) => ({\n \"aria-controls\": listId,\n \"aria-label\": t(\"Go to next slide\"),\n \"data-orientation\": orientation,\n disabled: !carousel?.canScrollNext(),\n ...props,\n onClick: handlerAll(props.onClick, () => carousel?.scrollNext()),\n }),\n [carousel, listId, orientation, t],\n )\n\n const getIndicatorsProps: PropGetter = useCallback(\n (props = {}) => ({\n \"aria-label\": t(\"Slides\"),\n \"aria-orientation\": orientation,\n role: \"tablist\",\n ...props,\n }),\n [orientation, t],\n )\n\n const getIndicatorProps: RequiredPropGetter<\"button\", { index: number }> =\n useCallback(\n ({ ref, index: indexProp, ...props }) => {\n const page = indexProp + 1\n const selected = index === indexProp\n\n return {\n type: \"button\" as const,\n \"aria-controls\": `${listId}-${indexProp}`,\n \"aria-label\": t(\"Go to {page} slide\", { page }),\n \"aria-selected\": selected,\n \"data-index\": indexProp.toString(),\n \"data-orientation\": orientation,\n \"data-selected\": dataAttr(selected),\n role: \"tab\",\n tabIndex: selected ? 0 : -1,\n ...props,\n ref: mergeRefs(ref, (node) => {\n indicatorMapRef.current.set(indexProp, node)\n }),\n onClick: handlerAll(props.onClick, () =>\n carousel?.scrollTo(indexProp),\n ),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown(indexProp)),\n }\n },\n [index, listId, t, orientation, onKeyDown, carousel],\n )\n\n return {\n carousel,\n index,\n setIndex,\n snapCount,\n total,\n getIndicatorProps,\n getIndicatorsProps,\n getItemProps,\n getListProps,\n getNextTriggerProps,\n getPrevTriggerProps,\n getRootProps,\n }\n}\n\nexport type UseCarouselReturn = ReturnType<typeof useCarousel>\n"],"mappings":";;;;;;;;;;;;;AAqDA,MAAM,CAAC,iBAAiB,sBAAsBA,gBAA+B,EAC3E,MAAM,kBACR,CAAC;AA4ID,MAAa,eAAe,EAC1B,IACA,QAAQ,UACR,WAAW,OAC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lCA,aACG,EAAE,KAAK,OAAO,WAAW,GAAG,YAAY;GACvC,MAAM,OAAO,YAAY;GACzB,MAAM,WAAW,UAAU;GAE3B,OAAO;IACL,MAAM;IACN,iBAAiB,GAAG,OAAO,GAAG;IAC9B,cAAc,EAAE,sBAAsB,EAAE,KAAK,CAAC;IAC9C,iBAAiB;IACjB,cAAc,UAAU,SAAS;IACjC,oBAAoB;IACpB,kBAAA,GAAiBD,cAAAA,SAAAA,CAAS,QAAQ;IAClC,MAAM;IACN,UAAU,WAAW,IAAI;IACzB,GAAG;IACH,KAAK,UAAU,MAAM,SAAS;KAC5B,gBAAgB,QAAQ,IAAI,WAAW,IAAI;IAC7C,CAAC;IACD,UAAA,GAASC,cAAAA,WAAAA,CAAW,MAAM,eACxB,UAAU,SAAS,SAAS,CAC9B;IACA,YAAA,GAAWA,cAAAA,WAAAA,CAAW,MAAM,WAAW,UAAU,SAAS,CAAC;GAC7D;EACF,GACA;GAAC;GAAO;GAAQ;GAAG;GAAa;GAAW;EAAQ,CASrC;EAChB;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
@@ -8,7 +8,7 @@ import { varAttr } from "../../core/system/var.js";
|
|
|
8
8
|
import { utils_exports } from "../../utils/index.js";
|
|
9
9
|
import { chartStyle } from "./chart.style.js";
|
|
10
10
|
import { ChartContext, useChart, useChartLabel, useChartLabelList, useChartLegend, useChartTooltip } from "./use-chart.js";
|
|
11
|
-
import { Fragment, isValidElement, useMemo, useRef } from "react";
|
|
11
|
+
import { Fragment, isValidElement, useCallback, useMemo, useRef, useState } from "react";
|
|
12
12
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
13
13
|
import { Label, LabelList, Legend, ResponsiveContainer, Tooltip } from "recharts";
|
|
14
14
|
// src/components/chart/chart.tsx
|
|
@@ -43,7 +43,18 @@ function parseJSON(value) {
|
|
|
43
43
|
const { ComponentContext, PropsContext: ChartPropsContext, useComponentContext: useChartComponentContext, usePropsContext: useChartPropsContext, withContext, withProvider } = createSlotComponent("chart", chartStyle);
|
|
44
44
|
const Chart = withProvider(({ children, components: componentsProp, render, withLegend = false, withTooltip = true, legendProps, responsiveContainerProps, tooltipProps, ...rest }) => {
|
|
45
45
|
const { highlightedDataKey, onHighlight } = useChart();
|
|
46
|
-
const
|
|
46
|
+
const [nameKey, setNameKey] = useState();
|
|
47
|
+
const nameKeysRef = useRef(/* @__PURE__ */ new Map());
|
|
48
|
+
const registerNameKey = useCallback((nameKey) => {
|
|
49
|
+
const nameKeys = nameKeysRef.current;
|
|
50
|
+
const id = Symbol();
|
|
51
|
+
nameKeys.set(id, nameKey);
|
|
52
|
+
setNameKey(nameKey);
|
|
53
|
+
return () => {
|
|
54
|
+
nameKeys.delete(id);
|
|
55
|
+
setNameKey(Array.from(nameKeys.values()).at(-1));
|
|
56
|
+
};
|
|
57
|
+
}, []);
|
|
47
58
|
const components = useMemo(() => [
|
|
48
59
|
...componentsProp,
|
|
49
60
|
{
|
|
@@ -65,10 +76,16 @@ const Chart = withProvider(({ children, components: componentsProp, render, with
|
|
|
65
76
|
onHighlight
|
|
66
77
|
}), [highlightedDataKey, onHighlight]);
|
|
67
78
|
const componentContext = useMemo(() => ({
|
|
68
|
-
|
|
79
|
+
nameKey,
|
|
80
|
+
registerNameKey,
|
|
69
81
|
legendProps,
|
|
70
82
|
tooltipProps
|
|
71
|
-
}), [
|
|
83
|
+
}), [
|
|
84
|
+
legendProps,
|
|
85
|
+
nameKey,
|
|
86
|
+
registerNameKey,
|
|
87
|
+
tooltipProps
|
|
88
|
+
]);
|
|
72
89
|
return /* @__PURE__ */ jsx(ChartContext, {
|
|
73
90
|
value: context,
|
|
74
91
|
children: /* @__PURE__ */ jsx(ComponentContext, {
|
|
@@ -113,13 +130,13 @@ const ChartLegend = withContext((props) => {
|
|
|
113
130
|
});
|
|
114
131
|
}, "legend")();
|
|
115
132
|
const ChartLegendContent = withContext(({ formatter, payload, withSwatch = true, ...rest }) => {
|
|
116
|
-
const {
|
|
133
|
+
const { nameKey } = useChartComponentContext();
|
|
117
134
|
const { getLegendItemProps } = useChartLegendContext();
|
|
118
135
|
return /* @__PURE__ */ jsx(styled.div, {
|
|
119
136
|
...rest,
|
|
120
137
|
children: payload?.map((data, index) => {
|
|
121
138
|
let value = data.value;
|
|
122
|
-
if (
|
|
139
|
+
if (nameKey) value = data.payload?.[nameKey];
|
|
123
140
|
const dataKey = (0, utils_exports.isString)(data.dataKey) || (0, utils_exports.isNumber)(data.dataKey) ? data.dataKey : value;
|
|
124
141
|
const color = parseJSON(data.color);
|
|
125
142
|
const formattedValue = formatter?.(value, data, index) ?? value;
|
|
@@ -167,14 +184,17 @@ const ChartTooltipCursor = withContext("path", "tooltipCursor")(void 0, ({ botto
|
|
|
167
184
|
};
|
|
168
185
|
});
|
|
169
186
|
const ChartTooltipContent = withContext(({ formatter, label: labelProp, labelFormatter, payload, withSwatch = true, ...rest }) => {
|
|
170
|
-
const {
|
|
187
|
+
const { nameKey } = useChartComponentContext();
|
|
171
188
|
const label = labelFormatter ? labelFormatter(labelProp, payload) : labelProp;
|
|
189
|
+
const items = nameKey ? payload.map((data) => ({
|
|
190
|
+
...data,
|
|
191
|
+
name: data.payload[nameKey]
|
|
192
|
+
})) : payload;
|
|
172
193
|
return /* @__PURE__ */ jsxs(styled.div, {
|
|
173
194
|
...rest,
|
|
174
|
-
children: [!(0, utils_exports.isUndefined)(label) && !(0, utils_exports.isNull)(label) ? /* @__PURE__ */ jsx(ChartTooltipLabel, { children: label }) : null, /* @__PURE__ */ jsx(ChartTooltipList, { children:
|
|
175
|
-
if (nameKeyRef.current) data.name = data.payload[nameKeyRef.current];
|
|
195
|
+
children: [!(0, utils_exports.isUndefined)(label) && !(0, utils_exports.isNull)(label) ? /* @__PURE__ */ jsx(ChartTooltipLabel, { children: label }) : null, /* @__PURE__ */ jsx(ChartTooltipList, { children: items.map((data, index) => {
|
|
176
196
|
const color = parseJSON(data.color) || data.payload.fill;
|
|
177
|
-
const result = formatter?.(data.value, data.name, data, index,
|
|
197
|
+
const result = formatter?.(data.value, data.name, data, index, items) ?? ((0, utils_exports.isArray)(data.value) ? data.value.join(", ") : data.value);
|
|
178
198
|
const [value, name] = (0, utils_exports.isArray)(result) ? result : [result, data.name];
|
|
179
199
|
return /* @__PURE__ */ jsxs(ChartTooltipItem, { children: [
|
|
180
200
|
withSwatch ? /* @__PURE__ */ jsx(ChartTooltipSwatch, { bg: color }) : null,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chart.js","names":["createContext","isString","isNumber","isObject","cast","isUndefined","isNull","isArray"],"sources":["../../../../src/components/chart/chart.tsx"],"sourcesContent":["\"use client\"\n\nimport type {\n JSXElementConstructor,\n PropsWithChildren,\n ReactElement,\n ReactNode,\n RefObject,\n} from \"react\"\nimport type {\n ActiveDotProps,\n DataKey,\n DefaultLegendContentProps,\n DotItemDotProps,\n DotProps,\n LabelProps,\n RenderableText,\n ResponsiveContainerProps,\n TooltipContentProps,\n TooltipProps,\n} from \"recharts\"\nimport type {\n CSSProps,\n ExtractStyleValueWithCondition,\n HTMLStyledProps,\n ThemeProps,\n} from \"../../core\"\nimport type { Dict, Merge } from \"../../utils\"\nimport type { ChartStyle } from \"./chart.style\"\nimport type {\n UseChartLabelListProps,\n UseChartLabelProps,\n UseChartLegendProps,\n UseChartLegendReturn,\n UseChartTooltipProps,\n} from \"./use-chart\"\nimport { Fragment, isValidElement, useMemo, useRef } from \"react\"\nimport {\n Label,\n LabelList,\n Legend,\n ResponsiveContainer,\n Tooltip,\n} from \"recharts\"\nimport { createSlotComponent, mergeProps, styled, varAttr } from \"../../core\"\nimport {\n cast,\n createContext,\n isArray,\n isNull,\n isNumber,\n isObject,\n isString,\n isUndefined,\n useSplitChildren,\n} from \"../../utils\"\nimport { chartStyle } from \"./chart.style\"\nimport {\n ChartContext,\n useChart,\n useChartLabel,\n useChartLabelList,\n useChartLegend,\n useChartTooltip,\n} from \"./use-chart\"\n\nexport type ChartDot =\n | ((props: DotItemDotProps) => ReactNode)\n | boolean\n | Merge<Partial<DotProps>, HTMLStyledProps<\"circle\">>\n | ReactElement\n\nexport type ChartActiveDot =\n | ((props: ActiveDotProps) => ReactNode)\n | boolean\n | Merge<Partial<ActiveDotProps>, HTMLStyledProps<\"circle\">>\n | ReactElement\n\nexport type ChartLabel =\n | ((props: any) => ReactElement | RenderableText)\n | boolean\n | (Merge<\n HTMLStyledProps<\"text\">,\n Pick<\n LabelProps,\n | \"angle\"\n | \"content\"\n | \"formatter\"\n | \"index\"\n | \"labelRef\"\n | \"offset\"\n | \"parentViewBox\"\n | \"position\"\n | \"textBreakAll\"\n | \"value\"\n | \"viewBox\"\n | \"zIndex\"\n >\n > & { dataKey?: DataKey<any> })\n | number\n | ReactElement\n | string\n\nexport type ChartLabelList =\n | ((props: LabelProps) => ReactElement | RenderableText)\n | boolean\n | ChartLabelListProps\n | ReactElement\n\nexport type ChartTickLine = boolean | HTMLStyledProps<\"line\">\n\nexport type GradientStrategy = \"invert\" | \"shade\" | \"tint\"\n\nexport function mergeSeries<Y>(\n series: Y[],\n color: CSSProps[\"color\"] = \"mono\",\n strategy: GradientStrategy = \"invert\",\n): (Y & { color: CSSProps[\"color\"] })[] {\n const colors = gradients(series.length, color, strategy)\n\n return series.map((item, index) => ({ ...item, color: colors[index] }))\n}\n\nexport function mergeData<Y>(\n data: Y[],\n color: ExtractStyleValueWithCondition<CSSProps[\"fill\"]> = \"mono\",\n strategy: GradientStrategy = \"invert\",\n): (Y & { fill: CSSProps[\"fill\"] })[] {\n const colors = gradients(data.length, color, strategy)\n\n return data.map((item, index) => ({ ...item, fill: colors[index] }))\n}\n\nexport function gradients(\n length: number,\n color: ExtractStyleValueWithCondition<CSSProps[\"color\"]> = \"mono\",\n strategy: GradientStrategy = \"invert\",\n): CSSProps[\"color\"][] {\n return Array.from({ length }, (_, index) => {\n const value = Math.floor(100 - (100 / length) * index)\n const percent = `${value}%`\n\n if (strategy === \"invert\")\n return [\n `tint(colors.${color as string}, ${percent})`,\n `shade(colors.${color as string}, ${percent})`,\n ]\n else return `${strategy}(colors.${color as string}, ${percent})`\n })\n}\n\nfunction parseJSON(value: any) {\n try {\n return JSON.parse(value)\n } catch {\n return value\n }\n}\n\ninterface ComponentContext extends Pick<\n ChartProps,\n \"legendProps\" | \"tooltipProps\"\n> {\n nameKeyRef: RefObject<string | undefined>\n}\n\nexport interface ChartProps extends HTMLStyledProps, ThemeProps<ChartStyle> {\n /**\n * The components to render the chart components.\n */\n components: {\n component: JSXElementConstructor<any>\n fallback: ReactNode\n }[]\n /**\n * The function to render the chart.\n */\n render: (props: PropsWithChildren) => ReactNode\n /**\n * The color of the label list.\n */\n labelListColor?: CSSProps[\"color\"]\n /**\n * The fill of the label list.\n */\n labelListFill?: CSSProps[\"fill\"]\n /**\n * The fill of the tooltip cursor.\n */\n tooltipCursorFill?: CSSProps[\"fill\"]\n /**\n * The fill opacity of the tooltip cursor.\n */\n tooltipCursorFillOpacity?: CSSProps[\"fillOpacity\"]\n /**\n * The stroke of the tooltip cursor.\n */\n tooltipCursorStroke?: CSSProps[\"stroke\"]\n /**\n * If `true`, legend is visible.\n *\n * @default false\n */\n withLegend?: boolean\n /**\n * If `true`, tooltip is visible.\n *\n * @default true\n */\n withTooltip?: boolean\n /**\n * Props for the legend component.\n */\n legendProps?: ChartLegendProps\n /**\n * Props for the responsive container component.\n */\n responsiveContainerProps?: ResponsiveContainerProps\n /**\n * Props for the tooltip component.\n */\n tooltipProps?: ChartTooltipProps\n}\n\nconst {\n ComponentContext,\n PropsContext: ChartPropsContext,\n useComponentContext: useChartComponentContext,\n usePropsContext: useChartPropsContext,\n withContext,\n withProvider,\n} = createSlotComponent<ChartProps, ChartStyle, ComponentContext>(\n \"chart\",\n chartStyle,\n)\n\nexport { ChartPropsContext, useChartComponentContext, useChartPropsContext }\n\nexport const Chart = withProvider(\n ({\n children,\n components: componentsProp,\n render,\n withLegend = false,\n withTooltip = true,\n legendProps,\n responsiveContainerProps,\n tooltipProps,\n ...rest\n }: ChartProps) => {\n const { highlightedDataKey, onHighlight } = useChart()\n const nameKeyRef = useRef<string | undefined>(undefined)\n const components = useMemo(\n () => [\n ...componentsProp,\n {\n component: ChartLegend,\n fallback: withLegend ? <ChartLegend /> : null,\n },\n {\n component: ChartTooltip,\n fallback: withTooltip ? <ChartTooltip /> : null,\n },\n ],\n [componentsProp, withLegend, withTooltip],\n )\n const [omittedChildren, ...customComponents] = useSplitChildren(\n children,\n ...components.map(({ component }) => component),\n )\n const context = useMemo(\n () => ({\n highlightedDataKey,\n onHighlight,\n }),\n [highlightedDataKey, onHighlight],\n )\n const componentContext = useMemo(\n () => ({\n nameKeyRef,\n legendProps,\n tooltipProps,\n }),\n [legendProps, tooltipProps],\n )\n\n return (\n <ChartContext value={context}>\n <ComponentContext value={componentContext}>\n <styled.div {...rest}>\n <ResponsiveContainer {...responsiveContainerProps}>\n {render({\n children: (\n <>\n {components.map(({ fallback }, index) => (\n <Fragment key={index}>\n {customComponents[index] ?? fallback}\n </Fragment>\n ))}\n\n {omittedChildren}\n </>\n ),\n })}\n </ResponsiveContainer>\n </styled.div>\n </ComponentContext>\n </ChartContext>\n )\n },\n \"root\",\n)(\n undefined,\n ({\n labelListColor,\n labelListFill,\n tooltipCursorFill,\n tooltipCursorFillOpacity,\n tooltipCursorStroke,\n ...rest\n }) => ({\n \"--label-list-color\": varAttr(labelListColor, \"colors\"),\n \"--label-list-fill\": varAttr(labelListFill, \"colors\"),\n \"--tooltip-cursor-fill\": varAttr(tooltipCursorFill, \"colors\"),\n \"--tooltip-cursor-fill-opacity\": tooltipCursorFillOpacity,\n \"--tooltip-cursor-stroke\": varAttr(tooltipCursorStroke, \"colors\"),\n ...rest,\n }),\n)\n\ninterface ChartLegendContext extends Pick<\n UseChartLegendReturn,\n \"getLegendItemProps\"\n> {}\n\nconst [ChartLegendContext, useChartLegendContext] =\n createContext<ChartLegendContext>({\n name: \"ChartLegendContext\",\n })\n\nexport interface ChartLegendProps extends Merge<\n HTMLStyledProps,\n UseChartLegendProps\n> {\n /**\n * Props for the content component.\n */\n contentProps?: Omit<ChartLegendContentProps, \"formatter\" | \"payload\">\n}\n\nexport const ChartLegend = withContext<\"div\", ChartLegendProps>((props) => {\n const { legendProps } = useChartComponentContext()\n const { contentProps, ...rest } = mergeProps(legendProps, props)()\n const {\n getLegendContentProps,\n getLegendItemProps,\n getLegendProps,\n getRootProps,\n } = useChartLegend({\n content: ({ formatter, payload }) => (\n <ChartLegendContent\n formatter={formatter}\n payload={payload}\n {...getLegendContentProps(contentProps)}\n />\n ),\n ...rest,\n })\n const context = useMemo(() => ({ getLegendItemProps }), [getLegendItemProps])\n\n return (\n <ChartLegendContext value={context}>\n <styled.div asChild {...getRootProps()}>\n <Legend {...getLegendProps()} />\n </styled.div>\n </ChartLegendContext>\n )\n}, \"legend\")()\n\ninterface ChartLegendContentProps\n extends\n HTMLStyledProps,\n Pick<DefaultLegendContentProps, \"formatter\" | \"payload\"> {\n /**\n * If `true`, swatch is visible.\n */\n withSwatch?: boolean\n}\n\nconst ChartLegendContent = withContext<\"div\", ChartLegendContentProps>(\n ({ formatter, payload, withSwatch = true, ...rest }) => {\n const { nameKeyRef } = useChartComponentContext()\n const { getLegendItemProps } = useChartLegendContext()\n\n return (\n <styled.div {...rest}>\n {payload?.map((data, index) => {\n let value = data.value\n\n if (nameKeyRef.current)\n value = (data.payload as any)?.[nameKeyRef.current]\n\n const dataKey =\n isString(data.dataKey) || isNumber(data.dataKey)\n ? data.dataKey\n : value\n const color = parseJSON(data.color)\n const formattedValue = formatter?.(value, data, index) ?? value\n\n return (\n <ChartLegendItem key={index} {...getLegendItemProps({ dataKey })}>\n {withSwatch ? <ChartLegendSwatch bg={color} /> : null}\n <ChartLegendValue>{formattedValue}</ChartLegendValue>\n </ChartLegendItem>\n )\n })}\n </styled.div>\n )\n },\n \"legendContent\",\n)()\n\ninterface ChartLegendItemProps extends HTMLStyledProps {}\n\nconst ChartLegendItem = withContext<\"div\", ChartLegendItemProps>(\n \"div\",\n \"legendItem\",\n)()\n\ninterface ChartLegendSwatchProps extends HTMLStyledProps {}\n\nconst ChartLegendSwatch = withContext<\"div\", ChartLegendSwatchProps>(\n \"div\",\n \"legendSwatch\",\n)()\n\ninterface ChartLegendValueProps extends HTMLStyledProps<\"span\"> {}\n\nconst ChartLegendValue = withContext<\"span\", ChartLegendValueProps>(\n \"span\",\n \"legendValue\",\n)()\n\nexport interface ChartTooltipProps<\n Y extends (number | string)[] | number | string = number,\n M extends number | string = string,\n> extends Omit<Merge<HTMLStyledProps, UseChartTooltipProps<Y, M>>, \"cursor\"> {\n /**\n * Props for the cursor component.\n */\n cursor?: boolean | ChartTooltipCursorProps | ReactElement\n /**\n * Props for the content component.\n */\n contentProps?: Omit<\n ChartTooltipContentProps,\n \"formatter\" | \"label\" | \"labelFormatter\" | \"payload\"\n >\n}\n\nexport const ChartTooltip = <\n Y extends (number | string)[] | number | string,\n M extends number | string,\n>(\n props: ChartTooltipProps<Y, M>,\n) => {\n const { tooltipProps } = useChartComponentContext()\n const {\n cursor = false,\n contentProps,\n ...rest\n } = {\n ...tooltipProps,\n ...props,\n } as ChartTooltipProps<Y, M>\n const { getContentProps, getRootProps } = useChartTooltip<Y, M>({\n content: ({ formatter, label, labelFormatter, payload }) => (\n <ChartTooltipContent\n formatter={formatter}\n label={label}\n labelFormatter={labelFormatter}\n payload={payload}\n {...getContentProps(contentProps)}\n />\n ),\n cursor:\n isValidElement(cursor) || !cursor ? (\n cursor\n ) : (\n <ChartTooltipCursor {...(isObject(cursor) ? cursor : {})} />\n ),\n ...rest,\n })\n\n return <Tooltip {...cast<TooltipProps>(getRootProps())} />\n}\n\ninterface ChartTooltipCursorProps extends Omit<\n HTMLStyledProps<\"path\">,\n \"height\" | \"points\" | \"width\" | \"x\" | \"y\"\n> {\n brushBottom?: number\n height?: number\n payload?: Dict[]\n payloadIndex?: number\n points?: { x: number; y: number }[]\n width?: number\n x?: number\n y?: number\n}\n\nconst ChartTooltipCursor = withContext<\"path\", ChartTooltipCursorProps>(\n \"path\",\n \"tooltipCursor\",\n)(\n undefined,\n ({\n bottom: _bottom,\n brushBottom: _brushBottom,\n fill,\n height,\n left: _left,\n payload: _payload,\n payloadIndex: _payloadIndex,\n points,\n right: _right,\n stroke,\n top: _top,\n width,\n x,\n y,\n ...rest\n }) => {\n const d = points\n ? `M${points[0]?.x},${points[0]?.y}L${points[1]?.x},${points[1]?.y}`\n : `M ${x},${y} h ${width} v ${height} h -${width} Z`\n return {\n asChild: true,\n children: <path d={d} height={height} width={width} />,\n fill: fill === \"#ccc\" ? undefined : fill,\n stroke: stroke === \"#ccc\" ? undefined : stroke,\n ...rest,\n }\n },\n)\n\ninterface ChartTooltipContentProps\n extends\n HTMLStyledProps,\n Pick<\n TooltipContentProps<any, any>,\n \"formatter\" | \"label\" | \"labelFormatter\" | \"payload\"\n > {\n /**\n * If `true`, swatch is visible.\n */\n withSwatch?: boolean\n}\n\nconst ChartTooltipContent = withContext<\"div\", ChartTooltipContentProps>(\n ({\n formatter,\n label: labelProp,\n labelFormatter,\n payload,\n withSwatch = true,\n ...rest\n }) => {\n const { nameKeyRef } = useChartComponentContext()\n const label = labelFormatter\n ? labelFormatter(labelProp, payload)\n : labelProp\n\n return (\n <styled.div {...rest}>\n {!isUndefined(label) && !isNull(label) ? (\n <ChartTooltipLabel>{label}</ChartTooltipLabel>\n ) : null}\n\n <ChartTooltipList>\n {payload.map((data, index) => {\n if (nameKeyRef.current) data.name = data.payload[nameKeyRef.current]\n\n const color = parseJSON(data.color) || data.payload.fill\n const result =\n formatter?.(data.value, data.name, data, index, payload) ??\n (isArray(data.value) ? data.value.join(\", \") : data.value)\n const [value, name] = isArray(result) ? result : [result, data.name]\n\n return (\n <ChartTooltipItem key={index}>\n {withSwatch ? <ChartTooltipSwatch bg={color} /> : null}\n <ChartTooltipName>{name}</ChartTooltipName>\n <ChartTooltipValue>{value}</ChartTooltipValue>\n </ChartTooltipItem>\n )\n })}\n </ChartTooltipList>\n </styled.div>\n )\n },\n \"tooltipContent\",\n)()\n\ninterface ChartTooltipLabel extends HTMLStyledProps<\"p\"> {}\n\nconst ChartTooltipLabel = withContext<\"p\", ChartTooltipLabel>(\n \"p\",\n \"tooltipLabel\",\n)()\n\ninterface ChartTooltipList extends HTMLStyledProps {}\n\nconst ChartTooltipList = withContext<\"div\", ChartTooltipList>(\n \"div\",\n \"tooltipList\",\n)()\n\ninterface ChartTooltipItem extends HTMLStyledProps {}\n\nconst ChartTooltipItem = withContext<\"div\", ChartTooltipItem>(\n \"div\",\n \"tooltipItem\",\n)()\n\ninterface ChartTooltipSwatch extends HTMLStyledProps {}\n\nconst ChartTooltipSwatch = withContext<\"div\", ChartTooltipSwatch>(\n \"div\",\n \"tooltipSwatch\",\n)()\n\ninterface ChartTooltipName extends HTMLStyledProps<\"span\"> {}\n\nconst ChartTooltipName = withContext<\"span\", ChartTooltipName>(\n \"span\",\n \"tooltipName\",\n)()\n\ninterface ChartTooltipValue extends HTMLStyledProps<\"span\"> {}\n\nconst ChartTooltipValue = withContext<\"span\", ChartTooltipValue>(\n \"span\",\n \"tooltipValue\",\n)()\n\nexport interface ChartLabelListProps extends Merge<\n HTMLStyledProps<\"text\">,\n UseChartLabelListProps\n> {}\n\nexport const ChartLabelList = withContext<\"text\", ChartLabelListProps>(\n (props) => {\n const { getLabelListProps, getRootProps } = useChartLabelList(props)\n\n return (\n <styled.text asChild {...getRootProps()}>\n <LabelList {...getLabelListProps()} />\n </styled.text>\n )\n },\n \"labelList\",\n)()\n\nexport interface ChartLabelProps extends Merge<\n HTMLStyledProps<\"text\">,\n UseChartLabelProps\n> {}\n\nexport const ChartLabel = withContext<\"text\", ChartLabelProps>((props) => {\n const { getLabelProps, getRootProps } = useChartLabel(props)\n\n return (\n <styled.text asChild {...getRootProps()}>\n <Label {...getLabelProps()} />\n </styled.text>\n )\n}, \"label\")()\n"],"mappings":";;;;;;;;;;;;;;AAiHA,SAAgB,YACd,QACA,QAA2B,QAC3B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CAAC,CAAC;AAOF,MAAa,iBAAiB,aAC3B,UAAU;CACT,MAAM,EAAE,mBAAmB,iBAAiB,kBAAkB,KAAK;CAEnE,OACE,oBAAC,OAAO,MAAR;EAAa,SAAA;EAAQ,GAAI,aAAa;EACpC,UAAA,oBAAC,WAAD,EAAW,GAAI,kBAAkB,EAAI,CAAA;CAC1B,CAAA;AAEjB,GACA,WACF,CAAC,CAAC;AAOF,MAAa,aAAa,aAAsC,UAAU;CACxE,MAAM,EAAE,eAAe,iBAAiB,cAAc,KAAK;CAE3D,OACE,oBAAC,OAAO,MAAR;EAAa,SAAA;EAAQ,GAAI,aAAa;EACpC,UAAA,oBAAC,OAAD,EAAO,GAAI,cAAc,EAAI,CAAA;CAClB,CAAA;AAEjB,GAAG,OAAO,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"chart.js","names":["createContext","isString","isNumber","isObject","cast","isUndefined","isNull","isArray"],"sources":["../../../../src/components/chart/chart.tsx"],"sourcesContent":["\"use client\"\n\nimport type {\n JSXElementConstructor,\n PropsWithChildren,\n ReactElement,\n ReactNode,\n} from \"react\"\nimport type {\n ActiveDotProps,\n DataKey,\n DefaultLegendContentProps,\n DotItemDotProps,\n DotProps,\n LabelProps,\n RenderableText,\n ResponsiveContainerProps,\n TooltipContentProps,\n TooltipProps,\n} from \"recharts\"\nimport type {\n CSSProps,\n ExtractStyleValueWithCondition,\n HTMLStyledProps,\n ThemeProps,\n} from \"../../core\"\nimport type { Dict, Merge } from \"../../utils\"\nimport type { ChartStyle } from \"./chart.style\"\nimport type {\n UseChartLabelListProps,\n UseChartLabelProps,\n UseChartLegendProps,\n UseChartLegendReturn,\n UseChartTooltipProps,\n} from \"./use-chart\"\nimport {\n Fragment,\n isValidElement,\n useCallback,\n useMemo,\n useRef,\n useState,\n} from \"react\"\nimport {\n Label,\n LabelList,\n Legend,\n ResponsiveContainer,\n Tooltip,\n} from \"recharts\"\nimport { createSlotComponent, mergeProps, styled, varAttr } from \"../../core\"\nimport {\n cast,\n createContext,\n isArray,\n isNull,\n isNumber,\n isObject,\n isString,\n isUndefined,\n useSplitChildren,\n} from \"../../utils\"\nimport { chartStyle } from \"./chart.style\"\nimport {\n ChartContext,\n useChart,\n useChartLabel,\n useChartLabelList,\n useChartLegend,\n useChartTooltip,\n} from \"./use-chart\"\n\nexport type ChartDot =\n | ((props: DotItemDotProps) => ReactNode)\n | boolean\n | Merge<Partial<DotProps>, HTMLStyledProps<\"circle\">>\n | ReactElement\n\nexport type ChartActiveDot =\n | ((props: ActiveDotProps) => ReactNode)\n | boolean\n | Merge<Partial<ActiveDotProps>, HTMLStyledProps<\"circle\">>\n | ReactElement\n\nexport type ChartLabel =\n | ((props: any) => ReactElement | RenderableText)\n | boolean\n | (Merge<\n HTMLStyledProps<\"text\">,\n Pick<\n LabelProps,\n | \"angle\"\n | \"content\"\n | \"formatter\"\n | \"index\"\n | \"labelRef\"\n | \"offset\"\n | \"parentViewBox\"\n | \"position\"\n | \"textBreakAll\"\n | \"value\"\n | \"viewBox\"\n | \"zIndex\"\n >\n > & { dataKey?: DataKey<any> })\n | number\n | ReactElement\n | string\n\nexport type ChartLabelList =\n | ((props: LabelProps) => ReactElement | RenderableText)\n | boolean\n | ChartLabelListProps\n | ReactElement\n\nexport type ChartTickLine = boolean | HTMLStyledProps<\"line\">\n\nexport type GradientStrategy = \"invert\" | \"shade\" | \"tint\"\n\nexport function mergeSeries<Y>(\n series: Y[],\n color: CSSProps[\"color\"] = \"mono\",\n strategy: GradientStrategy = \"invert\",\n): (Y & { color: CSSProps[\"color\"] })[] {\n const colors = gradients(series.length, color, strategy)\n\n return series.map((item, index) => ({ ...item, color: colors[index] }))\n}\n\nexport function mergeData<Y>(\n data: Y[],\n color: ExtractStyleValueWithCondition<CSSProps[\"fill\"]> = \"mono\",\n strategy: GradientStrategy = \"invert\",\n): (Y & { fill: CSSProps[\"fill\"] })[] {\n const colors = gradients(data.length, color, strategy)\n\n return data.map((item, index) => ({ ...item, fill: colors[index] }))\n}\n\nexport function gradients(\n length: number,\n color: ExtractStyleValueWithCondition<CSSProps[\"color\"]> = \"mono\",\n strategy: GradientStrategy = \"invert\",\n): CSSProps[\"color\"][] {\n return Array.from({ length }, (_, index) => {\n const value = Math.floor(100 - (100 / length) * index)\n const percent = `${value}%`\n\n if (strategy === \"invert\")\n return [\n `tint(colors.${color as string}, ${percent})`,\n `shade(colors.${color as string}, ${percent})`,\n ]\n else return `${strategy}(colors.${color as string}, ${percent})`\n })\n}\n\nfunction parseJSON(value: any) {\n try {\n return JSON.parse(value)\n } catch {\n return value\n }\n}\n\ninterface ComponentContext extends Pick<\n ChartProps,\n \"legendProps\" | \"tooltipProps\"\n> {\n nameKey: PropertyKey | undefined\n registerNameKey: (nameKey: PropertyKey) => () => void\n}\n\nexport interface ChartProps extends HTMLStyledProps, ThemeProps<ChartStyle> {\n /**\n * The components to render the chart components.\n */\n components: {\n component: JSXElementConstructor<any>\n fallback: ReactNode\n }[]\n /**\n * The function to render the chart.\n */\n render: (props: PropsWithChildren) => ReactNode\n /**\n * The color of the label list.\n */\n labelListColor?: CSSProps[\"color\"]\n /**\n * The fill of the label list.\n */\n labelListFill?: CSSProps[\"fill\"]\n /**\n * The fill of the tooltip cursor.\n */\n tooltipCursorFill?: CSSProps[\"fill\"]\n /**\n * The fill opacity of the tooltip cursor.\n */\n tooltipCursorFillOpacity?: CSSProps[\"fillOpacity\"]\n /**\n * The stroke of the tooltip cursor.\n */\n tooltipCursorStroke?: CSSProps[\"stroke\"]\n /**\n * If `true`, legend is visible.\n *\n * @default false\n */\n withLegend?: boolean\n /**\n * If `true`, tooltip is visible.\n *\n * @default true\n */\n withTooltip?: boolean\n /**\n * Props for the legend component.\n */\n legendProps?: ChartLegendProps\n /**\n * Props for the responsive container component.\n */\n responsiveContainerProps?: ResponsiveContainerProps\n /**\n * Props for the tooltip component.\n */\n tooltipProps?: ChartTooltipProps\n}\n\nconst {\n ComponentContext,\n PropsContext: ChartPropsContext,\n useComponentContext: useChartComponentContext,\n usePropsContext: useChartPropsContext,\n withContext,\n withProvider,\n} = createSlotComponent<ChartProps, ChartStyle, ComponentContext>(\n \"chart\",\n chartStyle,\n)\n\nexport { ChartPropsContext, useChartComponentContext, useChartPropsContext }\n\nexport const Chart = withProvider(\n ({\n children,\n components: componentsProp,\n render,\n withLegend = false,\n withTooltip = true,\n legendProps,\n responsiveContainerProps,\n tooltipProps,\n ...rest\n }: ChartProps) => {\n const { highlightedDataKey, onHighlight } = useChart()\n const [nameKey, setNameKey] = useState<PropertyKey>()\n const nameKeysRef = useRef(new Map<symbol, PropertyKey>())\n const registerNameKey = useCallback((nameKey: PropertyKey) => {\n const nameKeys = nameKeysRef.current\n const id = Symbol()\n\n nameKeys.set(id, nameKey)\n setNameKey(nameKey)\n\n return () => {\n nameKeys.delete(id)\n setNameKey(Array.from(nameKeys.values()).at(-1))\n }\n }, [])\n const components = useMemo(\n () => [\n ...componentsProp,\n {\n component: ChartLegend,\n fallback: withLegend ? <ChartLegend /> : null,\n },\n {\n component: ChartTooltip,\n fallback: withTooltip ? <ChartTooltip /> : null,\n },\n ],\n [componentsProp, withLegend, withTooltip],\n )\n const [omittedChildren, ...customComponents] = useSplitChildren(\n children,\n ...components.map(({ component }) => component),\n )\n const context = useMemo(\n () => ({\n highlightedDataKey,\n onHighlight,\n }),\n [highlightedDataKey, onHighlight],\n )\n const componentContext = useMemo(\n () => ({\n nameKey,\n registerNameKey,\n legendProps,\n tooltipProps,\n }),\n [legendProps, nameKey, registerNameKey, tooltipProps],\n )\n\n return (\n <ChartContext value={context}>\n <ComponentContext value={componentContext}>\n <styled.div {...rest}>\n <ResponsiveContainer {...responsiveContainerProps}>\n {render({\n children: (\n <>\n {components.map(({ fallback }, index) => (\n <Fragment key={index}>\n {customComponents[index] ?? fallback}\n </Fragment>\n ))}\n\n {omittedChildren}\n </>\n ),\n })}\n </ResponsiveContainer>\n </styled.div>\n </ComponentContext>\n </ChartContext>\n )\n },\n \"root\",\n)(\n undefined,\n ({\n labelListColor,\n labelListFill,\n tooltipCursorFill,\n tooltipCursorFillOpacity,\n tooltipCursorStroke,\n ...rest\n }) => ({\n \"--label-list-color\": varAttr(labelListColor, \"colors\"),\n \"--label-list-fill\": varAttr(labelListFill, \"colors\"),\n \"--tooltip-cursor-fill\": varAttr(tooltipCursorFill, \"colors\"),\n \"--tooltip-cursor-fill-opacity\": tooltipCursorFillOpacity,\n \"--tooltip-cursor-stroke\": varAttr(tooltipCursorStroke, \"colors\"),\n ...rest,\n }),\n)\n\ninterface ChartLegendContext extends Pick<\n UseChartLegendReturn,\n \"getLegendItemProps\"\n> {}\n\nconst [ChartLegendContext, useChartLegendContext] =\n createContext<ChartLegendContext>({\n name: \"ChartLegendContext\",\n })\n\nexport interface ChartLegendProps extends Merge<\n HTMLStyledProps,\n UseChartLegendProps\n> {\n /**\n * Props for the content component.\n */\n contentProps?: Omit<ChartLegendContentProps, \"formatter\" | \"payload\">\n}\n\nexport const ChartLegend = withContext<\"div\", ChartLegendProps>((props) => {\n const { legendProps } = useChartComponentContext()\n const { contentProps, ...rest } = mergeProps(legendProps, props)()\n const {\n getLegendContentProps,\n getLegendItemProps,\n getLegendProps,\n getRootProps,\n } = useChartLegend({\n content: ({ formatter, payload }) => (\n <ChartLegendContent\n formatter={formatter}\n payload={payload}\n {...getLegendContentProps(contentProps)}\n />\n ),\n ...rest,\n })\n const context = useMemo(() => ({ getLegendItemProps }), [getLegendItemProps])\n\n return (\n <ChartLegendContext value={context}>\n <styled.div asChild {...getRootProps()}>\n <Legend {...getLegendProps()} />\n </styled.div>\n </ChartLegendContext>\n )\n}, \"legend\")()\n\ninterface ChartLegendContentProps\n extends\n HTMLStyledProps,\n Pick<DefaultLegendContentProps, \"formatter\" | \"payload\"> {\n /**\n * If `true`, swatch is visible.\n */\n withSwatch?: boolean\n}\n\nconst ChartLegendContent = withContext<\"div\", ChartLegendContentProps>(\n ({ formatter, payload, withSwatch = true, ...rest }) => {\n const { nameKey } = useChartComponentContext()\n const { getLegendItemProps } = useChartLegendContext()\n\n return (\n <styled.div {...rest}>\n {payload?.map((data, index) => {\n let value = data.value\n\n if (nameKey) value = (data.payload as any)?.[nameKey]\n\n const dataKey =\n isString(data.dataKey) || isNumber(data.dataKey)\n ? data.dataKey\n : value\n const color = parseJSON(data.color)\n const formattedValue = formatter?.(value, data, index) ?? value\n\n return (\n <ChartLegendItem key={index} {...getLegendItemProps({ dataKey })}>\n {withSwatch ? <ChartLegendSwatch bg={color} /> : null}\n <ChartLegendValue>{formattedValue}</ChartLegendValue>\n </ChartLegendItem>\n )\n })}\n </styled.div>\n )\n },\n \"legendContent\",\n)()\n\ninterface ChartLegendItemProps extends HTMLStyledProps {}\n\nconst ChartLegendItem = withContext<\"div\", ChartLegendItemProps>(\n \"div\",\n \"legendItem\",\n)()\n\ninterface ChartLegendSwatchProps extends HTMLStyledProps {}\n\nconst ChartLegendSwatch = withContext<\"div\", ChartLegendSwatchProps>(\n \"div\",\n \"legendSwatch\",\n)()\n\ninterface ChartLegendValueProps extends HTMLStyledProps<\"span\"> {}\n\nconst ChartLegendValue = withContext<\"span\", ChartLegendValueProps>(\n \"span\",\n \"legendValue\",\n)()\n\nexport interface ChartTooltipProps<\n Y extends (number | string)[] | number | string = number,\n M extends number | string = string,\n> extends Omit<Merge<HTMLStyledProps, UseChartTooltipProps<Y, M>>, \"cursor\"> {\n /**\n * Props for the cursor component.\n */\n cursor?: boolean | ChartTooltipCursorProps | ReactElement\n /**\n * Props for the content component.\n */\n contentProps?: Omit<\n ChartTooltipContentProps,\n \"formatter\" | \"label\" | \"labelFormatter\" | \"payload\"\n >\n}\n\nexport const ChartTooltip = <\n Y extends (number | string)[] | number | string,\n M extends number | string,\n>(\n props: ChartTooltipProps<Y, M>,\n) => {\n const { tooltipProps } = useChartComponentContext()\n const {\n cursor = false,\n contentProps,\n ...rest\n } = {\n ...tooltipProps,\n ...props,\n } as ChartTooltipProps<Y, M>\n const { getContentProps, getRootProps } = useChartTooltip<Y, M>({\n content: ({ formatter, label, labelFormatter, payload }) => (\n <ChartTooltipContent\n formatter={formatter}\n label={label}\n labelFormatter={labelFormatter}\n payload={payload}\n {...getContentProps(contentProps)}\n />\n ),\n cursor:\n isValidElement(cursor) || !cursor ? (\n cursor\n ) : (\n <ChartTooltipCursor {...(isObject(cursor) ? cursor : {})} />\n ),\n ...rest,\n })\n\n return <Tooltip {...cast<TooltipProps>(getRootProps())} />\n}\n\ninterface ChartTooltipCursorProps extends Omit<\n HTMLStyledProps<\"path\">,\n \"height\" | \"points\" | \"width\" | \"x\" | \"y\"\n> {\n brushBottom?: number\n height?: number\n payload?: Dict[]\n payloadIndex?: number\n points?: { x: number; y: number }[]\n width?: number\n x?: number\n y?: number\n}\n\nconst ChartTooltipCursor = withContext<\"path\", ChartTooltipCursorProps>(\n \"path\",\n \"tooltipCursor\",\n)(\n undefined,\n ({\n bottom: _bottom,\n brushBottom: _brushBottom,\n fill,\n height,\n left: _left,\n payload: _payload,\n payloadIndex: _payloadIndex,\n points,\n right: _right,\n stroke,\n top: _top,\n width,\n x,\n y,\n ...rest\n }) => {\n const d = points\n ? `M${points[0]?.x},${points[0]?.y}L${points[1]?.x},${points[1]?.y}`\n : `M ${x},${y} h ${width} v ${height} h -${width} Z`\n return {\n asChild: true,\n children: <path d={d} height={height} width={width} />,\n fill: fill === \"#ccc\" ? undefined : fill,\n stroke: stroke === \"#ccc\" ? undefined : stroke,\n ...rest,\n }\n },\n)\n\ninterface ChartTooltipContentProps\n extends\n HTMLStyledProps,\n Pick<\n TooltipContentProps<any, any>,\n \"formatter\" | \"label\" | \"labelFormatter\" | \"payload\"\n > {\n /**\n * If `true`, swatch is visible.\n */\n withSwatch?: boolean\n}\n\nconst ChartTooltipContent = withContext<\"div\", ChartTooltipContentProps>(\n ({\n formatter,\n label: labelProp,\n labelFormatter,\n payload,\n withSwatch = true,\n ...rest\n }) => {\n const { nameKey } = useChartComponentContext()\n const label = labelFormatter\n ? labelFormatter(labelProp, payload)\n : labelProp\n const items = nameKey\n ? payload.map((data) => ({ ...data, name: data.payload[nameKey] }))\n : payload\n\n return (\n <styled.div {...rest}>\n {!isUndefined(label) && !isNull(label) ? (\n <ChartTooltipLabel>{label}</ChartTooltipLabel>\n ) : null}\n\n <ChartTooltipList>\n {items.map((data, index) => {\n const color = parseJSON(data.color) || data.payload.fill\n const result =\n formatter?.(data.value, data.name, data, index, items) ??\n (isArray(data.value) ? data.value.join(\", \") : data.value)\n const [value, name] = isArray(result) ? result : [result, data.name]\n\n return (\n <ChartTooltipItem key={index}>\n {withSwatch ? <ChartTooltipSwatch bg={color} /> : null}\n <ChartTooltipName>{name}</ChartTooltipName>\n <ChartTooltipValue>{value}</ChartTooltipValue>\n </ChartTooltipItem>\n )\n })}\n </ChartTooltipList>\n </styled.div>\n )\n },\n \"tooltipContent\",\n)()\n\ninterface ChartTooltipLabel extends HTMLStyledProps<\"p\"> {}\n\nconst ChartTooltipLabel = withContext<\"p\", ChartTooltipLabel>(\n \"p\",\n \"tooltipLabel\",\n)()\n\ninterface ChartTooltipList extends HTMLStyledProps {}\n\nconst ChartTooltipList = withContext<\"div\", ChartTooltipList>(\n \"div\",\n \"tooltipList\",\n)()\n\ninterface ChartTooltipItem extends HTMLStyledProps {}\n\nconst ChartTooltipItem = withContext<\"div\", ChartTooltipItem>(\n \"div\",\n \"tooltipItem\",\n)()\n\ninterface ChartTooltipSwatch extends HTMLStyledProps {}\n\nconst ChartTooltipSwatch = withContext<\"div\", ChartTooltipSwatch>(\n \"div\",\n \"tooltipSwatch\",\n)()\n\ninterface ChartTooltipName extends HTMLStyledProps<\"span\"> {}\n\nconst ChartTooltipName = withContext<\"span\", ChartTooltipName>(\n \"span\",\n \"tooltipName\",\n)()\n\ninterface ChartTooltipValue extends HTMLStyledProps<\"span\"> {}\n\nconst ChartTooltipValue = withContext<\"span\", ChartTooltipValue>(\n \"span\",\n \"tooltipValue\",\n)()\n\nexport interface ChartLabelListProps extends Merge<\n HTMLStyledProps<\"text\">,\n UseChartLabelListProps\n> {}\n\nexport const ChartLabelList = withContext<\"text\", ChartLabelListProps>(\n (props) => {\n const { getLabelListProps, getRootProps } = useChartLabelList(props)\n\n return (\n <styled.text asChild {...getRootProps()}>\n <LabelList {...getLabelListProps()} />\n </styled.text>\n )\n },\n \"labelList\",\n)()\n\nexport interface ChartLabelProps extends Merge<\n HTMLStyledProps<\"text\">,\n UseChartLabelProps\n> {}\n\nexport const ChartLabel = withContext<\"text\", ChartLabelProps>((props) => {\n const { getLabelProps, getRootProps } = useChartLabel(props)\n\n return (\n <styled.text asChild {...getRootProps()}>\n <Label {...getLabelProps()} />\n </styled.text>\n )\n}, \"label\")()\n"],"mappings":";;;;;;;;;;;;;;AAuHA,SAAgB,YACd,QACA,QAA2B,QAC3B,WAA6B,UACS;CACtC,MAAM,SAAS,UAAU,OAAO,QAAQ,OAAO,QAAQ;CAEvD,OAAO,OAAO,KAAK,MAAM,WAAW;EAAE,GAAG;EAAM,OAAO,OAAO;CAAO,EAAE;AACxE;AAEA,SAAgB,UACd,MACA,QAA0D,QAC1D,WAA6B,UACO;CACpC,MAAM,SAAS,UAAU,KAAK,QAAQ,OAAO,QAAQ;CAErD,OAAO,KAAK,KAAK,MAAM,WAAW;EAAE,GAAG;EAAM,MAAM,OAAO;CAAO,EAAE;AACrE;AAEA,SAAgB,UACd,QACA,QAA2D,QAC3D,WAA6B,UACR;CACrB,OAAO,MAAM,KAAK,EAAE,OAAO,IAAI,GAAG,UAAU;EAE1C,MAAM,UAAU,GADF,KAAK,MAAM,MAAO,MAAM,SAAU,KACzB,EAAE;EAEzB,IAAI,aAAa,UACf,OAAO,CACL,eAAe,MAAgB,IAAI,QAAQ,IAC3C,gBAAgB,MAAgB,IAAI,QAAQ,EAC9C;OACG,OAAO,GAAG,SAAS,UAAU,MAAgB,IAAI,QAAQ;CAChE,CAAC;AACH;AAEA,SAAS,UAAU,OAAY;CAC7B,IAAI;EACF,OAAO,KAAK,MAAM,KAAK;CACzB,QAAQ;EACN,OAAO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AAA,oBAAC,OAAD,EAAO,GAAI,cAAc,EAAI,CAAA;CAClB,CAAA;AAEjB,GAAG,OAAO,CAAC,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import { useSafeLayoutEffect } from "../../utils/effect.js";
|
|
3
3
|
import { createShouldForwardProp, mergeProps } from "../../core/components/props.js";
|
|
4
4
|
import { createSlotComponent } from "../../core/components/create-component.js";
|
|
5
5
|
import { getCSS } from "../../core/css/use-css.js";
|
|
@@ -513,10 +513,11 @@ const ChartPolarGrid = withContext((props) => {
|
|
|
513
513
|
}, "grid")();
|
|
514
514
|
const ChartRadial = withContext((props) => {
|
|
515
515
|
const { radialProps } = useComponentContext();
|
|
516
|
+
const { registerNameKey } = useChartComponentContext();
|
|
516
517
|
const { background: backgroundProp = true, children, dataKey, label: labelProp = false, labelList = false, nameKey, sectorProps, ...rest } = mergeProps(radialProps, props)();
|
|
518
|
+
useSafeLayoutEffect(() => registerNameKey(nameKey), [nameKey, registerNameKey]);
|
|
517
519
|
const system = useSystem();
|
|
518
520
|
const { theme } = useTheme();
|
|
519
|
-
const { nameKeyRef } = useChartComponentContext();
|
|
520
521
|
const labelProps = useSlotComponentProps({}, "labelList");
|
|
521
522
|
const backgroundProps = useSlotComponentProps({}, "radialBackground");
|
|
522
523
|
const css = useMemo(() => getCSS(system, theme), [system, theme]);
|
|
@@ -581,7 +582,6 @@ const ChartRadial = withContext((props) => {
|
|
|
581
582
|
shape,
|
|
582
583
|
...rest
|
|
583
584
|
});
|
|
584
|
-
assignRef(nameKeyRef, nameKey);
|
|
585
585
|
return /* @__PURE__ */ jsx(styled.svg, {
|
|
586
586
|
asChild: true,
|
|
587
587
|
...getRootProps(),
|