Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#19] 텍스트필드 v2 컴포넌트 구현 #38

Merged
merged 5 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"lucide-react": "^0.417.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-icons": "^5.2.1",
"react-hook-form": "^7.52.1",
"react-router-dom": "^6.25.1",
"tailwind-merge": "^2.4.0",
Expand Down
10 changes: 10 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions src/components/common/TextFieldV2/TextFieldV2.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Meta, StoryObj } from '@storybook/react';
import TextFieldV2 from '@/components/common/TextFieldV2/index.tsx';
import { RiDeleteBinLine } from 'react-icons/ri';

const meta: Meta = {
title: '텍스트 필드 V2',
component: TextFieldV2,
};

export default meta;

export type Story = StoryObj<typeof TextFieldV2>;

export const Default: Story = {
args: {
label: '레이블',
placeholder: '플레이스 홀더',
},
};

export const WithTrailingIcon: Story = {
args: {
label: '레이블',
placeholder: '플레이스 홀더',
trailingIcon: (
<div className={'cursor-pointer'}>
<RiDeleteBinLine size={24} color={'#B0B8C1'} />
</div>
),
},
};
50 changes: 50 additions & 0 deletions src/components/common/TextFieldV2/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Input, InputProps } from '@/components/ui/input.tsx';
import { Label } from '@/components/ui/label.tsx';
import { ReactNode, useId } from 'react';
import { cn } from '@/utils.ts';

export interface TextFieldV2Props extends Omit<InputProps, 'id' | 'type' | 'className'> {
label: string;
labelClassName?: string;
inputClassName?: string;
trailingIcon?: ReactNode;
}

const TextFieldV2 = ({
label,
labelClassName,
inputClassName,
trailingIcon,
...rest
}: TextFieldV2Props) => {
const id = useId();

return (
<div className="grid w-full items-center gap-2.5">
<Label
className={cn('text-small-writing text-gray-800 font-medium px-2.5', labelClassName)}
htmlFor={id}
>
{label}
</Label>
<div
className={cn(
'w-full px-2.5 pt-0 pb-3 flex flex-row justify-between items-center border-b-2 border-gray-100',
inputClassName,
)}
>
<Input
className={
'border-none rounded-none p-0 text-regular-title font-semibold placeholder:text-gray-400 focus-visible:ring-transparent focus-visible:ring-offset-0 caret-blue-500 text-gray-800'
}
id={id}
type={'text'}
{...rest}
/>
{trailingIcon}
</div>
</div>
);
};

export default TextFieldV2;
24 changes: 24 additions & 0 deletions src/components/ui/input.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as React from 'react';

import { cn } from '@/utils';

export interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {}

const Input = React.forwardRef<HTMLInputElement, InputProps>(
({ className, type, ...props }, ref) => {
return (
<input
type={type}
className={cn(
'flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50',
className,
)}
ref={ref}
{...props}
/>
);
},
);
Input.displayName = 'Input';

export { Input };
Loading