Skip to content

Commit 46edcc2

Browse files
committed
Merge pull request #165 from salesforce-ux/timepicker
Timepicker component initial
2 parents 4973c73 + a2fc8a2 commit 46edcc2

File tree

15 files changed

+577
-8
lines changed

15 files changed

+577
-8
lines changed

components/SLDSMenuPicklist/ListItemLabel.jsx renamed to components/SLDSMenuList/ListItemLabel.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const propTypes = {
1818
isHighlighted: React.PropTypes.bool,
1919
isSelected: React.PropTypes.bool,
2020
label: React.PropTypes.string,
21-
value: React.PropTypes.string,
21+
value: React.PropTypes.any,
2222
};
2323
const defaultProps = {
2424
data: {},

components/SLDSMenuList/index.jsx

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
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+
import React from "react";
11+
import ReactDOM from "react-dom";
12+
import isEqual from "lodash.isequal";
13+
14+
import {KEYS, EventUtil} from "../utils";
15+
import SLDSIcon from "../SLDSIcon";
16+
import List from "./List";
17+
import ListItemLabel from "./ListItemLabel";
18+
19+
const displayName = "SLDSMenuList";
20+
const propTypes = {
21+
className: React.PropTypes.string,
22+
/**
23+
* If true, renders checkmark icon on the selected Menu Item.
24+
*/
25+
checkmark: React.PropTypes.bool,
26+
label: React.PropTypes.string,
27+
/**
28+
* Custom element that overrides the default Menu Item component.
29+
*/
30+
listItemRenderer: React.PropTypes.node,
31+
/**
32+
* If true, component renders specifically to work inside Modal.
33+
*/
34+
onClick: React.PropTypes.func,
35+
onSelect: React.PropTypes.func,
36+
/**
37+
* Menu item data.
38+
*/
39+
options: React.PropTypes.array.isRequired,
40+
};
41+
const defaultProps = {
42+
checkmark: true
43+
};
44+
45+
/**
46+
* The SLDSMenuPicklist component is a variant of the Ligtning Design System Menu component.
47+
*/
48+
class SLDSMenuPicklist extends React.Component {
49+
constructor(props) {
50+
super(props);
51+
this.state = {
52+
highlightedIndex: 0,
53+
isOpen: false,
54+
lastBlurredIndex: -1,
55+
lastBlurredTimeStamp: -1,
56+
selectedIndex: this.props.selectedIndex,
57+
/* triggerId is the id of the element that triggers the Menu to open.
58+
* Need this for aria-labelledby on <ul> in Menu for accessibility. */
59+
triggerId: this.props.label ? this.props.label.replace(/\s+/g, '') + '_Button': 'Picklist_Button',
60+
};
61+
62+
}
63+
64+
componentWillUnmount(){
65+
this.isUnmounting = true;
66+
}
67+
68+
componentDidUpdate( prevProps, prevState) {
69+
if(this.state.lastBlurredTimeStamp !== prevState.lastBlurredTimeStamp){
70+
if(this.state.lastBlurredIndex === this.state.highlightedIndex){
71+
this.handleClose();
72+
}
73+
}
74+
if(this.state.selectedIndex !== prevState.selectedIndex){
75+
this.handleClose();
76+
}
77+
78+
if(this.props.selectedIndex !== prevProps.selectedIndex ||
79+
!isEqual(this.props.options, prevProps.options)){
80+
if (this.props.selectedIndex !== this.state.selectedIndex) {
81+
this.handleSelect(this.props.selectedIndex);
82+
}
83+
}
84+
}
85+
86+
handleSelect(index) {
87+
this.setState({selectedIndex: index})
88+
if(this.props.onSelect){
89+
this.props.onSelect(index);
90+
}
91+
}
92+
93+
handleClose() {
94+
if(this.props.onCancel){
95+
this.props.onCancel();
96+
}
97+
}
98+
99+
handleMouseDown(event){
100+
EventUtil.trapImmediate(event);
101+
}
102+
103+
handleUpdateHighlighted(nextIndex){
104+
this.setState({highlightedIndex: nextIndex});
105+
}
106+
107+
handleListBlur(){
108+
if(this.props.onListBlur){
109+
this.props.onListBlur();
110+
}
111+
}
112+
113+
handleCancel () {
114+
if(this.props.onCancel){
115+
this.props.onCancel();
116+
}
117+
}
118+
119+
getListItemRenderer() {
120+
return this.props.listItemRenderer?this.props.listItemRenderer:ListItemLabel;
121+
}
122+
123+
handleListItemBlur (index, relatedTarget) {
124+
this.setState({
125+
lastBlurredIndex: index,
126+
lastBlurredTimeStamp: Date.now()
127+
});
128+
}
129+
130+
render() {
131+
return <List
132+
checkmark={this.props.checkmark}
133+
highlightedIndex={this.state.highlightedIndex}
134+
itemRenderer={this.getListItemRenderer()}
135+
onCancel={this.handleCancel.bind(this)}
136+
onListBlur={this.handleListBlur.bind(this)}
137+
onListItemBlur={this.handleListItemBlur.bind(this)}
138+
onSelect={this.handleSelect.bind(this)}
139+
onUpdateHighlighted={this.handleUpdateHighlighted.bind(this)}
140+
options={this.props.options}
141+
ref="list"
142+
selectedIndex={this.state.selectedIndex}
143+
/>;
144+
}
145+
146+
}
147+
148+
149+
SLDSMenuPicklist.displayName = displayName;
150+
SLDSMenuPicklist.propTypes = propTypes;
151+
SLDSMenuPicklist.defaultProps = defaultProps;
152+
153+
module.exports = SLDSMenuPicklist;
154+
module.exports.ListItemLabel = ListItemLabel;
155+

components/SLDSMenuPicklist/index.jsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ import isEqual from "lodash.isequal";
1414
import SLDSPopover from "../SLDSPopover";
1515
import {KEYS, EventUtil} from "../utils";
1616
import SLDSIcon from "../SLDSIcon";
17-
import List from "./List";
18-
import ListItem from "./ListItem";
19-
import ListItemLabel from "./ListItemLabel";
17+
import List from "../SLDSMenuList/List";
18+
import ListItemLabel from "../SLDSMenuList/ListItemLabel";
2019

2120
const displayName = "SLDSMenuPicklist";
2221
const propTypes = {
@@ -298,6 +297,5 @@ SLDSMenuPicklist.propTypes = propTypes;
298297
SLDSMenuPicklist.defaultProps = defaultProps;
299298

300299
module.exports = SLDSMenuPicklist;
301-
module.exports.ListItem = ListItem;
302300
module.exports.ListItemLabel = ListItemLabel;
303301

0 commit comments

Comments
 (0)