-
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.
* feat(packages/ui): Label 컴포넌트 구현 * chore(packages/ui): Label 컴포넌트 예시
- Loading branch information
1 parent
f86ef1d
commit 0315ea4
Showing
4 changed files
with
72 additions
and
1 deletion.
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,17 @@ | ||
import { vars } from '@repo/theme'; | ||
import { style } from '@vanilla-extract/css'; | ||
|
||
export const labelStyle = style({ | ||
display: 'flex', | ||
alignItems: 'center', | ||
fontSize: vars.typography.fontSize[20], | ||
fontWeight: vars.typography.fontWeight.semibold, | ||
}); | ||
|
||
export const requiredStyle = style({ | ||
gap: vars.space[4], | ||
}); | ||
|
||
export const optionalStyle = style({ | ||
gap: vars.space[8], | ||
}); |
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,47 @@ | ||
import { forwardRef, LabelHTMLAttributes } from 'react'; | ||
import { Text } from '../Text/Text'; | ||
import { labelStyle, requiredStyle, optionalStyle } from './Label.css'; | ||
|
||
export type LabelVariant = 'default' | 'required' | 'optional'; | ||
|
||
export type LabelProps = LabelHTMLAttributes<HTMLLabelElement> & { | ||
variant?: LabelVariant; | ||
}; | ||
|
||
const LABEL_CLASS = { | ||
default: undefined, | ||
required: requiredStyle, | ||
optional: optionalStyle, | ||
} as const; | ||
|
||
export const Label = forwardRef<HTMLLabelElement, LabelProps>( | ||
({ children, variant = 'default', className, ...props }, ref) => { | ||
return ( | ||
<label | ||
ref={ref} | ||
className={`${labelStyle} ${LABEL_CLASS[variant]} ${className}`} | ||
aria-required={variant === 'required'} | ||
{...props} | ||
> | ||
{children} | ||
{variant === 'required' && ( | ||
<Text | ||
as="span" | ||
fontSize={20} | ||
fontWeight="semibold" | ||
color="primary600" | ||
> | ||
* | ||
</Text> | ||
)} | ||
{variant === 'optional' && ( | ||
<Text as="span" fontSize={16} fontWeight="semibold" color="grey300"> | ||
선택 | ||
</Text> | ||
)} | ||
</label> | ||
); | ||
} | ||
); | ||
|
||
Label.displayName = 'Label'; |
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