-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathindex.story.tsx
120 lines (110 loc) · 2.87 KB
/
index.story.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**
* External dependencies
*/
import type { StoryFn, Meta } from '@storybook/react';
/**
* WordPress dependencies
*/
import { useState } from '@wordpress/element';
import { fullscreen } from '@wordpress/icons';
/**
* Internal dependencies
*/
import Button from '../../button';
import InputControl from '../../input-control';
import Modal from '../';
import type { ModalProps } from '../types';
const meta: Meta< typeof Modal > = {
component: Modal,
title: 'Components/Overlays/Modal',
id: 'components-modal',
argTypes: {
children: {
control: { type: null },
},
onKeyDown: {
control: { type: null },
},
focusOnMount: {
options: [ true, false, 'firstElement', 'firstContentElement' ],
control: { type: 'select' },
},
role: {
control: { type: 'text' },
},
onRequestClose: {
action: 'onRequestClose',
},
isDismissible: {
control: { type: 'boolean' },
},
},
parameters: {
controls: { expanded: true },
},
};
export default meta;
const Template: StoryFn< typeof Modal > = ( { onRequestClose, ...args } ) => {
const [ isOpen, setOpen ] = useState( false );
const openModal = () => setOpen( true );
const closeModal: ModalProps[ 'onRequestClose' ] = ( event ) => {
setOpen( false );
onRequestClose( event );
};
return (
<>
<Button variant="secondary" onClick={ openModal }>
Open Modal
</Button>
{ isOpen && (
<Modal onRequestClose={ closeModal } { ...args }>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et magna
aliqua. Ut enim ad minim veniam, quis nostrud
exercitation ullamco laboris nisi ut aliquip ex ea ea
commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu
fugiat nulla pariatur. Excepteur sint occaecat cupidatat
non proident, sunt in culpa qui officia deserunt mollit
anim id est laborum.
</p>
<InputControl style={ { marginBottom: '20px' } } />
<Button variant="secondary" onClick={ closeModal }>
Close Modal
</Button>
</Modal>
) }
</>
);
};
export const Default: StoryFn< typeof Modal > = Template.bind( {} );
Default.args = {
title: 'Title',
};
Default.parameters = {
docs: {
source: {
code: '',
},
},
};
export const WithsizeSmall: StoryFn< typeof Modal > = Template.bind( {} );
WithsizeSmall.args = {
size: 'small',
};
WithsizeSmall.storyName = 'With size: small';
/**
* The `headerActions` prop can be used to add auxiliary actions to the header, for example a fullscreen mode toggle.
*/
export const WithHeaderActions: StoryFn< typeof Modal > = Template.bind( {} );
WithHeaderActions.args = {
...Default.args,
headerActions: (
<Button icon={ fullscreen } label="Fullscreen mode" size="compact" />
),
children: <div style={ { height: '200px' } } />,
};
WithHeaderActions.parameters = {
...Default.parameters,
};