@homebound/beam 2.131.0 → 2.132.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.
- package/dist/components/Button.js +3 -3
- package/dist/components/Table/GridTable.d.ts +2 -0
- package/dist/components/Table/GridTable.js +19 -5
- package/dist/components/internal/OverlayTrigger.js +1 -1
- package/dist/interfaces.d.ts +1 -1
- package/dist/utils/getInteractiveElement.d.ts +3 -0
- package/dist/utils/getInteractiveElement.js +10 -0
- package/package.json +1 -1
|
@@ -4,10 +4,10 @@ exports.Button = void 0;
|
|
|
4
4
|
const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const react_aria_1 = require("react-aria");
|
|
7
|
-
const react_router_dom_1 = require("react-router-dom");
|
|
8
7
|
const components_1 = require("./");
|
|
9
8
|
const Css_1 = require("../Css");
|
|
10
9
|
const utils_1 = require("../utils");
|
|
10
|
+
const getInteractiveElement_1 = require("../utils/getInteractiveElement");
|
|
11
11
|
const useTestIds_1 = require("../utils/useTestIds");
|
|
12
12
|
function Button(props) {
|
|
13
13
|
const { onClick: onPress, disabled, endAdornment, menuTriggerProps, tooltip, openInNew, download, contrast = false, ...otherProps } = props;
|
|
@@ -38,6 +38,7 @@ function Button(props) {
|
|
|
38
38
|
...buttonProps,
|
|
39
39
|
...focusProps,
|
|
40
40
|
...hoverProps,
|
|
41
|
+
className: typeof onPress === "string" ? components_1.navLink : undefined,
|
|
41
42
|
css: {
|
|
42
43
|
...Css_1.Css.buttonBase.tt("inherit").$,
|
|
43
44
|
...baseStyles,
|
|
@@ -48,12 +49,11 @@ function Button(props) {
|
|
|
48
49
|
},
|
|
49
50
|
...tid,
|
|
50
51
|
};
|
|
51
|
-
const button = typeof onPress === "string" ? ((0, utils_1.isAbsoluteUrl)(onPress) || openInNew || download ? ((0, jsx_runtime_1.jsx)("a", Object.assign({}, buttonAttrs, { href: onPress, className: components_1.navLink }, (download ? { download: "" } : { target: "_blank", rel: "noreferrer noopener" }), { children: buttonContent }), void 0)) : ((0, jsx_runtime_1.jsx)(react_router_dom_1.Link, Object.assign({}, buttonAttrs, { to: onPress, className: components_1.navLink }, { children: buttonContent }), void 0))) : ((0, jsx_runtime_1.jsx)("button", Object.assign({}, buttonAttrs, { children: buttonContent }), void 0));
|
|
52
52
|
// If we're disabled b/c of a non-boolean ReactNode, or the caller specified tooltip text, then show it in a tooltip
|
|
53
53
|
return (0, components_1.maybeTooltip)({
|
|
54
54
|
title: (0, components_1.resolveTooltip)(disabled, tooltip),
|
|
55
55
|
placement: "top",
|
|
56
|
-
children:
|
|
56
|
+
children: (0, getInteractiveElement_1.getButtonOrLink)(buttonContent, onPress, buttonAttrs, openInNew, download),
|
|
57
57
|
});
|
|
58
58
|
}
|
|
59
59
|
exports.Button = Button;
|
|
@@ -309,6 +309,8 @@ export declare type GridCellContent = {
|
|
|
309
309
|
typeScale?: Typography;
|
|
310
310
|
/** Allows the cell to stay in place when the user scrolls horizontally */
|
|
311
311
|
sticky?: "left" | "right";
|
|
312
|
+
/** If provided, content of the cell will be wrapped within a <button /> or <a /> tag depending on if the value is a function or a string. */
|
|
313
|
+
onClick?: () => {} | string;
|
|
312
314
|
};
|
|
313
315
|
declare type MaybeFn<T> = T | (() => T);
|
|
314
316
|
/**
|
|
@@ -45,6 +45,7 @@ const Css_1 = require("../../Css");
|
|
|
45
45
|
const hooks_1 = require("../../hooks");
|
|
46
46
|
const useRenderCount_1 = require("../../hooks/useRenderCount");
|
|
47
47
|
const utils_1 = require("../../utils");
|
|
48
|
+
const getInteractiveElement_1 = require("../../utils/getInteractiveElement");
|
|
48
49
|
const shallowEqual_1 = require("../../utils/shallowEqual");
|
|
49
50
|
const _1 = require(".");
|
|
50
51
|
exports.ASC = "ASC";
|
|
@@ -273,6 +274,11 @@ const renders = {
|
|
|
273
274
|
/** Renders table using divs with flexbox rows, which is the default render */
|
|
274
275
|
function renderDiv(style, id, columns, headerRows, totalsRows, filteredRows, firstRowMessage, _stickyHeader, firstLastColumnWidth, xss, _virtuosoRef, tableRef) {
|
|
275
276
|
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ ref: tableRef, css: {
|
|
277
|
+
// Use `fit-content` to ensure the width of the table takes up the full width of its content.
|
|
278
|
+
// Otherwise, the table's width would be that of its container, which may not be as wide as the table itself.
|
|
279
|
+
// In cases where we have sticky columns on a very wide table, then the container which the columns "stick" to (which is the table),
|
|
280
|
+
// needs to be as wide as the table's content, or else we lose the "stickiness" once scrolling past width of the table's container.
|
|
281
|
+
...Css_1.Css.mw("fit-content").$,
|
|
276
282
|
/*
|
|
277
283
|
Using (n + 3) here to target all rows that are after the first non-header row. Since n starts at 0, we can use
|
|
278
284
|
the + operator as an offset.
|
|
@@ -643,9 +649,9 @@ function isJSX(content) {
|
|
|
643
649
|
return typeof content === "object" && content && "type" in content && "props" in content;
|
|
644
650
|
}
|
|
645
651
|
/** If a column def return just string text for a given row, apply some default styling. */
|
|
646
|
-
function toContent(
|
|
647
|
-
var _a;
|
|
648
|
-
content = isGridCellContent(
|
|
652
|
+
function toContent(maybeContent, isHeader, canSortColumn, isClientSideSorting, style, as, alignment) {
|
|
653
|
+
var _a, _b;
|
|
654
|
+
let content = isGridCellContent(maybeContent) ? maybeContent.content : maybeContent;
|
|
649
655
|
if (typeof content === "function") {
|
|
650
656
|
// Actually create the JSX by calling `content()` here (which should be as late as
|
|
651
657
|
// possible, i.e. only for visible rows if we're in a virtual table).
|
|
@@ -662,11 +668,19 @@ function toContent(content, isHeader, canSortColumn, isClientSideSorting, style,
|
|
|
662
668
|
// for those tables.
|
|
663
669
|
throw new Error("GridTables with as=virtual & sortable columns should use functions that return JSX, instead of JSX");
|
|
664
670
|
}
|
|
671
|
+
content =
|
|
672
|
+
isGridCellContent(maybeContent) && !!maybeContent.onClick
|
|
673
|
+
? (0, getInteractiveElement_1.getButtonOrLink)(content, maybeContent.onClick, {
|
|
674
|
+
css: Css_1.Css.maxw100.lightBlue700.if(((_a = style === null || style === void 0 ? void 0 : style.presentationSettings) === null || _a === void 0 ? void 0 : _a.wrap) === false).truncate.$,
|
|
675
|
+
})
|
|
676
|
+
: content;
|
|
665
677
|
if (content && typeof content === "string" && isHeader && canSortColumn) {
|
|
666
678
|
return (0, jsx_runtime_1.jsx)(SortHeader_1.SortHeader, { content: content, iconOnLeft: alignment === "right" }, void 0);
|
|
667
679
|
}
|
|
668
|
-
else if (content &&
|
|
669
|
-
|
|
680
|
+
else if (content && ((_b = style === null || style === void 0 ? void 0 : style.presentationSettings) === null || _b === void 0 ? void 0 : _b.wrap) === false && typeof content === "string") {
|
|
681
|
+
// In order to truncate the text properly, then we need to wrap it in another element
|
|
682
|
+
// as our cell element is a flex container, which don't allow for applying truncation styles directly on it.
|
|
683
|
+
return ((0, jsx_runtime_1.jsx)("span", Object.assign({ css: Css_1.Css.truncate.mw0.$, title: content }, { children: content }), void 0));
|
|
670
684
|
}
|
|
671
685
|
else if (style.emptyCell && isContentEmpty(content)) {
|
|
672
686
|
// If the content is empty and the user specified an `emptyCell` node, return that.
|
|
@@ -23,7 +23,7 @@ function OverlayTrigger(props) {
|
|
|
23
23
|
placement: (placement ? `bottom ${placement}` : "bottom left"),
|
|
24
24
|
});
|
|
25
25
|
const tid = (0, utils_1.useTestIds)(props, isTextButton(trigger) ? (0, defaultTestId_1.defaultTestId)(trigger.label) : trigger.icon);
|
|
26
|
-
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ css: Css_1.Css.relative.dib.$ }, { children: [isTextButton(trigger) ? ((0, jsx_runtime_1.jsx)(Button_1.Button, Object.assign({ variant: "secondary" }, trigger, { menuTriggerProps: menuTriggerProps, buttonRef: buttonRef, endAdornment: (0, jsx_runtime_1.jsx)(Icon_1.Icon, { icon: state.isOpen ? "chevronUp" : "chevronDown" }, void 0), disabled: disabled, tooltip: tooltip }, tid), void 0)) : ((0, jsx_runtime_1.jsx)(IconButton_1.IconButton, Object.assign({}, trigger, { menuTriggerProps: menuTriggerProps, buttonRef: buttonRef }, tid), void 0)), state.isOpen && ((0, jsx_runtime_1.jsx)(internal_1.Popover, Object.assign({ triggerRef: buttonRef, popoverRef: popoverRef, positionProps: positionProps, onClose: () => state.close(), isOpen: state.isOpen }, { children: children }), void 0))] }), void 0));
|
|
26
|
+
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ css: Css_1.Css.relative.dib.$ }, { children: [isTextButton(trigger) ? ((0, jsx_runtime_1.jsx)(Button_1.Button, Object.assign({ variant: "secondary" }, trigger, { menuTriggerProps: menuTriggerProps, buttonRef: buttonRef, endAdornment: (0, jsx_runtime_1.jsx)(Icon_1.Icon, { icon: state.isOpen ? "chevronUp" : "chevronDown" }, void 0), disabled: disabled, tooltip: tooltip, onClick: utils_1.noop }, tid), void 0)) : ((0, jsx_runtime_1.jsx)(IconButton_1.IconButton, Object.assign({}, trigger, { menuTriggerProps: menuTriggerProps, buttonRef: buttonRef }, tid, { onClick: utils_1.noop }), void 0)), state.isOpen && ((0, jsx_runtime_1.jsx)(internal_1.Popover, Object.assign({ triggerRef: buttonRef, popoverRef: popoverRef, positionProps: positionProps, onClose: () => state.close(), isOpen: state.isOpen }, { children: children }), void 0))] }), void 0));
|
|
27
27
|
}
|
|
28
28
|
exports.OverlayTrigger = OverlayTrigger;
|
|
29
29
|
function isTextButton(trigger) {
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export interface BeamButtonProps {
|
|
|
16
16
|
*/
|
|
17
17
|
disabled?: boolean | ReactNode;
|
|
18
18
|
/** If function, then it is the handler that is called when the press is released over the target. Otherwise if string, it is the URL path for the link */
|
|
19
|
-
onClick
|
|
19
|
+
onClick: ((e: PressEvent) => void) | string;
|
|
20
20
|
/** Text to be shown via a tooltip when the user hovers over the button */
|
|
21
21
|
tooltip?: ReactNode;
|
|
22
22
|
/** Whether to open link in a new tab. This only effects the element if the `onClick` is a `string`/URL. */
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { PressEvent } from "@react-types/shared";
|
|
2
|
+
import { HTMLAttributes, ReactNode } from "react";
|
|
3
|
+
export declare function getButtonOrLink(content: ReactNode, onClick: ((e: PressEvent) => void) | string, attrs: HTMLAttributes<HTMLButtonElement | HTMLAnchorElement>, openInNew?: boolean, downloadLink?: boolean): JSX.Element;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getButtonOrLink = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
5
|
+
const react_router_dom_1 = require("react-router-dom");
|
|
6
|
+
const index_1 = require("./index");
|
|
7
|
+
function getButtonOrLink(content, onClick, attrs, openInNew = false, downloadLink = false) {
|
|
8
|
+
return typeof onClick === "string" ? ((0, index_1.isAbsoluteUrl)(onClick) || openInNew || downloadLink ? ((0, jsx_runtime_1.jsx)("a", Object.assign({}, attrs, { href: onClick }, (downloadLink ? { download: "" } : { target: "_blank", rel: "noreferrer noopener" }), { children: content }), void 0)) : ((0, jsx_runtime_1.jsx)(react_router_dom_1.Link, Object.assign({}, attrs, { to: onClick }, { children: content }), void 0))) : ((0, jsx_runtime_1.jsx)("button", Object.assign({}, attrs, { children: content }), void 0));
|
|
9
|
+
}
|
|
10
|
+
exports.getButtonOrLink = getButtonOrLink;
|