lucid-ui
Version:
A UI component library from AppNexus.
83 lines • 3.27 kB
JavaScript
;
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = __importDefault(require("react"));
var create_react_class_1 = __importDefault(require("create-react-class"));
var index_1 = require("../../../index");
exports.default = create_react_class_1.default({
getInitialState: function () {
return {
selectedIcons: [{ id: 'item2', isPartial: true }],
};
},
isSelected: function (id) {
return this.state.selectedIcons.some(function (_a) {
var selectedId = _a.id;
return id === selectedId;
});
},
isPartiallySelected: function (id) {
return this.state.selectedIcons.some(function (_a) {
var selectedId = _a.id, isPartial = _a.isPartial;
return id === selectedId && isPartial;
});
},
handleSelect: function (selectedId) {
var selectedIcons = this.state.selectedIcons;
if (this.isPartiallySelected(selectedId)) {
// if partially selected, remove from the list
this.setState({
selectedIcons: selectedIcons.filter(function (_a) {
var id = _a.id;
return id !== selectedId;
}),
});
}
else if (this.isSelected(selectedId)) {
// if already selected, ensure isPartial is true
this.setState({
selectedIcons: selectedIcons.map(function (_a) {
var id = _a.id, isPartial = _a.isPartial;
return ({
id: id,
isPartial: isPartial || id === selectedId,
});
}),
});
}
else {
// add selected icon to list
this.setState({
selectedIcons: __spreadArrays(selectedIcons, [{ id: selectedId, isPartial: false }]),
});
}
},
render: function () {
return (react_1.default.createElement(index_1.IconSelect, { onSelect: this.handleSelect, items: [
{
id: 'item1',
icon: react_1.default.createElement(index_1.ClockIcon, null),
isSelected: this.isSelected('item1'),
isPartial: this.isPartiallySelected('item1'),
label: 'Foo Bar',
},
{
id: 'item2',
icon: react_1.default.createElement(index_1.ClockIcon, null),
isSelected: this.isSelected('item2'),
isPartial: this.isPartiallySelected('item2'),
label: 'Bax Tar',
},
] }));
},
});
//# sourceMappingURL=3.partially-select-icons.js.map