index.tsx 831 Bytes

import { FormItem, DatePicker } from '@formily/antd-v5';
import { Field } from '@formily/react';
import cx from 'classnames';
import './index.less';
import { FieldProps } from '../../typings';

const DateInput: React.FC<FieldProps> = (props) => {
  const { name, title, validator = [], format, decoratorProps, componentProps } = props;

  return (
    <div className={cx('global_date')}>
      <Field
        {...props}
        name={name}
        title={title}
        decorator={[FormItem, { ...decoratorProps }]}
        component={[
          DatePicker,
          {
            allowClear: true,
            format: format || 'YYYY/MM/DD',
            ...componentProps,
            componenttypename: 'DatePicker',
          },
        ]}
        validator={validator}
      />
    </div>
  );
};

export default DateInput;