1
- import { useState } from ' react' ;
2
- import { Canvas , Story , ArgsTable , Meta } from ' @storybook/blocks' ;
3
- import { Offcanvas } from ' ../Offcanvas' ;
4
- import { OffcanvasCreator , offcanvasContent } from ' ./OffcanvasCreator' ;
1
+ import { Primary , Stories , ArgTypes , Meta } from ' @storybook/blocks' ;
5
2
import { StyledSystemLinks } from ' ../../../docs/StyledSystemLinks' ;
6
- import { Button } from ' ../.. ' ;
3
+ import * as OffcanvasStories from ' ./Offcanvas.stories ' ;
7
4
8
- <Meta title = " Components/Offcanvas" component = { Offcanvas } />
9
-
10
- export const Template = args => {
11
- const [open, setOpen] = useState (false );
12
- const openCanvas = () => setOpen (true );
13
- const closeCanvas = () => setOpen (false );
14
- return (
15
- <>
16
- <Button size = " small" mr = { 1 } onClick = { openCanvas } >
17
- Open Offcanvas
18
- </Button >
19
- { open && <Offcanvas { ... args } onClose = { closeCanvas } />}
20
- </>
21
- );
22
- };
5
+ <Meta of = { OffcanvasStories } />
23
6
24
7
# Offcanvas
25
8
@@ -30,20 +13,17 @@ content.
30
13
Offcanvas is responsive per default but the width can be adjusted (the default is 600px or 37.5rem). Content on the Offcanvas
31
14
is scrollable and has a space5 bounding box.
32
15
33
- <Canvas withSource = " none" >
34
- <Story
35
- name = " Default"
36
- args = { {
37
- children: offcanvasContent
38
- }}
39
- >
40
- { Template .bind ({})}
41
- </Story >
42
- </Canvas >
16
+ <Primary />
43
17
44
- ### Example Code
18
+ ## Properties
45
19
46
- The following contains a simple example, with a resulting Offcanvas similar to the live examples above.
20
+ <ArgTypes of = { OffcanvasStories } />
21
+
22
+ <StyledSystemLinks component = " Offcanvas" supportedProps = { [' width' ]} />
23
+
24
+ ## Usage
25
+
26
+ ### Basic use
47
27
48
28
``` jsx
49
29
const [showOffcanvas , setShowOffcanvas ] = useState (true );
@@ -62,31 +42,24 @@ const [showOffcanvas, setShowOffcanvas] = useState(true);
62
42
< / Offcanvas> ;
63
43
```
64
44
65
- ### More examples
66
-
67
- <Canvas withSource = " none" >
68
- <OffcanvasCreator />
69
- </Canvas >
70
-
71
- ## API
72
-
73
- <ArgsTable of = { Offcanvas } />
74
-
75
- <StyledSystemLinks component = " Offcanvas" supportedProps = { [' width' ]} />
76
-
77
- ### Dismiss
45
+ ### Dismissing the Offcanvas
78
46
79
47
Offcanvas provides a function to dismiss the component with an animation. The
80
48
dismiss function is available either through render props or a hook. After the
81
49
animation has finished the ` onClose ` callback will be called.
82
50
83
- #### Render Props
51
+ #### Via Render Props
52
+
53
+ Pass render function as a child to ` Offcanvas ` . Call the function passed as an argument to close the Offcanvas:
84
54
85
55
``` jsx
86
56
< Offcanvas> {dismiss => < Button onClick= {dismiss}> Close< / Button> }< / Offcanvas>
87
57
```
88
58
89
- #### Hook
59
+ #### Via Hook
60
+
61
+ Use the ` useOffcanvasDismiss ` hook to get the dismiss function. It is only available inside the ` Offcanvas ` component because
62
+ it uses React context to get the dismiss function.
90
63
91
64
``` jsx
92
65
const InsideOffcanvas = () => {
@@ -100,3 +73,5 @@ const OffcanvasWrapper = () => (
100
73
< / Offcanvas>
101
74
);
102
75
```
76
+
77
+ <Stories includePrimary = { false } />
0 commit comments