2022-06-07 08:49:12 +02:00
|
|
|
import { z } from 'zod'
|
|
|
|
import {
|
|
|
|
defaultButtonLabel,
|
2022-06-11 07:27:38 +02:00
|
|
|
InputBlockType,
|
2022-06-07 08:49:12 +02:00
|
|
|
optionBaseSchema,
|
2022-06-11 07:27:38 +02:00
|
|
|
blockBaseSchema,
|
2022-06-07 08:49:12 +02:00
|
|
|
} from '../shared'
|
|
|
|
import { textInputOptionsBaseSchema } from './text'
|
|
|
|
|
|
|
|
export const numberInputOptionsSchema = optionBaseSchema
|
|
|
|
.and(textInputOptionsBaseSchema)
|
|
|
|
.and(
|
|
|
|
z.object({
|
|
|
|
min: z.number().optional(),
|
|
|
|
max: z.number().optional(),
|
|
|
|
step: z.number().optional(),
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
2022-06-11 07:27:38 +02:00
|
|
|
export const numberInputSchema = blockBaseSchema.and(
|
2022-06-07 08:49:12 +02:00
|
|
|
z.object({
|
2022-06-11 07:27:38 +02:00
|
|
|
type: z.enum([InputBlockType.NUMBER]),
|
2022-06-07 08:49:12 +02:00
|
|
|
options: numberInputOptionsSchema,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
|
|
|
export const defaultNumberInputOptions: NumberInputOptions = {
|
|
|
|
labels: { button: defaultButtonLabel, placeholder: 'Type a number...' },
|
|
|
|
}
|
|
|
|
|
2022-06-11 07:27:38 +02:00
|
|
|
export type NumberInputBlock = z.infer<typeof numberInputSchema>
|
2022-06-07 08:49:12 +02:00
|
|
|
export type NumberInputOptions = z.infer<typeof numberInputOptionsSchema>
|