lucid-ui
Version:
A UI component library from AppNexus.
70 lines (63 loc) • 3.03 kB
JavaScript
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
import React from 'react';
import createClass from 'create-react-class';
import { IconSelect, ClockIcon, SwitchLabeled } from '../../../index';
export default createClass({
getInitialState: function getInitialState() {
return {
selectedIcons: ['item2'],
isDisabled: true
};
},
isSelected: function isSelected(id) {
return this.state.selectedIcons.includes(id);
},
handleSelect: function handleSelect(selectedId) {
var selectedIcons = this.state.selectedIcons; // if selected, then remove from list
if (this.isSelected(selectedId)) {
this.setState({
selectedIcons: selectedIcons.filter(function (id) {
return id !== selectedId;
})
});
} else {
// add it to list
this.setState({
selectedIcons: [].concat(_toConsumableArray(selectedIcons), [selectedId])
});
}
},
handleToggleDisabled: function handleToggleDisabled() {
this.setState({
isDisabled: !this.state.isDisabled
});
},
render: function render() {
var isDisabled = this.state.isDisabled;
return /*#__PURE__*/React.createElement("section", null, /*#__PURE__*/React.createElement(SwitchLabeled, {
Label: "IconSelect ".concat(isDisabled ? 'Disabled' : 'Enabled'),
isSelected: !isDisabled,
onSelect: this.handleToggleDisabled
}), /*#__PURE__*/React.createElement(IconSelect, {
isDisabled: isDisabled,
onSelect: this.handleSelect,
items: [{
id: 'item1',
icon: /*#__PURE__*/React.createElement(ClockIcon, null),
isSelected: this.isSelected('item1'),
label: 'Always Disabled',
isDisabled: true
}, {
id: 'item2',
icon: /*#__PURE__*/React.createElement(ClockIcon, null),
isSelected: this.isSelected('item2'),
label: 'Bax Tar'
}]
}));
}
});