UNPKG

@remotion/studio

Version:

APIs for interacting with the Remotion Studio

46 lines (45 loc) 2.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ZodEnumEditor = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = require("react"); const react_2 = require("react"); const Checkmark_1 = require("../../../icons/Checkmark"); const ComboBox_1 = require("../../NewComposition/ComboBox"); const Fieldset_1 = require("./Fieldset"); const SchemaLabel_1 = require("./SchemaLabel"); const zod_schema_type_1 = require("./zod-schema-type"); const zod_schema_type_2 = require("./zod-schema-type"); const ZodFieldValidation_1 = require("./ZodFieldValidation"); const container = { width: '100%', }; const ZodEnumEditor = ({ schema, jsonPath, setValue, value, onRemove }) => { const onChange = (0, react_2.useCallback)((updater, { shouldSave }) => { setValue(updater, { shouldSave }); }, [setValue]); const enumValues = (0, zod_schema_type_2.getEnumValues)(schema); const isRoot = jsonPath.length === 0; const comboBoxValues = (0, react_1.useMemo)(() => { return enumValues.map((option) => { return { value: option, label: option, id: option, keyHint: null, leftItem: option === value ? jsx_runtime_1.jsx(Checkmark_1.Checkmark, {}) : null, onClick: (id) => { onChange(() => id, { shouldSave: true }); }, quickSwitcherLabel: null, subMenu: null, type: 'item', }; }); }, [enumValues, onChange, value]); 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: true, children: [ jsx_runtime_1.jsx(SchemaLabel_1.SchemaLabel, { handleClick: null, jsonPath: jsonPath, onRemove: onRemove, valid: zodValidation.success, suffix: null }), jsx_runtime_1.jsx("div", { style: isRoot ? undefined : container, children: jsx_runtime_1.jsx(ComboBox_1.Combobox, { values: comboBoxValues, selectedId: value, title: value }) }), jsx_runtime_1.jsx(ZodFieldValidation_1.ZodFieldValidation, { path: jsonPath, zodValidation: zodValidation }) ] })); }; exports.ZodEnumEditor = ZodEnumEditor;