@saas-ui/forms 1.0.0-rc.0 → 1.0.0-rc.3

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.
package/src/field.tsx CHANGED
@@ -227,7 +227,7 @@ const createField = (
227
227
  ref={ref}
228
228
  id={id}
229
229
  name={name}
230
- label={label}
230
+ label={hideLabel ? label : undefined} // Only pass down the label when it should be inline.
231
231
  rules={inputRules}
232
232
  {...inputProps}
233
233
  />
@@ -292,7 +292,7 @@ export interface RegisterFieldTypeOptions {
292
292
  * @param component The React component
293
293
  * @param options
294
294
  * @param options.isControlled Set this to true if this is a controlled field.
295
- * @param options.hideLabel Hide the field label, for example for checkbox or switch field.
295
+ * @param options.hideLabel Hide the field label, for example for the checkbox field.
296
296
  */
297
297
  export const registerFieldType = (
298
298
  type: string,
@@ -320,9 +320,12 @@ export const registerFieldType = (
320
320
  return Field
321
321
  }
322
322
 
323
- // @todo Consider not registering all fields by default to lower the package size and computations.
324
- // Not all types may be required in a project.
325
- export const InputField = registerFieldType('text', Input)
323
+ export const InputField = registerFieldType(
324
+ 'text',
325
+ forwardRef(({ type = 'text', ...rest }, ref) => {
326
+ return <Input type={type} {...rest} ref={ref} />
327
+ })
328
+ )
326
329
  export const NumberInputField = registerFieldType('number', NumberInput, {
327
330
  isControlled: true,
328
331
  })
@@ -330,16 +333,11 @@ export const PasswordInputFIeld = registerFieldType('password', PasswordInput)
330
333
  export const TextareaField = registerFieldType('textarea', Textarea)
331
334
  export const SwitchField = registerFieldType(
332
335
  'switch',
333
- forwardRef(({ label, ...props }: { label?: string }, ref) => {
334
- return (
335
- <Switch ref={ref} {...props}>
336
- {label}
337
- </Switch>
338
- )
336
+ forwardRef(({ type, ...rest }, ref) => {
337
+ return <Switch {...rest} ref={ref} />
339
338
  }),
340
339
  {
341
340
  isControlled: true,
342
- hideLabel: true,
343
341
  }
344
342
  )
345
343
  export const SelectField = registerFieldType('select', Select, {
@@ -347,13 +345,15 @@ export const SelectField = registerFieldType('select', Select, {
347
345
  })
348
346
  export const CheckboxField = registerFieldType(
349
347
  'checkbox',
350
- forwardRef(({ label, ...props }: { label?: string }, ref) => {
351
- return (
352
- <Checkbox ref={ref} {...props}>
353
- {label}
354
- </Checkbox>
355
- )
356
- }),
348
+ forwardRef(
349
+ ({ label, type, ...props }: { label?: string; type: string }, ref) => {
350
+ return (
351
+ <Checkbox ref={ref} {...props}>
352
+ {label}
353
+ </Checkbox>
354
+ )
355
+ }
356
+ ),
357
357
  {
358
358
  hideLabel: true,
359
359
  }
@@ -4,7 +4,7 @@ import {
4
4
  FormLabel,
5
5
  FormLabelProps,
6
6
  ResponsiveValue,
7
- useStyles,
7
+ useStyleConfig,
8
8
  } from '@chakra-ui/react'
9
9
  import { __DEV__ } from '@chakra-ui/utils'
10
10
 
@@ -21,8 +21,8 @@ export interface ObjectFieldProps extends FieldProps {
21
21
  }
22
22
 
23
23
  export const FormLegend = (props: FormLabelProps) => {
24
- const styles = useStyles()
25
- return <FormLabel as="legend" sx={styles.legend} {...props} />
24
+ const styles = useStyleConfig('FormLegend')
25
+ return <FormLabel as="legend" sx={styles} {...props} />
26
26
  }
27
27
 
28
28
  export const ObjectField: React.FC<ObjectFieldProps> = (props) => {