|
1 | | -import { Meta, Story, Canvas, Props } from "@storybook/addon-docs/blocks"; |
2 | | -import { withKnobs } from "@storybook/addon-knobs"; |
3 | | -import { ViewPort, LeftResizable, Fill } from "../../"; |
4 | | -import { action } from '@storybook/addon-actions'; |
5 | | -import { green, red, description } from "../Utils"; |
6 | | -import { CommonHeader } from "../Utils"; |
7 | | - |
8 | | -<CommonHeader /> |
9 | | - |
10 | | -<Meta title="Basic examples/Resize events" /> |
11 | | - |
12 | | -## Resizable space with state controlled size |
13 | | - |
14 | | -By default the size of a resizable space is uncontrolled. Therefore the initial size passed is is |
15 | | -only the initial size of a space and React Spaces deals with any resizing. To keep the size of a |
16 | | -space controlled in state you need to use the onResizeEnd event to set the new size of a space |
17 | | -after a resize back to a state value. |
18 | | - |
19 | | -<Canvas> |
20 | | - <Story name="Controlled size"> |
21 | | - { |
22 | | - () => { |
23 | | - const [ size, setSize ] = React.useState("15%"); |
24 | | - return ( |
25 | | - <React.StrictMode> |
26 | | - <ViewPort> |
27 | | - <LeftResizable size={size} style={red} trackSize={true} onResizeEnd={(newSize) => setSize(newSize)}> |
28 | | - {description("Left")} |
29 | | - </LeftResizable> |
30 | | - <Fill style={green} trackSize={true}>{description("Fill")}</Fill> |
31 | | - </ViewPort> |
32 | | - </React.StrictMode> |
33 | | - ) |
34 | | - } |
35 | | - } |
36 | | - </Story> |
37 | | -</Canvas> |
38 | | - |
39 | | -## Cancelling resize with onResizeStart |
40 | | - |
41 | | -You can cancel a resize by returning `false` from a onResizeStart event handler. |
42 | | - |
43 | | -<Canvas> |
44 | | - <Story name="Cancelled resize"> |
45 | | - { |
46 | | - () => { |
47 | | - return ( |
48 | | - <React.StrictMode> |
49 | | - <ViewPort> |
50 | | - <LeftResizable size="15%" style={red} trackSize={true} onResizeStart={() => false}> |
51 | | - {description("Left")} |
52 | | - </LeftResizable> |
53 | | - <Fill style={green} trackSize={true}>{description("Fill")}</Fill> |
54 | | - </ViewPort> |
55 | | - </React.StrictMode> |
56 | | - ) |
57 | | - } |
58 | | - } |
59 | | - </Story> |
60 | | -</Canvas> |
| 1 | +import { Meta, Story, Canvas, Props } from "@storybook/addon-docs"; |
| 2 | +import { withKnobs } from "@storybook/addon-knobs"; |
| 3 | +import { ViewPort, LeftResizable, Fill } from "../../"; |
| 4 | +import { action } from '@storybook/addon-actions'; |
| 5 | +import { green, red, description } from "../Utils"; |
| 6 | +import { CommonHeader } from "../Utils"; |
| 7 | + |
| 8 | +<CommonHeader /> |
| 9 | + |
| 10 | +<Meta title="Basic examples/Resize events" /> |
| 11 | + |
| 12 | +## Resizable space with state controlled size |
| 13 | + |
| 14 | +By default the size of a resizable space is uncontrolled. Therefore the initial size passed is is |
| 15 | +only the initial size of a space and React Spaces deals with any resizing. To keep the size of a |
| 16 | +space controlled in state you need to use the onResizeEnd event to set the new size of a space |
| 17 | +after a resize back to a state value. |
| 18 | + |
| 19 | +<Canvas> |
| 20 | + <Story name="Controlled size"> |
| 21 | + { |
| 22 | + () => { |
| 23 | + const [ size, setSize ] = React.useState("15%"); |
| 24 | + return ( |
| 25 | + <React.StrictMode> |
| 26 | + <ViewPort> |
| 27 | + <LeftResizable size={size} style={red} trackSize={true} onResizeEnd={(newSize) => setSize(newSize)}> |
| 28 | + {description("Left")} |
| 29 | + </LeftResizable> |
| 30 | + <Fill style={green} trackSize={true}>{description("Fill")}</Fill> |
| 31 | + </ViewPort> |
| 32 | + </React.StrictMode> |
| 33 | + ) |
| 34 | + } |
| 35 | + } |
| 36 | + </Story> |
| 37 | +</Canvas> |
| 38 | + |
| 39 | +## Cancelling resize with onResizeStart |
| 40 | + |
| 41 | +You can cancel a resize by returning `false` from a onResizeStart event handler. |
| 42 | + |
| 43 | +<Canvas> |
| 44 | + <Story name="Cancelled resize"> |
| 45 | + { |
| 46 | + () => { |
| 47 | + return ( |
| 48 | + <React.StrictMode> |
| 49 | + <ViewPort> |
| 50 | + <LeftResizable size="15%" style={red} trackSize={true} onResizeStart={() => false}> |
| 51 | + {description("Left")} |
| 52 | + </LeftResizable> |
| 53 | + <Fill style={green} trackSize={true}>{description("Fill")}</Fill> |
| 54 | + </ViewPort> |
| 55 | + </React.StrictMode> |
| 56 | + ) |
| 57 | + } |
| 58 | + } |
| 59 | + </Story> |
| 60 | +</Canvas> |
0 commit comments