-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Dialog): add new Dialog component (#8)
* feat(Dialog): create new component * docs: update list example to use List component * feat(Dialog): no need for onClose event, there is already full controll from buttons * feat(Dialog) export dialog in main index
- Loading branch information
Showing
15 changed files
with
364 additions
and
10 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React, {PropTypes} from 'react' | ||
import Dialog from '../../../../src/Dialog/Dialog' | ||
import DialogBody from '../../../../src/Dialog/DialogBody' | ||
import DialogTitle from '../../../../src/Dialog/DialogTitle' | ||
import DialogHeader from '../../../../src/Dialog/DialogHeader' | ||
import DialogFooter from '../../../../src/Dialog/DialogFooter' | ||
import Button from '../../../../src/Button/Button' | ||
import List from '../../../../src/List/List' | ||
import ListItem from '../../../../src/List/ListItem' | ||
|
||
class Standard extends React.PureComponent { | ||
|
||
constructor(props){ | ||
super(props); | ||
this.state={isOpen: false}; | ||
} | ||
|
||
render () { | ||
return ( | ||
<div> | ||
<Button | ||
primary | ||
raised | ||
onClick={()=> { this.setState({isOpen: !this.state.isOpen}) }} | ||
> | ||
Show dialog | ||
</Button> | ||
<Dialog open={this.state.isOpen}> | ||
<DialogHeader> | ||
<DialogTitle>Choose a Ringtone</DialogTitle> | ||
</DialogHeader> | ||
<DialogBody scrollable> | ||
<List> | ||
<ListItem>None</ListItem> | ||
<ListItem>Callisto</ListItem> | ||
<ListItem>Ganymede</ListItem> | ||
<ListItem>Luna</ListItem> | ||
<ListItem>Marimba</ListItem> | ||
<ListItem>Schwifty</ListItem> | ||
<ListItem>Callisto</ListItem> | ||
<ListItem>Ganymede</ListItem> | ||
<ListItem>Luna</ListItem> | ||
<ListItem>Marimba</ListItem> | ||
<ListItem>Schwifty</ListItem> | ||
</List> | ||
</DialogBody> | ||
<DialogFooter> | ||
<Button compact onClick={()=> { this.setState({isOpen: false}) }}>Cancel</Button> | ||
<Button compact onClick={()=> { this.setState({isOpen: false}) }}>Accept</Button> | ||
</DialogFooter> | ||
</Dialog> | ||
</div> | ||
) | ||
} | ||
} | ||
export default Standard; |
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,42 @@ | ||
import React, {PropTypes} from 'react' | ||
import Dialog from '../../../../src/Dialog/Dialog' | ||
import DialogBody from '../../../../src/Dialog/DialogBody' | ||
import DialogTitle from '../../../../src/Dialog/DialogTitle' | ||
import DialogHeader from '../../../../src/Dialog/DialogHeader' | ||
import DialogFooter from '../../../../src/Dialog/DialogFooter' | ||
import Button from '../../../../src/Button/Button' | ||
|
||
class Standard extends React.PureComponent { | ||
|
||
constructor(props){ | ||
super(props); | ||
this.state={isOpen: false}; | ||
} | ||
|
||
render () { | ||
return ( | ||
<div> | ||
<Button | ||
primary | ||
raised | ||
onClick={()=> { this.setState({isOpen: !this.state.isOpen}) }} | ||
> | ||
Show dialog | ||
</Button> | ||
<Dialog open={this.state.isOpen}> | ||
<DialogHeader> | ||
<DialogTitle>Use Google's location service?</DialogTitle> | ||
</DialogHeader> | ||
<DialogBody> | ||
Let Google help apps determine location. | ||
</DialogBody> | ||
<DialogFooter> | ||
<Button compact onClick={()=> { this.setState({isOpen: false}) }}>Decline</Button> | ||
<Button compact onClick={()=> { this.setState({isOpen: false}) }}>Accept</Button> | ||
</DialogFooter> | ||
</Dialog> | ||
</div> | ||
) | ||
} | ||
} | ||
export default Standard; |
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,28 @@ | ||
import React, {PropTypes} from 'react' | ||
import ReactDOM from 'react-dom' | ||
import Standard from './Standard' | ||
import Scrollable from './Scrollable' | ||
|
||
class Template extends React.PureComponent { | ||
|
||
static propTypes = { | ||
children: PropTypes.node, | ||
} | ||
|
||
componentDidMount() { | ||
const standard = document.getElementById("simple"); | ||
ReactDOM.render(<Standard/>, standard); | ||
|
||
const scrollable = document.getElementById("scrollable"); | ||
ReactDOM.render(<Scrollable/>, scrollable); | ||
} | ||
|
||
render () { | ||
return ( | ||
<div> | ||
{this.props.children} | ||
</div> | ||
) | ||
} | ||
} | ||
export default Template; |
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,66 @@ | ||
--- | ||
title: "Dialog" | ||
--- | ||
|
||
### Simple dialog | ||
```react-snippet | ||
simple | ||
``` | ||
```jsx | ||
<Button | ||
primary | ||
raised | ||
onClick={()=> { this.setState({isOpen: !this.state.isOpen}) }} | ||
> | ||
Show dialog | ||
</Button> | ||
<Dialog open={this.state.isOpen}> | ||
<DialogHeader> | ||
<DialogTitle>Use Google's location service?</DialogTitle> | ||
</DialogHeader> | ||
<DialogBody> | ||
Let Google help apps determine location. | ||
</DialogBody> | ||
<DialogFooter> | ||
<Button compact onClick={()=> { this.setState({isOpen: false}) }}>Decline</Button> | ||
<Button compact onClick={()=> { this.setState({isOpen: false}) }}>Accept</Button> | ||
</DialogFooter> | ||
</Drawer> | ||
``` | ||
### Scrollable dialog | ||
```react-snippet | ||
scrollable | ||
``` | ||
```jsx | ||
<Button | ||
primary | ||
raised | ||
onClick={()=> { this.setState({isOpen: !this.state.isOpen}) }} | ||
> | ||
Show scrollable dialog | ||
</Button> | ||
<Dialog open={this.state.isOpen}> | ||
<DialogHeader> | ||
<DialogTitle>Choose a Ringtone</DialogTitle> | ||
</DialogHeader> | ||
<DialogBody scrollable> | ||
<List> | ||
<ListItem>None</ListItem> | ||
<ListItem>Callisto</ListItem> | ||
<ListItem>Ganymede</ListItem> | ||
<ListItem>Luna</ListItem> | ||
<ListItem>Marimba</ListItem> | ||
<ListItem>Schwifty</ListItem> | ||
<ListItem>Callisto</ListItem> | ||
<ListItem>Ganymede</ListItem> | ||
<ListItem>Luna</ListItem> | ||
<ListItem>Marimba</ListItem> | ||
<ListItem>Schwifty</ListItem> | ||
</List> | ||
</DialogBody> | ||
<DialogFooter> | ||
<Button compact onClick={()=> { this.setState({isOpen: false}) }}>Cancel</Button> | ||
<Button compact onClick={()=> { this.setState({isOpen: false}) }} >Accept</Button> | ||
</DialogFooter> | ||
</Drawer> | ||
``` |
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,37 @@ | ||
import React, { Component, PropTypes } from 'react'; | ||
import classnames from 'classnames'; | ||
import { ROOT, OPEN, SURFACE, BACKDROP, SCROLL_LOCK } from './constants'; | ||
|
||
class Dialog extends Component { | ||
|
||
static propTypes = { | ||
className: PropTypes.string, | ||
children: PropTypes.node, | ||
open: PropTypes.bool, | ||
} | ||
|
||
componentWillReceiveProps(nextProps) { | ||
if (nextProps.open) document.body.classList.add(SCROLL_LOCK); | ||
else document.body.classList.remove(SCROLL_LOCK); | ||
} | ||
|
||
render() { | ||
const { className, children, open, ...otherProps } = this.props; | ||
|
||
return ( | ||
<div | ||
className={classnames(ROOT, { | ||
[OPEN]: open, | ||
}, className)} | ||
{...otherProps} | ||
> | ||
<div className={SURFACE}> | ||
{children} | ||
</div> | ||
<div className={BACKDROP} /> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default Dialog; |
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,22 @@ | ||
import React, { PropTypes } from 'react'; | ||
import classnames from 'classnames'; | ||
import { BODY, SCROLLABLE } from './constants'; | ||
|
||
const propTypes = { | ||
className: PropTypes.string, | ||
children: PropTypes.node, | ||
scrollable: PropTypes.bool, | ||
}; | ||
|
||
const DialogBody = ({ className, children, scrollable, ...otherProps }) => ( | ||
<section | ||
className={classnames(BODY, { | ||
[SCROLLABLE]: scrollable, | ||
}, className)} | ||
{...otherProps} | ||
> | ||
{children} | ||
</section> | ||
); | ||
DialogBody.propTypes = propTypes; | ||
export default DialogBody; |
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,31 @@ | ||
import React, { PropTypes } from 'react'; | ||
import classnames from 'classnames'; | ||
import { FOOTER, FOOTER_BUTTON, FOOTER_BUTTON_CANCEL, FOOTER_BUTTON_ACCEPT } from './constants'; | ||
|
||
const propTypes = { | ||
className: PropTypes.string, | ||
children: PropTypes.node, | ||
}; | ||
|
||
const DialogFooter = ({ className, children }) => { | ||
const last = children.length - 1; | ||
const actions = React.Children.map(children, (action, index) => { | ||
const isLastAction = last === index; | ||
const actionClasses = action.props.className; | ||
const classes = classnames(actionClasses, 'mdc-button', FOOTER_BUTTON, { | ||
[FOOTER_BUTTON_CANCEL]: !isLastAction, | ||
[FOOTER_BUTTON_ACCEPT]: isLastAction, | ||
}); | ||
return React.cloneElement(action, { key: index, className: classes }); | ||
}); | ||
|
||
return ( | ||
<footer | ||
className={classnames(FOOTER, className)} | ||
> | ||
{actions} | ||
</footer> | ||
); | ||
}; | ||
DialogFooter.propTypes = propTypes; | ||
export default DialogFooter; |
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,18 @@ | ||
import React, { PropTypes } from 'react'; | ||
import classnames from 'classnames'; | ||
import { HEADER } from './constants'; | ||
|
||
const propTypes = { | ||
className: PropTypes.string, | ||
children: PropTypes.node, | ||
}; | ||
|
||
const DialogHeader = ({ className, children }) => ( | ||
<header | ||
className={classnames(HEADER, className)} | ||
> | ||
{children} | ||
</header> | ||
); | ||
DialogHeader.propTypes = propTypes; | ||
export default DialogHeader; |
Oops, something went wrong.