Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing props and value #1335

Merged
merged 5 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Table/Table.types.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { Key, CSSProperties } from "react";
import type { Key } from "react";
import PropTypes from "prop-types";

export type RowType = unknown;

export type CellInfoType = {
export interface CellInfoType {
cellData: unknown;
column: ColumnType;
row: RowType;
};
}

type ColumnInfoType = {
interface ColumnInfoType {
align?: ColumnAlignment;
label: string;
dataKey?: Key;
width?: string | number;
};
}

type ColumnAlignment = "left" | "right" | "center";

Expand Down
28 changes: 16 additions & 12 deletions src/Table/TableHead.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
// @ts-nocheck
import React from "react";
import styled from "styled-components";
import StyledTh from "./StyledTh";
import { Columns } from "./Table.types";
import type { ColumnType, Columns } from "./Table.types";

type TableHeadProps = {
interface TableHeadProps {
columns: Columns;
compact?: boolean;
sticky?: boolean;
};
}

const StyledHeaderRow = styled.tr(({ theme }) => ({
color: theme.colors.darkGrey,
borderBottom: `1px solid ${theme.colors.lightGrey}`,
}));

const defaultheaderFormatter = ({ label }) => label;
const renderHeaderCellContent = ({ headerFormatter = defaultheaderFormatter, ...column }) => headerFormatter(column);
const defaultheaderFormatter: ColumnType["headerFormatter"] = ({ label }) => label;

const renderHeaderCellContent = ({
headerFormatter = defaultheaderFormatter,
align,
label,
dataKey,
width,
}: ColumnType) => headerFormatter({ align, label, dataKey, width });

Comment on lines +19 to +25
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is possibly a breaking change, but it complies with the type described in Table.types.ts.

const TableHead: React.FC<TableHeadProps> = ({ columns, compact, sticky }) => {
const renderColumns = (allColumns) =>
allColumns.map((column) => (
const TableHead = ({ columns, compact, sticky }: TableHeadProps) => {
const renderColumns = (allColumns: Columns) =>
allColumns.map((column, index) => (
<StyledTh
scope="col"
key={column.dataKey ?? column.key ?? index}
Expand All @@ -38,7 +44,5 @@ const TableHead: React.FC<TableHeadProps> = ({ columns, compact, sticky }) => {
</thead>
);
};
TableHead.defaultProps = {
sticky: false,
};

export default TableHead;
Loading