Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit ef4fc21

Browse files
authored
feat(Dialog): add component (#790)
* feat(Dialog): add component * fix test * restore changes in header * remove test * add entry * use Header instead of Box
1 parent f964b9a commit ef4fc21

File tree

14 files changed

+485
-0
lines changed

14 files changed

+485
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
2626
- Remove handledProps from behaviors @jurokapsiar ([#805](https://github.com/stardust-ui/react/pull/805))
2727
- Add `create` shorthand factory to `Header` component @layershifter ([#809](https://github.com/stardust-ui/react/pull/809))
2828
- Add `keyframeParams` prop in the `Animation` component and the `animation` prop @mnajdova ([#794](https://github.com/stardust-ui/react/pull/794))
29+
- Add `Dialog` component @layershifter ([#790](https://github.com/stardust-ui/react/pull/790))
2930

3031
### Fixes
3132
- Handle `onClick` and `onFocus` on ListItems correctly @layershifter ([#779](https://github.com/stardust-ui/react/pull/779))
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Button, Dialog } from '@stardust-ui/react'
2+
import * as React from 'react'
3+
4+
const DialogExampleContent: React.FC = () => (
5+
<Dialog
6+
cancelButton="Cancel"
7+
confirmButton="Confirm"
8+
content="Are you sure you want to confirm this action?"
9+
header="Action confirmation"
10+
trigger={<Button content="Open a dialog" />}
11+
/>
12+
)
13+
14+
export default DialogExampleContent
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as React from 'react'
2+
3+
import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample'
4+
import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection'
5+
6+
const DialogContentExamples = () => (
7+
<ExampleSection title="Content">
8+
<ComponentExample
9+
title="Content"
10+
description="A dialog can contain a content."
11+
examplePath="components/Dialog/Content/DialogExampleContent"
12+
/>
13+
</ExampleSection>
14+
)
15+
16+
export default DialogContentExamples
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Button, Dialog } from '@stardust-ui/react'
2+
import * as React from 'react'
3+
4+
const DialogExample: React.FC = () => (
5+
<Dialog
6+
cancelButton="Cancel"
7+
confirmButton="Confirm"
8+
header="Action confirmation"
9+
trigger={<Button content="Open a dialog" />}
10+
/>
11+
)
12+
13+
export default DialogExample
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as React from 'react'
2+
3+
import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample'
4+
import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection'
5+
6+
const DialogTypesExamples = () => (
7+
<ExampleSection title="Types">
8+
<ComponentExample
9+
title="Dialog"
10+
description="A basic dialog."
11+
examplePath="components/Dialog/Types/DialogExample"
12+
/>
13+
</ExampleSection>
14+
)
15+
16+
export default DialogTypesExamples
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { Button, Dialog, Divider, Grid, Label, Segment } from '@stardust-ui/react'
2+
import * as React from 'react'
3+
4+
type DialogExampleCallbacksState = {
5+
log: string[]
6+
logCount: number
7+
open: boolean
8+
}
9+
10+
export default class DialogExampleCallbacks extends React.Component<
11+
{},
12+
DialogExampleCallbacksState
13+
> {
14+
state = {
15+
log: [],
16+
logCount: 0,
17+
open: false,
18+
}
19+
20+
handleOpen = () => {
21+
this.setState({ open: true })
22+
this.writeLog('onOpen()')
23+
}
24+
25+
handleClose = (callbackName: string) => () => {
26+
console.log(callbackName)
27+
this.setState({ open: false })
28+
this.writeLog(callbackName)
29+
}
30+
31+
clearLog = () => this.setState({ log: [], logCount: 0 })
32+
33+
writeLog = (eventName: string) =>
34+
this.setState({
35+
log: [`${new Date().toLocaleTimeString()}: ${eventName}`, ...this.state.log].slice(0, 20),
36+
logCount: this.state.logCount + 1,
37+
})
38+
39+
render() {
40+
const { log, logCount, open } = this.state
41+
42+
return (
43+
<Grid columns={2}>
44+
<Dialog
45+
cancelButton="Cancel"
46+
confirmButton="Confirm"
47+
onCancel={this.handleClose('onCancel()')}
48+
onConfirm={this.handleClose('onConfirm()')}
49+
onOpen={this.handleOpen}
50+
open={open}
51+
header="Action confirmation"
52+
trigger={<Button content="Open a dialog" />}
53+
/>
54+
55+
<Segment>
56+
<Button onClick={this.clearLog}>Clear</Button>
57+
Event Log <Label circular>{logCount}</Label>
58+
{log.length > 0 && <Divider />}
59+
<pre>
60+
{log.map((e, i) => (
61+
<div key={i}>{e}</div>
62+
))}
63+
</pre>
64+
</Segment>
65+
</Grid>
66+
)
67+
}
68+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as React from 'react'
2+
3+
import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample'
4+
import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection'
5+
6+
const DialogUsageExamples = () => (
7+
<ExampleSection title="Usage">
8+
<ComponentExample
9+
title="Callbacks"
10+
description="A dialog has different callbacks."
11+
examplePath="components/Dialog/Usage/DialogExampleCallbacks"
12+
/>
13+
</ExampleSection>
14+
)
15+
16+
export default DialogUsageExamples
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import * as React from 'react'
2+
3+
import Content from './Content'
4+
import Types from './Types'
5+
import Usage from './Usage'
6+
7+
const DialogExamples = () => (
8+
<>
9+
<Types />
10+
<Content />
11+
<Usage />
12+
</>
13+
)
14+
15+
export default DialogExamples

0 commit comments

Comments
 (0)