diff --git a/src/stories/form/Form.stories.tsx b/src/stories/form/Form.stories.tsx index 9deaecc..78dbb0e 100644 --- a/src/stories/form/Form.stories.tsx +++ b/src/stories/form/Form.stories.tsx @@ -1,4 +1,4 @@ -import { Field } from "./Form"; +import { ErrorMessageWrapper, Field } from "./Form"; import { Checkbox } from "./checkBox/Checkbox"; import { Story, Meta } from "@storybook/react"; import { Formik, Form, FormikProps } from "formik"; @@ -69,5 +69,8 @@ export const Template: Story = () => ( )} +
+ Generic Error outside Formik +
); diff --git a/src/stories/form/Form.tsx b/src/stories/form/Form.tsx index b149269..974c7d5 100644 --- a/src/stories/form/Form.tsx +++ b/src/stories/form/Form.tsx @@ -1,4 +1,5 @@ import { + ErrorMessageProps, FieldProps, ErrorMessage as FormikErrorMessage, Field as FormikField, @@ -12,32 +13,21 @@ import FormLabel from "./formlabel/FormLabel"; import Input from "./input/Input"; import { Radio } from "./radio/Radio"; -const ErrorMessageWrapper = styled.div` - display: flex; - align-items: center; - gap: ${(props) => props.theme.grid.sizes[2]}; -`; - -const BasicErrorMessage = ({ - name, - className, +export const ErrorMessageWrapper = ({ + children, }: { - name: string; - className?: string; + children: React.ReactNode; }) => ( -
- - {(msg) => ( - - - {msg} - - )} - -
+ + + {children} + ); -export const ErrorMessage = styled(BasicErrorMessage)` +const StyledErrorMessage = styled.div` + display: flex; + align-items: center; + gap: ${(props) => props.theme.grid.sizes[2]}; color: ${(props) => props.theme.palette.danger}; width: 100%; margin-top: 0.25rem; @@ -47,6 +37,12 @@ export const ErrorMessage = styled(BasicErrorMessage)` } `; +export const ErrorMessage = ({ ...props }: ErrorMessageProps) => ( + + {(msg) => {msg}} + +); + export const Field = ({ type = "text", placeholder,