UNPKG

@uiw/react-color-circle

Version:

Color swatch component for React.

67 lines (66 loc) 4.2 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"]; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2")); var _objectDestructuringEmpty2 = _interopRequireDefault(require("@babel/runtime/helpers/objectDestructuringEmpty")); var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); var _react = _interopRequireDefault(require("react")); var _colorConvert = require("@uiw/color-convert"); var _reactColorSwatch = _interopRequireDefault(require("@uiw/react-color-swatch")); var _Point = _interopRequireDefault(require("./Point")); var _jsxRuntime = require("react/jsx-runtime"); var _excluded = ["prefixCls", "className", "color", "colors", "rectProps", "pointProps", "style", "onChange"]; var Circle = /*#__PURE__*/_react["default"].forwardRef(function (props, ref) { var _pointProps$style, _pointProps$style2, _pointProps$style3, _pointProps$style4, _pointProps$style5; var _props$prefixCls = props.prefixCls, prefixCls = _props$prefixCls === void 0 ? 'w-color-circle' : _props$prefixCls, className = props.className, color = props.color, _props$colors = props.colors, colors = _props$colors === void 0 ? [] : _props$colors, _props$rectProps = props.rectProps, rectProps = _props$rectProps === void 0 ? {} : _props$rectProps, _props$pointProps = props.pointProps, pointProps = _props$pointProps === void 0 ? {} : _props$pointProps, _props$style = props.style, style = _props$style === void 0 ? {} : _props$style, _onChange = props.onChange, other = (0, _objectWithoutProperties2["default"])(props, _excluded); var hsva = typeof color === 'string' && (0, _colorConvert.validHex)(color) ? (0, _colorConvert.hexToHsva)(color) : color || {}; var hex = color ? (0, _colorConvert.hsvaToHex)(hsva) : ''; var cls = [prefixCls, className].filter(Boolean).join(' '); var clsPoint = ["".concat(prefixCls, "-point"), pointProps === null || pointProps === void 0 ? void 0 : pointProps.className].filter(Boolean).join(' '); pointProps.style = pointProps.style || {}; pointProps.style.borderRadius = ((_pointProps$style = pointProps.style) === null || _pointProps$style === void 0 ? void 0 : _pointProps$style.borderRadius) || '50%'; pointProps.style.width = ((_pointProps$style2 = pointProps.style) === null || _pointProps$style2 === void 0 ? void 0 : _pointProps$style2.width) || 26; pointProps.style.height = ((_pointProps$style3 = pointProps.style) === null || _pointProps$style3 === void 0 ? void 0 : _pointProps$style3.height) || 26; pointProps.style.marginRight = ((_pointProps$style4 = pointProps.style) === null || _pointProps$style4 === void 0 ? void 0 : _pointProps$style4.marginRight) || 0; pointProps.style.marginBottom = ((_pointProps$style5 = pointProps.style) === null || _pointProps$style5 === void 0 ? void 0 : _pointProps$style5.marginBottom) || 0; style.gap = style.gap || 10; return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactColorSwatch["default"], (0, _objectSpread2["default"])((0, _objectSpread2["default"])({ ref: ref, colors: colors, color: hex, style: style }, other), {}, { className: cls, rectRender: function rectRender(_ref) { var props = (0, _extends2["default"])({}, ((0, _objectDestructuringEmpty2["default"])(_ref), _ref)); return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Point["default"], (0, _objectSpread2["default"])((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, props), pointProps), {}, { style: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, props.style), pointProps.style), className: clsPoint, rectProps: rectProps })); }, onChange: function onChange(hsvColor) { _onChange && _onChange((0, _colorConvert.color)(hsvColor)); } })); }); Circle.displayName = 'Circle'; var _default = exports["default"] = Circle; module.exports = exports.default;