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