asb_cloud_front/src/components/Table/DatePickerWrapper.tsx

27 lines
749 B
TypeScript
Raw Normal View History

import { memo } from 'react'
import { DatePicker } from 'antd'
import { PickerDateProps } from 'antd/lib/date-picker/generatePicker'
import moment, { Moment } from 'moment'
import { defaultFormat } from '@utils'
export type DatePickerWrapperProps = PickerDateProps<Moment> & {
value?: Moment,
onChange?: (date: Moment | null) => any
isUTC?: boolean
}
export const DatePickerWrapper = memo<DatePickerWrapperProps>(({ value, onChange, isUTC, ...other }) => (
<DatePicker
showTime
allowClear={false}
format={defaultFormat}
defaultValue={moment()}
onChange={(date) => onChange?.(date)}
value={value && (isUTC ? moment.utc(value).local() : moment(value))}
{...other}
/>
))
export default DatePickerWrapper