forked from next-step/react-payments
-
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
12 changed files
with
209 additions
and
10 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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import { AppLayout } from '@/components'; | ||
import { TextField } from '@/shared/components'; | ||
import { letterSpacingValue, storybookControls, styleToken } from '@/shared/styles'; | ||
|
||
const FONT_SIZE = 18; | ||
const LETTER_SPACING = letterSpacingValue(FONT_SIZE, -8.5); | ||
|
||
const meta: Meta = { | ||
title: 'Primitive/TextField', | ||
component: TextField, | ||
parameters: { | ||
layout: 'centered', | ||
}, | ||
tags: ['autodocs'], | ||
argTypes: { | ||
...storybookControls.argTypes, | ||
type: { | ||
options: ['text', 'password', 'email', 'number', 'tel', 'url'], | ||
}, | ||
}, | ||
args: { | ||
as: 'input', | ||
type: 'text', | ||
variant: 'outline', | ||
width: styleToken.width.w100, | ||
height: '45px', | ||
padding: '13px 12px 13px 11px', | ||
borderRadius: '6px', | ||
fontSize: `${FONT_SIZE}px`, | ||
placeholder: '카드에 표시된 이름과 동일하게 입력하세요.', | ||
_placeholder: { | ||
letterSpacing: LETTER_SPACING, | ||
}, | ||
autoFocus: true, | ||
}, | ||
decorators: [ | ||
(Story) => ( | ||
<AppLayout> | ||
<Story /> | ||
</AppLayout> | ||
), | ||
], | ||
} satisfies Meta<typeof TextField>; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Primary: Story = {}; | ||
|
||
export const Password: Story = { | ||
args: { | ||
type: 'password', | ||
}, | ||
}; | ||
|
||
export const WithFocusOutlineStyle: Story = { | ||
args: { | ||
_focus: { | ||
outline: `2px solid ${styleToken.color.teal200}`, | ||
}, | ||
}, | ||
}; | ||
|
||
export const WithFocusPlaceholderStyle: Story = { | ||
args: { | ||
placeholder: '중앙 정렬', | ||
_placeholder: { | ||
color: styleToken.color.teal200, | ||
textAlign: 'center', | ||
letterSpacing: '2px', | ||
}, | ||
}, | ||
}; | ||
|
||
export const WithVariantFilled: Story = { | ||
args: { | ||
variant: 'filled', | ||
}, | ||
}; | ||
|
||
export const WithVariantFlushed: Story = { | ||
args: { | ||
variant: 'flushed', | ||
}, | ||
}; | ||
|
||
export const WithVariantUnstyled: Story = { | ||
args: { | ||
variant: 'unstyled', | ||
}, | ||
}; |
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,63 @@ | ||
import { forwardRef, HTMLProps } from 'react'; | ||
import styled from '@emotion/styled'; | ||
import type { FocusProps, PlaceholderProps, TextFieldVariant } from './TextField.type'; | ||
import { DefaultStyled, styleToken } from '@/shared/styles'; | ||
import { AsProps, StyleProps } from '@/shared/types'; | ||
|
||
type TextFieldProps = StyleProps & | ||
AsProps & | ||
HTMLProps<HTMLInputElement> & { | ||
variant?: TextFieldVariant; | ||
_placeholder?: PlaceholderProps; | ||
_focus?: FocusProps; | ||
}; | ||
|
||
export const TextField = forwardRef<HTMLInputElement, TextFieldProps>((props, ref) => { | ||
const { type, variant, ...restProps } = props; | ||
return <Root as="input" type={type || 'text'} variant={variant || 'outline'} ref={ref} {...restProps} />; | ||
}); | ||
|
||
const Root = styled(DefaultStyled)<TextFieldProps>` | ||
width: ${styleToken.width.w100}; | ||
height: 45px; | ||
padding: 13px 12px 13px 11px; | ||
border-radius: 6px; | ||
font-size: 18px; | ||
${({ variant }) => variantStyles[variant || 'outline']}; | ||
&::placeholder { | ||
letter-spacing: ${({ _placeholder }) => _placeholder?.letterSpacing}; | ||
color: ${({ _placeholder }) => _placeholder?.color}; | ||
text-align: ${({ _placeholder }) => _placeholder?.textAlign}; | ||
} | ||
&:focus-visible { | ||
${({ variant }) => variant && isValidVariantNoneOutline(variant) && `outline: none;`}; | ||
outline: ${({ _focus }) => _focus?.outline}; | ||
} | ||
`; | ||
|
||
const variantStyles = { | ||
outline: { | ||
border: `1px solid ${styleToken.color.gray400}`, | ||
borderRadius: '7px', | ||
}, | ||
filled: { | ||
backgroundColor: styleToken.color.gray200, | ||
border: 'none', | ||
borderRadius: '7px', | ||
}, | ||
flushed: { | ||
border: 'none', | ||
borderBottom: `2px solid ${styleToken.color.gray600}`, | ||
borderRadius: '0', | ||
}, | ||
unstyled: { | ||
border: 'none', | ||
borderRadius: '0', | ||
padding: '0', | ||
}, | ||
}; | ||
|
||
const isValidVariantNoneOutline = (variant: TextFieldVariant): variant is 'filled' | 'flushed' | 'unstyled' => | ||
['filled', 'flushed', 'unstyled'].includes(variant); |
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,13 @@ | ||
import { StyleProps } from '@/shared/types'; | ||
|
||
export type PlaceholderProps = { | ||
color?: StyleProps['color']; | ||
letterSpacing?: StyleProps['letterSpacing']; | ||
textAlign?: StyleProps['textAlign']; | ||
}; | ||
|
||
export type FocusProps = { | ||
outline?: StyleProps['outline']; | ||
}; | ||
|
||
export type TextFieldVariant = 'outline' | 'filled' | 'flushed' | 'unstyled'; |
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 * from './TextField'; |
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,3 +1,4 @@ | ||
export * from './Box'; | ||
export * from './HStack'; | ||
export * from './VStack'; | ||
export * from './TextField'; |
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,4 +1,5 @@ | ||
export * from './DefaultStyled'; | ||
export * from './GlobalStyles'; | ||
export * from './storybookControls'; | ||
export * from './styledUtils'; | ||
export * from './styleToken'; |
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,4 @@ | ||
const letterSpacingValue = (fontSize: number, letterSpacingPercentage: number) => | ||
(fontSize * letterSpacingPercentage) / 100; | ||
|
||
export { letterSpacingValue }; |
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