create-nextjs-cms 0.7.5 → 0.7.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-nextjs-cms",
3
- "version": "0.7.5",
3
+ "version": "0.7.7",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "bin": {
@@ -29,8 +29,8 @@
29
29
  "tsx": "^4.20.6",
30
30
  "typescript": "^5.9.2",
31
31
  "@lzcms/eslint-config": "0.3.0",
32
- "@lzcms/tsconfig": "0.1.0",
33
- "@lzcms/prettier-config": "0.1.0"
32
+ "@lzcms/prettier-config": "0.1.0",
33
+ "@lzcms/tsconfig": "0.1.0"
34
34
  },
35
35
  "prettier": "@lzcms/prettier-config",
36
36
  "scripts": {
@@ -4,20 +4,32 @@ import { CheckboxFieldClientConfig } from 'nextjs-cms/core/fields'
4
4
  import { useController, useFormContext } from 'react-hook-form'
5
5
  import { Switch } from '@/components/ui/switch'
6
6
 
7
+ function toChecked(value: unknown): boolean {
8
+ if (value === true) return true
9
+ if (value === 1) return true
10
+ if (value === '1') return true
11
+ if (value === 'true') return true
12
+ if (value === 'on') return true
13
+ return false
14
+ }
15
+
7
16
  export default function CheckboxFormInput({ input }: { input: CheckboxFieldClientConfig }) {
8
17
  const { control } = useFormContext()
18
+ const initialValue =
19
+ input.value !== undefined && input.value !== null ? toChecked(input.value) : toChecked(input.defaultValue)
20
+
9
21
  const {
10
22
  field,
11
- fieldState: { invalid, isTouched, isDirty, error },
23
+ fieldState: { error },
12
24
  } = useController({
13
25
  name: input.name,
14
26
  control,
15
- defaultValue: input.value === 1,
27
+ defaultValue: initialValue,
16
28
  })
17
29
  return (
18
30
  <FormInputElement
19
31
  validationError={error}
20
- value={input.value}
32
+ value={initialValue}
21
33
  readonly={input.readonly}
22
34
  label={input.label}
23
35
  required={input.required}
@@ -25,8 +37,9 @@ export default function CheckboxFormInput({ input }: { input: CheckboxFieldClien
25
37
  <Switch
26
38
  ref={field.ref}
27
39
  onCheckedChange={field.onChange}
28
- defaultChecked={input.value === 1}
40
+ checked={toChecked(field.value)}
29
41
  name={field.name}
42
+ disabled={input.readonly}
30
43
  />
31
44
  </FormInputElement>
32
45
  )
@@ -66,7 +66,7 @@
66
66
  "nanoid": "^5.1.2",
67
67
  "next": "16.1.1",
68
68
  "next-themes": "^0.4.6",
69
- "nextjs-cms": "0.7.5",
69
+ "nextjs-cms": "0.7.7",
70
70
  "plaiceholder": "^3.0.0",
71
71
  "prettier-plugin-tailwindcss": "^0.7.2",
72
72
  "qrcode": "^1.5.4",