Browse Source

Merge pull request #21849 from ant-design/master

chore: Merge master to feature
pull/21947/head
偏右 5 years ago
committed by GitHub
parent
commit
e01abd2309
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      .github/PULL_REQUEST_TEMPLATE.md
  2. 2
      .github/PULL_REQUEST_TEMPLATE/pr_cn.md
  3. 14
      components/carousel/__tests__/index.test.js
  4. 2
      components/carousel/index.en-US.md
  5. 18
      components/carousel/index.tsx
  6. 2
      components/carousel/index.zh-CN.md
  7. 2
      components/dropdown/demo/overlay-visible.md
  8. 4
      components/dropdown/index.zh-CN.md
  9. 5
      components/dropdown/style/index.less
  10. 4
      components/form/demo/control-hooks.md
  11. 2
      components/form/v3.en-US.md
  12. 2
      components/form/v3.zh-CN.md
  13. 2
      components/notification/demo/duration.md
  14. 15
      components/table/__tests__/Table.filter.test.js
  15. 3
      components/table/__tests__/__snapshots__/demo.test.js.snap
  16. 93
      components/table/demo/drag-sorting.md
  17. 5
      components/table/hooks/useFilter/FilterDropdown.tsx
  18. 3
      components/table/hooks/useFilter/index.tsx
  19. 1
      components/table/index.en-US.md
  20. 1
      components/table/index.zh-CN.md
  21. 1
      components/table/interface.tsx

2
.github/PULL_REQUEST_TEMPLATE.md

@ -48,6 +48,8 @@ Describe changes from userside, and list all potential break changes or other ri
### ☑️ Self Check before Merge
⚠️ Please check all items below before review. ⚠️
- [ ] Doc is updated/provided or not needed
- [ ] Demo is updated/provided or not needed
- [ ] TypeScript definition is updated/provided or not needed

2
.github/PULL_REQUEST_TEMPLATE/pr_cn.md

@ -48,7 +48,7 @@
### ☑️ 请求合并前的自查清单
> 请自检并全部勾选上
⚠️ 请自检并全部**勾选全部选项**。⚠️
- [ ] 文档已补充或无须补充
- [ ] 代码演示已提供或无须提供

14
components/carousel/__tests__/index.test.js

@ -126,18 +126,4 @@ describe('Carousel', () => {
).toBeTruthy();
});
});
describe('dots precise control by plain object', () => {
it('use dots to provide dotsClasse', () => {
const wrapper = mount(
<Carousel dots={{ dotsClass: 'customDots' }}>
<div>1</div>
<div>2</div>
<div>3</div>
</Carousel>,
);
wrapper.update();
expect(wrapper.find('.slick-dots').hasClass('customDots')).toBeTruthy();
});
});
});

2
components/carousel/index.en-US.md

@ -20,7 +20,7 @@ A carousel component. Scales with its container.
| autoplay | Whether to scroll automatically | boolean | `false` | |
| beforeChange | Callback function called before the current index changes | function(from, to) | - | |
| dotPosition | The position of the dots, which can be one of `top` `bottom` `left` `right` | string | bottom | |
| dots | Whether to show the dots at the bottom of the gallery, `string` for `dotsClass` | boolean \| { dotsClass?:string } | `true` | |
| dots | Whether to show the dots at the bottom of the gallery | boolean | `true` | |
| easing | Transition interpolation function name | string | `linear` | |
| effect | Transition effect | `scrollx` \| `fade` | `scrollx` | |

18
components/carousel/index.tsx

@ -1,5 +1,4 @@
import * as React from 'react';
import isPlainObject from 'lodash/isPlainObject';
import debounce from 'lodash/debounce';
import { Settings } from '@ant-design/react-slick';
import classNames from 'classnames';
@ -15,18 +14,13 @@ export type CarouselEffect = 'scrollx' | 'fade';
export type DotPosition = 'top' | 'bottom' | 'left' | 'right';
// Carousel
export interface CarouselProps extends Omit<Settings, 'dots' | 'dotsClass'> {
export interface CarouselProps extends Settings {
effect?: CarouselEffect;
style?: React.CSSProperties;
prefixCls?: string;
slickGoTo?: number;
dotPosition?: DotPosition;
children?: React.ReactNode;
dots?:
| boolean
| {
dotsClass?: string;
};
}
export default class Carousel extends React.Component<CarouselProps, {}> {
@ -112,13 +106,7 @@ export default class Carousel extends React.Component<CarouselProps, {}> {
const dotsClass = 'slick-dots';
const dotPosition = this.getDotPosition();
props.vertical = dotPosition === 'left' || dotPosition === 'right';
const enableDots = props.dots === true || isPlainObject(props.dots);
const dsClass = classNames(
dotsClass,
`${dotsClass}-${dotPosition || 'bottom'}`,
typeof props.dots === 'boolean' ? false : props.dots?.dotsClass,
);
props.dotsClass = `${dotsClass} ${dotsClass}-${dotPosition || 'bottom'}`;
const className = classNames(prefixCls, {
[`${prefixCls}-rtl`]: direction === 'rtl',
@ -127,7 +115,7 @@ export default class Carousel extends React.Component<CarouselProps, {}> {
return (
<div className={className}>
<SlickCarousel ref={this.saveSlick} {...props} dots={enableDots} dotsClass={dsClass} />
<SlickCarousel ref={this.saveSlick} {...props} />
</div>
);
};

2
components/carousel/index.zh-CN.md

@ -21,7 +21,7 @@ subtitle: 走马灯
| autoplay | 是否自动切换 | boolean | false | | |
| beforeChange | 切换面板的回调 | function(from, to) | 无 | | |
| dotPosition | 面板指示点位置,可选 `top` `bottom` `left` `right` | string | bottom | |
| dots | 是否显示面板指示点,如果为 `string` 则指定为 `dotsClass` | boolean \| { dotsClass?:string } | true | | |
| dots | 是否显示面板指示点 | boolean | true | | |
| easing | 动画效果 | string | linear | | |
| effect | 动画效果函数,可取 scrollx, fade | string | scrollx | | |

2
components/dropdown/demo/overlay-visible.md

@ -37,7 +37,7 @@ class OverlayVisible extends React.Component {
<Menu onClick={this.handleMenuClick}>
<Menu.Item key="1">Clicking me will not close the menu.</Menu.Item>
<Menu.Item key="2">Clicking me will not close the menu also.</Menu.Item>
<Menu.Item key="3">Clicking me will close the menu</Menu.Item>
<Menu.Item key="3">Clicking me will close the menu.</Menu.Item>
</Menu>
);
return (

4
components/dropdown/index.zh-CN.md

@ -41,9 +41,9 @@ title: Dropdown
| icon | 右侧的 icon | ReactNode | - | |
| overlay | 菜单 | [Menu](/components/menu/) | - | |
| placement | 菜单弹出位置:`bottomLeft` `bottomCenter` `bottomRight` `topLeft` `topCenter` `topRight` | String | `bottomLeft` | |
| size | 按钮大小,和 [Button](/components/button/) 一致 | string | 'default' | |
| size | 按钮大小,和 [Button](/components/button/) 一致 | string | `default` | |
| trigger | 触发下拉的行为 | Array&lt;`click`\|`hover`\|`contextMenu`> | `['hover']` | |
| type | 按钮类型,和 [Button](/components/button/) 一致 | string | 'default' | |
| type | 按钮类型,和 [Button](/components/button/) 一致 | string | `default` | |
| visible | 菜单是否显示 | boolean | - | |
| onClick | 点击左侧按钮的回调,和 [Button](/components/button/) 一致 | Function | - | |
| onVisibleChange | 菜单显示状态改变时调用,参数为 visible | Function | - | |

5
components/dropdown/style/index.less

@ -189,6 +189,7 @@
}
&-icon {
margin-right: 0;
color: @text-color-secondary;
font-style: normal;
.iconfont-size-under-12px(10px);
@ -203,11 +204,11 @@
}
&-submenu-title {
padding-right: 26px;
padding-right: @control-padding-horizontal + @font-size-sm;
.@{dropdown-prefix-cls}-rtl & {
padding-right: @control-padding-horizontal;
padding-left: 26px;
padding-left: @control-padding-horizontal + @font-size-sm;
}
}

4
components/form/demo/control-hooks.md

@ -9,10 +9,14 @@ title:
通过 `Form.useForm` 对表单数据域进行交互。
> 注意 `useForm` 是 [React Hooks](https://reactjs.org/docs/hooks-intro.html) 的实现,只能用于函数组件,class 组件请查看下面的例子。
## en-US
Call form method with `Form.useForm`.
> Note that `useForm` is a [React Hooks](https://reactjs.org/docs/hooks-intro.html) that only works in functional component.
```tsx
import { Form, Input, Button, Select } from 'antd';

2
components/form/v3.en-US.md

@ -102,7 +102,7 @@ class Demo extends React.Component {
render() {
return (
<Form ref={formRef}>
<Form ref={this.formRef}>
<Form.Item name="username" rules={[{ required: true }]}>
<Input />
</Form.Item>

2
components/form/v3.zh-CN.md

@ -104,7 +104,7 @@ class Demo extends React.Component {
render() {
return (
<Form ref={formRef}>
<Form ref={this.formRef}>
<Form.Item name="username" rules={[{ required: true }]}>
<Input />
</Form.Item>

2
components/notification/demo/duration.md

@ -20,7 +20,7 @@ const openNotification = () => {
const args = {
message: 'Notification Title',
description:
'I will never close automatically. I will be close automatically. I will never close automatically.',
'I will never close automatically. This is a purposely very very long description that has many many characters and words.',
duration: 0,
};
notification.open(args);

15
components/table/__tests__/Table.filter.test.js

@ -1198,4 +1198,19 @@ describe('Table.filter', () => {
.text(),
).toEqual('Reset');
});
it('filtered should work', () => {
const wrapper = mount(
createTable({
columns: [
{
...column,
filtered: true,
},
],
}),
);
expect(wrapper.find('.ant-table-filter-trigger').hasClass('active')).toBeTruthy();
});
});

3
components/table/__tests__/__snapshots__/demo.test.js.snap

@ -1460,7 +1460,6 @@ exports[`renders ./components/table/demo/drag-sorting.md correctly 1`] = `
<tr
class="ant-table-row ant-table-row-level-0"
data-row-key="1"
index="0"
style="cursor:move"
>
<td
@ -1482,7 +1481,6 @@ exports[`renders ./components/table/demo/drag-sorting.md correctly 1`] = `
<tr
class="ant-table-row ant-table-row-level-0"
data-row-key="2"
index="1"
style="cursor:move"
>
<td
@ -1504,7 +1502,6 @@ exports[`renders ./components/table/demo/drag-sorting.md correctly 1`] = `
<tr
class="ant-table-row ant-table-row-level-0"
data-row-key="3"
index="2"
style="cursor:move"
>
<td

93
components/table/demo/drag-sorting.md

@ -15,72 +15,47 @@ By using custom components, we can integrate table with react-dnd to implement d
```jsx
import { Table } from 'antd';
import { DndProvider, DragSource, DropTarget } from 'react-dnd';
import { DndProvider, useDrag, useDrop } from 'react-dnd';
import HTML5Backend from 'react-dnd-html5-backend';
import update from 'immutability-helper';
let dragingIndex = -1;
const type = 'DragbleBodyRow';
class BodyRow extends React.Component {
render() {
const { isOver, connectDragSource, connectDropTarget, moveRow, ...restProps } = this.props;
const style = { ...restProps.style, cursor: 'move' };
let { className } = restProps;
if (isOver) {
if (restProps.index > dragingIndex) {
className += ' drop-over-downward';
}
if (restProps.index < dragingIndex) {
className += ' drop-over-upward';
const DragableBodyRow = ({ index, moveRow, className, style, ...restProps }) => {
const ref = React.useRef();
const [{ isOver, dropClassName }, drop] = useDrop({
accept: type,
collect: monitor => {
const { index: dragIndex } = monitor.getItem() || {};
if (dragIndex === index) {
return {};
}
}
return connectDragSource(
connectDropTarget(<tr {...restProps} className={className} style={style} />),
);
}
}
const rowSource = {
beginDrag(props) {
dragingIndex = props.index;
return {
index: props.index,
};
},
};
const rowTarget = {
drop(props, monitor) {
const dragIndex = monitor.getItem().index;
const hoverIndex = props.index;
// Don't replace items with themselves
if (dragIndex === hoverIndex) {
return;
}
// Time to actually perform the action
props.moveRow(dragIndex, hoverIndex);
// Note: we're mutating the monitor item here!
// Generally it's better to avoid mutations,
// but it's good here for the sake of performance
// to avoid expensive index searches.
monitor.getItem().index = hoverIndex;
},
return {
isOver: monitor.isOver(),
dropClassName: dragIndex < index ? ' drop-over-downward' : ' drop-over-upward',
};
},
drop: item => {
moveRow(item.index, index);
},
});
const [, drag] = useDrag({
item: { type, index },
collect: monitor => ({
isDragging: monitor.isDragging(),
}),
});
drop(drag(ref));
return (
<tr
ref={ref}
className={`${className}${isOver ? dropClassName : ''}`}
style={{ cursor: 'move', ...style }}
{...restProps}
/>
);
};
const DragableBodyRow = DropTarget('row', rowTarget, (connect, monitor) => ({
connectDropTarget: connect.dropTarget(),
isOver: monitor.isOver(),
}))(
DragSource('row', rowSource, connect => ({
connectDragSource: connect.dragSource(),
}))(BodyRow),
);
const columns = [
{
title: 'Name',

5
components/table/hooks/useFilter/FilterDropdown.tsx

@ -76,7 +76,10 @@ function FilterDropdown<RecordType>(props: FilterDropdownProps<RecordType>) {
const { filterDropdownVisible, onFilterDropdownVisibleChange } = column;
const [visible, setVisible] = React.useState(false);
const filtered: boolean = !!(filterState && filterState.filteredKeys);
const filtered: boolean = !!(
filterState &&
(filterState.filteredKeys || filterState.forceFiltered)
);
const triggerVisible = (newVisible: boolean) => {
setVisible(newVisible);
if (onFilterDropdownVisibleChange) {

3
components/table/hooks/useFilter/index.tsx

@ -16,6 +16,7 @@ export interface FilterState<RecordType> {
column: ColumnType<RecordType>;
key: Key;
filteredKeys?: Key[] | null;
forceFiltered?: boolean;
}
function collectFilterStates<RecordType>(
@ -37,6 +38,7 @@ function collectFilterStates<RecordType>(
column,
key: getColumnKey(column, columnPos),
filteredKeys: column.filteredValue,
forceFiltered: column.filtered,
});
} else {
// Uncontrolled
@ -45,6 +47,7 @@ function collectFilterStates<RecordType>(
key: getColumnKey(column, columnPos),
filteredKeys:
init && column.defaultFilteredValue ? column.defaultFilteredValue! : undefined,
forceFiltered: column.filtered,
});
}
}

1
components/table/index.en-US.md

@ -167,6 +167,7 @@ Properties for expandable.
| defaultExpandAllRows | Expand all rows initially | boolean | `false` |
| defaultExpandedRowKeys | Initial expanded row keys | string\[] | - |
| expandIcon | Customize row expand Icon. Ref [example](https://codesandbox.io/s/fervent-bird-nuzpr) | Function(props):ReactNode | - |
| expandIconColumnIndex | Customize expand icon column index | number | - |
| expandedRowKeys | Current expanded row keys | string\[] | - |
| expandedRowRender | Expanded container render for each row | Function(record, index, indent, expanded):ReactNode | - |
| expandRowByClick | Whether to expand row by clicking anywhere in the whole row | boolean | `false` |

1
components/table/index.zh-CN.md

@ -172,6 +172,7 @@ const columns = [
| defaultExpandAllRows | 初始时,是否展开所有行 | boolean | false |
| defaultExpandedRowKeys | 默认展开的行 | string\[] | - |
| expandIcon | 自定义展开图标,参考[示例](https://codesandbox.io/s/fervent-bird-nuzpr) | Function(props):ReactNode | - |
| expandIconColumnIndex | 自定义展开按钮的列顺序 | number | - |
| expandedRowKeys | 展开的行,控制属性 | string\[] | - |
| expandedRowRender | 额外的展开行 | Function(record, index, indent, expanded):ReactNode | - |
| expandRowByClick | 通过点击行来展开子行 | boolean | `false` |

1
components/table/interface.tsx

@ -85,6 +85,7 @@ export interface ColumnType<RecordType> extends RcColumnType<RecordType> {
showSorterTooltip?: boolean;
// Filter
filtered?: boolean;
filters?: ColumnFilterItem[];
filterDropdown?: React.ReactNode | ((props: FilterDropdownProps) => React.ReactNode);
filterMultiple?: boolean;

Loading…
Cancel
Save