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); }

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); }

/* Copyright (c) 2015-present, salesforce.com, inc. All rights reserved */

/* Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license */
// Implements the [Visual Picker design pattern](https://lightningdesignsystem.com/components/visual-picker/) in React.
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames'; // ### shortid
// [npmjs.com/package/shortid](https://www.npmjs.com/package/shortid)
// shortid is a short, non-sequential, url-friendly, unique id generator

import shortid from 'shortid';
import { VISUAL_PICKER } from '../../utilities/constants';
var propTypes = {
  /**
   * HTML id for component.
   */
  id: PropTypes.string,

  /**
   * Visual Picker accepts `Checkbox`, `Radio` and `VisualPickerLink` components as children. Please see `Checkbox`, `Radio` and `VisualPickerLink` for props.
   */
  children: PropTypes.node,

  /**
   * CSS classes to be added to tag with `.slds-form-element`. Uses `classNames` [API](https://github.com/JedWatson/classnames).
   */
  className: PropTypes.oneOfType([PropTypes.array, PropTypes.object, PropTypes.string]),

  /**
   *  Label for the visual picker
   */
  label: PropTypes.string,

  /**
   *  Whether the visual picker is coverable on selection
   */
  coverable: PropTypes.bool,

  /**
   *  Whether the visual picker has a vertical layout
   */
  vertical: PropTypes.bool,

  /**
   * Whether the visual picker has links as children
   */
  links: PropTypes.bool,

  /**
   *  Size for visual picker
   */
  size: PropTypes.oneOf(['medium', 'large'])
};
var defaultProps = {
  size: 'medium',
  vertical: false,
  links: false
};
/**
 * Visual Picker Component
 */

var VisualPicker = /*#__PURE__*/function (_React$Component) {
  _inherits(VisualPicker, _React$Component);

  var _super = _createSuper(VisualPicker);

  function VisualPicker() {
    _classCallCheck(this, VisualPicker);

    return _super.apply(this, arguments);
  }

  _createClass(VisualPicker, [{
    key: "UNSAFE_componentWillMount",
    // eslint-disable-next-line camelcase
    value: function UNSAFE_componentWillMount() {
      this.generatedId = shortid.generate();
    }
  }, {
    key: "render",
    value: function render() {
      var _this = this;

      var options = React.Children.map(this.props.children, function (option, index) {
        return /*#__PURE__*/React.cloneElement(option, {
          index: "".concat(_this.props.id || _this.generatedId, "-").concat(index),
          coverable: _this.props.coverable,
          variant: 'visual-picker',
          name: "".concat(_this.props.id || _this.generatedId, "_options"),
          size: _this.props.size,
          vertical: !!_this.props.vertical
        });
      });
      return this.props.links ? /*#__PURE__*/React.createElement("div", {
        className: "slds-form-element__control"
      }, this.props.children) : /*#__PURE__*/React.createElement("fieldset", {
        id: this.props.id,
        className: classNames("slds-form-element", this.props.className)
      }, /*#__PURE__*/React.createElement("legend", {
        className: "slds-form-element__legend slds-form-element__label"
      }, this.props.label), /*#__PURE__*/React.createElement("div", {
        className: "slds-form-element__control"
      }, options));
    }
  }]);

  return VisualPicker;
}(React.Component);

VisualPicker.displayName = VISUAL_PICKER;
VisualPicker.propTypes = propTypes;
VisualPicker.defaultProps = defaultProps;
export default VisualPicker;
//# sourceMappingURL=index.js.map