diff --git a/components/avatar/__tests__/__snapshots__/demo.test.js.snap b/components/avatar/__tests__/__snapshots__/demo.test.js.snap index cb854d6d77..2a3d384068 100644 --- a/components/avatar/__tests__/__snapshots__/demo.test.js.snap +++ b/components/avatar/__tests__/__snapshots__/demo.test.js.snap @@ -79,6 +79,30 @@ exports[`renders ./components/avatar/demo/basic.md correctly 1`] = ` `; +exports[`renders ./components/avatar/demo/dynamic.md correctly 1`] = ` +
+ + + U + + + +
+`; + exports[`renders ./components/avatar/demo/type.md correctly 1`] = `
{ + const index = UserList.indexOf(this.state.user); + this.setState({ + user: index < UserList.length - 1 ? UserList[index + 1] : UserList[0], + color: index < colorList.length - 1 ? colorList[index + 1] : colorList[0], + }); + } + render() { + return ( +
+ {this.state.user} + +
+ ); + } +} + +ReactDOM.render( +, mountNode); +```` diff --git a/components/avatar/index.tsx b/components/avatar/index.tsx index 2068216c49..4320b0539c 100644 --- a/components/avatar/index.tsx +++ b/components/avatar/index.tsx @@ -24,9 +24,8 @@ export default class Avatar extends React.Component { shape: 'circle', size: 'default', }; - refs: { - avatarChildren: HTMLElement; - }; + + private avatarChildren: any; constructor(props) { super(props); @@ -36,7 +35,18 @@ export default class Avatar extends React.Component { } componentDidMount() { - const childrenNode = this.refs.avatarChildren; + this.setScale(); + } + + componentDidUpdate(prevProps, prevState) { + if (prevProps.children !== this.props.children + || (prevState.scale !== this.state.scale && this.state.scale === 1)) { + this.setScale(); + } + } + + setScale = () => { + const childrenNode = this.avatarChildren; if (childrenNode) { const childrenWidth = childrenNode.offsetWidth; const avatarWidth = ReactDOM.findDOMNode(this).getBoundingClientRect().width; @@ -45,6 +55,10 @@ export default class Avatar extends React.Component { this.setState({ scale: (avatarWidth - 8) / childrenWidth, }); + } else { + this.setState({ + scale: 1, + }); } } } @@ -54,21 +68,12 @@ export default class Avatar extends React.Component { prefixCls, shape, size, src, icon, className, ...others, } = this.props; - let sizeCls = ''; - switch (size) { - case 'large': - sizeCls = 'lg'; - break; - case 'small': - sizeCls = 'sm'; - break; - default: - sizeCls = ''; - break; - } + const sizeCls = classNames({ + [`${prefixCls}-lg`]: size === 'large', + [`${prefixCls}-sm`]: size === 'small', + }); - const classString = classNames(prefixCls, className, { - [`${prefixCls}-${sizeCls}`]: sizeCls, + const classString = classNames(prefixCls, className, sizeCls, { [`${prefixCls}-${shape}`]: shape, [`${prefixCls}-image`]: src, [`${prefixCls}-icon`]: icon, @@ -80,17 +85,30 @@ export default class Avatar extends React.Component { } else if (icon) { children = ; } else { - const childrenNode = this.refs.avatarChildren; - if (childrenNode && this.state.scale !== 1) { + const childrenNode = this.avatarChildren; + if (childrenNode || this.state.scale !== 1) { const childrenStyle: React.CSSProperties = { + msTransform: `scale(${this.state.scale})`, + WebkitTransform: `scale(${this.state.scale})`, transform: `scale(${this.state.scale})`, position: 'absolute', display: 'inline-block', - left: `calc(50% - ${childrenNode.offsetWidth / 2}px)`, + left: `calc(50% - ${Math.round(childrenNode.offsetWidth / 2)}px)`, }; - children = {children}; + children = this.avatarChildren = span} + style={childrenStyle} + > + {children} + ; } else { - children = {children}; + children = this.avatarChildren = span} + > + {children} + ; } } return ( diff --git a/components/form/__tests__/__snapshots__/demo.test.js.snap b/components/form/__tests__/__snapshots__/demo.test.js.snap index d0c4ffbc15..c759bfb5f1 100644 --- a/components/form/__tests__/__snapshots__/demo.test.js.snap +++ b/components/form/__tests__/__snapshots__/demo.test.js.snap @@ -2268,13 +2268,9 @@ exports[`renders ./components/form/demo/validate-other.md correctly 1`] = ` />
  • @@ -81,7 +79,6 @@ exports[`renders ./components/locale-provider/demo/all.md correctly 1`] = `
  • @@ -90,7 +87,6 @@ exports[`renders ./components/locale-provider/demo/all.md correctly 1`] = `
  • @@ -99,7 +95,6 @@ exports[`renders ./components/locale-provider/demo/all.md correctly 1`] = `
  • @@ -108,7 +103,6 @@ exports[`renders ./components/locale-provider/demo/all.md correctly 1`] = `
  • @@ -118,7 +112,6 @@ exports[`renders ./components/locale-provider/demo/all.md correctly 1`] = `
  • @@ -1548,14 +1541,12 @@ exports[`renders ./components/locale-provider/demo/basic.md correctly 1`] = `
  • @@ -1564,7 +1555,6 @@ exports[`renders ./components/locale-provider/demo/basic.md correctly 1`] = `
  • @@ -1573,7 +1563,6 @@ exports[`renders ./components/locale-provider/demo/basic.md correctly 1`] = `
  • @@ -1582,7 +1571,6 @@ exports[`renders ./components/locale-provider/demo/basic.md correctly 1`] = `
  • @@ -1591,7 +1579,6 @@ exports[`renders ./components/locale-provider/demo/basic.md correctly 1`] = `
  • @@ -1601,7 +1588,6 @@ exports[`renders ./components/locale-provider/demo/basic.md correctly 1`] = `
  • diff --git a/components/pagination/__tests__/__snapshots__/demo.test.js.snap b/components/pagination/__tests__/__snapshots__/demo.test.js.snap index 286eb15aea..74882c2354 100644 --- a/components/pagination/__tests__/__snapshots__/demo.test.js.snap +++ b/components/pagination/__tests__/__snapshots__/demo.test.js.snap @@ -8,14 +8,12 @@ exports[`renders ./components/pagination/demo/basic.md correctly 1`] = `
  • @@ -24,7 +22,6 @@ exports[`renders ./components/pagination/demo/basic.md correctly 1`] = `
  • @@ -33,7 +30,6 @@ exports[`renders ./components/pagination/demo/basic.md correctly 1`] = `
  • @@ -42,7 +38,6 @@ exports[`renders ./components/pagination/demo/basic.md correctly 1`] = `
  • @@ -51,7 +46,6 @@ exports[`renders ./components/pagination/demo/basic.md correctly 1`] = `
  • @@ -61,7 +55,6 @@ exports[`renders ./components/pagination/demo/basic.md correctly 1`] = `
  • @@ -77,14 +70,12 @@ exports[`renders ./components/pagination/demo/changer.md correctly 1`] = `
  • @@ -93,7 +84,6 @@ exports[`renders ./components/pagination/demo/changer.md correctly 1`] = `
  • @@ -102,7 +92,6 @@ exports[`renders ./components/pagination/demo/changer.md correctly 1`] = `
  • @@ -111,7 +100,6 @@ exports[`renders ./components/pagination/demo/changer.md correctly 1`] = `
  • @@ -120,7 +108,6 @@ exports[`renders ./components/pagination/demo/changer.md correctly 1`] = `
  • @@ -129,14 +116,12 @@ exports[`renders ./components/pagination/demo/changer.md correctly 1`] = `
  • @@ -146,7 +131,6 @@ exports[`renders ./components/pagination/demo/changer.md correctly 1`] = `
  • @@ -198,14 +182,12 @@ exports[`renders ./components/pagination/demo/controlled.md correctly 1`] = `
  • @@ -214,7 +196,6 @@ exports[`renders ./components/pagination/demo/controlled.md correctly 1`] = `
  • @@ -223,7 +204,6 @@ exports[`renders ./components/pagination/demo/controlled.md correctly 1`] = `
  • @@ -232,7 +212,6 @@ exports[`renders ./components/pagination/demo/controlled.md correctly 1`] = `
  • @@ -241,7 +220,6 @@ exports[`renders ./components/pagination/demo/controlled.md correctly 1`] = `
  • @@ -251,7 +229,6 @@ exports[`renders ./components/pagination/demo/controlled.md correctly 1`] = `
  • @@ -267,14 +244,12 @@ exports[`renders ./components/pagination/demo/jump.md correctly 1`] = `
  • @@ -283,7 +258,6 @@ exports[`renders ./components/pagination/demo/jump.md correctly 1`] = `
  • @@ -292,7 +266,6 @@ exports[`renders ./components/pagination/demo/jump.md correctly 1`] = `
  • @@ -301,7 +274,6 @@ exports[`renders ./components/pagination/demo/jump.md correctly 1`] = `
  • @@ -310,7 +282,6 @@ exports[`renders ./components/pagination/demo/jump.md correctly 1`] = `
  • @@ -319,14 +290,12 @@ exports[`renders ./components/pagination/demo/jump.md correctly 1`] = `
  • @@ -336,7 +305,6 @@ exports[`renders ./components/pagination/demo/jump.md correctly 1`] = `
  • @@ -367,14 +335,12 @@ exports[`renders ./components/pagination/demo/mini.md correctly 1`] = `
  • @@ -383,7 +349,6 @@ exports[`renders ./components/pagination/demo/mini.md correctly 1`] = `
  • @@ -392,7 +357,6 @@ exports[`renders ./components/pagination/demo/mini.md correctly 1`] = `
  • @@ -401,7 +365,6 @@ exports[`renders ./components/pagination/demo/mini.md correctly 1`] = `
  • @@ -410,7 +373,6 @@ exports[`renders ./components/pagination/demo/mini.md correctly 1`] = `
  • @@ -420,7 +382,6 @@ exports[`renders ./components/pagination/demo/mini.md correctly 1`] = `
  • @@ -433,14 +394,12 @@ exports[`renders ./components/pagination/demo/mini.md correctly 1`] = `
  • @@ -449,7 +408,6 @@ exports[`renders ./components/pagination/demo/mini.md correctly 1`] = `
  • @@ -458,7 +416,6 @@ exports[`renders ./components/pagination/demo/mini.md correctly 1`] = `
  • @@ -467,7 +424,6 @@ exports[`renders ./components/pagination/demo/mini.md correctly 1`] = `
  • @@ -476,7 +432,6 @@ exports[`renders ./components/pagination/demo/mini.md correctly 1`] = `
  • @@ -486,7 +441,6 @@ exports[`renders ./components/pagination/demo/mini.md correctly 1`] = `
  • @@ -550,14 +504,12 @@ exports[`renders ./components/pagination/demo/mini.md correctly 1`] = `
  • @@ -566,7 +518,6 @@ exports[`renders ./components/pagination/demo/mini.md correctly 1`] = `
  • @@ -575,7 +526,6 @@ exports[`renders ./components/pagination/demo/mini.md correctly 1`] = `
  • @@ -584,7 +534,6 @@ exports[`renders ./components/pagination/demo/mini.md correctly 1`] = `
  • @@ -593,7 +542,6 @@ exports[`renders ./components/pagination/demo/mini.md correctly 1`] = `
  • @@ -603,7 +551,6 @@ exports[`renders ./components/pagination/demo/mini.md correctly 1`] = `
  • @@ -620,14 +567,12 @@ exports[`renders ./components/pagination/demo/more.md correctly 1`] = `
  • @@ -636,14 +581,12 @@ exports[`renders ./components/pagination/demo/more.md correctly 1`] = `
  • @@ -652,7 +595,6 @@ exports[`renders ./components/pagination/demo/more.md correctly 1`] = `
  • @@ -661,7 +603,6 @@ exports[`renders ./components/pagination/demo/more.md correctly 1`] = `
  • @@ -670,7 +611,6 @@ exports[`renders ./components/pagination/demo/more.md correctly 1`] = `
  • @@ -679,7 +619,6 @@ exports[`renders ./components/pagination/demo/more.md correctly 1`] = `
  • @@ -688,14 +627,12 @@ exports[`renders ./components/pagination/demo/more.md correctly 1`] = `
  • @@ -705,7 +642,6 @@ exports[`renders ./components/pagination/demo/more.md correctly 1`] = `
  • @@ -720,7 +656,6 @@ exports[`renders ./components/pagination/demo/simple.md correctly 1`] = `
  • @@ -730,7 +665,6 @@ exports[`renders ./components/pagination/demo/simple.md correctly 1`] = ` title="2/5" > @@ -744,7 +678,6 @@ exports[`renders ./components/pagination/demo/simple.md correctly 1`] = `
  • @@ -766,14 +699,12 @@ exports[`renders ./components/pagination/demo/total.md correctly 1`] = `
  • @@ -782,7 +713,6 @@ exports[`renders ./components/pagination/demo/total.md correctly 1`] = `
  • @@ -791,7 +721,6 @@ exports[`renders ./components/pagination/demo/total.md correctly 1`] = `
  • @@ -800,7 +729,6 @@ exports[`renders ./components/pagination/demo/total.md correctly 1`] = `
  • @@ -809,7 +737,6 @@ exports[`renders ./components/pagination/demo/total.md correctly 1`] = `
  • @@ -819,7 +746,6 @@ exports[`renders ./components/pagination/demo/total.md correctly 1`] = `
  • @@ -838,14 +764,12 @@ exports[`renders ./components/pagination/demo/total.md correctly 1`] = `
  • @@ -854,7 +778,6 @@ exports[`renders ./components/pagination/demo/total.md correctly 1`] = `
  • @@ -863,7 +786,6 @@ exports[`renders ./components/pagination/demo/total.md correctly 1`] = `
  • @@ -872,7 +794,6 @@ exports[`renders ./components/pagination/demo/total.md correctly 1`] = `
  • @@ -881,7 +802,6 @@ exports[`renders ./components/pagination/demo/total.md correctly 1`] = `
  • @@ -891,7 +811,6 @@ exports[`renders ./components/pagination/demo/total.md correctly 1`] = `
  • diff --git a/components/slider/__tests__/__snapshots__/demo.test.js.snap b/components/slider/__tests__/__snapshots__/demo.test.js.snap index 7409753055..dfd03eef38 100644 --- a/components/slider/__tests__/__snapshots__/demo.test.js.snap +++ b/components/slider/__tests__/__snapshots__/demo.test.js.snap @@ -16,13 +16,9 @@ exports[`renders ./components/slider/demo/basic.md correctly 1`] = ` class="ant-slider-step" />
  • @@ -95,7 +93,6 @@ exports[`Table.pagination renders pagination correctly 1`] = `
  • @@ -105,7 +102,6 @@ exports[`Table.pagination renders pagination correctly 1`] = `
  • diff --git a/components/table/__tests__/__snapshots__/demo.test.js.snap b/components/table/__tests__/__snapshots__/demo.test.js.snap index ff959eec31..3cbaa77662 100644 --- a/components/table/__tests__/__snapshots__/demo.test.js.snap +++ b/components/table/__tests__/__snapshots__/demo.test.js.snap @@ -355,14 +355,12 @@ exports[`renders ./components/table/demo/basic.md correctly 1`] = `
  • @@ -372,7 +370,6 @@ exports[`renders ./components/table/demo/basic.md correctly 1`] = `
  • @@ -543,14 +540,12 @@ exports[`renders ./components/table/demo/bordered.md correctly 1`] = `
  • @@ -560,7 +555,6 @@ exports[`renders ./components/table/demo/bordered.md correctly 1`] = `
  • @@ -812,14 +806,12 @@ exports[`renders ./components/table/demo/colspan-rowspan.md correctly 1`] = `
  • @@ -829,7 +821,6 @@ exports[`renders ./components/table/demo/colspan-rowspan.md correctly 1`] = `
  • @@ -1010,14 +1001,12 @@ exports[`renders ./components/table/demo/custom-filter-panel.md correctly 1`] =
  • @@ -1027,7 +1016,6 @@ exports[`renders ./components/table/demo/custom-filter-panel.md correctly 1`] =
  • @@ -2351,14 +2339,12 @@ exports[`renders ./components/table/demo/dynamic-settings.md correctly 1`] = `
  • @@ -2368,7 +2354,6 @@ exports[`renders ./components/table/demo/dynamic-settings.md correctly 1`] = `
  • @@ -2554,14 +2539,12 @@ exports[`renders ./components/table/demo/edit-cell.md correctly 1`] = `
  • @@ -2571,7 +2554,6 @@ exports[`renders ./components/table/demo/edit-cell.md correctly 1`] = `
  • @@ -2714,14 +2696,12 @@ exports[`renders ./components/table/demo/edit-row.md correctly 1`] = `
  • @@ -2731,7 +2711,6 @@ exports[`renders ./components/table/demo/edit-row.md correctly 1`] = `
  • @@ -2932,14 +2911,12 @@ exports[`renders ./components/table/demo/expand.md correctly 1`] = `
  • @@ -2949,7 +2926,6 @@ exports[`renders ./components/table/demo/expand.md correctly 1`] = `
  • @@ -3489,14 +3465,12 @@ exports[`renders ./components/table/demo/expand-children.md correctly 1`] = `
  • @@ -3506,7 +3480,6 @@ exports[`renders ./components/table/demo/expand-children.md correctly 1`] = `
  • @@ -3944,14 +3917,12 @@ exports[`renders ./components/table/demo/fixed-columns.md correctly 1`] = `
  • @@ -3961,7 +3932,6 @@ exports[`renders ./components/table/demo/fixed-columns.md correctly 1`] = `
  • @@ -5270,14 +5240,12 @@ exports[`renders ./components/table/demo/fixed-columns-header.md correctly 1`] =
  • @@ -5286,7 +5254,6 @@ exports[`renders ./components/table/demo/fixed-columns-header.md correctly 1`] =
  • @@ -5295,7 +5262,6 @@ exports[`renders ./components/table/demo/fixed-columns-header.md correctly 1`] =
  • @@ -5304,7 +5270,6 @@ exports[`renders ./components/table/demo/fixed-columns-header.md correctly 1`] =
  • @@ -5313,7 +5278,6 @@ exports[`renders ./components/table/demo/fixed-columns-header.md correctly 1`] =
  • @@ -5322,14 +5286,12 @@ exports[`renders ./components/table/demo/fixed-columns-header.md correctly 1`] =
  • @@ -5339,7 +5301,6 @@ exports[`renders ./components/table/demo/fixed-columns-header.md correctly 1`] =
  • @@ -6595,14 +6556,12 @@ exports[`renders ./components/table/demo/fixed-header.md correctly 1`] = `
  • @@ -6611,7 +6570,6 @@ exports[`renders ./components/table/demo/fixed-header.md correctly 1`] = `
  • @@ -6621,7 +6579,6 @@ exports[`renders ./components/table/demo/fixed-header.md correctly 1`] = `
  • @@ -7668,14 +7625,12 @@ exports[`renders ./components/table/demo/grouping-columns.md correctly 1`] = `
  • @@ -7684,7 +7639,6 @@ exports[`renders ./components/table/demo/grouping-columns.md correctly 1`] = `
  • @@ -7693,7 +7647,6 @@ exports[`renders ./components/table/demo/grouping-columns.md correctly 1`] = `
  • @@ -7702,7 +7655,6 @@ exports[`renders ./components/table/demo/grouping-columns.md correctly 1`] = `
  • @@ -7711,7 +7663,6 @@ exports[`renders ./components/table/demo/grouping-columns.md correctly 1`] = `
  • @@ -7720,14 +7671,12 @@ exports[`renders ./components/table/demo/grouping-columns.md correctly 1`] = `
  • @@ -7737,7 +7686,6 @@ exports[`renders ./components/table/demo/grouping-columns.md correctly 1`] = `
  • @@ -7977,14 +7925,12 @@ exports[`renders ./components/table/demo/head.md correctly 1`] = `
  • @@ -7994,7 +7940,6 @@ exports[`renders ./components/table/demo/head.md correctly 1`] = `
  • @@ -8280,14 +8225,12 @@ exports[`renders ./components/table/demo/jsx.md correctly 1`] = `
  • @@ -8297,7 +8240,6 @@ exports[`renders ./components/table/demo/jsx.md correctly 1`] = `
  • @@ -8567,14 +8509,12 @@ exports[`renders ./components/table/demo/nested-table.md correctly 1`] = `
  • @@ -8584,7 +8524,6 @@ exports[`renders ./components/table/demo/nested-table.md correctly 1`] = `
  • @@ -8853,14 +8792,12 @@ exports[`renders ./components/table/demo/reset-filter.md correctly 1`] = `
  • @@ -8870,7 +8807,6 @@ exports[`renders ./components/table/demo/reset-filter.md correctly 1`] = `
  • @@ -9170,14 +9106,12 @@ exports[`renders ./components/table/demo/row-selection.md correctly 1`] = `
  • @@ -9187,7 +9121,6 @@ exports[`renders ./components/table/demo/row-selection.md correctly 1`] = `
  • @@ -9750,14 +9683,12 @@ exports[`renders ./components/table/demo/row-selection-and-operation.md correctl
  • @@ -9766,7 +9697,6 @@ exports[`renders ./components/table/demo/row-selection-and-operation.md correctl
  • @@ -9775,7 +9705,6 @@ exports[`renders ./components/table/demo/row-selection-and-operation.md correctl
  • @@ -9784,7 +9713,6 @@ exports[`renders ./components/table/demo/row-selection-and-operation.md correctl
  • @@ -9793,7 +9721,6 @@ exports[`renders ./components/table/demo/row-selection-and-operation.md correctl
  • @@ -9803,7 +9730,6 @@ exports[`renders ./components/table/demo/row-selection-and-operation.md correctl
  • @@ -10357,14 +10283,12 @@ exports[`renders ./components/table/demo/row-selection-custom.md correctly 1`] =
  • @@ -10373,7 +10297,6 @@ exports[`renders ./components/table/demo/row-selection-custom.md correctly 1`] =
  • @@ -10382,7 +10305,6 @@ exports[`renders ./components/table/demo/row-selection-custom.md correctly 1`] =
  • @@ -10391,7 +10313,6 @@ exports[`renders ./components/table/demo/row-selection-custom.md correctly 1`] =
  • @@ -10400,7 +10321,6 @@ exports[`renders ./components/table/demo/row-selection-custom.md correctly 1`] =
  • @@ -10410,7 +10330,6 @@ exports[`renders ./components/table/demo/row-selection-custom.md correctly 1`] =
  • @@ -10563,14 +10482,12 @@ exports[`renders ./components/table/demo/size.md correctly 1`] = `
  • @@ -10580,7 +10497,6 @@ exports[`renders ./components/table/demo/size.md correctly 1`] = `
  • @@ -10729,14 +10645,12 @@ exports[`renders ./components/table/demo/size.md correctly 1`] = `
  • @@ -10746,7 +10660,6 @@ exports[`renders ./components/table/demo/size.md correctly 1`] = `