Skip to content

Commit c293ce0

Browse files
committed
Restyle alert vs toast notifications
1 parent 9d13ece commit c293ce0

File tree

4 files changed

+99
-34
lines changed

4 files changed

+99
-34
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/pages/HomePage/ModalSection.jsx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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
},
@@ -133,10 +138,7 @@ module.exports = React.createClass( {
133138
</PrismCode>
134139

135140
<div className='slds-p-vertical--large'>
136-
<SLDSButton
137-
label='Open Modal'
138-
variant='brand'
139-
onClick={this.openModal} />
141+
<SLDSButton label='Open Modal' variant='brand' onClick={this.openModal} />
140142
<SLDSModal
141143
size='medium'
142144
directional={true}
@@ -150,6 +152,17 @@ module.exports = React.createClass( {
150152
onRequestClose={this.closeModal}>
151153
{this.getModalContent()}
152154
</SLDSModal>
155+
156+
<SLDSButton label='Open Prompt' variant='brand' onClick={this.togglePrompt} />
157+
<SLDSModal
158+
prompt='error'
159+
size='medium'
160+
isOpen={this.state.promptIsOpen}
161+
title={<span>Service Unavailable</span>}
162+
footer={[ <SLDSButton label='ok' variant='neutral' onClick={this.togglePrompt} /> ]}
163+
>
164+
Sit nulla est ex deserunt exercitation anim occaecat. Nostrud ullamco deserunt aute id consequat veniam incididunt duis in sint irure nisi.
165+
</SLDSModal>
153166
</div>
154167
</div>
155168
);

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)