Skip to content

Commit f19a454

Browse files
committed
build
1 parent fc79951 commit f19a454

File tree

13 files changed

+528
-52883
lines changed

13 files changed

+528
-52883
lines changed

dist/demo.css

Lines changed: 0 additions & 442 deletions
This file was deleted.

dist/demo.js

Lines changed: 0 additions & 52400 deletions
This file was deleted.

lib/SLDSDatepickerSingleSelect/SLDSYearSelector/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ module.exports = _react2.default.createClass({
5959
options: this.getOptions(),
6060
placeholder: 'Year',
6161
checkmark: false,
62+
modal: false,
6263
value: this.props.displayedDate.getFullYear(),
6364
onSelect: this.handleSelect,
6465
className: 'slds-picklist--fluid slds-shrink-none',

lib/SLDSDatepickerSingleSelect/index.js

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,21 @@ var propTypes = {
6060
*/
6161
value: _react2.default.PropTypes.instanceOf(Date),
6262

63+
strValue: _react2.default.PropTypes.string,
64+
6365
weekDayLabels: _react2.default.PropTypes.array
6466

6567
};
6668
var defaultProps = {
6769
abbrWeekDayLabels: ['S', 'M', 'T', 'W', 'T', 'F', 'S'],
6870
formatter: function formatter(date) {
69-
return date.getMonth() + 1 + '/' + date.getDate() + '/' + date.getFullYear();
71+
if (date) {
72+
return date.getMonth() + 1 + '/' + date.getDate() + '/' + date.getFullYear();
73+
}
7074
},
7175

7276
monthLabels: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
73-
onDateChange: function onDateChange(date) {
77+
onDateChange: function onDateChange(date, strValue) {
7478
console.log('onDateChange should be defined');
7579
},
7680
parser: function parser(str) {
@@ -97,12 +101,14 @@ module.exports = _react2.default.createClass({
97101
getInitialState: function getInitialState() {
98102
return {
99103
isOpen: false,
100-
value: this.props.value
104+
value: this.props.value,
105+
strValue: this.props.strValue
101106
};
102107
},
103108
handleChange: function handleChange(date) {
104109
this.setState({
105110
value: date,
111+
strValue: this.props.formatter(date),
106112
isOpen: false
107113
});
108114
if (this.props.onDateChange) {
@@ -127,8 +133,18 @@ module.exports = _react2.default.createClass({
127133
_reactDom2.default.findDOMNode(this.refs.date).focus();
128134
}
129135
},
136+
parseDate: function parseDate(strValue) {
137+
var d = this.props.parser(strValue);
138+
if (Object.prototype.toString.call(d) === "[object Date]") {
139+
if (!isNaN(d.getTime())) {
140+
return d;
141+
}
142+
}
143+
return new Date();
144+
},
130145
popover: function popover() {
131146
if (this.state && this.state.isOpen) {
147+
var date = this.state.strValue ? this.parseDate(this.state.strValue) : this.state.value;
132148
return _react2.default.createElement(
133149
_SLDSPopover2.default,
134150
{ className: 'slds-dropdown', targetElement: this.refs.date, onClose: this.handleClose },
@@ -142,31 +158,27 @@ module.exports = _react2.default.createClass({
142158
todayLabel: this.props.todayLabel,
143159
relativeYearFrom: this.props.relativeYearFrom,
144160
relativeYearTo: this.props.relativeYearTo,
145-
selectedDate: this.state.value ? this.state.value : new Date() })
161+
selectedDate: date ? date : new Date() })
146162
);
147163
}
148164
return _react2.default.createElement('span', null);
149165
},
150166
handleInputChange: function handleInputChange() {
151167
var string = _reactDom2.default.findDOMNode(this.refs.date).value;
152-
var date = this.props.parser(string);
153-
if (date) {
154-
this.setState({
155-
value: date,
156-
string: string
157-
});
158-
if (this.props.onDateChage) {
159-
this.props.onDateChange(value);
160-
}
161-
} else {
162-
this.setState({
163-
isOpen: false
164-
});
168+
this.setState({
169+
strValue: string
170+
});
171+
if (this.props.onDateChange) {
172+
var d = this.props.parser(string);
173+
this.props.onDateChange(d, string);
165174
}
166175
},
167176
handleKeyDown: function handleKeyDown(event) {
168177
if (event.keyCode) {
169-
if (event.keyCode === _utils.KEYS.ENTER || event.keyCode === _utils.KEYS.SPACE || event.keyCode === _utils.KEYS.DOWN || event.keyCode === _utils.KEYS.UP) {
178+
var isShift = !!event.shiftKey;
179+
if (!isShift && (event.keyCode === _utils.KEYS.ENTER ||
180+
// event.keyCode === KEYS.SPACE ||
181+
event.keyCode === _utils.KEYS.DOWN || event.keyCode === _utils.KEYS.UP)) {
170182
_utils.EventUtil.trapEvent(event);
171183

172184
this.setState({
@@ -175,6 +187,9 @@ module.exports = _react2.default.createClass({
175187
}
176188
}
177189
},
190+
getInputIcon: function getInputIcon() {
191+
return _react2.default.createElement(_InputIcon2.default, { name: 'event', style: { pointerEvents: 'none' } });
192+
},
178193
render: function render() {
179194
return _react2.default.createElement(
180195
'div',
@@ -190,14 +205,14 @@ module.exports = _react2.default.createClass({
190205
_react2.default.createElement(
191206
'div',
192207
{ className: 'slds-input-has-icon slds-input-has-icon--right' },
193-
_react2.default.createElement(_InputIcon2.default, { name: 'event' }),
208+
this.getInputIcon(),
194209
_react2.default.createElement('input', {
195210
name: 'date',
196211
ref: 'date',
197212
className: 'slds-input',
198213
type: 'text',
199214
placeholder: this.props.placeholder,
200-
value: this.state.value ? this.props.formatter(this.state.value) : '',
215+
value: this.state.strValue,
201216
onKeyDown: this.handleKeyDown,
202217
onChange: this.handleInputChange,
203218
onClick: this.handleClick,

lib/SLDSIcon/InputIcon/index.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.
File renamed without changes.

lib/SLDSMenuPicklist/ListItemLabel.js renamed to lib/SLDSMenuList/ListItemLabel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var propTypes = {
3333
isHighlighted: _react2.default.PropTypes.bool,
3434
isSelected: _react2.default.PropTypes.bool,
3535
label: _react2.default.PropTypes.string,
36-
value: _react2.default.PropTypes.string
36+
value: _react2.default.PropTypes.any
3737
};
3838
var defaultProps = {
3939
data: {},

lib/SLDSMenuList/index.js

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
"use strict";
2+
3+
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
4+
5+
var _react = require("react");
6+
7+
var _react2 = _interopRequireDefault(_react);
8+
9+
var _reactDom = require("react-dom");
10+
11+
var _reactDom2 = _interopRequireDefault(_reactDom);
12+
13+
var _lodash = require("lodash.isequal");
14+
15+
var _lodash2 = _interopRequireDefault(_lodash);
16+
17+
var _utils = require("../utils");
18+
19+
var _SLDSIcon = require("../SLDSIcon");
20+
21+
var _SLDSIcon2 = _interopRequireDefault(_SLDSIcon);
22+
23+
var _List = require("./List");
24+
25+
var _List2 = _interopRequireDefault(_List);
26+
27+
var _ListItemLabel = require("./ListItemLabel");
28+
29+
var _ListItemLabel2 = _interopRequireDefault(_ListItemLabel);
30+
31+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
32+
33+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
34+
35+
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
36+
37+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /*
38+
Copyright (c) 2015, salesforce.com, inc. All rights reserved.
39+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
40+
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
41+
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.
42+
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.
43+
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.
44+
*/
45+
46+
var displayName = "SLDSMenuList";
47+
var propTypes = {
48+
className: _react2.default.PropTypes.string,
49+
/**
50+
* If true, renders checkmark icon on the selected Menu Item.
51+
*/
52+
checkmark: _react2.default.PropTypes.bool,
53+
label: _react2.default.PropTypes.string,
54+
/**
55+
* Custom element that overrides the default Menu Item component.
56+
*/
57+
listItemRenderer: _react2.default.PropTypes.node,
58+
/**
59+
* If true, component renders specifically to work inside Modal.
60+
*/
61+
onClick: _react2.default.PropTypes.func,
62+
onSelect: _react2.default.PropTypes.func,
63+
/**
64+
* Menu item data.
65+
*/
66+
options: _react2.default.PropTypes.array.isRequired
67+
};
68+
var defaultProps = {
69+
checkmark: true
70+
};
71+
72+
/**
73+
* The SLDSMenuPicklist component is a variant of the Ligtning Design System Menu component.
74+
*/
75+
76+
var SLDSMenuPicklist = function (_React$Component) {
77+
_inherits(SLDSMenuPicklist, _React$Component);
78+
79+
function SLDSMenuPicklist(props) {
80+
_classCallCheck(this, SLDSMenuPicklist);
81+
82+
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(SLDSMenuPicklist).call(this, props));
83+
84+
_this.state = {
85+
highlightedIndex: 0,
86+
isOpen: false,
87+
lastBlurredIndex: -1,
88+
lastBlurredTimeStamp: -1,
89+
selectedIndex: _this.props.selectedIndex,
90+
/* triggerId is the id of the element that triggers the Menu to open.
91+
* Need this for aria-labelledby on <ul> in Menu for accessibility. */
92+
triggerId: _this.props.label ? _this.props.label.replace(/\s+/g, '') + '_Button' : 'Picklist_Button'
93+
};
94+
95+
return _this;
96+
}
97+
98+
_createClass(SLDSMenuPicklist, [{
99+
key: "componentWillUnmount",
100+
value: function componentWillUnmount() {
101+
this.isUnmounting = true;
102+
}
103+
}, {
104+
key: "componentDidUpdate",
105+
value: function componentDidUpdate(prevProps, prevState) {
106+
if (this.state.lastBlurredTimeStamp !== prevState.lastBlurredTimeStamp) {
107+
if (this.state.lastBlurredIndex === this.state.highlightedIndex) {
108+
this.handleClose();
109+
}
110+
}
111+
if (this.state.selectedIndex !== prevState.selectedIndex) {
112+
this.handleClose();
113+
}
114+
115+
if (this.props.selectedIndex !== prevProps.selectedIndex || !(0, _lodash2.default)(this.props.options, prevProps.options)) {
116+
if (this.props.selectedIndex !== this.state.selectedIndex) {
117+
this.handleSelect(this.props.selectedIndex);
118+
}
119+
}
120+
}
121+
}, {
122+
key: "handleSelect",
123+
value: function handleSelect(index) {
124+
this.setState({ selectedIndex: index });
125+
if (this.props.onSelect) {
126+
this.props.onSelect(index);
127+
}
128+
}
129+
}, {
130+
key: "handleClose",
131+
value: function handleClose() {
132+
if (this.props.onCancel) {
133+
this.props.onCancel();
134+
}
135+
}
136+
}, {
137+
key: "handleMouseDown",
138+
value: function handleMouseDown(event) {
139+
_utils.EventUtil.trapImmediate(event);
140+
}
141+
}, {
142+
key: "handleUpdateHighlighted",
143+
value: function handleUpdateHighlighted(nextIndex) {
144+
this.setState({ highlightedIndex: nextIndex });
145+
}
146+
}, {
147+
key: "handleListBlur",
148+
value: function handleListBlur() {
149+
if (this.props.onListBlur) {
150+
this.props.onListBlur();
151+
}
152+
}
153+
}, {
154+
key: "handleCancel",
155+
value: function handleCancel() {
156+
if (this.props.onCancel) {
157+
this.props.onCancel();
158+
}
159+
}
160+
}, {
161+
key: "getListItemRenderer",
162+
value: function getListItemRenderer() {
163+
return this.props.listItemRenderer ? this.props.listItemRenderer : _ListItemLabel2.default;
164+
}
165+
}, {
166+
key: "handleListItemBlur",
167+
value: function handleListItemBlur(index, relatedTarget) {
168+
this.setState({
169+
lastBlurredIndex: index,
170+
lastBlurredTimeStamp: Date.now()
171+
});
172+
}
173+
}, {
174+
key: "render",
175+
value: function render() {
176+
return _react2.default.createElement(_List2.default, {
177+
checkmark: this.props.checkmark,
178+
highlightedIndex: this.state.highlightedIndex,
179+
itemRenderer: this.getListItemRenderer(),
180+
onCancel: this.handleCancel.bind(this),
181+
onListBlur: this.handleListBlur.bind(this),
182+
onListItemBlur: this.handleListItemBlur.bind(this),
183+
onSelect: this.handleSelect.bind(this),
184+
onUpdateHighlighted: this.handleUpdateHighlighted.bind(this),
185+
options: this.props.options,
186+
ref: "list",
187+
selectedIndex: this.state.selectedIndex
188+
});
189+
}
190+
}]);
191+
192+
return SLDSMenuPicklist;
193+
}(_react2.default.Component);
194+
195+
SLDSMenuPicklist.displayName = displayName;
196+
SLDSMenuPicklist.propTypes = propTypes;
197+
SLDSMenuPicklist.defaultProps = defaultProps;
198+
199+
module.exports = SLDSMenuPicklist;
200+
module.exports.ListItemLabel = _ListItemLabel2.default;

lib/SLDSMenuPicklist/index.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,11 @@ var _SLDSIcon = require("../SLDSIcon");
2424

2525
var _SLDSIcon2 = _interopRequireDefault(_SLDSIcon);
2626

27-
var _List = require("./List");
27+
var _List = require("../SLDSMenuList/List");
2828

2929
var _List2 = _interopRequireDefault(_List);
3030

31-
var _ListItem = require("./ListItem");
32-
33-
var _ListItem2 = _interopRequireDefault(_ListItem);
34-
35-
var _ListItemLabel = require("./ListItemLabel");
31+
var _ListItemLabel = require("../SLDSMenuList/ListItemLabel");
3632

3733
var _ListItemLabel2 = _interopRequireDefault(_ListItemLabel);
3834

@@ -367,5 +363,4 @@ SLDSMenuPicklist.propTypes = propTypes;
367363
SLDSMenuPicklist.defaultProps = defaultProps;
368364

369365
module.exports = SLDSMenuPicklist;
370-
module.exports.ListItem = _ListItem2.default;
371366
module.exports.ListItemLabel = _ListItemLabel2.default;

0 commit comments

Comments
 (0)