"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.WithSuccess = exports.WithSizeSmall = exports.WithRightAddon = exports.WithPlaceholder = exports.WithNoSteppers = exports.WithMaxAndMin = exports.WithLabelTooltipPositionTop = exports.WithLabelTooltipInsideModal = exports.WithLabelTooltip = exports.WithHiddenLabel = exports.WithExtraInfoBelow = exports.WithExtraInfoAndError = exports.WithErrorIfValueIsLessThan1 = exports.WithDefaultValueUncontrolledBehaviour = exports.WithBothAddons = exports.WithAutoFocus = exports.WithAllActions = exports.WithASmallerStep = exports.RequiredStory = exports.QuietNumber = exports.OnAColouredBackground = exports.DisabledStory = exports.DefaultStoryWithAutoCompleteOff = exports.DefaultStory = 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', 'onStepUp', 'onStepDown');
var _default = exports.default = {
  title: 'Molecules / Input / FormattedNumber',
  parameters: {
    component: _.Input.FormattedNumber
  }
};
var DefaultStory = exports.DefaultStory = function DefaultStory() {
  return _react.default.createElement(_.Input.FormattedNumber, {
    id: "formatted-number-id",
    label: "Label",
    onChange: (0, _addonActions.action)('onChange')
  });
};
DefaultStory.story = {
  name: 'Default'
};
var DefaultStoryWithAutoCompleteOff = exports.DefaultStoryWithAutoCompleteOff = function DefaultStoryWithAutoCompleteOff() {
  return _react.default.createElement(_.Input.FormattedNumber, {
    id: "formatted-number-id",
    label: "Label",
    onChange: (0, _addonActions.action)('onChange'),
    autoComplete: "off"
  });
};
DefaultStoryWithAutoCompleteOff.story = {
  name: 'Default with Auto Complete off'
};
var WithValueControlledBehaviourExample = function WithValueControlledBehaviourExample() {
  var _useState = (0, _react.useState)(10),
    _useState2 = _slicedToArray(_useState, 2),
    value = _useState2[0],
    setValue = _useState2[1];
  var changeHandler = function changeHandler(v) {
    setValue(v);
  };
  return _react.default.createElement(_react.default.Fragment, null, _react.default.createElement(_.Input.FormattedNumber, {
    id: "formatted-number-id",
    label: "Label",
    value: value,
    onChange: changeHandler
  }), _react.default.createElement("button", {
    type: "button",
    onClick: function onClick() {
      return setValue((value !== null && value !== void 0 ? value : 0) - 1);
    }
  }, "Decrease"), _react.default.createElement("button", {
    type: "button",
    onClick: function onClick() {
      return setValue((value !== null && value !== void 0 ? value : 0) + 1);
    }
  }, "Increase"));
};
var WithValueControlledBehaviour = exports.WithValueControlledBehaviour = {
  render: function render() {
    return _react.default.createElement(WithValueControlledBehaviourExample, null);
  },
  name: 'With value (Controlled behaviour)'
};
var WithDefaultValueUncontrolledBehaviour = exports.WithDefaultValueUncontrolledBehaviour = function WithDefaultValueUncontrolledBehaviour() {
  return _react.default.createElement(_.Input.FormattedNumber, {
    id: "formatted-number-id",
    label: "Label",
    defaultValue: 15.2,
    step: 0.1
  });
};
WithDefaultValueUncontrolledBehaviour.story = {
  name: 'With default value (Uncontrolled behaviour)'
};
var WithASmallerStep = exports.WithASmallerStep = function WithASmallerStep() {
  return _react.default.createElement(_.Input.FormattedNumber, {
    id: "formatted-number-id",
    label: "Label",
    defaultValue: 15.2,
    step: 0.005
  });
};
WithASmallerStep.story = {
  name: 'With a smaller step'
};
var WithMaxAndMin = exports.WithMaxAndMin = function WithMaxAndMin() {
  return _react.default.createElement(_.Input.FormattedNumber, {
    id: "formatted-number-id",
    label: "Label",
    defaultValue: 12,
    min: 10,
    max: 20
  });
};
WithMaxAndMin.story = {
  name: 'With max and min'
};
var RequiredStory = exports.RequiredStory = function RequiredStory() {
  return _react.default.createElement(_Display.Display, {
    title: "Required",
    items: [{
      component: _react.default.createElement(_.Input.FormattedNumber, {
        id: "formatted-number-id",
        label: "Label",
        defaultValue: 91,
        required: true
      }),
      title: 'Default (without star)'
    }, {
      component: _react.default.createElement(_.Input.FormattedNumber, {
        id: "formatted-number-id",
        label: "Label",
        defaultValue: 91,
        required: true,
        visuallyEmphasiseRequired: true
      }),
      title: 'With star'
    }]
  });
};
RequiredStory.story = {
  name: 'Required'
};
var DisabledStory = exports.DisabledStory = function DisabledStory() {
  return _react.default.createElement(_.Input.FormattedNumber, {
    id: "formatted-number-id",
    label: "Label",
    defaultValue: 152.25,
    step: 0.25,
    disabled: true
  });
};
DisabledStory.story = {
  name: 'Disabled'
};
var WithAutoFocus = exports.WithAutoFocus = function WithAutoFocus() {
  return _react.default.createElement(_.Input.FormattedNumber, {
    id: "formatted-number-id",
    label: "Label",
    defaultValue: 152.25,
    step: 0.25,
    autoFocus: true
  });
};
WithAutoFocus.story = {
  name: 'With auto focus'
};
var WithAllActions = exports.WithAllActions = function WithAllActions() {
  return _react.default.createElement(_.Input.FormattedNumber, _extends({
    id: "formatted-number-id",
    label: "Label"
  }, handlers));
};
WithAllActions.story = {
  name: 'With all actions'
};
var WithErrorIfValueIsLessThan1Example = function WithErrorIfValueIsLessThan1Example() {
  var defaultValue = 0;
  var _useState3 = (0, _react.useState)(defaultValue),
    _useState4 = _slicedToArray(_useState3, 2),
    value = _useState4[0],
    setValue = _useState4[1];
  var showError = value === null || value < 1;
  return _react.default.createElement(_.Input.FormattedNumber, _extends({
    id: "formatted-number-id",
    label: "Label",
    step: 1,
    defaultValue: defaultValue,
    onChange: setValue
  }, showError ? {
    error: 'Number needs to be greater than 0'
  } : {}));
};
var WithErrorIfValueIsLessThan1 = exports.WithErrorIfValueIsLessThan1 = {
  render: function render() {
    return _react.default.createElement(WithErrorIfValueIsLessThan1Example, null);
  },
  name: 'With error if value is less than 1'
};
var WithSuccess = exports.WithSuccess = function WithSuccess() {
  return _react.default.createElement(_.Input.FormattedNumber, {
    id: "formatted-number-id",
    label: "Label",
    success: true
  });
};
WithSuccess.story = {
  name: 'With success'
};
var WithExtraInfoBelow = exports.WithExtraInfoBelow = function WithExtraInfoBelow() {
  return _react.default.createElement(_.Input.FormattedNumber, {
    id: "formatted-number-id",
    label: "Label",
    extraInfo: "Use this space wisely"
  });
};
WithExtraInfoBelow.story = {
  name: 'With extra info below'
};
var WithExtraInfoAndErrorExample = function WithExtraInfoAndErrorExample() {
  var defaultValue = 0;
  var _useState5 = (0, _react.useState)(defaultValue),
    _useState6 = _slicedToArray(_useState5, 2),
    value = _useState6[0],
    setValue = _useState6[1];
  var showError = value < 1;
  return _react.default.createElement(_.Input.FormattedNumber, _extends({
    id: "formatted-number-id",
    label: "Label",
    defaultValue: defaultValue,
    onChange: function onChange(x) {
      return x && setValue(x);
    },
    extraInfo: "Use this space wisely"
  }, showError ? {
    error: 'Number needs to be greater than 0'
  } : {}));
};
var WithExtraInfoAndError = exports.WithExtraInfoAndError = {
  render: function render() {
    return _react.default.createElement(WithExtraInfoAndErrorExample, null);
  }
};
var WithNoSteppers = exports.WithNoSteppers = function WithNoSteppers() {
  return _react.default.createElement(_.Input.FormattedNumber, {
    id: "formatted-number-id",
    label: "Label",
    noSteppers: true
  });
};
WithNoSteppers.story = {
  name: 'With no steppers'
};
var WithRightAddon = exports.WithRightAddon = function WithRightAddon() {
  return _react.default.createElement(_.Input.FormattedNumber, {
    id: "formatted-number-id",
    label: "Label",
    rightAddon: "SEK"
  });
};
WithRightAddon.story = {
  name: 'With right addon'
};
var WithBothAddons = exports.WithBothAddons = function WithBothAddons() {
  return _react.default.createElement(_.Input.FormattedNumber, {
    id: "formatted-number-id",
    label: "Label",
    leftAddon: _react.default.createElement(_.OldIcon.Bolt, {
      size: 4
    }),
    rightAddon: "SEK"
  });
};
WithBothAddons.story = {
  name: 'With both addons'
};
var WithHiddenLabel = exports.WithHiddenLabel = function WithHiddenLabel() {
  return _react.default.createElement(_.Input.FormattedNumber, {
    id: "formatted-number-id",
    label: "Label",
    hideLabel: true
  });
};
WithHiddenLabel.story = {
  name: 'With hidden label'
};
var WithSizeSmall = exports.WithSizeSmall = function WithSizeSmall() {
  return _react.default.createElement(_Display.Display, {
    title: "Size = \"s\"",
    items: [{
      component: _react.default.createElement(_.Input.FormattedNumber, {
        id: "formatted-number-id",
        label: "Label",
        size: "s"
      }),
      title: 'Default'
    }, {
      component: _react.default.createElement(_.Input.FormattedNumber, {
        id: "formatted-number-id",
        label: "Label",
        size: "s",
        noSteppers: true
      }),
      title: 'No steppers'
    }, {
      component: _react.default.createElement(_.Input.FormattedNumber, {
        id: "formatted-number-id",
        label: "Label",
        size: "s",
        error: "Some error text that will wrap itself over couple of lines"
      }),
      title: 'Error'
    }]
  });
};
WithSizeSmall.story = {
  name: 'With size small'
};
var WithLabelTooltip = exports.WithLabelTooltip = function WithLabelTooltip() {
  return _react.default.createElement(_.Input.FormattedNumber, {
    id: "formatted-number-id",
    label: "Label",
    labelTooltip: "Tooltip content",
    onChange: (0, _addonActions.action)('onChange')
  });
};
WithLabelTooltip.story = {
  name: 'With label tooltip'
};
var WithLabelTooltipPositionTop = exports.WithLabelTooltipPositionTop = function WithLabelTooltipPositionTop() {
  return _react.default.createElement(_react.default.Fragment, null, _react.default.createElement("br", null), _react.default.createElement("br", null), _react.default.createElement(_.Input.FormattedNumber, {
    id: "formatted-number-id",
    label: "Label",
    labelTooltip: "Tooltip content",
    labelTooltipPosition: "top",
    onChange: (0, _addonActions.action)('onChange')
  }));
};
WithLabelTooltipPositionTop.story = {
  name: 'With label tooltip (position top)'
};
var WithPlaceholder = exports.WithPlaceholder = function WithPlaceholder() {
  return _react.default.createElement(_Display.Display, {
    title: "Placeholders",
    items: [{
      title: 'Default',
      component: _react.default.createElement(_.Input.FormattedNumber, {
        id: "formatted-number-id",
        label: "Label",
        placeholder: "A placeholder",
        noSteppers: true
      })
    }, {
      title: 'With right addon',
      component: _react.default.createElement(_.Input.FormattedNumber, {
        id: "formatted-number-id",
        label: "Label",
        placeholder: "A placeholder",
        rightAddon: "EUR"
      })
    }, {
      title: 'With left addon',
      component: _react.default.createElement(_.Input.FormattedNumber, {
        id: "formatted-number-id",
        label: "Label",
        placeholder: "A placeholder",
        leftAddon: _react.default.createElement(_.OldIcon.Bolt, {
          size: 4
        })
      })
    }, {
      title: 'With steppers (placeholder removed)',
      component: _react.default.createElement(_.Input.FormattedNumber, {
        id: "formatted-number-id",
        label: "Label",
        placeholder: "A placeholder"
      })
    }]
  });
};
WithPlaceholder.story = {
  name: 'With placeholder'
};
var QuietNumber = exports.QuietNumber = function QuietNumber() {
  return _react.default.createElement(_Display.Display, {
    title: "Variant = \"quiet\"",
    items: [{
      component: _react.default.createElement(_.Input.FormattedNumber, {
        id: "formatted-number-id",
        label: "Label",
        onChange: (0, _addonActions.action)('onChange'),
        variant: "quiet",
        placeholder: "0"
      }),
      title: 'Default'
    }, {
      component: _react.default.createElement(_.Input.FormattedNumber, {
        id: "formatted-number-id",
        label: "Label",
        onChange: (0, _addonActions.action)('onChange'),
        variant: "quiet",
        placeholder: "0",
        value: 500,
        rightAddon: "SEK"
      }),
      title: 'Filled'
    }, {
      component: _react.default.createElement(_.Input.FormattedNumber, {
        id: "formatted-number-id",
        label: "Label",
        onChange: (0, _addonActions.action)('onChange'),
        variant: "quiet",
        noSteppers: true,
        width: "100%",
        placeholder: "0"
      }),
      title: 'Full width'
    }, {
      component: _react.default.createElement(_.Input.FormattedNumber, {
        id: "formatted-number-id",
        label: "Label",
        onChange: (0, _addonActions.action)('onChange'),
        variant: "quiet",
        noSteppers: true,
        disabled: true,
        placeholder: "0"
      }),
      title: 'Disabled'
    }, {
      component: _react.default.createElement(_.Input.FormattedNumber, {
        id: "formatted-number-id",
        label: "Label",
        onChange: (0, _addonActions.action)('onChange'),
        variant: "quiet",
        noSteppers: true,
        error: "Some error text that will wrap itself over couple of lines",
        placeholder: "0"
      }),
      title: 'Error'
    }, {
      component: _react.default.createElement(_.Input.FormattedNumber, {
        id: "formatted-number-id",
        label: "Label",
        onChange: (0, _addonActions.action)('onChange'),
        variant: "quiet",
        noSteppers: true,
        placeholder: "0",
        success: true
      }),
      title: 'Success'
    }, {
      component: _react.default.createElement(_.Input.FormattedNumber, {
        id: "formatted-number-id",
        label: "Label",
        onChange: (0, _addonActions.action)('onChange'),
        variant: "quiet",
        noSteppers: true,
        rightAddon: "%"
      }),
      title: 'Right addon'
    }, {
      component: _react.default.createElement(_.Input.FormattedNumber, {
        id: "formatted-number-id",
        label: "Label",
        onChange: (0, _addonActions.action)('onChange'),
        variant: "quiet",
        noSteppers: true,
        leftAddon: _react.default.createElement(_.OldIcon.Plus, {
          color: function color(t) {
            return t.color.cta;
          },
          size: 4
        })
      }),
      title: 'Left addon'
    }, {
      component: _react.default.createElement(_.Input.FormattedNumber, {
        id: "formatted-number-id",
        label: "Label",
        onChange: (0, _addonActions.action)('onChange'),
        variant: "quiet",
        noSteppers: true,
        rightAddon: "%",
        leftAddon: _react.default.createElement(_.OldIcon.Plus, {
          color: function color(t) {
            return t.color.cta;
          },
          size: 4
        })
      }),
      title: 'Both addon'
    }]
  });
};
QuietNumber.story = {
  name: 'Quiet'
};
var OnAColouredBackground = exports.OnAColouredBackground = function OnAColouredBackground() {
  return _react.default.createElement(_.Box, {
    p: 5,
    backgroundColor: function backgroundColor(t) {
      return t.color.disabledBackground;
    }
  }, _react.default.createElement(_.Input.FormattedNumber, {
    id: "unique-id-for-coloured-background",
    label: "On a coloured background"
  }));
};
OnAColouredBackground.story = {
  name: 'On a coloured background'
};
var WithLabelTooltipInsideModalExample = function WithLabelTooltipInsideModalExample() {
  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.FormattedNumber, {
    id: "unique-id",
    label: "Label",
    placeholder: "Placeholder",
    labelTooltip: "Tooltip content",
    labelTooltipInModal: true
  }))));
};
var WithLabelTooltipInsideModal = exports.WithLabelTooltipInsideModal = {
  render: function render() {
    return _react.default.createElement(WithLabelTooltipInsideModalExample, null);
  }
};