text: function _typeof(obj) { 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 _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
  
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
  
  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 _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  
  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, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  
  import PropTypes from 'prop-types';
  import React, { Component } from 'react';
  import classNames from 'classnames';
  import Copy from '../Copy';
  import CopyButton from '../CopyButton';
  import Icon from '../Icon';
  
  var CodeSnippet =
  /*#__PURE__*/
  function (_Component) {
    _inherits(CodeSnippet, _Component);
  
    function CodeSnippet() {
      var _ref;
  
      var _temp, _this;
  
      _classCallCheck(this, CodeSnippet);
  
      for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
        args[_key] = arguments[_key];
      }
  
      return _possibleConstructorReturn(_this, (_temp = _this = _possibleConstructorReturn(this, (_ref = CodeSnippet.__proto__ || Object.getPrototypeOf(CodeSnippet)).call.apply(_ref, [this].concat(args))), Object.defineProperty(_assertThisInitialized(_this), "state", {
        configurable: true,
        enumerable: true,
        writable: true,
        value: {
          shouldShowMoreLessBtn: false,
          expandedCode: false
        }
      }), Object.defineProperty(_assertThisInitialized(_this), "expandCode", {
        configurable: true,
        enumerable: true,
        writable: true,
        value: function value() {
          _this.setState({
            expandedCode: !_this.state.expandedCode
          });
        }
      }), _temp));
    }
  
    _createClass(CodeSnippet, [{
      key: "componentDidMount",
      value: function componentDidMount() {
        if (this.codeContent) {
          if (this.codeContent.getBoundingClientRect().height > 255) {
            this.setState({
              shouldShowMoreLessBtn: true
            });
          }
        }
      }
    }, {
      key: "render",
      value: function render() {
        var _this2 = this;
  
        var _props = this.props,
            className = _props.className,
            type = _props.type,
            children = _props.children,
            feedback = _props.feedback,
            onClick = _props.onClick,
            copyLabel = _props.copyLabel,
            light = _props.light,
            showMoreText = _props.showMoreText,
            showLessText = _props.showLessText,
            other = _objectWithoutProperties(_props, ["className", "type", "children", "feedback", "onClick", "copyLabel", "light", "showMoreText", "showLessText"]);
  
        var codeSnippetClasses = classNames(className, {
          'bx--snippet': true,
          'bx--snippet--single': type === 'single',
          'bx--snippet--multi': type === 'multi',
          'bx--snippet--inline': type === 'inline',
          'bx--snippet--expand': this.state.expandedCode,
          'bx--snippet--light': light
        });
        var expandCodeBtnText = this.state.expandedCode ? showLessText : showMoreText;
        var moreLessBtn = React.createElement("button", {
          className: "bx--btn bx--btn--ghost bx--btn--sm bx--snippet-btn--expand",
          type: "button",
          onClick: this.expandCode
        }, React.createElement("span", {
          className: "bx--snippet-btn--text"
        }, expandCodeBtnText), React.createElement(Icon, {
          "aria-hidden": "true",
          alt: expandCodeBtnText,
          name: "chevron--down",
          description: expandCodeBtnText,
          className: "bx--icon-chevron--down"
        }));
        var code = React.createElement("div", {
          role: "textbox",
          tabIndex: 0,
          className: "bx--snippet-container"
        }, React.createElement("code", null, React.createElement("pre", {
          ref: function ref(codeContent) {
            _this2.codeContent = codeContent;
          }
        }, children)));
        var copy = React.createElement(CopyButton, {
          onClick: onClick,
          feedback: feedback
        });
  
        if (type === 'inline') {
          return React.createElement(Copy, {
            className: codeSnippetClasses,
            "aria-label": copyLabel,
            feedback: feedback
          }, React.createElement("code", null, children));
        }
  
        if (type === 'single') {
          return React.createElement("div", _extends({}, other, {
            className: codeSnippetClasses
          }), code, copy);
        }
  
        if (!this.state.shouldShowMoreLessBtn && type === 'multi') {
          return React.createElement("div", _extends({}, other, {
            className: codeSnippetClasses
          }), code, copy);
        }
  
        if (this.state.shouldShowMoreLessBtn && type === 'multi') {
          return React.createElement("div", _extends({
            className: codeSnippetClasses
          }, other), code, copy, moreLessBtn);
        }
      }
    }]);
  
    return CodeSnippet;
  }(Component);
  
  Object.defineProperty(CodeSnippet, "propTypes", {
    configurable: true,
    enumerable: true,
    writable: true,
    value: {
      /**
       * The type of code snippet
       * can be inline, single or multi
       */
      type: PropTypes.oneOf(['single', 'inline', 'multi']),
      className: PropTypes.string,
      children: PropTypes.string,
      feedback: PropTypes.string,
      copyLabel: PropTypes.string,
      onClick: PropTypes.func,
  
      /**
       * Used with multi snippet only
       * when text is more than 15 lines
       */
      showMoreText: PropTypes.string,
      showLessText: PropTypes.string,
  
      /**
       * Used with inline snippet only
       * to display alternate color
       */
      light: PropTypes.bool
    }
  });
  Object.defineProperty(CodeSnippet, "defaultProps", {
    configurable: true,
    enumerable: true,
    writable: true,
    value: {
      type: 'single',
      showMoreText: 'Show more',
      showLessText: 'Show less'
    }
  });
  export { CodeSnippet as default };