@intility/bifrost-react
Version:
React library for Intility's design system, Bifrost.
149 lines (148 loc) • 4.08 kB
JavaScript
"use client";
import { c as _c } from "react-compiler-runtime";
import { forwardRef, useState } from "react";
import classNames from "classnames";
import { faAngleRight } from "@fortawesome/free-solid-svg-icons/faAngleRight";
import Icon from "../Icon/Icon.js";
import TableCell from "./Table.Cell.js";
import accessibleOnClick from "../../utils/accessibleOnClick.js";
import SlideDown from "../SlideDown/SlideDown.js";
import useLocale from "../../hooks/useLocale.js";
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
const TableRow = /*#__PURE__*/forwardRef((t0, ref) => {
const $ = _c(28);
const {
className,
onClick: onClickProp,
content,
eager: t1,
open: openProp,
onOpenChange,
children,
limitExpandClick,
...props
} = t0;
const eager = t1 === undefined ? false : t1;
const locale = useLocale();
const [openState, setOpenState] = useState(false);
const open = openProp ?? openState;
let t2;
if ($[0] !== onOpenChange) {
t2 = event => {
event.stopPropagation();
setOpenState(_temp);
if (typeof onOpenChange === "function") {
onOpenChange();
}
};
$[0] = onOpenChange;
$[1] = t2;
} else {
t2 = $[1];
}
const handleArrowClick = t2;
const onClick = content && !limitExpandClick ? handleArrowClick : onClickProp;
const t3 = !limitExpandClick;
const t4 = content && !open;
let t5;
if ($[2] !== className || $[3] !== onClick || $[4] !== t3 || $[5] !== t4) {
t5 = classNames(className, {
"bf-table-row-clickable": onClick,
"bf-table-expand-nolimit": t3,
"bf-table-expand-closed": t4
});
$[2] = className;
$[3] = onClick;
$[4] = t3;
$[5] = t4;
$[6] = t5;
} else {
t5 = $[6];
}
const t6 = accessibleOnClick(props, onClick);
let t7;
if ($[7] !== content || $[8] !== handleArrowClick || $[9] !== limitExpandClick || $[10] !== locale || $[11] !== open || $[12] !== openState) {
t7 = content && /*#__PURE__*/_jsx(TableCell, {
className: "bf-table-expand-icon-cell",
onClick: limitExpandClick ? handleArrowClick : undefined,
"aria-label": `${openState ? locale.collapse : locale.expand} ${locale.row}`,
children: /*#__PURE__*/_jsx("div", {
className: "bf-table-expand-icon-wrapper",
children: /*#__PURE__*/_jsx(Icon, {
className: classNames("bf-table-expand-icon", {
"bf-table-expand-icon-open": open
}),
icon: faAngleRight
})
})
});
$[7] = content;
$[8] = handleArrowClick;
$[9] = limitExpandClick;
$[10] = locale;
$[11] = open;
$[12] = openState;
$[13] = t7;
} else {
t7 = $[13];
}
let t8;
if ($[14] !== children || $[15] !== props || $[16] !== ref || $[17] !== t5 || $[18] !== t6 || $[19] !== t7) {
t8 = /*#__PURE__*/_jsxs("tr", {
className: t5,
ref: ref,
...props,
...t6,
children: [t7, children]
});
$[14] = children;
$[15] = props;
$[16] = ref;
$[17] = t5;
$[18] = t6;
$[19] = t7;
$[20] = t8;
} else {
t8 = $[20];
}
let t9;
if ($[21] !== content || $[22] !== eager || $[23] !== open) {
t9 = content && /*#__PURE__*/_jsx("tr", {
children: /*#__PURE__*/_jsx("td", {
className: "bf-table-expandable-cell",
colSpan: 999,
children: /*#__PURE__*/_jsx(SlideDown, {
open: open,
eager: eager,
children: /*#__PURE__*/_jsx("div", {
className: "bf-table-expanded-content bfc-base-2-bg",
children: content
})
})
})
});
$[21] = content;
$[22] = eager;
$[23] = open;
$[24] = t9;
} else {
t9 = $[24];
}
let t10;
if ($[25] !== t8 || $[26] !== t9) {
t10 = /*#__PURE__*/_jsxs(_Fragment, {
children: [t8, t9]
});
$[25] = t8;
$[26] = t9;
$[27] = t10;
} else {
t10 = $[27];
}
return t10;
});
TableRow.displayName = "Table.Row";
export default TableRow;
function _temp(o) {
return !o;
}