@saas-ui/forms 0.3.4 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- {"version":3,"file":"index.modern.js","sources":["../src/display-field.tsx","../src/field.tsx","../src/resolvers/yup.ts","../src/layout.tsx","../src/utils.ts","../src/use-array-field.tsx","../src/array-field.tsx","../src/object-field.tsx","../src/fields.tsx","../src/form.tsx","../src/submit-button.tsx","../src/auto-form.tsx","../src/display-if.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useFormContext } from 'react-hook-form'\n\nimport {\n Text,\n FormControl,\n FormControlProps,\n FormLabel,\n} from '@chakra-ui/react'\n\nimport { FieldProps } from './field'\n\nexport interface DisplayFieldProps\n extends FormControlProps,\n Omit<FieldProps, 'type' | 'label'> {}\n\nexport const DisplayField: React.FC<DisplayFieldProps> = ({\n name,\n label,\n placeholder,\n ...props\n}) => {\n const { getValues } = useFormContext()\n\n return (\n <FormControl {...props}>\n {label ? <FormLabel htmlFor={name}>{label}</FormLabel> : null}\n <Text fontSize=\"md\">{getValues(name)}</Text>\n </FormControl>\n )\n}\n","import * as React from 'react'\nimport {\n useFormContext,\n FormState,\n Controller,\n get,\n RegisterOptions,\n FieldValues,\n FieldPath,\n} from 'react-hook-form'\n\nimport {\n forwardRef,\n Box,\n FormControl,\n FormControlProps,\n FormLabel,\n FormHelperText,\n FormErrorMessage,\n Input,\n Textarea,\n Checkbox,\n Switch,\n useMergeRefs,\n} from '@chakra-ui/react'\n\nimport { NumberInput } from '@saas-ui/number-input'\nimport { PasswordInput } from '@saas-ui/password-input'\nimport { RadioInput } from '@saas-ui/radio'\nimport { PinInput } from '@saas-ui/pin-input'\nimport { Select, NativeSelect } from '@saas-ui/select'\n\nexport interface Option {\n value: string\n label?: string\n [key: string]: unknown\n}\n\nexport type FieldRules = Pick<\n RegisterOptions,\n 'required' | 'min' | 'max' | 'maxLength' | 'minLength' | 'pattern'\n>\n\nexport type FieldTypes =\n | 'text'\n | 'number'\n | 'password'\n | 'textarea'\n | 'select'\n | 'native-select'\n | 'checkbox'\n | 'radio'\n | 'switch'\n | 'pin'\n | string\n\nexport interface FieldProps<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\n> extends Omit<FormControlProps, 'label' | 'type'> {\n /**\n * The field name\n */\n name: TName\n /**\n * The field label\n */\n label?: string\n /**\n * Hide the field label\n */\n hideLabel?: boolean\n /**\n * Field help text\n */\n help?: string\n /**\n * React hook form rules\n */\n rules?: Omit<\n RegisterOptions<TFieldValues, TName>,\n 'valueAsNumber' | 'valueAsDate' | 'setValueAs' | 'disabled'\n >\n /**\n * Options used for selects and radio fields\n */\n options?: Option[]\n /**\n * The field type\n * Build-in types:\n * - text\n * - number\n * - password\n * - textarea\n * - select\n * - native-select\n * - checkbox\n * - radio\n * - switch\n * - pin\n *\n * Will default to a text field if there is no matching type.\n * @default 'text'\n */\n type?: FieldTypes\n /**\n * The input placeholder\n */\n placeholder?: string\n}\n\nconst inputTypes: Record<FieldTypes, any> = {}\n\nconst defaultInputType = 'text'\n\nconst getInput = (type: string) => {\n return inputTypes[type] || inputTypes[defaultInputType]\n}\n\nconst getError = (name: string, formState: FormState<{ [x: string]: any }>) => {\n return get(formState.errors, name)\n}\n\nconst isTouched = (\n name: string,\n formState: FormState<{ [x: string]: any }>\n) => {\n return get(formState.touchedFields, name)\n}\n\nexport const BaseField: React.FC<FieldProps> = (props) => {\n const { name, label, help, variant, hideLabel, children, ...controlProps } =\n props\n\n const { formState } = useFormContext()\n\n const error = getError(name, formState)\n\n return (\n <FormControl variant={variant} {...controlProps} isInvalid={!!error}>\n {label && !hideLabel ? (\n <FormLabel variant={variant}>{label}</FormLabel>\n ) : null}\n <Box>\n {children}\n {help && !error?.message ? (\n <FormHelperText>{help}</FormHelperText>\n ) : null}\n {error?.message && (\n <FormErrorMessage>{error?.message}</FormErrorMessage>\n )}\n </Box>\n </FormControl>\n )\n}\nexport const Field = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FieldProps<TFieldValues> & {\n [key: string]: unknown // Make sure attributes of custom components work. Need to change this to a global typedef at some point.\n },\n ref: React.ForwardedRef<typeof FormControl>\n ) => {\n const { type = defaultInputType } = props\n const InputComponent = getInput(type)\n\n return <InputComponent ref={ref} {...props} />\n }\n) as <TFieldValues extends FieldValues>(\n props: FieldProps<TFieldValues> & {\n [key: string]: unknown\n } & {\n ref?: React.ForwardedRef<typeof FormControl>\n }\n) => React.ReactElement\n\ninterface CreateFieldProps {\n displayName: string\n hideLabel?: boolean\n BaseField: React.FC<any>\n}\n\nconst createField = (\n InputComponent: React.FC<any>,\n { displayName, hideLabel, BaseField }: CreateFieldProps\n) => {\n const Field = forwardRef<FieldProps, typeof FormControl>((props, ref) => {\n const {\n name,\n label,\n help,\n isDisabled,\n isInvalid,\n isReadOnly,\n isRequired,\n rules,\n variant,\n ...inputProps\n } = props\n\n const inputRules = {\n required: isRequired,\n ...rules,\n }\n\n return (\n <BaseField\n name={name}\n label={label}\n help={help}\n hideLabel={hideLabel}\n isDisabled={isDisabled}\n isInvalid={isInvalid}\n isReadOnly={isReadOnly}\n isRequired={isRequired}\n variant={variant}\n >\n <InputComponent\n ref={ref}\n name={name}\n label={label}\n rules={inputRules}\n {...inputProps}\n />\n </BaseField>\n )\n })\n Field.displayName = displayName\n\n return Field\n}\n\nexport const withControlledInput = (InputComponent: any) => {\n return forwardRef<FieldProps, typeof InputComponent>(\n ({ name, rules, ...inputProps }, ref) => {\n const { control } = useFormContext()\n\n return (\n <Controller\n name={name}\n control={control}\n rules={rules}\n render={({ field: { ref: _ref, ...field } }) => (\n <InputComponent\n {...field}\n {...inputProps}\n ref={useMergeRefs(ref, _ref)}\n />\n )}\n />\n )\n }\n )\n}\n\nexport const withUncontrolledInput = (InputComponent: any) => {\n return forwardRef<FieldProps, typeof InputComponent>(\n ({ name, rules, ...inputProps }, ref) => {\n const { register } = useFormContext()\n\n const { ref: _ref, ...field } = register(name, rules)\n\n return (\n <InputComponent\n {...field}\n {...inputProps}\n ref={useMergeRefs(ref, _ref)}\n />\n )\n }\n )\n}\n\nexport interface RegisterFieldTypeOptions {\n isControlled?: boolean\n hideLabel?: boolean\n BaseField?: React.FC<any>\n}\n\n/**\n * Register a new field type\n * @param type The name for this field in kebab-case, eg `email` or `array-field`\n * @param component The React component\n * @param options\n * @param options.isControlled Set this to true if this is a controlled field.\n * @param options.hideLabel Hide the field label, for example for checkbox or switch field.\n */\nexport const registerFieldType = (\n type: string,\n component: React.FC<any>,\n options?: RegisterFieldTypeOptions\n) => {\n let InputComponent\n if (options?.isControlled) {\n InputComponent = withControlledInput(component)\n } else {\n InputComponent = withUncontrolledInput(component)\n }\n\n const Field = createField(InputComponent, {\n displayName: `${type\n .split('-')\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join('')}Field`,\n hideLabel: options?.hideLabel,\n BaseField: options?.BaseField || BaseField,\n })\n\n inputTypes[type] = Field\n\n return Field\n}\n\n// @todo Consider not registering all fields by default to lower the package size and computations.\n// Not all types may be required in a project.\nexport const InputField = registerFieldType('text', Input)\nexport const NumberInputField = registerFieldType('number', NumberInput, {\n isControlled: true,\n})\nexport const PasswordInputFIeld = registerFieldType('password', PasswordInput)\nexport const TextareaField = registerFieldType('textarea', Textarea)\nexport const SwitchField = registerFieldType(\n 'switch',\n forwardRef(({ label, ...props }: { label?: string }, ref) => {\n return (\n <Switch ref={ref} {...props}>\n {label}\n </Switch>\n )\n }),\n {\n isControlled: true,\n hideLabel: true,\n }\n)\nexport const SelectField = registerFieldType('select', Select, {\n isControlled: true,\n})\nexport const CheckboxField = registerFieldType(\n 'checkbox',\n forwardRef(({ label, ...props }: { label?: string }, ref) => {\n return (\n <Checkbox ref={ref} {...props}>\n {label}\n </Checkbox>\n )\n }),\n {\n hideLabel: true,\n }\n)\nexport const RadioField = registerFieldType('radio', RadioInput, {\n isControlled: true,\n})\nexport const PinField = registerFieldType('pin', PinInput, {\n isControlled: true,\n})\nexport const NativeSelectField = registerFieldType(\n 'native-select',\n NativeSelect,\n { isControlled: true }\n)\n","import { SchemaOf, AnySchema, reach } from 'yup'\nexport { yupResolver } from '@hookform/resolvers/yup'\n\nimport { FieldProps } from '../field'\n\n// @TODO get proper typings for the schema fields\n\nconst getType = (field: any) => {\n if (field.spec.meta?.type) {\n return field.spec.meta.type\n }\n\n switch (field.type) {\n case 'array':\n return 'array'\n case 'object':\n return 'object'\n case 'number':\n return 'number'\n case 'date':\n return 'date'\n case 'string':\n default:\n return 'text'\n }\n}\n\ntype Options = {\n min?: number\n max?: number\n}\n\nconst getArrayOption = (field: any, name: string) => {\n for (const test of field.tests) {\n if (test.OPTIONS?.params[name]) return test.OPTIONS.params[name]\n }\n}\n\n/**\n * A helper function to render forms automatically based on a Yup schema\n *\n * @param schema The Yup schema\n * @returns {FieldProps[]}\n */\nexport const getFieldsFromSchema = (\n schema: SchemaOf<AnySchema>\n): FieldProps[] => {\n const fields = []\n\n let schemaFields: Record<string, any> = {}\n if (schema.type === 'array') {\n /* @ts-ignore this is actually valid */\n schemaFields = schema.innerType.fields\n } else {\n schemaFields = schema.fields\n }\n\n for (const name in schemaFields) {\n const field = schemaFields[name]\n\n const options: Options = {}\n if (field.type === 'array') {\n options.min = getArrayOption(field, 'min')\n options.max = getArrayOption(field, 'max')\n }\n\n fields.push({\n name,\n label: field.spec.label || name,\n type: getType(field),\n ...options,\n })\n }\n return fields\n}\n\nexport const getNestedSchema = (schema: SchemaOf<AnySchema>, path: string) => {\n return reach(schema, path)\n}\n","import * as React from 'react'\n\nimport { chakra, SimpleGrid, SimpleGridProps, useTheme } from '@chakra-ui/react'\n\nexport type FormLayoutProps = SimpleGridProps\n\ninterface FormLayoutItemProps {\n children: React.ReactNode\n}\n\nconst FormLayoutItem: React.FC<FormLayoutItemProps> = ({ children }) => {\n return <chakra.div>{children}</chakra.div>\n}\n\n/**\n * FormLayout\n *\n * Renders form items in a `SimpleGrid`\n * @see https://chakra-ui.com/docs/layout/simple-grid\n */\nexport const FormLayout = ({ children, ...props }: FormLayoutProps) => {\n const theme = useTheme()\n\n const defaultProps = theme.components?.FormLayout?.defaultProps ?? {\n spacing: 4,\n }\n\n const gridProps = {\n ...defaultProps,\n ...props,\n }\n\n return (\n <SimpleGrid {...gridProps}>\n {React.Children.map(children, (child) => {\n if (React.isValidElement(child)) {\n return <FormLayoutItem>{child}</FormLayoutItem>\n }\n return child\n })}\n </SimpleGrid>\n )\n}\n","import * as React from 'react'\n\nexport const mapNestedFields = (name: string, children: React.ReactNode) => {\n return React.Children.map(children, (child) => {\n if (React.isValidElement(child) && child.props.name) {\n return React.cloneElement(child, {\n ...child.props,\n name: `${name}.${child.props.name}`,\n })\n }\n return child\n })\n}\n","import * as React from 'react'\nimport {\n useFieldArray,\n useFormContext,\n UseFieldArrayReturn,\n} from 'react-hook-form'\n\nimport { createContext } from '@chakra-ui/react-utils'\n\nexport interface UseArrayFieldReturn extends UseFieldArrayReturn {\n /**\n * The array field name\n */\n name: string\n /**\n * The default value for new items\n */\n defaultValue: Record<string, any>\n /**\n * Min amount of items\n */\n min?: number\n /**\n * Max amount of items\n */\n max?: number\n}\n\nexport const [ArrayFieldProvider, useArrayFieldContext] =\n createContext<UseArrayFieldReturn>({\n name: 'ArrayFieldContext',\n })\n\nexport interface UseArrayFieldRowReturn {\n /**\n * Name of the array field including the index, eg 'field.0'\n */\n name: string\n /**\n * The field index\n */\n index: number\n /**\n * Remove this array item\n */\n remove: () => void\n /**\n * True if this is the first item\n */\n isFirst: boolean\n /**\n * True if this is the last item\n */\n isLast: boolean\n}\n\nexport const [ArrayFieldRowProvider, useArrayFieldRowContext] =\n createContext<UseArrayFieldRowReturn>({\n name: 'ArrayFieldRowContext',\n })\n\nexport interface ArrayFieldOptions {\n /**\n * The field name\n */\n name: string\n /**\n * Default value for new values in the array\n */\n defaultValue?: Record<string, any>\n /**\n * Default key name for rows, change this if your data uses 'id'\n * @default \"id\"\n */\n keyName?: string\n min?: number\n max?: number\n}\n\nexport const useArrayField = ({\n name,\n defaultValue = {},\n keyName,\n min,\n max,\n}: ArrayFieldOptions) => {\n const { control } = useFormContext()\n const context = useFieldArray({\n control,\n name,\n keyName,\n })\n\n return {\n ...context,\n name,\n defaultValue,\n min,\n max,\n }\n}\n\nexport interface UseArrayFieldRowProps {\n index: number\n}\n\nexport const useArrayFieldRow = ({ index }: UseArrayFieldRowProps) => {\n const { clearErrors } = useFormContext()\n const { name, remove, fields } = useArrayFieldContext()\n\n React.useEffect(() => {\n // reset errors, to make sure min/max errors reset correctly\n clearErrors(name)\n }, [])\n\n return {\n index,\n isFirst: index === 0,\n isLast: index === fields.length - 1,\n name: `${name}.${index}`,\n remove: React.useCallback(() => {\n clearErrors(name)\n remove(index)\n }, [index]),\n }\n}\n\nexport const useArrayFieldRemoveButton = () => {\n const { isFirst, remove } = useArrayFieldRowContext()\n const { min, fields } = useArrayFieldContext()\n\n const isDisabled = isFirst && !!(min && fields.length <= min)\n\n return {\n onClick: () => remove(),\n isDisabled,\n }\n}\n\nexport const useArrayFieldAddButton = () => {\n const { append, defaultValue, max, fields } = useArrayFieldContext()\n\n const isDisabled = !!(max && fields.length >= max)\n\n return {\n onClick: () =>\n append(defaultValue, {\n shouldFocus: false,\n }),\n isDisabled,\n }\n}\n","import * as React from 'react'\n\nimport { chakra, ResponsiveValue } from '@chakra-ui/system'\n\nimport { AddIcon, MinusIcon } from '@chakra-ui/icons'\nimport { IconButton, ButtonProps } from '@saas-ui/button'\n\nimport { FormLayout } from './layout'\nimport { BaseField, FieldProps } from './field'\n\nimport { mapNestedFields } from './utils'\n\nimport {\n useArrayField,\n useArrayFieldRow,\n useArrayFieldContext,\n ArrayFieldProvider,\n ArrayFieldOptions,\n ArrayFieldRowProvider,\n useArrayFieldRowContext,\n useArrayFieldRemoveButton,\n useArrayFieldAddButton,\n} from './use-array-field'\n\ninterface ArrayField {\n id: string\n [key: string]: unknown\n}\n\ninterface ArrayFieldRowProps {\n /**\n * Amount of field columns\n */\n columns?: ResponsiveValue<number>\n /**\n * Spacing between fields\n */\n spacing?: ResponsiveValue<string | number>\n /**\n * The array index\n */\n index: number\n}\n\nexport const ArrayFieldRow: React.FC<ArrayFieldRowProps> = ({\n children,\n columns,\n spacing,\n index,\n}) => {\n return (\n <ArrayFieldRowContainer index={index}>\n <ArrayFieldRowFields columns={columns} spacing={spacing}>\n {children}\n </ArrayFieldRowFields>\n <ArrayFieldRemoveButton />\n </ArrayFieldRowContainer>\n )\n}\n\nexport interface ArrayFieldRowFieldsProps {\n /**\n * Amount of field columns\n */\n columns?: ResponsiveValue<number>\n /**\n * Spacing between fields\n */\n spacing?: ResponsiveValue<string | number>\n}\n\nexport const ArrayFieldRowFields: React.FC<ArrayFieldRowFieldsProps> = ({\n children,\n columns,\n spacing,\n ...layoutProps\n}) => {\n const { name } = useArrayFieldRowContext()\n return (\n <FormLayout\n flex=\"1\"\n columns={columns}\n gridGap={spacing}\n mr=\"2\"\n {...layoutProps}\n >\n {mapNestedFields(name, children)}\n </FormLayout>\n )\n}\n\nexport const ArrayFieldRowContainer: React.FC<ArrayFieldRowProps> = ({\n children,\n index,\n}) => {\n const context = useArrayFieldRow({ index })\n\n const styles = {\n display: 'flex',\n flexDirection: 'row',\n alignItems: 'flex-end',\n width: '100%',\n mb: 4,\n }\n\n return (\n <ArrayFieldRowProvider value={context}>\n <chakra.div __css={styles}>{children}</chakra.div>\n </ArrayFieldRowProvider>\n )\n}\n\nexport const ArrayFieldRemoveButton: React.FC<ButtonProps> = (props) => {\n return (\n <IconButton\n icon={<MinusIcon />}\n aria-label=\"Remove row\"\n {...useArrayFieldRemoveButton()}\n {...props}\n />\n )\n}\n\nexport const ArrayFieldAddButton: React.FC<ButtonProps> = (props) => {\n return (\n <IconButton\n icon={<AddIcon />}\n aria-label=\"Add row\"\n float=\"right\"\n {...useArrayFieldAddButton()}\n {...props}\n />\n )\n}\n\nexport interface ArrayFieldProps\n extends ArrayFieldOptions,\n Omit<FieldProps, 'defaultValue'> {}\n\nexport const ArrayField: React.FC<ArrayFieldProps> = (props) => {\n const { children, ...containerProps } = props\n\n return (\n <ArrayFieldContainer {...containerProps}>\n <ArrayFieldRows>\n {(fields: ArrayField[]) => (\n <>\n {fields.map(({ id }, index: number) => (\n <ArrayFieldRow key={id} index={index}>\n {children}\n </ArrayFieldRow>\n ))}\n </>\n )}\n </ArrayFieldRows>\n <ArrayFieldAddButton />\n </ArrayFieldContainer>\n )\n}\n\nexport interface ArrayFieldRowsProps {\n children: (fields: ArrayField[]) => React.ReactElement | null\n}\n\nexport const ArrayFieldRows = ({\n children,\n}: ArrayFieldRowsProps): React.ReactElement | null => {\n const { fields } = useArrayFieldContext()\n return children(fields)\n}\n\nexport const ArrayFieldContainer: React.FC<ArrayFieldProps> = ({\n name,\n defaultValue,\n keyName,\n min,\n max,\n children,\n ...fieldProps\n}) => {\n const context = useArrayField({\n name,\n defaultValue,\n keyName,\n min,\n max,\n })\n\n return (\n <ArrayFieldProvider value={context}>\n <BaseField name={name} {...fieldProps}>\n {children}\n </BaseField>\n </ArrayFieldProvider>\n )\n}\n","import * as React from 'react'\nimport {\n FormControl,\n FormLabel,\n FormLabelProps,\n ResponsiveValue,\n useStyles,\n} from '@chakra-ui/react'\n\nimport { FormLayout } from './layout'\nimport { FieldProps } from './field'\n\nimport { mapNestedFields } from './utils'\n\nexport interface ObjectFieldProps extends FieldProps {\n name: string\n children: React.ReactNode\n columns?: ResponsiveValue<number>\n spacing?: ResponsiveValue<string | number>\n}\n\nexport const FormLegend = (props: FormLabelProps) => {\n const styles = useStyles()\n return <FormLabel as=\"legend\" sx={styles.legend} {...props} />\n}\n\nexport const ObjectField: React.FC<ObjectFieldProps> = (props) => {\n const { name, label, hideLabel, children, columns, spacing, ...fieldProps } =\n props\n\n return (\n <FormControl name={name} as=\"fieldset\" {...fieldProps}>\n <FormLegend display={hideLabel ? 'none' : 'block'}>{label}</FormLegend>\n <FormLayout columns={columns} gridGap={spacing}>\n {mapNestedFields(name, children)}\n </FormLayout>\n </FormControl>\n )\n}\n","import * as React from 'react'\nimport { getFieldsFromSchema, getNestedSchema } from './resolvers/yup'\n\nimport { FormLayout } from './layout'\nimport { Field, FieldProps } from './field'\n\nimport { ArrayField } from './array-field'\nimport { ObjectField } from './object-field'\n\nexport interface FieldsProps {\n schema: any\n}\n\nconst getNestedFields = (schema: any, name: string) => {\n return getFieldsFromSchema(getNestedSchema(schema, name)).map(\n ({ name, type, ...nestedFieldProps }: FieldProps): React.ReactNode => (\n <Field key={name} name={name} type={type} {...nestedFieldProps} />\n )\n )\n}\n\nexport const Fields: React.FC<FieldsProps> = ({ schema, ...props }) => {\n return (\n <FormLayout {...props}>\n {getFieldsFromSchema(schema).map(\n ({\n name,\n type,\n defaultValue,\n ...fieldProps\n }: FieldProps): React.ReactNode => {\n if (type === 'array') {\n return (\n <ArrayField name={name} {...fieldProps}>\n {getNestedFields(schema, name)}\n </ArrayField>\n )\n } else if (type === 'object') {\n return (\n <ObjectField name={name} {...fieldProps}>\n {getNestedFields(schema, name)}\n </ObjectField>\n )\n }\n\n return <Field key={name} name={name} type={type} {...fieldProps} />\n }\n )}\n </FormLayout>\n )\n}\n","import * as React from 'react'\n\nimport { chakra, HTMLChakraProps, forwardRef } from '@chakra-ui/react'\n\nimport {\n useForm,\n FormProvider,\n UseFormProps,\n UseFormReturn,\n FieldValues,\n SubmitHandler,\n SubmitErrorHandler,\n} from 'react-hook-form'\n\nimport { yupResolver } from './resolvers/yup'\n\nexport type { UseFormReturn }\n\ninterface FormOptions<TFieldValues extends FieldValues = FieldValues> {\n /**\n * The form schema, currently supports Yup schema only.\n */\n schema?: any\n /**\n * The submit handler.\n */\n onSubmit: SubmitHandler<TFieldValues>\n /**\n * Triggers when there are validation errors.\n */\n onError?: SubmitErrorHandler<TFieldValues>\n /**\n * Ref on the HTMLFormElement.\n */\n formRef?: React.MutableRefObject<HTMLFormElement>\n}\n\nexport interface FormProps<TFieldValues extends FieldValues = FieldValues>\n extends UseFormProps<TFieldValues>,\n Omit<HTMLChakraProps<'form'>, 'onSubmit' | 'onError'>,\n FormOptions<TFieldValues> {}\n\n/**\n * @todo Figure out how to pass down FieldValues to all Field components,\n * if at all possible.\n */\nexport const Form = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const {\n mode = 'all',\n resolver,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n schema,\n defaultValues,\n onSubmit,\n onError,\n formRef,\n children,\n ...rest\n } = props\n\n const form = {\n mode,\n resolver,\n defaultValues,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n }\n\n // @todo remove yup dependency and just use resolver prop?\n if (schema) {\n form.resolver = yupResolver(schema)\n }\n\n const methods = useForm<TFieldValues>(form)\n const { handleSubmit } = methods\n\n // This exposes the useForm api through the forwareded ref\n React.useImperativeHandle(ref, () => methods, [ref, methods])\n\n return (\n <FormProvider {...methods}>\n <chakra.form\n ref={formRef}\n onSubmit={handleSubmit(onSubmit, onError)}\n {...rest}\n >\n {children}\n </chakra.form>\n </FormProvider>\n )\n }\n) as <TFieldValues extends FieldValues>(\n props: FormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement\n","import * as React from 'react'\n\nimport { useFormContext } from 'react-hook-form'\n\nimport { Button, ButtonProps } from '@saas-ui/button'\n\nimport { forwardRef } from '@chakra-ui/system'\n\nexport interface SubmitButtonProps extends ButtonProps {\n /**\n * Disable the submit button if the form is untouched.\n *\n * Change the default behavior by updating\n * `SubmitButton.defaultProps.disableIfUntouched`\n */\n disableIfUntouched?: boolean\n /**\n * Disable the submit button if the form is invalid.\n *\n * Change the default behavior by updating\n * `SubmitButton.defaultProps.disableIfInvalid`\n */\n disableIfInvalid?: boolean\n}\n\nexport const SubmitButton = forwardRef<SubmitButtonProps, 'button'>(\n (props, ref) => {\n const { children, disableIfUntouched, disableIfInvalid, ...rest } = props\n const { formState } = useFormContext()\n\n const isDisabled =\n (disableIfUntouched && !formState.isDirty) ||\n (disableIfInvalid && !formState.isValid)\n\n return (\n <Button\n type=\"submit\"\n isLoading={formState.isSubmitting}\n isPrimary\n ref={ref}\n isDisabled={isDisabled}\n {...rest}\n >\n {children}\n </Button>\n )\n }\n)\n\nSubmitButton.defaultProps = {\n label: 'Submit',\n disableIfUntouched: false,\n disableIfInvalid: false,\n}\n","import * as React from 'react'\nimport { FieldValues, UseFormReturn } from 'react-hook-form'\nimport { forwardRef } from '@chakra-ui/react'\n\nimport { Form, FormProps } from './form'\n\nimport { FormLayout } from './layout'\nimport { Fields } from './fields'\nimport { SubmitButton } from './submit-button'\n\ninterface AutoFormOptions {\n schema: any\n submitLabel?: false | string\n}\n\nexport interface AutoFormProps<TFieldValues extends FieldValues>\n extends Omit<FormProps<TFieldValues>, 'schema'>,\n AutoFormOptions {}\n\nexport const AutoForm = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: AutoFormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const { schema, submitLabel = 'Submit', ...rest } = props\n return (\n <Form {...rest} schema={schema} ref={ref}>\n <FormLayout>\n {<Fields schema={schema} />}\n {submitLabel && <SubmitButton label={submitLabel} />}\n </FormLayout>\n </Form>\n )\n }\n) as <TFieldValues extends FieldValues>(\n props: AutoFormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement\n","import * as React from 'react'\nimport {\n useFormContext,\n useWatch,\n FieldValues,\n UseFormReturn,\n} from 'react-hook-form'\n\nexport interface DisplayIfProps<TFieldValues> {\n children: React.ReactElement\n name: string\n defaultValue?: unknown\n isDisabled?: boolean\n isExact?: boolean\n condition?: (value: unknown, context: UseFormReturn<TFieldValues>) => boolean\n}\n\nexport const DisplayIf = <TFieldValues extends FieldValues = FieldValues>({\n children,\n name,\n defaultValue,\n isDisabled,\n isExact,\n condition = (value) => !!value,\n}: DisplayIfProps<TFieldValues>) => {\n const value = useWatch({\n name,\n defaultValue,\n disabled: isDisabled,\n exact: isExact,\n })\n const context = useFormContext<TFieldValues>()\n return condition(value, context) ? children : null\n}\n"],"names":["DisplayField","_ref","name","label","props","getValues","useFormContext","React","FormControl","FormLabel","htmlFor","Text","fontSize","inputTypes","defaultInputType","BaseField","help","variant","hideLabel","children","controlProps","formState","error","get","errors","getError","isInvalid","Box","message","FormHelperText","FormErrorMessage","Field","forwardRef","ref","type","InputComponent","getInput","withControlledInput","rules","inputProps","control","Controller","render","_ref3","field","useMergeRefs","withUncontrolledInput","register","registerFieldType","component","options","isControlled","displayName","isDisabled","isReadOnly","isRequired","inputRules","required","createField","split","map","part","charAt","toUpperCase","slice","join","InputField","Input","NumberInputField","NumberInput","PasswordInputFIeld","PasswordInput","TextareaField","Textarea","SwitchField","Switch","SelectField","Select","CheckboxField","Checkbox","RadioField","RadioInput","PinField","PinInput","NativeSelectField","NativeSelect","getType","spec","meta","_field$spec$meta","getArrayOption","test","tests","OPTIONS","_test$OPTIONS","params","getFieldsFromSchema","schema","fields","schemaFields","innerType","min","max","push","FormLayoutItem","chakra","div","FormLayout","gridProps","useTheme","components","_theme$components","_theme$components$For2","defaultProps","spacing","SimpleGrid","Children","child","isValidElement","mapNestedFields","cloneElement","ArrayFieldProvider","useArrayFieldContext","createContext","ArrayFieldRowProvider","useArrayFieldRowContext","useArrayField","defaultValue","keyName","useFieldArray","useArrayFieldRow","index","clearErrors","remove","useEffect","isFirst","isLast","length","useCallback","useArrayFieldRemoveButton","onClick","useArrayFieldAddButton","append","shouldFocus","ArrayFieldRow","columns","ArrayFieldRowContainer","ArrayFieldRowFields","ArrayFieldRemoveButton","layoutProps","flex","gridGap","mr","context","value","__css","display","flexDirection","alignItems","width","mb","IconButton","icon","MinusIcon","ArrayFieldAddButton","AddIcon","float","ArrayField","containerProps","ArrayFieldContainer","ArrayFieldRows","id","key","_ref2","fieldProps","FormLegend","styles","useStyles","as","sx","legend","ObjectField","getNestedFields","path","reach","getNestedSchema","nestedFieldProps","Fields","Form","mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","defaultValues","onSubmit","onError","formRef","rest","form","yupResolver","methods","useForm","handleSubmit","useImperativeHandle","FormProvider","SubmitButton","disableIfUntouched","disableIfInvalid","Button","isLoading","isSubmitting","isPrimary","isDirty","isValid","AutoForm","submitLabel","DisplayIf","isExact","condition","useWatch","disabled","exact"],"mappings":"u4CAgBaA,EAA4CC,QAACC,KACxDA,EADwDC,MAExDA,KAEGC,SAEH,MAAMC,UAAEA,GAAcC,iBAEtB,OACEC,gBAACC,EAAgBJ,EACdD,eAAQI,gBAACE,GAAUC,QAASR,GAAOC,GAAqB,kBACzDI,gBAACI,GAAKC,SAAS,MAAMP,EAAUH,kPCoF/BW,EAAsC,GAEtCC,EAAmB,OAiBZC,EAAmCX,IAC9C,MAAMF,KAAEA,EAAFC,MAAQA,EAARa,KAAeA,EAAfC,QAAqBA,EAArBC,UAA8BA,EAA9BC,SAAyCA,GAC7Cf,EAD0DgB,IAC1DhB,MAEIiB,UAAEA,GAAcf,IAEhBgB,EAjBS,EAACpB,EAAcmB,IACvBE,EAAIF,EAAUG,OAAQtB,GAgBfuB,CAASvB,EAAMmB,gBAE7B,OACEd,gBAACC,KAAYS,QAASA,GAAaG,GAAcM,YAAaJ,IAC3DnB,IAAUe,eACTX,gBAACE,GAAUQ,QAASA,GAAUd,GAC5B,kBACJI,gBAACoB,OACER,GACAH,SAASM,GAAAA,EAAOM,QAEb,kBADFrB,gBAACsB,OAAgBb,UAElBM,SAAAA,EAAOM,uBACNrB,gBAACuB,aAAkBR,SAAAA,EAAOM,YAMvBG,GAAQC,EACnB,CACE5B,EAGA6B,KAEA,MAAMC,KAAEA,EAAOpB,GAAqBV,EAC9B+B,EAhDQD,CAAAA,GACTrB,EAAWqB,I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K,EACV4K,MAAOJ,IAEOvN,KACmBa,EAAW"}
1
+ {"version":3,"file":"index.modern.js","sources":["../src/display-field.tsx","../src/field.tsx","../src/resolvers/yup.ts","../src/layout.tsx","../src/utils.ts","../src/use-array-field.tsx","../src/array-field.tsx","../src/object-field.tsx","../src/fields.tsx","../src/form.tsx","../src/submit-button.tsx","../src/auto-form.tsx","../src/display-if.tsx","../../saas-ui-stepper/dist/index.modern.js","../src/use-step-form.tsx","../src/step-form.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useFormContext } from 'react-hook-form'\n\nimport {\n Text,\n FormControl,\n FormControlProps,\n FormLabel,\n} from '@chakra-ui/react'\n\nimport { FieldProps } from './field'\n\nexport interface DisplayFieldProps\n extends FormControlProps,\n Omit<FieldProps, 'type' | 'label'> {}\n\nexport const DisplayField: React.FC<DisplayFieldProps> = ({\n name,\n label,\n placeholder,\n ...props\n}) => {\n return (\n <FormControl {...props}>\n {label ? <FormLabel htmlFor={name}>{label}</FormLabel> : null}\n <Text fontSize=\"md\">\n <FormValue name={name} />\n </Text>\n </FormControl>\n )\n}\n\nexport const FormValue: React.FC<{ name: string }> = ({ name }) => {\n const { getValues } = useFormContext()\n return getValues(name) || null\n}\n","import * as React from 'react'\nimport {\n useFormContext,\n FormState,\n Controller,\n get,\n RegisterOptions,\n FieldValues,\n FieldPath,\n} from 'react-hook-form'\n\nimport {\n forwardRef,\n Box,\n FormControl,\n FormControlProps,\n FormLabel,\n FormHelperText,\n FormErrorMessage,\n Input,\n Textarea,\n Checkbox,\n Switch,\n useMergeRefs,\n} from '@chakra-ui/react'\n\nimport { NumberInput } from '@saas-ui/number-input'\nimport { PasswordInput } from '@saas-ui/password-input'\nimport { RadioInput } from '@saas-ui/radio'\nimport { PinInput } from '@saas-ui/pin-input'\nimport { Select, NativeSelect } from '@saas-ui/select'\n\nexport interface Option {\n value: string\n label?: string\n [key: string]: unknown\n}\n\nexport type FieldRules = Pick<\n RegisterOptions,\n 'required' | 'min' | 'max' | 'maxLength' | 'minLength' | 'pattern'\n>\n\nexport type FieldTypes =\n | 'text'\n | 'number'\n | 'password'\n | 'textarea'\n | 'select'\n | 'native-select'\n | 'checkbox'\n | 'radio'\n | 'switch'\n | 'pin'\n | string\n\nexport interface FieldProps<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\n> extends Omit<FormControlProps, 'label' | 'type'> {\n /**\n * The field name\n */\n name: TName\n /**\n * The field label\n */\n label?: string\n /**\n * Hide the field label\n */\n hideLabel?: boolean\n /**\n * Field help text\n */\n help?: string\n /**\n * React hook form rules\n */\n rules?: Omit<\n RegisterOptions<TFieldValues, TName>,\n 'valueAsNumber' | 'valueAsDate' | 'setValueAs' | 'disabled'\n >\n /**\n * Options used for selects and radio fields\n */\n options?: Option[]\n /**\n * The field type\n * Build-in types:\n * - text\n * - number\n * - password\n * - textarea\n * - select\n * - native-select\n * - checkbox\n * - radio\n * - switch\n * - pin\n *\n * Will default to a text field if there is no matching type.\n * @default 'text'\n */\n type?: FieldTypes\n /**\n * The input placeholder\n */\n placeholder?: string\n}\n\nconst inputTypes: Record<FieldTypes, any> = {}\n\nconst defaultInputType = 'text'\n\nconst getInput = (type: string) => {\n return inputTypes[type] || inputTypes[defaultInputType]\n}\n\nconst getError = (name: string, formState: FormState<{ [x: string]: any }>) => {\n return get(formState.errors, name)\n}\n\nconst isTouched = (\n name: string,\n formState: FormState<{ [x: string]: any }>\n) => {\n return get(formState.touchedFields, name)\n}\n\nexport const BaseField: React.FC<FieldProps> = (props) => {\n const { name, label, help, variant, hideLabel, children, ...controlProps } =\n props\n\n const { formState } = useFormContext()\n\n const error = getError(name, formState)\n\n return (\n <FormControl variant={variant} {...controlProps} isInvalid={!!error}>\n {label && !hideLabel ? (\n <FormLabel variant={variant}>{label}</FormLabel>\n ) : null}\n <Box>\n {children}\n {help && !error?.message ? (\n <FormHelperText>{help}</FormHelperText>\n ) : null}\n {error?.message && (\n <FormErrorMessage>{error?.message}</FormErrorMessage>\n )}\n </Box>\n </FormControl>\n )\n}\nexport const Field = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FieldProps<TFieldValues> & {\n [key: string]: unknown // Make sure attributes of custom components work. Need to change this to a global typedef at some point.\n },\n ref: React.ForwardedRef<typeof FormControl>\n ) => {\n const { type = defaultInputType } = props\n const InputComponent = getInput(type)\n\n return <InputComponent ref={ref} {...props} />\n }\n) as <TFieldValues extends FieldValues>(\n props: FieldProps<TFieldValues> & {\n [key: string]: unknown\n } & {\n ref?: React.ForwardedRef<typeof FormControl>\n }\n) => React.ReactElement\n\ninterface CreateFieldProps {\n displayName: string\n hideLabel?: boolean\n BaseField: React.FC<any>\n}\n\nconst createField = (\n InputComponent: React.FC<any>,\n { displayName, hideLabel, BaseField }: CreateFieldProps\n) => {\n const Field = forwardRef<FieldProps, typeof FormControl>((props, ref) => {\n const {\n name,\n label,\n help,\n isDisabled,\n isInvalid,\n isReadOnly,\n isRequired,\n rules,\n variant,\n ...inputProps\n } = props\n\n const inputRules = {\n required: isRequired,\n ...rules,\n }\n\n return (\n <BaseField\n name={name}\n label={label}\n help={help}\n hideLabel={hideLabel}\n isDisabled={isDisabled}\n isInvalid={isInvalid}\n isReadOnly={isReadOnly}\n isRequired={isRequired}\n variant={variant}\n >\n <InputComponent\n ref={ref}\n name={name}\n label={label}\n rules={inputRules}\n {...inputProps}\n />\n </BaseField>\n )\n })\n Field.displayName = displayName\n\n return Field\n}\n\nexport const withControlledInput = (InputComponent: any) => {\n return forwardRef<FieldProps, typeof InputComponent>(\n ({ name, rules, ...inputProps }, ref) => {\n const { control } = useFormContext()\n\n return (\n <Controller\n name={name}\n control={control}\n rules={rules}\n render={({ field: { ref: _ref, ...field } }) => (\n <InputComponent\n {...field}\n {...inputProps}\n ref={useMergeRefs(ref, _ref)}\n />\n )}\n />\n )\n }\n )\n}\n\nexport const withUncontrolledInput = (InputComponent: any) => {\n return forwardRef<FieldProps, typeof InputComponent>(\n ({ name, rules, ...inputProps }, ref) => {\n const { register } = useFormContext()\n\n const { ref: _ref, ...field } = register(name, rules)\n\n return (\n <InputComponent\n {...field}\n {...inputProps}\n ref={useMergeRefs(ref, _ref)}\n />\n )\n }\n )\n}\n\nexport interface RegisterFieldTypeOptions {\n isControlled?: boolean\n hideLabel?: boolean\n BaseField?: React.FC<any>\n}\n\n/**\n * Register a new field type\n * @param type The name for this field in kebab-case, eg `email` or `array-field`\n * @param component The React component\n * @param options\n * @param options.isControlled Set this to true if this is a controlled field.\n * @param options.hideLabel Hide the field label, for example for checkbox or switch field.\n */\nexport const registerFieldType = (\n type: string,\n component: React.FC<any>,\n options?: RegisterFieldTypeOptions\n) => {\n let InputComponent\n if (options?.isControlled) {\n InputComponent = withControlledInput(component)\n } else {\n InputComponent = withUncontrolledInput(component)\n }\n\n const Field = createField(InputComponent, {\n displayName: `${type\n .split('-')\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join('')}Field`,\n hideLabel: options?.hideLabel,\n BaseField: options?.BaseField || BaseField,\n })\n\n inputTypes[type] = Field\n\n return Field\n}\n\n// @todo Consider not registering all fields by default to lower the package size and computations.\n// Not all types may be required in a project.\nexport const InputField = registerFieldType('text', Input)\nexport const NumberInputField = registerFieldType('number', NumberInput, {\n isControlled: true,\n})\nexport const PasswordInputFIeld = registerFieldType('password', PasswordInput)\nexport const TextareaField = registerFieldType('textarea', Textarea)\nexport const SwitchField = registerFieldType(\n 'switch',\n forwardRef(({ label, ...props }: { label?: string }, ref) => {\n return (\n <Switch ref={ref} {...props}>\n {label}\n </Switch>\n )\n }),\n {\n isControlled: true,\n hideLabel: true,\n }\n)\nexport const SelectField = registerFieldType('select', Select, {\n isControlled: true,\n})\nexport const CheckboxField = registerFieldType(\n 'checkbox',\n forwardRef(({ label, ...props }: { label?: string }, ref) => {\n return (\n <Checkbox ref={ref} {...props}>\n {label}\n </Checkbox>\n )\n }),\n {\n hideLabel: true,\n }\n)\nexport const RadioField = registerFieldType('radio', RadioInput, {\n isControlled: true,\n})\nexport const PinField = registerFieldType('pin', PinInput, {\n isControlled: true,\n})\nexport const NativeSelectField = registerFieldType(\n 'native-select',\n NativeSelect,\n { isControlled: true }\n)\n","import { SchemaOf, AnySchema, reach } from 'yup'\nexport { yupResolver } from '@hookform/resolvers/yup'\n\nimport { FieldProps } from '../field'\n\n// @TODO get proper typings for the schema fields\n\nconst getType = (field: any) => {\n if (field.spec.meta?.type) {\n return field.spec.meta.type\n }\n\n switch (field.type) {\n case 'array':\n return 'array'\n case 'object':\n return 'object'\n case 'number':\n return 'number'\n case 'date':\n return 'date'\n case 'string':\n default:\n return 'text'\n }\n}\n\ntype Options = {\n min?: number\n max?: number\n}\n\nconst getArrayOption = (field: any, name: string) => {\n for (const test of field.tests) {\n if (test.OPTIONS?.params[name]) return test.OPTIONS.params[name]\n }\n}\n\n/**\n * A helper function to render forms automatically based on a Yup schema\n *\n * @param schema The Yup schema\n * @returns {FieldProps[]}\n */\nexport const getFieldsFromSchema = (\n schema: SchemaOf<AnySchema>\n): FieldProps[] => {\n const fields = []\n\n let schemaFields: Record<string, any> = {}\n if (schema.type === 'array') {\n /* @ts-ignore this is actually valid */\n schemaFields = schema.innerType.fields\n } else {\n schemaFields = schema.fields\n }\n\n for (const name in schemaFields) {\n const field = schemaFields[name]\n\n const options: Options = {}\n if (field.type === 'array') {\n options.min = getArrayOption(field, 'min')\n options.max = getArrayOption(field, 'max')\n }\n\n fields.push({\n name,\n label: field.spec.label || name,\n type: getType(field),\n ...options,\n })\n }\n return fields\n}\n\nexport const getNestedSchema = (schema: SchemaOf<AnySchema>, path: string) => {\n return reach(schema, path)\n}\n","import * as React from 'react'\n\nimport { chakra, SimpleGrid, SimpleGridProps, useTheme } from '@chakra-ui/react'\n\nexport type FormLayoutProps = SimpleGridProps\n\ninterface FormLayoutItemProps {\n children: React.ReactNode\n}\n\nconst FormLayoutItem: React.FC<FormLayoutItemProps> = ({ children }) => {\n return <chakra.div>{children}</chakra.div>\n}\n\n/**\n * FormLayout\n *\n * Renders form items in a `SimpleGrid`\n * @see https://chakra-ui.com/docs/layout/simple-grid\n */\nexport const FormLayout = ({ children, ...props }: FormLayoutProps) => {\n const theme = useTheme()\n\n const defaultProps = theme.components?.FormLayout?.defaultProps ?? {\n spacing: 4,\n }\n\n const gridProps = {\n ...defaultProps,\n ...props,\n }\n\n return (\n <SimpleGrid {...gridProps}>\n {React.Children.map(children, (child) => {\n if (React.isValidElement(child)) {\n return <FormLayoutItem>{child}</FormLayoutItem>\n }\n return child\n })}\n </SimpleGrid>\n )\n}\n","import * as React from 'react'\n\nexport const mapNestedFields = (name: string, children: React.ReactNode) => {\n return React.Children.map(children, (child) => {\n if (React.isValidElement(child) && child.props.name) {\n return React.cloneElement(child, {\n ...child.props,\n name: `${name}.${child.props.name}`,\n })\n }\n return child\n })\n}\n","import * as React from 'react'\nimport {\n useFieldArray,\n useFormContext,\n UseFieldArrayReturn,\n} from 'react-hook-form'\n\nimport { createContext } from '@chakra-ui/react-utils'\n\nexport interface UseArrayFieldReturn extends UseFieldArrayReturn {\n /**\n * The array field name\n */\n name: string\n /**\n * The default value for new items\n */\n defaultValue: Record<string, any>\n /**\n * Min amount of items\n */\n min?: number\n /**\n * Max amount of items\n */\n max?: number\n}\n\nexport const [ArrayFieldProvider, useArrayFieldContext] =\n createContext<UseArrayFieldReturn>({\n name: 'ArrayFieldContext',\n })\n\nexport interface UseArrayFieldRowReturn {\n /**\n * Name of the array field including the index, eg 'field.0'\n */\n name: string\n /**\n * The field index\n */\n index: number\n /**\n * Remove this array item\n */\n remove: () => void\n /**\n * True if this is the first item\n */\n isFirst: boolean\n /**\n * True if this is the last item\n */\n isLast: boolean\n}\n\nexport const [ArrayFieldRowProvider, useArrayFieldRowContext] =\n createContext<UseArrayFieldRowReturn>({\n name: 'ArrayFieldRowContext',\n })\n\nexport interface ArrayFieldOptions {\n /**\n * The field name\n */\n name: string\n /**\n * Default value for new values in the array\n */\n defaultValue?: Record<string, any>\n /**\n * Default key name for rows, change this if your data uses a different 'id' field\n * @default \"id\"\n */\n keyName?: string\n min?: number\n max?: number\n}\n\nexport const useArrayField = ({\n name,\n defaultValue = {},\n keyName,\n min,\n max,\n}: ArrayFieldOptions) => {\n const { control } = useFormContext()\n const context = useFieldArray({\n control,\n name,\n keyName,\n })\n\n return {\n ...context,\n name,\n defaultValue,\n min,\n max,\n }\n}\n\nexport interface UseArrayFieldRowProps {\n index: number\n}\n\nexport const useArrayFieldRow = ({ index }: UseArrayFieldRowProps) => {\n const { clearErrors } = useFormContext()\n const { name, remove, fields } = useArrayFieldContext()\n\n React.useEffect(() => {\n // reset errors, to make sure min/max errors reset correctly\n clearErrors(name)\n }, [])\n\n return {\n index,\n isFirst: index === 0,\n isLast: index === fields.length - 1,\n name: `${name}.${index}`,\n remove: React.useCallback(() => {\n clearErrors(name)\n remove(index)\n }, [index]),\n }\n}\n\nexport const useArrayFieldRemoveButton = () => {\n const { isFirst, remove } = useArrayFieldRowContext()\n const { min, fields } = useArrayFieldContext()\n\n const isDisabled = isFirst && !!(min && fields.length <= min)\n\n return {\n onClick: () => remove(),\n isDisabled,\n }\n}\n\nexport const useArrayFieldAddButton = () => {\n const { append, defaultValue, max, fields } = useArrayFieldContext()\n\n const isDisabled = !!(max && fields.length >= max)\n\n return {\n onClick: () =>\n append(defaultValue, {\n shouldFocus: false,\n }),\n isDisabled,\n }\n}\n","import * as React from 'react'\n\nimport { chakra, ResponsiveValue } from '@chakra-ui/system'\n\nimport { AddIcon, MinusIcon } from '@chakra-ui/icons'\nimport { IconButton, ButtonProps } from '@saas-ui/button'\n\nimport { FormLayout } from './layout'\nimport { BaseField, FieldProps } from './field'\n\nimport { mapNestedFields } from './utils'\n\nimport {\n useArrayField,\n useArrayFieldRow,\n useArrayFieldContext,\n ArrayFieldProvider,\n ArrayFieldOptions,\n ArrayFieldRowProvider,\n useArrayFieldRowContext,\n useArrayFieldRemoveButton,\n useArrayFieldAddButton,\n UseArrayFieldReturn,\n} from './use-array-field'\n\ninterface ArrayField {\n id: string\n [key: string]: unknown\n}\n\ninterface ArrayFieldRowProps {\n /**\n * Amount of field columns\n */\n columns?: ResponsiveValue<number>\n /**\n * Spacing between fields\n */\n spacing?: ResponsiveValue<string | number>\n /**\n * The array index\n */\n index: number\n}\n\nexport const ArrayFieldRow: React.FC<ArrayFieldRowProps> = ({\n children,\n columns,\n spacing,\n index,\n}) => {\n return (\n <ArrayFieldRowContainer index={index}>\n <ArrayFieldRowFields columns={columns} spacing={spacing}>\n {children}\n </ArrayFieldRowFields>\n <ArrayFieldRemoveButton />\n </ArrayFieldRowContainer>\n )\n}\n\nexport interface ArrayFieldRowFieldsProps {\n /**\n * Amount of field columns\n */\n columns?: ResponsiveValue<number>\n /**\n * Spacing between fields\n */\n spacing?: ResponsiveValue<string | number>\n}\n\nexport const ArrayFieldRowFields: React.FC<ArrayFieldRowFieldsProps> = ({\n children,\n columns,\n spacing,\n ...layoutProps\n}) => {\n const { name } = useArrayFieldRowContext()\n return (\n <FormLayout\n flex=\"1\"\n columns={columns}\n gridGap={spacing}\n mr=\"2\"\n {...layoutProps}\n >\n {mapNestedFields(name, children)}\n </FormLayout>\n )\n}\n\nexport const ArrayFieldRowContainer: React.FC<ArrayFieldRowProps> = ({\n children,\n index,\n}) => {\n const context = useArrayFieldRow({ index })\n\n const styles = {\n display: 'flex',\n flexDirection: 'row',\n alignItems: 'flex-end',\n width: '100%',\n mb: 4,\n }\n\n return (\n <ArrayFieldRowProvider value={context}>\n <chakra.div __css={styles}>{children}</chakra.div>\n </ArrayFieldRowProvider>\n )\n}\n\nexport const ArrayFieldRemoveButton: React.FC<ButtonProps> = (props) => {\n return (\n <IconButton\n icon={<MinusIcon />}\n aria-label=\"Remove row\"\n {...useArrayFieldRemoveButton()}\n {...props}\n />\n )\n}\n\nexport const ArrayFieldAddButton: React.FC<ButtonProps> = (props) => {\n return (\n <IconButton\n icon={<AddIcon />}\n aria-label=\"Add row\"\n float=\"right\"\n {...useArrayFieldAddButton()}\n {...props}\n />\n )\n}\n\nexport interface ArrayFieldProps\n extends ArrayFieldOptions,\n Omit<FieldProps, 'defaultValue'> {}\n\nexport const ArrayField = React.forwardRef(\n (props: ArrayFieldProps, ref: React.ForwardedRef<UseArrayFieldReturn>) => {\n const { children, ...containerProps } = props\n\n return (\n <ArrayFieldContainer ref={ref} {...containerProps}>\n <ArrayFieldRows>\n {(fields: ArrayField[]) => (\n <>\n {fields.map(({ id }, index: number) => (\n <ArrayFieldRow key={id} index={index}>\n {children}\n </ArrayFieldRow>\n ))}\n </>\n )}\n </ArrayFieldRows>\n <ArrayFieldAddButton />\n </ArrayFieldContainer>\n )\n }\n)\n\nexport interface ArrayFieldRowsProps {\n children: (fields: ArrayField[]) => React.ReactElement | null\n}\n\nexport const ArrayFieldRows = ({\n children,\n}: ArrayFieldRowsProps): React.ReactElement | null => {\n const { fields } = useArrayFieldContext()\n return children(fields)\n}\n\nexport const ArrayFieldContainer = React.forwardRef(\n (\n {\n name,\n defaultValue,\n keyName,\n min,\n max,\n children,\n ...fieldProps\n }: ArrayFieldProps,\n ref: React.ForwardedRef<UseArrayFieldReturn>\n ) => {\n const context = useArrayField({\n name,\n defaultValue,\n keyName,\n min,\n max,\n })\n\n // This exposes the useArrayField api through the forwarded ref\n React.useImperativeHandle(ref, () => context, [ref, context])\n\n return (\n <ArrayFieldProvider value={context}>\n <BaseField name={name} {...fieldProps}>\n {children}\n </BaseField>\n </ArrayFieldProvider>\n )\n }\n)\n","import * as React from 'react'\nimport {\n FormControl,\n FormLabel,\n FormLabelProps,\n ResponsiveValue,\n useStyles,\n} from '@chakra-ui/react'\n\nimport { FormLayout } from './layout'\nimport { FieldProps } from './field'\n\nimport { mapNestedFields } from './utils'\n\nexport interface ObjectFieldProps extends FieldProps {\n name: string\n children: React.ReactNode\n columns?: ResponsiveValue<number>\n spacing?: ResponsiveValue<string | number>\n}\n\nexport const FormLegend = (props: FormLabelProps) => {\n const styles = useStyles()\n return <FormLabel as=\"legend\" sx={styles.legend} {...props} />\n}\n\nexport const ObjectField: React.FC<ObjectFieldProps> = (props) => {\n const { name, label, hideLabel, children, columns, spacing, ...fieldProps } =\n props\n\n return (\n <FormControl name={name} as=\"fieldset\" {...fieldProps}>\n <FormLegend display={hideLabel ? 'none' : 'block'}>{label}</FormLegend>\n <FormLayout columns={columns} gridGap={spacing}>\n {mapNestedFields(name, children)}\n </FormLayout>\n </FormControl>\n )\n}\n","import * as React from 'react'\nimport { getFieldsFromSchema, getNestedSchema } from './resolvers/yup'\n\nimport { FormLayout } from './layout'\nimport { Field, FieldProps } from './field'\n\nimport { ArrayField } from './array-field'\nimport { ObjectField } from './object-field'\n\nexport interface FieldsProps {\n schema: any\n}\n\nconst getNestedFields = (schema: any, name: string) => {\n return getFieldsFromSchema(getNestedSchema(schema, name)).map(\n ({ name, type, ...nestedFieldProps }: FieldProps): React.ReactNode => (\n <Field key={name} name={name} type={type} {...nestedFieldProps} />\n )\n )\n}\n\nexport const Fields: React.FC<FieldsProps> = ({ schema, ...props }) => {\n return (\n <FormLayout {...props}>\n {getFieldsFromSchema(schema).map(\n ({\n name,\n type,\n defaultValue,\n ...fieldProps\n }: FieldProps): React.ReactNode => {\n if (type === 'array') {\n return (\n <ArrayField name={name} {...fieldProps}>\n {getNestedFields(schema, name)}\n </ArrayField>\n )\n } else if (type === 'object') {\n return (\n <ObjectField name={name} {...fieldProps}>\n {getNestedFields(schema, name)}\n </ObjectField>\n )\n }\n\n return <Field key={name} name={name} type={type} {...fieldProps} />\n }\n )}\n </FormLayout>\n )\n}\n","import * as React from 'react'\n\nimport { chakra, HTMLChakraProps, forwardRef } from '@chakra-ui/react'\n\nimport {\n useForm,\n FormProvider,\n UseFormProps,\n UseFormReturn,\n FieldValues,\n SubmitHandler,\n SubmitErrorHandler,\n} from 'react-hook-form'\n\nimport { yupResolver } from './resolvers/yup'\n\nexport type { UseFormReturn }\n\ninterface FormOptions<TFieldValues extends FieldValues = FieldValues> {\n /**\n * The form schema, currently supports Yup schema only.\n */\n schema?: any\n /**\n * The submit handler.\n */\n onSubmit: SubmitHandler<TFieldValues>\n /**\n * Triggers when there are validation errors.\n */\n onError?: SubmitErrorHandler<TFieldValues>\n /**\n * Ref on the HTMLFormElement.\n */\n formRef?: React.MutableRefObject<HTMLFormElement>\n}\n\nexport interface FormProps<TFieldValues extends FieldValues = FieldValues>\n extends UseFormProps<TFieldValues>,\n Omit<HTMLChakraProps<'form'>, 'onSubmit' | 'onError'>,\n FormOptions<TFieldValues> {}\n\n/**\n * @todo Figure out how to pass down FieldValues to all Field components,\n * if at all possible.\n */\nexport const Form = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const {\n mode = 'all',\n resolver,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n schema,\n defaultValues,\n onSubmit,\n onError,\n formRef,\n children,\n ...rest\n } = props\n\n const form = {\n mode,\n resolver,\n defaultValues,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n }\n\n // @todo remove yup dependency and just use resolver prop?\n if (schema) {\n form.resolver = yupResolver(schema)\n }\n\n const methods = useForm<TFieldValues>(form)\n const { handleSubmit } = methods\n\n // This exposes the useForm api through the forwarded ref\n React.useImperativeHandle(ref, () => methods, [ref, methods])\n\n return (\n <FormProvider {...methods}>\n <chakra.form\n ref={formRef}\n onSubmit={handleSubmit(onSubmit, onError)}\n {...rest}\n >\n {children}\n </chakra.form>\n </FormProvider>\n )\n }\n) as <TFieldValues extends FieldValues>(\n props: FormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement\n","import * as React from 'react'\n\nimport { useFormContext } from 'react-hook-form'\n\nimport { Button, ButtonProps } from '@saas-ui/button'\n\nimport { forwardRef } from '@chakra-ui/system'\n\nexport interface SubmitButtonProps extends ButtonProps {\n /**\n * Disable the submit button if the form is untouched.\n *\n * Change the default behavior by updating\n * `SubmitButton.defaultProps.disableIfUntouched`\n */\n disableIfUntouched?: boolean\n /**\n * Disable the submit button if the form is invalid.\n *\n * Change the default behavior by updating\n * `SubmitButton.defaultProps.disableIfInvalid`\n */\n disableIfInvalid?: boolean\n}\n\nexport const SubmitButton = forwardRef<SubmitButtonProps, 'button'>(\n (props, ref) => {\n const { children, disableIfUntouched, disableIfInvalid, ...rest } = props\n const { formState } = useFormContext()\n\n const isDisabled =\n (disableIfUntouched && !formState.isDirty) ||\n (disableIfInvalid && !formState.isValid)\n\n return (\n <Button\n type=\"submit\"\n isLoading={formState.isSubmitting}\n isPrimary\n ref={ref}\n isDisabled={isDisabled}\n {...rest}\n >\n {children}\n </Button>\n )\n }\n)\n\nSubmitButton.defaultProps = {\n label: 'Submit',\n disableIfUntouched: false,\n disableIfInvalid: false,\n}\n","import * as React from 'react'\nimport { FieldValues, UseFormReturn } from 'react-hook-form'\nimport { forwardRef } from '@chakra-ui/react'\n\nimport { Form, FormProps } from './form'\n\nimport { FormLayout } from './layout'\nimport { Fields } from './fields'\nimport { SubmitButton } from './submit-button'\n\ninterface AutoFormOptions {\n schema: any\n submitLabel?: false | string\n}\n\nexport interface AutoFormProps<TFieldValues extends FieldValues>\n extends Omit<FormProps<TFieldValues>, 'schema'>,\n AutoFormOptions {}\n\nexport const AutoForm = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: AutoFormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const { schema, submitLabel = 'Submit', ...rest } = props\n return (\n <Form {...rest} schema={schema} ref={ref}>\n <FormLayout>\n {<Fields schema={schema} />}\n {submitLabel && <SubmitButton label={submitLabel} />}\n </FormLayout>\n </Form>\n )\n }\n) as <TFieldValues extends FieldValues>(\n props: AutoFormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement\n","import * as React from 'react'\nimport {\n useFormContext,\n useWatch,\n FieldValues,\n UseFormReturn,\n} from 'react-hook-form'\n\nexport interface DisplayIfProps<TFieldValues> {\n children: React.ReactElement\n name: string\n defaultValue?: unknown\n isDisabled?: boolean\n isExact?: boolean\n condition?: (value: unknown, context: UseFormReturn<TFieldValues>) => boolean\n}\n\nexport const DisplayIf = <TFieldValues extends FieldValues = FieldValues>({\n children,\n name,\n defaultValue,\n isDisabled,\n isExact,\n condition = (value) => !!value,\n}: DisplayIfProps<TFieldValues>) => {\n const value = useWatch({\n name,\n defaultValue,\n disabled: isDisabled,\n exact: isExact,\n })\n const context = useFormContext<TFieldValues>()\n return condition(value, context) ? children : null\n}\n","import*as e from\"react\";import{forwardRef as t,useMultiStyleConfig as s,omitThemingProps as r,StylesProvider as n,chakra as a,useStyles as i}from\"@chakra-ui/system\";import{Icon as c,CheckIcon as p}from\"@chakra-ui/icons\";import{Collapse as l}from\"@saas-ui/collapse\";import{getChildrenOfType as o,getChildOfType as m}from\"@saas-ui/react-utils\";import{cx as u,__DEV__ as d}from\"@chakra-ui/utils\";import{createContext as f}from\"@chakra-ui/react-utils\";function v(){return v=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var s=arguments[t];for(var r in s)Object.prototype.hasOwnProperty.call(s,r)&&(e[r]=s[r])}return e},v.apply(this,arguments)}function S(e,t){if(null==e)return{};var s,r,n={},a=Object.keys(e);for(r=0;r<a.length;r++)t.indexOf(s=a[r])>=0||(n[s]=e[s]);return n}const[_,N]=f({name:\"StepperContext\",errorMessage:\"useStepperContext: `context` is undefined. Seems you forgot to wrap stepper components in `<Stepper />`\"});function h(t){const{step:s}=t,[r,n]=e.useState(-1),a=e.useRef([]),[,i]=e.useState(Date.now()),c=e.useCallback(e=>{const t=[...a.current];-1===t.indexOf(e)&&t.push(e),a.current=t,i(Date.now())},[a,i]),p=e=>{const t=a.current.indexOf(e);-1!==t&&n(t)};return e.useLayoutEffect(()=>{\"string\"==typeof s?p(s):\"number\"==typeof s?n(s):-1===r&&n(0)},[s]),{stepsRef:a,activeStep:a.current[r],activeIndex:r,isFirstStep:0===r,isLastStep:r===a.current.length-1,isCompleted:r>=a.current.length,setIndex:n,setStep:p,nextStep:()=>{n(r+1)},prevStep:()=>{n(r-1)},registerStep:c,unregisterStep:e=>{a.current=a.current.slice(a.current.indexOf(e),1)}}}function x(t){const{name:s,isActive:r,isCompleted:n}=t,{registerStep:a,unregisterStep:i,activeStep:c}=N();return e.useEffect(()=>{if(s)return a(s),()=>{i(s)}},[]),{isActive:s?c===s:r,isCompleted:n}}function y({label:e=\"Back\"}={}){const{isFirstStep:t,prevStep:s}=N();return{isDisabled:t,onClick:s,label:e}}function C({label:e=\"Next\",submitLabel:t=\"Submit\"}={}){const{isLastStep:s,isCompleted:r,nextStep:n}=N();return{isDisabled:r,onClick:n,label:s?t:e}}const E=[\"children\",\"orientation\"],g=[\"children\",\"orientation\",\"stepComponent\"],b=[\"children\",\"isOpen\"],k=[\"icon\",\"isActive\",\"isCompleted\",\"className\"],A=[\"title\",\"icon\",\"isActive\",\"isCompleted\"],O=[\"isActive\"],D=t((t,i)=>{const c=s(\"Stepper\",t),p=r(t),{children:l,orientation:o}=p,m=S(p,E),d=h(t),f=v({display:\"flex\",flexDirection:\"column\"},c.container);/*#__PURE__*/return e.createElement(n,{value:c},/*#__PURE__*/e.createElement(_,{value:d},/*#__PURE__*/e.createElement(a.div,v({ref:i,__css:f},m,{className:u(\"saas-stepper__container\",t.className)}),/*#__PURE__*/e.createElement(I,{orientation:o},l))))});d&&(D.displayName=\"Stepper\");const I=t=>{var s,r;const{children:n,orientation:c,stepComponent:p}=t,l=S(t,g),d=i(),{activeIndex:f}=N(),_=v({display:\"flex\",flexDirection:\"row\",alignItems:\"center\"},d.steps),h=\"vertical\"===c,x=p||L,y=o(n,x),C=y.reduce((t,s,r,n)=>(t.push(/*#__PURE__*/e.createElement(x,v({key:r},s.props,{icon:s.props.icon||r+1,isActive:f===r,isCompleted:s.props.isCompleted||f>r}))),\"vertical\"===c&&t.push(/*#__PURE__*/e.createElement(w,{isOpen:f===r},s.props.children)),r<n.length-1&&t.push(/*#__PURE__*/e.createElement(F,{key:`separator-${r}`,isActive:r<f})),t),[]),E=m(n,T),b=f>=y.length?E:h?null:/*#__PURE__*/e.createElement(w,null,null==(s=y[f])||null==(r=s.props)?void 0:r.children);/*#__PURE__*/return e.createElement(e.Fragment,null,/*#__PURE__*/e.createElement(a.div,v({__css:_},l,{className:u(\"saas-stepper__steps\",t.className)}),C),b)};d&&(I.displayName=\"StepperSteps\");const w=t=>{const{children:s,isOpen:r=!0}=t,n=S(t,b),c=i();/*#__PURE__*/return e.createElement(a.div,v({__css:c.content},n,{className:u(\"saas-stepper__content\",t.className)}),/*#__PURE__*/e.createElement(l,{in:r},s))};d&&(w.displayName=\"StepperContent\");const j=t=>{const{icon:s,isCompleted:r,className:n}=t,l=S(t,k),o=v({display:\"flex\",alignItems:\"center\",justifyContent:\"center\",borderRadius:\"full\",fontSize:\"1em\",me:2},i().icon);let m;return m=r?/*#__PURE__*/e.createElement(c,{as:p}):s,/*#__PURE__*/e.createElement(a.div,v({__css:o},l,{className:u(\"saas-stepper__icon\",n)}),m)};d&&(j.displayName=\"StepperIcon\");const L=t=>{const{title:s,icon:r,isActive:n,isCompleted:c}=t,p=S(t,A),l=x(t),o=v({display:\"flex\",alignItems:\"center\",flexDirection:\"row\"},i().step);/*#__PURE__*/return e.createElement(a.div,v({__css:o,\"data-active\":l.isActive,\"data-completed\":l.isCompleted},p,{className:u(\"saas-stepper__step\",t.className)}),/*#__PURE__*/e.createElement(j,{icon:r,isActive:n,isCompleted:c}),s&&/*#__PURE__*/e.createElement(R,null,s))};d&&(L.displayName=\"StepperStep\");const F=t=>{const{isActive:s}=t,r=S(t,O),n=v({flex:1,borderTopWidth:\"1px\",mx:2},i().separator);/*#__PURE__*/return e.createElement(a.div,v({\"data-active\":s},r,{className:u(\"saas-stepper__separator\",t.className),__css:n}))};d&&(F.displayName=\"StepperSeparator\");const R=t=>{const s=i();/*#__PURE__*/return e.createElement(a.p,v({},t,{__css:s.title,className:u(\"saas-stepper__title\",t.className)}))};d&&(R.displayName=\"StepperStepTitle\");const T=t=>{const s=i();/*#__PURE__*/return e.createElement(a.div,v({__css:s.completed},t,{className:u(\"saas-stepper__completed\",t.className)}))};d&&(T.displayName=\"StepperCompleted\");export{D as Stepper,T as StepperCompleted,w as StepperContent,j as StepperIcon,_ as StepperProvider,F as StepperSeparator,L as StepperStep,R as StepperStepTitle,I as StepperSteps,C as useNext,y as usePrev,x as useStep,h as useStepper,N as useStepperContext};\n//# sourceMappingURL=index.modern.js.map\n","import * as React from 'react'\nimport { FieldValues, SubmitHandler } from 'react-hook-form'\nimport { createContext } from '@chakra-ui/react-utils'\nimport {\n useStepper,\n useStep,\n UseStepperProps,\n UseStepperReturn,\n} from '@saas-ui/stepper'\n\nexport interface StepState {\n name: string\n schema?: any\n isActive?: boolean\n isCompleted?: boolean\n}\n\nexport interface StepFormContext extends UseStepperReturn {\n updateStep(state: StepState): void\n steps: Record<string, StepState>\n}\n\nexport const [StepFormProvider, useStepFormContext] =\n createContext<StepFormContext>({\n name: 'StepFormContext',\n errorMessage:\n 'useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`',\n })\n\nimport { FormProps } from './form'\n\nexport interface UseStepFormProps<\n TFieldValues extends FieldValues = FieldValues\n> extends UseStepperProps,\n FormProps<TFieldValues> {}\n\nexport function useStepForm<TFieldValues extends FieldValues = FieldValues>(\n props: UseStepFormProps<TFieldValues>\n) {\n const stepper = useStepper(props)\n\n const { activeStep, isLastStep, nextStep } = stepper\n\n const [steps, updateSteps] = React.useState({})\n\n const onSubmitStep: SubmitHandler<TFieldValues> = React.useCallback(\n async (data) => {\n if (isLastStep) {\n return props\n .onSubmit?.(data)\n .then(() => {\n const step = steps[activeStep]\n updateStep({\n ...step,\n isCompleted: true,\n })\n })\n .then(nextStep) // Show completed step\n }\n\n nextStep()\n },\n [activeStep, isLastStep]\n )\n\n const getFormProps = React.useCallback(\n (props) => {\n const step = steps[activeStep]\n return {\n onSubmit: onSubmitStep,\n schema: step?.schema,\n }\n },\n [steps, onSubmitStep, activeStep]\n )\n\n const updateStep = React.useCallback(\n (step) => {\n updateSteps((steps) => {\n return {\n ...steps,\n [step.name]: step,\n }\n })\n },\n [steps]\n )\n\n return {\n getFormProps,\n updateStep,\n steps,\n ...stepper,\n }\n}\n\nexport type UseStepFormReturn = ReturnType<typeof useStepForm>\n\nexport interface UseFormStepProps {\n name: string\n schema?: any\n}\n\nexport function useFormStep(props: UseFormStepProps): StepState {\n const { name, schema } = props\n const step = useStep({ name })\n\n const { steps, updateStep } = useStepFormContext()\n\n React.useEffect(() => {\n updateStep({ name, schema })\n }, [name, schema])\n\n return {\n ...step,\n ...(steps[name] || { name, schema }),\n }\n}\n","import * as React from 'react'\n\nimport { FieldValues, UseFormReturn } from 'react-hook-form'\n\nimport {\n chakra,\n HTMLChakraProps,\n useMultiStyleConfig,\n StylesProvider,\n} from '@chakra-ui/system'\n\nimport { callAllHandlers, runIfFn, cx, __DEV__ } from '@chakra-ui/utils'\n\nimport {\n StepperProvider,\n StepperSteps,\n StepperStepsProps,\n StepperStep,\n useStepperContext,\n} from '@saas-ui/stepper'\nimport { Button, ButtonProps } from '@saas-ui/button'\n\nimport { Form, FormProps } from './form'\nimport { SubmitButton } from './submit-button'\n\nimport {\n useStepForm,\n useFormStep,\n StepFormProvider,\n UseStepFormProps,\n} from './use-step-form'\n\nexport interface StepFormProps<TFieldValues extends FieldValues = FieldValues>\n extends UseStepFormProps<TFieldValues>,\n FormProps<TFieldValues> {}\n\nexport const StepForm = React.forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: StepFormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const { children, onSubmit, ...rest } = props\n\n const stepper = useStepForm<TFieldValues>(props)\n\n const { getFormProps, ...ctx } = stepper\n\n const context = React.useMemo(() => ctx, [ctx])\n\n return (\n <StepperProvider value={context}>\n <StepFormProvider value={context}>\n <Form ref={ref} {...rest} {...getFormProps(props)}>\n {runIfFn(children, stepper)}\n </Form>\n </StepFormProvider>\n </StepperProvider>\n )\n }\n) as <TFieldValues extends FieldValues>(\n props: FormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement\n\nexport interface FormStepOptions {\n /**\n * The step name\n */\n name: string\n /**\n * Schema\n */\n schema?: any\n}\n\nexport const FormStepper: React.FC<StepperStepsProps> = (props) => {\n const styles = useMultiStyleConfig('Stepper', props)\n\n const { children } = props\n\n const elements = React.Children.map(children, (child) => {\n if (React.isValidElement(child) && child?.type === FormStep) {\n const { isCompleted } = useFormStep(child.props) // Register this step\n return (\n <StepperStep\n name={child.props.name}\n title={child.props.title}\n isCompleted={isCompleted}\n >\n {child.props.children}\n </StepperStep>\n )\n }\n return child\n })\n\n return (\n <StylesProvider value={styles}>\n <StepperSteps mb=\"4\" {...props}>\n {elements}\n </StepperSteps>\n </StylesProvider>\n )\n}\n\nexport interface FormStepProps\n extends FormStepOptions,\n HTMLChakraProps<'div'> {}\n\nexport const FormStep: React.FC<FormStepProps> = (props) => {\n const { name, schema, children, className, ...rest } = props\n const step = useFormStep({ name, schema })\n\n const { isActive } = step\n\n return isActive ? (\n <chakra.div {...rest} className={cx('saas-form__step', className)}>\n {children}\n </chakra.div>\n ) : null\n}\n\nif (__DEV__) {\n FormStep.displayName = 'FormStep'\n}\n\nexport const PrevButton: React.FC<ButtonProps> = (props) => {\n const { isFirstStep, isCompleted, prevStep } = useStepperContext()\n\n return (\n <Button\n isDisabled={isFirstStep || isCompleted}\n label=\"Back\"\n {...props}\n className={cx('saas-form__prev-button', props.className)}\n onClick={callAllHandlers(props.onClick, prevStep)}\n />\n )\n}\n\nif (__DEV__) {\n PrevButton.displayName = 'PrevButton'\n}\n\nexport interface NextButtonProps extends ButtonProps {\n submitLabel?: string\n}\n\nexport const NextButton: React.FC<NextButtonProps> = (props) => {\n const { label = 'Next', submitLabel = 'Complete', ...rest } = props\n const { isLastStep, isCompleted } = useStepperContext()\n\n return (\n <SubmitButton\n isDisabled={isCompleted}\n label={isLastStep || isCompleted ? submitLabel : label}\n {...rest}\n className={cx('saas-form__next-button', props.className)}\n />\n )\n}\n\nif (__DEV__) {\n NextButton.displayName = 'NextButton'\n}\n"],"names":["DisplayField","_ref","name","label","props","React","FormControl","FormLabel","htmlFor","Text","fontSize","FormValue","getValues","useFormContext","inputTypes","defaultInputType","BaseField","help","variant","hideLabel","children","controlProps","formState","error","get","errors","getError","isInvalid","Box","message","FormHelperText","FormErrorMessage","Field","forwardRef","ref","type","InputComponent","getInput","withControlledInput","rules","inputProps","control","Controller","render","_ref3","field","useMergeRefs","withUncontrolledInput","register","registerFieldType","component","options","isControlled","displayName","isDisabled","isReadOnly","isRequired","inputRules","required","createField","split","map","part","charAt","toUpperCase","slice","join","InputField","Input","NumberInputField","NumberInput","PasswordInputFIeld","PasswordInput","TextareaField","Textarea","SwitchField","Switch","SelectField","Select","CheckboxField","Checkbox","RadioField","RadioInput","PinField","PinInput","NativeSelectField","NativeSelect","getType","spec","meta","_field$spec$meta","getArrayOption","test","tests","OPTIONS","_test$OPTIONS","params","getFieldsFromSchema","schema","fields","schemaFields","innerType","min","max","push","FormLayoutItem","chakra","div","FormLayout","gridProps","useTheme","components","_theme$components","_theme$components$For2","defaultProps","spacing","SimpleGrid","Children","child","isValidElement","mapNestedFields","cloneElement","ArrayFieldProvider","useArrayFieldContext","createContext","ArrayFieldRowProvider","useArrayFieldRowContext","useArrayField","defaultValue","keyName","useFieldArray","useArrayFieldRow","index","clearErrors","remove","useEffect","isFirst","isLast","length","useCallback","useArrayFieldRemoveButton","onClick","useArrayFieldAddButton","append","shouldFocus","ArrayFieldRow","columns","ArrayFieldRowContainer","ArrayFieldRowFields","ArrayFieldRemoveButton","layoutProps","flex","gridGap","mr","context","value","__css","display","flexDirection","alignItems","width","mb","IconButton","icon","MinusIcon","ArrayFieldAddButton","AddIcon","float","ArrayField","containerProps","ArrayFieldContainer","ArrayFieldRows","id","key","fieldProps","useImperativeHandle","FormLegend","styles","useStyles","as","sx","legend","ObjectField","getNestedFields","path","reach","getNestedSchema","nestedFieldProps","Fields","_ref2","Form","mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","defaultValues","onSubmit","onError","formRef","rest","form","yupResolver","methods","useForm","handleSubmit","FormProvider","SubmitButton","disableIfUntouched","disableIfInvalid","Button","isLoading","isSubmitting","isPrimary","isDirty","isValid","AutoForm","submitLabel","DisplayIf","isExact","condition","useWatch","disabled","exact","StepperProvider","useStepperContext","errorMessage","useStepper","step","activeIndex","setIndex","useState","stepsRef","useRef","onUpdate","Date","now","registerStep","newSteps","current","indexOf","setStep","i","useLayoutEffect","activeStep","isFirstStep","isLastStep","isCompleted","nextStep","prevStep","unregisterStep","useStep","isActive","StepFormProvider","useStepFormContext","useStepForm","stepper","steps","updateSteps","onSubmitStep","async","data","then","updateStep","getFormProps","useFormStep","StepForm","ctx","useMemo","runIfFn","FormStepper","useMultiStyleConfig","elements","FormStep","StepperStep","title","StylesProvider","StepperSteps","className","cx","__DEV__","PrevButton","callAllHandlers","NextButton"],"mappings":"mqDAgBaA,GAA4CC,QAACC,KACxDA,EADwDC,MAExDA,KAEGC,uBAEH,OACEC,gBAACC,EAAgBF,EACdD,eAAQE,gBAACE,GAAUC,QAASN,GAAOC,GAAqB,kBACzDE,gBAACI,GAAKC,SAAS,mBACbL,gBAACM,IAAUT,KAAMA,OAMZS,GAAwC,EAAGT,KAAAA,MACtD,MAAMU,UAAEA,GAAcC,IACtB,OAAOD,EAAUV,IAAS,0PC6EtBY,GAAsC,GAEtCC,GAAmB,OAiBZC,GAAmCZ,IAC9C,MAAMF,KAAEA,EAAFC,MAAQA,EAARc,KAAeA,EAAfC,QAAqBA,EAArBC,UAA8BA,EA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 +1,32 @@
1
+ import * as React from 'react';
2
+ import { FieldValues, UseFormReturn } from 'react-hook-form';
3
+ import { HTMLChakraProps } from '@chakra-ui/system';
4
+ import { StepperStepsProps } from '@saas-ui/stepper';
5
+ import { ButtonProps } from '@saas-ui/button';
6
+ import { FormProps } from './form';
7
+ import { UseStepFormProps } from './use-step-form';
8
+ export interface StepFormProps<TFieldValues extends FieldValues = FieldValues> extends UseStepFormProps<TFieldValues>, FormProps<TFieldValues> {
9
+ }
10
+ export declare const StepForm: <TFieldValues extends FieldValues>(props: FormProps<TFieldValues> & {
11
+ ref?: React.ForwardedRef<UseFormReturn<TFieldValues, object>> | undefined;
12
+ }) => React.ReactElement;
13
+ export interface FormStepOptions {
14
+ /**
15
+ * The step name
16
+ */
17
+ name: string;
18
+ /**
19
+ * Schema
20
+ */
21
+ schema?: any;
22
+ }
23
+ export declare const FormStepper: React.FC<StepperStepsProps>;
24
+ export interface FormStepProps extends FormStepOptions, HTMLChakraProps<'div'> {
25
+ }
26
+ export declare const FormStep: React.FC<FormStepProps>;
27
+ export declare const PrevButton: React.FC<ButtonProps>;
28
+ export interface NextButtonProps extends ButtonProps {
29
+ submitLabel?: string;
30
+ }
31
+ export declare const NextButton: React.FC<NextButtonProps>;
32
+ //# sourceMappingURL=step-form.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"step-form.d.ts","sourceRoot":"","sources":["../src/step-form.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAE5D,OAAO,EAEL,eAAe,EAGhB,MAAM,mBAAmB,CAAA;AAI1B,OAAO,EAGL,iBAAiB,EAGlB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAU,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAErD,OAAO,EAAQ,SAAS,EAAE,MAAM,QAAQ,CAAA;AAGxC,OAAO,EAIL,gBAAgB,EACjB,MAAM,iBAAiB,CAAA;AAExB,MAAM,WAAW,aAAa,CAAC,YAAY,SAAS,WAAW,GAAG,WAAW,CAC3E,SAAQ,gBAAgB,CAAC,YAAY,CAAC,EACpC,SAAS,CAAC,YAAY,CAAC;CAAG;AAE9B,eAAO,MAAM,QAAQ;;MA2BhB,MAAM,YAAY,CAAA;AAEvB,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;OAEG;IACH,MAAM,CAAC,EAAE,GAAG,CAAA;CACb;AAED,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CA4BnD,CAAA;AAED,MAAM,WAAW,aACf,SAAQ,eAAe,EACrB,eAAe,CAAC,KAAK,CAAC;CAAG;AAE7B,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,aAAa,CAW5C,CAAA;AAMD,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAY5C,CAAA;AAMD,MAAM,WAAW,eAAgB,SAAQ,WAAW;IAClD,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CAYhD,CAAA"}
@@ -52,7 +52,7 @@ export interface ArrayFieldOptions {
52
52
  */
53
53
  defaultValue?: Record<string, any>;
54
54
  /**
55
- * Default key name for rows, change this if your data uses 'id'
55
+ * Default key name for rows, change this if your data uses a different 'id' field
56
56
  * @default "id"
57
57
  */
58
58
  keyName?: string;
@@ -0,0 +1,44 @@
1
+ import * as React from 'react';
2
+ import { FieldValues, SubmitHandler } from 'react-hook-form';
3
+ import { UseStepperProps, UseStepperReturn } from '@saas-ui/stepper';
4
+ export interface StepState {
5
+ name: string;
6
+ schema?: any;
7
+ isActive?: boolean;
8
+ isCompleted?: boolean;
9
+ }
10
+ export interface StepFormContext extends UseStepperReturn {
11
+ updateStep(state: StepState): void;
12
+ steps: Record<string, StepState>;
13
+ }
14
+ export declare const StepFormProvider: React.Provider<StepFormContext>, useStepFormContext: () => StepFormContext;
15
+ import { FormProps } from './form';
16
+ export interface UseStepFormProps<TFieldValues extends FieldValues = FieldValues> extends UseStepperProps, FormProps<TFieldValues> {
17
+ }
18
+ export declare function useStepForm<TFieldValues extends FieldValues = FieldValues>(props: UseStepFormProps<TFieldValues>): {
19
+ stepsRef: React.MutableRefObject<string[]>;
20
+ activeStep: string;
21
+ activeIndex: number;
22
+ isFirstStep: boolean;
23
+ isLastStep: boolean;
24
+ isCompleted: boolean;
25
+ setIndex: React.Dispatch<React.SetStateAction<number>>;
26
+ setStep: (name: string) => void;
27
+ nextStep: () => void;
28
+ prevStep: () => void;
29
+ registerStep: (name: string) => void;
30
+ unregisterStep: (name: string) => void;
31
+ getFormProps: (props: any) => {
32
+ onSubmit: SubmitHandler<TFieldValues>;
33
+ schema: any;
34
+ };
35
+ updateStep: (step: any) => void;
36
+ steps: {};
37
+ };
38
+ export declare type UseStepFormReturn = ReturnType<typeof useStepForm>;
39
+ export interface UseFormStepProps {
40
+ name: string;
41
+ schema?: any;
42
+ }
43
+ export declare function useFormStep(props: UseFormStepProps): StepState;
44
+ //# sourceMappingURL=use-step-form.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-step-form.d.ts","sourceRoot":"","sources":["../src/use-step-form.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAE5D,OAAO,EAGL,eAAe,EACf,gBAAgB,EACjB,MAAM,kBAAkB,CAAA;AAEzB,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,GAAG,CAAA;IACZ,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB;AAED,MAAM,WAAW,eAAgB,SAAQ,gBAAgB;IACvD,UAAU,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAAA;IAClC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;CACjC;AAED,eAAO,MAAO,gBAAgB,mCAAE,kBAAkB,uBAK9C,CAAA;AAEJ,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAElC,MAAM,WAAW,gBAAgB,CAC/B,YAAY,SAAS,WAAW,GAAG,WAAW,CAC9C,SAAQ,eAAe,EACrB,SAAS,CAAC,YAAY,CAAC;CAAG;AAE9B,wBAAgB,WAAW,CAAC,YAAY,SAAS,WAAW,GAAG,WAAW,EACxE,KAAK,EAAE,gBAAgB,CAAC,YAAY,CAAC;;;;;;;;;;;;;;;;;;;EAyDtC;AAED,oBAAY,iBAAiB,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAA;AAE9D,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,GAAG,CAAA;CACb;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,SAAS,CAc9D"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saas-ui/forms",
3
- "version": "0.3.4",
3
+ "version": "0.5.2",
4
4
  "description": "Theme and components agnostic SaasProvider",
5
5
  "source": "src/index.ts",
6
6
  "exports": {
@@ -64,14 +64,16 @@
64
64
  "dependencies": {
65
65
  "@chakra-ui/icons": "^1.1.1",
66
66
  "@chakra-ui/react-utils": "^1.2.1",
67
+ "@chakra-ui/utils": "^1.10.4",
67
68
  "@hookform/resolvers": "^2.8.3",
68
- "@saas-ui/button": "0.2.1",
69
- "@saas-ui/input-right-button": "0.2.1",
70
- "@saas-ui/number-input": "0.2.2",
71
- "@saas-ui/password-input": "0.2.2",
72
- "@saas-ui/pin-input": "0.2.1",
73
- "@saas-ui/radio": "0.2.1",
74
- "@saas-ui/select": "0.2.2",
69
+ "@saas-ui/button": "0.3.0",
70
+ "@saas-ui/input-right-button": "0.3.0",
71
+ "@saas-ui/number-input": "0.3.0",
72
+ "@saas-ui/password-input": "0.3.0",
73
+ "@saas-ui/pin-input": "0.3.0",
74
+ "@saas-ui/radio": "0.3.0",
75
+ "@saas-ui/react-utils": "0.1.0",
76
+ "@saas-ui/select": "0.3.0",
75
77
  "react-hook-form": "^7.22.0"
76
78
  },
77
79
  "peerDependencies": {
@@ -20,6 +20,7 @@ import {
20
20
  useArrayFieldRowContext,
21
21
  useArrayFieldRemoveButton,
22
22
  useArrayFieldAddButton,
23
+ UseArrayFieldReturn,
23
24
  } from './use-array-field'
24
25
 
25
26
  interface ArrayField {
@@ -137,26 +138,28 @@ export interface ArrayFieldProps
137
138
  extends ArrayFieldOptions,
138
139
  Omit<FieldProps, 'defaultValue'> {}
139
140
 
140
- export const ArrayField: React.FC<ArrayFieldProps> = (props) => {
141
- const { children, ...containerProps } = props
142
-
143
- return (
144
- <ArrayFieldContainer {...containerProps}>
145
- <ArrayFieldRows>
146
- {(fields: ArrayField[]) => (
147
- <>
148
- {fields.map(({ id }, index: number) => (
149
- <ArrayFieldRow key={id} index={index}>
150
- {children}
151
- </ArrayFieldRow>
152
- ))}
153
- </>
154
- )}
155
- </ArrayFieldRows>
156
- <ArrayFieldAddButton />
157
- </ArrayFieldContainer>
158
- )
159
- }
141
+ export const ArrayField = React.forwardRef(
142
+ (props: ArrayFieldProps, ref: React.ForwardedRef<UseArrayFieldReturn>) => {
143
+ const { children, ...containerProps } = props
144
+
145
+ return (
146
+ <ArrayFieldContainer ref={ref} {...containerProps}>
147
+ <ArrayFieldRows>
148
+ {(fields: ArrayField[]) => (
149
+ <>
150
+ {fields.map(({ id }, index: number) => (
151
+ <ArrayFieldRow key={id} index={index}>
152
+ {children}
153
+ </ArrayFieldRow>
154
+ ))}
155
+ </>
156
+ )}
157
+ </ArrayFieldRows>
158
+ <ArrayFieldAddButton />
159
+ </ArrayFieldContainer>
160
+ )
161
+ }
162
+ )
160
163
 
161
164
  export interface ArrayFieldRowsProps {
162
165
  children: (fields: ArrayField[]) => React.ReactElement | null
@@ -169,28 +172,36 @@ export const ArrayFieldRows = ({
169
172
  return children(fields)
170
173
  }
171
174
 
172
- export const ArrayFieldContainer: React.FC<ArrayFieldProps> = ({
173
- name,
174
- defaultValue,
175
- keyName,
176
- min,
177
- max,
178
- children,
179
- ...fieldProps
180
- }) => {
181
- const context = useArrayField({
182
- name,
183
- defaultValue,
184
- keyName,
185
- min,
186
- max,
187
- })
188
-
189
- return (
190
- <ArrayFieldProvider value={context}>
191
- <BaseField name={name} {...fieldProps}>
192
- {children}
193
- </BaseField>
194
- </ArrayFieldProvider>
195
- )
196
- }
175
+ export const ArrayFieldContainer = React.forwardRef(
176
+ (
177
+ {
178
+ name,
179
+ defaultValue,
180
+ keyName,
181
+ min,
182
+ max,
183
+ children,
184
+ ...fieldProps
185
+ }: ArrayFieldProps,
186
+ ref: React.ForwardedRef<UseArrayFieldReturn>
187
+ ) => {
188
+ const context = useArrayField({
189
+ name,
190
+ defaultValue,
191
+ keyName,
192
+ min,
193
+ max,
194
+ })
195
+
196
+ // This exposes the useArrayField api through the forwarded ref
197
+ React.useImperativeHandle(ref, () => context, [ref, context])
198
+
199
+ return (
200
+ <ArrayFieldProvider value={context}>
201
+ <BaseField name={name} {...fieldProps}>
202
+ {children}
203
+ </BaseField>
204
+ </ArrayFieldProvider>
205
+ )
206
+ }
207
+ )
@@ -20,12 +20,17 @@ export const DisplayField: React.FC<DisplayFieldProps> = ({
20
20
  placeholder,
21
21
  ...props
22
22
  }) => {
23
- const { getValues } = useFormContext()
24
-
25
23
  return (
26
24
  <FormControl {...props}>
27
25
  {label ? <FormLabel htmlFor={name}>{label}</FormLabel> : null}
28
- <Text fontSize="md">{getValues(name)}</Text>
26
+ <Text fontSize="md">
27
+ <FormValue name={name} />
28
+ </Text>
29
29
  </FormControl>
30
30
  )
31
31
  }
32
+
33
+ export const FormValue: React.FC<{ name: string }> = ({ name }) => {
34
+ const { getValues } = useFormContext()
35
+ return getValues(name) || null
36
+ }
package/src/form.tsx CHANGED
@@ -87,7 +87,7 @@ export const Form = forwardRef(
87
87
  const methods = useForm<TFieldValues>(form)
88
88
  const { handleSubmit } = methods
89
89
 
90
- // This exposes the useForm api through the forwareded ref
90
+ // This exposes the useForm api through the forwarded ref
91
91
  React.useImperativeHandle(ref, () => methods, [ref, methods])
92
92
 
93
93
  return (
package/src/index.ts CHANGED
@@ -9,6 +9,8 @@ export * from './array-field'
9
9
  export * from './use-array-field'
10
10
  export * from './object-field'
11
11
  export * from './display-if'
12
+ export * from './step-form'
13
+ export * from './use-step-form'
12
14
 
13
15
  export * from '@saas-ui/input-right-button'
14
16