-
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.
Browse files
Browse the repository at this point in the history
…ngText [Feat] input supportingText 구현
- Loading branch information
Showing
5 changed files
with
99 additions
and
22 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 |
---|---|---|
@@ -1,35 +1,56 @@ | ||
import React, { InputHTMLAttributes } from 'react'; | ||
import React, { ForwardedRef, InputHTMLAttributes, forwardRef } from 'react'; | ||
|
||
import { | ||
inputContainerStyle, | ||
containerStyle, | ||
inputStyle, | ||
inputWarpperStyle, | ||
inputSupportStyle, | ||
sizeStyle, | ||
variantStyle, | ||
warpperStyle, | ||
} from '@/common/component/Input/Input.style'; | ||
import Label from '@/common/component/Label/Label'; | ||
import SupportingText from '@/common/component/SupportingText/SupportingText'; | ||
|
||
type InputSize = 'small' | 'medium' | 'large'; | ||
type InputVariant = 'outline' | 'underline' | 'colored'; | ||
type InputVariant = 'default' | 'underline' | 'colored'; | ||
|
||
export interface InputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'size'> { | ||
variant: InputVariant; | ||
variant?: InputVariant; | ||
size?: InputSize; //default: medium(p: 1.2rem) | ||
label?: string; | ||
LeftIcon?: React.FunctionComponent<React.SVGProps<SVGSVGElement>>; //svg 컴포넌트 | ||
isError?: boolean; | ||
isNotice?: boolean; | ||
supportingText?: string; | ||
} | ||
|
||
const Input = ({ variant, size = 'medium', label, LeftIcon, ...props }: InputProps) => { | ||
const Input = ( | ||
{ | ||
variant = 'default', | ||
size = 'medium', | ||
label, | ||
LeftIcon, | ||
isError = false, | ||
isNotice = false, | ||
supportingText, | ||
...props | ||
}: InputProps, | ||
ref: ForwardedRef<HTMLInputElement> | ||
) => { | ||
return ( | ||
<article css={inputContainerStyle}> | ||
<article css={containerStyle}> | ||
{label && <Label id={label}>{label}</Label>} | ||
<div css={[inputWarpperStyle, variantStyle(variant), sizeStyle(size)]}> | ||
<div css={[warpperStyle, variantStyle({ variant, isError }), sizeStyle(size)]}> | ||
{LeftIcon && <LeftIcon />} | ||
<input css={[inputStyle]} {...props} /> | ||
<input ref={ref} css={inputStyle} {...props} /> | ||
</div> | ||
{supportingText && ( | ||
<SupportingText isError={isError} isNotice={isNotice}> | ||
{supportingText} | ||
</SupportingText> | ||
)} | ||
</article> | ||
); | ||
}; | ||
|
||
export default Input; | ||
export default forwardRef(Input); |
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,9 @@ | ||
import { css } from '@emotion/react'; | ||
|
||
import { theme } from '@/common/style/theme/theme'; | ||
|
||
export const textStyle = (isError: boolean, isNotice: boolean) => { | ||
const textColor = isError ? theme.colors.red : isNotice ? theme.colors.blue_900 : theme.colors.gray_400; | ||
|
||
return css({ color: textColor, wordBreak: 'break-word', ...theme.text.body04 }); | ||
}; |
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,14 @@ | ||
import { ComponentPropsWithoutRef } from 'react'; | ||
|
||
import { textStyle } from '@/common/component/SupportingText/SupportingText.style'; | ||
|
||
interface SupportingTextProps extends ComponentPropsWithoutRef<'p'> { | ||
isError?: boolean; | ||
isNotice?: boolean; | ||
} | ||
|
||
const SupportingText = ({ isError = false, isNotice = false, children }: SupportingTextProps) => { | ||
return <p css={textStyle(isError, isNotice)}>{children}</p>; | ||
}; | ||
|
||
export default SupportingText; |
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