@saas-ui/forms 2.5.1 → 2.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -31,11 +31,9 @@ import {
31
31
  NativeSelectProps,
32
32
  SelectButtonProps,
33
33
  SelectListProps,
34
- SelectOption,
35
34
  } from './select'
36
35
 
37
36
  import { createField } from './create-field'
38
- import { FieldOption, FieldOptions } from './types'
39
37
 
40
38
  export interface InputFieldProps extends InputProps {
41
39
  type?: string
package/src/field.tsx CHANGED
@@ -5,6 +5,7 @@ import { FocusableElement } from '@chakra-ui/utils'
5
5
  import { useField } from './fields-context'
6
6
  import { FieldProps } from './types'
7
7
  import { useFieldProps } from './form-context'
8
+ import { InputField } from './default-fields'
8
9
 
9
10
  export interface Option {
10
11
  value: string
@@ -36,7 +37,7 @@ export const Field = React.forwardRef(
36
37
  ) => {
37
38
  const { type = defaultInputType, name } = props
38
39
  const overrides = useFieldProps(name)
39
- const InputComponent = useField(overrides?.type || type)
40
+ const InputComponent = useField(overrides?.type || type, InputField)
40
41
 
41
42
  return <InputComponent ref={ref} {...props} {...overrides} />
42
43
  }
@@ -1,6 +1,6 @@
1
1
  import React from 'react'
2
2
  import { defaultFieldTypes, InputField } from './default-fields'
3
- import { GetBaseField } from './types'
3
+ import type { GetBaseField } from './types'
4
4
 
5
5
  export interface FieldsContextValue {
6
6
  fields: Record<string, React.FC<any>>
@@ -10,14 +10,11 @@ export interface FieldsContextValue {
10
10
  const FieldsContext = React.createContext<FieldsContextValue | null>(null)
11
11
 
12
12
  export const FieldsProvider: React.FC<{
13
- value: Partial<FieldsContextValue>
13
+ value: FieldsContextValue
14
14
  children: React.ReactNode
15
15
  }> = (props) => {
16
- const fields = { ...defaultFieldTypes, ...props.value.fields }
17
16
  return (
18
- <FieldsContext.Provider
19
- value={{ fields, getBaseField: props.value.getBaseField }}
20
- >
17
+ <FieldsContext.Provider value={props.value}>
21
18
  {props.children}
22
19
  </FieldsContext.Provider>
23
20
  )
@@ -27,7 +24,10 @@ export const useFieldsContext = () => {
27
24
  return React.useContext(FieldsContext)
28
25
  }
29
26
 
30
- export const useField = (type: string): React.FC<any> => {
27
+ export const useField = (
28
+ type: string,
29
+ fallback: React.FC<any>
30
+ ): React.FC<any> => {
31
31
  const context = React.useContext(FieldsContext)
32
- return context?.fields?.[type] || InputField
32
+ return context?.fields?.[type] || fallback
33
33
  }
@@ -6,7 +6,7 @@ import {
6
6
  FieldValues,
7
7
  } from 'react-hook-form'
8
8
  import { FieldResolver } from './field-resolver'
9
- import { BaseFieldProps, FieldProps } from './types'
9
+ import type { BaseFieldProps } from './types'
10
10
 
11
11
  export type FormContextValue<
12
12
  TFieldValues extends FieldValues = FieldValues,
package/src/types.ts CHANGED
@@ -1,13 +1,13 @@
1
- import { FormControlProps } from '@chakra-ui/react'
2
- import { MaybeRenderProp } from '@chakra-ui/react-utils'
3
- import { FieldPath, FieldValues, RegisterOptions } from 'react-hook-form'
4
- import { DefaultFields } from './default-fields'
5
- import { FormProps, FormRenderContext } from './form'
6
- import { SubmitButtonProps } from './submit-button'
7
- import { ObjectFieldProps } from './object-field'
8
- import { ArrayFieldProps } from './array-field'
9
- import { StepFormRenderContext, UseStepFormProps } from './use-step-form'
10
- import { StepsOptions } from './step-form'
1
+ import type { FormControlProps } from '@chakra-ui/react'
2
+ import type { MaybeRenderProp } from '@chakra-ui/react-utils'
3
+ import type { FieldPath, FieldValues, RegisterOptions } from 'react-hook-form'
4
+ import type { DefaultFields } from './default-fields'
5
+ import type { FormProps, FormRenderContext } from './form'
6
+ import type { SubmitButtonProps } from './submit-button'
7
+ import type { ObjectFieldProps } from './object-field'
8
+ import type { ArrayFieldProps } from './array-field'
9
+ import type { StepFormRenderContext, UseStepFormProps } from './use-step-form'
10
+ import type { StepsOptions } from './step-form'
11
11
 
12
12
  export type FieldOption = { label?: string; value: string }
13
13
  export type FieldOptions<TOption extends FieldOption = FieldOption> =