2022-06-12 17:34:33 +02:00
|
|
|
import { z } from 'zod'
|
2023-01-25 11:27:47 +01:00
|
|
|
import { optionBaseSchema, blockBaseSchema } from '../baseSchemas'
|
|
|
|
import { InputBlockType } from './enums'
|
2022-06-12 17:34:33 +02:00
|
|
|
|
|
|
|
export const fileInputOptionsSchema = optionBaseSchema.and(
|
|
|
|
z.object({
|
2022-06-25 09:24:47 +02:00
|
|
|
isRequired: z.boolean().optional(),
|
2022-06-12 17:34:33 +02:00
|
|
|
isMultipleAllowed: z.boolean(),
|
|
|
|
labels: z.object({
|
|
|
|
placeholder: z.string(),
|
|
|
|
button: z.string(),
|
2023-01-20 08:12:59 +01:00
|
|
|
clear: z.string().optional(),
|
|
|
|
skip: z.string().optional(),
|
2022-06-12 17:34:33 +02:00
|
|
|
}),
|
2022-06-21 16:53:45 +02:00
|
|
|
sizeLimit: z.number().optional(),
|
2022-06-12 17:34:33 +02:00
|
|
|
})
|
|
|
|
)
|
|
|
|
|
|
|
|
export const fileInputStepSchema = blockBaseSchema.and(
|
|
|
|
z.object({
|
|
|
|
type: z.literal(InputBlockType.FILE),
|
|
|
|
options: fileInputOptionsSchema,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
2023-02-20 17:40:51 +01:00
|
|
|
export const defaultFileInputOptions = {
|
2022-06-25 09:24:47 +02:00
|
|
|
isRequired: true,
|
2022-06-12 17:34:33 +02:00
|
|
|
isMultipleAllowed: false,
|
|
|
|
labels: {
|
|
|
|
placeholder: `<strong>
|
|
|
|
Click to upload
|
|
|
|
</strong> or drag and drop<br>
|
|
|
|
(size limit: 10MB)`,
|
|
|
|
button: 'Upload',
|
2023-01-20 08:12:59 +01:00
|
|
|
clear: 'Clear',
|
|
|
|
skip: 'Skip',
|
2022-06-12 17:34:33 +02:00
|
|
|
},
|
2023-02-20 17:40:51 +01:00
|
|
|
} satisfies FileInputOptions
|
2022-06-12 17:34:33 +02:00
|
|
|
|
|
|
|
export type FileInputBlock = z.infer<typeof fileInputStepSchema>
|
|
|
|
export type FileInputOptions = z.infer<typeof fileInputOptionsSchema>
|