Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/FE-053 : Input 컴포넌트 fixed Height helper text 대응 #73

Merged
merged 3 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/app/login/components/LoginForm/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const LoginForm = () => {
name="email"
placeholder="회사 이메일"
showError={true}
fix
/>
</InputSection>
<InputSection label="비밀번호" direction="column">
Expand All @@ -54,6 +55,7 @@ const LoginForm = () => {
name="password"
placeholder="비밀번호"
showError={true}
fix
/>
</InputSection>
{<LoginButton submitErrorMsg={errors?.submit?.message as string} />}
Expand Down
11 changes: 11 additions & 0 deletions src/components/Input/Input.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,17 @@ export const inputError = style({
border: `1px solid ${color.red500}`,
});

export const fixedError = recipe({
base: {},
variants: {
fix: {
true: {
height: space.lg,
},
},
},
});

globalStyle(`${clearButton} > img`, {
margin: '0 auto',
backgroundPosition: 'center',
Expand Down
5 changes: 3 additions & 2 deletions src/components/Input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ type InputProps = {
name: string;
type?: Type;
showError?: boolean;
fix?: boolean;
} & React.ComponentPropsWithoutRef<'input'>;

const Input = forwardRef(function Input(props: InputProps, ref: ForwardedRef<HTMLInputElement>) {
const { type, name, placeholder, showError, className, ...rest } = props;
const { type, name, placeholder, showError, className, fix, ...rest } = props;
const { formState, resetField } = useFormContext();
const handleReset = useCallback(() => resetField(name, { defaultValue: '', keepDirty: false }), [name, resetField]);
const errorMessage = formState.errors[name]?.message as string;
Expand Down Expand Up @@ -57,7 +58,7 @@ const Input = forwardRef(function Input(props: InputProps, ref: ForwardedRef<HTM
<SvgIcon id="clear" width={24} height={24} />
</button>
</div>
<InputErrorMessage name={name} showError={showError} />
<InputErrorMessage name={name} showError={showError} fix={fix} />
</div>
);
});
Expand Down
24 changes: 14 additions & 10 deletions src/components/Input/InputErrorMessage.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import Typography from '../Typography/Typography';
import { useFormContext } from 'react-hook-form';
import { fixedError } from './Input.css';

type errorProps = {
name: string;
showError?: boolean;
name: string;
showError?: boolean;
fix?: boolean;
};

const InputErrorMessage = ({ name, showError = true }: errorProps) => {
const { formState } = useFormContext();
const errorMessage = showError && (formState.errors[name]?.message as string);
const InputErrorMessage = ({ name, showError = true, fix = false }: errorProps) => {
const { formState } = useFormContext();
const errorMessage = showError && (formState.errors[name]?.message as string);

return (
<Typography style={{ marginTop: '8px' }} color="red500" variant="label5" as="p">
{errorMessage}
</Typography>
);
return (
<div className={fixedError({ fix })}>
<Typography style={{ marginTop: '8px' }} color="red500" variant="label5" as="p">
{errorMessage}
</Typography>
</div>
);
};

export default InputErrorMessage;