Merge 7f1a4d54a8 into 3eaef4a748
This commit is contained in:
commit
1fbf52fe8b
|
|
@ -5,7 +5,7 @@ import { FormControl, FormDescription, FormField, FormItem, FormMessage } from '
|
||||||
import { Switch } from '@/lib/registry/default/ui/switch'
|
import { Switch } from '@/lib/registry/default/ui/switch'
|
||||||
import { computed } from 'vue'
|
import { computed } from 'vue'
|
||||||
import AutoFormLabel from './AutoFormLabel.vue'
|
import AutoFormLabel from './AutoFormLabel.vue'
|
||||||
import { beautifyObjectName } from './utils'
|
import { beautifyObjectName, maybeBooleanishToBoolean } from './utils'
|
||||||
|
|
||||||
const props = defineProps<FieldProps>()
|
const props = defineProps<FieldProps>()
|
||||||
|
|
||||||
|
|
@ -21,7 +21,7 @@ const booleanComponent = computed(() => props.config?.component === 'switch' ? S
|
||||||
<component
|
<component
|
||||||
:is="booleanComponent"
|
:is="booleanComponent"
|
||||||
v-bind="{ ...slotProps.componentField }"
|
v-bind="{ ...slotProps.componentField }"
|
||||||
:disabled="disabled"
|
:disabled="maybeBooleanishToBoolean(config?.inputProps?.disabled) ?? disabled"
|
||||||
:checked="slotProps.componentField.modelValue"
|
:checked="slotProps.componentField.modelValue"
|
||||||
@update:checked="slotProps.componentField['onUpdate:modelValue']"
|
@update:checked="slotProps.componentField['onUpdate:modelValue']"
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import { cn } from '@/lib/utils'
|
||||||
import { DateFormatter, getLocalTimeZone } from '@internationalized/date'
|
import { DateFormatter, getLocalTimeZone } from '@internationalized/date'
|
||||||
import { CalendarIcon } from 'lucide-vue-next'
|
import { CalendarIcon } from 'lucide-vue-next'
|
||||||
import AutoFormLabel from './AutoFormLabel.vue'
|
import AutoFormLabel from './AutoFormLabel.vue'
|
||||||
import { beautifyObjectName } from './utils'
|
import { beautifyObjectName, maybeBooleanishToBoolean } from './utils'
|
||||||
|
|
||||||
defineProps<FieldProps>()
|
defineProps<FieldProps>()
|
||||||
|
|
||||||
|
|
@ -28,7 +28,7 @@ const df = new DateFormatter('en-US', {
|
||||||
<slot v-bind="slotProps">
|
<slot v-bind="slotProps">
|
||||||
<div>
|
<div>
|
||||||
<Popover>
|
<Popover>
|
||||||
<PopoverTrigger as-child :disabled="disabled">
|
<PopoverTrigger as-child :disabled="maybeBooleanishToBoolean(config?.inputProps?.disabled) ?? disabled">
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
:class="cn(
|
:class="cn(
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import { Label } from '@/lib/registry/default/ui/label'
|
||||||
import { RadioGroup, RadioGroupItem } from '@/lib/registry/default/ui/radio-group'
|
import { RadioGroup, RadioGroupItem } from '@/lib/registry/default/ui/radio-group'
|
||||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/lib/registry/default/ui/select'
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/lib/registry/default/ui/select'
|
||||||
import AutoFormLabel from './AutoFormLabel.vue'
|
import AutoFormLabel from './AutoFormLabel.vue'
|
||||||
import { beautifyObjectName } from './utils'
|
import { beautifyObjectName, maybeBooleanishToBoolean } from './utils'
|
||||||
|
|
||||||
defineProps<FieldProps & {
|
defineProps<FieldProps & {
|
||||||
options?: string[]
|
options?: string[]
|
||||||
|
|
@ -20,14 +20,14 @@ defineProps<FieldProps & {
|
||||||
</AutoFormLabel>
|
</AutoFormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<slot v-bind="slotProps">
|
<slot v-bind="slotProps">
|
||||||
<RadioGroup v-if="config?.component === 'radio'" :disabled="disabled" :orientation="'vertical'" v-bind="{ ...slotProps.componentField }">
|
<RadioGroup v-if="config?.component === 'radio'" :disabled="maybeBooleanishToBoolean(config?.inputProps?.disabled) ?? disabled" :orientation="'vertical'" v-bind="{ ...slotProps.componentField }">
|
||||||
<div v-for="(option, index) in options" :key="option" class="mb-2 flex items-center gap-3 space-y-0">
|
<div v-for="(option, index) in options" :key="option" class="mb-2 flex items-center gap-3 space-y-0">
|
||||||
<RadioGroupItem :id="`${option}-${index}`" :value="option" />
|
<RadioGroupItem :id="`${option}-${index}`" :value="option" />
|
||||||
<Label :for="`${option}-${index}`">{{ beautifyObjectName(option) }}</Label>
|
<Label :for="`${option}-${index}`">{{ beautifyObjectName(option) }}</Label>
|
||||||
</div>
|
</div>
|
||||||
</RadioGroup>
|
</RadioGroup>
|
||||||
|
|
||||||
<Select v-else :disabled="disabled" v-bind="{ ...slotProps.componentField }">
|
<Select v-else :disabled="maybeBooleanishToBoolean(config?.inputProps?.disabled) ?? disabled" v-bind="{ ...slotProps.componentField }">
|
||||||
<SelectTrigger class="w-full">
|
<SelectTrigger class="w-full">
|
||||||
<SelectValue :placeholder="config?.inputProps?.placeholder" />
|
<SelectValue :placeholder="config?.inputProps?.placeholder" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ async function parseFileAsString(file: File | undefined): Promise<string> {
|
||||||
v-if="!inputFile"
|
v-if="!inputFile"
|
||||||
type="file"
|
type="file"
|
||||||
v-bind="{ ...config?.inputProps }"
|
v-bind="{ ...config?.inputProps }"
|
||||||
:disabled="disabled"
|
:disabled="config?.inputProps?.disabled ?? disabled"
|
||||||
@change="async (ev: InputEvent) => {
|
@change="async (ev: InputEvent) => {
|
||||||
const file = (ev.target as HTMLInputElement).files?.[0]
|
const file = (ev.target as HTMLInputElement).files?.[0]
|
||||||
inputFile = file
|
inputFile = file
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ const inputComponent = computed(() => props.config?.component === 'textarea' ? T
|
||||||
:is="inputComponent"
|
:is="inputComponent"
|
||||||
type="text"
|
type="text"
|
||||||
v-bind="{ ...slotProps.componentField, ...config?.inputProps }"
|
v-bind="{ ...slotProps.componentField, ...config?.inputProps }"
|
||||||
:disabled="disabled"
|
:disabled="config?.inputProps?.disabled ?? disabled"
|
||||||
/>
|
/>
|
||||||
</slot>
|
</slot>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ defineProps<FieldProps>()
|
||||||
</AutoFormLabel>
|
</AutoFormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<slot v-bind="slotProps">
|
<slot v-bind="slotProps">
|
||||||
<Input type="number" v-bind="{ ...slotProps.componentField, ...config?.inputProps }" :disabled="disabled" />
|
<Input type="number" v-bind="{ ...slotProps.componentField, ...config?.inputProps }" :disabled="config?.inputProps?.disabled ?? disabled" />
|
||||||
</slot>
|
</slot>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormDescription v-if="config?.description">
|
<FormDescription v-if="config?.description">
|
||||||
|
|
|
||||||
|
|
@ -169,3 +169,20 @@ export function getFromPath<TValue = unknown, TFallback = TValue>(
|
||||||
|
|
||||||
return resolvedValue as TValue | undefined
|
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
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import { FormControl, FormDescription, FormField, FormItem, FormMessage } from '
|
||||||
import { Switch } from '@/lib/registry/new-york/ui/switch'
|
import { Switch } from '@/lib/registry/new-york/ui/switch'
|
||||||
import { computed } from 'vue'
|
import { computed } from 'vue'
|
||||||
import AutoFormLabel from './AutoFormLabel.vue'
|
import AutoFormLabel from './AutoFormLabel.vue'
|
||||||
import { beautifyObjectName } from './utils'
|
import { beautifyObjectName, maybeBooleanishToBoolean } from './utils'
|
||||||
|
|
||||||
const props = defineProps<FieldProps>()
|
const props = defineProps<FieldProps>()
|
||||||
|
|
||||||
|
|
@ -21,7 +21,7 @@ const booleanComponent = computed(() => props.config?.component === 'switch' ? S
|
||||||
<component
|
<component
|
||||||
:is="booleanComponent"
|
:is="booleanComponent"
|
||||||
v-bind="{ ...slotProps.componentField }"
|
v-bind="{ ...slotProps.componentField }"
|
||||||
:disabled="disabled"
|
:disabled="maybeBooleanishToBoolean(config?.inputProps?.disabled) ?? disabled"
|
||||||
:checked="slotProps.componentField.modelValue"
|
:checked="slotProps.componentField.modelValue"
|
||||||
@update:checked="slotProps.componentField['onUpdate:modelValue']"
|
@update:checked="slotProps.componentField['onUpdate:modelValue']"
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import { cn } from '@/lib/utils'
|
||||||
import { DateFormatter, getLocalTimeZone } from '@internationalized/date'
|
import { DateFormatter, getLocalTimeZone } from '@internationalized/date'
|
||||||
import { CalendarIcon } from '@radix-icons/vue'
|
import { CalendarIcon } from '@radix-icons/vue'
|
||||||
import AutoFormLabel from './AutoFormLabel.vue'
|
import AutoFormLabel from './AutoFormLabel.vue'
|
||||||
import { beautifyObjectName } from './utils'
|
import { beautifyObjectName, maybeBooleanishToBoolean } from './utils'
|
||||||
|
|
||||||
defineProps<FieldProps>()
|
defineProps<FieldProps>()
|
||||||
|
|
||||||
|
|
@ -28,7 +28,7 @@ const df = new DateFormatter('en-US', {
|
||||||
<slot v-bind="slotProps">
|
<slot v-bind="slotProps">
|
||||||
<div>
|
<div>
|
||||||
<Popover>
|
<Popover>
|
||||||
<PopoverTrigger as-child :disabled="disabled">
|
<PopoverTrigger as-child :disabled="maybeBooleanishToBoolean(config?.inputProps?.disabled) ?? disabled">
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
:class="cn(
|
:class="cn(
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import { Label } from '@/lib/registry/new-york/ui/label'
|
||||||
import { RadioGroup, RadioGroupItem } from '@/lib/registry/new-york/ui/radio-group'
|
import { RadioGroup, RadioGroupItem } from '@/lib/registry/new-york/ui/radio-group'
|
||||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/lib/registry/new-york/ui/select'
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/lib/registry/new-york/ui/select'
|
||||||
import AutoFormLabel from './AutoFormLabel.vue'
|
import AutoFormLabel from './AutoFormLabel.vue'
|
||||||
import { beautifyObjectName } from './utils'
|
import { beautifyObjectName, maybeBooleanishToBoolean } from './utils'
|
||||||
|
|
||||||
defineProps<FieldProps & {
|
defineProps<FieldProps & {
|
||||||
options?: string[]
|
options?: string[]
|
||||||
|
|
@ -20,14 +20,14 @@ defineProps<FieldProps & {
|
||||||
</AutoFormLabel>
|
</AutoFormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<slot v-bind="slotProps">
|
<slot v-bind="slotProps">
|
||||||
<RadioGroup v-if="config?.component === 'radio'" :disabled="disabled" :orientation="'vertical'" v-bind="{ ...slotProps.componentField }">
|
<RadioGroup v-if="config?.component === 'radio'" :disabled="maybeBooleanishToBoolean(config?.inputProps?.disabled) ?? disabled" :orientation="'vertical'" v-bind="{ ...slotProps.componentField }">
|
||||||
<div v-for="(option, index) in options" :key="option" class="mb-2 flex items-center gap-3 space-y-0">
|
<div v-for="(option, index) in options" :key="option" class="mb-2 flex items-center gap-3 space-y-0">
|
||||||
<RadioGroupItem :id="`${option}-${index}`" :value="option" />
|
<RadioGroupItem :id="`${option}-${index}`" :value="option" />
|
||||||
<Label :for="`${option}-${index}`">{{ beautifyObjectName(option) }}</Label>
|
<Label :for="`${option}-${index}`">{{ beautifyObjectName(option) }}</Label>
|
||||||
</div>
|
</div>
|
||||||
</RadioGroup>
|
</RadioGroup>
|
||||||
|
|
||||||
<Select v-else :disabled="disabled" v-bind="{ ...slotProps.componentField }">
|
<Select v-else :disabled="maybeBooleanishToBoolean(config?.inputProps?.disabled) ?? disabled" v-bind="{ ...slotProps.componentField }">
|
||||||
<SelectTrigger class="w-full">
|
<SelectTrigger class="w-full">
|
||||||
<SelectValue :placeholder="config?.inputProps?.placeholder" />
|
<SelectValue :placeholder="config?.inputProps?.placeholder" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ async function parseFileAsString(file: File | undefined): Promise<string> {
|
||||||
v-if="!inputFile"
|
v-if="!inputFile"
|
||||||
type="file"
|
type="file"
|
||||||
v-bind="{ ...config?.inputProps }"
|
v-bind="{ ...config?.inputProps }"
|
||||||
:disabled="disabled"
|
:disabled="config?.inputProps?.disabled ?? disabled"
|
||||||
@change="async (ev: InputEvent) => {
|
@change="async (ev: InputEvent) => {
|
||||||
const file = (ev.target as HTMLInputElement).files?.[0]
|
const file = (ev.target as HTMLInputElement).files?.[0]
|
||||||
inputFile = file
|
inputFile = file
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ const inputComponent = computed(() => props.config?.component === 'textarea' ? T
|
||||||
:is="inputComponent"
|
:is="inputComponent"
|
||||||
type="text"
|
type="text"
|
||||||
v-bind="{ ...slotProps.componentField, ...config?.inputProps }"
|
v-bind="{ ...slotProps.componentField, ...config?.inputProps }"
|
||||||
:disabled="disabled"
|
:disabled="config?.inputProps?.disabled ?? disabled"
|
||||||
/>
|
/>
|
||||||
</slot>
|
</slot>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ defineProps<FieldProps>()
|
||||||
</AutoFormLabel>
|
</AutoFormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<slot v-bind="slotProps">
|
<slot v-bind="slotProps">
|
||||||
<Input type="number" v-bind="{ ...slotProps.componentField, ...config?.inputProps }" :disabled="disabled" />
|
<Input type="number" v-bind="{ ...slotProps.componentField, ...config?.inputProps }" :disabled="config?.inputProps?.disabled ?? disabled" />
|
||||||
</slot>
|
</slot>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormDescription v-if="config?.description">
|
<FormDescription v-if="config?.description">
|
||||||
|
|
|
||||||
|
|
@ -169,3 +169,20 @@ export function getFromPath<TValue = unknown, TFallback = TValue>(
|
||||||
|
|
||||||
return resolvedValue as TValue | undefined
|
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
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user