Repository URL to install this package:
|
Version:
2.1.16 ▾
|
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const exotic_1 = require("exotic");
const utils_1 = require("@skava/utils");
const SelectDropDown_1 = require("@skava/ui/dist/components/molecules/SelectDropDown");
const fixture_1 = require("./fixture");
const styled_1 = require("./styled");
const isColor = obj => {
return exotic_1.isObj(obj) && obj.type === 'color';
};
const renderBeforeText = props => {
if (isColor(props) === true) {
return react_1.default.createElement(styled_1.ColorItemContent, {
value: props.value
});
}
return '';
};
const renderItem = (itemProps, state) => {
const {
label,
value
} = itemProps,
remainingProps = tslib_1.__rest(itemProps, ["label", "value"]);
const color = renderBeforeText(itemProps);
const text = react_1.default.createElement(SelectDropDown_1.SelectText, null, label);
return react_1.default.createElement(styled_1.ColorOption, Object.assign({
onClick: itemProps.onClick
}, remainingProps), color, text);
};
class ColorSelectDropDown extends react_1.default.Component {
constructor() {
super(...arguments);
this.renderActiveItem = (props, state) => {
const {
label
} = this.props;
return react_1.default.createElement(SelectDropDown_1.ActiveOption, Object.assign({
label: label,
state: state
}, props));
};
}
render() {
const passThroughProps = utils_1.omit(this.props, ['label']);
return react_1.default.createElement(styled_1.StyledColorSelectDropDown, Object.assign({
renderItem: renderItem,
renderActiveItem: this.renderActiveItem
}, passThroughProps));
}
}
ColorSelectDropDown.defaultProps = {
className: '',
options: fixture_1.colorList
};
exports.ColorSelectDropDown = ColorSelectDropDown;
exports.default = ColorSelectDropDown;