default value
This commit is contained in:
@@ -8,6 +8,7 @@ import type { CollectionId } from '../collections'
|
||||
const toggleControlSchema = z.object({
|
||||
kind: z.literal('toggle'),
|
||||
label: z.string().optional(),
|
||||
default: z.boolean().optional(),
|
||||
})
|
||||
|
||||
const sliderControlSchema = z.object({
|
||||
@@ -18,6 +19,7 @@ const sliderControlSchema = z.object({
|
||||
step: z.number().default(1),
|
||||
unit: z.string().optional(),
|
||||
displayMode: z.enum(['slider', 'stepper', 'dial']).default('slider'),
|
||||
default: z.number().optional(),
|
||||
})
|
||||
|
||||
const temperatureControlSchema = z.object({
|
||||
@@ -26,6 +28,7 @@ const temperatureControlSchema = z.object({
|
||||
min: z.number().default(16),
|
||||
max: z.number().default(30),
|
||||
unit: z.enum(['C', 'F']).default('C'),
|
||||
default: z.number().optional(),
|
||||
})
|
||||
|
||||
const controlSchema = z.discriminatedUnion('kind', [
|
||||
|
||||
@@ -30,11 +30,11 @@ const defaultControlValue = (interactive: Interactive, index: number): ControlVa
|
||||
if (!control) return false
|
||||
switch (control.kind) {
|
||||
case 'toggle':
|
||||
return false
|
||||
return control.default ?? false
|
||||
case 'slider':
|
||||
return control.min
|
||||
return control.default ?? control.min
|
||||
case 'temperature':
|
||||
return control.min
|
||||
return control.default ?? control.min
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user