Skip to content

Commit

Permalink
[Feat] Label 컴포넌트 구현 (#61)
Browse files Browse the repository at this point in the history
* feat(packages/ui): Label 컴포넌트 구현

* chore(packages/ui): Label 컴포넌트 예시
  • Loading branch information
minseong0324 authored Jan 15, 2025
1 parent f86ef1d commit 0315ea4
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 1 deletion.
7 changes: 6 additions & 1 deletion apps/web/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import { Icon, Toast, Text, Badge, Checkbox } from '@repo/ui';
import { Icon, Toast, Text, Badge, Checkbox, Label } from '@repo/ui';
import { overlay } from 'overlay-kit';

export default function Home() {
Expand Down Expand Up @@ -60,6 +60,11 @@ export default function Home() {
<Checkbox label="체크박스" />
<Checkbox label="체크박스" disabled checked />
<Checkbox label="체크박스" disabled />
<div style={{ display: 'flex', flexDirection: 'column', gap: '8px' }}>
<Label variant="default">어떤 글을 생성할까요?</Label>
<Label variant="required">어떤 글을 생성할까요?</Label>
<Label variant="optional">어떤 글을 생성할까요?</Label>
</div>
</div>
);
}
17 changes: 17 additions & 0 deletions packages/ui/src/components/Label/Label.css.ts
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],
});
47 changes: 47 additions & 0 deletions packages/ui/src/components/Label/Label.tsx
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';
2 changes: 2 additions & 0 deletions packages/ui/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ export { Badge } from './Badge/Badge';
export type { BadgeProps } from './Badge/Badge';
export { Checkbox } from './Checkbox/Checkbox';
export type { CheckboxProps } from './Checkbox/Checkbox';
export { Label } from './Label/Label';
export type { LabelProps, LabelVariant } from './Label/Label';

0 comments on commit 0315ea4

Please sign in to comment.