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, Button, Flexbox, OldIcon, Input, Modal } from '../../..';
import { Display } from '../../../common/Display';
var handlers = actions('onBlur', 'onClick', 'onFocus', 'onKeyDown', 'onKeyUp', 'onKeyPress', 'onChange');
export default {
  title: 'Molecules / Input / Text',
  parameters: {
    component: Input.Text
  }
};
export var DefaultStory = {
  render: function render() {
    return React.createElement(Input.Text, {
      label: "Label",
      placeholder: "Placeholder"
    });
  },
  name: 'Default'
};
export var WithValueControlledBehaviour = {
  render: function render() {
    return React.createElement(Input.Text, {
      label: "Label",
      placeholder: "Placeholder",
      value: "Some predefined text"
    });
  },
  name: 'With value (Controlled behaviour)'
};
export var WithDefaultValueUncontrolledBehaviour = {
  render: function render() {
    return React.createElement(Input.Text, {
      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.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.createElement(Component, null);
  },
  name: 'Error if empty text'
};
export var SuccessStory = {
  render: function render() {
    return React.createElement(Input.Text, {
      label: "Label",
      placeholder: "Placeholder",
      success: true
    });
  },
  name: 'Success'
};
export var DisabledStory = {
  render: function render() {
    return React.createElement(Input.Text, {
      label: "Label",
      placeholder: "Placeholder",
      disabled: true
    });
  },
  name: 'Disabled'
};
export var DisabledAddon = {
  render: function render() {
    return React.createElement(Input.Text, {
      label: "Label",
      placeholder: "Placeholder",
      disabled: true,
      leftAddon: React.createElement(OldIcon.Bolt, {
        size: 4
      }),
      rightAddon: "SEK"
    });
  },
  name: 'Disabled +addon'
};
export var WithAutoFocus = {
  render: function render() {
    return React.createElement(Input.Text, {
      label: "Label",
      placeholder: "Placeholder",
      autoFocus: true
    });
  },
  name: 'With auto focus'
};
export var WithAutoComplete = {
  render: function render() {
    return React.createElement(React.Fragment, null, React.createElement(Input.Text, {
      label: "Ordinary Text",
      placeholder: "Placeholder",
      autoComplete: "on"
    }), React.createElement(Input.Text, {
      label: "E-mail",
      placeholder: "Placeholder",
      autoComplete: "email",
      type: "email"
    }), React.createElement(Input.Text, {
      label: "Phone number",
      placeholder: "Placeholder",
      autoComplete: "tel",
      type: "tel"
    }));
  },
  name: 'With auto complete'
};
export var RequiredStory = {
  render: function render() {
    return React.createElement(Display, {
      title: "Required",
      items: [{
        component: React.createElement(Input.Text, {
          label: "Label",
          placeholder: "Placeholder",
          required: true
        }),
        title: 'Default (without star)'
      }, {
        component: React.createElement(Input.Text, {
          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.Text, _extends({
      label: "Label",
      placeholder: "Placeholder"
    }, handlers)));
  },
  name: 'Actions'
};
export var ExtraInfoBelow = {
  render: function render() {
    return React.createElement(Input.Text, {
      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.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.createElement(Component, null);
  },
  name: 'Extra info with error'
};
export var EdgeCases = {
  render: function render() {
    return React.createElement(Display, {
      items: [{
        component: React.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.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'
};
export var FullWidthStory = {
  render: function render() {
    return React.createElement(Display, {
      title: "Full width inputs",
      items: [{
        component: React.createElement(Input.Text, {
          label: "Label",
          width: "100%",
          placeholder: "Placeholder"
        }),
        title: 'Default'
      }, {
        component: React.createElement(Input.Text, {
          label: "Label",
          width: "100%",
          placeholder: "Placeholder",
          leftAddon: React.createElement(OldIcon.Bolt, {
            size: 4
          })
        }),
        title: 'Left addon'
      }, {
        component: React.createElement(Input.Text, {
          label: "Label",
          width: "100%",
          placeholder: "Placeholder",
          rightAddon: "SEK"
        }),
        title: 'Right addon'
      }]
    });
  },
  name: 'Full width'
};
export var RightAddonStory = {
  render: function render() {
    return React.createElement(Input.Text, {
      label: "Label",
      placeholder: "Placeholder",
      rightAddon: "SEK"
    });
  },
  name: 'Right addon'
};
export var BothAddons = {
  render: function render() {
    return React.createElement(Input.Text, {
      label: "Label",
      placeholder: "Placeholder",
      leftAddon: React.createElement(OldIcon.Bolt, {
        size: 4
      }),
      rightAddon: "SEK"
    });
  },
  name: 'Both addons'
};
export var HiddenLabel = {
  render: function render() {
    return React.createElement(Input.Text, {
      label: "Label",
      placeholder: "Placeholder",
      hideLabel: true
    });
  },
  name: 'Hidden label'
};
export var SimpleLoginForm = {
  render: function render() {
    return React.createElement(Flexbox, {
      container: true,
      direction: "column",
      gap: 4
    }, React.createElement(Flexbox, {
      item: true,
      container: true,
      gap: 4
    }, React.createElement(Flexbox, {
      item: true,
      basis: "50%"
    }, React.createElement(Input.Text, {
      width: "100%",
      label: "Username",
      placeholder: "Username",
      extraInfo: "Please provide your username (worst UX right here)"
    })), React.createElement(Flexbox, {
      item: true,
      basis: "50%"
    }, React.createElement(Input.Text, {
      width: "100%",
      label: "Password",
      placeholder: "Password",
      error: "Simple error"
    }))), React.createElement(Flexbox, {
      item: true,
      container: true,
      justifyContent: "flex-end",
      grow: 1
    }, React.createElement(Button, {
      fullWidth: true
    }, "Login")));
  },
  name: 'Simple login form'
};
export var Small = function Small() {
  return React.createElement(Display, {
    title: "Size = \"s\"",
    items: [{
      component: React.createElement(Input.Text, {
        label: "Label",
        size: "s",
        placeholder: "Placeholder"
      }),
      title: 'Default'
    }, {
      component: React.createElement(Input.Text, {
        label: "Label",
        size: "s",
        width: "100%",
        placeholder: "Placeholder"
      }),
      title: 'Full width'
    }, {
      component: React.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.createElement(Input.Text, {
        label: "Label",
        size: "s",
        placeholder: "Placeholder",
        leftAddon: React.createElement(OldIcon.Bolt, {
          size: 4
        })
      }),
      title: 'Left addon'
    }, {
      component: React.createElement(Input.Text, {
        label: "Label",
        size: "s",
        placeholder: "Placeholder",
        rightAddon: "SEK"
      }),
      title: 'Right addon'
    }]
  });
};
export var Quiet = function Quiet() {
  return React.createElement(Display, {
    title: "Variant = \"quiet\"",
    items: [{
      component: React.createElement(Input.Text, {
        variant: "quiet",
        label: "Label",
        placeholder: "Placeholder"
      }),
      title: 'Default'
    }, {
      component: React.createElement(Input.Text, {
        variant: "quiet",
        label: "Label",
        placeholder: "Placeholder",
        value: "Fill State"
      }),
      title: 'Filled'
    }, {
      component: React.createElement(Input.Text, {
        variant: "quiet",
        label: "Label",
        width: "100%",
        placeholder: "Placeholder"
      }),
      title: 'Full width'
    }, {
      component: React.createElement(Input.Text, {
        variant: "quiet",
        label: "Label",
        width: "100%",
        disabled: true,
        value: "0"
      }),
      title: 'Disabled'
    }, {
      component: React.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.createElement(Input.Text, {
        variant: "quiet",
        label: "Label",
        placeholder: "Placeholder",
        success: true
      }),
      title: 'Success'
    }, {
      component: React.createElement(Input.Text, {
        variant: "quiet",
        label: "Label",
        placeholder: "Placeholder",
        rightAddon: "%"
      }),
      title: 'Right addon'
    }, {
      component: React.createElement(Input.Text, {
        variant: "quiet",
        label: "Label",
        placeholder: "Placeholder",
        leftAddon: "$"
      }),
      title: 'Left addon'
    }, {
      component: React.createElement(Input.Text, {
        variant: "quiet",
        label: "Label",
        placeholder: "Placeholder",
        leftAddon: "$",
        rightAddon: "%"
      }),
      title: 'Both addon'
    }]
  });
};
export var WithLabelTooltip = {
  render: function render() {
    return React.createElement(Input.Text, {
      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.Text, {
      label: "Label",
      labelTooltip: "Tooltip content",
      labelTooltipPosition: "top",
      placeholder: "Placeholder"
    }));
  },
  name: 'With tooltip (position top) as label addon'
};
export var WithMaxLength = {
  render: function render() {
    return React.createElement(Input.Text, {
      maxLength: 3,
      label: "has max length",
      placeholder: "Placeholder"
    });
  },
  name: 'With maxLength'
};
export var AlternatingTypes = function AlternatingTypes() {
  return React.createElement("form", {
    onSubmit: function onSubmit(e) {
      e.preventDefault();
    }
  }, React.createElement("div", null, React.createElement(Input.Text, {
    label: "email",
    type: "email"
  })), React.createElement("div", null, React.createElement(Input.Text, {
    label: "password",
    type: "password"
  })), React.createElement("div", null, React.createElement(Input.Text, {
    label: "search",
    type: "search"
  })), React.createElement("div", null, React.createElement(Input.Text, {
    label: "search",
    type: "submit"
  })));
};
export var OnAColouredBackground = {
  render: function render() {
    return React.createElement(Box, {
      p: 5,
      backgroundColor: function backgroundColor(t) {
        return t.color.disabledBackground;
      }
    }, React.createElement(Input.Text, {
      label: "On a colored background",
      placeholder: "Placeholder"
    }));
  },
  name: 'On a coloured background'
};
export var MouseEvents = {
  render: function render() {
    var Component = function Component() {
      var _useState5 = useState(false),
        _useState6 = _slicedToArray(_useState5, 2),
        isHovered = _useState6[0],
        setIsHovered = _useState6[1];
      var label = isHovered ? 'Is hovered' : 'Not hovered';
      return React.createElement(Input.Text, {
        label: label,
        placeholder: "Placeholder",
        onMouseEnter: function onMouseEnter() {
          return setIsHovered(true);
        },
        onMouseLeave: function onMouseLeave() {
          return setIsHovered(false);
        }
      });
    };
    return React.createElement(Component, null);
  },
  name: 'MouseEvents'
};
export var WithLabelTooltipInsideModal = {
  render: function render() {
    var Example = function Example() {
      var _useState7 = 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.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.Text, {
        label: "Label",
        placeholder: "Placeholder",
        labelTooltipInModal: true,
        labelTooltip: "Tooltip content"
      }))));
    };
    return React.createElement(Example, null);
  },
  name: 'With label tooltip inside modal'
};