"use strict";

exports.__esModule = true;
exports.default = void 0;

var _react = _interopRequireDefault(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _ = require("./..");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: 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; }

/**
 * @category controls
 * @component checkbox
 * @variations collab-ui-react
 */
var Checkbox = function Checkbox(props) {
  var checked = props.checked,
      children = props.children,
      className = props.className,
      disabled = props.disabled,
      htmlId = props.htmlId,
      indeterminate = props.indeterminate,
      inputRef = props.inputRef,
      label = props.label,
      name = props.name,
      nestedLevel = props.nestedLevel,
      onChange = props.onChange,
      required = props.required,
      value = props.value,
      otherProps = _objectWithoutProperties(props, ["checked", "children", "className", "disabled", "htmlId", "indeterminate", "inputRef", "label", "name", "nestedLevel", "onChange", "required", "value"]);

  return _react.default.createElement("div", {
    className: 'cui-input-group cui-checkbox' + ("" + (nestedLevel && " cui-input--nested-" + nestedLevel || '')) + (" " + className)
  }, _react.default.createElement("input", _extends({
    "aria-checked": checked,
    className: "cui-input cui-checkbox__input" + ("" + (indeterminate && ' indeterminate' || '')),
    type: "checkbox",
    ref: inputRef,
    disabled: disabled,
    checked: checked,
    required: required,
    name: name,
    value: value,
    onChange: onChange,
    tabIndex: 0,
    id: htmlId
  }, otherProps)), _react.default.createElement(_.Label, {
    className: "cui-checkbox__label",
    label: label,
    htmlFor: htmlId
  }), children);
};

Checkbox.propTypes = {
  /**
   * optional nextLevel prop type
   */
  nestedLevel: _propTypes.default.number,

  /**
   * optional className prop type
   */
  className: _propTypes.default.string,

  /**
   * optional indeterminate prop type
   */
  indeterminate: _propTypes.default.bool,

  /**
   * optional disabled prop type
   */
  disabled: _propTypes.default.bool,

  /**
   * optional required prop type
   */
  required: _propTypes.default.bool,

  /**
   * optional checked prop type
   */
  checked: _propTypes.default.bool,

  /**
   * optional name prop type
   */
  name: _propTypes.default.string,

  /**
   * optional label prop type
   */
  label: _propTypes.default.string.isRequired,

  /**
   * optional value prop type
   */
  value: _propTypes.default.string,

  /**
   * optional ref prop type
   */
  inputRef: _propTypes.default.func,

  /**
   * Unique HTML ID. Used for tying label to HTML input. Handy hook for automated testing.
   */
  htmlId: _propTypes.default.string.isRequired,

  /**
   * optional onChange prop type
   */
  onChange: _propTypes.default.func,

  /**
   * Child component to display next to the input
   */
  children: _propTypes.default.node
};
Checkbox.defaultProps = {
  nestedLevel: 0,
  className: '',
  indeterminate: false,
  disabled: false,
  required: false,
  autoFocus: false,
  checked: false,
  name: '',
  value: '',
  label: '',
  inputRef: null,
  onChange: null
};
Checkbox.displayName = 'Checkbox';
var _default = Checkbox;
/**
* @name Default Checkbox Group
*
* @category controls
* @component checkbox
* @section default
*
* @js

import { CheckboxGroup, InputHelper } from '@collab-ui/react';

export default function DefaultCheckboxGroup() {

  return (
    <CheckboxGroup name='CheckboxGroup1'>
      <Checkbox
        value='me'
        label='me'
        htmlId='testCheckbox1'
        onChange={()=>{}}
      />
      <Checkbox
        value='you'
        label='you'
        htmlId='testCheckbox2'
        onChange={()=>{}}
      />
      <Checkbox
        value='us'
        label='us'
        htmlId='testCheckbox3'
        onChange={()=>{}}
      >
        <InputHelper message={'I\'m here to help'} className='cui-checkbox-help' />
      </Checkbox>
    </CheckboxGroup>
  );
}

**/

/**
* @name Indeterminate Checkbox
* @description Checkboxes can be marked as indeterminate by passing in the indeterminate prop.
*
* @category controls
* @component checkbox
* @section indeterminate
*
* @js

export default function CheckboxIndeterminate() {
  return (
    <Checkbox
      value='indeterminate'
      label='Indeterminate Checkbox'
      htmlId='indeterminateCheckbox'
      onChange={()=>{}}
      indeterminate
    />
  );
}
**/

/**
* @name Disabled Checkbox
* @description Checkboxes can be disabled by passing in the disabled prop.
*
* @category controls
* @component checkbox
* @section disabled
*
* @js

export default function CheckboxDisabled() {
  return (
    <Checkbox
      value='disabledChecked'
      label='Disabled Checkbox'
      htmlId='disabledCheckbox'
      disabled
      onChange={()=>{}}
    />
  );
}
**/

/**
* @name Checked Checkbox
* @description Checkboxes can be checked be passing in the checked prop.
*
* @category controls
* @component checkbox
* @section checked
*
* @js

export default function CheckboxChecked() {
  return (
    <Checkbox
      value='checked'
      label='Checked Checkbox'
      htmlId='checkedCheckbox'
      checked
      onChange={()=>{}}
    />
  );
}
**/

/**
* @name Nested Checkboxes
* @description The level of nesting checkboxes is controlled by the nestedLevel prop.  You can have up to 3 nested levels.  Ex. nestedLevel={1} nestedLevel={2} nestedLevel=[3} etc.
*
* @category controls
* @component checkbox
* @section nested
*
* @js

export default class CheckboxNested extends React.PureComponent {
  state = {
    parent: false,
    child1: false,
    child2: false,
    child3: false,
  }

  render() {
    return (
      <span>
        <Checkbox
          value='parent'
          label='Parent Checkbox Example'
          htmlId='parentCheckbox'
          checked={this.state.parent}
          onChange={() => this.setState({ parent: !this.state.parent })}
          key='child-0'
        />
        <Checkbox
          value='child1'
          label='Child Checkbox Nested 1 Level'
          htmlId='childCheckbox1'
          nestedLevel={1}
          checked={this.state.child1}
          onChange={() => this.setState({ child1: !this.state.child1 })}
          key='child-1'
        />
        <Checkbox
          value='child2'
          label='Child Checkbox Nested 2 Levels'
          htmlId='childCheckbox2'
          nestedLevel={2}
          checked={this.state.child2}
          onChange={() => this.setState({ child2: !this.state.child2 })}
          key='child-2'
        />
        <Checkbox
          value='child3'
          label='Child Checkbox Nested 3 Levels'
          htmlId='childCheckbox3'
          nestedLevel={3}
          checked={this.state.child3}
          onChange={() => this.setState({ child3: !this.state.child3 })}
          key='child-3'
        />
      </span>
    );
  }
}
**/

exports.default = _default;