@yamada-ui/react
Version:
React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion
1 lines • 3.81 kB
Source Map (JSON)
{"version":3,"file":"list.cjs","names":["createSlotComponent","listStyle","styled"],"sources":["../../../../src/components/list/list.tsx"],"sourcesContent":["\"use client\"\n\nimport type { ReactElement } from \"react\"\nimport type {\n CSSProps,\n HTMLProps,\n HTMLStyledProps,\n ThemeProps,\n} from \"../../core\"\nimport type { ListStyle } from \"./list.style\"\nimport { cloneElement, isValidElement, useMemo } from \"react\"\nimport { createSlotComponent, styled } from \"../../core\"\nimport { listStyle } from \"./list.style\"\n\nexport interface ListItem extends ListItemProps {}\n\nexport interface ListRootProps\n extends HTMLStyledProps<\"ul\">,\n Omit<ThemeProps<ListStyle>, \"styleType\"> {\n /**\n * If provided, generate elements based on items.\n */\n items?: ListItem[]\n /**\n * The CSS `list-style-position` property.\n */\n stylePosition?: CSSProps[\"listStylePosition\"]\n /**\n * The CSS `list-style-position` property.\n */\n styleType?: CSSProps[\"listStyleType\"]\n}\n\nconst {\n PropsContext: ListPropsContext,\n usePropsContext: useListPropsContext,\n withContext,\n withProvider,\n} = createSlotComponent<ListRootProps, ListStyle>(\"list\", listStyle)\n\nexport { ListPropsContext, useListPropsContext }\n\n/**\n * `List` is a component for displaying lists. By default, it renders a `ul` element.\n *\n * @see https://yamada-ui.com/docs/components/list\n */\nexport const ListRoot = withProvider<\"ul\", ListRootProps, \"styleType\">(\n ({\n as: asProp,\n children,\n items,\n stylePosition: listStylePosition,\n styleType: listStyleType = \"none\",\n ...rest\n }) => {\n const as = asProp ?? (listStyleType == \"decimal\" ? \"ol\" : undefined)\n const computedChildren = useMemo(() => {\n if (children) return children\n\n return items?.map((props, index) => <ListItem key={index} {...props} />)\n }, [children, items])\n\n return (\n <styled.ul\n as={as}\n listStylePosition={listStylePosition}\n listStyleType={listStyleType}\n role=\"list\"\n {...rest}\n >\n {computedChildren}\n </styled.ul>\n )\n },\n \"root\",\n { transferProps: [\"styleType\"] },\n)()\n\nexport interface ListItemProps extends HTMLStyledProps<\"li\"> {\n /**\n * The icon to use.\n */\n icon?: ReactElement<any>\n}\n\nexport const ListItem = withContext<\"li\", ListItemProps>(\n ({ children, icon, ...rest }) => (\n <styled.li {...rest}>\n <ListItemIcon>{icon}</ListItemIcon>\n\n {children}\n </styled.li>\n ),\n \"item\",\n)()\n\nexport interface ListIconProps extends HTMLStyledProps<\"svg\"> {}\n\nexport const ListItemIcon = withContext<\"svg\", ListIconProps>(\n ({ children, ...rest }) => {\n if (isValidElement<HTMLProps<\"svg\">>(children)) {\n return cloneElement(children, {\n ...children.props,\n ...rest,\n role: \"presentation\",\n })\n } else {\n return null\n }\n },\n \"icon\",\n)({ \"data-list-icon\": \"\" })\n"],"mappings":";;;;;;;;;;;;;AAiCA,MAAM,EACJ,cAAc,kBACd,iBAAiB,qBACjB,aACA,iBACEA,6CAA8C,QAAQC,6BAAU;;;;;;AASpE,MAAa,WAAW,cACrB,EACC,IAAI,QACJ,UACA,OACA,eAAe,mBACf,WAAW,gBAAgB,OAC3B,GAAG,WACC;CACJ,MAAM,KAAK,WAAW,iBAAiB,YAAY,OAAO;CAC1D,MAAM,4CAAiC;AACrC,MAAI,SAAU,QAAO;AAErB,SAAO,OAAO,KAAK,OAAO,UAAU,2CAAC,YAAqB,GAAI,SAAX,MAAoB,CAAC;IACvE,CAAC,UAAU,MAAM,CAAC;AAErB,QACE,2CAACC,uBAAO;EACF;EACe;EACJ;EACf,MAAK;EACL,GAAI;YAEH;GACS;GAGhB,QACA,EAAE,eAAe,CAAC,YAAY,EAAE,CACjC,EAAE;AASH,MAAa,WAAW,aACrB,EAAE,UAAU,KAAM,GAAG,WACpB,4CAACA,uBAAO;CAAG,GAAI;YACb,2CAAC,0BAAc,OAAoB,EAElC;EACS,EAEd,OACD,EAAE;AAIH,MAAa,eAAe,aACzB,EAAE,SAAU,GAAG,WAAW;AACzB,+BAAqC,SAAS,CAC5C,gCAAoB,UAAU;EAC5B,GAAG,SAAS;EACZ,GAAG;EACH,MAAM;EACP,CAAC;KAEF,QAAO;GAGX,OACD,CAAC,EAAE,kBAAkB,IAAI,CAAC"}