@remotion/studio
Version:
APIs for interacting with the Remotion Studio
34 lines (33 loc) • 2.28 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZodNumberEditor = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const react_2 = require("react");
const InputDragger_1 = require("../../NewComposition/InputDragger");
const Fieldset_1 = require("./Fieldset");
const SchemaLabel_1 = require("./SchemaLabel");
const zod_number_constraints_1 = require("./zod-number-constraints");
const zod_schema_type_1 = require("./zod-schema-type");
const ZodFieldValidation_1 = require("./ZodFieldValidation");
const fullWidth = {
width: '100%',
};
const ZodNumberEditor = ({ jsonPath, value, schema, setValue, onRemove, mayPad }) => {
const onNumberChange = (0, react_2.useCallback)((newValue) => {
setValue(() => newValue, { shouldSave: false });
}, [setValue]);
const onNumberChangeEnd = (0, react_2.useCallback)((newValue) => {
setValue(() => newValue, { shouldSave: true });
}, [setValue]);
const onTextChange = (0, react_2.useCallback)((newValue) => {
setValue(() => Number(newValue), { shouldSave: true });
}, [setValue]);
const zodValidation = (0, react_1.useMemo)(() => (0, zod_schema_type_1.zodSafeParse)(schema, value), [schema, value]);
return (jsx_runtime_1.jsxs(Fieldset_1.Fieldset, { shouldPad: mayPad, children: [
jsx_runtime_1.jsx(SchemaLabel_1.SchemaLabel, { handleClick: null, jsonPath: jsonPath, onRemove: onRemove, valid: zodValidation.success, suffix: null }), jsx_runtime_1.jsxs("div", { style: fullWidth, children: [
jsx_runtime_1.jsx(InputDragger_1.InputDragger, { type: 'number', value: value, style: fullWidth, status: zodValidation.success ? 'ok' : 'error', placeholder: jsonPath.join('.'), onTextChange: onTextChange, onValueChange: onNumberChange, onValueChangeEnd: onNumberChangeEnd, min: (0, zod_number_constraints_1.getZodNumberMinimum)(schema), max: (0, zod_number_constraints_1.getZodNumberMaximum)(schema), step: (0, zod_number_constraints_1.getZodNumberStep)(schema), rightAlign: false }), jsx_runtime_1.jsx(ZodFieldValidation_1.ZodFieldValidation, { path: jsonPath, zodValidation: zodValidation })
] })
] }));
};
exports.ZodNumberEditor = ZodNumberEditor;