mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-11-30 02:59:04 +08:00
Merge branch 'master' into chore/mergem
This commit is contained in:
commit
e3a2c38e67
@ -31,8 +31,6 @@ export interface ScrollNumberState {
|
||||
count?: string | number | null;
|
||||
}
|
||||
|
||||
let lastCount: any;
|
||||
|
||||
class ScrollNumber extends Component<ScrollNumberProps, ScrollNumberState> {
|
||||
static defaultProps = {
|
||||
count: null,
|
||||
@ -44,12 +42,13 @@ class ScrollNumber extends Component<ScrollNumberProps, ScrollNumberState> {
|
||||
if (nextState.count === nextProps.count) {
|
||||
return null;
|
||||
}
|
||||
lastCount = nextState.count;
|
||||
return { animateStarted: true };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
lastCount?: string | number | null;
|
||||
|
||||
constructor(props: ScrollNumberProps) {
|
||||
super(props);
|
||||
this.state = {
|
||||
@ -63,9 +62,9 @@ class ScrollNumber extends Component<ScrollNumberProps, ScrollNumberState> {
|
||||
return 10 + num;
|
||||
}
|
||||
const currentDigit = getNumberArray(this.state.count)[i];
|
||||
const lastDigit = getNumberArray(lastCount)[i];
|
||||
const lastDigit = getNumberArray(this.lastCount)[i];
|
||||
// 同方向则在同一侧切换数字
|
||||
if (this.state.count! > lastCount) {
|
||||
if (Number(this.state.count) > Number(this.lastCount)) {
|
||||
if (currentDigit >= lastDigit) {
|
||||
return 10 + num;
|
||||
}
|
||||
@ -77,10 +76,11 @@ class ScrollNumber extends Component<ScrollNumberProps, ScrollNumberState> {
|
||||
return num;
|
||||
}
|
||||
|
||||
componentDidUpdate() {
|
||||
componentDidUpdate(_: any, prevState: ScrollNumberState) {
|
||||
this.lastCount = prevState.count;
|
||||
if (this.state.animateStarted) {
|
||||
this.setState({ animateStarted: false, count: this.props.count }, () => {
|
||||
const onAnimated = this.props.onAnimated;
|
||||
const { onAnimated } = this.props;
|
||||
if (onAnimated) {
|
||||
onAnimated();
|
||||
}
|
||||
@ -104,7 +104,7 @@ class ScrollNumber extends Component<ScrollNumberProps, ScrollNumberState> {
|
||||
renderCurrentNumber(prefixCls: string, num: number, i: number) {
|
||||
const position = this.getPositionByNum(num, i);
|
||||
const removeTransition =
|
||||
this.state.animateStarted || getNumberArray(lastCount)[i] === undefined;
|
||||
this.state.animateStarted || getNumberArray(this.lastCount)[i] === undefined;
|
||||
return createElement(
|
||||
'span',
|
||||
{
|
||||
|
@ -134,9 +134,9 @@ describe('Calendar', () => {
|
||||
const onPanelChangeStub = jest.fn();
|
||||
const wrapper = mount(<Calendar mode={yearMode} onPanelChange={onPanelChangeStub} />);
|
||||
expect(wrapper.state().mode).toEqual(yearMode);
|
||||
wrapper.instance().setType('date');
|
||||
wrapper.setProps({ mode: monthMode });
|
||||
expect(wrapper.state().mode).toEqual(monthMode);
|
||||
expect(onPanelChangeStub).toHaveBeenCalledTimes(1);
|
||||
expect(onPanelChangeStub).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
it('Calendar should support locale', () => {
|
||||
|
@ -76,10 +76,14 @@ class Calendar extends React.Component<CalendarProps, CalendarState> {
|
||||
};
|
||||
|
||||
static getDerivedStateFromProps(nextProps: CalendarProps) {
|
||||
const newState = {} as CalendarState;
|
||||
if ('value' in nextProps) {
|
||||
return { value: nextProps.value! };
|
||||
newState.value = nextProps.value!;
|
||||
}
|
||||
return null;
|
||||
if ('mode' in nextProps) {
|
||||
newState.mode = nextProps.mode;
|
||||
}
|
||||
return Object.keys(newState).length > 0 ? newState : null;
|
||||
}
|
||||
|
||||
prefixCls?: string;
|
||||
@ -100,14 +104,6 @@ class Calendar extends React.Component<CalendarProps, CalendarState> {
|
||||
};
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps: CalendarProps) {
|
||||
if ('mode' in this.props && this.props.mode !== prevProps.mode) {
|
||||
this.setState({
|
||||
mode: this.props.mode!,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
monthCellRender = (value: moment.Moment) => {
|
||||
const { monthCellRender = noop as Function } = this.props;
|
||||
const { prefixCls } = this;
|
||||
|
@ -105,7 +105,7 @@ input[type='checkbox'] {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
label {
|
||||
> label {
|
||||
color: @label-color;
|
||||
|
||||
&::after {
|
||||
|
@ -136,43 +136,7 @@ class Transfer extends React.Component<TransferProps, any> {
|
||||
};
|
||||
}
|
||||
|
||||
componentDidUpdate = (prevProps: TransferProps, prevState: any) => {
|
||||
const { sourceSelectedKeys, targetSelectedKeys } = prevState;
|
||||
if (
|
||||
prevProps.targetKeys !== this.props.targetKeys ||
|
||||
prevProps.dataSource !== this.props.dataSource
|
||||
) {
|
||||
// clear cached separated dataSource
|
||||
this.separatedDataSource = null;
|
||||
|
||||
if (!prevProps.selectedKeys) {
|
||||
// clear key no longer existed
|
||||
// clear checkedKeys according to targetKeys
|
||||
const { dataSource, targetKeys = [] } = prevProps;
|
||||
|
||||
const newSourceSelectedKeys: String[] = [];
|
||||
const newTargetSelectedKeys: String[] = [];
|
||||
dataSource.forEach(({ key }: { key: string }) => {
|
||||
if (sourceSelectedKeys.includes(key) && !targetKeys.includes(key)) {
|
||||
newSourceSelectedKeys.push(key);
|
||||
}
|
||||
if (targetSelectedKeys.includes(key) && targetKeys.includes(key)) {
|
||||
newTargetSelectedKeys.push(key);
|
||||
}
|
||||
});
|
||||
this.setState({
|
||||
sourceSelectedKeys: newSourceSelectedKeys,
|
||||
targetSelectedKeys: newTargetSelectedKeys,
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
separateDataSource(props: TransferProps) {
|
||||
if (this.separatedDataSource) {
|
||||
return this.separatedDataSource;
|
||||
}
|
||||
|
||||
const { dataSource, rowKey, targetKeys = [] } = props;
|
||||
|
||||
const leftDataSource: TransferItem[] = [];
|
||||
@ -192,12 +156,10 @@ class Transfer extends React.Component<TransferProps, any> {
|
||||
}
|
||||
});
|
||||
|
||||
this.separatedDataSource = {
|
||||
return {
|
||||
leftDataSource,
|
||||
rightDataSource,
|
||||
};
|
||||
|
||||
return this.separatedDataSource;
|
||||
}
|
||||
|
||||
moveTo = (direction: TransferDirection) => {
|
||||
|
Loading…
Reference in New Issue
Block a user