-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from MARU-EGG/atom-component-refactor
[USER]: Feat Text-input component
- Loading branch information
Showing
3 changed files
with
70 additions
and
4 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
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,36 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import TextArea from './text-input'; | ||
|
||
const meta = { | ||
title: 'Example/TextArea', | ||
component: TextArea, | ||
tags: ['autodocs'], | ||
parameters: { | ||
layout: 'centered', | ||
}, | ||
args: { | ||
onValueChange: (value: string) => console.log(value), | ||
}, | ||
} satisfies Meta<typeof TextArea>; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
placeholder: 'Enter text here...', | ||
}, | ||
}; | ||
|
||
export const Disabled: Story = { | ||
args: { | ||
placeholder: 'Enter text here...', | ||
disabled: true, | ||
}, | ||
}; | ||
|
||
export const WithValue: Story = { | ||
args: { | ||
value: '마루에그에게 물어보고싶어요', | ||
}, | ||
}; |
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,30 @@ | ||
import React from 'react'; | ||
import { cn } from '../../../../utils/style'; | ||
|
||
export interface TextInputProps extends React.InputHTMLAttributes<HTMLInputElement> { | ||
value?: string; | ||
onValueChange?: (value: string) => void; | ||
disabled?: boolean; | ||
defaultValue?: string; | ||
} | ||
|
||
const TextInput = React.forwardRef<HTMLInputElement, TextInputProps>(function TextArea( | ||
{ disabled = false, placeholder, onValueChange, defaultValue, value }, | ||
ref, | ||
) { | ||
return ( | ||
<input | ||
ref={ref} | ||
type="text" | ||
className={cn(`w-full rounded-2xl bg-transparent px-5 py-2 text-body3`, `placeholder:text-[#72777A]`)} | ||
value={value} | ||
placeholder={placeholder} | ||
disabled={disabled} | ||
onChange={(e) => { | ||
onValueChange?.(e.target.value); | ||
}} | ||
/> | ||
); | ||
}); | ||
|
||
export default TextInput; |