UNPKG

@aokiapp/rjsf-mantine-theme

Version:

Mantine theme, fields and widgets for react-jsonschema-form

72 lines (69 loc) 1.93 kB
import { jsx } from 'react/jsx-runtime'; import { getUiOptions, labelValue, ariaDescribedByIds } from '@rjsf/utils'; import { useCallback } from 'react'; import { DatePickerInput } from '@mantine/dates'; import { createErrors } from '../utils/createErrors.mjs'; function MantineDateWidget(props) { const { id, placeholder, label, hideLabel, value, required, readonly, disabled, onChange, onChangeOverride, autofocus, rawErrors, uiSchema, hideError, schema } = props; const options = getUiOptions(uiSchema); const inputValue = value ? fromRawDateStrToUtcTime(value) : null; const _onChange = useCallback( (value2) => onChange(value2 ? fromUtcTimeToRawDateStr(value2) : void 0), [onChange] ); const description = options.description || schema.description; return /* @__PURE__ */ jsx( DatePickerInput, { value: inputValue, onChange: onChangeOverride || _onChange, id, placeholder, label: labelValue(label, hideLabel, void 0), required, clearable: !required, disabled: disabled || readonly, autoFocus: autofocus, error: createErrors(rawErrors, hideError), "aria-describedby": ariaDescribedByIds(id), ...options.props, className: "armt-widget-date-mt", description }, id ); } function fromUtcTimeToRawDateStr(value) { if (value === null) { return null; } const date = new Date(value); date.setMinutes(date.getMinutes() - (/* @__PURE__ */ new Date()).getTimezoneOffset()); return date.toISOString().split("T")[0]; } function fromRawDateStrToUtcTime(value) { if (value === null) { return null; } const date = new Date(value); date.setMinutes(date.getMinutes() + (/* @__PURE__ */ new Date()).getTimezoneOffset()); return date; } export { MantineDateWidget as default }; //# sourceMappingURL=MantineDateWidget.mjs.map