function _extends() { _extends = Object.assign ? Object.assign.bind() : 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 _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import React, { useState } from 'react';
import { actions } from '@storybook/addon-actions';
import { Box, Input, Modal } from '../../..';
import { Display } from '../../../common/Display';
var handlers = actions('onBlur', 'onClick', 'onFocus', 'onKeyDown', 'onKeyUp', 'onKeyPress', 'onChange');
export default {
  title: 'Molecules / Input / Textarea',
  parameters: {
    component: Input.Textarea
  }
};
export var Default = {
  render: function render() {
    return React.createElement(Input.Textarea, {
      label: "Label",
      placeholder: "Placeholder"
    });
  }
};
export var WithValueControlledBehaviour = {
  render: function render() {
    return React.createElement(Input.Textarea, {
      label: "Label",
      placeholder: "Placeholder",
      value: "Some predefined text"
    });
  },
  name: 'With value (Controlled behaviour)'
};
export var WithDefaultValueUncontrolledBehaviour = {
  render: function render() {
    return React.createElement(Input.Textarea, {
      label: "Label",
      placeholder: "Placeholder",
      defaultValue: "Some predefined text"
    });
  },
  name: 'With default value (Uncontrolled behaviour)'
};
export var ErrorIfEmptyText = {
  render: function render() {
    var Component = function Component() {
      var _useState = useState(''),
        _useState2 = _slicedToArray(_useState, 2),
        value = _useState2[0],
        setValue = _useState2[1];
      return React.createElement(Input.Textarea, _extends({
        label: "My awesome text field",
        placeholder: "This is a placeholder",
        onChange: function onChange(e) {
          return setValue(e.target.value);
        }
      }, value === '' ? {
        error: 'Something went wrong'
      } : {}));
    };
    return React.createElement(Component, null);
  },
  name: 'Error if empty text'
};
export var SuccessStory = {
  render: function render() {
    return React.createElement(Input.Textarea, {
      label: "Label",
      placeholder: "Placeholder",
      success: true
    });
  },
  name: 'Success'
};
export var DisabledStory = {
  render: function render() {
    return React.createElement(Input.Textarea, {
      label: "Label",
      placeholder: "Placeholder",
      disabled: true
    });
  },
  name: 'Disabled'
};
export var WithAutoFocus = {
  render: function render() {
    return React.createElement(Input.Textarea, {
      label: "Label",
      placeholder: "Placeholder",
      autoFocus: true
    });
  },
  name: 'With auto focus'
};
export var RequiredStory = {
  render: function render() {
    return React.createElement(Display, {
      title: "Required",
      items: [{
        component: React.createElement(Input.Textarea, {
          label: "Label",
          placeholder: "Placeholder",
          required: true
        }),
        title: 'Default (without star)'
      }, {
        component: React.createElement(Input.Textarea, {
          label: "Label",
          placeholder: "Placeholder",
          required: true,
          visuallyEmphasiseRequired: true
        }),
        title: 'With star'
      }]
    });
  },
  name: 'Required'
};
export var ActionsStory = {
  render: function render() {
    return React.createElement(React.Fragment, null, React.createElement("p", null, "Actions are a bit laggy because of the @storybook/addon-actions. Prod performance is not affected."), React.createElement(Input.Textarea, _extends({
      label: "Label",
      placeholder: "Placeholder"
    }, handlers)));
  },
  name: 'Actions'
};
export var ExtraInfoBelow = {
  render: function render() {
    return React.createElement(Input.Textarea, {
      label: "Label",
      placeholder: "Placeholder",
      extraInfo: "Use this space wisely"
    });
  },
  name: 'Extra info below'
};
export var ExtraInfoWithError = {
  render: function render() {
    var Component = function Component() {
      var _useState3 = useState(''),
        _useState4 = _slicedToArray(_useState3, 2),
        value = _useState4[0],
        setValue = _useState4[1];
      return React.createElement(Input.Textarea, _extends({
        label: "My awesome text field",
        placeholder: "This is a placeholder",
        extraInfo: "Use this space wisely",
        onChange: function onChange(e) {
          return setValue(e.target.value);
        }
      }, value === '' ? {
        error: 'Enter text'
      } : {}));
    };
    return React.createElement(Component, null);
  },
  name: 'Extra info with error'
};
export var EdgeCases = {
  render: function render() {
    return React.createElement(Display, {
      items: [{
        component: React.createElement(Input.Textarea, {
          label: "Too long label, goes into ellipsis. Consider smaller label or bigger input",
          placeholder: "If placeholder goes too long though, it probably should be truncated into ellipsis, right?",
          extraInfo: "This is much necessary info wow"
        }),
        title: 'Long values'
      }, {
        component: React.createElement(Input.Textarea, {
          label: "Small label",
          placeholder: "",
          extraInfo: "Big extra fat extraInfo that will wrap over many lines. Be careful with this pattern, use it only with small texts!"
        }),
        title: 'Long extraInfo'
      }]
    });
  },
  name: 'Edge cases'
};
export var FullWidth = {
  render: function render() {
    return React.createElement(Input.Textarea, {
      label: "Label",
      width: "100%",
      placeholder: "Placeholder"
    });
  },
  name: 'Full width'
};
export var SpecificWidth = {
  render: function render() {
    return React.createElement(Input.Textarea, {
      label: "Label",
      width: "400px",
      placeholder: "Placeholder"
    });
  },
  name: 'Specific width'
};
export var HiddenLabel = {
  render: function render() {
    return React.createElement(Input.Textarea, {
      label: "Label",
      placeholder: "Placeholder",
      hideLabel: true
    });
  },
  name: 'Hidden label'
};
export var WithLabelTooltip = {
  render: function render() {
    return React.createElement(Input.Textarea, {
      label: "Label",
      labelTooltip: "Tooltip content",
      placeholder: "Placeholder"
    });
  },
  name: 'With tooltip as label addon'
};
export var WithLabelTooltipPositionTop = {
  render: function render() {
    return React.createElement(React.Fragment, null, React.createElement("br", null), React.createElement("br", null), React.createElement(Input.Textarea, {
      label: "Label",
      labelTooltip: "Tooltip content",
      labelTooltipPosition: "top",
      placeholder: "Placeholder"
    }));
  },
  name: 'With tooltip (position top) as label addon'
};
export var OnAColouredBackground = {
  render: function render() {
    return React.createElement(Box, {
      p: 5,
      backgroundColor: function backgroundColor(t) {
        return t.color.disabledBackground;
      }
    }, React.createElement(Input.Textarea, {
      label: "On a colored background",
      placeholder: "Placeholder"
    }));
  },
  name: 'On a coloured background'
};
export var WithMaxLength = {
  render: function render() {
    return React.createElement(React.Fragment, null, React.createElement(Input.Textarea, {
      label: "Label",
      maxLength: 20
    }));
  },
  name: 'With max length 20 characters'
};
export var WithResizeNone = {
  render: function render() {
    return React.createElement(React.Fragment, null, React.createElement(Input.Textarea, {
      label: "Label",
      noResize: true
    }));
  },
  name: 'With resize none'
};
export var WithLabelTooltipInsideModal = {
  render: function render() {
    var Example = function Example() {
      var _useState5 = useState(true),
        _useState6 = _slicedToArray(_useState5, 2),
        open = _useState6[0],
        setOpen = _useState6[1];
      var onOpen = function onOpen() {
        setOpen(true);
      };
      var onClose = function onClose() {
        setOpen(false);
      };
      return React.createElement(React.Fragment, null, React.createElement("button", {
        type: "button",
        onClick: onOpen
      }, "Open modal"), React.createElement(Modal, {
        onClose: onClose,
        title: "Dialog information",
        open: open
      }, React.createElement(Box, {
        mb: 2
      }, React.createElement(Input.Textarea, {
        label: "Label",
        placeholder: "Placeholder",
        labelTooltip: "Tooltip content",
        labelTooltipInModal: true
      }))));
    };
    return React.createElement(Example, null);
  },
  name: 'With label tooltip inside modal'
};