Skip to content

Commit 641db9d

Browse files
committed
Make lookup fixed items optional.
1 parent e73260c commit 641db9d

File tree

6 files changed

+100
-49
lines changed

6 files changed

+100
-49
lines changed

components/SLDSLookup/Menu/ActionItem/index.jsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,20 @@ class ActionItem extends React.Component {
1919
if(nextProps.isActive !== this.props.isActive && nextProps.isActive === true) this.props.setFocus(this.props.id);
2020
}
2121

22+
renderIcon(){
23+
if(this.props.icon){
24+
return <Icon name={this.props.icon} category="utility" size="x-small" className="slds-icon-text-default" />
25+
}
26+
}
27+
2228
render(){
2329
let className = 'slds-button';
2430
if(this.props.isActive) className += ' slds-theme--shade'
2531

2632
return (
2733
<button id={this.props.id} tabIndex="-1" className={className} onClick={this.props.onSelect} onMouseDown={this.props.onSelect}>
28-
<Icon name={this.props.icon} category="utility" size="x-small" className="slds-icon-text-default" />
29-
{this.props.children}
34+
{this.renderIcon()}
35+
{this.props.children}
3036
</button>
3137
)
3238
}

components/SLDSLookup/Menu/index.js

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,58 @@ class Menu extends React.Component {
3535
}
3636
}
3737

38+
getHeader(){
39+
if(this.props.header !== false && this.props.header !== undefined){
40+
41+
let content = (this.props.searchTerm ? '"' + this.props.searchTerm + '"' : "") + ' in ' + this.props.type + 's';
42+
if(this.props.header !== true) content = this.props.header;
43+
44+
let headerActive = false;
45+
this.props.focusIndex === 0 ? headerActive = true: headerActive = false;
46+
47+
return (
48+
<div className="slds-lookup__item">
49+
<ActionItem
50+
id='searchRecords'
51+
icon={this.props.header === true ? 'search' : false}
52+
type={this.props.type}
53+
isActive={headerActive}
54+
setFocus={this.props.setFocus}
55+
onSelect={this.props.headerClick}
56+
>
57+
{content}
58+
</ActionItem>
59+
</div>
60+
)
61+
}
62+
}
63+
64+
getFooter(){
65+
if(this.props.footer != false && this.props.footer !== undefined){
66+
67+
let content = 'New ' + this.props.type;
68+
if(this.props.footer !== true) content = this.props.footer;
69+
70+
let footerActive = false;
71+
this.props.focusIndex === this.props.listLength+1 ? footerActive = true: footerActive = false;
72+
73+
return (
74+
<div className="slds-lookup__item">
75+
<ActionItem
76+
id='addNewItem'
77+
icon={this.props.footer === true ? 'add' : false}
78+
type={this.props.type}
79+
isActive={footerActive}
80+
setFocus={this.props.setFocus}
81+
onSelect={this.props.footerClick}
82+
>
83+
{content}
84+
</ActionItem>
85+
</div>
86+
)
87+
}
88+
}
89+
3890
renderItems(){
3991
return this.props.items.filter(this.filter, this).map((c, i) => {
4092
//isActive means it is aria-activedescendant
@@ -65,35 +117,13 @@ class Menu extends React.Component {
65117

66118
return (
67119
<section>
68-
<div className="slds-lookup__item">
69-
<ActionItem
70-
id='searchRecords'
71-
icon='search'
72-
type={this.props.type}
73-
isActive={isSearchRecordsActive}
74-
setFocus={this.props.setFocus}
75-
onSelect={this.props.onSearchRecords}
76-
>
77-
{this.props.searchTerm ? '"' + this.props.searchTerm + '"' : ""} in {this.props.type + 's'}
78-
</ActionItem>
79-
</div>
120+
{this.getHeader()}
80121

81122
<ul id="list" className="slds-lookup__list" role="presentation" ref="list">
82123
{this.renderItems()}
83124
</ul>
84125

85-
<div className="slds-lookup__item">
86-
<ActionItem
87-
id='addNewItem'
88-
icon='add'
89-
type={this.props.type}
90-
isActive={isNewItemBtnActive}
91-
setFocus={this.props.setFocus}
92-
onSelect={this.props.onNewItem}
93-
>
94-
New {this.props.type}
95-
</ActionItem>
96-
</div>
126+
{this.getFooter()}
97127
</section>
98128
)
99129
}
@@ -109,8 +139,6 @@ Menu.propTypes = {
109139
filterWith: React.PropTypes.func,
110140
getListLength: React.PropTypes.func,
111141
setFocus: React.PropTypes.func,
112-
onSelect: React.PropTypes.func,
113-
addItem: React.PropTypes.func,
114142
};
115143

116144
Menu.defaultProps = {

components/SLDSLookup/index.jsx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,14 @@ class SLDSLookup extends React.Component {
8787
});
8888
}
8989

90-
newItem(){
90+
footerClick(){
9191
this.handleClose();
92-
if(this.props.onNewItem) this.props.onNewItem();
92+
if(this.props.onFooterClick) this.props.onFooterClick();
9393
}
9494

95-
searchRecords(){
95+
headerClick(){
9696
this.handleClose();
97-
if(this.props.onSearchRecords) this.props.onSearchRecords();
97+
if(this.props.onHeaderClick) this.props.onHeaderClick();
9898
}
9999

100100
//=================================================
@@ -153,11 +153,11 @@ class SLDSLookup extends React.Component {
153153
EventUtil.trapImmediate(event);
154154
//If the focus is on the first fixed Action Item in Menu
155155
if(this.state.focusIndex === 0){
156-
this.searchRecords();
156+
this.headerClick();
157157
}
158158
//If the focus is on the last fixed Action Item in Menu
159159
else if(this.state.focusIndex === (this.state.listLength + 1)){
160-
this.newItem();
160+
this.footerClick();
161161
}
162162
//If not, then select menu item
163163
else{
@@ -191,8 +191,10 @@ class SLDSLookup extends React.Component {
191191
getListLength={this.getListLength.bind(this)}
192192
setFocus={this.setFocus.bind(this)}
193193
onSelect={this.selectItem.bind(this)}
194-
onSearchRecords={this.searchRecords.bind(this)}
195-
onNewItem={this.newItem.bind(this)}
194+
header={this.props.header}
195+
headerClick={this.headerClick.bind(this)}
196+
footer={this.props.footer}
197+
footerClick={this.footerClick.bind(this)}
196198
/>;
197199
}
198200
}
@@ -296,16 +298,16 @@ SLDSLookup.propTypes = {
296298
filterWith: React.PropTypes.func,
297299
onItemSelect: React.PropTypes.func,
298300
onChange: React.PropTypes.func,
299-
onNewItem: React.PropTypes.func,
300-
onSearchRecords: React.PropTypes.func,
301-
modal: React.PropTypes["bool"],
302-
disabled: React.PropTypes["bool"],
301+
onFooterClick: React.PropTypes.func,
302+
onHeaderClick: React.PropTypes.func,
303+
modal: React.PropTypes.bool,
304+
disabled: React.PropTypes.bool,
303305
};
304306

305307
SLDSLookup.defaultProps = {
306308
filterWith: defaultFilter,
307309
modal: false,
308-
disabled: false
310+
disabled: false,
309311
};
310312

311313
module.exports = SLDSLookup;

demo/code-snippets/SLDSLookupPage.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
Default Props Prop Values
2+
* header={false} [true, false, custom DOM node]
3+
* footer={false} [true, false, custom DOM node]
4+
5+
true renders default header or footer
6+
false does not render header or footer
7+
pass in custom DOM node to render in header or footer
18

29
const items = [
310
{label:'Paddy\'s Pub'},
@@ -12,9 +19,11 @@ const items = [
1219
items={items}
1320
label="Accounts"
1421
type="account"
22+
header={this.getHeader()}
23+
footer={true}
1524
onChange={this.onChange}
1625
onItemSelect={this.onItemSelect}
17-
onNewItem={this.newItem}
18-
onSearchRecords={this.searchRecords} />
26+
onHeaderClick={this.searchRecords}
27+
onFooterClick={this.newItem} />
1928

2029

demo/pages/HomePage/LookupBaseDynamicSection.jsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ module.exports = React.createClass( {
6565
type="account"
6666
onChange={this.onChange}
6767
onItemSelect={this.selectItem}
68-
onNewItem={this.newItem}
6968
onItemSelect={this.handleItemSelect}
70-
onSearchRecords={this.searchRecords}
7169
/>
7270
</div>
7371

demo/pages/HomePage/LookupBaseSection.jsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ module.exports = React.createClass( {
4040
alert('New Item Clicked');
4141
},
4242

43-
searchRecords(){
44-
alert('Search Records Clicked');
43+
customHeaderClick(){
44+
alert('custom header clicked');
4545
},
4646

4747
onChange(newValue){
@@ -52,6 +52,12 @@ module.exports = React.createClass( {
5252
console.log(item + ' Selected');
5353
},
5454

55+
getHeader(){
56+
return(
57+
<div>MY CUSTOM HEADER</div>
58+
)
59+
},
60+
5561
render() {
5662
return (
5763

@@ -72,10 +78,12 @@ module.exports = React.createClass( {
7278
items={items}
7379
label="Accounts"
7480
type="account"
81+
header={this.getHeader()}
82+
onHeaderClick={this.customHeaderClick}
83+
footer={true}
84+
onFooterClick={this.newItem}
7585
onChange={this.onChange}
7686
onItemSelect={this.selectItem}
77-
onNewItem={this.newItem}
78-
onSearchRecords={this.searchRecords}
7987
/>
8088
</div>
8189

0 commit comments

Comments
 (0)