Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
198 changes: 166 additions & 32 deletions client/components/notice/index.jsx
Original file line number Diff line number Diff line change
@@ -1,51 +1,61 @@
/**
* External dependencies
*/
var React = require( 'react/addons' ),
joinClasses = require( 'react/lib/joinClasses' ),
noop = require( 'lodash/noop' );
import React, { PropTypes } from 'react';
import classnames from 'classnames';
import noop from 'lodash/noop';
import ScreenReaderText from '../screen-reader-text';
import i18n from 'lib/mixins/i18n';

require( './style.scss' );

/**
* Internal dependencies
*/
var Button = require( '../button' ),
Gridicon = require( '../gridicon' ),
ScreenReaderText = require( '../screen-reader-text' );

require( './style.scss' );
import Gridicon from '../gridicon';

module.exports = React.createClass( {
export default React.createClass( {
mixins: [ i18n.mixin ],
displayName: 'SimpleNotice',
dismissTimeout: null,

getDefaultProps: function() {
getDefaultProps() {
return {
status: 'is-info',
duration: 0,
status: null,
showDismiss: true,
className: '',
onClick: noop
onDismissClick: noop
};
},

propTypes: {
// we should validate the allowed statuses
status: React.PropTypes.string,
showDismiss: React.PropTypes.bool,
status: PropTypes.string,
showDismiss: PropTypes.bool,
isCompact: PropTypes.bool,
duration: React.PropTypes.number,
isCompact: React.PropTypes.bool,
text: React.PropTypes.oneOfType( [
React.PropTypes.string,
React.PropTypes.object
text: PropTypes.oneOfType( [
PropTypes.oneOfType( [ PropTypes.string, PropTypes.node ] ),
PropTypes.arrayOf( PropTypes.oneOfType( [ PropTypes.string, PropTypes.node ] ) )
] ),
className: React.PropTypes.string
icon: PropTypes.string,
className: PropTypes.string
},

componentDidMount: function() {
componentDidMount() {
if ( this.props.duration > 0 ) {
setTimeout( this.props.onClick, this.props.duration );
this.dismissTimeout = setTimeout( this.props.onDismissClick, this.props.duration );
}
},

componentWillUnmount() {
if ( this.dismissTimeout ) {
clearTimeout( this.dismissTimeout );
}
},

renderChildren: function() {
renderChildren() {
let content;

if ( typeof this.props.children === 'string' ) {
Expand All @@ -62,35 +72,159 @@ module.exports = React.createClass( {
return content;
},

render: function() {
var noticeClass, dismiss;
getIcon() {
let icon;

switch ( this.props.status ) {
case 'is-info':
icon = 'info';
break;
case 'is-success':
icon = 'checkmark';
break;
case 'is-error':
icon = 'notice';
break;
case 'is-warning':
icon = 'notice';
break;
default:
icon = 'info';
break;
}

return icon;
},

render() {
let dismiss;

// The class determines the nature of a notice
// and its status.
noticeClass = joinClasses( 'notice', this.props.status );
let noticeClass = classnames( 'notice', this.props.status );

if ( this.props.isCompact ) {
noticeClass = joinClasses( noticeClass, 'is-compact' );
noticeClass = classnames( noticeClass, 'is-compact' );
}

// By default, a dismiss button is rendered to
// allow the user to hide the notice
if ( this.props.showDismiss ) {
noticeClass = joinClasses( noticeClass, 'is-dismissable' );
noticeClass = classnames( noticeClass, 'is-dismissable' );
dismiss = (
<Button className="notice__dismiss" onClick={ this.props.onClick } >
<span tabIndex="0" className="notice__dismiss" onClick={ this.props.onDismissClick } >
<Gridicon icon="cross" size={ 24 } />
<ScreenReaderText>{ this.translate( 'Dismiss' ) }</ScreenReaderText>
</Button>
</span>
);
}

return (
<div className={ joinClasses( this.props.className, noticeClass ) }>
{ this.renderChildren() }
<div className={ classnames( this.props.className, noticeClass ) }>
<Gridicon className="notice__icon" icon={ this.props.icon || this.getIcon() } size={ 24 } />
<div className="notice__content">
{ this.renderChildren() }
</div>
{ dismiss }
</div>
);
}

} );


// /**
// * External dependencies
// */
// var React = require( 'react/addons' ),
// joinClasses = require( 'react/lib/joinClasses' ),
// noop = require( 'lodash/noop' );

// /**
// * Internal dependencies
// */
// var Button = require( '../button' ),
// Gridicon = require( '../gridicon' ),
// ScreenReaderText = require( '../screen-reader-text' );

// require( './style.scss' );

// module.exports = React.createClass( {
// displayName: 'SimpleNotice',

// getDefaultProps: function() {
// return {
// status: 'is-info',
// showDismiss: true,
// className: '',
// onClick: noop
// };
// },

// propTypes: {
// // we should validate the allowed statuses
// status: React.PropTypes.string,
// showDismiss: React.PropTypes.bool,
// duration: React.PropTypes.number,
// isCompact: React.PropTypes.bool,
// text: React.PropTypes.oneOfType( [
// React.PropTypes.string,
// React.PropTypes.object
// ] ),
// className: React.PropTypes.string
// },

// componentDidMount: function() {
// if ( this.props.duration > 0 ) {
// setTimeout( this.props.onClick, this.props.duration );
// }
// },

// renderChildren: function() {
// let content;

// if ( typeof this.props.children === 'string' ) {
// return <span className="notice__text">{ this.props.children }</span>;
// }

// if ( this.props.text ) {
// content = [ this.props.children ];
// content.unshift( <span key="notice_text" className="notice__text">{ this.props.text }</span> );
// } else {
// content = <span key="notice_text" className="notice__text">{ this.props.children }</span>;
// }

// return content;
// },

// render: function() {
// var noticeClass, dismiss;

// // The class determines the nature of a notice
// // and its status.
// noticeClass = joinClasses( 'notice', this.props.status );

// if ( this.props.isCompact ) {
// noticeClass = joinClasses( noticeClass, 'is-compact' );
// }

// // By default, a dismiss button is rendered to
// // allow the user to hide the notice
// if ( this.props.showDismiss ) {
// noticeClass = joinClasses( noticeClass, 'is-dismissable' );
// dismiss = (
// <Button className="notice__dismiss" onClick={ this.props.onClick } >
// <Gridicon icon="cross" size={ 24 } />
// <ScreenReaderText>{ this.translate( 'Dismiss' ) }</ScreenReaderText>
// </Button>
// );
// }

// return (
// <div className={ joinClasses( this.props.className, noticeClass ) }>
// { this.renderChildren() }
// { dismiss }
// </div>
// );
// }

// } );
Loading