Skip to content

Commit

Permalink
feat: form-label에 required props 및 ui 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
DongjaJ committed Jan 18, 2025
1 parent 6c8fd1d commit 22f41b5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
27 changes: 26 additions & 1 deletion src/ui/form/form-item.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ const meta: Meta<typeof FormField> = {
control: form.control as any,
}}
/>
{/*
// error State는 이렇게 관리, storybook에선 보여주기 힘듬
<FormField
control={form.control}
name="username"
Expand All @@ -71,7 +73,7 @@ const meta: Meta<typeof FormField> = {
<FormErrorMessage />
</FormItem>
)}
/>
/> */}
<button hidden />
</form>
</Form>
Expand Down Expand Up @@ -106,6 +108,29 @@ export const First: Story = {
),
};

export const required: Story = {
render: (args) => (
<FormField
control={args.control}
name="username"
render={({ field }) => (
<FormItem>
<FormLabel required>폼 라밸</FormLabel>
<InputContainer>
<Input {...field} />
{field.value && (
<InputRightElement>
<DeleteCir />
</InputRightElement>
)}
</InputContainer>
<FormErrorMessage />
</FormItem>
)}
/>
),
};

export const WithoutLabel: Story = {
render: (args) => (
<FormField
Expand Down
6 changes: 6 additions & 0 deletions src/ui/form/form-label.styles.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,11 @@ export const formLabelBase = style([
typography('body_2_14_sb'),
{
color: globalVars.color.grey800,
display: 'flex',
gap: 4,
},
]);

export const requiredIcon = style({
color: globalVars.color.mainblue500,
});
8 changes: 5 additions & 3 deletions src/ui/form/form-label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { cx } from '../util.ts';
import { useFormField } from './form-field.tsx';
import * as styles from './form-label.styles.css.ts';

export type FormLabelProps = ComponentProps<'label'>;
export type FormLabelProps = ComponentProps<'label'> & {
required?: boolean;
};

// TODO required 속성 지원 필요
export const FormLabel = (props: FormLabelProps) => {
const { children, className, ...restProps } = props;
const { children, className, required, ...restProps } = props;

const { formItemId } = useFormField();
return (
Expand All @@ -17,6 +18,7 @@ export const FormLabel = (props: FormLabelProps) => {
className={cx(styles.formLabelBase, className)}
>
{children}
{required && <span className={styles.requiredIcon}>*</span>}
</label>
);
};

0 comments on commit 22f41b5

Please sign in to comment.