Skip to content

Commit 8fcb3fd

Browse files
committed
refactor: drawer
1 parent c7b15a9 commit 8fcb3fd

23 files changed

+610
-757
lines changed

components/_util/transition.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const getTransitionProps = (transitionName: string, opt: TransitionProps
2727
// appearFromClass: `${transitionName}-appear ${transitionName}-appear-prepare`,
2828
// appearActiveClass: `antdv-base-transtion`,
2929
// appearToClass: `${transitionName}-appear ${transitionName}-appear-active`,
30-
enterFromClass: `${transitionName}-enter ${transitionName}-enter-prepare`,
30+
enterFromClass: `${transitionName}-enter ${transitionName}-enter-prepare ${transitionName}-enter-start`,
3131
enterActiveClass: `${transitionName}-enter ${transitionName}-enter-prepare`,
3232
enterToClass: `${transitionName}-enter ${transitionName}-enter-active`,
3333
leaveFromClass: ` ${transitionName}-leave`,

components/drawer/demo/basic.vue

+10-8
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ Basic drawer.
1919
<template>
2020
<a-button type="primary" @click="showDrawer">Open</a-button>
2121
<a-drawer
22-
v-model:visible="visible"
22+
v-model:open="open"
2323
class="custom-class"
24+
root-class-name="root-class-name"
25+
:root-style="{ color: 'blue' }"
2426
style="color: red"
2527
title="Basic Drawer"
2628
placement="right"
27-
@after-visible-change="afterVisibleChange"
29+
@after-open-change="afterOpenChange"
2830
>
2931
<p>Some contents...</p>
3032
<p>Some contents...</p>
@@ -35,19 +37,19 @@ Basic drawer.
3537
import { defineComponent, ref } from 'vue';
3638
export default defineComponent({
3739
setup() {
38-
const visible = ref<boolean>(false);
40+
const open = ref<boolean>(false);
3941
40-
const afterVisibleChange = (bool: boolean) => {
41-
console.log('visible', bool);
42+
const afterOpenChange = (bool: boolean) => {
43+
console.log('open', bool);
4244
};
4345
4446
const showDrawer = () => {
45-
visible.value = true;
47+
open.value = true;
4648
};
4749
4850
return {
49-
visible,
50-
afterVisibleChange,
51+
open,
52+
afterOpenChange,
5153
showDrawer,
5254
};
5355
},

components/drawer/demo/extra.vue

+5-11
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,7 @@ Extra actions should be placed at corner of drawer in Ant Design, you can using
2424
<a-radio value="left">left</a-radio>
2525
</a-radio-group>
2626
<a-button type="primary" @click="showDrawer">Open</a-button>
27-
<a-drawer
28-
:width="500"
29-
title="Basic Drawer"
30-
:placement="placement"
31-
:visible="visible"
32-
@close="onClose"
33-
>
27+
<a-drawer :width="500" title="Basic Drawer" :placement="placement" :open="open" @close="onClose">
3428
<template #extra>
3529
<a-button style="margin-right: 8px" @click="onClose">Cancel</a-button>
3630
<a-button type="primary" @click="onClose">Submit</a-button>
@@ -46,18 +40,18 @@ import type { DrawerProps } from 'ant-design-vue';
4640
export default defineComponent({
4741
setup() {
4842
const placement = ref<DrawerProps['placement']>('left');
49-
const visible = ref<boolean>(false);
43+
const open = ref<boolean>(false);
5044
5145
const showDrawer = () => {
52-
visible.value = true;
46+
open.value = true;
5347
};
5448
5549
const onClose = () => {
56-
visible.value = false;
50+
open.value = false;
5751
};
5852
return {
5953
placement,
60-
visible,
54+
open,
6155
showDrawer,
6256
onClose,
6357
};

components/drawer/demo/form-in-drawer.vue

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Use form in drawer with submit button.
2424
<a-drawer
2525
title="Create a new account"
2626
:width="720"
27-
:visible="visible"
27+
:open="open"
2828
:body-style="{ paddingBottom: '80px' }"
2929
:footer-style="{ textAlign: 'right' }"
3030
@close="onClose"
@@ -134,19 +134,19 @@ export default defineComponent({
134134
description: [{ required: true, message: 'Please enter url description' }],
135135
};
136136
137-
const visible = ref<boolean>(false);
137+
const open = ref<boolean>(false);
138138
139139
const showDrawer = () => {
140-
visible.value = true;
140+
open.value = true;
141141
};
142142
143143
const onClose = () => {
144-
visible.value = false;
144+
open.value = false;
145145
};
146146
return {
147147
form,
148148
rules,
149-
visible,
149+
open,
150150
showDrawer,
151151
onClose,
152152
};

components/drawer/demo/multi-level-drawer.vue

+6-11
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,15 @@ Open a new drawer on top of an existing drawer to handle multi branch tasks.
1919
<template>
2020
<a-button type="primary" @click="showDrawer">Open</a-button>
2121
<a-drawer
22-
v-model:visible="visible"
22+
v-model:open="open"
2323
title="Multi-level drawer"
2424
width="520"
2525
:closable="false"
2626
:footer-style="{ textAlign: 'right' }"
2727
@close="onClose"
2828
>
2929
<a-button type="primary" @click="showChildrenDrawer">Two-level drawer</a-button>
30-
<a-drawer
31-
v-model:visible="childrenDrawer"
32-
title="Two-level Drawer"
33-
width="320"
34-
:closable="false"
35-
>
30+
<a-drawer v-model:open="childrenDrawer" title="Two-level Drawer" width="320" :closable="false">
3631
<a-button type="primary" @click="showChildrenDrawer">This is two-level drawer</a-button>
3732
</a-drawer>
3833

@@ -47,21 +42,21 @@ import { defineComponent, ref } from 'vue';
4742
4843
export default defineComponent({
4944
setup() {
50-
const visible = ref<boolean>(false);
45+
const open = ref<boolean>(false);
5146
5247
const childrenDrawer = ref<boolean>(false);
5348
5449
const showDrawer = () => {
55-
visible.value = true;
50+
open.value = true;
5651
};
5752
const onClose = () => {
58-
visible.value = false;
53+
open.value = false;
5954
};
6055
const showChildrenDrawer = () => {
6156
childrenDrawer.value = true;
6257
};
6358
return {
64-
visible,
59+
open,
6560
childrenDrawer,
6661
showDrawer,
6762
onClose,

components/drawer/demo/placement.vue

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ The Drawer can appear from any edge of the screen.
2828
title="Basic Drawer"
2929
:placement="placement"
3030
:closable="false"
31-
:visible="visible"
31+
:open="open"
3232
@close="onClose"
3333
>
3434
<p>Some contents...</p>
@@ -42,18 +42,18 @@ import type { DrawerProps } from 'ant-design-vue';
4242
export default defineComponent({
4343
setup() {
4444
const placement = ref<DrawerProps['placement']>('left');
45-
const visible = ref<boolean>(false);
45+
const open = ref<boolean>(false);
4646
4747
const showDrawer = () => {
48-
visible.value = true;
48+
open.value = true;
4949
};
5050
5151
const onClose = () => {
52-
visible.value = false;
52+
open.value = false;
5353
};
5454
return {
5555
placement,
56-
visible,
56+
open,
5757
showDrawer,
5858
onClose,
5959
};

components/drawer/demo/render-in-current.vue

+8-8
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Render in current dom. custom container, check `getContainer`.
3838
title="Basic Drawer"
3939
placement="right"
4040
:closable="false"
41-
:visible="visible"
41+
:open="open"
4242
:get-container="false"
4343
:style="{ position: 'absolute' }"
4444
@close="onClose"
@@ -51,23 +51,23 @@ Render in current dom. custom container, check `getContainer`.
5151
import { defineComponent, ref } from 'vue';
5252
export default defineComponent({
5353
setup() {
54-
const visible = ref(false);
54+
const open = ref(false);
5555
56-
const afterVisibleChange = (bool: boolean) => {
57-
console.log('visible', bool);
56+
const afterOpenChange = (bool: boolean) => {
57+
console.log('open', bool);
5858
};
5959
6060
const showDrawer = () => {
61-
visible.value = true;
61+
open.value = true;
6262
};
6363
6464
const onClose = () => {
65-
visible.value = false;
65+
open.value = false;
6666
};
6767
6868
return {
69-
visible,
70-
afterVisibleChange,
69+
open,
70+
afterOpenChange,
7171
showDrawer,
7272
onClose,
7373
};

components/drawer/demo/size.vue

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ The default width (or height) of Drawer is `378px`, and there is a presetted lar
2121
Open Default Size (378px)
2222
</a-button>
2323
<a-button type="primary" @click="showDrawer('large')">Open Large Size (736px)</a-button>
24-
<a-drawer title="Basic Drawer" :size="size" :visible="visible" @close="onClose">
24+
<a-drawer title="Basic Drawer" :size="size" :open="open" @close="onClose">
2525
<template #extra>
2626
<a-button style="margin-right: 8px" @click="onClose">Cancel</a-button>
2727
<a-button type="primary" @click="onClose">Submit</a-button>
@@ -36,19 +36,19 @@ import { defineComponent, ref } from 'vue';
3636
import type { DrawerProps } from 'ant-design-vue';
3737
export default defineComponent({
3838
setup() {
39-
const visible = ref<boolean>(false);
39+
const open = ref<boolean>(false);
4040
const size = ref<DrawerProps['size']>('default');
4141
4242
const showDrawer = (val: DrawerProps['size']) => {
4343
size.value = val;
44-
visible.value = true;
44+
open.value = true;
4545
};
4646
4747
const onClose = () => {
48-
visible.value = false;
48+
open.value = false;
4949
};
5050
return {
51-
visible,
51+
open,
5252
size,
5353
showDrawer,
5454
onClose,

components/drawer/demo/user-profile.vue

+5-5
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Use Drawer to quickly preview details of an object, such as those in a list.
4242
</a-list-item>
4343
</template>
4444
</a-list>
45-
<a-drawer width="640" placement="right" :closable="false" :visible="visible" @close="onClose">
45+
<a-drawer width="640" placement="right" :closable="false" :open="open" @close="onClose">
4646
<p :style="[pStyle, pStyle2]">User Profile</p>
4747
<p :style="pStyle">Personal</p>
4848
<a-row>
@@ -136,7 +136,7 @@ export default defineComponent({
136136
descriptionItem,
137137
},
138138
setup() {
139-
const visible = ref<boolean>(false);
139+
const open = ref<boolean>(false);
140140
const pStyle = {
141141
fontSize: '16px',
142142
color: 'rgba(0,0,0,0.85)',
@@ -149,13 +149,13 @@ export default defineComponent({
149149
};
150150
151151
const showDrawer = () => {
152-
visible.value = true;
152+
open.value = true;
153153
};
154154
const onClose = () => {
155-
visible.value = false;
155+
open.value = false;
156156
};
157157
return {
158-
visible,
158+
open,
159159
pStyle,
160160
pStyle2,
161161
showDrawer,

components/drawer/index.en-US.md

+9-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
category: Components
33
type: Feedback
44
title: Drawer
5-
cover: https://img.alicdn.com/imgextra/i4/O1CN019djdZP1OHwXSRGCOW_!!6000000001681-55-tps-161-117.svg
5+
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*v3TvSq2E0HAAAAAAAAAAAAAADrJ8AQ/original
66
---
77

88
A panel which slides in from the edge of the screen.
@@ -17,16 +17,17 @@ A Drawer is a panel that is typically overlaid on top of a page and slides in fr
1717

1818
## API
1919

20+
**🚨 Note:** v4 use `rootClassName` & `rootStyle` to config wrapper style instead of `class` & `style` in v4 to align the API with Modal.
21+
2022
| Props | Description | Type | Default | Version |
2123
| --- | --- | --- | --- | --- |
2224
| autofocus | Whether Drawer should get focused after open | boolean | true | 3.0.0 |
2325
| bodyStyle | Style of the drawer content part | CSSProperties | - | |
24-
| class | The class name of the container of the Drawer dialog | string | - | |
26+
| class | Config Drawer Panel className. Use `rootClassName` if want to config top dom style | string | - | |
2527
| closable | Whether a close (x) button is visible on top left of the Drawer dialog or not | boolean | true | |
2628
| closeIcon | Custom close icon | VNode \| slot | `<CloseOutlined />` | 3.0.0 |
2729
| contentWrapperStyle | Style of the drawer wrapper of content part | CSSProperties | - | 3.0.0 |
2830
| destroyOnClose | Whether to unmount child components on closing drawer or not | boolean | false | |
29-
| drawerStyle | Style of the popup layer element | CSSProperties | - | |
3031
| extra | Extra actions area at corner | VNode \| slot | - | 3.0.0 |
3132
| footer | The footer for Drawer | VNode \| slot | - | 3.0.0 |
3233
| footerStyle | Style of the drawer footer part | CSSProperties | - | 3.0.0 |
@@ -40,16 +41,19 @@ A Drawer is a panel that is typically overlaid on top of a page and slides in fr
4041
| maskStyle | Style for Drawer's mask element | CSSProperties | {} | |
4142
| placement | The placement of the Drawer | 'top' \| 'right' \| 'bottom' \| 'left' | 'right' | |
4243
| push | Nested drawers push behavior | boolean \| {distance: string \| number} | { distance: 180 } | 3.0.0 |
44+
| rootClassName | The class name of the container of the Drawer dialog | string | - | 4.0 |
45+
| rootStyle | Style of wrapper element which **contains mask** compare to `style` | CSSProperties | - | 4.0 |
46+
| style | Style of Drawer panel. Use `bodyStyle` if want to config body only | CSSProperties | - | |
4347
| size | presetted size of drawer, default `378px` and large `736px` | `default` \| `large` | `default` | 3.0.0 |
4448
| style | Style of wrapper element which contains mask compare to drawerStyle | CSSProperties | - | |
4549
| title | The title for Drawer | string \| slot | - | |
46-
| visible(v-model) | Whether the Drawer dialog is visible or not | boolean | - | |
50+
| open(v-model) | Whether the Drawer dialog is visible or not | boolean | - | 4.0 |
4751
| width | Width of the Drawer dialog | string \| number | 378 | |
4852
| zIndex | The `z-index` of the Drawer | Number | 1000 | |
4953

5054
## Events
5155

5256
| Name | Description | Type | Default | Version |
5357
| --- | --- | --- | --- | --- |
54-
| afterVisibleChange | Callback after the animation ends when switching drawers. | function(visible) | - | |
58+
| afterOpenChange | Callback after the animation ends when switching drawers. | function(open) | - | 4.0 |
5559
| close | Specify a callback that will be called when a user clicks mask, close button or Cancel button. | function(e) | - | |

0 commit comments

Comments
 (0)