UNPKG

@rjsf/antd

Version:

Ant Design theme, fields and widgets for react-jsonschema-form

27 lines 1.78 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { ariaDescribedByIds } from '@rjsf/utils'; import { DatePicker } from 'antd'; import dayjs from 'dayjs'; const DATE_PICKER_STYLE = { width: '100%', }; /** The `DateWidget` component uses the `BaseInputTemplate` changing the type to `date` and transforms * the value to undefined when it is falsy during the `onChange` handling. * * @param props - The `WidgetProps` for this component */ export default function DateWidget({ disabled, registry, id, onBlur, onChange, onFocus, placeholder, readonly, value, showTime = false, }) { const { formContext } = registry; const { readonlyAsDisabled = true } = formContext; const handleChange = (nextValue) => onChange(nextValue && (showTime ? nextValue.toISOString() : nextValue.format('YYYY-MM-DD'))); const handleBlur = () => onBlur(id, value); const handleFocus = () => onFocus(id, value); const getPopupContainer = DateWidget.getPopupContainerCallback(); return (_jsx(DatePicker, { disabled: disabled || (readonlyAsDisabled && readonly), getPopupContainer: getPopupContainer, id: id, name: id, onBlur: !readonly ? handleBlur : undefined, onChange: !readonly ? handleChange : undefined, onFocus: !readonly ? handleFocus : undefined, placeholder: placeholder, showTime: showTime, style: DATE_PICKER_STYLE, value: value && dayjs(value), "aria-describedby": ariaDescribedByIds(id) })); } /** Give the playground a place to hook into the `getPopupContainer` callback generation function so that it can be * disabled while in the playground. Since the callback is a simple function, it can be returned by this static * "generator" function. */ DateWidget.getPopupContainerCallback = () => (node) => node.parentNode; //# sourceMappingURL=index.js.map