-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathposition-centered-to-parent.stories.js
More file actions
62 lines (54 loc) · 1.69 KB
/
position-centered-to-parent.stories.js
File metadata and controls
62 lines (54 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import React from 'react'
import { action } from '@storybook/addon-actions'
import NewWindow from '../src/NewWindow'
import Button from './components/Button'
import Container from './components/Container'
import { storiesOf } from '@storybook/react'
const stories = storiesOf('react-new-window', module)
class CenteredToParentStory extends React.PureComponent {
state = {
opened: false,
count: 0
}
componentDidMount() {
this.interval = setInterval(() => {
this.setState(prevState => ({ count: prevState.count + 1 }))
}, 1000)
}
componentWillUnmount() {
clearInterval(this.interval)
}
render() {
const { opened, count } = this.state
return (
<Container>
<h2>React New Window</h2>
<h3>prop: center: "parent"</h3>
<h4>Counting {count}...</h4>
<Button onClick={() => this.toggleOpened()}>
{opened ? 'Close the opened window' : 'Open a new window'}
</Button>
{opened && (
<NewWindow
onUnload={() => this.newWindowUnloaded()}
center="parent"
features={{ left: 200, top: 200, width: 400, height: 400 }}
>
<h2>Hi 👋</h2>
<h4>Counting here as well {count}...</h4>
<Button>Keeping the same style as my parent</Button>
</NewWindow>
)}
</Container>
)
}
toggleOpened() {
action(this.state.opened ? 'Closing the window' : 'Opening the window')()
this.setState(prevState => ({ opened: !prevState.opened }))
}
newWindowUnloaded() {
action('Window unloaded')()
this.setState({ opened: false })
}
}
stories.add('Position: Centered To Parent', () => <CenteredToParentStory />)