@homebound/beam 2.240.2 → 2.241.1

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.
@@ -196,6 +196,7 @@ function RowImpl(props) {
196
196
  };
197
197
  const cellClassNames = revealOnRowHover ? revealOnRowHoverClass : undefined;
198
198
  const cellOnClick = applyCellHighlight ? () => api.setActiveCellId(cellId) : undefined;
199
+ const tooltip = (0, utils_1.isGridCellContent)(maybeContent) ? maybeContent.tooltip : undefined;
199
200
  const renderFn = ((rowStyle === null || rowStyle === void 0 ? void 0 : rowStyle.renderCell) || (rowStyle === null || rowStyle === void 0 ? void 0 : rowStyle.rowLink)) && wrapAction
200
201
  ? (0, cell_1.rowLinkRenderFn)(as)
201
202
  : isHeader || isTotals || isExpandableHeader
@@ -203,7 +204,7 @@ function RowImpl(props) {
203
204
  : (rowStyle === null || rowStyle === void 0 ? void 0 : rowStyle.onClick) && wrapAction
204
205
  ? (0, cell_1.rowClickRenderFn)(as, api)
205
206
  : (0, cell_1.defaultRenderFn)(as);
206
- return renderFn(columnIndex, cellCss, content, row, rowStyle, cellClassNames, cellOnClick);
207
+ return renderFn(columnIndex, cellCss, content, row, rowStyle, cellClassNames, cellOnClick, tooltip);
207
208
  }) }));
208
209
  }
209
210
  /**
@@ -27,9 +27,11 @@ export type GridCellContent = {
27
27
  css?: Properties;
28
28
  /** Allows cell to reveal content when the user hovers over a row. Content must be wrapped in an element in order to be hidden. IE <div>{value}</div>*/
29
29
  revealOnRowHover?: true;
30
+ /** Tooltip to add to a cell. **Only Works on Headers** */
31
+ tooltip?: ReactNode;
30
32
  };
31
33
  /** Allows rendering a specific cell. */
32
- export type RenderCellFn<R extends Kinded> = (idx: number, css: Properties, content: ReactNode, row: R, rowStyle: RowStyle<R> | undefined, classNames: string | undefined, onClick: VoidFunction | undefined) => ReactNode;
34
+ export type RenderCellFn<R extends Kinded> = (idx: number, css: Properties, content: ReactNode, row: R, rowStyle: RowStyle<R> | undefined, classNames: string | undefined, onClick: VoidFunction | undefined, tooltip: ReactNode | undefined) => ReactNode;
33
35
  /** Renders our default cell element, i.e. if no row links and no custom renderCell are used. */
34
36
  export declare const defaultRenderFn: (as: RenderAs) => RenderCellFn<any>;
35
37
  /**
@@ -5,37 +5,46 @@ const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
5
5
  const react_router_dom_1 = require("react-router-dom");
6
6
  const CssReset_1 = require("../../CssReset");
7
7
  const TableStyles_1 = require("../TableStyles");
8
+ const Tooltip_1 = require("../../Tooltip");
8
9
  const Css_1 = require("../../../Css");
9
10
  /** Renders our default cell element, i.e. if no row links and no custom renderCell are used. */
10
- const defaultRenderFn = (as) => (key, css, content, row, rowStyle, classNames, onClick) => {
11
+ const defaultRenderFn = (as) => (key, css, content, row, rowStyle, classNames, onClick, tooltip) => {
11
12
  const Cell = as === "table" ? "td" : "div";
12
- return ((0, jsx_runtime_1.jsx)(Cell, { css: { ...css, ...(0, TableStyles_1.tableRowStyles)(as) }, className: classNames, onClick: onClick, children: content }, key));
13
+ return ((0, jsx_runtime_1.jsx)(Cell, { css: { ...css, ...(0, TableStyles_1.tableRowStyles)(as) }, className: classNames, onClick: onClick, children: (0, Tooltip_1.maybeTooltip)({ title: tooltip, placement: "top", children: content }) }, key));
13
14
  };
14
15
  exports.defaultRenderFn = defaultRenderFn;
15
16
  /**
16
17
  * Sets up the `GridContext` so that header cells can access the current sort settings.
17
18
  * Used for the Header, Totals, and Expanded Header row's cells.
18
19
  * */
19
- const headerRenderFn = (column, as, colSpan) => (key, css, content, row, rowStyle, classNames) => {
20
+ const headerRenderFn = (column, as, colSpan) => (key, css, content, row, rowStyle, classNames, onClick, tooltip) => {
20
21
  const Cell = as === "table" ? "th" : "div";
21
- return ((0, jsx_runtime_1.jsx)(Cell, { css: { ...css, ...(0, TableStyles_1.tableRowStyles)(as, column) }, className: classNames, ...(as === "table" && { colSpan }), children: content }, key));
22
+ return ((0, jsx_runtime_1.jsx)(Cell, { css: { ...css, ...(0, TableStyles_1.tableRowStyles)(as, column) }, className: classNames, ...(as === "table" && { colSpan }), children: (0, Tooltip_1.maybeTooltip)({ title: tooltip, placement: "top", children: content }) }, key));
22
23
  };
23
24
  exports.headerRenderFn = headerRenderFn;
24
25
  /** Renders a cell element when a row link is in play. */
25
- const rowLinkRenderFn = (as) => (key, css, content, row, rowStyle, classNames) => {
26
+ const rowLinkRenderFn = (as) => (key, css, content, row, rowStyle, classNames, onClick, tooltip) => {
26
27
  const to = rowStyle.rowLink(row);
27
28
  if (as === "table") {
28
- return ((0, jsx_runtime_1.jsx)("td", { css: { ...css, ...(0, TableStyles_1.tableRowStyles)(as) }, className: classNames, children: (0, jsx_runtime_1.jsx)(react_router_dom_1.Link, { to: to, css: Css_1.Css.noUnderline.color("unset").db.$, className: CssReset_1.navLink, children: content }) }, key));
29
+ return ((0, jsx_runtime_1.jsx)("td", { css: { ...css, ...(0, TableStyles_1.tableRowStyles)(as) }, className: classNames, children: (0, Tooltip_1.maybeTooltip)({
30
+ title: tooltip,
31
+ placement: "top",
32
+ children: ((0, jsx_runtime_1.jsx)(react_router_dom_1.Link, { to: to, css: Css_1.Css.noUnderline.color("unset").db.$, className: CssReset_1.navLink, children: content })),
33
+ }) }, key));
29
34
  }
30
- return ((0, jsx_runtime_1.jsx)(react_router_dom_1.Link, { to: to, css: { ...Css_1.Css.noUnderline.color("unset").$, ...css }, className: `${CssReset_1.navLink} ${classNames}`, children: content }, key));
35
+ return (0, Tooltip_1.maybeTooltip)({
36
+ title: tooltip,
37
+ placement: "top",
38
+ children: ((0, jsx_runtime_1.jsx)(react_router_dom_1.Link, { to: to, css: { ...Css_1.Css.noUnderline.color("unset").$, ...css }, className: `${CssReset_1.navLink} ${classNames}`, children: content }, key)),
39
+ });
31
40
  };
32
41
  exports.rowLinkRenderFn = rowLinkRenderFn;
33
42
  /** Renders a cell that will fire the RowStyle.onClick. */
34
- const rowClickRenderFn = (as, api) => (key, css, content, row, rowStyle, classNames, onClick) => {
35
- const Row = as === "table" ? "tr" : "div";
36
- return ((0, jsx_runtime_1.jsx)(Row, { ...{ key }, css: { ...css, ...(0, TableStyles_1.tableRowStyles)(as) }, className: classNames, onClick: (e) => {
43
+ const rowClickRenderFn = (as, api) => (key, css, content, row, rowStyle, classNames, onClick, tooltip) => {
44
+ const Cell = as === "table" ? "td" : "div";
45
+ return ((0, jsx_runtime_1.jsx)(Cell, { ...{ key }, css: { ...css, ...(0, TableStyles_1.tableRowStyles)(as) }, className: classNames, onClick: (e) => {
37
46
  rowStyle.onClick(row, api);
38
47
  onClick && onClick();
39
- }, children: content }));
48
+ }, children: (0, Tooltip_1.maybeTooltip)({ title: tooltip, placement: "top", children: content }) }));
40
49
  };
41
50
  exports.rowClickRenderFn = rowClickRenderFn;
@@ -1,4 +1,4 @@
1
- import { ReactElement, ReactNode } from "react";
1
+ import { ReactNode } from "react";
2
2
  interface TooltipProps {
3
3
  /** The content that shows up when hovered */
4
4
  title: ReactNode;
@@ -10,7 +10,7 @@ interface TooltipProps {
10
10
  export declare function Tooltip(props: TooltipProps): import("@emotion/react/jsx-runtime").JSX.Element;
11
11
  export type Placement = "top" | "bottom" | "left" | "right" | "auto";
12
12
  export declare function maybeTooltip(props: Omit<TooltipProps, "children"> & {
13
- children: ReactElement;
13
+ children: ReactNode;
14
14
  }): import("@emotion/react/jsx-runtime").JSX.Element;
15
15
  export declare function resolveTooltip(disabled?: boolean | ReactNode, tooltip?: ReactNode, readOnly?: boolean | ReactNode): ReactNode | undefined;
16
16
  export {};
@@ -1,31 +1,8 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  Object.defineProperty(exports, "__esModule", { value: true });
26
3
  exports.resolveTooltip = exports.maybeTooltip = exports.Tooltip = void 0;
27
4
  const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
28
- const react_1 = __importStar(require("react"));
5
+ const react_1 = require("react");
29
6
  const react_aria_1 = require("react-aria");
30
7
  const react_dom_1 = require("react-dom");
31
8
  const react_popper_1 = require("react-popper");
@@ -35,11 +12,13 @@ const utils_1 = require("../utils");
35
12
  function Tooltip(props) {
36
13
  const { placement, children, title, disabled, delay = 0 } = props;
37
14
  const state = (0, react_stately_1.useTooltipTriggerState)({ delay, isDisabled: disabled });
38
- const triggerRef = react_1.default.useRef(null);
15
+ const triggerRef = (0, react_1.useRef)(null);
39
16
  const { triggerProps, tooltipProps: _tooltipProps } = (0, react_aria_1.useTooltipTrigger)({ isDisabled: disabled }, state, triggerRef);
40
17
  const { tooltipProps } = (0, react_aria_1.useTooltip)(_tooltipProps, state);
41
18
  const tid = (0, utils_1.useTestIds)(props, "tooltip");
42
19
  return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("span", { ref: triggerRef, ...triggerProps, ...(!state.isOpen && typeof title === "string" ? { title } : {}), ...tid,
20
+ // Add display contents to prevent the tooltip wrapping element from short-circuiting inherited styles (i.e. flex item positioning)
21
+ css: Css_1.Css.display("contents").$,
43
22
  // Adding `draggable` as a hack to allow focus to continue through this element and into its children.
44
23
  // This is due to some code in React-Aria that prevents default due ot mobile browser inconsistencies,
45
24
  // and the only way they don't prevent default is if the element is draggable.
@@ -48,9 +27,14 @@ function Tooltip(props) {
48
27
  }
49
28
  exports.Tooltip = Tooltip;
50
29
  function Popper({ triggerRef, content, placement = "auto" }) {
30
+ var _a;
51
31
  const popperRef = (0, react_1.useRef)(null);
52
32
  const [arrowRef, setArrowRef] = (0, react_1.useState)(null);
53
- const { styles, attributes } = (0, react_popper_1.usePopper)(triggerRef.current, popperRef.current, {
33
+ // Since we use `display: contents;` on the `triggerRef`, then the element.offsetTop/Left/etc all equal `0`. This would make
34
+ // the tooltip show in the top left of the document. So instead, we target either the first child, if available, or the parent element as the tooltip target.
35
+ // It is possible there are no children if the element only has text content, which is the reasoning for the parentElement fallback.
36
+ const targetElement = triggerRef.current ? (_a = triggerRef.current.children[0]) !== null && _a !== void 0 ? _a : triggerRef.current.parentElement : null;
37
+ const { styles, attributes } = (0, react_popper_1.usePopper)(targetElement, popperRef.current, {
54
38
  modifiers: [
55
39
  { name: "arrow", options: { element: arrowRef } },
56
40
  { name: "offset", options: { offset: [0, 5] } },
@@ -60,9 +44,8 @@ function Popper({ triggerRef, content, placement = "auto" }) {
60
44
  return (0, react_dom_1.createPortal)((0, jsx_runtime_1.jsxs)("div", { ref: popperRef, style: styles.popper, ...attributes.popper, css: Css_1.Css.maxw("320px").bgGray900.white.px1.py("4px").br4.xs.add("zIndex", 999999).$, children: [(0, jsx_runtime_1.jsx)("div", { ref: setArrowRef, style: { ...styles.arrow }, id: "arrow" }), content] }), document.body);
61
45
  }
62
46
  // Helper function to conditionally wrap component with Tooltip if necessary.
63
- // `maybeTooltip` requires that the `children` prop be a ReactElement, even though <Tooltip /> allows for ReactNode.
64
47
  function maybeTooltip(props) {
65
- return props.title ? (0, jsx_runtime_1.jsx)(Tooltip, { ...props }) : props.children;
48
+ return props.title ? (0, jsx_runtime_1.jsx)(Tooltip, { ...props }) : (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: props.children });
66
49
  }
67
50
  exports.maybeTooltip = maybeTooltip;
68
51
  // Helper function for resolving showing the Tooltip text via a 'disabled' prop, or the 'tooltip' prop.
@@ -14,6 +14,7 @@ const Css_1 = require("../../Css");
14
14
  const utils_1 = require("../../utils");
15
15
  const defaultTestId_1 = require("../../utils/defaultTestId");
16
16
  function OverlayTrigger(props) {
17
+ var _a, _b, _c;
17
18
  const { trigger, buttonRef, menuTriggerProps, placement, state, disabled, tooltip, children, variant, hideEndAdornment, showActiveBorder = false, contrast = false, } = props;
18
19
  const popoverRef = (0, react_1.useRef)(null);
19
20
  const { overlayProps: positionProps } = (0, react_aria_1.useOverlayPosition)({
@@ -32,7 +33,7 @@ function OverlayTrigger(props) {
32
33
  : isIconButton(trigger)
33
34
  ? trigger.icon
34
35
  : trigger.name);
35
- return ((0, jsx_runtime_1.jsxs)("div", { css: Css_1.Css.relative.dib.$, children: [isTextButton(trigger) ? ((0, jsx_runtime_1.jsx)(Button_1.Button, { variant: variant ? variant : "secondary", contrast: contrast, ...trigger, menuTriggerProps: menuTriggerProps, buttonRef: buttonRef, endAdornment: !hideEndAdornment ? (0, jsx_runtime_1.jsx)(Icon_1.Icon, { icon: state.isOpen ? "chevronUp" : "chevronDown" }) : null, disabled: disabled, tooltip: tooltip, onClick: utils_1.noop, forceFocusStyles: showActiveBorder && state.isOpen, ...tid })) : isNavLinkButton(trigger) ? ((0, jsx_runtime_1.jsx)(NavLink_1.NavLink, { ...trigger, label: trigger.navLabel, disabled: !!disabled, contrast: contrast, menuTriggerProps: menuTriggerProps, buttonRef: buttonRef, ...tid })) : isIconButton(trigger) ? ((0, jsx_runtime_1.jsx)(IconButton_1.IconButton, { ...trigger, menuTriggerProps: menuTriggerProps, buttonRef: buttonRef, ...tid, disabled: disabled, tooltip: tooltip, onClick: utils_1.noop, forceFocusStyles: showActiveBorder && state.isOpen })) : ((0, jsx_runtime_1.jsx)(AvatarButton_1.AvatarButton, { ...trigger, menuTriggerProps: menuTriggerProps, buttonRef: buttonRef, ...tid, disabled: disabled, tooltip: tooltip, onClick: utils_1.noop, forceFocusStyles: showActiveBorder && state.isOpen })), state.isOpen && ((0, jsx_runtime_1.jsx)(internal_1.Popover, { triggerRef: buttonRef, popoverRef: popoverRef, positionProps: positionProps, onClose: () => state.close(), isOpen: state.isOpen, children: children }))] }));
36
+ return ((0, jsx_runtime_1.jsxs)("div", { css: Css_1.Css.relative.dib.$, children: [isTextButton(trigger) ? ((0, jsx_runtime_1.jsx)(Button_1.Button, { variant: variant ? variant : "secondary", contrast: contrast, ...trigger, menuTriggerProps: menuTriggerProps, buttonRef: buttonRef, endAdornment: !hideEndAdornment ? (0, jsx_runtime_1.jsx)(Icon_1.Icon, { icon: state.isOpen ? "chevronUp" : "chevronDown" }) : null, disabled: disabled, tooltip: tooltip, onClick: (_a = menuTriggerProps.onPress) !== null && _a !== void 0 ? _a : utils_1.noop, forceFocusStyles: showActiveBorder && state.isOpen, ...tid })) : isNavLinkButton(trigger) ? ((0, jsx_runtime_1.jsx)(NavLink_1.NavLink, { ...trigger, label: trigger.navLabel, disabled: !!disabled, contrast: contrast, menuTriggerProps: menuTriggerProps, buttonRef: buttonRef, ...tid })) : isIconButton(trigger) ? ((0, jsx_runtime_1.jsx)(IconButton_1.IconButton, { ...trigger, menuTriggerProps: menuTriggerProps, buttonRef: buttonRef, ...tid, disabled: disabled, tooltip: tooltip, onClick: (_b = menuTriggerProps.onPress) !== null && _b !== void 0 ? _b : utils_1.noop, forceFocusStyles: showActiveBorder && state.isOpen })) : ((0, jsx_runtime_1.jsx)(AvatarButton_1.AvatarButton, { ...trigger, menuTriggerProps: menuTriggerProps, buttonRef: buttonRef, ...tid, disabled: disabled, tooltip: tooltip, onClick: (_c = menuTriggerProps.onPress) !== null && _c !== void 0 ? _c : utils_1.noop, forceFocusStyles: showActiveBorder && state.isOpen })), state.isOpen && ((0, jsx_runtime_1.jsx)(internal_1.Popover, { triggerRef: buttonRef, popoverRef: popoverRef, positionProps: positionProps, onClose: () => state.close(), isOpen: state.isOpen, children: children }))] }));
36
37
  }
37
38
  exports.OverlayTrigger = OverlayTrigger;
38
39
  function isTextButton(trigger) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homebound/beam",
3
- "version": "2.240.2",
3
+ "version": "2.241.1",
4
4
  "author": "Homebound",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",