@yamada-ui/react
Version:
React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion
1 lines • 6.68 kB
Source Map (JSON)
{"version":3,"file":"dropzone.cjs","names":["createSlotComponent","dropzoneStyle","useInputBorder","useDropzone","Portal","styled","Fade","useLoadingComponent","DropzoneAccept: FC<DropzoneAcceptProps>","DropzoneReject: FC<DropzoneRejectProps>","DropzoneIdle: FC<DropzoneIdleProps>"],"sources":["../../../../src/components/dropzone/dropzone.tsx"],"sourcesContent":["\"use client\"\n\nimport type { FC, PropsWithChildren } from \"react\"\nimport type { HTMLStyledProps, ThemeProps } from \"../../core\"\nimport type { Merge } from \"../../utils\"\nimport type { FadeProps } from \"../fade\"\nimport type { UseInputBorderProps } from \"../input\"\nimport type { Loading } from \"../loading\"\nimport type { DropzoneStyle } from \"./dropzone.style\"\nimport type { UseDropzoneProps, UseDropzoneReturn } from \"./use-dropzone\"\nimport { useMemo } from \"react\"\nimport { createSlotComponent, styled } from \"../../core\"\nimport { Fade } from \"../fade\"\nimport { useInputBorder } from \"../input\"\nimport { useLoadingComponent } from \"../loading\"\nimport { Portal } from \"../portal\"\nimport { dropzoneStyle } from \"./dropzone.style\"\nimport { useDropzone } from \"./use-dropzone\"\n\ninterface ComponentContext\n extends Pick<\n UseDropzoneReturn,\n \"dragAccept\" | \"dragIdle\" | \"dragReject\" | \"loading\"\n > {}\n\nexport interface DropzoneRootProps\n extends Merge<HTMLStyledProps, UseDropzoneProps>,\n UseInputBorderProps,\n ThemeProps<DropzoneStyle>,\n Pick<DropzoneLoadingProps, \"loadingScheme\"> {\n /**\n * Props for dropzone input element.\n */\n inputProps?: HTMLStyledProps<\"input\">\n /**\n * Props for dropzone loading icon element.\n */\n loadingProps?: DropzoneLoadingProps\n /**\n * Props for dropzone overlay element.\n */\n overlayProps?: DropzoneOverlayProps\n}\n\nconst {\n ComponentContext,\n PropsContext: DropzonePropsContext,\n useComponentContext,\n usePropsContext: useDropzonePropsContext,\n withContext,\n withProvider,\n} = createSlotComponent<DropzoneRootProps, DropzoneStyle>(\n \"dropzone\",\n dropzoneStyle,\n)\n\nexport { DropzonePropsContext, useDropzonePropsContext }\n\n/**\n * `Dropzone` is a component used for uploading files via drag and drop.\n *\n * @see https://yamada-ui.com/docs/components/dropzone\n */\nexport const DropzoneRoot = withProvider(\n ({\n children,\n errorBorderColor,\n focusBorderColor,\n loadingScheme,\n inputProps,\n loadingProps,\n overlayProps,\n ...rest\n }) => {\n const varProps = useInputBorder({ errorBorderColor, focusBorderColor })\n const {\n dragAccept,\n dragIdle,\n dragReject,\n loading,\n getInputProps,\n getRootProps,\n } = useDropzone(rest)\n const context = useMemo(\n () => ({\n dragAccept,\n dragIdle,\n dragReject,\n loading,\n }),\n [dragAccept, dragIdle, dragReject, loading],\n )\n\n return (\n <ComponentContext value={context}>\n <Portal>\n <styled.input {...getInputProps(inputProps)} />\n </Portal>\n\n <styled.div data-group {...varProps} {...getRootProps()}>\n <DropzoneOverlay {...overlayProps}>\n <DropzoneLoading loadingScheme={loadingScheme} {...loadingProps} />\n </DropzoneOverlay>\n\n {children}\n </styled.div>\n </ComponentContext>\n )\n },\n \"root\",\n)()\n\nexport interface DropzoneIconProps extends HTMLStyledProps<\"svg\"> {}\n\nexport const DropzoneIcon = withContext<\"svg\", DropzoneIconProps>(\n \"svg\",\n \"icon\",\n)()\n\nexport interface DropzoneTitleProps extends HTMLStyledProps<\"p\"> {}\n\nexport const DropzoneTitle = withContext<\"p\", DropzoneTitleProps>(\n \"p\",\n \"title\",\n)()\n\nexport interface DropzoneDescriptionProps extends HTMLStyledProps<\"p\"> {}\n\nexport const DropzoneDescription = withContext<\"p\", DropzoneDescriptionProps>(\n \"p\",\n \"description\",\n)()\n\nexport interface DropzoneDescriptionProps extends HTMLStyledProps<\"p\"> {}\n\ninterface DropzoneOverlayProps extends FadeProps {\n loadingProps?: DropzoneLoadingProps\n}\n\nconst DropzoneOverlay = withContext<\"div\", DropzoneOverlayProps>(\n Fade,\n \"overlay\",\n)(undefined, (props) => {\n const { loading } = useComponentContext()\n\n return { open: loading, unmountOnExit: true, ...props }\n})\n\ninterface DropzoneLoadingProps extends Loading.Props {\n /**\n * The loading scheme.\n *\n * @default 'oval'\n */\n loadingScheme?: Loading.Scheme\n}\n\nconst DropzoneLoading = withContext<\"svg\", DropzoneLoadingProps>(\n ({ loadingScheme = \"oval\", ...rest }) => {\n const Component = useLoadingComponent(loadingScheme)\n\n return <Component {...rest} />\n },\n \"loading\",\n)()\n\nexport interface DropzoneAcceptProps extends PropsWithChildren {}\n\nexport const DropzoneAccept: FC<DropzoneAcceptProps> = ({ children }) => {\n const { dragAccept } = useComponentContext()\n\n return dragAccept ? children : null\n}\n\nexport interface DropzoneRejectProps extends PropsWithChildren {}\n\nexport const DropzoneReject: FC<DropzoneRejectProps> = ({ children }) => {\n const { dragReject } = useComponentContext()\n\n return dragReject ? children : null\n}\n\nexport interface DropzoneIdleProps extends PropsWithChildren {}\n\nexport const DropzoneIdle: FC<DropzoneIdleProps> = ({ children }) => {\n const { dragIdle } = useComponentContext()\n\n return dragIdle ? children : null\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA4CA,MAAM,EACJ,kBACA,cAAc,sBACd,qBACA,iBAAiB,yBACjB,aACA,iBACEA,6CACF,YACAC,qCACD;;;;;;AASD,MAAa,eAAe,cACzB,EACC,UACA,kBACA,kBACA,eACA,YACA,cACA,aACA,GAAG,WACC;CACJ,MAAM,WAAWC,wCAAe;EAAE;EAAkB;EAAkB,CAAC;CACvE,MAAM,EACJ,YACA,UACA,YACA,SACA,eACA,iBACEC,iCAAY,KAAK;AAWrB,QACE,4CAAC;EAAiB,iCAVX;GACL;GACA;GACA;GACA;GACD,GACD;GAAC;GAAY;GAAU;GAAY;GAAQ,CAC5C;aAIG,2CAACC,mCACC,2CAACC,uBAAO,SAAM,GAAI,cAAc,WAAW,GAAI,GACxC,EAET,4CAACA,uBAAO;GAAI;GAAW,GAAI;GAAU,GAAI,cAAc;cACrD,2CAAC;IAAgB,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