Skip to content

Commit 36bc48b

Browse files
committed
[docs] Add storybook for testing
NOTE: I strongly prefer storybook over the docs site for testing the animation, as the docs site causes a ton of page jumping that makes it hard to click the button easily
1 parent f23dbbf commit 36bc48b

1 file changed

Lines changed: 102 additions & 0 deletions

File tree

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
import type { Meta, StoryObj } from '@storybook/react';
10+
import React, { useState } from 'react';
11+
import { hideStorybookControls } from '../../../.storybook/utils';
12+
13+
import { EuiButton, EuiText } from '../index';
14+
15+
import { EuiFlyout, EuiFlyoutProps, EuiFlyoutBody } from './index';
16+
17+
const meta: Meta<EuiFlyoutProps> = {
18+
title: 'EuiFlyout',
19+
component: EuiFlyout,
20+
args: {
21+
// Component defaults
22+
type: 'overlay',
23+
side: 'right',
24+
size: 'm',
25+
paddingSize: 'l',
26+
pushMinBreakpoint: 'l',
27+
closeButtonPosition: 'inside',
28+
hideCloseButton: false,
29+
ownFocus: true,
30+
},
31+
};
32+
33+
export default meta;
34+
type Story = StoryObj<EuiFlyoutProps>;
35+
36+
const StatefulFlyout = (props: Partial<EuiFlyoutProps>) => {
37+
const [isOpen, setIsOpen] = useState(true);
38+
return (
39+
<>
40+
<EuiButton size="s" onClick={() => setIsOpen(!isOpen)}>
41+
Toggle flyout
42+
</EuiButton>
43+
{isOpen && <EuiFlyout {...props} onClose={() => setIsOpen(false)} />}
44+
</>
45+
);
46+
};
47+
48+
export const Playground: Story = {
49+
render: ({ ...args }) => <StatefulFlyout {...args} />,
50+
};
51+
52+
export const PushFlyouts: Story = {
53+
render: ({ ...args }) => {
54+
const fillerText = (
55+
<EuiText>
56+
<p>
57+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eu
58+
condimentum ipsum, nec ornare metus. Sed egestas elit nec placerat
59+
suscipit. Cras pulvinar nisi eget enim sodales fringilla. Aliquam
60+
lobortis lorem at ornare aliquet. Mauris laoreet laoreet mollis.
61+
Pellentesque aliquet tortor dui, non luctus turpis pulvinar vitae.
62+
Nunc ultrices scelerisque erat eu rutrum. Nam at ligula enim. Ut nec
63+
nisl faucibus, euismod neque ut, aliquam nisl. Donec eu ante ut arcu
64+
rutrum blandit nec ac nisl. In elementum id enim vitae aliquam. In
65+
sagittis, neque vitae ultricies interdum, sapien justo efficitur
66+
ligula, sit amet fermentum nisl magna sit amet turpis. Nulla facilisi.
67+
Proin nec viverra mi. Morbi dolor arcu, ornare non consequat et,
68+
viverra dapibus tellus.
69+
</p>
70+
</EuiText>
71+
);
72+
return (
73+
<>
74+
<StatefulFlyout {...args}>
75+
<EuiFlyoutBody>{fillerText}</EuiFlyoutBody>
76+
</StatefulFlyout>
77+
{fillerText}
78+
</>
79+
);
80+
},
81+
args: {
82+
type: 'push',
83+
pushAnimation: false,
84+
pushMinBreakpoint: 'xs',
85+
},
86+
argTypes: hideStorybookControls([
87+
'onClose',
88+
'aria-label',
89+
'as',
90+
'closeButtonPosition',
91+
'closeButtonProps',
92+
'focusTrapProps',
93+
'hideCloseButton',
94+
'includeFixedHeadersInFocusTrap',
95+
'maskProps',
96+
'maxWidth',
97+
'outsideClickCloses',
98+
'ownFocus',
99+
'paddingSize',
100+
'style',
101+
]),
102+
};

0 commit comments

Comments
 (0)