Skip to content

Commit

Permalink
feat(ui): extra styling variant of the table component (#2715)
Browse files Browse the repository at this point in the history
  • Loading branch information
sstraatemans authored Dec 6, 2024
1 parent 1f46bee commit dbd9076
Show file tree
Hide file tree
Showing 20 changed files with 511 additions and 184 deletions.
5 changes: 5 additions & 0 deletions .changeset/nervous-turtles-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@kadena/kode-ui': minor
---

add an extra styling variant to the table component
1 change: 1 addition & 0 deletions packages/apps/rwa-demo/src/app/(app)/assets/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const Assets = () => {
return (
<>
<CompactTable
variant="open"
fields={[
{
key: 'uuid',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const AgentsList: FC = () => {
/>
<SectionCardBody>
<CompactTable
variant="open"
fields={[
{
label: 'Name',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const InvestorList: FC = () => {

<SectionCardBody>
<CompactTable
variant="open"
fields={[
{
label: 'Name',
Expand Down
32 changes: 20 additions & 12 deletions packages/libs/kode-ui/src/components/Table/Body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,22 @@ import {
useTableCell,
useTableRow,
} from 'react-aria';
import { tableDataCell, tableRow } from './Table.css';
import type { ITableProps } from './Table';
import { spacerClass, tableDataCell, tableRow } from './Table.css';

export interface ITableRowProps<T> {
item: GridNode<T>;
state: TableState<T> | TreeGridState<T>;
children: ReactNode;
selectionMode: TableProps<T>['selectionMode'];
variant: ITableProps<HTMLTableElement>['variant'];
}

export function TableRow<T extends object>({
item,
children,
state,
variant,
}: ITableRowProps<T>) {
const ref = useRef(null);
const { rowProps, isSelected } = useTableRow(
Expand All @@ -36,27 +39,32 @@ export function TableRow<T extends object>({
const { isHovered, hoverProps } = useHover({ isDisabled: false });

return (
<tr
className={tableRow}
{...mergeProps(rowProps, focusProps, hoverProps)}
data-focused={isFocusVisible || undefined}
data-hovered={isHovered || undefined}
data-selected={isSelected || undefined}
ref={ref}
>
{children}
</tr>
<>
{variant === 'open' && <tr className={spacerClass} />}
<tr
className={tableRow}
{...mergeProps(rowProps, focusProps, hoverProps)}
data-focused={isFocusVisible || undefined}
data-hovered={isHovered || undefined}
data-selected={isSelected || undefined}
ref={ref}
>
{children}
</tr>
</>
);
}

interface ITableCellProps<T> {
cell: GridNode<T>;
state: TableState<T>;
variant: ITableProps<HTMLTableElement>['variant'];
}

export function TableCell<T extends object>({
cell,
state,
variant = 'default',
}: ITableCellProps<T>) {
const ref = useRef(null);
const { gridCellProps } = useTableCell({ node: cell }, state, ref);
Expand All @@ -65,7 +73,7 @@ export function TableCell<T extends object>({
return (
<td
{...mergeProps(gridCellProps, focusProps)}
className={tableDataCell}
className={tableDataCell({ variant })}
data-focused={isFocusVisible || undefined}
ref={ref}
>
Expand Down
20 changes: 8 additions & 12 deletions packages/libs/kode-ui/src/components/Table/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,33 @@ import {
useTableColumnHeader,
useTableHeaderRow,
} from 'react-aria';
import type { ITableProps } from '..';
import { Stack } from '..';

import { MonoExpandLess, MonoExpandMore } from '@kadena/kode-icons/system';
import classNames from 'classnames';
import {
columnHeader,
defaultHeader,
headerBase,
subtleHeader,
} from './Table.css';
import { columnHeader, headerBase } from './Table.css';

interface ITableHeaderRowProps<T> {
item: GridNode<T>;
state: TableState<T>;
children: ReactNode;
isSubtle?: boolean;
variant: ITableProps<HTMLTableElement>['variant'];
}

export function TableHeaderRow<T extends object>({
item,
state,
children,
isSubtle = false,
variant = 'default',
}: ITableHeaderRowProps<T>) {
const ref = useRef(null);
const { rowProps } = useTableHeaderRow({ node: item }, state, ref);

return (
<tr
className={classNames(headerBase, {
[subtleHeader]: isSubtle,
[defaultHeader]: !isSubtle,
})}
className={headerBase({ variant, subtleHeader: isSubtle })}
{...rowProps}
ref={ref}
>
Expand All @@ -65,11 +59,13 @@ interface ITableColumnHeaderProps<T> {
column: GridNode<T>;
state: TableState<T>;
isSubtle?: boolean;
variant: ITableProps<HTMLTableElement>['variant'];
}

export function TableColumnHeader<T extends object>({
column,
state,
variant,
}: ITableColumnHeaderProps<T>) {
const ref = useRef(null);
const { columnHeaderProps } = useTableColumnHeader(
Expand All @@ -87,7 +83,7 @@ export function TableColumnHeader<T extends object>({
<th
{...mergeProps(columnHeaderProps, focusProps)}
colSpan={column.colspan}
className={columnHeader}
className={columnHeader({ variant })}
style={{
width: getWidthStyle(column.props.width),
minWidth: getWidthStyle(column.props.minWidth),
Expand Down
Loading

0 comments on commit dbd9076

Please sign in to comment.