chowa
Version:
UI component library based on React
49 lines (48 loc) • 1.75 kB
JavaScript
/**
* @license chowa v1.1.3
*
* Copyright (c) Chowa Techonlogies Co.,Ltd.(http://www.chowa.cn).
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
;
Object.defineProperty(exports, "__esModule", { value: true });
const React = require("react");
const classNames = require("classnames");
const utils_1 = require("../utils");
const tool_1 = require("./tool");
class ColorRecommend extends React.PureComponent {
constructor(props) {
super(props);
this.state = {
hsbColors: this.compileColors(props.colors)
};
}
compileColors(colors) {
if (!Array.isArray(colors)) {
return [];
}
return colors.map((color) => tool_1.anyToHsb(color));
}
componentDidUpdate(preProps) {
if (!utils_1.isEqual(preProps.colors, this.props.colors)) {
this.setState({ hsbColors: this.compileColors(this.props.colors) });
}
}
onSelecthandler(color) {
this.props.onChange(color);
}
render() {
const { value } = this.props;
const { hsbColors } = this.state;
return (React.createElement("ul", { className: utils_1.preClass('color-recommend-wrapper') }, hsbColors.map((color, key) => {
const colorClass = classNames({
[utils_1.preClass('color-recommend')]: true,
[utils_1.preClass('color-active')]: utils_1.isEqual(color, value)
});
return (React.createElement("li", { key: key, className: colorClass, onClick: this.onSelecthandler.bind(this, color), style: { background: tool_1.toStrRgb(color) } }));
})));
}
}
exports.default = ColorRecommend;