Skip to content

Commit

Permalink
Resolve tanstack dependency for DataTable (#1018)
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfheij-sil authored Jul 19, 2024
2 parents 224fa5f + f45b2a2 commit 922bd6a
Show file tree
Hide file tree
Showing 9 changed files with 628 additions and 596 deletions.
295 changes: 149 additions & 146 deletions lib/platform-bible-react/dist/index.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/platform-bible-react/dist/index.cjs.map

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions lib/platform-bible-react/dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as SelectPrimitive from '@radix-ui/react-select';
import * as SliderPrimitive from '@radix-ui/react-slider';
import * as SwitchPrimitives from '@radix-ui/react-switch';
import * as TabsPrimitive from '@radix-ui/react-tabs';
import { ColumnDef, Row, Table as tsTable } from '@tanstack/react-table';
import { ColumnDef as TSColumnDef, Row as TSRow, SortDirection as TSSortDirection, Table as TSTable } from '@tanstack/react-table';
import { VariantProps } from 'class-variance-authority';
import React$1 from 'react';
import { ChangeEvent, ChangeEventHandler, FocusEventHandler, MouseEvent as MouseEvent$1, MouseEventHandler, MutableRefObject, PropsWithChildren, ReactNode, SyntheticEvent } from 'react';
Expand Down Expand Up @@ -154,13 +154,17 @@ export type BookChapterControlProps = {
handleSubmit: (scrRef: ScriptureReference) => void;
};
export declare function BookChapterControl({ scrRef, handleSubmit }: BookChapterControlProps): import("react/jsx-runtime").JSX.Element;
export type ColumnDef<TData, TValue = unknown> = TSColumnDef<TData, TValue>;
export type RowContents<TData> = TSRow<TData>;
export type TableContents<TData> = TSTable<TData>;
export type SortDirection = TSSortDirection;
export interface DataTableProps<TData, TValue> {
columns: ColumnDef<TData, TValue>[];
data: TData[];
enablePagination?: boolean;
showPaginationControls?: boolean;
showColumnVisibilityControls?: boolean;
onRowClickHandler?: (row: Row<TData>, table: tsTable<TData>) => void;
onRowClickHandler?: (row: RowContents<TData>, table: TableContents<TData>) => void;
}
export declare function DataTable<TData, TValue>({ columns, data, enablePagination, showPaginationControls, showColumnVisibilityControls, onRowClickHandler, }: DataTableProps<TData, TValue>): import("react/jsx-runtime").JSX.Element;
export declare const buttonVariants: (props?: ({
Expand Down
873 changes: 438 additions & 435 deletions lib/platform-bible-react/dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/platform-bible-react/dist/index.js.map

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { useState } from 'react';

import {
ColumnDef,
ColumnDef as TSColumnDef,
ColumnFiltersState,
Row,
SortingState,
VisibilityState,
flexRender,
getCoreRowModel,
getFilteredRowModel,
getPaginationRowModel,
getSortedRowModel,
Row as TSRow,
SortDirection as TSSortDirection,
SortingState,
Table as TSTable,
useReactTable,
Table as tsTable,
VisibilityState,
} from '@tanstack/react-table';

import {
Expand All @@ -27,13 +28,18 @@ import { Button } from '@/components/shadcn-ui/button';
import DataTablePagination from './data-table-pagination.component';
import DataTableViewOptions from './data-table-column-toggle.component';

export type ColumnDef<TData, TValue = unknown> = TSColumnDef<TData, TValue>;
export type RowContents<TData> = TSRow<TData>;
export type TableContents<TData> = TSTable<TData>;
export type SortDirection = TSSortDirection;

interface DataTableProps<TData, TValue> {
columns: ColumnDef<TData, TValue>[];
data: TData[];
enablePagination?: boolean;
showPaginationControls?: boolean;
showColumnVisibilityControls?: boolean;
onRowClickHandler?: (row: Row<TData>, table: tsTable<TData>) => void;
onRowClickHandler?: (row: RowContents<TData>, table: TableContents<TData>) => void;
}

function DataTable<TData, TValue>({
Expand Down Expand Up @@ -71,7 +77,7 @@ function DataTable<TData, TValue>({
return (
<div>
{showColumnVisibilityControls && <DataTableViewOptions table={table} />}
<div className="pr-twp">
<div className="pr-twp pr-font-sans">
<Table>
<TableHeader>
{table.getHeaderGroups().map((headerGroup) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ import {
CircleXIcon,
CircleHelpIcon,
} from 'lucide-react';
import { ColumnDef, Row, SortDirection, Table } from '@tanstack/react-table';
import { LanguageStrings } from 'platform-bible-utils';
import { Button } from '@/components/shadcn-ui/button';
import DataTable from '@/components/advanced-components/data-table/data-table.component';
import DataTable, {
ColumnDef,
RowContents,
SortDirection,
TableContents,
} from '@/components/advanced-components/data-table/data-table.component';

export type Status = true | false | undefined;

Expand Down Expand Up @@ -160,7 +164,10 @@ function InventoryDataTable({
const countLabel = localizedStrings['%webView_inventory_table_header_count%'];
const statusLabel = localizedStrings['%webView_inventory_table_header_status%'];

const rowClickHandler = (row: Row<CharacterData>, table: Table<CharacterData>) => {
const rowClickHandler = (
row: RowContents<CharacterData>,
table: TableContents<CharacterData>,
) => {
table.toggleAllRowsSelected(false); // this is pretty hacky, and also prevents us from selecting multiple rows
row.toggleSelected(undefined);

Expand Down
6 changes: 6 additions & 0 deletions lib/platform-bible-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import './index.css';
// Components and Types
export { default as BookChapterControl } from './components/advanced-components/book-chapter-control/book-chapter-control.component';
export { default as DataTable } from './components/advanced-components/data-table/data-table.component';
export type {
ColumnDef,
RowContents,
SortDirection,
TableContents,
} from './components/advanced-components/data-table/data-table.component';

export { Button, type ButtonProps, buttonVariants } from './components/shadcn-ui/button';
export { default as ChapterRangeSelector } from './components/chapter-range-selector.component';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { ColumnDef, SortDirection } from '@tanstack/react-table';
import {
ColumnDef,
SortDirection,
} from '@/components/advanced-components/data-table/data-table.component';
import { Button } from '../../..';

type MyDataType = {
Expand Down

0 comments on commit 922bd6a

Please sign in to comment.