From e5b09aa8790a1e750dc83ab077df8b91318821ec Mon Sep 17 00:00:00 2001 From: dingkang Date: Wed, 18 May 2022 19:29:01 +0800 Subject: [PATCH] docs: replace class component with hooks (#35613) * docs(badge): replace class component with hooks * docs(button): replace class component with hooks * docs(calendar): replace class component with hooks * docs(card): replace class component with hooks * docs(button): replace class component with hooks * chore(deps): remove webpack devDependencies * docs(cascader): replace class component with hooks * docs(checkbox): replace class component with hooks * docs(collapse): replace class component with hooks * docs(comment): replace class component with hooks * docs(descriptions): replace class component with hooks * docs(config-provider): replace class component with hooks * docs(date-picker): replace class component with hooks * docs(drawer): replace class component with hooks * docs(dropdown): replace class component with hooks * docs(dropdown): replace class component with hooks * docs(empty): replace class component with hooks * docs(grid): replace class component with hooks * docs(input): replace class component with hooks * docs(input-number): replace class component with hooks * docs(demo): fix lint error * docs(layout): replace class component with hooks * docs(list): replace class component with hooks * docs(mentions): replace class component with hooks * docs: fix code review issue * docs(modal): replace class component with hooks --- components/modal/demo/button-props.md | 66 ++-- components/modal/demo/dark.md | 529 +++++++++++++------------- components/modal/demo/footer.md | 105 +++-- components/modal/demo/locale.md | 58 ++- components/modal/demo/modal-render.md | 156 ++++---- components/modal/demo/position.md | 92 ++--- 6 files changed, 465 insertions(+), 541 deletions(-) diff --git a/components/modal/demo/button-props.md b/components/modal/demo/button-props.md index 2d39e18ec6f4..84853a55e28e 100644 --- a/components/modal/demo/button-props.md +++ b/components/modal/demo/button-props.md @@ -16,51 +16,41 @@ Passing `okButtonProps` and `cancelButtonProps` will customize the OK button and ```jsx import { Modal, Button } from 'antd'; -class App extends React.Component { - state = { visible: false }; +export default () => { + const [visible, setVisible] = React.useState(false); - showModal = () => { - this.setState({ - visible: true, - }); + const showModal = () => { + setVisible(true); }; - handleOk = e => { + const handleOk = e => { console.log(e); - this.setState({ - visible: false, - }); + setVisible(false); }; - handleCancel = e => { + const handleCancel = e => { console.log(e); - this.setState({ - visible: false, - }); + setVisible(false); }; - render() { - return ( - <> - - -

Some contents...

-

Some contents...

-

Some contents...

-
- - ); - } -} - -export default App; + return ( + <> + + +

Some contents...

+

Some contents...

+

Some contents...

+
+ + ); +}; ``` diff --git a/components/modal/demo/dark.md b/components/modal/demo/dark.md index 52c9e0e52eea..b1e1dc216587 100644 --- a/components/modal/demo/dark.md +++ b/components/modal/demo/dark.md @@ -15,6 +15,7 @@ debug: true Basic modal. ```jsx +import { useState } from 'react'; import { Modal, DatePicker, @@ -296,303 +297,283 @@ const TableTransfer = ({ leftColumns, rightColumns, ...restProps }) => ( ); -class App extends React.Component { - state = { - visible: false, - targetKeys: oriTargetKeys, - selectedKeys: [], - disabled: false, - showSearch: false, - }; +export default () => { + const [visible, setVisible] = useState(false); + const [targetKeys, setTargetKeys] = useState(oriTargetKeys); + const [selectedKeys, setSelectedKeys] = useState([]); + const [disabled, setDisabled] = useState(false); + const [showSearch, setShowSearch] = useState(false); - handleDisable = disabled => { - this.setState({ - disabled, - }); + const handleDisable = isDisabled => { + setDisabled(isDisabled); }; - handleTableTransferChange = nextTargetKeys => { - this.setState({ targetKeys: nextTargetKeys }); + const handleTableTransferChange = nextTargetKeys => { + setTargetKeys(nextTargetKeys); }; - triggerDisable = disabled => { - this.setState({ disabled }); + const triggerDisable = isDisabled => { + setDisabled(isDisabled); }; - triggerShowSearch = showSearch => { - this.setState({ showSearch }); + const triggerShowSearch = isShowSearch => { + setShowSearch(isShowSearch); }; - handleTransferChange = nextTargetKeys => { - this.setState({ targetKeys: nextTargetKeys }); + const handleTransferChange = nextTargetKeys => { + setTargetKeys(nextTargetKeys); }; - handleTransferSelectChange = (sourceSelectedKeys, targetSelectedKeys) => { - this.setState({ selectedKeys: [...sourceSelectedKeys, ...targetSelectedKeys] }); + const handleTransferSelectChange = (sourceSelectedKeys, targetSelectedKeys) => { + setSelectedKeys([...sourceSelectedKeys, ...targetSelectedKeys]); }; - showModal = () => { - this.setState({ - visible: true, - }); + const showModal = () => { + setVisible(true); }; - handleOk = e => { + const handleOk = e => { console.log(e); - this.setState({ - visible: false, - }); + setVisible(false); }; - handleCancel = e => { + const handleCancel = e => { console.log(e); - this.setState({ - visible: false, - }); + setVisible(false); }; - render() { - const { disabled, selectedKeys, targetKeys, showSearch } = this.state; - const columns = [ - { - title: 'Name', - dataIndex: 'name', - key: 'name', - filters: [ - { text: 'Joe', value: 'Joe' }, - { text: 'Jim', value: 'Jim' }, - ], - filteredValue: null, - onFilter: (value, record) => record.name.includes(value), - sorter: (a, b) => a.name.length - b.name.length, - sortOrder: true, - ellipsis: true, - }, - { - title: 'Age', - dataIndex: 'age', - key: 'age', - sorter: false, - sortOrder: true, - ellipsis: true, - }, - { - title: 'Address', - dataIndex: 'address', - key: 'address', - filters: [ - { text: 'London', value: 'London' }, - { text: 'New York', value: 'New York' }, - ], - filteredValue: null, - onFilter: (value, record) => record.address.includes(value), - sorter: false, - sortOrder: true, - ellipsis: true, - }, - ]; - return ( - <> - - - - - Content - Content - Content - Content - Content - Content - Content - - - - - -

{text}

-
-
-
- -

{text}

-
- -

{text}

-
-
- item.title} - disabled={disabled} - /> - - item.title.indexOf(inputValue) !== -1 || item.tag.indexOf(inputValue) !== -1 - } - leftColumns={[ - { - dataIndex: 'title', - title: 'Name', - }, - { - dataIndex: 'description', - title: 'Description', - }, - ]} - rightColumns={[ - { - dataIndex: 'title', - title: 'Name', - }, - ]} - /> - - record.name.includes(value), + sorter: (a, b) => a.name.length - b.name.length, + sortOrder: true, + ellipsis: true, + }, + { + title: 'Age', + dataIndex: 'age', + key: 'age', + sorter: false, + sortOrder: true, + ellipsis: true, + }, + { + title: 'Address', + dataIndex: 'address', + key: 'address', + filters: [ + { text: 'London', value: 'London' }, + { text: 'New York', value: 'New York' }, + ], + filteredValue: null, + onFilter: (value, record) => record.address.includes(value), + sorter: false, + sortOrder: true, + ellipsis: true, + }, + ]; + return ( + <> + + + + + Content + Content + Content + Content + Content + Content + Content + + + + + +

{text}

+
+
+
+ +

{text}

+
+ +

{text}

+
+
+ item.title} + disabled={disabled} + /> + + item.title.indexOf(inputValue) !== -1 || item.tag?.indexOf(inputValue) !== -1 + } + leftColumns={[ + { + dataIndex: 'title', + title: 'Name', + }, + { + dataIndex: 'description', + title: 'Description', + }, + ]} + rightColumns={[ + { + dataIndex: 'title', + title: 'Name', + }, + ]} + /> + + + + + + - - - - - - - - - - - - Content of Tab Pane 1 - - - Content of Tab Pane 2 - - - Content of Tab Pane 3 - - - - Create a services site 2015-09-01 - Solve initial network problems 2015-09-01 - } color="red"> - Technical testing 2015-09-01 - - Network problems being solved 2015-09-01 - - - } defaultExpandedKeys={['0-0-0']}> - - - - - - - - - - - - - + + + + + + + + Content of Tab Pane 1 + + + Content of Tab Pane 2 + + + Content of Tab Pane 3 + + + + Create a services site 2015-09-01 + Solve initial network problems 2015-09-01 + } color="red"> + Technical testing 2015-09-01 + + Network problems being solved 2015-09-01 + + + } defaultExpandedKeys={['0-0-0']}> + + + + + - - 'Footer'} /> -
{ - let totalBorrow = 0; - let totalRepayment = 0; - - pageData.forEach(({ borrow, repayment }) => { - totalBorrow += borrow; - totalRepayment += repayment; - }); - - return ( - <> - - - - - - - - - - - ); - }} - /> -
-
Total - {totalBorrow} - - {totalRepayment} -
Balance - {totalBorrow - totalRepayment} -
-
- - } - > - - - - - - - - - - ); - } -} - -export default App; + + + + + + + + + +
'Footer'} /> +
{ + let totalBorrow = 0; + let totalRepayment = 0; + + pageData.forEach(({ borrow, repayment }) => { + totalBorrow += borrow; + totalRepayment += repayment; + }); + + return ( + <> + + + + + + + + + + + ); + }} + /> +
+
Total + {totalBorrow} + + {totalRepayment} +
Balance + {totalBorrow - totalRepayment} +
+
+ + } + > + + + + + + + + + + ); +}; ```