Skip to content

Commit 9bf6170

Browse files
committed
modal progress
1 parent 5bbb288 commit 9bf6170

File tree

4 files changed

+76
-39
lines changed

4 files changed

+76
-39
lines changed

components/SLDSModal/index.jsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ module.exports = React.createClass( {
9494
</div>
9595

9696
</div>
97-
9897
</Modal>
9998
);
10099
},
@@ -103,13 +102,26 @@ module.exports = React.createClass( {
103102

104103
if(this.state.isOpen !== prevState.isOpen){
105104
if(window && document && document.body){
106-
document.body.style.overflow = this.state.isOpen?'hidden':'inherit';
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+
}
114+
if(!this.state.isOpen){
115+
if(this.isMounted()){
116+
const el = this.getDOMNode().parentNode;
117+
if(el && el.getAttribute('data-slds-modal')){
118+
React.unmountComponentAtNode(el);
119+
document.body.removeChild(el);
120+
}
121+
}
107122
}
108123
}
109124

110-
if(this.props.isOpen !== prevProps.isOpen){
111-
this.setState({isOpen:this.props.isOpen});
112-
}
113125

114126
}
115127

components/SLDSModal/manager.jsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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 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);
22+
}
23+
};
24+
25+
module.exports = SLDSModalManager;

components/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1212
import SLDSPicklistBase from './SLDSPicklistBase';
1313
import SLDSSettings from './SLDSSettings';
1414
import SLDSButton from './SLDSButton';
15+
import SLDSModal from './SLDSModal';
16+
import SLDSModalManager from './SLDSModal/manager';
1517

1618
module.exports = {
1719
SLDSPicklistBase: SLDSPicklistBase,
1820
SLDSSettings: SLDSSettings,
19-
SLDSButton: SLDSButton
21+
SLDSButton: SLDSButton,
22+
SLDSModal: SLDSModal,
23+
SLDSModalManager: SLDSModalManager
2024
};

demo/pages/HomePage/ModalSection.jsx

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@ import {EventUtil} from '../../../components/utils';
1717
import SLDSDateInput from '../../../components/SLDSDateInput';
1818

1919
import SLDSModal from '../../../components/SLDSModal';
20+
import {SLDSModalManager} from '../../../components';
2021

2122

22-
const items = ['Paddy\'s Pub', 'Tyrell Corp', 'Paper St. Soap Company', 'Nakatomi Investments', 'Acme Landscaping', 'Acme Construction'];
2323

2424

25-
import Modal from 'react-modal';
26-
2725

2826

2927
const customStyles = {
@@ -60,6 +58,7 @@ module.exports = React.createClass( {
6058

6159
openModal () {
6260
this.setState({modalIsOpen: true});
61+
SLDSModalManager.trigger(this.getModal());
6362
},
6463

6564
closeModal () {
@@ -78,33 +77,14 @@ module.exports = React.createClass( {
7877
// EventUtil.trap(e);
7978
},
8079

81-
render() {
82-
return (
83-
84-
85-
<div className='slds-p-around--medium'>
86-
87-
<h3 className='slds-text-heading--medium slds-truncate'>
88-
Modal (Work in progress)
89-
</h3>
90-
{/*
91-
<PrismCode className='language-markup'>
92-
{require("raw-loader!../../code-snippets/SLDSLookupPage.txt")}
93-
</PrismCode>
94-
*/}
95-
96-
<div className='slds-p-vertical--large'>
97-
<SLDSButton flavor='brand' onClick={this.openModal}>
98-
Open Modal
99-
</SLDSButton>
100-
101-
<SLDSModal
80+
getModal () {
81+
return (<SLDSModal
10282
title={<span>Super Stuff</span>}
10383
footer={[
10484
<button className='slds-button slds-button--neutral' onClick={this.closeModal}>Cancel</button>,
10585
<button className='slds-button slds-button--neutral slds-button--brand' onClick={this.handleSubmitModal}>Save</button>
10686
]}
107-
isOpen={this.state.modalIsOpen}>
87+
isOpen={true}>
10888

10989
<SLDSButton flavor='brand' onClick={this.handleButtonClick}>
11090
Test Button
@@ -116,22 +96,38 @@ module.exports = React.createClass( {
11696
<p>Dolor eiusmod sunt ex incididunt cillum quis nostrud velit duis sit officia. Lorem aliqua enim laboris do dolor eiusmod officia. Mollit incididunt nisi consectetur esse laborum eiusmod pariatur proident. Eiusmod et adipisicing culpa deserunt
11797
nostrud ad veniam nulla aute est. Labore esse esse cupidatat amet velit id elit consequat minim ullamco mollit enim excepteur ea.</p>
11898
</div>
119-
99+
{/*
120100
<SLDSModal
121101
title={<span>Super Stuff</span>}
122102
isOpen={true}>
103+
AAA
104+
AAA
105+
</SLDSModal>
106+
*/}
107+
</SLDSModal>);
108+
},
123109

124-
AAA
110+
render() {
111+
return (
125112

126-
<SLDSModal
127-
title={<span>Super Stuff</span>}
128-
isOpen={true}>BBB</SLDSModal>
129113

130-
AAA
114+
<div className='slds-p-around--medium'>
131115

132-
</SLDSModal>
116+
<h3 className='slds-text-heading--medium slds-truncate'>
117+
Modal (Work in progress)
118+
</h3>
119+
{/*
120+
<PrismCode className='language-markup'>
121+
{require("raw-loader!../../code-snippets/SLDSLookupPage.txt")}
122+
</PrismCode>
123+
*/}
124+
125+
<div className='slds-p-vertical--large'>
126+
<SLDSButton flavor='brand' onClick={this.openModal}>
127+
Open Modal
128+
</SLDSButton>
133129

134-
</SLDSModal>
130+
{this.getModal()}
135131

136132
</div>
137133
</div>

0 commit comments

Comments
 (0)