Skip to content

Commit 74ce944

Browse files
committed
Add proptypes to notifications and duration prop
1 parent 7dcd469 commit 74ce944

File tree

2 files changed

+52
-27
lines changed

2 files changed

+52
-27
lines changed

components/SLDSNotification/index.js

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,38 @@ const classNames = require("classnames");
1414
import SLDSButton from "../SLDSButton";
1515
import {Icon} from "../SLDSIcons";
1616

17+
const displayName = 'SLDSNotification';
18+
const propTypes = {
19+
className: React.PropTypes.string,
20+
content: React.PropTypes.node,
21+
dismissible: React.PropTypes.bool,
22+
duration: React.PropTypes.number,
23+
icon: React.PropTypes.string,
24+
onDismiss: React.PropTypes.func,
25+
texture: React.PropTypes.bool,
26+
theme: React.PropTypes.oneOf(["success", "warning", "error", "offline"]),
27+
variant: React.PropTypes.oneOf(["alert", "toast"]),
28+
};
29+
30+
const defaultProps = {
31+
dismissible: true,
32+
};
33+
1734
class SLDSNotification extends React.Component {
1835
constructor(props){
1936
super(props);
2037
this.state = { isOpen: true };
2138
}
2239

40+
componentDidMount() {
41+
if(this.props.duration) {
42+
const that = this;
43+
setTimeout(function() {
44+
that.setState({ isOpen: false});
45+
}, that.props.duration);
46+
}
47+
}
48+
2349
renderIcon(){
2450
if(this.props.icon){
2551
let classes = "";
@@ -57,7 +83,7 @@ class SLDSNotification extends React.Component {
5783

5884
onDismiss(){
5985
if(this.props.onDismiss) this.props.onDismiss();
60-
this.setState({isOpen:false});
86+
this.setState({isOpen: false});
6187
}
6288

6389
renderAlertContent(){
@@ -94,34 +120,25 @@ class SLDSNotification extends React.Component {
94120

95121
render(){
96122
if(this.state.isOpen){
97-
return(
98-
<div className="slds-notify-container">
99-
<div className={this.getClassName()} role="alert">
100-
<span className="slds-assistive-text">{this.props.theme}</span>
101-
{this.renderClose()}
102-
{this.renderAlertContent()}
103-
{this.renderToastContent()}
123+
return (
124+
<div className="slds-notify-container">
125+
<div className={this.getClassName()} role="alert">
126+
<span className="slds-assistive-text">{this.props.theme}</span>
127+
{this.renderClose()}
128+
{this.renderAlertContent()}
129+
{this.renderToastContent()}
130+
</div>
104131
</div>
105-
</div>
106-
);
132+
);
107133
}else{
108134
return null;
109135
}
110136
}
111137
}
112-
SLDSNotification.propTypes = {
113-
content: React.PropTypes.node,
114-
icon: React.PropTypes.string,
115-
variant: React.PropTypes.oneOf(["alert", "toast"]),
116-
theme: React.PropTypes.oneOf(["success", "warning", "error", "offline"]),
117-
texture: React.PropTypes.bool,
118-
dismissible: React.PropTypes.bool,
119-
onDismiss: React.PropTypes.func,
120-
};
121138

122-
SLDSNotification.defaultProps = {
123-
dismissible: true
124-
};
139+
SLDSNotification.displayName = displayName;
140+
SLDSNotification.propTypes = propTypes;
141+
SLDSNotification.defaultProps = defaultProps;
125142

126143
module.exports = SLDSNotification;
127144

demo/pages/HomePage/NotificationSection.jsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ module.exports = React.createClass( {
2222

2323
getInitialState () {
2424
return {
25-
modalIsOpen: false
25+
modalIsOpen: false,
26+
toastsAreOpen: true,
2627
};
2728
},
2829

@@ -89,9 +90,14 @@ module.exports = React.createClass( {
8990
Notification
9091
</a>
9192
</h3>
92-
<h4>
93-
* All notifications are fixed and centered at the top of the screen.
94-
</h4>
93+
<ul className="slds-p-vertical--medium">
94+
<li>
95+
<h4>* All notifications are fixed and centered at the top of the screen.</h4>
96+
</li>
97+
<li>
98+
<h4>* Toasts default duration is five seconds and will then disappear.</h4>
99+
</li>
100+
</ul>
95101
<PrismCode className='language-markup'>
96102
{require('raw-loader!../../code-snippets/SLDSNotification.txt')}
97103
</PrismCode>
@@ -102,6 +108,9 @@ module.exports = React.createClass( {
102108
<div className="slds-p-bottom--small">
103109
{this.state.modalIsOpen ? null: <SLDSNotification variant='alert' theme='success' icon='notification' texture={true} content={successMsg} onDismiss={this.dismissToast} />}
104110
</div>
111+
<div className="slds-p-bottom--small">
112+
{this.state.modalIsOpen ? null: <SLDSNotification variant='alert' theme='success' icon='notification' texture={true} content={successMsg} duration={5000} onDismiss={this.dismissToast} />}
113+
</div>
105114
<div className="slds-p-bottom--small">
106115
{this.state.modalIsOpen ? null: <SLDSNotification variant='alert' theme='error' icon='warning' texture={true} content={errorMsg} onDismiss={this.dismissToast} />}
107116
</div>
@@ -113,7 +122,6 @@ module.exports = React.createClass( {
113122

114123
<div className="slds-p-vertical--small">
115124
<h4 className="slds-text-heading--small ">Toasts</h4>
116-
117125
<div className="demo-only" style={toastStyle}>
118126
Base
119127
{this.state.modalIsOpen ? null: <SLDSNotification variant='toast' theme='success' icon='notification' content={successMsg} onDismiss={this.dismissToast} />}

0 commit comments

Comments
 (0)