@segmentify/ui 0.0.24 → 0.0.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app.d.ts +12 -0
- package/dist/components/atoms/table.d.ts +5 -12
- package/dist/components/molecules/base-button.d.ts +7 -21
- package/dist/components/molecules/combobox-field.d.ts +15 -16
- package/dist/components/molecules/confirmation-dialog.d.ts +1 -1
- package/dist/components/molecules/debounced-input.d.ts +11 -3
- package/dist/components/molecules/select-field.d.ts +5 -4
- package/dist/components/organisms/data-table/actions.d.ts +12 -0
- package/dist/components/organisms/data-table/column-visibility.d.ts +7 -0
- package/dist/components/organisms/data-table/content.d.ts +18 -0
- package/dist/components/organisms/data-table/context.d.ts +10 -0
- package/dist/components/organisms/data-table/index.d.ts +16 -0
- package/dist/components/organisms/data-table/pagination.d.ts +6 -0
- package/dist/components/organisms/data-table/root.d.ts +13 -0
- package/dist/components/organisms/data-table/search.d.ts +7 -0
- package/dist/components/organisms/data-table/toolbar.d.ts +7 -0
- package/dist/components/organisms/form-checkbox.d.ts +5 -3
- package/dist/components/organisms/form-combobox.d.ts +5 -5
- package/dist/components/organisms/form-date-picker.d.ts +5 -3
- package/dist/hooks/use-data-table.d.ts +160 -0
- package/dist/index.d.ts +2 -1
- package/dist/mock/actions.d.ts +6 -0
- package/dist/mock/columns.d.ts +9 -0
- package/dist/segmentify-ui.cjs +85 -82
- package/dist/segmentify-ui.js +18468 -16099
- package/dist/ui.css +168 -39
- package/package.json +1 -1
package/dist/app.d.ts
CHANGED
|
@@ -1,2 +1,14 @@
|
|
|
1
|
+
export type Product = {
|
|
2
|
+
id: number;
|
|
3
|
+
title: string;
|
|
4
|
+
description: string;
|
|
5
|
+
price: number;
|
|
6
|
+
discountPercentage: number;
|
|
7
|
+
rating: number;
|
|
8
|
+
stock: number;
|
|
9
|
+
brand: string;
|
|
10
|
+
category: string;
|
|
11
|
+
thumbnail: string;
|
|
12
|
+
};
|
|
1
13
|
declare function App(): import("react/jsx-runtime").JSX.Element;
|
|
2
14
|
export default App;
|
|
@@ -1,17 +1,10 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
declare function Table({ className, ...props }: React.ComponentProps<'table'>): import("react/jsx-runtime").JSX.Element;
|
|
3
|
-
|
|
4
|
-
disableHover?: boolean;
|
|
5
|
-
};
|
|
6
|
-
declare function TableHeader({ className, disableHover, ...props }: TableHeaderProps): import("react/jsx-runtime").JSX.Element;
|
|
7
|
-
declare function TableHead({ className, ...props }: React.ComponentProps<'th'>): import("react/jsx-runtime").JSX.Element;
|
|
3
|
+
declare function TableHeader({ className, ...props }: React.ComponentProps<'thead'>): import("react/jsx-runtime").JSX.Element;
|
|
8
4
|
declare function TableBody({ className, ...props }: React.ComponentProps<'tbody'>): import("react/jsx-runtime").JSX.Element;
|
|
9
|
-
declare function
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
};
|
|
13
|
-
declare function TableRow({ className, disableHover, ...props }: TableRowProps): import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
declare function TableFooter({ className, ...props }: React.ComponentProps<'tfoot'>): import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
declare function TableRow({ className, ...props }: React.ComponentProps<'tr'>): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
declare function TableHead({ className, ...props }: React.ComponentProps<'th'>): import("react/jsx-runtime").JSX.Element;
|
|
14
8
|
declare function TableCell({ className, ...props }: React.ComponentProps<'td'>): import("react/jsx-runtime").JSX.Element;
|
|
15
9
|
declare function TableCaption({ className, ...props }: React.ComponentProps<'caption'>): import("react/jsx-runtime").JSX.Element;
|
|
16
|
-
|
|
17
|
-
export { Table, TableHeader, TableBody, TableHeadRow, TableFooter, TableHead, TableRow, TableCell, TableCaption };
|
|
10
|
+
export { Table, TableHeader, TableBody, TableFooter, TableHead, TableRow, TableCell, TableCaption };
|
|
@@ -1,29 +1,15 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { buttonVariants } from '../../lib/design-variants';
|
|
3
3
|
import { VariantProps } from 'class-variance-authority';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
type?: 'button' | 'submit' | 'reset';
|
|
8
|
-
size?: VariantProps<typeof buttonVariants>['size'];
|
|
9
|
-
variant?: VariantProps<typeof buttonVariants>['variant'];
|
|
4
|
+
declare const BaseButton: React.ForwardRefExoticComponent<Omit<Omit<React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref">, "children"> & {
|
|
5
|
+
size?: VariantProps<typeof buttonVariants>["size"];
|
|
6
|
+
variant?: VariantProps<typeof buttonVariants>["variant"];
|
|
10
7
|
label?: string;
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
isSuffix?: boolean;
|
|
9
|
+
isPrefix?: boolean;
|
|
13
10
|
isLoading?: boolean;
|
|
14
|
-
onClick?: () => void;
|
|
15
11
|
labelClassName?: string;
|
|
16
|
-
|
|
17
|
-
form?: string;
|
|
18
|
-
};
|
|
19
|
-
type IconOnlyProps = BaseProps & {
|
|
20
|
-
isIconOnly: true;
|
|
21
|
-
icon: React.ReactNode;
|
|
22
|
-
};
|
|
23
|
-
type DefaultButtonProps = BaseProps & {
|
|
24
|
-
isIconOnly?: false;
|
|
12
|
+
isIconOnly?: boolean;
|
|
25
13
|
icon?: React.ReactNode;
|
|
26
|
-
}
|
|
27
|
-
type BaseButtonProps = Union.Strict<IconOnlyProps | DefaultButtonProps>;
|
|
28
|
-
declare const BaseButton: ({ icon, type, label, size, variant, suffix, prefix, isLoading, onClick, className, labelClassName, disabled, isIconOnly, form, }: BaseButtonProps) => import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
} & React.RefAttributes<HTMLButtonElement>>;
|
|
29
15
|
export { BaseButton };
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import type { SelectItemProps } from '../../lib/types';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
type TriggerProps = {
|
|
3
|
+
trigger: React.ReactNode;
|
|
4
|
+
triggerPlaceholder?: never;
|
|
5
|
+
} | {
|
|
6
|
+
trigger?: never;
|
|
7
|
+
triggerPlaceholder: string;
|
|
8
|
+
};
|
|
9
|
+
type Props = TriggerProps & {
|
|
4
10
|
isDisabled?: boolean;
|
|
5
11
|
options: SelectItemProps[];
|
|
6
|
-
triggerPlaceholder: string;
|
|
7
12
|
isFormControlWrapper?: boolean;
|
|
8
13
|
avoidCollisions?: boolean;
|
|
9
14
|
contentClassName?: string;
|
|
@@ -12,21 +17,15 @@ type BaseProps = {
|
|
|
12
17
|
containerClassName?: string;
|
|
13
18
|
contentListClassName?: string;
|
|
14
19
|
closeOnSelect?: boolean;
|
|
20
|
+
align?: 'start' | 'center' | 'end';
|
|
15
21
|
label?: string;
|
|
16
|
-
onInputChange
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
value: string[];
|
|
22
|
+
onInputChange?: (inputValue: string) => void;
|
|
23
|
+
clearable?: boolean;
|
|
24
|
+
multiple?: boolean;
|
|
25
|
+
value: string | string[];
|
|
26
|
+
onValueChange: (value: string | string[]) => void;
|
|
22
27
|
hasAllOption?: boolean;
|
|
23
28
|
allOptionLabel?: string;
|
|
24
|
-
handleSelectAll: (value: string | string[], availableOptions: SelectItemProps[]) => void;
|
|
25
|
-
};
|
|
26
|
-
type SingleSelectProps = BaseProps & {
|
|
27
|
-
isMultiSelect?: false;
|
|
28
|
-
value: string;
|
|
29
29
|
};
|
|
30
|
-
|
|
31
|
-
export declare const ComboboxField: ({ value, isDisabled, hasAllOption, isMultiSelect, options, allOptionLabel, triggerPlaceholder, isFormControlWrapper, avoidCollisions, contentClassName, inputPlaceholder, emptyMessage, containerClassName, contentListClassName, closeOnSelect, label, handleSelectItem, handleSelectAll, onInputChange, }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
30
|
+
export declare const ComboboxField: ({ value, isDisabled, hasAllOption, multiple, options, allOptionLabel, triggerPlaceholder, trigger, isFormControlWrapper, avoidCollisions, align, contentClassName, inputPlaceholder, emptyMessage, containerClassName, contentListClassName, closeOnSelect, label, onValueChange, onInputChange, clearable, }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
32
31
|
export {};
|
|
@@ -1,11 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import type { O } from 'ts-toolbelt';
|
|
2
|
+
interface BaseSearchInputProps {
|
|
3
3
|
value: string;
|
|
4
4
|
onChange: (value: string) => void;
|
|
5
5
|
placeholder: string;
|
|
6
6
|
className?: string;
|
|
7
|
-
label?: string;
|
|
8
7
|
inputClassName?: string;
|
|
9
8
|
}
|
|
9
|
+
type WithLabelProps = O.Merge<BaseSearchInputProps, {
|
|
10
|
+
label: string;
|
|
11
|
+
name: string;
|
|
12
|
+
}>;
|
|
13
|
+
type WithoutLabelProps = O.Merge<BaseSearchInputProps, {
|
|
14
|
+
label?: undefined;
|
|
15
|
+
name?: string;
|
|
16
|
+
}>;
|
|
17
|
+
type SearchInputProps = WithLabelProps | WithoutLabelProps;
|
|
10
18
|
declare function DebouncedInput({ value, onChange, className, inputClassName, name, placeholder, label }: SearchInputProps): import("react/jsx-runtime").JSX.Element;
|
|
11
19
|
export { DebouncedInput };
|
|
@@ -4,14 +4,15 @@ import type { SelectItemProps } from '../../lib/types';
|
|
|
4
4
|
interface SelectFieldProps extends React.ComponentProps<typeof Select> {
|
|
5
5
|
options: SelectItemProps[];
|
|
6
6
|
placeholder: string;
|
|
7
|
-
triggerClassName: string;
|
|
8
|
-
containerClassName: string;
|
|
9
7
|
onChange: (value: string) => void;
|
|
10
8
|
value: string;
|
|
11
|
-
label
|
|
9
|
+
label?: string;
|
|
10
|
+
labelClassName?: string;
|
|
11
|
+
triggerClassName?: string;
|
|
12
|
+
containerClassName?: string;
|
|
12
13
|
isPortal?: boolean;
|
|
13
14
|
hasFormControlWrapper?: boolean;
|
|
14
15
|
selectContentClassName?: string;
|
|
15
16
|
}
|
|
16
|
-
export declare const SelectField: ({ options, placeholder, hasFormControlWrapper, selectContentClassName, onChange, value, label, triggerClassName, containerClassName, isPortal, ...props }: SelectFieldProps) => import("react/jsx-runtime").JSX.Element;
|
|
17
|
+
export declare const SelectField: ({ options, placeholder, hasFormControlWrapper, selectContentClassName, onChange, value, label, triggerClassName, labelClassName, containerClassName, isPortal, ...props }: SelectFieldProps) => import("react/jsx-runtime").JSX.Element;
|
|
17
18
|
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
export interface ActionItem {
|
|
3
|
+
label: string;
|
|
4
|
+
icon?: ReactNode;
|
|
5
|
+
onClick: () => void;
|
|
6
|
+
variant?: 'default' | 'destructive';
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface ActionsProps {
|
|
10
|
+
actions: ActionItem[];
|
|
11
|
+
}
|
|
12
|
+
export declare const Actions: ({ actions }: ActionsProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
interface ColumnVisibilityProps {
|
|
2
|
+
inputPlaceholder?: string;
|
|
3
|
+
emptyMessage?: string;
|
|
4
|
+
allOptionLabel?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function ColumnVisibility({ inputPlaceholder, emptyMessage, allOptionLabel, }: ColumnVisibilityProps): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { type Row } from '@tanstack/react-table';
|
|
3
|
+
export interface RenderRowSubComponentProps<TData = unknown> {
|
|
4
|
+
row: Row<TData>;
|
|
5
|
+
}
|
|
6
|
+
interface ContentProps {
|
|
7
|
+
className?: string;
|
|
8
|
+
loadingContent?: ReactNode;
|
|
9
|
+
emptyContent?: ReactNode;
|
|
10
|
+
/**
|
|
11
|
+
* Render a sub-component below a row when it's expanded.
|
|
12
|
+
* The sub-component can handle its own data fetching and render sub-rows.
|
|
13
|
+
* @example ({ row }) => <SubRowAsync row={row} />
|
|
14
|
+
*/
|
|
15
|
+
renderRowSubComponent?: (props: RenderRowSubComponentProps) => ReactNode;
|
|
16
|
+
}
|
|
17
|
+
export declare function Content({ className, loadingContent, emptyContent, renderRowSubComponent, }: ContentProps): import("react/jsx-runtime").JSX.Element;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Table as TanstackTable } from '@tanstack/react-table';
|
|
2
|
+
export interface DataTableContextValue<TData> {
|
|
3
|
+
table: TanstackTable<TData>;
|
|
4
|
+
isLoading: boolean;
|
|
5
|
+
globalFilter: string;
|
|
6
|
+
onGlobalFilterChange: (value: string) => void;
|
|
7
|
+
totalCount?: number;
|
|
8
|
+
}
|
|
9
|
+
export declare const DataTableContext: import("react").Context<DataTableContextValue<unknown> | null>;
|
|
10
|
+
export declare function useDataTableContext<TData>(): DataTableContextValue<TData>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Root } from './root';
|
|
2
|
+
import { Toolbar } from './toolbar';
|
|
3
|
+
import { Search } from './search';
|
|
4
|
+
import { ColumnVisibility } from './column-visibility';
|
|
5
|
+
import { Content } from './content';
|
|
6
|
+
export type { ActionItem, ActionsProps } from './actions';
|
|
7
|
+
export type { RenderRowSubComponentProps } from './content';
|
|
8
|
+
export declare const DataTable: {
|
|
9
|
+
Root: typeof Root;
|
|
10
|
+
Toolbar: typeof Toolbar;
|
|
11
|
+
Search: typeof Search;
|
|
12
|
+
ColumnVisibility: typeof ColumnVisibility;
|
|
13
|
+
Content: typeof Content;
|
|
14
|
+
Pagination: ({ showSelectedCount, showPaginationInfo, className }: import("./pagination").PaginationProps) => import("react/jsx-runtime").JSX.Element;
|
|
15
|
+
Actions: ({ actions }: import("./actions").ActionsProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
16
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export interface PaginationProps {
|
|
2
|
+
showSelectedCount?: boolean;
|
|
3
|
+
showPaginationInfo?: boolean;
|
|
4
|
+
className?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const Pagination: ({ showSelectedCount, showPaginationInfo, className }: PaginationProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { type Table as TanstackTable } from '@tanstack/react-table';
|
|
3
|
+
interface RootProps<TData> {
|
|
4
|
+
table: TanstackTable<TData>;
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
isLoading?: boolean;
|
|
7
|
+
globalFilter?: string;
|
|
8
|
+
onGlobalFilterChange?: (value: string) => void;
|
|
9
|
+
totalCount?: number;
|
|
10
|
+
className?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function Root<TData>({ table, children, isLoading, globalFilter, onGlobalFilterChange, totalCount, className, }: RootProps<TData>): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export {};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
type
|
|
2
|
-
|
|
1
|
+
import { type Control, type FieldValues, type Path } from 'react-hook-form';
|
|
2
|
+
type FormCheckboxProps<TFieldValues extends FieldValues = FieldValues> = {
|
|
3
|
+
name: Path<TFieldValues>;
|
|
4
|
+
control?: Control<TFieldValues>;
|
|
3
5
|
label: string;
|
|
4
6
|
formClassName?: string;
|
|
5
7
|
};
|
|
6
|
-
export declare const FormCheckbox: ({ name, formClassName, ...props }:
|
|
8
|
+
export declare const FormCheckbox: <TFieldValues extends FieldValues = FieldValues>({ name, control, formClassName, ...props }: FormCheckboxProps<TFieldValues>) => import("react/jsx-runtime").JSX.Element;
|
|
7
9
|
export {};
|
|
@@ -2,25 +2,25 @@ import { type Control, type FieldValues, type Path } from 'react-hook-form';
|
|
|
2
2
|
import type { SelectItemProps } from '../../lib/types';
|
|
3
3
|
type FormComboboxProps<TFieldValues extends FieldValues = FieldValues> = {
|
|
4
4
|
name: Path<TFieldValues>;
|
|
5
|
-
control?: Control<TFieldValues>;
|
|
6
5
|
label: string;
|
|
7
6
|
triggerPlaceholder: string;
|
|
8
7
|
inputPlaceholder: string;
|
|
9
8
|
options: SelectItemProps[];
|
|
10
9
|
description?: string;
|
|
11
|
-
|
|
10
|
+
multiple?: boolean;
|
|
12
11
|
emptyMessage: string;
|
|
13
12
|
containerClassName?: string;
|
|
14
13
|
contentClassName?: string;
|
|
15
14
|
contentListClassName?: string;
|
|
16
15
|
avoidCollisions?: boolean;
|
|
17
|
-
|
|
16
|
+
clearable?: boolean;
|
|
18
17
|
hasAllOption?: boolean;
|
|
19
18
|
allOptionLabel?: string;
|
|
20
19
|
closeOnSelect?: boolean;
|
|
21
|
-
onInputChange
|
|
20
|
+
onInputChange?: (inputValue: string) => void;
|
|
22
21
|
isDisabled?: boolean;
|
|
23
22
|
tooltipContent?: string;
|
|
23
|
+
control?: Control<TFieldValues>;
|
|
24
24
|
};
|
|
25
|
-
export declare const FormCombobox: <TFieldValues extends FieldValues = FieldValues>({ name,
|
|
25
|
+
export declare const FormCombobox: <TFieldValues extends FieldValues = FieldValues>({ name, label, triggerPlaceholder, inputPlaceholder, options, description, multiple, emptyMessage, containerClassName, contentClassName, contentListClassName, avoidCollisions, clearable, hasAllOption, allOptionLabel, closeOnSelect, onInputChange, isDisabled, tooltipContent, control, }: FormComboboxProps<TFieldValues>) => import("react/jsx-runtime").JSX.Element;
|
|
26
26
|
export {};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { type Control, type FieldValues, type Path } from 'react-hook-form';
|
|
2
|
+
export interface FormDatePickerProps<TFieldValues extends FieldValues = FieldValues> {
|
|
3
|
+
name: Path<TFieldValues>;
|
|
4
|
+
control?: Control<TFieldValues>;
|
|
3
5
|
disabledCondition?: boolean | ((date: Date) => boolean);
|
|
4
6
|
label?: string;
|
|
5
7
|
placeholder?: string;
|
|
@@ -8,4 +10,4 @@ export interface FormDatePickerProps {
|
|
|
8
10
|
triggerClassName?: string;
|
|
9
11
|
showErrorPlaceholder?: boolean;
|
|
10
12
|
}
|
|
11
|
-
export declare const FormDatePicker: ({ name, disabledCondition, label, placeholder, description, containerClassName, triggerClassName, showErrorPlaceholder, }: FormDatePickerProps) => import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export declare const FormDatePicker: <TFieldValues extends FieldValues = FieldValues>({ name, control, disabledCondition, label, placeholder, description, containerClassName, triggerClassName, showErrorPlaceholder, }: FormDatePickerProps<TFieldValues>) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { type ColumnDef, type ColumnFiltersState, type SortingState, type VisibilityState, type PaginationState, type RowSelectionState, type ColumnPinningState, type ExpandedState, type Table } from '@tanstack/react-table';
|
|
2
|
+
import { type UseQueryOptions } from '@tanstack/react-query';
|
|
3
|
+
export interface FetcherParams {
|
|
4
|
+
pageIndex: number;
|
|
5
|
+
pageSize: number;
|
|
6
|
+
sorting: SortingState;
|
|
7
|
+
columnFilters: ColumnFiltersState;
|
|
8
|
+
globalFilter: string;
|
|
9
|
+
}
|
|
10
|
+
export interface FetcherResponse<TData> {
|
|
11
|
+
data: TData[];
|
|
12
|
+
totalCount?: number;
|
|
13
|
+
}
|
|
14
|
+
export interface UseDataTableOptions<TData> {
|
|
15
|
+
/**
|
|
16
|
+
* Unique key for the query cache
|
|
17
|
+
* @required
|
|
18
|
+
*/
|
|
19
|
+
queryKey: string;
|
|
20
|
+
/**
|
|
21
|
+
* Column definitions for the table
|
|
22
|
+
*/
|
|
23
|
+
columns: ColumnDef<TData>[];
|
|
24
|
+
/**
|
|
25
|
+
* Fetcher function to load data
|
|
26
|
+
* Receives fetch params and should return data + optional totalCount
|
|
27
|
+
*/
|
|
28
|
+
fetcher: (params: FetcherParams) => Promise<FetcherResponse<TData>>;
|
|
29
|
+
/**
|
|
30
|
+
* Initial page size
|
|
31
|
+
* @default 10
|
|
32
|
+
*/
|
|
33
|
+
initialPageSize?: number;
|
|
34
|
+
/**
|
|
35
|
+
* Initial sorting state
|
|
36
|
+
*/
|
|
37
|
+
initialSorting?: SortingState;
|
|
38
|
+
/**
|
|
39
|
+
* Initial column visibility
|
|
40
|
+
*/
|
|
41
|
+
initialColumnVisibility?: VisibilityState;
|
|
42
|
+
/**
|
|
43
|
+
* Initial column pinning state
|
|
44
|
+
* @example { left: ['select'], right: ['actions'] }
|
|
45
|
+
*/
|
|
46
|
+
initialColumnPinning?: ColumnPinningState;
|
|
47
|
+
/**
|
|
48
|
+
* Whether pagination is handled manually (server-side)
|
|
49
|
+
* @default false
|
|
50
|
+
*/
|
|
51
|
+
manualPagination?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Whether sorting is handled manually (server-side)
|
|
54
|
+
* @default false
|
|
55
|
+
*/
|
|
56
|
+
manualSorting?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Whether filtering is handled manually (server-side)
|
|
59
|
+
* @default false
|
|
60
|
+
*/
|
|
61
|
+
manualFiltering?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Function to get sub-rows from a row (for expandable rows)
|
|
64
|
+
* @example (row) => row.subRows
|
|
65
|
+
*/
|
|
66
|
+
getSubRows?: (row: TData) => TData[] | undefined;
|
|
67
|
+
/**
|
|
68
|
+
* Function to determine if a row can be expanded.
|
|
69
|
+
* Set to `() => true` to allow all rows to expand (useful for lazy-loaded sub-components).
|
|
70
|
+
* @example () => true
|
|
71
|
+
* @example (row) => row.original.hasDetails
|
|
72
|
+
*/
|
|
73
|
+
getRowCanExpand?: (row: {
|
|
74
|
+
original: TData;
|
|
75
|
+
}) => boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Additional react-query options
|
|
78
|
+
* Allows customizing staleTime, gcTime, refetchInterval, etc.
|
|
79
|
+
*/
|
|
80
|
+
queryOptions?: Omit<UseQueryOptions<FetcherResponse<TData>, Error>, 'queryKey' | 'queryFn'>;
|
|
81
|
+
}
|
|
82
|
+
export interface UseDataTableReturn<TData> {
|
|
83
|
+
/**
|
|
84
|
+
* The table instance from @tanstack/react-table
|
|
85
|
+
*/
|
|
86
|
+
table: Table<TData>;
|
|
87
|
+
/**
|
|
88
|
+
* The current data array
|
|
89
|
+
*/
|
|
90
|
+
data: TData[];
|
|
91
|
+
/**
|
|
92
|
+
* Whether the initial data is loading (no data yet)
|
|
93
|
+
*/
|
|
94
|
+
isLoading: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Whether data is being fetched (including background refetches)
|
|
97
|
+
*/
|
|
98
|
+
isFetching: boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Whether a refetch is in progress
|
|
101
|
+
*/
|
|
102
|
+
isRefetching: boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Error if the fetch failed
|
|
105
|
+
*/
|
|
106
|
+
error: Error | null;
|
|
107
|
+
/**
|
|
108
|
+
* Total count of items (for pagination)
|
|
109
|
+
*/
|
|
110
|
+
totalCount: number;
|
|
111
|
+
/**
|
|
112
|
+
* Refetch the data
|
|
113
|
+
*/
|
|
114
|
+
refetch: () => void;
|
|
115
|
+
/**
|
|
116
|
+
* Current global filter value
|
|
117
|
+
*/
|
|
118
|
+
globalFilter: string;
|
|
119
|
+
/**
|
|
120
|
+
* Set the global filter
|
|
121
|
+
*/
|
|
122
|
+
setGlobalFilter: (value: string) => void;
|
|
123
|
+
/**
|
|
124
|
+
* Current sorting state
|
|
125
|
+
*/
|
|
126
|
+
sorting: SortingState;
|
|
127
|
+
/**
|
|
128
|
+
* Current pagination state
|
|
129
|
+
*/
|
|
130
|
+
pagination: PaginationState;
|
|
131
|
+
/**
|
|
132
|
+
* Current column filters
|
|
133
|
+
*/
|
|
134
|
+
columnFilters: ColumnFiltersState;
|
|
135
|
+
/**
|
|
136
|
+
* Current column visibility
|
|
137
|
+
*/
|
|
138
|
+
columnVisibility: VisibilityState;
|
|
139
|
+
/**
|
|
140
|
+
* Current row selection
|
|
141
|
+
*/
|
|
142
|
+
rowSelection: RowSelectionState;
|
|
143
|
+
/**
|
|
144
|
+
* Current column pinning state
|
|
145
|
+
*/
|
|
146
|
+
columnPinning: ColumnPinningState;
|
|
147
|
+
/**
|
|
148
|
+
* Current expanded state
|
|
149
|
+
*/
|
|
150
|
+
expanded: ExpandedState;
|
|
151
|
+
/**
|
|
152
|
+
* Whether the query is in success state
|
|
153
|
+
*/
|
|
154
|
+
isSuccess: boolean;
|
|
155
|
+
/**
|
|
156
|
+
* Whether the query is in error state
|
|
157
|
+
*/
|
|
158
|
+
isError: boolean;
|
|
159
|
+
}
|
|
160
|
+
export declare function useDataTable<TData>({ queryKey, columns, fetcher, initialPageSize, initialSorting, initialColumnVisibility, initialColumnPinning, manualPagination, manualSorting, manualFiltering, getSubRows, getRowCanExpand, queryOptions, }: UseDataTableOptions<TData>): UseDataTableReturn<TData>;
|
package/dist/index.d.ts
CHANGED
|
@@ -66,10 +66,11 @@ export { Spinner } from './components/atoms/spinner';
|
|
|
66
66
|
export { Switch } from './components/atoms/switch';
|
|
67
67
|
export { SwitchField } from './components/molecules/switch-field';
|
|
68
68
|
export { Tabs, TabsList, TabsTrigger, TabsContent } from './components/atoms/tabs';
|
|
69
|
-
export { Table, TableHeader, TableBody,
|
|
69
|
+
export { Table, TableHeader, TableBody, TableFooter, TableHead, TableRow, TableCell, TableCaption, } from './components/atoms/table';
|
|
70
70
|
export { Textarea } from './components/atoms/textarea';
|
|
71
71
|
export { TextAreaField } from './components/molecules/textarea-field';
|
|
72
72
|
export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider } from './components/atoms/tooltip';
|
|
73
73
|
export { TooltipField } from './components/molecules/tooltip-field';
|
|
74
74
|
export { QuillEditor } from './components/atoms/quill-editor';
|
|
75
|
+
export { useDataTable, type UseDataTableOptions, type UseDataTableReturn, type FetcherParams, type FetcherResponse, } from './hooks/use-data-table';
|
|
75
76
|
export { cn } from './lib/utils';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ColumnDef } from '@tanstack/react-table';
|
|
2
|
+
import { Product } from '../app';
|
|
3
|
+
import { type ReactNode } from 'react';
|
|
4
|
+
export type ColumnDefWithSubCell<TData> = ColumnDef<TData> & {
|
|
5
|
+
meta?: {
|
|
6
|
+
subCell?: (data: TData) => ReactNode;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export declare const columns: ColumnDefWithSubCell<Product>[];
|