-
Notifications
You must be signed in to change notification settings - Fork 0
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
10 changed files
with
383 additions
and
147 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
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 +1,3 @@ | ||
export { default as FormInput } from './FormInput'; | ||
export { default } from './FormInput'; | ||
|
||
export type { FormTextInputProps, FormImageInputProps } from './FormInput'; |
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,40 @@ | ||
import { action } from '@storybook/addon-actions'; | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import { useState } from 'react'; | ||
|
||
import FormItem from './FormItem'; | ||
|
||
const meta: Meta<typeof FormItem.Image> = { | ||
component: FormItem.Image, | ||
decorators: [ | ||
function Decorator(Story, ctx) { | ||
const [previewImageUrl, setPreviewImageUrl] = useState(''); | ||
|
||
return ( | ||
<Story | ||
args={{ | ||
...ctx.args, | ||
previewImageUrl, | ||
onImageChange: (imageUrl) => { | ||
action('onImageChange')(imageUrl); | ||
setPreviewImageUrl(imageUrl); | ||
}, | ||
}} | ||
/> | ||
); | ||
}, | ||
], | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof FormItem.Image>; | ||
|
||
export const Main: Story = { | ||
args: { | ||
label: '이름', | ||
optional: false, | ||
errorMessage: '', | ||
caption: '', | ||
}, | ||
}; |
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,48 @@ | ||
import { style } from '@vanilla-extract/css'; | ||
import { Breakpoint, textStyleInfo } from '@/constants/style'; | ||
import { textStyle } from '@/styles/text.css'; | ||
import { themeVars } from '@/styles/theme.css'; | ||
import { getMediaQuery } from '@/utils/style'; | ||
|
||
export const container = style({ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
gap: '12px', | ||
}); | ||
|
||
export const titleArea = style({ | ||
display: 'flex', | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
gap: '4px', | ||
}); | ||
|
||
export const optionalText = style([ | ||
textStyle.body2SB, | ||
{ | ||
color: themeVars.color.grayscale.gray5.hex, | ||
}, | ||
]); | ||
|
||
export const inputArea = style({ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
gap: '8px', | ||
}); | ||
|
||
export const caption = style([ | ||
textStyle.body2R, | ||
{ | ||
display: 'block', | ||
minHeight: `${textStyleInfo.body2R.pc.lineHeight}px`, | ||
'@media': { | ||
[getMediaQuery([Breakpoint.MOBILE2, Breakpoint.MOBILE1])]: { | ||
minHeight: `${textStyleInfo.body2R.mobile.lineHeight}px`, | ||
}, | ||
}, | ||
}, | ||
]); | ||
|
||
export const errorText = style({ | ||
color: themeVars.color.system.caution.hex, | ||
}); |
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,88 @@ | ||
import { type ReactNode } from 'react'; | ||
import * as styles from './FormItem.css'; | ||
import FormInput, { | ||
type FormImageInputProps, | ||
type FormTextInputProps, | ||
} from '@/components/common/FormInput'; | ||
import { textStyle } from '@/styles/text.css'; | ||
import { className } from '@/utils/style'; | ||
|
||
interface FormItemPropsBase { | ||
label: string; | ||
optional?: boolean; | ||
caption?: string; | ||
errorMessage?: string; | ||
} | ||
|
||
interface FormTextItemProps | ||
extends FormItemPropsBase, | ||
Omit<FormTextInputProps, 'isError'> {} | ||
|
||
interface FormImageItemProps | ||
extends FormItemPropsBase, | ||
Omit<FormImageInputProps, 'isError'> {} | ||
|
||
const FormItemLayout = ({ | ||
label, | ||
optional, | ||
caption, | ||
errorMessage, | ||
children, | ||
}: FormItemPropsBase & { children: ReactNode }) => ( | ||
<div className={styles.container}> | ||
<div className={styles.titleArea}> | ||
<span className={textStyle.subtitle2SB}>{label}</span> | ||
{optional && <span className={styles.optionalText}>(선택)</span>} | ||
</div> | ||
{children} | ||
<span | ||
className={className( | ||
styles.caption, | ||
errorMessage ? styles.errorText : undefined, | ||
)} | ||
> | ||
{errorMessage ? errorMessage : caption} | ||
</span> | ||
</div> | ||
); | ||
|
||
const FormTextItem = ({ | ||
label, | ||
optional, | ||
caption, | ||
errorMessage, | ||
...inputProps | ||
}: FormTextItemProps) => ( | ||
<FormItemLayout | ||
label={label} | ||
optional={optional} | ||
caption={caption} | ||
errorMessage={errorMessage} | ||
> | ||
<FormInput.Text {...inputProps} isError={!!errorMessage} /> | ||
</FormItemLayout> | ||
); | ||
|
||
const FormImageItem = ({ | ||
label, | ||
optional, | ||
caption, | ||
errorMessage, | ||
...inputProps | ||
}: FormImageItemProps) => ( | ||
<FormItemLayout | ||
label={label} | ||
optional={optional} | ||
caption={caption} | ||
errorMessage={errorMessage} | ||
> | ||
<FormInput.Image {...inputProps} isError={!!errorMessage} /> | ||
</FormItemLayout> | ||
); | ||
|
||
const FormItem = { | ||
Text: FormTextItem, | ||
Image: FormImageItem, | ||
}; | ||
|
||
export default FormItem; |
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,41 @@ | ||
import { action } from '@storybook/addon-actions'; | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import { useState } from 'react'; | ||
|
||
import FormItem from './FormItem'; | ||
|
||
const meta: Meta<typeof FormItem.Text> = { | ||
component: FormItem.Text, | ||
decorators: [ | ||
function Decorator(Story, ctx) { | ||
const [value, setValue] = useState(''); | ||
|
||
return ( | ||
<Story | ||
args={{ | ||
...ctx.args, | ||
value, | ||
onTextChange: (newText) => { | ||
action('onTextChange')(newText); | ||
setValue(newText); | ||
}, | ||
}} | ||
/> | ||
); | ||
}, | ||
], | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof FormItem.Text>; | ||
|
||
export const Main: Story = { | ||
args: { | ||
label: '이름', | ||
optional: false, | ||
placeholder: '텍스트를 입력해주세요.', | ||
errorMessage: '', | ||
caption: '', | ||
}, | ||
}; |
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 { default } from './FormItem'; |
Oops, something went wrong.