This repository has been archived by the owner on Dec 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(demo): add helpers for resizable chart demo (#557)
- Loading branch information
Showing
8 changed files
with
139 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
packages/superset-ui-demo/storybook/shared/components/ResizableChartDemo.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import styled from '@superset-ui/style'; | ||
import React, { useState, ReactNode } from 'react'; | ||
import { DecoratorFunction } from '@storybook/addons'; | ||
import ResizablePanel, { Size } from './ResizablePanel'; | ||
|
||
export const SupersetBody = styled.div` | ||
background: #f5f5f5; | ||
padding: 16px; | ||
min-height: 100%; | ||
.panel { | ||
margin-bottom: 0; | ||
} | ||
`; | ||
|
||
export default function ResizableChartDemo({ | ||
children, | ||
panelPadding = 30, | ||
initialSize = { width: 500, height: 300 }, | ||
}: { | ||
children: (innerSize: Size) => ReactNode; | ||
panelPadding?: number; | ||
initialSize?: Size; | ||
}) { | ||
// size are all inner size | ||
const [size, setSize] = useState(initialSize); | ||
return ( | ||
<SupersetBody> | ||
<ResizablePanel initialSize={initialSize} onResize={(e, data) => setSize(data.size)}> | ||
{children({ width: size.width - panelPadding, height: size.height - panelPadding })} | ||
</ResizablePanel> | ||
</SupersetBody> | ||
); | ||
} | ||
|
||
export const withResizableChartDemo: DecoratorFunction<ReactNode> = (storyFn, context) => { | ||
const { | ||
parameters: { initialSize, panelPadding }, | ||
} = context; | ||
return ( | ||
<ResizableChartDemo initialSize={initialSize as Size | undefined} panelPadding={panelPadding}> | ||
{innerSize => storyFn({ ...context, ...innerSize })} | ||
</ResizableChartDemo> | ||
); | ||
}; |
40 changes: 40 additions & 0 deletions
40
packages/superset-ui-demo/storybook/shared/components/ResizablePanel.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React, { PropsWithChildren, ReactNode } from 'react'; | ||
import { ResizableBox, ResizableBoxProps, ResizeCallbackData } from 'react-resizable'; | ||
|
||
import 'react-resizable/css/styles.css'; | ||
|
||
export type Size = ResizeCallbackData['size']; | ||
|
||
export default function ResizablePanel({ | ||
children, | ||
heading = undefined, | ||
initialSize = { width: 500, height: 300 }, | ||
minConstraints = [100, 100] as [number, number], | ||
onResize, | ||
...props | ||
}: PropsWithChildren<Omit<ResizableBoxProps, 'width' | 'height'>> & { | ||
heading?: ReactNode; | ||
initialSize?: Size; | ||
}) { | ||
const { width, height } = initialSize; | ||
return ( | ||
<ResizableBox | ||
className="panel" | ||
width={width} | ||
height={height} | ||
minConstraints={minConstraints} | ||
onResize={ | ||
onResize | ||
? (e, data) => { | ||
const { size } = data; | ||
onResize(e, { ...data, size }); | ||
} | ||
: undefined | ||
} | ||
{...props} | ||
> | ||
{heading ? <div className="panel-heading">{heading}</div> : null} | ||
<div className="panel-body">{children}</div> | ||
</ResizableBox> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3210,7 +3210,7 @@ | |
simplebar-react "^1.0.0-alpha.6" | ||
ts-dedent "^1.1.0" | ||
|
||
"@storybook/[email protected]", "@storybook/components@^5.2.5": | ||
"@storybook/[email protected]": | ||
version "5.3.19" | ||
resolved "https://registry.yarnpkg.com/@storybook/components/-/components-5.3.19.tgz#aac1f9eea1247cc85bd93b10fca803876fb84a6b" | ||
integrity sha512-3g23/+ktlocaHLJKISu9Neu3XKa6aYP2ctDYkRtGchSB0Q55hQsUVGO+BEVuT7Pk2D59mVCxboBjxcRoPUY4pw== | ||
|
@@ -3960,6 +3960,13 @@ | |
"@types/react" "*" | ||
"@types/webpack" "*" | ||
|
||
"@types/react-resizable@^1.7.2": | ||
version "1.7.2" | ||
resolved "https://registry.yarnpkg.com/@types/react-resizable/-/react-resizable-1.7.2.tgz#ff7f6d67394abb6f64207fcc574ffccb932d8a97" | ||
integrity sha512-6c6L94+VOksr9838LDrlYeucic2+0qkGnwolGE77YJztYHCWSucQV0e9+Qyl+uHpJTBRS95A5JESBg5NgCAC3A== | ||
dependencies: | ||
"@types/react" "*" | ||
|
||
"@types/[email protected]": | ||
version "11.0.4" | ||
resolved "https://registry.yarnpkg.com/@types/react-syntax-highlighter/-/react-syntax-highlighter-11.0.4.tgz#d86d17697db62f98046874f62fdb3e53a0bbc4cd" | ||
|
@@ -14590,7 +14597,7 @@ [email protected]: | |
fbjs "^0.8.9" | ||
loose-envify "^1.3.1" | ||
|
||
prop-types@^15.5.0, prop-types@^15.5.10, prop-types@^15.5.4, prop-types@^15.5.7, prop-types@^15.5.8, prop-types@^15.6.0, prop-types@^15.6.1, prop-types@^15.6.2, prop-types@^15.7.2: | ||
prop-types@15.x, prop-types@^15.5.0, prop-types@^15.5.10, prop-types@^15.5.4, prop-types@^15.5.7, prop-types@^15.5.8, prop-types@^15.6.0, prop-types@^15.6.1, prop-types@^15.6.2, prop-types@^15.7.2: | ||
version "15.7.2" | ||
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5" | ||
integrity sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ== | ||
|
@@ -15091,6 +15098,14 @@ react-prop-types@^0.4.0: | |
dependencies: | ||
warning "^3.0.0" | ||
|
||
react-resizable@^1.10.1: | ||
version "1.10.1" | ||
resolved "https://registry.yarnpkg.com/react-resizable/-/react-resizable-1.10.1.tgz#f0c2cf1d83b3470b87676ce6d6b02bbe3f4d8cd4" | ||
integrity sha512-Jd/bKOKx6+19NwC4/aMLRu/J9/krfxlDnElP41Oc+oLiUWs/zwV1S9yBfBZRnqAwQb6vQ/HRSk3bsSWGSgVbpw== | ||
dependencies: | ||
prop-types "15.x" | ||
react-draggable "^4.0.3" | ||
|
||
react-select@^1.2.1: | ||
version "1.3.0" | ||
resolved "https://registry.yarnpkg.com/react-select/-/react-select-1.3.0.tgz#1828ad5bf7f3e42a835c7e2d8cb13b5c20714876" | ||
|
@@ -16635,12 +16650,11 @@ store2@^2.7.1: | |
resolved "https://registry.yarnpkg.com/store2/-/store2-2.11.0.tgz#307636a239014ef4d8f1c8b47afe903509484fc8" | ||
integrity sha512-WeIZ5+c/KzBSutSqOjUCAkk1qTLVBcYUuvrhNx8ndjLZKdZRfP6Vv7AOxlynuL6tVU/6zt6e2CTHwWI5KE+fKg== | ||
|
||
storybook-addon-jsx@^7.1.0: | ||
version "7.2.0" | ||
resolved "https://registry.yarnpkg.com/storybook-addon-jsx/-/storybook-addon-jsx-7.2.0.tgz#06f3345c2e98180336f9a32b523d51eef07ff7b4" | ||
integrity sha512-DW0oYXINrfcKPH/48vjKFHwg4DnujWCuqjjJtd/YeDla50fELf5SxvW4Qyp9Gd77ccDnFZKokWNCfuS5tMxtsw== | ||
storybook-addon-jsx@^7.2.3: | ||
version "7.2.3" | ||
resolved "https://registry.yarnpkg.com/storybook-addon-jsx/-/storybook-addon-jsx-7.2.3.tgz#754c54407d2f656568bb40cd6d2a85fb92cf1798" | ||
integrity sha512-8KJNtejqsYHcdgCI7Mf+1UlBG7Ya4JyFiDMwmT5ZixhKNcbJh9yUdF+/yYp4rguhRuCxZ783gs1XiD0REVzDug== | ||
dependencies: | ||
"@storybook/components" "^5.2.5" | ||
copy-to-clipboard "^3.0.8" | ||
js-beautify "^1.8.8" | ||
react-element-to-jsx-string "^14.3.1" | ||
|
af7421d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to following URLs: