-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
71 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Dropzone, DropzoneProps } from '@sopt-makers/ui'; | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
|
||
const meta: Meta<DropzoneProps> = { | ||
title: 'Components/Dropzone', | ||
component: Dropzone, | ||
tags: ['autodocs'], | ||
args: { | ||
label: 'label', | ||
description: 'description', | ||
required: true, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
export const Default: StoryObj<DropzoneProps> = { | ||
args: { | ||
label: '이미지 등록', | ||
description: `[PC] 이미지는 1824*328 px 크기로 올려주세요.`, | ||
width: '500px', | ||
}, | ||
render: (args) => <Dropzone {...args} />, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,43 @@ | ||
import { IconImagePlus } from '@sopt-makers/icons'; | ||
import { FieldBox } from 'FieldBox'; | ||
import type { HTMLAttributes, ReactNode } from 'react'; | ||
import { forwardRef } from 'react'; | ||
import { useDropzone } from 'react-dropzone'; | ||
import { dropzoneStyle } from './style.css'; | ||
|
||
export interface DropZoneProps extends HTMLAttributes<HTMLInputElement> { | ||
export interface DropzoneProps extends HTMLAttributes<HTMLInputElement> { | ||
label?: string; | ||
description?: string; | ||
required?: boolean; | ||
width?: number; | ||
height?: number; | ||
width?: string; | ||
height?: string; | ||
icon?: ReactNode; | ||
} | ||
|
||
const DropZone = forwardRef<HTMLInputElement, DropZoneProps>((props, forwardedRef) => { | ||
const { label, description, required = false, width, height, icon = 'andada' } = props; | ||
export const Dropzone = forwardRef<HTMLInputElement, DropzoneProps>((props, forwardedRef) => { | ||
const { | ||
label, | ||
description, | ||
required = false, | ||
width = '300px', | ||
height = '170px', | ||
icon = <IconImagePlus color='white' style={{ width: '24px', height: '24px' }} />, | ||
} = props; | ||
|
||
const { getRootProps, getInputProps } = useDropzone(); | ||
|
||
return ( | ||
<FieldBox topAddon={<FieldBox.Label description={description} label={label} required={required} />}> | ||
<input ref={forwardedRef} type='file'> | ||
<FieldBox | ||
topAddon={ | ||
<FieldBox.TopAddon leftAddon={<FieldBox.Label description={description} label={label} required={required} />} /> | ||
} | ||
> | ||
<div className={dropzoneStyle} style={{ width, height }} {...getRootProps()}> | ||
{icon} | ||
</input> | ||
<input ref={forwardedRef} {...getInputProps()} /> | ||
</div> | ||
</FieldBox> | ||
); | ||
}); | ||
|
||
DropZone.displayName = 'DropZone'; | ||
|
||
export default DropZone; | ||
Dropzone.displayName = 'Dropzone'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './DropZone'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { style } from '@vanilla-extract/css'; | ||
import theme from '../theme.css'; | ||
|
||
export const dropzoneStyle = style({ | ||
position: 'relative', | ||
display: 'flex', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
backgroundColor: theme.colors.gray700, | ||
borderRadius: '10px', | ||
|
||
cursor: 'pointer', | ||
}); | ||
|
||
export const dropzoneInputStyle = style({ | ||
position: 'absolute', | ||
width: 'transparent', | ||
height: 'transparent', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters