Skip to content

Commit

Permalink
Merge pull request #38 from internxt/feat/expot-Table-components-corr…
Browse files Browse the repository at this point in the history
…ectly

[_]: fix/export Table components correctly
  • Loading branch information
xabg2 authored Dec 18, 2024
2 parents 93ba06d + 90b4e39 commit b0d230f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
41 changes: 36 additions & 5 deletions src/components/table/Table.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
import React from 'react';

interface TableProps extends React.HTMLAttributes<HTMLTableElement> {
export interface TableProps extends React.HTMLAttributes<HTMLTableElement> {
children: React.ReactNode;
className?: string;
}

interface TableHeaderProps extends React.HTMLAttributes<HTMLTableSectionElement> {
export interface TableHeaderProps extends React.HTMLAttributes<HTMLTableSectionElement> {
children: React.ReactNode;
className?: string;
}

interface TableBodyProps extends React.HTMLAttributes<HTMLTableSectionElement> {
export interface TableBodyProps extends React.HTMLAttributes<HTMLTableSectionElement> {
children: React.ReactNode;
className?: string;
}

interface TableRowProps extends React.HTMLAttributes<HTMLTableRowElement> {
export interface TableRowProps extends React.HTMLAttributes<HTMLTableRowElement> {
children: React.ReactNode;
className?: string;
}

interface TableCellProps extends React.HTMLAttributes<HTMLTableCellElement> {
export interface TableCellProps extends React.HTMLAttributes<HTMLTableCellElement> {
children: React.ReactNode;
className?: string;
isHeader?: boolean;
}

/**
* Table component
*
* A container for tabular data. Wraps the `<table>` element with a div for additional styling or layout purposes.
* @param {TableProps} props - The props for the table component.
*/
export const Table: React.FC<TableProps> = ({ children, className, ...props }) => (
<div className={className}>
<table className="w-full" {...props}>
Expand All @@ -34,24 +40,49 @@ export const Table: React.FC<TableProps> = ({ children, className, ...props }) =
</div>
);

/**
* TableHeader component
*
* Represents the header section of the table. Wraps the `<thead>` element.
* @param {TableHeaderProps} props - The props for the table header component.
*/
export const TableHeader: React.FC<TableHeaderProps> = ({ children, className, ...props }) => (
<thead className={className} {...props}>
{children}
</thead>
);

/**
* TableBody component
*
* Represents the body section of the table. Wraps the `<tbody>` element.
* @param {TableBodyProps} props - The props for the table body component.
*/
export const TableBody: React.FC<TableBodyProps> = ({ children, className, ...props }) => (
<tbody className={className} {...props}>
{children}
</tbody>
);

/**
* TableRow component
*
* Represents a single row in the table. Wraps the `<tr>` element.
* @param {TableRowProps} props - The props for the table row component.
*/
export const TableRow: React.FC<TableRowProps> = ({ children, className, onClick, ...props }) => (
<tr onClick={onClick} className={className} {...props}>
{children}
</tr>
);

/**
* TableCell component
*
* Represents a single cell in the table, either header (`<th>`) or data (`<td>`).
* @param {TableCellProps} props - The props for the table cell component.
* @param {boolean} [props.isHeader=false] - Determines if the cell is a header (`<th>`).
*/
export const TableCell: React.FC<TableCellProps> = ({ children, className, isHeader = false, onClick, ...props }) => {
const Component = isHeader ? 'th' : 'td';
return (
Expand Down
7 changes: 7 additions & 0 deletions src/components/table/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export { Table } from './Table';
export { TableHeader } from './Table';
export { TableBody } from './Table';
export { TableRow } from './Table';
export { TableCell } from './Table';

export type { TableProps, TableHeaderProps, TableBodyProps, TableRowProps, TableCellProps } from './Table';

0 comments on commit b0d230f

Please sign in to comment.