Repository URL to install this package:
|
Version:
8.1.0-rc.5 ▾
|
"use strict";
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _classnames = _interopRequireDefault(require("classnames"));
var _Button = require("../Button");
var _InputFeedback = _interopRequireDefault(require("./InputFeedback"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var SyncIcon = function SyncIcon(props) {
return /*#__PURE__*/_react["default"].createElement("svg", props, /*#__PURE__*/_react["default"].createElement("path", {
fill: "currentColor",
d: "M12 18.016v-3L15.984 19 12 23.031v-3c-2.188 0-4.07-.789-5.648-2.367-1.579-1.578-2.368-3.46-2.368-5.648 0-1.563.422-2.985 1.266-4.266l1.453 1.453C6.234 10.047 6 10.984 6 12.016c0 1.656.586 3.07 1.758 4.242C8.93 17.43 10.344 18.016 12 18.016zM12 4c2.188 0 4.07.79 5.648 2.367 1.579 1.578 2.368 3.461 2.368 5.649 0 1.562-.422 2.984-1.266 4.265l-1.453-1.453c.469-.844.703-1.781.703-2.812 0-1.657-.586-3.07-1.758-4.243C15.07 6.602 13.656 6.016 12 6.016v3L8.016 5.03 12 1v3z"
}));
};
SyncIcon.defaultProps = {
viewBox: "0 0 24 24",
xmlns: "http://www.w3.org/2000/svg"
};
var ColorPicker = /*#__PURE__*/function (_Component) {
_inherits(ColorPicker, _Component);
var _super = _createSuper(ColorPicker);
function ColorPicker(props) {
var _this;
_classCallCheck(this, ColorPicker);
_this = _super.call(this, props);
_defineProperty(_assertThisInitialized(_this), "onButtonClick", function () {
_this.input.click();
});
_defineProperty(_assertThisInitialized(_this), "onInternalChange", function (e) {
var currentColor = e.target.value;
_this.setState({
currentColor: currentColor
});
_this.props.onColorChange(currentColor);
});
_defineProperty(_assertThisInitialized(_this), "onReset", function () {
var currentColor = _this.props.defaultColor;
_this.setState({
currentColor: currentColor
});
_this.props.onColorChange(currentColor);
});
_defineProperty(_assertThisInitialized(_this), "setInputRef", function (node) {
_this.input = node;
});
_defineProperty(_assertThisInitialized(_this), "isColorInputSupported", function () {
var input = document.createElement('input');
input.setAttribute('type', 'color');
return input.type !== 'text';
});
_this.state = {
currentColor: _this.props.color || _this.props.defaultColor,
isColorInputSupported: _this.isColorInputSupported()
};
return _this;
}
_createClass(ColorPicker, [{
key: "render",
value: function render() {
var _this$state = this.state,
currentColor = _this$state.currentColor,
isColorInputSupported = _this$state.isColorInputSupported;
var _this$props = this.props,
label = _this$props.label,
defaultColor = _this$props.defaultColor,
valid = _this$props.valid,
errorMessage = _this$props.errorMessage,
onBlur = _this$props.onBlur,
disabled = _this$props.disabled;
var shouldShowResetButton = defaultColor !== currentColor;
var className = (0, _classnames["default"])({
'ColorPicker-input Input-field': !isColorInputSupported
}, {
'ColorPicker-input--hideInput': isColorInputSupported
}, {
'ColorPicker-input--invalid': !valid
});
return /*#__PURE__*/_react["default"].createElement("div", {
className: "ColorPicker"
}, isColorInputSupported && /*#__PURE__*/_react["default"].createElement(_Button.Button, {
variant: "whiteWithBorder",
type: "button",
onClick: this.onButtonClick,
disabled: disabled
}, /*#__PURE__*/_react["default"].createElement("div", {
className: "ColorPicker-buttonIcon Button-icon",
style: {
background: currentColor
}
}), /*#__PURE__*/_react["default"].createElement(_Button.ButtonLabel, null, label)), /*#__PURE__*/_react["default"].createElement("input", {
className: className,
type: "color",
value: currentColor,
ref: this.setInputRef,
onChange: this.onInternalChange,
onBlur: onBlur,
disabled: disabled
}), shouldShowResetButton && !disabled && /*#__PURE__*/_react["default"].createElement(_Button.IconButton, {
className: "ColorPicker-resetIcon",
type: "button",
variant: "whiteWithBorder",
icon: SyncIcon,
semantic: "Reset color",
dimension: "small",
onClick: this.onReset
}), !valid && errorMessage && /*#__PURE__*/_react["default"].createElement(_InputFeedback["default"], {
type: "error"
}, errorMessage));
}
}]);
return ColorPicker;
}(_react.Component);
_defineProperty(ColorPicker, "propTypes", {
/** Provides the default background color */
defaultColor: _propTypes["default"].string.isRequired,
/** Provides the background color that has been previously saved */
color: _propTypes["default"].string,
/** Provides a function that will be called after the color state changes and passes the new color as an argument. */
onColorChange: _propTypes["default"].func.isRequired,
onBlur: _propTypes["default"].func,
label: _propTypes["default"].string,
valid: _propTypes["default"].bool,
errorMessage: _propTypes["default"].string,
disabled: _propTypes["default"].bool
});
_defineProperty(ColorPicker, "defaultProps", {
color: null,
label: null,
valid: true,
errorMessage: '',
disabled: false,
onBlur: function onBlur() {}
});
var _default = ColorPicker;
exports["default"] = _default;