UNPKG

@yamada-ui/react

Version:

React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion

1 lines 4.7 kB
{"version":3,"file":"reorder.cjs","names":["createSlotComponent","reorderStyle","useValue","useReorder","ReorderContext","styled","OriginalReorder","useReorderItem","ReorderItemContext","useReorderItemContext","GripVerticalIcon"],"sources":["../../../../src/components/reorder/reorder.tsx"],"sourcesContent":["\"use client\"\n\nimport type { PropsWithChildren, ReactElement } from \"react\"\nimport type { GenericsComponent, HTMLStyledProps, ThemeProps } from \"../../core\"\nimport type { Merge } from \"../../utils\"\nimport type { HTMLMotionProps } from \"../motion\"\nimport type { ReorderStyle } from \"./reorder.style\"\nimport type { UseReorderItemProps, UseReorderProps } from \"./use-reorder\"\nimport { Reorder as OriginalReorder } from \"motion/react\"\nimport { createSlotComponent, styled } from \"../../core\"\nimport { useValue } from \"../../hooks/use-value\"\nimport { GripVerticalIcon } from \"../icon\"\nimport { reorderStyle } from \"./reorder.style\"\nimport {\n ReorderContext,\n ReorderItemContext,\n useReorder,\n useReorderItem,\n useReorderItemContext,\n} from \"./use-reorder\"\n\nexport interface ReorderItem<Y = string> extends ReorderItemProps<Y> {}\n\nexport interface ReorderRootProps<Y = string>\n extends Merge<\n HTMLMotionProps<\"ul\">,\n Omit<UseReorderProps<Y>, \"item\" | \"items\" | \"orientation\">\n >,\n ThemeProps<ReorderStyle> {\n /**\n * If provided, generate reorder items based on items.\n *\n */\n items?: ReorderItem<Y>[]\n}\n\nconst {\n PropsContext: ReorderPropsContext,\n usePropsContext: useReorderPropsContext,\n withContext,\n withProvider,\n} = createSlotComponent<ReorderRootProps, ReorderStyle>(\"reorder\", reorderStyle)\n\nexport { ReorderPropsContext, useReorderPropsContext }\n\n/**\n * `Reorder` is a component that allows you to change the order of items using drag and drop.\n *\n * @see https://yamada-ui.com/docs/components/reorder\n */\nexport const ReorderRoot = withProvider<\"ul\", ReorderRootProps>(\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint\n <Y extends any = string>({\n orientation: orientationProp,\n ...rest\n }: ReorderRootProps<Y>) => {\n const orientation = useValue(orientationProp)\n const { children, getRootProps } = useReorder({\n ...rest,\n item: <ReorderItem />,\n orientation,\n })\n\n return (\n <ReorderContext value={{ orientation }}>\n <styled.ul\n as={OriginalReorder.Group<Y>}\n {...(getRootProps() as HTMLStyledProps<\"ul\">)}\n >\n {children}\n </styled.ul>\n </ReorderContext>\n )\n },\n \"root\",\n { transferProps: [\"orientation\"] },\n)() as GenericsComponent<{\n <Y = string>(props: ReorderRootProps<Y>): ReactElement\n}>\n\nexport interface ReorderItemProps<Y = string>\n extends Omit<\n Merge<HTMLMotionProps<\"li\">, UseReorderItemProps<Y>>,\n \"children\"\n >,\n PropsWithChildren {}\n\nexport const ReorderItem = withContext<\"li\", ReorderItemProps>(\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint\n <Y extends any = string>(props: ReorderItemProps<Y>) => {\n const { getItemProps, getTriggerProps } = useReorderItem(props)\n\n return (\n <ReorderItemContext value={{ getTriggerProps }}>\n <styled.li\n as={OriginalReorder.Item<Y>}\n {...(getItemProps() as HTMLStyledProps<\"li\">)}\n />\n </ReorderItemContext>\n )\n },\n \"item\",\n)() as GenericsComponent<{\n <Y = string>(props: ReorderItemProps<Y>): ReactElement\n}>\n\nexport interface ReorderTriggerProps extends HTMLStyledProps {}\n\nexport const ReorderTrigger = withContext<\"div\", ReorderTriggerProps>(\n \"div\",\n \"trigger\",\n)(undefined, (props) => {\n const { getTriggerProps } = useReorderItemContext()\n\n return { children: <GripVerticalIcon />, ...getTriggerProps(props) }\n})\n"],"mappings":";;;;;;;;;;;;;;;;AAoCA,MAAM,EACJ,cAAc,qBACd,iBAAiB,wBACjB,aACA,iBACEA,6CAAoD,WAAWC,mCAAa;;;;;;AAShF,MAAa,cAAc,cAEA,EACvB,aAAa,gBACb,GAAG,WACsB;CACzB,MAAM,cAAcC,uCAAS,gBAAgB;CAC7C,MAAM,EAAE,UAAU,iBAAiBC,+BAAW;EAC5C,GAAG;EACH,MAAM,2CAAC,gBAAc;EACrB;EACD,CAAC;AAEF,QACE,2CAACC;EAAe,OAAO,EAAE,aAAa;YACpC,2CAACC,uBAAO;GACN,IAAIC,qBAAgB;GACpB,GAAK,cAAc;GAElB;IACS;GACG;GAGrB,QACA,EAAE,eAAe,CAAC,cAAc,EAAE,CACnC,EAAE;AAWH,MAAa,cAAc,aAEA,UAA+B;CACtD,MAAM,EAAE,cAAc,oBAAoBC,mCAAe,MAAM;AAE/D,QACE,2CAACC;EAAmB,OAAO,EAAE,iBAAiB;YAC5C,2CAACH,uBAAO;GACN,IAAIC,qBAAgB;GACpB,GAAK,cAAc;IACnB;GACiB;GAGzB,OACD,EAAE;AAMH,MAAa,iBAAiB,YAC5B,OACA,UACD,CAAC,SAAY,UAAU;CACtB,MAAM,EAAE,oBAAoBG,2CAAuB;AAEnD,QAAO;EAAE,UAAU,2CAACC,gDAAmB;EAAE,GAAG,gBAAgB,MAAM;EAAE;EACpE"}