@hitachivantara/uikit-react-core
Version:
Core React components for the NEXT Design System.
71 lines (70 loc) • 2.48 kB
JavaScript
import { jsx } from "react/jsx-runtime";
import { forwardRef, useContext } from "react";
import { useDefaultProps } from "@hitachivantara/uikit-react-utils";
import { capitalize } from "../../utils/helpers.js";
import TableContext from "../TableContext.js";
import { TableSectionContext } from "../TableSectionContext.js";
import { useClasses } from "./TableCell.styles.js";
import { staticClasses } from "./TableCell.styles.js";
const defaultComponent = "td";
const HvTableCell = forwardRef(
function HvTableCell2(props, ref) {
const {
children,
component,
className,
style,
classes: classesProp,
align = "inherit",
variant = "default",
type: typeProp,
stickyColumn = false,
stickyColumnMostLeft = false,
stickyColumnLeastRight = false,
groupColumnMostLeft = false,
groupColumnMostRight = false,
sorted = false,
resizable = false,
resizing = false,
...others
} = useDefaultProps("HvTableCell", props);
const { classes, cx } = useClasses(classesProp);
const tableContext = useContext(TableContext);
const tableSectionContext = useContext(TableSectionContext);
const type = typeProp || tableSectionContext?.type || "body";
const Component = component || tableContext?.components?.Td || defaultComponent;
return /* @__PURE__ */ jsx(
Component,
{
ref,
role: Component === defaultComponent ? null : "cell",
style,
className: cx(
classes.root,
classes[type],
align !== "inherit" && classes[`align${capitalize(align)}`],
variant !== "default" && classes[`variant${capitalize(variant)}`],
{
[classes.variantList]: tableContext.variant === "listrow",
[classes.variantListHead]: tableContext.variant === "listrow" && type !== "body",
[classes.sorted]: sorted,
[classes.stickyColumn]: stickyColumn,
[classes.stickyColumnMostLeft]: stickyColumnMostLeft,
[classes.stickyColumnLeastRight]: stickyColumnLeastRight,
[classes.groupColumnMostLeft]: groupColumnMostLeft,
[classes.groupColumnMostRight]: groupColumnMostRight,
[classes.resizable]: resizable,
[classes.resizing]: resizing
},
className
),
...others,
children
}
);
}
);
export {
HvTableCell,
staticClasses as tableCellClasses
};