From 0c77d1943f10c662f428dfcf510102d089c0c1cf Mon Sep 17 00:00:00 2001 From: Damien Roche Date: Tue, 17 Dec 2024 09:19:21 +0100 Subject: [PATCH] fix: add disabled support for boolean --- .../ui/auto-form/AutoFormFieldBoolean.vue | 4 ++-- .../lib/registry/default/ui/auto-form/utils.ts | 17 +++++++++++++++++ .../ui/auto-form/AutoFormFieldBoolean.vue | 4 ++-- .../lib/registry/new-york/ui/auto-form/utils.ts | 17 +++++++++++++++++ 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/apps/www/src/lib/registry/default/ui/auto-form/AutoFormFieldBoolean.vue b/apps/www/src/lib/registry/default/ui/auto-form/AutoFormFieldBoolean.vue index e6bb6a25..81b9d6e3 100644 --- a/apps/www/src/lib/registry/default/ui/auto-form/AutoFormFieldBoolean.vue +++ b/apps/www/src/lib/registry/default/ui/auto-form/AutoFormFieldBoolean.vue @@ -5,7 +5,7 @@ import { FormControl, FormDescription, FormField, FormItem, FormMessage } from ' import { Switch } from '@/lib/registry/default/ui/switch' import { computed } from 'vue' import AutoFormLabel from './AutoFormLabel.vue' -import { beautifyObjectName } from './utils' +import { beautifyObjectName, maybeBooleanishToBoolean } from './utils' const props = defineProps() @@ -21,7 +21,7 @@ const booleanComponent = computed(() => props.config?.component === 'switch' ? S diff --git a/apps/www/src/lib/registry/default/ui/auto-form/utils.ts b/apps/www/src/lib/registry/default/ui/auto-form/utils.ts index 1fa3a296..160a4dfe 100644 --- a/apps/www/src/lib/registry/default/ui/auto-form/utils.ts +++ b/apps/www/src/lib/registry/default/ui/auto-form/utils.ts @@ -169,3 +169,20 @@ export function getFromPath( return resolvedValue as TValue | undefined } + +type Booleanish = boolean | 'true' | 'false' + +export function booleanishToBoolean(value: Booleanish) { + switch (value) { + case 'true': + case true: + return true + case 'false': + case false: + return false + } +} + +export function maybeBooleanishToBoolean(value?: Booleanish) { + return value ? booleanishToBoolean(value) : undefined +} diff --git a/apps/www/src/lib/registry/new-york/ui/auto-form/AutoFormFieldBoolean.vue b/apps/www/src/lib/registry/new-york/ui/auto-form/AutoFormFieldBoolean.vue index 40fee8cc..21bfbd2b 100644 --- a/apps/www/src/lib/registry/new-york/ui/auto-form/AutoFormFieldBoolean.vue +++ b/apps/www/src/lib/registry/new-york/ui/auto-form/AutoFormFieldBoolean.vue @@ -5,7 +5,7 @@ import { FormControl, FormDescription, FormField, FormItem, FormMessage } from ' import { Switch } from '@/lib/registry/new-york/ui/switch' import { computed } from 'vue' import AutoFormLabel from './AutoFormLabel.vue' -import { beautifyObjectName } from './utils' +import { beautifyObjectName, maybeBooleanishToBoolean } from './utils' const props = defineProps() @@ -21,7 +21,7 @@ const booleanComponent = computed(() => props.config?.component === 'switch' ? S diff --git a/apps/www/src/lib/registry/new-york/ui/auto-form/utils.ts b/apps/www/src/lib/registry/new-york/ui/auto-form/utils.ts index 1fa3a296..160a4dfe 100644 --- a/apps/www/src/lib/registry/new-york/ui/auto-form/utils.ts +++ b/apps/www/src/lib/registry/new-york/ui/auto-form/utils.ts @@ -169,3 +169,20 @@ export function getFromPath( return resolvedValue as TValue | undefined } + +type Booleanish = boolean | 'true' | 'false' + +export function booleanishToBoolean(value: Booleanish) { + switch (value) { + case 'true': + case true: + return true + case 'false': + case false: + return false + } +} + +export function maybeBooleanishToBoolean(value?: Booleanish) { + return value ? booleanishToBoolean(value) : undefined +}