Skip to content

Commit fdffb08

Browse files
committed
Merge pull request #57 from salesforce-ux/notifications
Notifications
2 parents 9d13ece + 2fb261e commit fdffb08

File tree

6 files changed

+135
-56
lines changed

6 files changed

+135
-56
lines changed

components/SLDSModal/index.jsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ module.exports = React.createClass( {
115115
const modalClass = {
116116
'slds-modal': true,
117117
'slds-fade-in-open':this.state.revealed,
118-
'slds-modal--large':this.props.size === 'large'
118+
'slds-modal--large':this.props.size === 'large',
119+
'slds-modal--prompt':this.isPrompt()
119120
};
120121

121122
return <div
@@ -135,7 +136,6 @@ module.exports = React.createClass( {
135136

136137
{this.props.children}
137138

138-
{this.isPrompt() ? this.props.footer : null}
139139
</div>
140140

141141
{this.footerComponent()}
@@ -167,12 +167,13 @@ module.exports = React.createClass( {
167167

168168
const footerClass = {
169169
'slds-modal__footer': true,
170-
'slds-modal__footer--directional': this.props.directional
170+
'slds-modal__footer--directional': this.props.directional,
171+
'slds-theme--default': this.isPrompt()
171172
};
172173

173174
const hasFooter = this.props.footer && this.props.footer.length > 0;
174175

175-
if (!this.isPrompt() && hasFooter ) {
176+
if (hasFooter ) {
176177
footer = (<div className={cx(footerClass)}>{this.props.footer}</div>);
177178
}
178179

@@ -191,6 +192,7 @@ module.exports = React.createClass( {
191192

192193
if (this.isPrompt()) {
193194
headerClasses.push(`slds-theme--${this.props.prompt}`);
195+
headerClasses.push('slds-theme--alert-texture');
194196
headingClasses.push('slds-text-heading--small');
195197
} else {
196198
headingClasses.push('slds-text-heading--medium')

components/SLDSNotification/index.js

Lines changed: 71 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,38 @@ class SLDSNotification extends React.Component {
2020
this.state = { isOpen: true };
2121
}
2222

23-
getClassName() {
24-
return classNames(this.props.className, 'slds-notify ', {
25-
[`slds-notify--${this.props.variant}`]: this.props.variant,
26-
[`slds-theme--${this.props.theme}`]: this.props.theme,
27-
[`slds-theme--alert-texture-animated`]: this.props.texture,
28-
});
29-
}
30-
3123
renderIcon(){
3224
if(this.props.icon){
33-
return <Icon category='utility' name={this.props.icon} size='small' className='slds-m-right--x-small slds-col slds-no-flex' />;
25+
let classes = '';
26+
if(this.props.variant === 'alert') {
27+
classes = 'slds-m-right--x-small';
28+
}
29+
else if(this.props.variant === 'toast') {
30+
classes = 'slds-m-right--small slds-col slds-no-flex';
31+
}
32+
return <Icon category='utility' name={this.props.icon} size='small' className={classes} />;
33+
}
34+
}
35+
36+
renderClose(){
37+
let that = this;
38+
if(this.props.dismissible){
39+
let size = '';
40+
if(this.props.variant === 'alert') {
41+
size = 'medium';
42+
}
43+
else if(this.props.variant === 'toast') {
44+
size = 'large';
45+
}
46+
return <SLDSButton
47+
label='Dismiss Notification'
48+
variant='icon'
49+
iconName='close'
50+
iconSize={size}
51+
inverse={true}
52+
className='slds-button slds-notify__close'
53+
onClick={that.onDismiss.bind(that)}
54+
/>
3455
}
3556
}
3657

@@ -39,28 +60,47 @@ class SLDSNotification extends React.Component {
3960
this.setState({isOpen:false});
4061
}
4162

63+
renderAlertContent(){
64+
if(this.props.variant === 'alert'){
65+
return(
66+
<h2>
67+
{this.renderIcon()}
68+
{this.props.content}
69+
</h2>
70+
);
71+
}
72+
}
73+
74+
renderToastContent(){
75+
if(this.props.variant === 'toast'){
76+
return(
77+
<section className="notify__content slds-grid">
78+
{this.renderIcon()}
79+
<div className="slds-col slds-align-middle">
80+
<h2 className="slds-text-heading--small ">{this.props.content}</h2>
81+
</div>
82+
</section>
83+
);
84+
}
85+
}
86+
87+
getClassName() {
88+
return classNames(this.props.className, 'slds-notify ', {
89+
[`slds-notify--${this.props.variant}`]: this.props.variant,
90+
[`slds-theme--${this.props.theme}`]: this.props.theme,
91+
[`slds-theme--alert-texture-animated`]: this.props.texture,
92+
});
93+
}
94+
4295
render(){
4396
if(this.state.isOpen){
4497
return(
4598
<div className="slds-notify-container">
4699
<div className={this.getClassName()} role="alert">
47-
<SLDSButton
48-
label='Dismiss Notification'
49-
variant='icon'
50-
iconName='close'
51-
iconSize='large'
52-
inverse={true}
53-
className='slds-button slds-notify__close'
54-
onClick={this.onDismiss.bind(this)}
55-
/>
56-
57100
<span className="slds-assistive-text">{this.props.theme}</span>
58-
59-
<section className="notify__content slds-grid">
60-
{this.renderIcon()}
61-
<h2 className="slds-col slds-align-middle slds-text-heading--small">{this.props.content}</h2>
62-
</section>
63-
101+
{this.renderClose()}
102+
{this.renderAlertContent()}
103+
{this.renderToastContent()}
64104
</div>
65105
</div>
66106
);
@@ -75,7 +115,13 @@ SLDSNotification.propTypes = {
75115
variant: React.PropTypes.oneOf(['alert', 'toast']),
76116
theme: React.PropTypes.oneOf(['success', 'warning', 'error', 'offline']),
77117
texture: React.PropTypes.bool,
118+
dismissible: React.PropTypes.bool,
78119
onDismiss: React.PropTypes.func,
79120
};
121+
122+
SLDSNotification.defaultProps = {
123+
dismissible: true
124+
};
125+
80126
module.exports = SLDSNotification;
81127

demo/code-snippets/SLDSModal.txt

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@ Default Props Prop Values
44
* directional=false [true, false] If true, aligns buttons left and right in Footer
55
* tagline='' Optional tagline underneath Header title
66

7-
<SLDSButton
8-
label='Open Modal'
9-
variant='brand'
10-
onClick={this.openModal}
11-
/>
12-
7+
<SLDSButton label='Open Modal' variant='brand' onClick={this.openModal} />
138
<SLDSModal
149
directional={true}
1510
isOpen={this.state.modalIsOpen}
@@ -20,6 +15,17 @@ Default Props Prop Values
2015
<SLDSButton key='nextBtn' label='Next' variant='brand' onClick={this.handleSubmitModal} />
2116
]}
2217
onRequestClose={this.closeModal}
23-
>
18+
>
2419
{this.getModalContent()}
2520
</SLDSModal>
21+
22+
<SLDSButton label='Open Prompt' variant='neutral' onClick={this.togglePrompt} />
23+
<SLDSModal
24+
prompt='error'
25+
size='medium'
26+
isOpen={this.state.promptIsOpen}
27+
title={<span>Service Unavailable</span>}
28+
footer={[ <SLDSButton label='Got it' variant='neutral' onClick={this.togglePrompt} /> ]}
29+
>
30+
Sit nulla est ex deserunt exercitation anim occaecat. Nostrud ullamco deserunt aute id consequat veniam incididunt duis in sint irure nisi.
31+
</SLDSModal>
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
1+
Alerts
22
<SLDSNotification variant='alert' theme='success' icon='notification' texture={true} content={successMsg} onDismiss={this.dismissToast} />
33
<SLDSNotification variant='alert' theme='error' icon='warning' texture={true} content={errorMsg} onDismiss={this.dismissToast} />
4-
<SLDSNotification variant='toast' theme='success' icon='notification' content={successMsg} />
4+
<SLDSNotification variant='alert' icon='user' content={offlineMsg} dismissible={false} onDismiss={this.dismissToast} />
55

6+
Toasts
7+
<SLDSNotification variant='toast' theme='success' icon='notification' content={successMsg} onDismiss={this.dismissToast} />
68
<SLDSModal
79
isOpen={this.state.modalIsOpen}
8-
toast={<SLDSNotification variant='toast' theme='error' icon='warning' texture={true} content={errorMessage} />}
10+
toast={<SLDSNotification variant='toast' theme='error' icon='warning' content={errorMsg} onDismiss={this.dismissToast} />}
911
title={<span>Lightning Design System: Style with Ease</span>}
1012
footer={[
1113
<SLDSButton key='cancelBtn' label='Cancel' variant='neutral' onClick={this.closeModal} />,
1214
<SLDSButton key='saveBtn' label='Save' variant='brand' onClick={this.handleSubmitModal} />
13-
]}
14-
onRequestClose={this.closeModal}
15-
>
16-
{this.getModalContent()}
15+
]}
16+
onRequestClose={this.closeModal}
17+
>
18+
{this.getModalContent()}
1719
</SLDSModal>

demo/pages/HomePage/ModalSection.jsx

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
Copyright (c) 2015, salesforce.com, inc. All rights reserved.
3-
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4-
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
5-
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
6-
Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
7-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8-
*/
2+
Copyright (c) 2015, salesforce.com, inc. All rights reserved.
3+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4+
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
5+
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
6+
Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
7+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8+
*/
99

1010
'use strict';
1111

@@ -24,14 +24,19 @@ module.exports = React.createClass( {
2424

2525
getInitialState () {
2626
return {
27-
modalIsOpen: false
27+
modalIsOpen: false,
28+
promptIsOpen:false
2829
};
2930
},
3031

3132
openModal () {
3233
this.setState({modalIsOpen: true});
3334
},
3435

36+
togglePrompt () {
37+
this.setState({promptIsOpen: !this.state.promptIsOpen});
38+
},
39+
3540
closeModal () {
3641
this.setState({modalIsOpen: false});
3742
},
@@ -132,11 +137,9 @@ module.exports = React.createClass( {
132137
{require("raw-loader!../../code-snippets/SLDSModal.txt")}
133138
</PrismCode>
134139

135-
<div className='slds-p-vertical--large'>
136-
<SLDSButton
137-
label='Open Modal'
138-
variant='brand'
139-
onClick={this.openModal} />
140+
<div className='slds-p-vertical--medium'>
141+
<h4 className="slds-text-heading--small ">Base</h4>
142+
<SLDSButton label='Open Modal' variant='brand' onClick={this.openModal} />
140143
<SLDSModal
141144
size='medium'
142145
directional={true}
@@ -150,7 +153,23 @@ module.exports = React.createClass( {
150153
onRequestClose={this.closeModal}>
151154
{this.getModalContent()}
152155
</SLDSModal>
156+
153157
</div>
158+
159+
<div className='slds-p-vertical--medium'>
160+
<h4 className="slds-text-heading--small">Prompt</h4>
161+
<SLDSButton label='Open Prompt' variant='neutral' onClick={this.togglePrompt} />
162+
<SLDSModal
163+
prompt='error'
164+
size='medium'
165+
isOpen={this.state.promptIsOpen}
166+
title={<span>Service Unavailable</span>}
167+
footer={[ <SLDSButton label='Got it' variant='neutral' onClick={this.togglePrompt} /> ]}
168+
>
169+
Sit nulla est ex deserunt exercitation anim occaecat. Nostrud ullamco deserunt aute id consequat veniam incididunt duis in sint irure nisi.
170+
</SLDSModal>
171+
</div>
172+
154173
</div>
155174
);
156175
}

demo/pages/HomePage/NotificationSection.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ module.exports = React.createClass( {
7979
render() {
8080
let successMsg = ['New contact added ', <a href="#" key="0123">Sara Smith</a>];
8181
let errorMsg = 'There was a problem updating the record.';
82+
let offlineMsg = 'Sandbox: TestOrg123';
8283
let toastStyle = { display: 'inline-block'};
8384
return (
8485

@@ -102,6 +103,9 @@ module.exports = React.createClass( {
102103
<div className="slds-p-bottom--small">
103104
{this.state.modalIsOpen ? null: <SLDSNotification variant='alert' theme='error' icon='warning' texture={true} content={errorMsg} onDismiss={this.dismissToast} />}
104105
</div>
106+
<div className="slds-p-bottom--small">
107+
{this.state.modalIsOpen ? null: <SLDSNotification variant='alert' icon='user' content={offlineMsg} dismissible={false} onDismiss={this.dismissToast} />}
108+
</div>
105109
</div>
106110
</div>
107111

0 commit comments

Comments
 (0)