Skip to content

Commit

Permalink
feat: Publish Dropzone.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brokyeom committed Dec 5, 2024
1 parent 8db8de3 commit 7742554
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 11 deletions.
24 changes: 24 additions & 0 deletions apps/docs/src/stories/Dropzone.stories.tsx
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} />,
};
37 changes: 26 additions & 11 deletions packages/ui/DropZone/DropZone.tsx
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';
1 change: 1 addition & 0 deletions packages/ui/DropZone/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './DropZone';
19 changes: 19 additions & 0 deletions packages/ui/DropZone/style.css.ts
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',
});
1 change: 1 addition & 0 deletions packages/ui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ export { default as Tab } from './Tab';
export * from './Skeleton';
export * from './FieldBox';
export * from './Tag';
export * from './Dropzone';
// test component
export { default as Test } from './Test';

0 comments on commit 7742554

Please sign in to comment.