Skip to content

Commit 7413207

Browse files
committed
modal trigger progress
1 parent 9bf6170 commit 7413207

File tree

6 files changed

+243
-85
lines changed

6 files changed

+243
-85
lines changed

components/SLDSModal/index.jsx

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,10 @@ import React from 'react';
1313
import SLDSButton from '../SLDSButton';
1414
import {Icon} from '../SLDSIcons';
1515
import {EventUtil} from '../utils';
16-
import SLDSDateInput from '../SLDSDateInput';
1716

1817

1918
import Modal from 'react-modal';
2019

21-
22-
2320
const customStyles = {
2421
content : {
2522
position : 'default',
@@ -51,10 +48,20 @@ module.exports = React.createClass( {
5148

5249
getInitialState () {
5350
return {
54-
isOpen: this.props.isOpen
51+
isOpen: this.props.isOpen,
52+
revealed: false
5553
};
5654
},
5755

56+
componentDidMount () {
57+
if(!this.state.revealed){
58+
setTimeout(()=>{
59+
this.setState({revealed:true});
60+
}.bind(this));
61+
}
62+
this.updateBodyScroll();
63+
},
64+
5865
openModal () {
5966
this.setState({isOpen: true});
6067
},
@@ -67,14 +74,19 @@ module.exports = React.createClass( {
6774
this.closeModal();
6875
},
6976

70-
render() {
71-
return (
72-
<Modal
73-
isOpen={this.state.isOpen}
74-
onRequestClose={this.closeModal}
75-
style={customStyles}
76-
overlayClassName='slds-modal-backdrop slds-modal-backdrop--open' >
77-
<div className='slds-modal slds-fade-in-open'
77+
updateBodyScroll () {
78+
if(window && document && document.body){
79+
if(this.state.isOpen){
80+
document.body.style.overflow = 'hidden';
81+
}
82+
else{
83+
document.body.style.overflow = 'inherit';
84+
}
85+
}
86+
},
87+
88+
getModal() {
89+
return <div className={'slds-modal' +(this.state.revealed?' slds-fade-in-open':'')}
7890
onClick={this.closeModal}>
7991
<div className='slds-modal__container' onClick={(e)=>{EventUtil.trap(e);}}>
8092
<div className='slds-modal__header'>
@@ -83,34 +95,41 @@ module.exports = React.createClass( {
8395
<Icon name='close' category='utility' size='small'/>
8496
<span className='slds-assistive-text'>Close</span>
8597
</SLDSButton>
98+
</div>
99+
100+
<div className='slds-modal__content'>
101+
86102
{this.props.children}
87103

88104
</div>
89-
90105
<div className='slds-modal__footer'>
91106
{this.props.footer}
92107
</div>
93108

94109
</div>
95110

96-
</div>
111+
</div>;
112+
},
113+
114+
render() {
115+
return (
116+
<Modal
117+
isOpen={this.state.isOpen}
118+
onRequestClose={this.closeModal}
119+
style={customStyles}
120+
overlayClassName={'slds-modal-backdrop'+ (this.state.revealed?' slds-modal-backdrop--open':'')} >
121+
{this.getModal()}
97122
</Modal>
98123
);
99124
},
100125

101126
componentDidUpdate (prevProps, prevState) {
102127

103128
if(this.state.isOpen !== prevState.isOpen){
104-
if(window && document && document.body){
105-
if(this.state.isOpen){
106-
document.body.style.overflow = 'hidden';
107-
}
108-
else{
109-
if(document.body.className && document.body.className.indexOf('ReactModal__Body--open')<0){
110-
document.body.style.overflow = 'inherit';
111-
}
112-
}
113-
}
129+
130+
this.updateBodyScroll();
131+
132+
114133
if(!this.state.isOpen){
115134
if(this.isMounted()){
116135
const el = this.getDOMNode().parentNode;

components/SLDSModal/manager.jsx

Lines changed: 131 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,138 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1010
'use strict';
1111

1212
import React from 'react';
13+
import SLDSButton from '../SLDSButton';
14+
import {Icon} from '../SLDSIcons';
1315
import {EventUtil} from '../utils';
14-
import SLDSModal from '../index';
15-
16-
const SLDSModalManager = {
17-
trigger: (comp) => {
18-
const el = document.createElement('span');
19-
el.setAttribute('data-slds-modal', true);
20-
document.body.appendChild(el);
21-
React.render(comp, el);
16+
17+
18+
import Modal from 'react-modal';
19+
20+
const customStyles = {
21+
content : {
22+
position : 'default',
23+
top : 'default',
24+
left : 'default',
25+
right : 'default',
26+
bottom : 'default',
27+
border : 'default',
28+
background : 'default',
29+
overflow : 'default',
30+
WebkitOverflowScrolling : 'default',
31+
borderRadius : 'default',
32+
outline : 'default',
33+
padding : 'default'
34+
},
35+
overlay : {
36+
backgroundColor: 'default'
2237
}
2338
};
2439

25-
module.exports = SLDSModalManager;
40+
module.exports = React.createClass( {
41+
42+
getDefaultProps () {
43+
return {
44+
title:'',
45+
isOpen:false
46+
};
47+
},
48+
49+
getInitialState () {
50+
return {
51+
isOpen: this.props.isOpen,
52+
revealed: false
53+
};
54+
},
55+
56+
componentDidMount () {
57+
if(!this.state.revealed){
58+
setTimeout(()=>{
59+
this.setState({revealed:true});
60+
}.bind(this));
61+
}
62+
this.updateBodyScroll();
63+
},
64+
65+
openModal () {
66+
this.setState({isOpen: true});
67+
},
68+
69+
closeModal () {
70+
this.setState({isOpen: false});
71+
},
72+
73+
handleSubmitModal () {
74+
this.closeModal();
75+
},
76+
77+
updateBodyScroll () {
78+
if(window && document && document.body){
79+
if(this.state.isOpen){
80+
document.body.style.overflow = 'hidden';
81+
}
82+
else{
83+
document.body.style.overflow = 'inherit';
84+
}
85+
}
86+
},
87+
88+
getModal() {
89+
return <div className={'slds-modal' +(this.state.revealed?' slds-fade-in-open':'')}
90+
onClick={this.closeModal}>
91+
<div className='slds-modal__container' onClick={(e)=>{EventUtil.trap(e);}}>
92+
<div className='slds-modal__header'>
93+
<h2 className='slds-text-heading--medium'>{this.props.title}</h2>
94+
<SLDSButton className='slds-button slds-modal__close' onClick={this.closeModal}>
95+
<Icon name='close' category='utility' size='small'/>
96+
<span className='slds-assistive-text'>Close</span>
97+
</SLDSButton>
98+
</div>
99+
100+
<div className='slds-modal__content'>
101+
102+
{this.props.children}
103+
104+
</div>
105+
<div className='slds-modal__footer'>
106+
{this.props.footer}
107+
</div>
108+
109+
</div>
110+
111+
</div>;
112+
},
113+
114+
render() {
115+
return (
116+
<Modal
117+
isOpen={this.state.isOpen}
118+
onRequestClose={this.closeModal}
119+
style={customStyles}
120+
overlayClassName={'slds-modal-backdrop'+ (this.state.revealed?' slds-modal-backdrop--open':'')} >
121+
{this.getModal()}
122+
</Modal>
123+
);
124+
},
125+
126+
componentDidUpdate (prevProps, prevState) {
127+
128+
if(this.state.isOpen !== prevState.isOpen){
129+
130+
this.updateBodyScroll();
131+
132+
if(!this.state.isOpen){
133+
if(this.isMounted()){
134+
const el = this.getDOMNode().parentNode;
135+
if(el && el.getAttribute('data-slds-modal')){
136+
React.unmountComponentAtNode(el);
137+
document.body.removeChild(el);
138+
}
139+
}
140+
}
141+
}
142+
143+
144+
}
145+
146+
147+
});

components/SLDSModal/trigger.jsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
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+
*/
9+
10+
'use strict';
11+
12+
import React from 'react';
13+
import {EventUtil} from '../utils';
14+
import SLDSModal from './index';
15+
16+
const SLDSModalTrigger = {
17+
open: (cfg) => {
18+
const el = document.createElement('span');
19+
el.setAttribute('data-slds-modal', true);
20+
document.body.appendChild(el);
21+
22+
const comp = <SLDSModal
23+
title={cfg.title}
24+
footer={cfg.footer}
25+
isOpen={true}>
26+
{cfg.content}
27+
</SLDSModal>
28+
React.render(comp, el);
29+
}
30+
};
31+
32+
module.exports = SLDSModalTrigger;

components/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ import SLDSPicklistBase from './SLDSPicklistBase';
1313
import SLDSSettings from './SLDSSettings';
1414
import SLDSButton from './SLDSButton';
1515
import SLDSModal from './SLDSModal';
16-
import SLDSModalManager from './SLDSModal/manager';
16+
import SLDSModalTrigger from './SLDSModal/trigger';
1717

1818
module.exports = {
1919
SLDSPicklistBase: SLDSPicklistBase,
2020
SLDSSettings: SLDSSettings,
2121
SLDSButton: SLDSButton,
2222
SLDSModal: SLDSModal,
23-
SLDSModalManager: SLDSModalManager
23+
SLDSModalTrigger: SLDSModalTrigger
2424
};

demo/assets/styles/salesforce-lightning-design-system-scoped.css

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,8 +1829,8 @@ body {
18291829
text-decoration: none;
18301830
cursor: pointer; }
18311831
.slds .slds-modal {
1832-
opacity: 0;
1833-
visibility: hidden;
1832+
opacity: 0.0;
1833+
visibility: visible;
18341834
-webkit-transition: -webkit-transform 0.1s linear, opacity 0.1s linear;
18351835
transition: transform 0.1s linear, opacity 0.1s linear;
18361836
position: fixed;
@@ -1901,8 +1901,8 @@ body {
19011901
.slds .slds-modal-backdrop {
19021902
-webkit-transition-duration: 0.4s;
19031903
transition-duration: 0.4s;
1904-
opacity: 0;
1905-
visibility: hidden;
1904+
opacity: 0.0;
1905+
visibility: visible;
19061906
position: fixed;
19071907
top: 0;
19081908
right: 0;

0 commit comments

Comments
 (0)