Skip to content

Commit 016cf0f

Browse files
committed
custom list item renderer
1 parent 1c8efa9 commit 016cf0f

21 files changed

+602
-180
lines changed

components/SLDSButton/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class Button extends React.Component {
3535
}
3636

3737
onClick(e) {
38+
console.log('YES!!!');
3839
this.setState({ active: !this.state.active });
3940
}
4041

components/SLDSPicklistBase/index.jsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1212
import React, {PropTypes} from 'react';
1313
import SLDSPopover from '../SLDSPopover';
1414
import List from './list';
15+
import ListItem from './list-item';
16+
import ListItemLabel from './list-item-label';
1517

1618
import {InputIcon, ButtonIcon} from "./../SLDSIcons";
1719
import {Icon} from "../SLDSIcons";
@@ -38,7 +40,8 @@ module.exports = React.createClass( {
3840
initialFocus: false,
3941
modal: false,
4042
className:'',
41-
listClassName:''
43+
listClassName:'',
44+
listItemRenderer:ListItemLabel
4245
}
4346
},
4447

@@ -58,8 +61,10 @@ module.exports = React.createClass( {
5861
// setTimeout(()=>{
5962
this.setFocus();
6063
// this.setState({isFocused:true});
61-
// }.bind(this),100);
64+
// }.bind(this),100); =>
6265
}
66+
console.log('this.props.listItemRenderer: ',this.props.listItemRenderer);
67+
6368
},
6469

6570
getIndexByValue(value){
@@ -168,6 +173,7 @@ module.exports = React.createClass( {
168173
onListBlur={this.handleListBlur}
169174
onListItemBlur={this.handleListItemBlur}
170175
onCancel={this.handleCancel}
176+
itemRenderer={this.props.listItemRenderer}
171177
theme={this.props.theme} />;
172178
},
173179

@@ -269,3 +275,6 @@ module.exports = React.createClass( {
269275
},
270276

271277
});
278+
279+
module.exports.ListItem = ListItem;
280+
module.exports.ListItemLabel = ListItemLabel;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
'use strict';
10+
11+
12+
import React from 'react';
13+
import {Icon} from '../SLDSIcons';
14+
15+
import {KEYS,EventUtil} from '../utils';
16+
17+
18+
module.exports = React.createClass({
19+
20+
displayName: 'SLDSPicklistBase-list-item-label',
21+
22+
getDefaultProps () {
23+
return {
24+
index: 0,
25+
label: '',
26+
value: null,
27+
inverted: false,
28+
isSelected: false,
29+
isHighlighted: false
30+
};
31+
},
32+
33+
render () {
34+
return (
35+
<section>
36+
{
37+
this.props.isSelected?<Icon name='check' position='left' category='utility' />:null
38+
}
39+
{
40+
this.props.label
41+
}
42+
</section>
43+
);
44+
},
45+
46+
47+
48+
});

components/SLDSPicklistBase/list-item.jsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {Icon} from '../SLDSIcons';
1414

1515
import {KEYS,EventUtil} from '../utils';
1616

17+
import ListItemLabelRenderer from './list-item-label';
1718

1819
module.exports = React.createClass({
1920

@@ -27,6 +28,7 @@ module.exports = React.createClass({
2728
inverted: false,
2829
isSelected: false,
2930
isHighlighted: false,
31+
labelRenderer: ListItemLabelRenderer,
3032

3133
onSelect (index) {
3234
console.log('onSelect should be defined ',index);
@@ -47,6 +49,10 @@ module.exports = React.createClass({
4749
};
4850
},
4951

52+
componentDidMount () {
53+
console.log('!!! this.props.labelRenderer: ',this.props.labelRenderer);
54+
},
55+
5056
handleClick (e) {
5157
e.preventDefault();
5258
e.stopPropagation();
@@ -128,10 +134,21 @@ module.exports = React.createClass({
128134
}
129135
},
130136

137+
getLabel () {
138+
const LabelComp = this.props.labelRenderer;
139+
return <LabelComp
140+
index={this.props.index}
141+
label={this.props.label}
142+
value={this.props.value}
143+
inverted={this.props.inverted}
144+
isSelected={this.props.isSelected}
145+
isHighlighted={this.props.isHighlighted}
146+
/>;
147+
},
148+
131149
render () {
132150
return (
133151
<li
134-
135152
className={"slds-dropdown__item slds-has-icon slds-has-icon--left slds-theme--"+this.props.theme}
136153
onMouseDown={this.handleMouseDown}
137154
tabIndex={-1}>
@@ -147,8 +164,7 @@ module.exports = React.createClass({
147164
aria-checked={this.props.isSelected}
148165
role='menuitemradio'
149166
tabIndex={-1}>
150-
{this.props.isSelected?<Icon name='check' position='left' category='utility' />:null}
151-
{this.props.label}
167+
{this.getLabel()}
152168
</a>
153169
</li>
154170
);

components/SLDSPicklistBase/list.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ module.exports = React.createClass({
2626
selectedIndex:-1,
2727
highlightedIndex:0,
2828
className:'',
29+
itemRenderer:null,
2930
onListBlur:()=>{
3031
console.log("onListBlur should be overwritten");
3132
},
@@ -123,10 +124,11 @@ module.exports = React.createClass({
123124
},
124125

125126
getItems () {
127+
126128
return this.props.options.map((option, index) =>{
127129
return (
128130
<ListItem
129-
key={index}
131+
key={'ListItem_'+index}
130132
index={index}
131133
label={option.label}
132134
value={option.value}
@@ -138,6 +140,7 @@ module.exports = React.createClass({
138140
onFocus={this.handleItemFocus}
139141
onSelect={this.handleSelect}
140142
onSearch={this.handleSearch}
143+
labelRenderer={this.props.itemRenderer}
141144
onCancel={this.handleCancel}/>
142145
);
143146
});

components/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1010
*/
1111

1212
import SLDSPicklistBase from './SLDSPicklistBase';
13+
import SLDSPicklistBaseListItem from './SLDSPicklistBase/list-item';
1314
import SLDSSettings from './SLDSSettings';
1415
import SLDSButton from './SLDSButton';
1516
import SLDSModal from './SLDSModal';
@@ -18,6 +19,7 @@ import SLDSToast from './SLDSToast';
1819

1920
module.exports = {
2021
SLDSPicklistBase: SLDSPicklistBase,
22+
SLDSPicklistBaseListItem: SLDSPicklistBaseListItem,
2123
SLDSSettings: SLDSSettings,
2224
SLDSButton: SLDSButton,
2325
SLDSModal: SLDSModal,
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
const CustomItemLabelRenderer = React.createClass( {
3+
render() {
4+
return <section>
5+
{
6+
this.props.isSelected?<Icon name='like' position='left' category='utility' />:null
7+
}
8+
{
9+
this.props.label
10+
}
11+
</section>;
12+
}
13+
});
14+
15+
const options = [
16+
{label:'A Option',value:'A0'},
17+
{label:'B Option',value:'B0'},
18+
{label:'C Option',value:'C0'},
19+
{label:'D Option',value:'D0'},
20+
];
21+
22+
<SLDSPicklistBase
23+
options={options}
24+
listItemRenderer={CustomItemLabelRenderer}
25+
label="Contacts"
26+
placeholder="Select a contact"/>

demo/pages/HomePage/ModalSection.jsx

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,41 @@ module.exports = React.createClass( {
4242

4343
getModalContent () {
4444
return <div>
45+
<p>
46+
Utilize our detailed guidelines to confidently design excellent apps that fit right into the Salesforce ecosystem. With the Design System, you get access to all of the Salesforce core visual and interaction design patterns so that you can follow established best practices and build apps that have a consistent look and feel with the Salesforce user experience.
47+
</p>
48+
49+
<p>
50+
Utilize our detailed guidelines to confidently design excellent apps that fit right into the Salesforce ecosystem. With the Design System, you get access to all of the Salesforce core visual and interaction design patterns so that you can follow established best practices and build apps that have a consistent look and feel with the Salesforce user experience.
51+
</p>
52+
53+
<p>
54+
Utilize our detailed guidelines to confidently design excellent apps that fit right into the Salesforce ecosystem. With the Design System, you get access to all of the Salesforce core visual and interaction design patterns so that you can follow established best practices and build apps that have a consistent look and feel with the Salesforce user experience.
55+
</p>
56+
57+
<p>
58+
Utilize our detailed guidelines to confidently design excellent apps that fit right into the Salesforce ecosystem. With the Design System, you get access to all of the Salesforce core visual and interaction design patterns so that you can follow established best practices and build apps that have a consistent look and feel with the Salesforce user experience.
59+
</p>
60+
61+
<p>
62+
Utilize our detailed guidelines to confidently design excellent apps that fit right into the Salesforce ecosystem. With the Design System, you get access to all of the Salesforce core visual and interaction design patterns so that you can follow established best practices and build apps that have a consistent look and feel with the Salesforce user experience.
63+
</p>
64+
65+
<p>
66+
Utilize our detailed guidelines to confidently design excellent apps that fit right into the Salesforce ecosystem. With the Design System, you get access to all of the Salesforce core visual and interaction design patterns so that you can follow established best practices and build apps that have a consistent look and feel with the Salesforce user experience.
67+
</p>
68+
69+
<p>
70+
Utilize our detailed guidelines to confidently design excellent apps that fit right into the Salesforce ecosystem. With the Design System, you get access to all of the Salesforce core visual and interaction design patterns so that you can follow established best practices and build apps that have a consistent look and feel with the Salesforce user experience.
71+
</p>
72+
73+
<p>
74+
Utilize our detailed guidelines to confidently design excellent apps that fit right into the Salesforce ecosystem. With the Design System, you get access to all of the Salesforce core visual and interaction design patterns so that you can follow established best practices and build apps that have a consistent look and feel with the Salesforce user experience.
75+
</p>
76+
77+
<p>
78+
Utilize our detailed guidelines to confidently design excellent apps that fit right into the Salesforce ecosystem. With the Design System, you get access to all of the Salesforce core visual and interaction design patterns so that you can follow established best practices and build apps that have a consistent look and feel with the Salesforce user experience.
79+
</p>
4580

4681
<SLDSPicklistBase
4782
options={[
@@ -68,6 +103,21 @@ module.exports = React.createClass( {
68103
Utilize our detailed guidelines to confidently design excellent apps that fit right into the Salesforce ecosystem. With the Design System, you get access to all of the Salesforce core visual and interaction design patterns so that you can follow established best practices and build apps that have a consistent look and feel with the Salesforce user experience.
69104
</p>
70105

106+
<p>
107+
Utilize our detailed guidelines to confidently design excellent apps that fit right into the Salesforce ecosystem. With the Design System, you get access to all of the Salesforce core visual and interaction design patterns so that you can follow established best practices and build apps that have a consistent look and feel with the Salesforce user experience.
108+
</p>
109+
110+
111+
<p>
112+
Utilize our detailed guidelines to confidently design excellent apps that fit right into the Salesforce ecosystem. With the Design System, you get access to all of the Salesforce core visual and interaction design patterns so that you can follow established best practices and build apps that have a consistent look and feel with the Salesforce user experience.
113+
</p>
114+
115+
116+
<p>
117+
Utilize our detailed guidelines to confidently design excellent apps that fit right into the Salesforce ecosystem. With the Design System, you get access to all of the Salesforce core visual and interaction design patterns so that you can follow established best practices and build apps that have a consistent look and feel with the Salesforce user experience.
118+
</p>
119+
120+
71121

72122

73123
</div>;

0 commit comments

Comments
 (0)