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 styled from 'styled-components';
import { Box, Drawer, Flexbox, Modal, Button as UIButton, Icon, Typography, PopOver } from '../..';
import Tooltip from '.';
import { Display } from '../../common/Display';
export default {
  title: 'Molecules / Tooltip',
  parameters: {
    component: Tooltip
  }
};
var label = 'Information in a Tooltip should not be vital for the user to complete a task';
var Button = styled.button.withConfig({
  displayName: "Tooltipstories__Button",
  componentId: "sc-j9k610-0"
})(["display:block;"]);
var StyledDiv = styled.div.withConfig({
  displayName: "Tooltipstories__StyledDiv",
  componentId: "sc-j9k610-1"
})(["margin:20px 0 20px 20px;"]);
export var DefaultStory = {
  render: function render() {
    return React.createElement(React.Fragment, null, React.createElement(StyledDiv, null, "Default delays", React.createElement(Tooltip, {
      label: label,
      position: "top"
    }, React.createElement(Button, {
      type: "button"
    }, "Hover me"))), React.createElement(StyledDiv, null, "Open delay: 2000ms; Close delay: 3000ms", React.createElement(Tooltip, {
      label: label,
      position: "top",
      openDelay: 2000,
      closeDelay: 3000
    }, React.createElement(Button, {
      type: "button"
    }, "Hover me"))), React.createElement(StyledDiv, null, "Open delay: 10ms; Close delay: 10ms", React.createElement(Tooltip, {
      label: label,
      position: "top",
      openDelay: 10,
      closeDelay: 10
    }, React.createElement(Button, {
      type: "button"
    }, "Hover me"))), React.createElement(StyledDiv, null, "Open delay: 0ms; Close delay: 0ms", React.createElement(Tooltip, {
      label: label,
      position: "top",
      openDelay: 0,
      closeDelay: 0
    }, React.createElement(Button, {
      type: "button"
    }, "Hover me"))));
  },
  name: 'Default'
};
export var InvertedColorsStory = {
  render: function render() {
    return React.createElement(React.Fragment, null, React.createElement(StyledDiv, null, "Inverted colors", React.createElement(Tooltip, {
      label: "inverted label",
      position: "top",
      invertedColors: true
    }, React.createElement(Button, {
      type: "button"
    }, "Hover me"))));
  },
  name: 'Inverted colors'
};
export var WithMode = {
  render: function render() {
    return React.createElement(Tooltip, {
      label: label,
      mode: "click"
    }, React.createElement(Button, {
      type: "button"
    }, "Click me"));
  },
  name: 'With On Click Mode'
};
var veryLongLabel = 'Llanfairpwllgwyngyllgogerychwyrndrob';
export var WithVeryLongWord = {
  render: function render() {
    return React.createElement(Tooltip, {
      label: veryLongLabel
    }, React.createElement(Button, {
      type: "button"
    }, "Hover me"));
  }
};
export var WithPosition = {
  render: function render() {
    return React.createElement(Display, {
      items: [{
        component: React.createElement(Tooltip, {
          label: label,
          position: "bottom"
        }, React.createElement(Button, {
          type: "button"
        }, "Hover me")),
        title: 'bottom'
      }, {
        component: React.createElement(Tooltip, {
          label: label,
          position: "left"
        }, React.createElement(Button, {
          type: "button"
        }, "Hover me")),
        title: 'left'
      }, {
        component: React.createElement(Tooltip, {
          label: label,
          position: "top"
        }, React.createElement(Button, {
          type: "button"
        }, "Hover me")),
        title: 'top'
      }, {
        component: React.createElement(Tooltip, {
          label: label,
          position: "right"
        }, React.createElement(Button, {
          type: "button"
        }, "Hover me")),
        title: 'right'
      }, {
        component: React.createElement(Tooltip, {
          label: label,
          position: "right-start"
        }, React.createElement(Button, {
          type: "button"
        }, "Hover me")),
        title: 'right-start'
      }, {
        component: React.createElement(Tooltip, {
          label: label,
          position: "right-end"
        }, React.createElement(Button, {
          type: "button"
        }, "Hover me")),
        title: 'right-end'
      }, {
        component: React.createElement(Tooltip, {
          label: label,
          position: "top-start"
        }, React.createElement(Button, {
          type: "button"
        }, "Hover me")),
        title: 'top-start'
      }, {
        component: React.createElement(Tooltip, {
          label: label,
          position: "top-end"
        }, React.createElement(Button, {
          type: "button"
        }, "Hover me")),
        title: 'top-end'
      }, {
        component: React.createElement(Tooltip, {
          label: label,
          position: "left-start"
        }, React.createElement(Button, {
          type: "button"
        }, "Hover me")),
        title: 'left-start'
      }, {
        component: React.createElement(Tooltip, {
          label: label,
          position: "left-end"
        }, React.createElement(Button, {
          type: "button"
        }, "Hover me")),
        title: 'left-end'
      }, {
        component: React.createElement(Tooltip, {
          label: label,
          position: "bottom-start"
        }, React.createElement(Button, {
          type: "button"
        }, "Hover me")),
        title: 'bottom-start'
      }, {
        component: React.createElement(Tooltip, {
          label: label,
          position: "bottom-end"
        }, React.createElement(Button, {
          type: "button"
        }, "Hover me")),
        title: 'bottom-end'
      }]
    });
  },
  name: 'With position defined'
};
export var ZindexWars = {
  render: function render() {
    var Example = function Example() {
      var _useState = useState(false),
        _useState2 = _slicedToArray(_useState, 2),
        open = _useState2[0],
        setOpen = _useState2[1];
      var openModal = function openModal() {
        setOpen(true);
      };
      var closeModal = function closeModal() {
        setOpen(false);
      };
      return React.createElement(Drawer, null, React.createElement(Box, {
        mb: 4
      }, React.createElement(Tooltip, {
        label: label
      }, React.createElement(Button, null, "Hover me"))), React.createElement(Button, {
        onClick: openModal
      }, "Open modal"), React.createElement(Modal, {
        open: open,
        onClose: closeModal
      }, React.createElement(Tooltip, {
        label: label,
        inModal: true
      }, React.createElement(Button, null, "Hover me"))));
    };
    return React.createElement(Example, null);
  },
  name: 'Integration: With Drawer and Modal'
};
export var CustomMaxWidth = {
  render: function render() {
    return React.createElement(Tooltip, {
      label: label,
      maxWidth: 100
    }, React.createElement(Button, {
      type: "button"
    }, "Hover me"));
  },
  name: 'Custom max-width'
};
export var ControlledOpen = function ControlledOpen() {
  var _useState3 = useState(true),
    _useState4 = _slicedToArray(_useState3, 2),
    isOpen = _useState4[0],
    setOpen = _useState4[1];
  return React.createElement(React.Fragment, null, React.createElement(Button, {
    onClick: function onClick() {
      return setOpen(!isOpen);
    }
  }, "Toogle Tooltip"), React.createElement(Flexbox, {
    container: true
  }, React.createElement(Box, {
    mt: 10
  }, React.createElement(Tooltip, {
    isOpen: isOpen,
    label: "This is a controlled tooltip.",
    position: "right"
  }, React.createElement("div", null, React.createElement(Icon.Edit16, null))))));
};
export var WrapChild = function WrapChild() {
  var _useState5 = useState(true),
    _useState6 = _slicedToArray(_useState5, 1),
    isOpen = _useState6[0];
  return React.createElement(React.Fragment, null, React.createElement(Flexbox, {
    container: true
  }, React.createElement(Box, {
    mt: 20
  }, React.createElement(Tooltip, {
    isOpen: isOpen,
    label: "With the wrapChiild prop, a DOM element of type span wraps the children, this guarantees a element in the DOM to work properly with ref (and thus positioning).",
    position: "right",
    wrapChild: true
  }, React.createElement(Icon.Edit16, null)))), React.createElement(Flexbox, {
    container: true
  }, React.createElement(Box, {
    mt: 40
  }, React.createElement(Tooltip, {
    isOpen: isOpen,
    label: "This tooltip doesn't use the wrapChild prop, but has a children that correctly handles refs",
    position: "right"
  }, React.createElement("div", null, React.createElement(Icon.Edit16, null))))));
};
export var BrokenPositioning = function BrokenPositioning() {
  var _useState7 = useState(true),
    _useState8 = _slicedToArray(_useState7, 1),
    isOpen = _useState8[0];
  return React.createElement(Flexbox, {
    container: true
  }, React.createElement(Box, {
    mt: 40
  }, React.createElement(Tooltip, {
    isOpen: isOpen,
    label: "This tooltip has children which doesn't handle refs correctly. Thus, it's positioning doesn't work properly. See wrapChild for examples of how to fix this.",
    position: "right"
  }, React.createElement(Icon.Edit16, null))));
};
export var WithClickableContent = function WithClickableContent() {
  var _useState9 = useState(false),
    _useState10 = _slicedToArray(_useState9, 2),
    isOpen = _useState10[0],
    setIsOpen = _useState10[1];
  return React.createElement(Flexbox, {
    container: true
  }, React.createElement(Box, {
    mt: 40
  }, React.createElement(Tooltip, {
    isOpen: isOpen,
    label: React.createElement(Button, {
      onClick: function onClick() {
        return alert('You clicked me!');
      }
    }, "Try to click me"),
    position: "right",
    pointerEvents: true,
    wrapChild: true
  }, React.createElement(UIButton, {
    variant: "neutral",
    onClick: function onClick() {
      return setIsOpen(!isOpen);
    }
  }, React.createElement(Icon.Edit16, null)))));
};
export var WithOffset = function WithOffset() {
  return React.createElement(Box, {
    p: 20
  }, React.createElement(Flexbox, {
    container: true,
    gap: 4,
    alignItems: "center"
  }, React.createElement(Typography, {
    type: "primary"
  }, "Hover the pen!"), React.createElement(Tooltip, {
    label: "This tooltip has offset",
    wrapChild: true,
    offset: [-20, 40]
  }, React.createElement(Icon.Edit16, null))));
};
export var WithOffsetAsAFunction = function WithOffsetAsAFunction() {
  return React.createElement(Box, {
    p: 20
  }, React.createElement(Flexbox, {
    container: true,
    gap: 4,
    alignItems: "center"
  }, React.createElement(Typography, {
    type: "primary"
  }, "Hover the pen!"), React.createElement(Tooltip, {
    position: "bottom",
    label: "This tooltip has offset",
    wrapChild: true,
    offset: function offset(_ref) {
      var placement = _ref.placement,
        reference = _ref.reference,
        popper = _ref.popper;
      if (placement === 'bottom') {
        return [0, popper.height * 4];
      }
      return [];
    }
  }, React.createElement(Icon.Edit16, null))));
};
var OverflowBox = styled(Box).withConfig({
  displayName: "Tooltipstories__OverflowBox",
  componentId: "sc-j9k610-2"
})(["border:5px solid red;height:50vh;width:400px;overflow:scroll;"]);
export var CustomBoundary = function CustomBoundary() {
  var _useState11 = useState(),
    _useState12 = _slicedToArray(_useState11, 2),
    boundaryElement = _useState12[0],
    setBoundaryElement = _useState12[1];
  return React.createElement(Flexbox, {
    container: true,
    alignItems: "center",
    justifyContent: "space-around"
  }, React.createElement(OverflowBox, {
    pb: 40,
    pt: 0,
    my: 40,
    ref: setBoundaryElement
  }, React.createElement("div", {
    style: {
      height: '80vh',
      background: 'orange'
    }
  }), React.createElement(Tooltip, {
    label: "This tooltip is positioned bottom but it flips to the top because when there's no portal we have better control over what the container is.",
    position: "bottom",
    pointerEvents: true,
    customBoundary: boundaryElement
  }, React.createElement("span", null, "custom boundary")), React.createElement("div", {
    style: {
      height: '80vh',
      background: 'orange'
    }
  })), React.createElement(OverflowBox, {
    pb: 40,
    pt: 0
  }, React.createElement(Tooltip, {
    label: React.createElement("span", null, "This tooltip is positioned bottom, and as its portal wrapped, it will only reposition when outside the border of the page"),
    position: "bottom",
    pointerEvents: true
  }, React.createElement("span", null, "Default with portal"))));
};
var StyledTooltip = styled(Tooltip).withConfig({
  displayName: "Tooltipstories__StyledTooltip",
  componentId: "sc-j9k610-3"
})(["", "{background:red;}"], PopOver.components.TooltipContent);
export var StyledPopOver = function StyledPopOver() {
  return React.createElement(Box, {
    py: 20
  }, React.createElement(StyledTooltip, {
    label: "label",
    position: "top",
    wrapChild: true
  }, React.createElement(Typography, {
    type: "primary"
  }, "hover me")));
};
export var BottomSheet = function BottomSheet() {
  var _useState13 = useState(false),
    _useState14 = _slicedToArray(_useState13, 2),
    open = _useState14[0],
    setOpen = _useState14[1];
  return React.createElement(Box, {
    py: 20
  }, React.createElement(Tooltip, {
    label: React.createElement(React.Fragment, null, "popover content ", React.createElement(Button, {
      onClick: function onClick() {
        return alert('You clicked me!');
      }
    }, "click")),
    position: "bottom",
    wrapChild: true,
    pointerEvents: true,
    bottomSheetQuery: function bottomSheetQuery(t) {
      return t.media.lessThan(t.breakpoints.sm);
    },
    bottomSheetTitle: "BottomSheet Title",
    isOpen: open,
    onBottomSheetClose: function onBottomSheetClose() {
      return setOpen(false);
    }
  }, React.createElement(UIButton, {
    variant: "neutral",
    onClick: function onClick() {
      return setOpen(!open);
    }
  }, React.createElement(Typography, {
    type: "primary"
  }, "CLICK ME"))));
};