Merge branch 'fe/feat/74-workspace-create-modal' into 'fe/develop'

Feat: WorkSpaceCreateModal 컴포넌트 구현 - S11P21S002-74

See merge request s11-s-project/S11P21S002!8
This commit is contained in:
조현수 2024-08-28 15:40:30 +09:00
commit 9d985c671f
6 changed files with 164 additions and 35 deletions

View File

@ -1,33 +0,0 @@
import * as React from 'react';
import { cn } from '@/lib/utils';
interface ButtonProps {
isActive: boolean;
text: string;
onClick: () => void;
progress?: number;
}
export default function Button({ isActive, text, onClick, progress = 0 }: ButtonProps): JSX.Element {
const buttonText = progress === 100 ? '업로드 완료' : text;
return (
<button
className={cn(
'relative flex h-12 w-full items-center justify-center rounded-lg border-2 px-5 py-2.5 transition-all duration-300',
isActive
? 'cursor-pointer border-primary bg-primary text-white'
: 'cursor-not-allowed border-gray-200 bg-gray-100 text-gray-500'
)}
disabled={!isActive}
onClick={isActive ? onClick : undefined}
style={{ '--progress-width': `${progress}%` } as React.CSSProperties}
>
<span className="relative z-10 font-sans text-base font-bold leading-6">{buttonText}</span>
<div
className="transition-width absolute left-0 top-0 z-0 h-full bg-white bg-opacity-20 duration-300"
style={{ width: `var(--progress-width, 0%)` }}
></div>
</button>
);
}

View File

@ -0,0 +1,39 @@
import { cn } from '@/lib/utils';
import { Button as BaseButton, ButtonProps as BaseButtonProps } from '@/components/ui/button';
interface ProgressButtonProps extends BaseButtonProps {
isActive: boolean;
progress?: number;
text: string;
}
export default function ProgressButton({
isActive,
text,
progress = 0,
variant,
size,
className,
...props
}: ProgressButtonProps): JSX.Element {
const buttonText = progress === 100 ? '업로드 완료' : text;
return (
<BaseButton
className={cn('relative w-full overflow-hidden', className)}
variant={variant}
size={size}
disabled={!isActive}
{...props}
>
{progress > 0 && (
<div
className="absolute left-0 top-0 h-full bg-primary transition-all duration-300"
style={{ width: `${progress}%` }}
></div>
)}
<span className={cn('relative z-10', progress > 0 && 'text-white')}>{buttonText}</span>
</BaseButton>
);
}

View File

@ -1,6 +1,6 @@
import { useState } from 'react';
import CloseButton from './CloseButton';
import Button from './Button';
import ProgressButton from './ProgressButton';
import FileList from './FileList';
import { uploadFiles } from '@/api/upload';
@ -103,11 +103,13 @@ export default function ImageUploadModal({ title, buttonText, onClose }: ImageUp
)}
</div>
<div className="flex justify-center">
<Button
<ProgressButton
isActive={files.length > 0 && !isUploading}
text={isUploading ? `업로드 중... (${uploadProgress}%)` : buttonText}
onClick={handleUpload}
progress={uploadProgress}
type="submit"
variant="outlinePrimary"
/>
</div>
</div>

View File

@ -0,0 +1,78 @@
import { zodResolver } from '@hookform/resolvers/zod';
import { useForm } from 'react-hook-form';
import { z } from 'zod';
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '../ui/form';
import { Input } from '../ui/input';
import { Button } from '../ui/button';
const formSchema = z.object({
workspaceName: z.string().max(50).min(1, {
message: '이름을 입력해주세요.',
}),
workspaceDescription: z.string().max(200).optional(),
});
export type WorkSpaceCreateFormValues = z.infer<typeof formSchema>;
const defaultValues: Partial<WorkSpaceCreateFormValues> = {
workspaceName: '',
workspaceDescription: '',
};
export default function WorkSpaceCreateForm({ onSubmit }: { onSubmit: (data: WorkSpaceCreateFormValues) => void }) {
const form = useForm<WorkSpaceCreateFormValues>({
resolver: zodResolver(formSchema),
defaultValues,
});
return (
<Form {...form}>
<form
onSubmit={form.handleSubmit(onSubmit)}
className="flex flex-col gap-5"
>
<FormField
name="workspaceName"
control={form.control}
render={({ field }) => (
<FormItem>
<FormLabel className="body-strong"> </FormLabel>
<FormControl>
<Input
placeholder="이름을 입력해주세요."
maxLength={50}
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
name="workspaceDescription"
control={form.control}
render={({ field }) => (
<FormItem>
<FormLabel className="body-strong"> </FormLabel>
<FormControl>
<Input
placeholder="워크스페이스 설명을 입력해주세요."
maxLength={200}
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<Button
type="submit"
variant="outlinePrimary"
disabled={!form.formState.isValid}
>
</Button>
</form>
</Form>
);
}

View File

@ -0,0 +1,18 @@
import '@/index.css';
import WorkSpaceCreateModal from '.';
export default {
title: 'Modal/WorkSpaceCreateModal',
component: WorkSpaceCreateModal,
};
export const Default = () => (
<WorkSpaceCreateModal
onClose={() => {
console.log('close');
}}
onSubmit={(data) => {
console.log(data);
}}
/>
);

View File

@ -0,0 +1,25 @@
import WorkSpaceCreateForm, { WorkSpaceCreateFormValues } from './WorkSpaceCreateForm';
import XIcon from '@/assets/icons/x.svg?react';
export default function WorkSpaceCreateModal({
onClose,
onSubmit,
}: {
onClose: () => void;
onSubmit: (data: WorkSpaceCreateFormValues) => void;
}) {
return (
<div className="flex w-[610px] flex-col gap-10 rounded-3xl border px-10 py-5 shadow-lg">
<header className="flex gap-5">
<h1 className="small-title w-full"> </h1>
<button
className="flex h-8 w-8 items-center justify-center"
onClick={onClose}
>
<XIcon className="stroke-gray-900" />
</button>
</header>
<WorkSpaceCreateForm onSubmit={onSubmit} />
</div>
);
}