forked from ddrilling/asb_cloud_front
Добавлен компонент для обработки диапозона дат
This commit is contained in:
parent
b40ad4921e
commit
45418da791
34
src/components/Table/DateRangeWrapper.tsx
Normal file
34
src/components/Table/DateRangeWrapper.tsx
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
import { memo } from 'react'
|
||||||
|
import { DatePicker, } from 'antd'
|
||||||
|
import moment, { Moment } from 'moment'
|
||||||
|
import { RangeValue } from 'rc-picker/lib/interface'
|
||||||
|
import { RangePickerSharedProps } from 'rc-picker/lib/RangePicker'
|
||||||
|
|
||||||
|
import { defaultFormat } from '@utils'
|
||||||
|
|
||||||
|
const { RangePicker } = DatePicker
|
||||||
|
|
||||||
|
export type DateRangeWrapperProps = RangePickerSharedProps<Moment> & {
|
||||||
|
value: RangeValue<Moment>,
|
||||||
|
onChange: (date: RangeValue<Moment>) => any
|
||||||
|
isUTC?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
const normalizeDates = (value: RangeValue<Moment>, isUTC?: boolean): RangeValue<Moment> => value && [
|
||||||
|
value[0] ? (isUTC ? moment.utc(value[0]).local() : moment(value[0])) : null,
|
||||||
|
value[1] ? (isUTC ? moment.utc(value[1]).local() : moment(value[1])) : null,
|
||||||
|
]
|
||||||
|
|
||||||
|
export const DateRangeWrapper = memo<DateRangeWrapperProps>(({ value, onChange, isUTC, ...other }) => (
|
||||||
|
<RangePicker
|
||||||
|
showTime
|
||||||
|
allowClear={false}
|
||||||
|
format={defaultFormat}
|
||||||
|
defaultValue={[moment().subtract(60000), moment()]}
|
||||||
|
onChange={(date) => onChange(date)}
|
||||||
|
value={normalizeDates(value)}
|
||||||
|
{...other}
|
||||||
|
/>
|
||||||
|
))
|
||||||
|
|
||||||
|
export default DateRangeWrapper
|
Loading…
Reference in New Issue
Block a user