office-ui-fabric-react
Version:
Reusable React components for building experiences for Office 365.
89 lines • 4.19 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var React = require("react");
var Utilities_1 = require("../../../Utilities");
var colors_1 = require("../../../utilities/color/colors");
var getClassNames = Utilities_1.classNamesFunction();
var ColorRectangleBase = /** @class */ (function (_super) {
tslib_1.__extends(ColorRectangleBase, _super);
function ColorRectangleBase(props) {
var _this = _super.call(this, props) || this;
_this._root = Utilities_1.createRef();
_this._onMouseDown = function (ev) {
_this._events.on(window, 'mousemove', _this._onMouseMove, true);
_this._events.on(window, 'mouseup', _this._onMouseUp, true);
_this._onMouseMove(ev);
};
_this._onMouseMove = function (ev) {
var _a = _this.props, color = _a.color, onSVChanged = _a.onSVChanged;
if (!_this._root.current) {
return;
}
var rectSize = _this._root.current.getBoundingClientRect();
var sPercentage = (ev.clientX - rectSize.left) / rectSize.width;
var vPercentage = (ev.clientY - rectSize.top) / rectSize.height;
var newColor = Utilities_1.assign({}, color, {
s: Math.min(colors_1.MAX_COLOR_SATURATION, Math.max(0, sPercentage * colors_1.MAX_COLOR_SATURATION)),
v: Math.min(colors_1.MAX_COLOR_VALUE, Math.max(0, colors_1.MAX_COLOR_VALUE - vPercentage * colors_1.MAX_COLOR_VALUE))
});
newColor.hex = colors_1.hsv2hex(newColor.h, newColor.s, newColor.v);
newColor.str =
newColor.a === 100
? '#' + newColor.hex
: "rgba(" + newColor.r + ", " + newColor.g + ", " + newColor.b + ", " + newColor.a / 100 + ")";
_this.setState({
isAdjusting: true,
color: newColor
});
if (onSVChanged) {
onSVChanged(newColor.s, newColor.v);
}
ev.preventDefault();
ev.stopPropagation();
};
_this._onMouseUp = function (ev) {
_this._events.off();
_this.setState({
isAdjusting: false,
origin: undefined
});
};
var color = _this.props.color;
_this.state = {
isAdjusting: false,
origin: undefined,
color: color,
fullColorString: colors_1.getFullColorString(color)
};
return _this;
}
ColorRectangleBase.prototype.componentWillUnmount = function () {
this._events.dispose();
};
ColorRectangleBase.prototype.componentWillReceiveProps = function (newProps) {
var color = newProps.color;
this.setState({
color: color,
fullColorString: colors_1.getFullColorString(color)
});
};
ColorRectangleBase.prototype.render = function () {
var _a = this.props, minSize = _a.minSize, theme = _a.theme, className = _a.className, styles = _a.styles;
var _b = this.state, color = _b.color, fullColorString = _b.fullColorString;
var classNames = getClassNames(styles, {
theme: theme,
className: className
});
return (React.createElement("div", { ref: this._root, className: classNames.root, style: { minWidth: minSize, minHeight: minSize, backgroundColor: fullColorString }, onMouseDown: this._onMouseDown },
React.createElement("div", { className: classNames.light }),
React.createElement("div", { className: classNames.dark }),
React.createElement("div", { className: classNames.thumb, style: { left: color.s + '%', top: colors_1.MAX_COLOR_VALUE - color.v + '%', backgroundColor: color.str } })));
};
ColorRectangleBase.defaultProps = {
minSize: 220
};
return ColorRectangleBase;
}(Utilities_1.BaseComponent));
exports.ColorRectangleBase = ColorRectangleBase;
//# sourceMappingURL=ColorRectangle.base.js.map
;