Skip to content

Commit 69560dd

Browse files
committed
Clean up code
1 parent b58048a commit 69560dd

File tree

7 files changed

+65
-49
lines changed

7 files changed

+65
-49
lines changed

components/SLDSLookup/Menu/Item/index.jsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class Item extends React.Component {
4141
return this.props.onSelect(this.props.id);
4242
}
4343

44+
//Scroll menu item based on up/down mouse keys (assumes all items are the same height)
4445
scrollFocus(){
4546
const height = React.findDOMNode(this).offsetHeight;
4647
if(height && this.props.handleItemFocus){
@@ -62,7 +63,7 @@ class Item extends React.Component {
6263
href={this.props.href}
6364
id={id}
6465
tabIndex="-1"
65-
aria-disabled={this.props.disabled}
66+
aria-disabled={this.props.isDisabled}
6667
role="option"
6768
onClick={this.handleClick.bind(this)}
6869
onMouseDown={this.handleClick.bind(this)}>
@@ -76,11 +77,14 @@ class Item extends React.Component {
7677

7778
Item.propTypes = {
7879
id: React.PropTypes.string,
80+
href: React.PropTypes.string,
81+
searchTerm: React.PropTypes.string,
82+
isActive: React.PropTypes.bool,
83+
isDisabled: React.PropTypes.bool,
7984
setFocus: React.PropTypes.func,
8085
scrollFocus: React.PropTypes.func,
81-
isActive: React.PropTypes.bool,
8286
onSelect: React.PropTypes.func,
83-
searchTerm: React.PropTypes.string,
87+
handleItemFocus: React.PropTypes.func,
8488
};
8589

8690
Item.defaultProps = {

components/SLDSLookup/Menu/index.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class Menu extends React.Component {
1717
this.state = {};
1818
}
1919

20+
//Set filtered list length in parent to determine active indexes for aria-activedescendent
2021
componentDidUpdate(prevProps, prevState){
2122
let list = React.findDOMNode(this.refs.list).children.length;
2223
this.props.getListLength(list);
@@ -26,6 +27,7 @@ class Menu extends React.Component {
2627
return this.props.filterWith(this.props.searchTerm, item);
2728
}
2829

30+
//Scroll menu up/down when using mouse keys
2931
handleItemFocus (itemIndex, itemHeight) {
3032
if(this.refs.list){
3133
React.findDOMNode(this.refs.list).scrollTop = itemIndex * itemHeight;
@@ -51,17 +53,17 @@ class Menu extends React.Component {
5153
renderSearchDetails(){
5254
return(
5355
<button className="slds-button">
54-
<Icon name="search" category="utility" size="x-small" className="slds-icon-text-default" />
55-
{this.props.searchTerm ? '"' + this.props.searchTerm + '"' : ""} in {this.props.type}
56+
<Icon name="search" category="utility" size="x-small" className="slds-icon-text-default" />
57+
{this.props.searchTerm ? '"' + this.props.searchTerm + '"' : ""} in {this.props.type}
5658
</button>
5759
);
5860
}
5961

6062
renderAddItem(){
6163
return(
6264
<button className="slds-button" onClick={this.props.addItem} onMouseDown={this.props.addItem}>
63-
<Icon name="add" category="utility" size="x-small" className="slds-icon-text-default" />
64-
New {this.props.type}
65+
<Icon name="add" category="utility" size="x-small" className="slds-icon-text-default" />
66+
New {this.props.type}
6567
</button>
6668
);
6769
}
@@ -90,14 +92,16 @@ class Menu extends React.Component {
9092

9193
Menu.propTypes = {
9294
searchTerm: React.PropTypes.string,
93-
filterWith: React.PropTypes.func,
94-
onSelect: React.PropTypes.func,
9595
label: React.PropTypes.string,
96+
type: React.PropTypes.string,
97+
listLength: React.PropTypes.number,
98+
focusIndex: React.PropTypes.number,
9699
items: React.PropTypes.array,
100+
onSelect: React.PropTypes.func,
101+
addItem: React.PropTypes.func,
102+
filterWith: React.PropTypes.func,
97103
setFocus: React.PropTypes.func,
98104
getListLength: React.PropTypes.func,
99-
listLength: React.PropTypes.number,
100-
focusIndex: React.PropTypes.number,
101105
};
102106

103107
Menu.defaultProps = {

components/SLDSLookup/index.jsx

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
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
import React, { Component } from 'react';
1111
import Menu from './Menu';
12-
import {Icon, InputIcon, ButtonIcon} from "./../SLDSIcons";
12+
import {Icon, InputIcon} from "./../SLDSIcons";
13+
import SLDSButton from '../SLDSButton';
1314
import {KEYS,EventUtil} from '../utils';
1415
import escapeRegExp from 'lodash.escaperegexp';
1516

@@ -59,9 +60,7 @@ class SLDSLookup extends React.Component {
5960
}
6061

6162
getListLength(qty){
62-
if(qty !== this.state.listLength){
63-
this.setState({listLength:qty});
64-
}
63+
if(qty !== this.state.listLength) this.setState({listLength:qty});
6564
}
6665

6766
//=================================================
@@ -82,7 +81,7 @@ class SLDSLookup extends React.Component {
8281
}
8382

8483
//=================================================
85-
// Basic Event Listeners on Input
84+
// Event Listeners on Input
8685
handleClose() {
8786
this.setState({
8887
isOpen:false,
@@ -127,7 +126,6 @@ class SLDSLookup extends React.Component {
127126
EventUtil.trapImmediate(event);
128127
this.decreaseIndex();
129128
}
130-
131129
//If user hits enter/space key, select current activedescendant item
132130
else if((event.keyCode === KEYS.ENTER || event.keyCode === KEYS.SPACE) && this.state.focusIndex !== null){
133131
EventUtil.trapImmediate(event);
@@ -152,25 +150,25 @@ class SLDSLookup extends React.Component {
152150
focusIndex={this.state.focusIndex}
153151
addItem={this.props.addItem}
154152
type={this.props.type}
155-
/>;
156-
}else{
157-
return null;
153+
/>;
158154
}
159155
}
160156

161157
renderSelectedItem(){
162158
return (
163159
<div className="slds-pill">
164160
<a href="#" className="slds-pill__label">
165-
<span>
166-
<Icon name="account" />
167-
{this.props.items[this.state.selectedIndex].label}
168-
</span>
161+
<Icon name={this.props.type} />
162+
{this.props.items[this.state.selectedIndex].label}
169163
</a>
170-
<button className="slds-button slds-button--icon-bare" onClick={this.handleDeleteSelected.bind(this)} ref="clearSelectedItemButton">
171-
<ButtonIcon name="close" />
172-
<span className="slds-assistive-text">Remove</span>
173-
</button>
164+
<SLDSButton
165+
label='Remove'
166+
variant='icon'
167+
iconName='close'
168+
iconSize='medium'
169+
onClick={this.handleDeleteSelected.bind(this)}
170+
ref="clearSelectedItemButton"
171+
/>
174172
</div>
175173
);
176174
}
@@ -203,7 +201,8 @@ class SLDSLookup extends React.Component {
203201
onBlur={this.handleBlur.bind(this)}
204202
onClick={this.handleClick.bind(this)}
205203
onKeyDown={this.handleKeyDown.bind(this)}
206-
value={this.state.searchTerm} />
204+
value={this.state.searchTerm}
205+
/>
207206
</div>
208207

209208
{this.renderMenu()}
@@ -217,13 +216,20 @@ class SLDSLookup extends React.Component {
217216
SLDSLookup.propTypes = {
218217
items: React.PropTypes.array,
219218
label: React.PropTypes.string,
219+
type: React.PropTypes.string,
220+
addItem: React.PropTypes.func,
221+
filterWith: React.PropTypes.func,
222+
onItemSelect: React.PropTypes.func,
220223
};
221224

222225
SLDSLookup.defaultProps = {
223226
filterWith: defaultFilter,
224227
onItemSelect: function(item){
225-
//console.log('onItemSelect should be defined');
226-
}
228+
//console.log('onItemSelect should be defined');
229+
},
230+
addItem: function(item){
231+
//console.log('onItemSelect should be defined');
232+
},
227233
};
228234

229235
module.exports = SLDSLookup;

components/SLDSModal/index.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1111

1212
import React from 'react';
1313
import SLDSButton from '../SLDSButton';
14-
import {Icon} from '../SLDSIcons';
1514
import {EventUtil} from '../utils';
1615
import SLDSSettings from '../SLDSSettings';
1716
import cx from 'classnames';

demo/code-snippets/SLDSLookupPage.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11

2-
const items = ["Paddy's Pub", "Tyrell Corp", "Paper St. Soap Company"];
2+
const items = [
3+
{label:'Paddy\'s Pub'},
4+
{label:'Tyrell Corp'},
5+
{label:'Paper St. Soap Company'},
6+
{label:'Nakatomi Investments'},
7+
{label:'Acme Landscaping'},
8+
{label:'Acme Construction'}
9+
];
10+
11+
<SLDSLookup items={items} label="Accounts" type="account" />
312

4-
<SLDSLookup items={items} label="Contacts" />

demo/pages/HomePage/LookupBaseSection.jsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ module.exports = React.createClass( {
3636
return {};
3737
},
3838

39-
addItem(){
40-
alert('Add item clicked');
41-
},
42-
43-
4439
render() {
4540
return (
4641

@@ -57,7 +52,7 @@ module.exports = React.createClass( {
5752
</PrismCode>
5853

5954
<div className="slds-p-vertical--large">
60-
<SLDSLookup items={items} label="Accounts" type="account" addItem={this.addItem} />
55+
<SLDSLookup items={items} label="Accounts" type="account" />
6156
</div>
6257

6358
</div>

demo/pages/HomePage/index.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ module.exports = React.createClass( {
5959
</div>
6060
<main className='stage-main slds-grid slds-wrap slds-grow' role='main'>
6161
<div className='region region--main slds-grow slds-size--1-of-1 slds-medium-size--1-of-2 slds-large-size--8-of-12 slds-col-rule--right slds-p-around--large'>
62-
<LookupBaseSection />
6362

6463
<ButtonSection />
6564

65+
<LookupBaseSection />
66+
6667
<PicklistBaseSection />
6768

6869
<ModalSection />
6970

70-
7171
<DatePickerSingleSelectSection />
7272

7373
<IconSection />

0 commit comments

Comments
 (0)