Skip to content
This repository has been archived by the owner on Feb 11, 2023. It is now read-only.

Commit

Permalink
feat: Create form wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
re-taro committed Dec 13, 2022
1 parent aa6b224 commit 4bd9603
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/components/shared/form/wrapper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type {
FormControlProps,
FormErrorMessageProps,
FormLabelProps,
HelpTextProps,
} from "@chakra-ui/react";
import {
FormControl,
FormErrorMessage,
FormHelperText,
FormLabel,
} from "@chakra-ui/react";
import type { ReactNode, FC } from "react";

export type WrapperProps = {
label?: FormLabelProps["children"];
errorText?: FormErrorMessageProps["children"];
helperText?: HelpTextProps["children"];
children?: ReactNode;
} & Pick<FormControlProps, "isInvalid" | "isRequired">;

export const Wrapper: FC<WrapperProps> = ({
label,
errorText,
helperText,
isInvalid,
isRequired,
children,
}) => (
<FormControl isInvalid={isInvalid} isRequired={isRequired}>
{label && <FormLabel>{label}</FormLabel>}
{children}
{errorText && <FormErrorMessage>{errorText}</FormErrorMessage>}
{helperText && <FormHelperText>{helperText}</FormHelperText>}
</FormControl>
);

0 comments on commit 4bd9603

Please sign in to comment.