@veracity/vui 1.2.1 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"usePopover.d.ts","sourceRoot":"","sources":["../../../src/popover/usePopover.ts"],"names":[],"mappings":";AACA,OAAc,EAAE,QAAQ,EAAE,KAAK,IAAI,UAAU,EAAE,MAAM,UAAU,CAAA;AAI/D,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAEpD;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,KAAK,GAAE,eAAoB;;;;;;;;;EA2G7D;AAED,oBAAY,cAAc,GAAG,UAAU,CAAC,OAAO,UAAU,CAAC,CAAA"}
1
+ {"version":3,"file":"usePopover.d.ts","sourceRoot":"","sources":["../../../src/popover/usePopover.ts"],"names":[],"mappings":";AACA,OAAc,EAAE,QAAQ,EAAE,KAAK,IAAI,UAAU,EAAE,MAAM,UAAU,CAAA;AAI/D,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAEpD;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,KAAK,GAAE,eAAoB;;;;;;;;;EA+G7D;AAED,oBAAY,cAAc,GAAG,UAAU,CAAC,OAAO,UAAU,CAAC,CAAA"}
@@ -24,9 +24,7 @@ const consts_1 = require("./consts");
24
24
  * Exposes functions used for ref callbacks on consuming components, programatic open/close methods and properties.
25
25
  */
26
26
  function usePopover(props = {}) {
27
- const { closeOnBlur = true, closeOnEsc = true, defaultIsOpen = false,
28
- // disablePortal,
29
- isOpen: isOpenProp, matchWidth, offset, onClose: onCloseProp, onOpen: onOpenProp, options, placement = 'bottom-start', trigger = 'click' } = props;
27
+ const { closeOnBlur = true, closeOnEsc = true, defaultIsOpen = false, flip = true, isOpen: isOpenProp, matchWidth, offset, onClose: onCloseProp, onOpen: onOpenProp, options, placement = 'bottom-start', trigger = 'click' } = props;
30
28
  const [isOpen, setIsOpen] = (0, react_1.useState)(isOpenProp !== null && isOpenProp !== void 0 ? isOpenProp : defaultIsOpen);
31
29
  const [instance, setInstance] = (0, react_1.useState)(null);
32
30
  const [reference, setReference] = (0, react_1.useState)(null);
@@ -49,7 +47,14 @@ function usePopover(props = {}) {
49
47
  setIsOpen(true);
50
48
  onOpen(instance);
51
49
  onShow === null || onShow === void 0 ? void 0 : onShow(instance);
52
- }, placement, plugins: [...(!isControlled && closeOnEsc ? [consts_1.closeOnEscPlugin] : []), ...plugins], popperOptions: Object.assign(Object.assign({}, popperOptions), { modifiers: [Object.assign(Object.assign({}, consts_1.matchWidthModifier), { enabled: !!matchWidth }), ...((_b = popperOptions.modifiers) !== null && _b !== void 0 ? _b : [])] }), showOnCreate: isOpenProp !== null && isOpenProp !== void 0 ? isOpenProp : defaultIsOpen, trigger: !isControlled ? trigger : 'manual' }, otherOptions);
50
+ }, placement, plugins: [...(!isControlled && closeOnEsc ? [consts_1.closeOnEscPlugin] : []), ...plugins], popperOptions: Object.assign(Object.assign({}, popperOptions), { modifiers: [
51
+ {
52
+ name: 'flip',
53
+ enabled: flip
54
+ },
55
+ Object.assign(Object.assign({}, consts_1.matchWidthModifier), { enabled: !!matchWidth }),
56
+ ...((_b = popperOptions.modifiers) !== null && _b !== void 0 ? _b : [])
57
+ ] }), showOnCreate: isOpenProp !== null && isOpenProp !== void 0 ? isOpenProp : defaultIsOpen, trigger: !isControlled ? trigger : 'manual' }, otherOptions);
53
58
  }, [closeOnBlur, closeOnEsc, offset, options, placement, trigger]);
54
59
  // Create a new Tippy instance
55
60
  (0, react_1.useEffect)(() => {
@@ -63,12 +68,10 @@ function usePopover(props = {}) {
63
68
  // Handle showing/hiding popup in controlled mode
64
69
  (0, react_1.useEffect)(() => {
65
70
  if (isControlled) {
66
- if (isOpenProp) {
71
+ if (isOpenProp)
67
72
  instance === null || instance === void 0 ? void 0 : instance.show();
68
- }
69
- else {
73
+ else
70
74
  instance === null || instance === void 0 ? void 0 : instance.hide();
71
- }
72
75
  }
73
76
  }, [isOpenProp]);
74
77
  return {
@@ -8,6 +8,8 @@ export declare type UsePopoverProps = {
8
8
  closeOnEsc?: boolean;
9
9
  /** Content is opened on first render. Uncontrolled mode. */
10
10
  defaultIsOpen?: boolean;
11
+ /** Content placement could be changed to the opposite depending on available space. */
12
+ flip?: boolean;
11
13
  /** Content is opened/closed by the consumer. Controlled mode. */
12
14
  isOpen?: boolean;
13
15
  /** Sets the content element width to be the same as trigger element. */
@@ -1 +1 @@
1
- {"version":3,"file":"usePopover.types.d.ts","sourceRoot":"","sources":["../../../src/popover/usePopover.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,IAAI,UAAU,EAAE,MAAM,UAAU,CAAA;AAEnE,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAEpC,oBAAY,cAAc,GAAG,OAAO,GAAG,OAAO,GAAG,SAAS,GAAG,QAAQ,GAAG,YAAY,CAAA;AAEpF,oBAAY,eAAe,GAAG;IAC5B,kFAAkF;IAClF,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,2DAA2D;IAC3D,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,4DAA4D;IAC5D,aAAa,CAAC,EAAE,OAAO,CAAA;IAEvB,iEAAiE;IACjE,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,wEAAwE;IACxE,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,oDAAoD;IACpD,MAAM,CAAC,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAA;IAC7B,4CAA4C;IAC5C,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,UAAU,CAAC,KAAK,IAAI,CAAA;IAClD,2CAA2C;IAC3C,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,UAAU,CAAC,KAAK,IAAI,CAAA;IACjD,mCAAmC;IACnC,OAAO,CAAC,EA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AAE,cAAc,GAAG,SAAS,CAAA;CACrC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"tooltip.d.ts","sourceRoot":"","sources":["../../../src/tooltip/tooltip.tsx"],"names":[],"mappings":"AAOA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAE9C;;;;;KAKK;AACL,eAAO,MAAM,OAAO,UAAW,YAAY,gBA8C1C,CAAA;AAED,eAAe,OAAO,CAAA"}
1
+ {"version":3,"file":"tooltip.d.ts","sourceRoot":"","sources":["../../../src/tooltip/tooltip.tsx"],"names":[],"mappings":"AAOA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAG9C;;;;;KAKK;AACL,eAAO,MAAM,OAAO,UAAW,YAAY,gBA0D1C,CAAA;AAED,eAAe,OAAO,CAAA"}
@@ -4,12 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Tooltip = void 0;
7
- const react_1 = __importDefault(require("react"));
7
+ const react_1 = __importDefault(require("@tippyjs/react"));
8
+ const react_2 = __importDefault(require("react"));
8
9
  const box_1 = __importDefault(require("../box"));
9
10
  const core_1 = require("../core");
10
11
  const link_1 = require("../link");
11
- const popover_1 = __importDefault(require("../popover"));
12
12
  const tooltip_setup_1 = require("./tooltip.setup");
13
+ const tooltipContent_1 = require("./tooltipContent");
13
14
  /**
14
15
  * A simple text popup hint.
15
16
  *
@@ -19,15 +20,20 @@ const tooltip_setup_1 = require("./tooltip.setup");
19
20
  const Tooltip = (props) => {
20
21
  const { children, fontSize = '16px', linkText, linkProps, maxWidth = '400px', text = 'demo', placement = 'top' } = props;
21
22
  const isDesktop = (0, core_1.useUp)('md');
22
- return (react_1.default.createElement(popover_1.default, { placement: placement, trigger: "mouseenter" },
23
- react_1.default.createElement(popover_1.default.Trigger, { as: box_1.default, display: "inline-flex" }, children),
24
- react_1.default.createElement(popover_1.default.Content, { bg: tooltip_setup_1.color, color: "white", fontSize: fontSize, m: 1, maxW: maxWidth, p: 1, pl: 2, pr: 2 },
25
- isDesktop && (react_1.default.createElement(box_1.default, { bg: tooltip_setup_1.color, bottom: tooltip_setup_1.pointerPlacement[placement].bottom, h: `${tooltip_setup_1.pointerSize}px`, left: tooltip_setup_1.pointerPlacement[placement].left, position: "absolute", right: tooltip_setup_1.pointerPlacement[placement].right, top: tooltip_setup_1.pointerPlacement[placement].top, transform: `translate(${tooltip_setup_1.pointerPlacement[placement].translate}) rotate(45deg)`, w: `${tooltip_setup_1.pointerSize}px` })),
26
- react_1.default.createElement(core_1.v.div, null,
23
+ return (react_2.default.createElement(react_1.default, { content: react_2.default.createElement(tooltipContent_1.TooltipContent, { fontSize: fontSize, maxWidth: maxWidth },
24
+ isDesktop && (react_2.default.createElement(box_1.default, { bg: tooltip_setup_1.color, bottom: tooltip_setup_1.pointerPlacement[placement].bottom, h: `${tooltip_setup_1.pointerSize}px`, left: tooltip_setup_1.pointerPlacement[placement].left, position: "absolute", right: tooltip_setup_1.pointerPlacement[placement].right, top: tooltip_setup_1.pointerPlacement[placement].top, transform: `translate(${tooltip_setup_1.pointerPlacement[placement].translate}) rotate(45deg)`, w: `${tooltip_setup_1.pointerSize}px` })),
25
+ react_2.default.createElement(core_1.v.div, null,
27
26
  text,
28
- !!linkText && (react_1.default.createElement(react_1.default.Fragment, null,
27
+ !!linkText && (react_2.default.createElement(react_2.default.Fragment, null,
29
28
  "\u00A0",
30
- react_1.default.createElement(link_1.Link, Object.assign({ variant: "light" }, linkProps), linkText)))))));
29
+ react_2.default.createElement(link_1.Link, Object.assign({ variant: "light" }, linkProps), linkText))))), interactive: true, offset: [0, 2], placement: placement, popperOptions: {
30
+ modifiers: [
31
+ {
32
+ name: 'flip',
33
+ enabled: false
34
+ }
35
+ ]
36
+ } }, children));
31
37
  };
32
38
  exports.Tooltip = Tooltip;
33
39
  exports.default = exports.Tooltip;
@@ -0,0 +1,3 @@
1
+ import { TooltipProps } from './tooltip.types';
2
+ export declare const TooltipContent: (props: TooltipProps) => JSX.Element;
3
+ //# sourceMappingURL=tooltipContent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tooltipContent.d.ts","sourceRoot":"","sources":["../../../src/tooltip/tooltipContent.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAE9C,eAAO,MAAM,cAAc,UAAW,YAAY,gBAoBjD,CAAA"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.TooltipContent = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ const box_1 = __importDefault(require("../box"));
9
+ const tooltip_setup_1 = require("./tooltip.setup");
10
+ const TooltipContent = (props) => {
11
+ const { children, fontSize = '16px', maxWidth = '400px' } = props;
12
+ return (react_1.default.createElement(box_1.default, { bg: tooltip_setup_1.color, borderRadius: "md", boxShadow: "2", className: "vui-tooltip-content", color: "white", fontSize: fontSize, m: 1, maxW: maxWidth, overflowY: "auto", p: 1, pl: 2, pr: 2 }, children));
13
+ };
14
+ exports.TooltipContent = TooltipContent;
@@ -1 +1 @@
1
- {"version":3,"file":"usePopover.d.ts","sourceRoot":"","sources":["../../../src/popover/usePopover.ts"],"names":[],"mappings":";AACA,OAAc,EAAE,QAAQ,EAAE,KAAK,IAAI,UAAU,EAAE,MAAM,UAAU,CAAA;AAI/D,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAEpD;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,KAAK,GAAE,eAAoB;;;;;;;;;EA2G7D;AAED,oBAAY,cAAc,GAAG,UAAU,CAAC,OAAO,UAAU,CAAC,CAAA"}
1
+ {"version":3,"file":"usePopover.d.ts","sourceRoot":"","sources":["../../../src/popover/usePopover.ts"],"names":[],"mappings":";AACA,OAAc,EAAE,QAAQ,EAAE,KAAK,IAAI,UAAU,EAAE,MAAM,UAAU,CAAA;AAI/D,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAEpD;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,KAAK,GAAE,eAAoB;;;;;;;;;EA+G7D;AAED,oBAAY,cAAc,GAAG,UAAU,CAAC,OAAO,UAAU,CAAC,CAAA"}
@@ -8,9 +8,7 @@ import { closeOnEscPlugin, matchWidthModifier } from './consts';
8
8
  * Exposes functions used for ref callbacks on consuming components, programatic open/close methods and properties.
9
9
  */
10
10
  export default function usePopover(props = {}) {
11
- const { closeOnBlur = true, closeOnEsc = true, defaultIsOpen = false,
12
- // disablePortal,
13
- isOpen: isOpenProp, matchWidth, offset, onClose: onCloseProp, onOpen: onOpenProp, options, placement = 'bottom-start', trigger = 'click' } = props;
11
+ const { closeOnBlur = true, closeOnEsc = true, defaultIsOpen = false, flip = true, isOpen: isOpenProp, matchWidth, offset, onClose: onCloseProp, onOpen: onOpenProp, options, placement = 'bottom-start', trigger = 'click' } = props;
14
12
  const [isOpen, setIsOpen] = useState(isOpenProp ?? defaultIsOpen);
15
13
  const [instance, setInstance] = useState(null);
16
14
  const [reference, setReference] = useState(null);
@@ -46,7 +44,14 @@ export default function usePopover(props = {}) {
46
44
  plugins: [...(!isControlled && closeOnEsc ? [closeOnEscPlugin] : []), ...plugins],
47
45
  popperOptions: {
48
46
  ...popperOptions,
49
- modifiers: [{ ...matchWidthModifier, enabled: !!matchWidth }, ...(popperOptions.modifiers ?? [])]
47
+ modifiers: [
48
+ {
49
+ name: 'flip',
50
+ enabled: flip
51
+ },
52
+ { ...matchWidthModifier, enabled: !!matchWidth },
53
+ ...(popperOptions.modifiers ?? [])
54
+ ]
50
55
  },
51
56
  showOnCreate: isOpenProp ?? defaultIsOpen,
52
57
  trigger: !isControlled ? trigger : 'manual',
@@ -68,12 +73,10 @@ export default function usePopover(props = {}) {
68
73
  // Handle showing/hiding popup in controlled mode
69
74
  useEffect(() => {
70
75
  if (isControlled) {
71
- if (isOpenProp) {
76
+ if (isOpenProp)
72
77
  instance?.show();
73
- }
74
- else {
78
+ else
75
79
  instance?.hide();
76
- }
77
80
  }
78
81
  }, [isOpenProp]);
79
82
  return {
@@ -8,6 +8,8 @@ export declare type UsePopoverProps = {
8
8
  closeOnEsc?: boolean;
9
9
  /** Content is opened on first render. Uncontrolled mode. */
10
10
  defaultIsOpen?: boolean;
11
+ /** Content placement could be changed to the opposite depending on available space. */
12
+ flip?: boolean;
11
13
  /** Content is opened/closed by the consumer. Controlled mode. */
12
14
  isOpen?: boolean;
13
15
  /** Sets the content element width to be the same as trigger element. */
@@ -1 +1 @@
1
- {"version":3,"file":"usePopover.types.d.ts","sourceRoot":"","sources":["../../../src/popover/usePopover.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,IAAI,UAAU,EAAE,MAAM,UAAU,CAAA;AAEnE,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAEpC,oBAAY,cAAc,GAAG,OAAO,GAAG,OAAO,GAAG,SAAS,GAAG,QAAQ,GAAG,YAAY,CAAA;AAEpF,oBAAY,eAAe,GAAG;IAC5B,kFAAkF;IAClF,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,2DAA2D;IAC3D,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,4DAA4D;IAC5D,aAAa,CAAC,EAAE,OAAO,CAAA;IAEvB,iEAAiE;IACjE,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,wEAAwE;IACxE,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,oDAAoD;IACpD,MAAM,CAAC,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAA;IAC7B,4CAA4C;IAC5C,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,UAAU,CAAC,KAAK,IAAI,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C;IACnC,OAAO,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,CAAA;IAC7B,gFAAgF;IAChF,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,6DAA6D;IAC7D,OAAO,CAAC,EAAE,cAAc,GAAG,SAAS,CAAA;CACrC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"tooltip.d.ts","sourceRoot":"","sources":["../../../src/tooltip/tooltip.tsx"],"names":[],"mappings":"AAOA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAE9C;;;;;KAKK;AACL,eAAO,MAAM,OAAO,UAAW,YAAY,gBA8C1C,CAAA;AAED,eAAe,OAAO,CAAA"}
1
+ {"version":3,"file":"tooltip.d.ts","sourceRoot":"","sources":["../../../src/tooltip/tooltip.tsx"],"names":[],"mappings":"AAOA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAG9C;;;;;KAKK;AACL,eAAO,MAAM,OAAO,UAAW,YAAY,gBA0D1C,CAAA;AAED,eAAe,OAAO,CAAA"}
@@ -1,9 +1,10 @@
1
+ import Tippy from '@tippyjs/react';
1
2
  import React from 'react';
2
3
  import Box from '../box';
3
4
  import { useUp, v } from '../core';
4
5
  import { Link } from '../link';
5
- import Popover from '../popover';
6
6
  import { color, pointerPlacement, pointerSize } from './tooltip.setup';
7
+ import { TooltipContent } from './tooltipContent';
7
8
  /**
8
9
  * A simple text popup hint.
9
10
  *
@@ -13,14 +14,19 @@ import { color, pointerPlacement, pointerSize } from './tooltip.setup';
13
14
  export const Tooltip = (props) => {
14
15
  const { children, fontSize = '16px', linkText, linkProps, maxWidth = '400px', text = 'demo', placement = 'top' } = props;
15
16
  const isDesktop = useUp('md');
16
- return (React.createElement(Popover, { placement: placement, trigger: "mouseenter" },
17
- React.createElement(Popover.Trigger, { as: Box, display: "inline-flex" }, children),
18
- React.createElement(Popover.Content, { bg: color, color: "white", fontSize: fontSize, m: 1, maxW: maxWidth, p: 1, pl: 2, pr: 2 },
17
+ return (React.createElement(Tippy, { content: React.createElement(TooltipContent, { fontSize: fontSize, maxWidth: maxWidth },
19
18
  isDesktop && (React.createElement(Box, { bg: color, bottom: pointerPlacement[placement].bottom, h: `${pointerSize}px`, left: pointerPlacement[placement].left, position: "absolute", right: pointerPlacement[placement].right, top: pointerPlacement[placement].top, transform: `translate(${pointerPlacement[placement].translate}) rotate(45deg)`, w: `${pointerSize}px` })),
20
19
  React.createElement(v.div, null,
21
20
  text,
22
21
  !!linkText && (React.createElement(React.Fragment, null,
23
22
  "\u00A0",
24
- React.createElement(Link, { variant: "light", ...linkProps }, linkText)))))));
23
+ React.createElement(Link, { variant: "light", ...linkProps }, linkText))))), interactive: true, offset: [0, 2], placement: placement, popperOptions: {
24
+ modifiers: [
25
+ {
26
+ name: 'flip',
27
+ enabled: false
28
+ }
29
+ ]
30
+ } }, children));
25
31
  };
26
32
  export default Tooltip;
@@ -0,0 +1,3 @@
1
+ import { TooltipProps } from './tooltip.types';
2
+ export declare const TooltipContent: (props: TooltipProps) => JSX.Element;
3
+ //# sourceMappingURL=tooltipContent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tooltipContent.d.ts","sourceRoot":"","sources":["../../../src/tooltip/tooltipContent.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAE9C,eAAO,MAAM,cAAc,UAAW,YAAY,gBAoBjD,CAAA"}
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ import Box from '../box';
3
+ import { color } from './tooltip.setup';
4
+ export const TooltipContent = (props) => {
5
+ const { children, fontSize = '16px', maxWidth = '400px' } = props;
6
+ return (React.createElement(Box, { bg: color, borderRadius: "md", boxShadow: "2", className: "vui-tooltip-content", color: "white", fontSize: fontSize, m: 1, maxW: maxWidth, overflowY: "auto", p: 1, pl: 2, pr: 2 }, children));
7
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veracity/vui",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "Veracity UI is a React component library crafted for use within Veracity applications and pages. Based on Styled Components and @xstyled.",
5
5
  "module": "./dist/esm/index.js",
6
6
  "main": "./dist/cjs/index.js",
@@ -20,6 +20,7 @@
20
20
  "url": "https://dnvgl-one.visualstudio.com/DefaultCollection/Veracity/_git/WEB-VUI"
21
21
  },
22
22
  "dependencies": {
23
+ "@tippyjs/react": "4.2.6",
23
24
  "@types/styled-components": "5.1.24",
24
25
  "@xstyled/core": "2.5.0",
25
26
  "@xstyled/styled-components": "2.5.0",
@@ -15,7 +15,7 @@ export default function usePopover(props: UsePopoverProps = {}) {
15
15
  closeOnBlur = true,
16
16
  closeOnEsc = true,
17
17
  defaultIsOpen = false,
18
- // disablePortal,
18
+ flip = true,
19
19
  isOpen: isOpenProp,
20
20
  matchWidth,
21
21
  offset,
@@ -73,7 +73,14 @@ export default function usePopover(props: UsePopoverProps = {}) {
73
73
  plugins: [...(!isControlled && closeOnEsc ? [closeOnEscPlugin] : []), ...plugins],
74
74
  popperOptions: {
75
75
  ...popperOptions,
76
- modifiers: [{ ...matchWidthModifier, enabled: !!matchWidth }, ...(popperOptions.modifiers ?? [])]
76
+ modifiers: [
77
+ {
78
+ name: 'flip',
79
+ enabled: flip
80
+ },
81
+ { ...matchWidthModifier, enabled: !!matchWidth },
82
+ ...(popperOptions.modifiers ?? [])
83
+ ]
77
84
  },
78
85
  showOnCreate: isOpenProp ?? defaultIsOpen,
79
86
  trigger: !isControlled ? trigger : 'manual',
@@ -99,11 +106,8 @@ export default function usePopover(props: UsePopoverProps = {}) {
99
106
  // Handle showing/hiding popup in controlled mode
100
107
  useEffect(() => {
101
108
  if (isControlled) {
102
- if (isOpenProp) {
103
- instance?.show()
104
- } else {
105
- instance?.hide()
106
- }
109
+ if (isOpenProp) instance?.show()
110
+ else instance?.hide()
107
111
  }
108
112
  }, [isOpenProp])
109
113
 
@@ -11,7 +11,8 @@ export type UsePopoverProps = {
11
11
  closeOnEsc?: boolean
12
12
  /** Content is opened on first render. Uncontrolled mode. */
13
13
  defaultIsOpen?: boolean
14
- // disablePortal?: boolean
14
+ /** Content placement could be changed to the opposite depending on available space. */
15
+ flip?: boolean
15
16
  /** Content is opened/closed by the consumer. Controlled mode. */
16
17
  isOpen?: boolean
17
18
  /** Sets the content element width to be the same as trigger element. */
@@ -1,11 +1,12 @@
1
- import React from 'react'
1
+ import Tippy from '@tippyjs/react'
2
+ import React, { JSXElementConstructor, ReactElement } from 'react'
2
3
 
3
4
  import Box from '../box'
4
5
  import { useUp, v } from '../core'
5
6
  import { Link } from '../link'
6
- import Popover from '../popover'
7
7
  import { color, pointerPlacement, pointerSize } from './tooltip.setup'
8
8
  import { TooltipProps } from './tooltip.types'
9
+ import { TooltipContent } from './tooltipContent'
9
10
 
10
11
  /**
11
12
  * A simple text popup hint.
@@ -27,37 +28,49 @@ export const Tooltip = (props: TooltipProps) => {
27
28
  const isDesktop = useUp('md')
28
29
 
29
30
  return (
30
- <Popover placement={placement} trigger="mouseenter">
31
- <Popover.Trigger as={Box} display="inline-flex">
32
- {children}
33
- </Popover.Trigger>
34
- <Popover.Content bg={color} color="white" fontSize={fontSize} m={1} maxW={maxWidth} p={1} pl={2} pr={2}>
35
- {isDesktop && (
36
- <Box
37
- bg={color}
38
- bottom={pointerPlacement[placement].bottom}
39
- h={`${pointerSize}px`}
40
- left={pointerPlacement[placement].left}
41
- position="absolute"
42
- right={pointerPlacement[placement].right}
43
- top={pointerPlacement[placement].top}
44
- transform={`translate(${pointerPlacement[placement].translate}) rotate(45deg)`}
45
- w={`${pointerSize}px`}
46
- />
47
- )}
48
- <v.div>
49
- {text}
50
- {!!linkText && (
51
- <>
52
- &nbsp;
53
- <Link variant="light" {...linkProps}>
54
- {linkText}
55
- </Link>
56
- </>
31
+ <Tippy
32
+ content={
33
+ <TooltipContent fontSize={fontSize} maxWidth={maxWidth}>
34
+ {isDesktop && (
35
+ <Box
36
+ bg={color}
37
+ bottom={pointerPlacement[placement].bottom}
38
+ h={`${pointerSize}px`}
39
+ left={pointerPlacement[placement].left}
40
+ position="absolute"
41
+ right={pointerPlacement[placement].right}
42
+ top={pointerPlacement[placement].top}
43
+ transform={`translate(${pointerPlacement[placement].translate}) rotate(45deg)`}
44
+ w={`${pointerSize}px`}
45
+ />
57
46
  )}
58
- </v.div>
59
- </Popover.Content>
60
- </Popover>
47
+ <v.div>
48
+ {text}
49
+ {!!linkText && (
50
+ <>
51
+ &nbsp;
52
+ <Link variant="light" {...linkProps}>
53
+ {linkText}
54
+ </Link>
55
+ </>
56
+ )}
57
+ </v.div>
58
+ </TooltipContent>
59
+ }
60
+ interactive
61
+ offset={[0, 2]}
62
+ placement={placement}
63
+ popperOptions={{
64
+ modifiers: [
65
+ {
66
+ name: 'flip',
67
+ enabled: false
68
+ }
69
+ ]
70
+ }}
71
+ >
72
+ {children as ReactElement<any, string | JSXElementConstructor<any>> | undefined}
73
+ </Tippy>
61
74
  )
62
75
  }
63
76
 
@@ -0,0 +1,27 @@
1
+ import React from 'react'
2
+
3
+ import Box from '../box'
4
+ import { color } from './tooltip.setup'
5
+ import { TooltipProps } from './tooltip.types'
6
+
7
+ export const TooltipContent = (props: TooltipProps) => {
8
+ const { children, fontSize = '16px', maxWidth = '400px' } = props
9
+ return (
10
+ <Box
11
+ bg={color}
12
+ borderRadius="md"
13
+ boxShadow="2"
14
+ className="vui-tooltip-content"
15
+ color="white"
16
+ fontSize={fontSize}
17
+ m={1}
18
+ maxW={maxWidth}
19
+ overflowY="auto"
20
+ p={1}
21
+ pl={2}
22
+ pr={2}
23
+ >
24
+ {children}
25
+ </Box>
26
+ )
27
+ }