import { yupResolver } from "@hookform/resolvers/yup"; import { Meta } from "@storybook/react"; import { useForm } from "react-hook-form"; import * as Yup from "yup"; import React, { useRef } from "react"; import { Input } from ":/components/Forms/Input/index"; import { Button } from ":/components/Button"; import { getFieldState, getFieldErrorMessage, onSubmit, } from ":/tests/reactHookFormUtils"; export default { title: "Components/Forms/Input", component: Input, } as Meta; export const Default = { args: { defaultValue: "Hello world", label: "Your name", }, }; export const Success = { args: { defaultValue: "Hello world", label: "Your name", state: "success", icon: person, text: "This is an optional success message", }, }; export const Error = { args: { defaultValue: "Hello world", label: "Your name", state: "error", icon: person, text: "This is an optional error message", }, }; export const DisabledEmpty = { args: { label: "Your name", icon: person, disabled: true, }, }; export const DisabledFilled = { args: { label: "Your name", defaultValue: "John Doe", icon: person, disabled: true, }, }; export const Empty = { args: { label: "Your email", }, }; export const Icon = { args: { label: "Account balance", icon: attach_money, defaultValue: "1000", }, }; export const IconRight = { args: { label: "Account balance", rightIcon: attach_money, defaultValue: "1000", }, }; export const IconBoth = { args: { label: "Not a recommended use", icon: attach_money, rightIcon: attach_money, defaultValue: "Is isn't recommended to use both icons", }, }; export const OverflowingText = { args: { label: "Your name", icon: attach_money, defaultValue: "John Dave Mike Smith Doe Junior Senior Yoda Skywalker", }, }; export const WithText = { args: { defaultValue: "Hello world", label: "Your name", text: "This is a text, you can display anything you want here like warnings, informations or errors.", }, }; export const WithTextRight = { args: { defaultValue: "Hello world", label: "Your name", rightText: "0/300", }, }; export const WithBothTexts = { args: { defaultValue: "Hello world", label: "Your name", text: "This is a text, you can display anything you want here like warnings, informations or errors.", rightText: "0/300", }, }; export const FullWidth = { args: { defaultValue: "Hello world", label: "Your name", fullWidth: true, text: "This is a text, you can display anything you want here like warnings, informations or errors.", rightText: "0/300", }, }; export const CharCounter = { args: { defaultValue: "CEO", label: "Job title", text: "This is a text, you can display anything you want here like warnings, informations or errors.", charCounter: true, charCounterMax: 30, }, }; export const Controlled = () => { const [value, setValue] = React.useState("I am controlled"); return (
Value: {value}
setValue(e.target.value)} />
); }; export const NonControlled = () => { return ; }; export const WithRef = () => { const ref = useRef(null); return (
); }; export const ReactHookForm = () => { interface InputExampleFormValues { email: string; } const inputExampleSchema = Yup.object().shape({ email: Yup.string().email().required(), }); const { register, handleSubmit, formState } = useForm( { defaultValues: { email: "", }, mode: "onChange", reValidateMode: "onChange", resolver: yupResolver(inputExampleSchema), }, ); return (
); }; export const FormExample = () => { return (
apartment} />
location_on} />
map} />
); };