-
Notifications
You must be signed in to change notification settings - Fork 611
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1324 from ant-design/5.1.0
bump 5.1.0
- Loading branch information
Showing
142 changed files
with
4,590 additions
and
5,663 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export function isPromise(obj: unknown): obj is Promise<unknown> { | ||
return ( | ||
!!obj && typeof obj === 'object' && typeof (obj as any).then === 'function' | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const assignWith = require('lodash.assignwith') | ||
|
||
export function mergeProps<A, B>(a: A, b: B): B & A | ||
export function mergeProps<A, B, C>(a: A, b: B, c: C): C & B & A | ||
export function mergeProps(...items: any[]) { | ||
function customizer(objValue: any, srcValue: any) { | ||
return srcValue === undefined ? objValue : srcValue | ||
} | ||
|
||
let ret = { ...items[0] } | ||
for (let i = 1; i < items.length; i++) { | ||
ret = assignWith(ret, items[i], customizer) | ||
} | ||
return ret | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,39 @@ | ||
import { DatePickerPropsType } from '../date-picker/PropsType' | ||
import type { ReactNode } from 'react' | ||
import { DatePickerFilter, Precision } from '../date-picker/date-picker-utils' | ||
import { PickerDate } from '../date-picker/util' | ||
import { | ||
PickerValueExtend, | ||
PickerViewPropsType, | ||
} from '../picker-view/PropsType' | ||
|
||
export interface DatePickerProps extends DatePickerPropsType { | ||
onScrollChange?: (newValue: any, vals: any, index: number) => void | ||
triggerTypes?: string | ||
styles?: any | ||
export type RenderLabel = (type: Precision | 'now', data: number) => ReactNode | ||
|
||
export interface DatePickerViewPropsType | ||
extends Pick< | ||
PickerViewPropsType, | ||
| 'style' | ||
| 'itemStyle' | ||
| 'numberOfLines' | ||
| 'renderMaskTop' | ||
| 'renderMaskBottom' | ||
> { | ||
value?: PickerDate | ||
defaultValue?: PickerDate | ||
mode?: Precision | 'date' | ||
minDate?: Date | ||
maxDate?: Date | ||
onChange?: (value: Date, extend?: PickerValueExtend) => void | ||
onValueChange?: (vals: any, index: number) => void | ||
precision?: Precision | ||
renderLabel?: RenderLabel | ||
locale?: { | ||
year?: string | ||
month?: string | ||
day?: string | ||
hour?: string | ||
minute?: string | ||
am?: string | ||
pm?: string | ||
} | ||
filter?: DatePickerFilter | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,102 @@ | ||
import React from 'react' | ||
import RCDatePicker from '../date-picker/datepicker' | ||
import useMergedState from 'rc-util/lib/hooks/useMergedState' | ||
import React, { | ||
FunctionComponent, | ||
memo, | ||
useCallback, | ||
useContext, | ||
useMemo, | ||
} from 'react' | ||
|
||
import { getComponentLocale } from '../_util/getLocale' | ||
import { DatePickerProps } from './PropsType' | ||
import { mergeProps } from '../_util/with-default-props' | ||
import { getValueExtend, usePickerValue } from '../date-picker/columns-extend' | ||
import { generateDatePickerColumns } from '../date-picker/date-picker-utils' | ||
import { LocaleContext } from '../locale-provider' | ||
export default class DatePickerView extends React.Component< | ||
DatePickerProps, | ||
any | ||
> { | ||
static defaultProps = { | ||
mode: 'datetime', | ||
// extra: '请选择', | ||
minuteStep: 1, | ||
use12Hours: false, | ||
} | ||
|
||
static contextType = LocaleContext | ||
|
||
render() { | ||
// tslint:disable-next-line:no-this-assignment | ||
const { props, context } = this | ||
const locale = getComponentLocale(props, context, 'DatePickerView', () => | ||
require('./locale/zh_CN'), | ||
) | ||
import RMCPickerView from '../picker-view/picker-view' | ||
import { PickerViewStyle } from '../picker-view/style' | ||
import { WithThemeStyles } from '../style' | ||
import { DatePickerViewPropsType } from './PropsType' | ||
import useRenderLabel from './useRenderLabel' | ||
|
||
// DatePicker use `defaultDate`, maybe because there are PopupDatePicker inside? @yiminghe | ||
// Here Use `date` instead of `defaultDate`, make it controlled fully. | ||
return ( | ||
<RCDatePicker | ||
{...props} | ||
locale={locale} | ||
date={props.value} | ||
onDateChange={props.onChange} | ||
onValueChange={props.onValueChange} | ||
onScrollChange={props.onScrollChange} | ||
/> | ||
) | ||
} | ||
export interface DatePickerViewProps | ||
extends DatePickerViewPropsType, | ||
WithThemeStyles<PickerViewStyle> {} | ||
|
||
const defaultProps = { | ||
minDate: new Date('2000-1-1'), | ||
maxDate: new Date('2030-1-1'), | ||
mode: 'date', | ||
} | ||
|
||
const DatePickerView: FunctionComponent<DatePickerViewProps> = memo((props) => { | ||
const p = mergeProps(defaultProps, props) | ||
const { | ||
value, | ||
defaultValue, | ||
minDate, | ||
maxDate, | ||
mode, | ||
precision, | ||
renderLabel, | ||
filter, | ||
...restProps | ||
} = p | ||
|
||
const _precision = precision || (mode === 'date' ? 'day' : mode) || 'day' | ||
|
||
const [innerValue, setInnerValue] = useMergedState<Date>(new Date(), { | ||
value: value, | ||
defaultValue: defaultValue, | ||
}) | ||
|
||
const _locale = getComponentLocale( | ||
p, | ||
useContext(LocaleContext), | ||
'DatePickerView', | ||
() => require('./locale/zh_CN'), | ||
) | ||
|
||
const mergedRenderLabel = useRenderLabel(renderLabel, _locale) | ||
|
||
const pickerValue = usePickerValue(innerValue, minDate, maxDate, _precision) | ||
|
||
const columns = useMemo(() => { | ||
return generateDatePickerColumns( | ||
pickerValue, | ||
minDate, | ||
maxDate, | ||
_precision, | ||
mergedRenderLabel, | ||
filter, | ||
false, | ||
) | ||
}, [maxDate, mergedRenderLabel, minDate, _precision, filter, pickerValue]) | ||
|
||
const handleSelect = useCallback( | ||
(val: string, i: number) => { | ||
const pvalue = pickerValue.slice(0) | ||
pvalue[i] = val | ||
const { dateValue, extend } = getValueExtend(columns, pvalue, _precision) | ||
setInnerValue(dateValue) | ||
p.onChange?.(dateValue, { | ||
items: extend, | ||
columns, | ||
}) | ||
p.onValueChange?.(dateValue, i) | ||
}, | ||
[columns, _precision, p, pickerValue, setInnerValue], | ||
) | ||
|
||
return ( | ||
<RMCPickerView | ||
{...restProps} | ||
value={pickerValue} | ||
columns={columns} | ||
handleSelect={handleSelect} | ||
/> | ||
) | ||
}) | ||
|
||
DatePickerView.displayName = 'Picker' | ||
|
||
export default DatePickerView |
Oops, something went wrong.