@douglasneuroinformatics/libui 4.9.1 → 5.0.1
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/components.d.ts +5 -48
- package/dist/components.js +1139 -725
- package/dist/components.js.map +1 -1
- package/dist/hooks.d.ts +4 -2
- package/dist/{types-9zYgx7C8.d.ts → types-CQ7qbFhC.d.ts} +57 -1
- package/package.json +3 -2
- package/src/components/DataTable/DataTable.stories.tsx +207 -37
- package/src/components/DataTable/DataTable.tsx +22 -279
- package/src/components/DataTable/DataTableBody.tsx +69 -0
- package/src/components/DataTable/DataTableContent.tsx +36 -0
- package/src/components/DataTable/DataTableControls.tsx +55 -0
- package/src/components/DataTable/DataTableEmptyState.tsx +25 -0
- package/src/components/DataTable/DataTableHead.tsx +58 -0
- package/src/components/DataTable/DataTablePagination.tsx +62 -0
- package/src/components/DataTable/DataTableRowActionCell.tsx +67 -0
- package/src/components/DataTable/__tests__/DataTable.spec.tsx +60 -0
- package/src/components/DataTable/constants.ts +7 -0
- package/src/components/DataTable/context.ts +5 -0
- package/src/components/DataTable/hooks.ts +60 -0
- package/src/components/DataTable/store.ts +203 -0
- package/src/components/DataTable/types.ts +99 -0
- package/src/components/DataTable/utils.tsx +138 -0
- package/src/components/Form/ErrorMessage.tsx +29 -7
- package/src/components/Form/Form.tsx +5 -1
- package/src/hooks/useDestructiveAction/useDestructiveActionStore.test.ts +2 -7
- package/src/hooks/useNotificationsStore/useNotificationsStore.test.ts +1 -8
- package/src/testing/setup-tests.ts +1 -3
- package/src/components/DataTable/DestructiveActionDialog.tsx +0 -67
- package/src/components/DataTable/RowActionsDropdown.tsx +0 -64
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-misused-promises */
|
|
2
|
-
|
|
3
|
-
import type React from 'react';
|
|
4
|
-
|
|
5
|
-
import type { Promisable } from 'type-fest';
|
|
6
|
-
|
|
7
|
-
import { useTranslation } from '@/hooks';
|
|
8
|
-
|
|
9
|
-
import { Button } from '../Button';
|
|
10
|
-
import { Dialog } from '../Dialog';
|
|
11
|
-
|
|
12
|
-
export type DestructiveActionPending = (() => Promisable<void>) | null;
|
|
13
|
-
|
|
14
|
-
export const DestructiveActionDialog: React.FC<{
|
|
15
|
-
destructiveActionPending: DestructiveActionPending;
|
|
16
|
-
setDestructiveActionPending: React.Dispatch<React.SetStateAction<DestructiveActionPending>>;
|
|
17
|
-
}> = ({ destructiveActionPending, setDestructiveActionPending }) => {
|
|
18
|
-
const { t } = useTranslation();
|
|
19
|
-
return (
|
|
20
|
-
<Dialog
|
|
21
|
-
open={destructiveActionPending !== null}
|
|
22
|
-
onOpenChange={(open) => {
|
|
23
|
-
if (!open) {
|
|
24
|
-
setDestructiveActionPending(null);
|
|
25
|
-
}
|
|
26
|
-
}}
|
|
27
|
-
>
|
|
28
|
-
<Dialog.Content onOpenAutoFocus={(event) => event.preventDefault()}>
|
|
29
|
-
<Dialog.Header>
|
|
30
|
-
<Dialog.Title>
|
|
31
|
-
{t({
|
|
32
|
-
en: 'Confirm Action',
|
|
33
|
-
fr: "Confirmer l'action"
|
|
34
|
-
})}
|
|
35
|
-
</Dialog.Title>
|
|
36
|
-
<Dialog.Description>
|
|
37
|
-
{t({
|
|
38
|
-
en: 'This action cannot be reversed. Please confirm that you would like to continue.',
|
|
39
|
-
fr: 'Cette action ne peut être inversée. Veuillez confirmer que vous souhaitez poursuivre.'
|
|
40
|
-
})}
|
|
41
|
-
</Dialog.Description>
|
|
42
|
-
</Dialog.Header>
|
|
43
|
-
<Dialog.Footer>
|
|
44
|
-
<Button
|
|
45
|
-
className="min-w-16"
|
|
46
|
-
type="button"
|
|
47
|
-
variant="danger"
|
|
48
|
-
onClick={async () => {
|
|
49
|
-
await destructiveActionPending?.();
|
|
50
|
-
setDestructiveActionPending(null);
|
|
51
|
-
}}
|
|
52
|
-
>
|
|
53
|
-
{t('libui.yes')}
|
|
54
|
-
</Button>
|
|
55
|
-
<Button
|
|
56
|
-
className="min-w-16"
|
|
57
|
-
type="button"
|
|
58
|
-
variant="primary"
|
|
59
|
-
onClick={() => setDestructiveActionPending(null)}
|
|
60
|
-
>
|
|
61
|
-
{t('libui.no')}
|
|
62
|
-
</Button>
|
|
63
|
-
</Dialog.Footer>
|
|
64
|
-
</Dialog.Content>
|
|
65
|
-
</Dialog>
|
|
66
|
-
);
|
|
67
|
-
};
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import type React from 'react';
|
|
2
|
-
|
|
3
|
-
import type { Row } from '@tanstack/react-table';
|
|
4
|
-
import { MoreHorizontalIcon } from 'lucide-react';
|
|
5
|
-
import type { Promisable } from 'type-fest';
|
|
6
|
-
|
|
7
|
-
import { useTranslation } from '@/hooks';
|
|
8
|
-
|
|
9
|
-
import { Button } from '../Button';
|
|
10
|
-
import { DropdownMenu } from '../DropdownMenu';
|
|
11
|
-
|
|
12
|
-
import type { DestructiveActionPending } from './DestructiveActionDialog';
|
|
13
|
-
|
|
14
|
-
export type RowAction<TData extends { [key: string]: unknown }> = {
|
|
15
|
-
destructive?: boolean;
|
|
16
|
-
label: string;
|
|
17
|
-
onSelect: (row: TData) => Promisable<void>;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export const RowActionsDropdown = <TData extends { [key: string]: unknown }>({
|
|
21
|
-
row,
|
|
22
|
-
rowActions,
|
|
23
|
-
setDestructiveActionPending
|
|
24
|
-
}: {
|
|
25
|
-
row: Row<TData>;
|
|
26
|
-
rowActions: RowAction<TData>[];
|
|
27
|
-
setDestructiveActionPending: React.Dispatch<React.SetStateAction<DestructiveActionPending>>;
|
|
28
|
-
}) => {
|
|
29
|
-
const { t } = useTranslation();
|
|
30
|
-
return (
|
|
31
|
-
<div className="flex w-full justify-end">
|
|
32
|
-
<DropdownMenu>
|
|
33
|
-
<DropdownMenu.Trigger asChild>
|
|
34
|
-
<Button className="-m-1.5" size="icon" variant="ghost">
|
|
35
|
-
<MoreHorizontalIcon className="h-4 w-4" />
|
|
36
|
-
</Button>
|
|
37
|
-
</DropdownMenu.Trigger>
|
|
38
|
-
<DropdownMenu.Content align="end">
|
|
39
|
-
<DropdownMenu.Label>
|
|
40
|
-
{t({
|
|
41
|
-
en: 'Actions',
|
|
42
|
-
fr: 'Actions'
|
|
43
|
-
})}
|
|
44
|
-
</DropdownMenu.Label>
|
|
45
|
-
{rowActions.map(({ destructive, label, onSelect }, i) => (
|
|
46
|
-
<DropdownMenu.Item
|
|
47
|
-
className={destructive ? 'text-destructive' : undefined}
|
|
48
|
-
key={i}
|
|
49
|
-
onSelect={() => {
|
|
50
|
-
if (destructive) {
|
|
51
|
-
setDestructiveActionPending(() => () => void onSelect(row.original));
|
|
52
|
-
} else {
|
|
53
|
-
void onSelect(row.original);
|
|
54
|
-
}
|
|
55
|
-
}}
|
|
56
|
-
>
|
|
57
|
-
{label}
|
|
58
|
-
</DropdownMenu.Item>
|
|
59
|
-
))}
|
|
60
|
-
</DropdownMenu.Content>
|
|
61
|
-
</DropdownMenu>
|
|
62
|
-
</div>
|
|
63
|
-
);
|
|
64
|
-
};
|