@remotion/studio
Version:
APIs for interacting with the Remotion Studio
63 lines (62 loc) • 3.47 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZodDateEditor = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const colors_1 = require("../../../helpers/colors");
const RemInput_1 = require("../../NewComposition/RemInput");
const layout_1 = require("../../layout");
const Fieldset_1 = require("./Fieldset");
const SchemaLabel_1 = require("./SchemaLabel");
const ZodFieldValidation_1 = require("./ZodFieldValidation");
const local_state_1 = require("./local-state");
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, showSaveButton, defaultValue, schema, onSave, onRemove, saving, saveDisabledByParent, mayPad, }) => {
const { localValue, onChange: setLocalValue, reset, } = (0, local_state_1.useLocalState)({
schema,
setValue,
unsavedValue: value,
savedValue: defaultValue,
});
const onChange = (0, react_1.useCallback)((e) => {
// React does not support e.target.valueAsDate :(
setLocalValue(() => new Date(e.target.value), false, false);
}, [setLocalValue]);
const save = (0, react_1.useCallback)(() => {
onSave(() => value, false, false);
}, [onSave, value]);
return ((0, jsx_runtime_1.jsxs)(Fieldset_1.Fieldset, { shouldPad: mayPad, success: localValue.zodValidation.success, children: [(0, jsx_runtime_1.jsx)(SchemaLabel_1.SchemaLabel, { handleClick: null, isDefaultValue: localValue.value.getTime() === defaultValue.getTime(), jsonPath: jsonPath, onReset: reset, onSave: save, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving, valid: localValue.zodValidation.success, saveDisabledByParent: saveDisabledByParent, suffix: null }), (0, jsx_runtime_1.jsxs)("div", { style: fullWidth, children: [(0, jsx_runtime_1.jsx)(RemInput_1.RemotionInput, { value: formatDate(localValue.value), type: "datetime-local", status: localValue.zodValidation.success ? 'ok' : 'error', placeholder: jsonPath.join('.'), onChange: onChange, style: inputStyle, rightAlign: false }), (0, jsx_runtime_1.jsx)(layout_1.Spacing, { y: 1, block: true }), (0, jsx_runtime_1.jsx)("div", { style: explainer, children: "Date is in local format" }), (0, jsx_runtime_1.jsx)(ZodFieldValidation_1.ZodFieldValidation, { path: jsonPath, localValue: localValue })] })] }));
};
exports.ZodDateEditor = ZodDateEditor;