Skip to content

Commit

Permalink
fix: TopAddon 을 활용한 방식으로 문서 수정,
Browse files Browse the repository at this point in the history
  • Loading branch information
Brokyeom committed Dec 2, 2024
1 parent dc0815a commit 5a567c4
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 19 deletions.
57 changes: 50 additions & 7 deletions apps/docs/src/stories/FieldBox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
FieldBoxProps,
FieldBoxLabelProps,
FieldBoxBottomAddonProps,
FieldBoxLabel,
TextField,
TextArea,
Radio,
Expand All @@ -22,7 +21,16 @@ type FieldBoxStoryProps = FieldBoxProps & FieldBoxLabelProps & FieldBoxBottomAdd
* #### 예시 코드
* ```tsx
* <FieldBox>
* topAddon={<FieldBox.Label label='안녕?' description='디스크립션' required />}
* topAddon={
* <FieldBox.TopAddon
* leftAddon={<FieldBox.Label label={args.label} description={args.description} required={args.required} />}
* rightAddon={
* <Button variant='outlined' size='sm' disabled>
* 미리보기
* </Button>
* }
* />
* }
* bottomAddon={
* <FieldBox.BottomAddon
* leftAddon={<div style={{ color: colors.white }}>레프트애드온</div>}
Expand Down Expand Up @@ -63,7 +71,14 @@ export const WithTextField: StoryObj<FieldBoxStoryProps> = {
return (
<FieldBox
topAddon={
<FieldBoxLabel label={args.label} description={args.description} required={args.required}></FieldBoxLabel>
<FieldBox.TopAddon
leftAddon={<FieldBox.Label label={args.label} description={args.description} required={args.required} />}
rightAddon={
<Button variant='outlined' size='sm' disabled>
미리보기
</Button>
}
/>
}
bottomAddon={
<FieldBox.BottomAddon
Expand All @@ -88,7 +103,14 @@ export const WithTextArea: StoryObj<FieldBoxStoryProps> = {
return (
<FieldBox
topAddon={
<FieldBoxLabel label={args.label} description={args.description} required={args.required}></FieldBoxLabel>
<FieldBox.TopAddon
leftAddon={<FieldBox.Label label={args.label} description={args.description} required={args.required} />}
rightAddon={
<Button variant='outlined' size='sm' disabled>
미리보기
</Button>
}
/>
}
bottomAddon={
<FieldBox.BottomAddon
Expand All @@ -114,7 +136,14 @@ export const WithRadio: StoryObj<FieldBoxStoryProps> = {
return (
<FieldBox
topAddon={
<FieldBoxLabel label={args.label} description={args.description} required={args.required}></FieldBoxLabel>
<FieldBox.TopAddon
leftAddon={<FieldBox.Label label={args.label} description={args.description} required={args.required} />}
rightAddon={
<Button variant='outlined' size='sm' disabled>
미리보기
</Button>
}
/>
}
bottomAddon={
<FieldBox.BottomAddon
Expand Down Expand Up @@ -146,7 +175,14 @@ export const WithCheckBox: StoryObj<FieldBoxStoryProps> = {
return (
<FieldBox
topAddon={
<FieldBoxLabel label={args.label} description={args.description} required={args.required}></FieldBoxLabel>
<FieldBox.TopAddon
leftAddon={<FieldBox.Label label={args.label} description={args.description} required={args.required} />}
rightAddon={
<Button variant='outlined' size='sm' disabled>
미리보기
</Button>
}
/>
}
bottomAddon={
<FieldBox.BottomAddon
Expand Down Expand Up @@ -180,7 +216,14 @@ export const WithChip: StoryObj<FieldBoxStoryProps> = {
return (
<FieldBox
topAddon={
<FieldBoxLabel label={args.label} description={args.description} required={args.required}></FieldBoxLabel>
<FieldBox.TopAddon
leftAddon={<FieldBox.Label label={args.label} description={args.description} required={args.required} />}
rightAddon={
<Button variant='outlined' size='sm' disabled>
미리보기
</Button>
}
/>
}
bottomAddon={
<FieldBox.BottomAddon
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/FieldBox/FieldBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const FieldBoxImpl = forwardRef<HTMLDivElement, FieldBoxProps>((props, forwarded
return (
<div ref={forwardedRef} {...restProps}>
{topAddon}
<div>{children}</div>
<div>{bottomAddon}</div>
{children}
{bottomAddon}
</div>
);
});
Expand Down
12 changes: 7 additions & 5 deletions packages/ui/FieldBox/components/Label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ export const FieldBoxLabel = forwardRef<HTMLDivElement, FieldBoxLabelProps>((pro
return (
<div aria-label={label} aria-required={required} ref={forwardedRef}>
<label className={TopAddonLabelStyle}>
<span>
{label}
{required ? <span className={requiredMarkStyle}>*</span> : null}
</span>
<p className={TopAddonDescriptionStyle}>{description}</p>
{label ? (
<span>
{label}
{required ? <span className={requiredMarkStyle}>*</span> : null}
</span>
) : null}
{description ? <p className={TopAddonDescriptionStyle}>{description}</p> : null}
</label>
</div>
);
Expand Down
3 changes: 2 additions & 1 deletion packages/ui/FieldBox/style.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import theme from '../theme.css';
export const TopAddonLabelStyle = style({
...theme.fontsObject.LABEL_3_14_SB,
display: 'flex',
gap: '8px',
flexDirection: 'column',
textAlign: 'left',
color: theme.colors.white,
Expand All @@ -12,7 +13,6 @@ export const TopAddonLabelStyle = style({
export const TopAddonDescriptionStyle = style({
...theme.fontsObject.LABEL_4_12_SB,
color: theme.colors.gray300,
marginBottom: '8px',
});

export const requiredMarkStyle = style({
Expand All @@ -21,6 +21,7 @@ export const requiredMarkStyle = style({
});

export const topAddonContainerStyle = style({
marginBottom: '8px',
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
Expand Down
10 changes: 6 additions & 4 deletions packages/ui/Input/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ const TextField = forwardRef<HTMLInputElement, TextFieldProps>((props, ref) => {
return (
<FieldBox
bottomAddon={
<FieldBox.BottomAddon
leftAddon={hasError() && errorMessage ? <FieldBox.ErrorMessage message={errorMessage} /> : null}
rightAddon={bottomAddon}
/>
(hasError() && errorMessage) || bottomAddon ? (
<FieldBox.BottomAddon
leftAddon={hasError() && errorMessage ? <FieldBox.ErrorMessage message={errorMessage} /> : null}
rightAddon={bottomAddon}
/>
) : null
}
className={className}
ref={ref}
Expand Down

0 comments on commit 5a567c4

Please sign in to comment.