@yamada-ui/react
Version:
React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion
1 lines • 8.67 kB
Source Map (JSON)
{"version":3,"file":"timeline.cjs","names":["createSlotComponent","timelineStyle","rest","children","index","styled","varAttr"],"sources":["../../../../src/components/timeline/timeline.tsx"],"sourcesContent":["\"use client\"\n\nimport type { ReactNode } from \"react\"\nimport type { CSSProps, HTMLStyledProps, ThemeProps } from \"../../core\"\nimport type { TimelineStyle } from \"./timeline.style\"\nimport { useMemo } from \"react\"\nimport { createSlotComponent, styled, varAttr } from \"../../core\"\nimport { dataAttr, isUndefined } from \"../../utils\"\nimport { timelineStyle } from \"./timeline.style\"\n\nexport interface TimelineItem\n extends Omit<TimelineItemProps, \"content\" | \"title\"> {\n align?: \"end\" | \"start\"\n content?: ReactNode\n description?: ReactNode\n indicator?: ReactNode\n title?: ReactNode\n connectorProps?: TimelineConnectorProps\n contentProps?: TimelineContentProps\n descriptionProps?: TimelineDescriptionProps\n indicatorProps?: TimelineIndicatorProps\n titleProps?: TimelineTitleProps\n}\n\ninterface ComponentContext extends Pick<TimelineRootProps, \"index\"> {}\n\nexport interface TimelineRootProps\n extends HTMLStyledProps<\"ul\">,\n ThemeProps<TimelineStyle> {\n /**\n * The index of the active timeline item.\n */\n index?: number\n /**\n * The fill color of the indicator.\n */\n indicatorFill?: CSSProps[\"bg\"]\n /**\n * The size of the indicator.\n */\n indicatorSize?: CSSProps[\"boxSize\"]\n /**\n * The stroke color of the indicator.\n */\n indicatorStroke?: CSSProps[\"color\"]\n /**\n * If provided, generate timeline components based on items.\n */\n items?: TimelineItem[]\n /**\n * The color of the separator.\n */\n separatorColor?: CSSProps[\"color\"]\n /**\n * The gap of the separator.\n */\n separatorGap?: CSSProps[\"gap\"]\n /**\n * The style of the separator.\n */\n separatorStyle?: CSSProps[\"borderStyle\"]\n /**\n * The width of the separator.\n */\n separatorWidth?: CSSProps[\"width\"]\n}\n\nconst {\n ComponentContext,\n PropsContext: TimelinePropsContext,\n useComponentContext,\n usePropsContext: useTimelinePropsContext,\n withContext,\n withProvider,\n} = createSlotComponent<TimelineRootProps, TimelineStyle, ComponentContext>(\n \"timeline\",\n timelineStyle,\n)\n\nexport { TimelinePropsContext, useTimelinePropsContext }\n\n/**\n * `Timeline` is a component that is used to display a list of events in chronological order.\n *\n * @see https://yamada-ui.com/docs/components/timeline\n */\nexport const TimelineRoot = withProvider(\n ({ children, index = -1, items = [], ...rest }) => {\n const context = useMemo(() => ({ index }), [index])\n const computedChildren = useMemo(() => {\n if (children) return children\n\n return items.map(\n (\n {\n align = \"start\",\n content,\n description,\n indicator,\n title,\n connectorProps,\n contentProps,\n descriptionProps,\n indicatorProps,\n titleProps,\n ...rest\n },\n index,\n ) => {\n const children = {\n connector: (\n <TimelineConnector {...connectorProps}>\n <TimelineIndicator {...indicatorProps}>\n {indicator}\n </TimelineIndicator>\n </TimelineConnector>\n ),\n content: (\n <TimelineContent {...contentProps}>\n {content ?? (\n <>\n <TimelineTitle {...titleProps}>{title}</TimelineTitle>\n <TimelineDescription {...descriptionProps}>\n {description}\n </TimelineDescription>\n </>\n )}\n </TimelineContent>\n ),\n }\n\n return (\n <TimelineItem key={index} index={index} {...rest}>\n {align === \"start\" ? children.connector : children.content}\n {align === \"start\" ? children.content : children.connector}\n </TimelineItem>\n )\n },\n )\n }, [items, children])\n\n return (\n <ComponentContext value={context}>\n <styled.ul {...rest}>{computedChildren}</styled.ul>\n </ComponentContext>\n )\n },\n \"root\",\n)(\n undefined,\n ({\n indicatorFill,\n indicatorSize,\n indicatorStroke,\n separatorColor,\n separatorGap,\n separatorStyle,\n separatorWidth,\n ...rest\n }) => ({\n \"--indicator-fill\": varAttr(indicatorFill, \"colors\"),\n \"--indicator-size\": varAttr(indicatorSize, \"sizes\"),\n \"--indicator-stroke\": varAttr(indicatorStroke, \"colors\"),\n \"--separator-color\": varAttr(separatorColor, \"colors\"),\n \"--separator-gap\": varAttr(separatorGap, \"spaces\"),\n \"--separator-style\": varAttr(separatorStyle),\n \"--separator-width\": varAttr(separatorWidth, \"sizes\"),\n ...rest,\n }),\n)\n\nexport interface TimelineItemProps extends HTMLStyledProps<\"li\"> {\n /**\n * The index of the timeline item.\n */\n index?: number\n}\n\nexport const TimelineItem = withContext<\"li\", TimelineItemProps>(\"li\", \"item\")(\n undefined,\n ({ index, ...rest }) => {\n const { index: currentIndex } = useComponentContext()\n const active =\n !isUndefined(index) && !isUndefined(currentIndex) && index <= currentIndex\n\n return {\n ...rest,\n \"data-active\": dataAttr(active),\n \"data-index\": index,\n }\n },\n)\n\nexport interface TimelineConnectorProps extends HTMLStyledProps {}\n\nexport const TimelineConnector = withContext<\"div\", TimelineConnectorProps>(\n \"div\",\n \"connector\",\n)({ \"data-connector\": \"\" })\n\nexport interface TimelineIndicatorProps extends HTMLStyledProps {}\n\nconst TimelineIcon = styled(\"div\", {\n base: {\n bg: \"{indicator-fill}\",\n borderColor: \"{indicator-stroke}\",\n borderWidth: \"{separator-width}\",\n boxSize: \"full\",\n rounded: \"{indicator-rounded}\",\n },\n})\n\nexport const TimelineIndicator = withContext<\"div\", TimelineIndicatorProps>(\n \"div\",\n \"indicator\",\n)(undefined, ({ children = <TimelineIcon />, ...rest }) => ({\n children,\n ...rest,\n}))\n\nexport interface TimelineContentProps extends HTMLStyledProps {}\n\nexport const TimelineContent = withContext<\"div\", TimelineContentProps>(\n \"div\",\n \"content\",\n)({ \"data-content\": \"\" })\n\nexport interface TimelineTitleProps extends HTMLStyledProps<\"h3\"> {}\n\nexport const TimelineTitle = withContext<\"h3\", TimelineTitleProps>(\n \"h3\",\n \"title\",\n)()\n\nexport interface TimelineDescriptionProps extends HTMLStyledProps<\"p\"> {}\n\nexport const TimelineDescription = withContext<\"p\", TimelineDescriptionProps>(\n \"p\",\n \"description\",\n)()\n"],"mappings":";;;;;;;;;;;;;;;AAmEA,MAAM,EACJ,kBACA,cAAc,sBACd,qBACA,iBAAiB,yBACjB,aACA,iBACEA,6CACF,YACAC,qCACD;;;;;;AASD,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