Skip to content

Commit

Permalink
fix(table): table-column align prop
Browse files Browse the repository at this point in the history
  • Loading branch information
chirokas committed May 16, 2024
1 parent 8988981 commit 907fb33
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changeset/rich-sloths-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@nextui-org/table": patch
"@nextui-org/theme": patch
---

Fix #2886 TableColumn align prop fixed, style improved.
5 changes: 4 additions & 1 deletion packages/components/table/src/table-cell.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {GridNode} from "@react-types/grid";
import type {TableColumnProps} from "./base";

import {Key, useMemo} from "react";
import {forwardRef, HTMLNextUIProps} from "@nextui-org/system";
Expand Down Expand Up @@ -49,6 +50,8 @@ const TableCell = forwardRef<"td", TableCellProps>((props, ref) => {
);
}, [node.rendered]);

const columnProps: TableColumnProps<unknown> = node.column?.props || {};

return (
<Component
ref={domRef}
Expand All @@ -62,7 +65,7 @@ const TableCell = forwardRef<"td", TableCellProps>((props, ref) => {
}),
otherProps,
)}
className={slots.td?.({class: tdStyles})}
className={slots.td?.({align: columnProps.align, class: tdStyles})}
>
{cell}
</Component>
Expand Down
4 changes: 2 additions & 2 deletions packages/components/table/src/table-column-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const TableColumnHeader = forwardRef<"th", TableColumnHeaderProps>((props, ref)

const {isFocusVisible, focusProps} = useFocusRing();
const {isHovered, hoverProps} = useHover({});
const {hideHeader, ...columnProps} = node.props;
const {hideHeader, align, ...columnProps} = node.props;

const allowsSorting = columnProps.allowsSorting;

Expand All @@ -57,7 +57,7 @@ const TableColumnHeader = forwardRef<"th", TableColumnHeaderProps>((props, ref)
allowsSorting ? hoverProps : {},
otherProps,
)}
className={slots.th?.({class: thStyles})}
className={slots.th?.({align, class: thStyles})}
>
{hideHeader ? <VisuallyHidden>{node.rendered}</VisuallyHidden> : node.rendered}
{allowsSorting && (
Expand Down
18 changes: 16 additions & 2 deletions packages/core/theme/src/components/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ const table = tv({
"group",
"px-3",
"h-10",
"text-left",
"rtl:text-right",
"align-middle",
"bg-default-100",
"whitespace-nowrap",
Expand Down Expand Up @@ -249,6 +247,20 @@ const table = tv({
table: "w-full",
},
},
align: {
start: {
th: "text-start",
td: "text-start",
},
center: {
th: "text-center",
td: "text-center",
},
end: {
th: "text-end",
td: "text-end",
},
},
},
defaultVariants: {
layout: "auto",
Expand All @@ -259,6 +271,8 @@ const table = tv({
hideHeader: false,
isStriped: false,
fullWidth: true,
disableAnimation: false,
align: "start",
},
});

Expand Down

0 comments on commit 907fb33

Please sign in to comment.