Skip to content

Commit b5c49a6

Browse files
authored
23479: Corrections to DataTable layout and contrast (#93)
- Fixed DataTable light mode color contrast issues - Tightened spacing of DataTableCaption and exposed props
1 parent c64f1b6 commit b5c49a6

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

src/components/DataDisplay/DataTable/DataTable.tsx

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ export interface DataTableProps
1414
extends PropsWithChildren,
1515
Omit<ComponentProps<"div">, "ref"> {
1616
bordered?: boolean;
17+
/** Children to send to DataTableCaption */
1718
caption?: ReactNode;
19+
/** Props to send to DataTableCaption. Ensure this object is memoized. */
20+
captionProps?: Omit<DataTableCaptionProps, "children">;
1821
/** The <th /> index from 0 to scroll to within <thead />'s first row */
1922
centeredColumnIndex?: number;
2023
/** @deprecated See centeredColumnIndex */
@@ -52,6 +55,7 @@ export interface DataTableProps
5255

5356
export const DataTableComponent: FC<DataTableProps> = ({
5457
caption: captionChildren,
58+
captionProps,
5559
centeredColumnIndex,
5660
centeredIndex: deprecatedCenteredColumnIndex,
5761
centeredRowIndex,
@@ -150,7 +154,7 @@ export const DataTableComponent: FC<DataTableProps> = ({
150154
>
151155
<THead columns={columns} stickyColumns={stickyColumns} />
152156
<tbody
153-
className={"group/body divide-y text-gray-500 dark:text-gray-200"}
157+
className={"group/body divide-y text-gray-800 dark:text-gray-200"}
154158
>
155159
{loading
156160
? new Array(loadingRows).fill(0).map((_, y) => (
@@ -169,7 +173,13 @@ export const DataTableComponent: FC<DataTableProps> = ({
169173
: children}
170174
</tbody>
171175
{captionChildren && (
172-
<caption className="sticky left-4 w-fit *:justify-start">
176+
<caption
177+
{...captionProps}
178+
className={twMerge(
179+
"sticky left-4 w-fit *:justify-start",
180+
captionProps?.className,
181+
)}
182+
>
173183
<DataTable.Caption>{captionChildren}</DataTable.Caption>
174184
</caption>
175185
)}
@@ -280,26 +290,17 @@ const DataTableCell = forwardRef<HTMLTableCellElement, DataTableCellProps>(
280290
);
281291
DataTableCell.displayName = "DataTable.Cell";
282292

283-
export type DataTableCaptionProps = {
284-
className?: string;
285-
children?: ReactNode;
286-
};
287-
288-
export const DataTableCaption: FC<DataTableCaptionProps> = function ({
289-
children,
290-
className,
291-
}) {
292-
return (
293-
<span
294-
className={twMerge(
295-
"mt-4 flex justify-center text-sm text-gray-500 dark:text-gray-400",
296-
className,
297-
)}
298-
>
299-
{children}
300-
</span>
301-
);
302-
};
293+
export type DataTableCaptionProps = ComponentProps<"span">;
294+
/** An inline component styled to look like a <caption />. Through DataTable it is embedded inside <caption /> */
295+
export const DataTableCaption: FC<DataTableCaptionProps> = (props) => (
296+
<span
297+
{...props}
298+
className={twMerge(
299+
"mt-2 flex justify-center text-sm text-gray-600 dark:text-gray-400",
300+
props.className,
301+
)}
302+
/>
303+
);
303304

304305
const dataTableHeaderColorsClassNames = "bg-gray-100 dark:bg-gray-700";
305306

0 commit comments

Comments
 (0)