"use strict";

function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.WithValueControlledBehaviour = exports.WithMaxLength = exports.WithLabelTooltipPositionTop = exports.WithLabelTooltipInsideModal = exports.WithLabelTooltip = exports.WithDefaultValueUncontrolledBehaviour = exports.WithAutoFocus = exports.WithAutoComplete = exports.SuccessStory = exports.Small = exports.SimpleLoginForm = exports.RightAddonStory = exports.RequiredStory = exports.Quiet = exports.OnAColouredBackground = exports.MouseEvents = exports.HiddenLabel = exports.FullWidthStory = exports.ExtraInfoWithError = exports.ExtraInfoBelow = exports.ErrorIfEmptyText = exports.EdgeCases = exports.DisabledStory = exports.DisabledAddon = exports.DefaultStory = exports.BothAddons = exports.AlternatingTypes = exports.ActionsStory = void 0;
var _react = _interopRequireWildcard(require("react"));
var _addonActions = require("@storybook/addon-actions");
var _ = require("../../..");
var _Display = require("../../../common/Display");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
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; }
var handlers = (0, _addonActions.actions)('onBlur', 'onClick', 'onFocus', 'onKeyDown', 'onKeyUp', 'onKeyPress', 'onChange');
var _default = exports.default = {
  title: 'Molecules / Input / Text',
  parameters: {
    component: _.Input.Text
  }
};
var DefaultStory = exports.DefaultStory = {
  render: function render() {
    return _react.default.createElement(_.Input.Text, {
      label: "Label",
      placeholder: "Placeholder"
    });
  },
  name: 'Default'
};
var WithValueControlledBehaviour = exports.WithValueControlledBehaviour = {
  render: function render() {
    return _react.default.createElement(_.Input.Text, {
      label: "Label",
      placeholder: "Placeholder",
      value: "Some predefined text"
    });
  },
  name: 'With value (Controlled behaviour)'
};
var WithDefaultValueUncontrolledBehaviour = exports.WithDefaultValueUncontrolledBehaviour = {
  render: function render() {
    return _react.default.createElement(_.Input.Text, {
      label: "Label",
      placeholder: "Placeholder",
      defaultValue: "Some predefined text"
    });
  },
  name: 'With default value (Uncontrolled behaviour)'
};
var ErrorIfEmptyText = exports.ErrorIfEmptyText = {
  render: function render() {
    var Component = function Component() {
      var _useState = (0, _react.useState)(''),
        _useState2 = _slicedToArray(_useState, 2),
        value = _useState2[0],
        setValue = _useState2[1];
      return _react.default.createElement(_.Input.Text, _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.default.createElement(Component, null);
  },
  name: 'Error if empty text'
};
var SuccessStory = exports.SuccessStory = {
  render: function render() {
    return _react.default.createElement(_.Input.Text, {
      label: "Label",
      placeholder: "Placeholder",
      success: true
    });
  },
  name: 'Success'
};
var DisabledStory = exports.DisabledStory = {
  render: function render() {
    return _react.default.createElement(_.Input.Text, {
      label: "Label",
      placeholder: "Placeholder",
      disabled: true
    });
  },
  name: 'Disabled'
};
var DisabledAddon = exports.DisabledAddon = {
  render: function render() {
    return _react.default.createElement(_.Input.Text, {
      label: "Label",
      placeholder: "Placeholder",
      disabled: true,
      leftAddon: _react.default.createElement(_.OldIcon.Bolt, {
        size: 4
      }),
      rightAddon: "SEK"
    });
  },
  name: 'Disabled +addon'
};
var WithAutoFocus = exports.WithAutoFocus = {
  render: function render() {
    return _react.default.createElement(_.Input.Text, {
      label: "Label",
      placeholder: "Placeholder",
      autoFocus: true
    });
  },
  name: 'With auto focus'
};
var WithAutoComplete = exports.WithAutoComplete = {
  render: function render() {
    return _react.default.createElement(_react.default.Fragment, null, _react.default.createElement(_.Input.Text, {
      label: "Ordinary Text",
      placeholder: "Placeholder",
      autoComplete: "on"
    }), _react.default.createElement(_.Input.Text, {
      label: "E-mail",
      placeholder: "Placeholder",
      autoComplete: "email",
      type: "email"
    }), _react.default.createElement(_.Input.Text, {
      label: "Phone number",
      placeholder: "Placeholder",
      autoComplete: "tel",
      type: "tel"
    }));
  },
  name: 'With auto complete'
};
var RequiredStory = exports.RequiredStory = {
  render: function render() {
    return _react.default.createElement(_Display.Display, {
      title: "Required",
      items: [{
        component: _react.default.createElement(_.Input.Text, {
          label: "Label",
          placeholder: "Placeholder",
          required: true
        }),
        title: 'Default (without star)'
      }, {
        component: _react.default.createElement(_.Input.Text, {
          label: "Label",
          placeholder: "Placeholder",
          required: true,
          visuallyEmphasiseRequired: true
        }),
        title: 'With star'
      }]
    });
  },
  name: 'Required'
};
var ActionsStory = exports.ActionsStory = {
  render: function render() {
    return _react.default.createElement(_react.default.Fragment, null, _react.default.createElement("p", null, "Actions are a bit laggy because of the @storybook/addon-actions. Prod performance is not affected."), _react.default.createElement(_.Input.Text, _extends({
      label: "Label",
      placeholder: "Placeholder"
    }, handlers)));
  },
  name: 'Actions'
};
var ExtraInfoBelow = exports.ExtraInfoBelow = {
  render: function render() {
    return _react.default.createElement(_.Input.Text, {
      label: "Label",
      placeholder: "Placeholder",
      extraInfo: "Use this space wisely"
    });
  },
  name: 'Extra info below'
};
var ExtraInfoWithError = exports.ExtraInfoWithError = {
  render: function render() {
    var Component = function Component() {
      var _useState3 = (0, _react.useState)(''),
        _useState4 = _slicedToArray(_useState3, 2),
        value = _useState4[0],
        setValue = _useState4[1];
      return _react.default.createElement(_.Input.Text, _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.default.createElement(Component, null);
  },
  name: 'Extra info with error'
};
var EdgeCases = exports.EdgeCases = {
  render: function render() {
    return _react.default.createElement(_Display.Display, {
      items: [{
        component: _react.default.createElement(_.Input.Text, {
          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.default.createElement(_.Input.Text, {
          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'
};
var FullWidthStory = exports.FullWidthStory = {
  render: function render() {
    return _react.default.createElement(_Display.Display, {
      title: "Full width inputs",
      items: [{
        component: _react.default.createElement(_.Input.Text, {
          label: "Label",
          width: "100%",
          placeholder: "Placeholder"
        }),
        title: 'Default'
      }, {
        component: _react.default.createElement(_.Input.Text, {
          label: "Label",
          width: "100%",
          placeholder: "Placeholder",
          leftAddon: _react.default.createElement(_.OldIcon.Bolt, {
            size: 4
          })
        }),
        title: 'Left addon'
      }, {
        component: _react.default.createElement(_.Input.Text, {
          label: "Label",
          width: "100%",
          placeholder: "Placeholder",
          rightAddon: "SEK"
        }),
        title: 'Right addon'
      }]
    });
  },
  name: 'Full width'
};
var RightAddonStory = exports.RightAddonStory = {
  render: function render() {
    return _react.default.createElement(_.Input.Text, {
      label: "Label",
      placeholder: "Placeholder",
      rightAddon: "SEK"
    });
  },
  name: 'Right addon'
};
var BothAddons = exports.BothAddons = {
  render: function render() {
    return _react.default.createElement(_.Input.Text, {
      label: "Label",
      placeholder: "Placeholder",
      leftAddon: _react.default.createElement(_.OldIcon.Bolt, {
        size: 4
      }),
      rightAddon: "SEK"
    });
  },
  name: 'Both addons'
};
var HiddenLabel = exports.HiddenLabel = {
  render: function render() {
    return _react.default.createElement(_.Input.Text, {
      label: "Label",
      placeholder: "Placeholder",
      hideLabel: true
    });
  },
  name: 'Hidden label'
};
var SimpleLoginForm = exports.SimpleLoginForm = {
  render: function render() {
    return _react.default.createElement(_.Flexbox, {
      container: true,
      direction: "column",
      gap: 4
    }, _react.default.createElement(_.Flexbox, {
      item: true,
      container: true,
      gap: 4
    }, _react.default.createElement(_.Flexbox, {
      item: true,
      basis: "50%"
    }, _react.default.createElement(_.Input.Text, {
      width: "100%",
      label: "Username",
      placeholder: "Username",
      extraInfo: "Please provide your username (worst UX right here)"
    })), _react.default.createElement(_.Flexbox, {
      item: true,
      basis: "50%"
    }, _react.default.createElement(_.Input.Text, {
      width: "100%",
      label: "Password",
      placeholder: "Password",
      error: "Simple error"
    }))), _react.default.createElement(_.Flexbox, {
      item: true,
      container: true,
      justifyContent: "flex-end",
      grow: 1
    }, _react.default.createElement(_.Button, {
      fullWidth: true
    }, "Login")));
  },
  name: 'Simple login form'
};
var Small = exports.Small = function Small() {
  return _react.default.createElement(_Display.Display, {
    title: "Size = \"s\"",
    items: [{
      component: _react.default.createElement(_.Input.Text, {
        label: "Label",
        size: "s",
        placeholder: "Placeholder"
      }),
      title: 'Default'
    }, {
      component: _react.default.createElement(_.Input.Text, {
        label: "Label",
        size: "s",
        width: "100%",
        placeholder: "Placeholder"
      }),
      title: 'Full width'
    }, {
      component: _react.default.createElement(_.Input.Text, {
        label: "Label",
        size: "s",
        placeholder: "Placeholder",
        error: "Some error text that will wrap itself over couple of lines"
      }),
      title: 'Error'
    }, {
      component: _react.default.createElement(_.Input.Text, {
        label: "Label",
        size: "s",
        placeholder: "Placeholder",
        leftAddon: _react.default.createElement(_.OldIcon.Bolt, {
          size: 4
        })
      }),
      title: 'Left addon'
    }, {
      component: _react.default.createElement(_.Input.Text, {
        label: "Label",
        size: "s",
        placeholder: "Placeholder",
        rightAddon: "SEK"
      }),
      title: 'Right addon'
    }]
  });
};
var Quiet = exports.Quiet = function Quiet() {
  return _react.default.createElement(_Display.Display, {
    title: "Variant = \"quiet\"",
    items: [{
      component: _react.default.createElement(_.Input.Text, {
        variant: "quiet",
        label: "Label",
        placeholder: "Placeholder"
      }),
      title: 'Default'
    }, {
      component: _react.default.createElement(_.Input.Text, {
        variant: "quiet",
        label: "Label",
        placeholder: "Placeholder",
        value: "Fill State"
      }),
      title: 'Filled'
    }, {
      component: _react.default.createElement(_.Input.Text, {
        variant: "quiet",
        label: "Label",
        width: "100%",
        placeholder: "Placeholder"
      }),
      title: 'Full width'
    }, {
      component: _react.default.createElement(_.Input.Text, {
        variant: "quiet",
        label: "Label",
        width: "100%",
        disabled: true,
        value: "0"
      }),
      title: 'Disabled'
    }, {
      component: _react.default.createElement(_.Input.Text, {
        variant: "quiet",
        label: "Label",
        placeholder: "Placeholder",
        error: "Some error text that will wrap itself over couple of lines"
      }),
      title: 'Error'
    }, {
      component: _react.default.createElement(_.Input.Text, {
        variant: "quiet",
        label: "Label",
        placeholder: "Placeholder",
        success: true
      }),
      title: 'Success'
    }, {
      component: _react.default.createElement(_.Input.Text, {
        variant: "quiet",
        label: "Label",
        placeholder: "Placeholder",
        rightAddon: "%"
      }),
      title: 'Right addon'
    }, {
      component: _react.default.createElement(_.Input.Text, {
        variant: "quiet",
        label: "Label",
        placeholder: "Placeholder",
        leftAddon: "$"
      }),
      title: 'Left addon'
    }, {
      component: _react.default.createElement(_.Input.Text, {
        variant: "quiet",
        label: "Label",
        placeholder: "Placeholder",
        leftAddon: "$",
        rightAddon: "%"
      }),
      title: 'Both addon'
    }]
  });
};
var WithLabelTooltip = exports.WithLabelTooltip = {
  render: function render() {
    return _react.default.createElement(_.Input.Text, {
      label: "Label",
      labelTooltip: "Tooltip content",
      placeholder: "Placeholder"
    });
  },
  name: 'With tooltip as label addon'
};
var WithLabelTooltipPositionTop = exports.WithLabelTooltipPositionTop = {
  render: function render() {
    return _react.default.createElement(_react.default.Fragment, null, _react.default.createElement("br", null), _react.default.createElement("br", null), _react.default.createElement(_.Input.Text, {
      label: "Label",
      labelTooltip: "Tooltip content",
      labelTooltipPosition: "top",
      placeholder: "Placeholder"
    }));
  },
  name: 'With tooltip (position top) as label addon'
};
var WithMaxLength = exports.WithMaxLength = {
  render: function render() {
    return _react.default.createElement(_.Input.Text, {
      maxLength: 3,
      label: "has max length",
      placeholder: "Placeholder"
    });
  },
  name: 'With maxLength'
};
var AlternatingTypes = exports.AlternatingTypes = function AlternatingTypes() {
  return _react.default.createElement("form", {
    onSubmit: function onSubmit(e) {
      e.preventDefault();
    }
  }, _react.default.createElement("div", null, _react.default.createElement(_.Input.Text, {
    label: "email",
    type: "email"
  })), _react.default.createElement("div", null, _react.default.createElement(_.Input.Text, {
    label: "password",
    type: "password"
  })), _react.default.createElement("div", null, _react.default.createElement(_.Input.Text, {
    label: "search",
    type: "search"
  })), _react.default.createElement("div", null, _react.default.createElement(_.Input.Text, {
    label: "search",
    type: "submit"
  })));
};
var OnAColouredBackground = exports.OnAColouredBackground = {
  render: function render() {
    return _react.default.createElement(_.Box, {
      p: 5,
      backgroundColor: function backgroundColor(t) {
        return t.color.disabledBackground;
      }
    }, _react.default.createElement(_.Input.Text, {
      label: "On a colored background",
      placeholder: "Placeholder"
    }));
  },
  name: 'On a coloured background'
};
var MouseEvents = exports.MouseEvents = {
  render: function render() {
    var Component = function Component() {
      var _useState5 = (0, _react.useState)(false),
        _useState6 = _slicedToArray(_useState5, 2),
        isHovered = _useState6[0],
        setIsHovered = _useState6[1];
      var label = isHovered ? 'Is hovered' : 'Not hovered';
      return _react.default.createElement(_.Input.Text, {
        label: label,
        placeholder: "Placeholder",
        onMouseEnter: function onMouseEnter() {
          return setIsHovered(true);
        },
        onMouseLeave: function onMouseLeave() {
          return setIsHovered(false);
        }
      });
    };
    return _react.default.createElement(Component, null);
  },
  name: 'MouseEvents'
};
var WithLabelTooltipInsideModal = exports.WithLabelTooltipInsideModal = {
  render: function render() {
    var Example = function Example() {
      var _useState7 = (0, _react.useState)(true),
        _useState8 = _slicedToArray(_useState7, 2),
        open = _useState8[0],
        setOpen = _useState8[1];
      var onOpen = function onOpen() {
        setOpen(true);
      };
      var onClose = function onClose() {
        setOpen(false);
      };
      return _react.default.createElement(_react.default.Fragment, null, _react.default.createElement("button", {
        type: "button",
        onClick: onOpen
      }, "Open modal"), _react.default.createElement(_.Modal, {
        onClose: onClose,
        title: "Dialog information",
        open: open
      }, _react.default.createElement(_.Box, {
        mb: 2
      }, _react.default.createElement(_.Input.Text, {
        label: "Label",
        placeholder: "Placeholder",
        labelTooltipInModal: true,
        labelTooltip: "Tooltip content"
      }))));
    };
    return _react.default.createElement(Example, null);
  },
  name: 'With label tooltip inside modal'
};