Skip to content

Commit af1ec25

Browse files
committed
Added extra docs for useCurrentSpace() hook
1 parent 5a55b97 commit af1ec25

File tree

5 files changed

+50
-9
lines changed

5 files changed

+50
-9
lines changed

src/components/stories/00-docs/03-UsefulEvents.stories.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const Example = () => {
2020
const shouldResize = // logic to determine if resizing should be possible
2121

2222
return (
23-
<LeftResizable onResizeStart={() => shouldResize}>
23+
<LeftResizable onResizeStart={(resizeType: "resize-left" | "resize-top" | "resize-right" | "resize-bottom") => shouldResize}>
2424
...
2525
</LeftResizable>
2626
)
@@ -42,7 +42,7 @@ const Example = () => {
4242

4343
return (
4444
<ViewPort>
45-
<LeftResizable onResizeEnd={(newSize) => setSize(newSize)}>
45+
<LeftResizable onResizeEnd={(newSize: number, domRect: DOMRect, resizeType: "resize-left" | "resize-top" | "resize-right" | "resize-bottom") => setSize(newSize)}>
4646
...
4747
</LeftResizable>
4848
</ViewPort>

src/components/stories/02-components/Positioned.Resizable.stories.mdx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ import { CommonHeader, PropsTable, PropsHeader, Prop, StandardProps } from "../U
1616
<Story name="Properties">
1717
<PropsTable>
1818
<PropsHeader>Positioned properties</PropsHeader>
19-
<Prop name="bottom" type="number | string" description="Bottom offset from edge of parent space." />
19+
<Prop name="bottom" type="number | string" description="Bottom offset from edge of parent space. (optional)" />
2020
<Prop name="left" type="number | string" description="Left offset from edge of parent space." />
21-
<Prop name="right" type="number | string" description="Right offset from edge of parent space." />
21+
<Prop name="right" type="number | string" description="Right offset from edge of parent space. (optional)" />
2222
<Prop name="top" type="number | string" description="Top offset from edge of parent space." />
23-
<Prop name="width" type="number | string" description="Width of space" />
24-
<Prop name="height" type="number | string" description="Height of space" />
23+
<Prop name="width" type="number | string" description="Width of space (optional)" />
24+
<Prop name="height" type="number | string" description="Height of space (optional)" />
25+
<Prop name="resizable" type="(ResizeType | 'resize-left' | 'resize-top' | 'resize-right' | 'resize-bottom')[]" description="Array of sides that are resizable" />
2526
<StandardProps />
2627
</PropsTable>
2728
</Story>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { Meta, Story, Canvas, Props } from "@storybook/addon-docs/blocks";
2+
import { withKnobs } from "@storybook/addon-knobs";
3+
import { ViewPort, Bottom } from "../../";
4+
import { green, description, lorem } from "../Utils";
5+
import { CommonHeader, PropsTable, StandardProps, AnchoredProps } from "../Utils";
6+
7+
<CommonHeader />
8+
9+
<Meta title="Hooks/useCurrentSpace" />
10+
11+
## useCurrentSpace()
12+
13+
Hook that gives information / events on closest parent space. For example:
14+
15+
```jsx
16+
const InnerComponent = () => {
17+
const space = useCurrentSpace(); // information on <Space.LeftResizable />
18+
19+
return <div>{$`width: ${space.size.width}, height: ${space.size.height}`}</div>
20+
}
21+
22+
<Space.ViewPort>
23+
<Space.LeftResizable size="20%">
24+
<InnerComponent />
25+
</Space.LeftResizable>
26+
</Space.ViewPort>
27+
28+
```
29+
30+
The hook returns the following information:
31+
32+
- **size** - sizing information of the space from the DOM
33+
- **layer** - current layer of the space
34+
- **startMouseDrag** / **startTouchDrag** - a handler which can be attached to inner components to start drag behaviour on <Positioned /> spaces. i.e. could be used to implement a title bar in a dialog which can be used to drag the dialog.
35+
36+
```jsx
37+
<button onMouseDown={space.startMouseDrag} onTouchStart={space.startTouchDrag}>
38+
Drag handle
39+
</button>
40+
```

src/components/stories/02-components/Testing.stories.mdx renamed to src/components/stories/04-testing/Testing.stories.mdx

File renamed without changes.

src/components/stories/Utils.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export const StandardProps = () => (
7474
/>
7575
<Prop
7676
name="centerContent"
77-
type="CenterType.Vertical ('vertical'), CenterType.HorizontalVertical ('horizontalVertical')"
77+
type="CenterType.Vertical | CenterType.HorizontalVertical | 'vertical' | 'horizontalVertical'"
7878
description="Apply centering to children."
7979
/>
8080
<Prop name="className" type="string" description="A class name to apply to the space element." />
@@ -143,7 +143,7 @@ export const ResizableProps = () => (
143143
/>
144144
<Prop
145145
name="handlePlacement"
146-
type="ResizeHandlePlacement.OverlayInside ('overlay-inside'), ResizeHandlePlacement.Inside ('inside'), ResizeHandlePlacement.OverlayBoundary ('overlay-boundary')"
146+
type="ResizeHandlePlacement.OverlayInside | 'overlay-inside' | ResizeHandlePlacement.Inside | 'inside' | ResizeHandlePlacement.OverlayBoundary | 'overlay-boundary'"
147147
default="overlay-inside"
148148
description="Determines method of placement of the resize handle. By default the handle is placed overlays content inside the space ('overlay'). Other options are to take up space within the space ('inside') or to be overlayed in the middle of the boundary of the space and neighbouring spaces ('overlay-boundary')"
149149
/>
@@ -156,7 +156,7 @@ export const ResizableProps = () => (
156156
/>
157157
<Prop
158158
name="onResizeEnd"
159-
type="(newSize: number, newRect: DOMRect) => void"
159+
type="(newSize: number, newRect: DOMRect, resizeType: ResizeType | 'resize-left' | 'resize-top' | 'resize-right' | 'resize-bottom') => void"
160160
description="Triggered when a resize ends. The final size in pixels of the space in after the resize is passed as the first parameter."
161161
/>
162162
</>

0 commit comments

Comments
 (0)