@remotion/studio
Version:
APIs for interacting with the Remotion Studio
63 lines (62 loc) • 3.14 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZodDateEditor = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const react_2 = require("react");
const colors_1 = require("../../../helpers/colors");
const layout_1 = require("../../layout");
const RemInput_1 = require("../../NewComposition/RemInput");
const Fieldset_1 = require("./Fieldset");
const SchemaLabel_1 = require("./SchemaLabel");
const zod_schema_type_1 = require("./zod-schema-type");
const ZodFieldValidation_1 = require("./ZodFieldValidation");
const fullWidth = {
width: '100%',
};
const explainer = {
fontFamily: 'sans-serif',
fontSize: 12,
color: colors_1.VERY_LIGHT_TEXT,
};
// This will do 2 things:
// - Make the calendar icon white
// Turn the input popup a dark mode input
const inputStyle = {
colorScheme: 'dark',
};
const formatDate = (date) => {
// Get the year, month, day, hours, minutes, seconds, and milliseconds
const year = date.getFullYear();
const month = date.getMonth() + 1; // Month is zero-indexed, so we add 1
const day = date.getDate();
const hours = date.getHours();
const minutes = date.getMinutes();
const seconds = date.getSeconds();
const milliseconds = date.getMilliseconds();
// Format the date as a string
const formattedDate = `${year}-${month.toString().padStart(2, '0')}-${day
.toString()
.padStart(2, '0')}T${hours.toString().padStart(2, '0')}:${minutes
.toString()
.padStart(2, '0')}:${seconds.toString().padStart(2, '0')}.${milliseconds
.toString()
.padStart(3, '0')}`;
return formattedDate;
};
const ZodDateEditor = ({ jsonPath, value, setValue, schema, onRemove, mayPad }) => {
const onChange = (0, react_2.useCallback)((e) => {
// React does not support e.target.valueAsDate :(
setValue(() => new Date(e.target.value), { shouldSave: false });
}, [setValue]);
const onBlur = (0, react_2.useCallback)(() => {
setValue((v) => v, { 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(RemInput_1.RemotionInput, { value: formatDate(value), type: "datetime-local", status: zodValidation.success ? 'ok' : 'error', placeholder: jsonPath.join('.'), onChange: onChange, onBlur: onBlur, style: inputStyle, rightAlign: false }), jsx_runtime_1.jsx(layout_1.Spacing, { y: 1, block: true }), jsx_runtime_1.jsx("div", { style: explainer, children: "Date is in local format" }), jsx_runtime_1.jsx(ZodFieldValidation_1.ZodFieldValidation, { path: jsonPath, zodValidation: zodValidation })
] })
] }));
};
exports.ZodDateEditor = ZodDateEditor;