From 58df74c38e5ab223f69940db30af47631e74aeac Mon Sep 17 00:00:00 2001 From: dingkang Date: Sat, 14 May 2022 16:40:42 +0800 Subject: [PATCH] docs: replace class component with hooks (#35519) * 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 --- components/drawer/demo/form-in-drawer.md | 258 +++++++++--------- components/drawer/demo/multi-level-drawer.md | 79 +++--- components/drawer/demo/placement.md | 84 +++--- components/drawer/demo/render-in-current.md | 62 ++--- components/drawer/demo/user-profile.md | 266 +++++++++---------- components/dropdown/demo/loading.md | 80 +++--- components/dropdown/demo/overlay-visible.md | 81 +++--- components/empty/demo/config-provider.md | 99 ++++--- components/grid/demo/playground.md | 141 +++++----- components/input-number/demo/disabled.md | 40 ++- components/input/demo/autosize-textarea.md | 55 ++-- components/input/demo/textarea-resize.md | 35 +-- components/input/demo/tooltip.md | 78 +++--- 13 files changed, 621 insertions(+), 737 deletions(-) diff --git a/components/drawer/demo/form-in-drawer.md b/components/drawer/demo/form-in-drawer.md index 821842a87c..a79cecffee 100644 --- a/components/drawer/demo/form-in-drawer.md +++ b/components/drawer/demo/form-in-drawer.md @@ -19,144 +19,136 @@ import { PlusOutlined } from '@ant-design/icons'; const { Option } = Select; -class DrawerForm extends React.Component { - state = { visible: false }; +export default () => { + const [visible, setVisible] = React.useState(false); - showDrawer = () => { - this.setState({ - visible: true, - }); + const showDrawer = () => { + setVisible(true); }; - onClose = () => { - this.setState({ - visible: false, - }); + const onClose = () => { + setVisible(false); }; - render() { - return ( - <> - - - - - - } - > -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - trigger.parentElement} - /> - - - - - - - - - - -
-
- - ); - } -} - -export default () => ; + return ( + <> + + + + + + } + > +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + trigger.parentElement} + /> + + + + + + + + + + +
+
+ + ); +}; ``` ```css diff --git a/components/drawer/demo/multi-level-drawer.md b/components/drawer/demo/multi-level-drawer.md index f1be8f443c..63844c4568 100644 --- a/components/drawer/demo/multi-level-drawer.md +++ b/components/drawer/demo/multi-level-drawer.md @@ -16,65 +16,54 @@ Open a new drawer on top of an existing drawer to handle multi branch tasks. ```jsx import { Drawer, Button } from 'antd'; -class App extends React.Component { - state = { visible: false, childrenDrawer: false }; +export default () => { + const [visible, setVisible] = React.useState(false); + const [childrenDrawer, setChildrenDrawer] = React.useState(false); - showDrawer = () => { - this.setState({ - visible: true, - }); + const showDrawer = () => { + setVisible(true); }; - onClose = () => { - this.setState({ - visible: false, - }); + const onClose = () => { + setVisible(false); }; - showChildrenDrawer = () => { - this.setState({ - childrenDrawer: true, - }); + const showChildrenDrawer = () => { + setChildrenDrawer(true); }; - onChildrenDrawerClose = () => { - this.setState({ - childrenDrawer: false, - }); + const onChildrenDrawerClose = () => { + setChildrenDrawer(false); }; - render() { - return ( - <> - + + - - - This is two-level drawer - + This is two-level drawer - - ); - } -} - -export default App; + + + ); +}; ```