1
0
mirror of https://github.com/yldio/copilot.git synced 2024-11-14 07:10:05 +02:00

Adding modal to side nav and refactoring

This commit is contained in:
Alex Windett 2016-11-23 11:59:37 +00:00
parent 01a527063e
commit 9e0193de7d
5 changed files with 82 additions and 29 deletions

View File

@ -8,6 +8,7 @@ const Modal = React.createClass({
children: React.PropTypes.node, children: React.PropTypes.node,
className: React.PropTypes.string, className: React.PropTypes.string,
name: React.PropTypes.string, name: React.PropTypes.string,
trigger: React.PropTypes.func.isRequired
}, },
getInitialState: function() { getInitialState: function() {
@ -19,7 +20,7 @@ const Modal = React.createClass({
handleReveal: function(e) { handleReveal: function(e) {
e.preventDefault(); e.preventDefault();
this.setState({ this.setState({
active: true active: this.state.active ? false : true
}); });
}, },
@ -27,37 +28,68 @@ const Modal = React.createClass({
const { const {
children, children,
className, className,
name name,
trigger
} = this.props; } = this.props;
const {
active
} = this.state;
const {
handleReveal
} = this;
const triggerClass = classNames(
className,
styles.trigger
);
const modal = classNames( const modal = classNames(
className, className,
styles.modal, styles.modal,
this.state.active ? styles['modal-active'] : ''
); );
const overlay = classNames( const overlay = classNames(
className, className,
styles.overlay, styles.overlay,
this.state.active ? styles['overlay-active'] : ''
); );
return ( return (
<div> <div>
<a <span
aria-label={name} aria-label={name}
onClick={this.handleReveal} className={triggerClass}
href="#"
onClick={handleReveal}
role="link"
tabIndex={0} tabIndex={0}
> >
Click me to reveal modal {trigger()}
</a> </span>
<div className={overlay} /> { active ? (
<section aria-label={name} className={modal} > <div
<span className={styles.close}>X</span> aria-label="overlay"
<h2>This is the Modal</h2> className={overlay}
onClick={handleReveal}
role="link"
tabIndex={-2}
/>
) : null }
{ active ? (
<div aria-label={name} className={modal} >
<button
className={styles.close}
href='#'
onClick={handleReveal}
role="dialog"
tabIndex={-1}
>X</button>
{children} {children}
</section> </div>
) : null }
</div> </div>
); );
} }

View File

@ -12,12 +12,18 @@ const Column = require('../column');
const Modal = require('./index.js'); const Modal = require('./index.js');
const styles = require('./style.css'); const styles = require('./style.css');
const trigger = () => {
return (
<p>This is the trigger</p>
)
};
nmodule.exports = ReactDOM.renderToString( nmodule.exports = ReactDOM.renderToString(
<Base> <Base>
<Row> <Row>
<Column> <Column>
<Modal active name="modal1" > <Modal name="modal1" trigger={trigger} >
Create an Instance <h2>This is the Modal</h2>
</Modal> </Modal>
</Column> </Column>
</Row> </Row>
@ -31,10 +37,16 @@ nmodule.exports = ReactDOM.renderToString(
const React = require('react'); const React = require('react');
const Modal = require('ui/button'); const Modal = require('ui/button');
const trigger = () => {
return (
<p>This is the trigger</p>
)
};
module.exports = () => { module.exports = () => {
return ( return (
<Modal> <Modal name="modal1" trigger={trigger} >
Hello World <h2>This is the Modal</h2>
</Modal> </Modal>
); );
} }

View File

@ -1,4 +1,4 @@
.overlay-active { .overlay {
background: rgba(0, 0, 0, 0.4); background: rgba(0, 0, 0, 0.4);
height: 100%; height: 100%;
left: 0; left: 0;
@ -10,7 +10,7 @@
.modal { .modal {
background: white; background: white;
display: none; display: block;
left: 50%; left: 50%;
margin: 0 auto; margin: 0 auto;
padding: 20px; padding: 20px;
@ -20,17 +20,24 @@
z-index: 1; z-index: 1;
} }
.modal-active {
display: block;
}
.close { .close {
background: red; background-color: #FFFFFF;
border: solid 1px #D8D8D8;
border-radius: 4px;
box-shadow: 0 2px 0 0 rgba(0, 0, 0, 0.05);
color: black; color: black;
font-size: 24px; cursor: #000000;
font-size: 20px;
padding: 0 10px; padding: 0 10px;
position: absolute; position: absolute;
right: -20px; right: -20px;
text-align: center; text-align: center;
text-decoration: none;
top: -15px; top: -15px;
} }
.trigger {
cursor: pointer;
display: inline-block;
outline: none;
}

View File

@ -21,7 +21,8 @@ module.exports = {
Tab: require('./components/tab/readme.md'), Tab: require('./components/tab/readme.md'),
Tabs: require('./components/tabs/readme.md'), Tabs: require('./components/tabs/readme.md'),
Widget: require('./components/widget/readme.md'), Widget: require('./components/widget/readme.md'),
Pagination: require('./components/pagination/readme.md') Pagination: require('./components/pagination/readme.md'),
Modal: require('./components/modal/readme.md')
}, },
FAQ: require('./faq.md') FAQ: require('./faq.md')
}; };

View File

@ -15,5 +15,6 @@ module.exports = {
RadioGroup: require('./components/radio-group'), RadioGroup: require('./components/radio-group'),
Select: require('./components/select'), Select: require('./components/select'),
Widget: require('./components/widget'), Widget: require('./components/widget'),
Pagination: require('./components/pagination') Pagination: require('./components/pagination'),
Modal: require('./components/modal')
}; };