Skip to content

Commit 6f1f02c

Browse files
webholicsranzwertig
andcommitted
Add storybook examples
Co-authored-by: Christian Ranz <[email protected]>
1 parent 687ad78 commit 6f1f02c

11 files changed

+681
-21
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -1 +1,13 @@
11
# react-positioning-protal
2+
3+
---
4+
5+
MIT License
6+
7+
Copyright 2020 Mario Volke & Christian Ranz
8+
9+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

package-lock.json

+115
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"test": "run-s test:*",
1010
"test:lint": "eslint ./ --ext .js,.jsx,.ts,.tsx",
1111
"fix": "npm run test:lint -- --fix",
12-
"start": "start-storybook",
12+
"start": "start-storybook -p 3000",
1313
"changes": "update-changelog --dry-run --link-commit https://github.com/codastic/react-positioning-portal/commit/:commit .",
1414
"prerelease": "npm run -s test && update-changelog --link-commit https://github.com/codastic/react-positioning-portal/commit/:commit .",
1515
"release": "release .",
@@ -49,6 +49,8 @@
4949
"@storybook/addon-storysource": "^5.3.13",
5050
"@storybook/react": "^5.3.13",
5151
"@types/react-dom": "^16.9.5",
52+
"@types/react-transition-group": "^4.2.4",
53+
"@types/styled-components": "^5.0.1",
5254
"@typescript-eslint/eslint-plugin": "^2.24.0",
5355
"@typescript-eslint/parser": "^2.24.0",
5456
"babel-loader": "^8.0.6",
@@ -62,8 +64,10 @@
6264
"prettier": "^1.19.1",
6365
"react": "^16.13.1",
6466
"react-dom": "^16.13.1",
67+
"react-transition-group": "^4.3.0",
6568
"rollup": "^2.1.0",
6669
"rollup-plugin-typescript2": "^0.26.0",
70+
"styled-components": "^5.0.1",
6771
"ts-loader": "^6.2.1",
6872
"typescript": "^3.8.3"
6973
}
+128-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import * as React from 'react';
22
import { action } from '@storybook/addon-actions';
33
import { withState, Store } from '@dump247/storybook-state';
4+
import { Transition } from 'react-transition-group';
5+
6+
import Button from '../storybook/Button';
7+
import Flyout from '../storybook/Flyout';
8+
import { globalStyleDecorator } from '../storybook/decorators';
49

510
import PositioningPortal from './PositioningPortal';
611

712
export default {
8-
title: 'PositioningPortal'
13+
title: 'PositioningPortal',
14+
decorators: [globalStyleDecorator]
915
};
1016

1117
const baseStory = (store: Store<{ isOpen: boolean }>) => (
@@ -14,18 +20,17 @@ const baseStory = (store: Store<{ isOpen: boolean }>) => (
1420
onOpen={action('onOpen')}
1521
onShouldClose={() => store.set({ isOpen: false })}
1622
portalContent={
17-
<button
18-
type="button"
19-
onClick={() => store.set({ isOpen: false })}
20-
style={{ width: '20em', height: '10em', border: '1px solid blue' }}
21-
>
22-
Close portal
23-
</button>
23+
<Flyout>
24+
Flyout positioned with portal.
25+
<Button type="button" onClick={() => store.set({ isOpen: false })}>
26+
Close flyout
27+
</Button>
28+
</Flyout>
2429
}
2530
>
26-
<button type="button" onClick={() => store.set({ isOpen: true })}>
31+
<Button type="button" onClick={() => store.set({ isOpen: true })}>
2732
Open portal
28-
</button>
33+
</Button>
2934
</PositioningPortal>
3035
);
3136

@@ -36,3 +41,116 @@ export const scrollableTest = withState({ isOpen: false }, store => (
3641
{baseStory(store)}
3742
</div>
3843
));
44+
45+
export const withAnimation = withState(
46+
{ isOpen: false },
47+
(store: Store<{ isOpen: boolean }>) => (
48+
<PositioningPortal
49+
isOpen={store.state.isOpen}
50+
onOpen={action('onOpen')}
51+
onShouldClose={() => store.set({ isOpen: false })}
52+
portalContent={({
53+
isOpen,
54+
isPositioned,
55+
transitionStarted,
56+
transitionEnded
57+
}) => (
58+
<Transition
59+
addEndListener={(node, done) => {
60+
node.addEventListener('transitionend', done, false);
61+
}}
62+
in={isOpen && isPositioned}
63+
onEnter={transitionStarted}
64+
onExited={transitionEnded}
65+
>
66+
{state => (
67+
<Flyout state={state}>
68+
Flyout positioned with portal.
69+
<Button
70+
type="button"
71+
onClick={() => store.set({ isOpen: false })}
72+
>
73+
Close flyout
74+
</Button>
75+
</Flyout>
76+
)}
77+
</Transition>
78+
)}
79+
>
80+
<Button type="button" onClick={() => store.set({ isOpen: true })}>
81+
Open portal
82+
</Button>
83+
</PositioningPortal>
84+
)
85+
);
86+
87+
export const sameWidthAsParent = withState(
88+
{ isOpen: false },
89+
(store: Store<{ isOpen: boolean }>) => (
90+
<PositioningPortal
91+
isOpen={store.state.isOpen}
92+
onOpen={action('onOpen')}
93+
onShouldClose={() => store.set({ isOpen: false })}
94+
portalContent={({ relatedWidth }) => (
95+
<Flyout relatedWidth={relatedWidth}>
96+
Flyout positioned with portal.
97+
<Button type="button" onClick={() => store.set({ isOpen: false })}>
98+
Close flyout
99+
</Button>
100+
</Flyout>
101+
)}
102+
>
103+
<Button type="button" onClick={() => store.set({ isOpen: true })}>
104+
Open portal which will have same width
105+
</Button>
106+
</PositioningPortal>
107+
)
108+
);
109+
110+
export const noClickOutsideClose = withState(
111+
{ isOpen: false },
112+
(store: Store<{ isOpen: boolean }>) => (
113+
<PositioningPortal
114+
closeOnOutsideClick={false}
115+
isOpen={store.state.isOpen}
116+
onOpen={action('onOpen')}
117+
onShouldClose={() => store.set({ isOpen: false })}
118+
portalContent={
119+
<Flyout>
120+
Flyout positioned with portal.
121+
<Button type="button" onClick={() => store.set({ isOpen: false })}>
122+
Close flyout
123+
</Button>
124+
</Flyout>
125+
}
126+
>
127+
<Button type="button" onClick={() => store.set({ isOpen: true })}>
128+
Open portal
129+
</Button>
130+
</PositioningPortal>
131+
)
132+
);
133+
134+
export const closeOnKeydownEnter = withState(
135+
{ isOpen: false },
136+
(store: Store<{ isOpen: boolean }>) => (
137+
<PositioningPortal
138+
closeOnKeyDown={(event: KeyboardEvent) => event.keyCode === 13}
139+
isOpen={store.state.isOpen}
140+
onOpen={action('onOpen')}
141+
onShouldClose={() => store.set({ isOpen: false })}
142+
portalContent={
143+
<Flyout>
144+
Flyout positioned with portal.
145+
<Button type="button" onClick={() => store.set({ isOpen: false })}>
146+
Close flyout
147+
</Button>
148+
</Flyout>
149+
}
150+
>
151+
<Button type="button" onClick={() => store.set({ isOpen: true })}>
152+
Open portal
153+
</Button>
154+
</PositioningPortal>
155+
)
156+
);

0 commit comments

Comments
 (0)