@g4rcez/components 4.1.1 → 4.1.3
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/core/button.d.ts +77 -0
- package/dist/components/core/button.d.ts.map +1 -0
- package/dist/components/core/button.jsx +79 -0
- package/dist/components/core/heading.d.ts +3 -0
- package/dist/components/core/heading.d.ts.map +1 -0
- package/dist/components/core/heading.jsx +4 -0
- package/dist/components/core/polymorph.d.ts +10 -0
- package/dist/components/core/polymorph.d.ts.map +1 -0
- package/dist/components/core/polymorph.jsx +5 -0
- package/dist/components/core/render-on-view.d.ts +7 -0
- package/dist/components/core/render-on-view.d.ts.map +1 -0
- package/dist/components/core/render-on-view.jsx +31 -0
- package/dist/components/core/resizable.d.ts +3 -0
- package/dist/components/core/resizable.d.ts.map +1 -0
- package/dist/components/core/resizable.jsx +51 -0
- package/dist/components/core/slot.d.ts +16 -0
- package/dist/components/core/slot.d.ts.map +1 -0
- package/dist/components/core/slot.jsx +156 -0
- package/dist/components/core/tag.d.ts +35 -0
- package/dist/components/core/tag.d.ts.map +1 -0
- package/dist/components/core/tag.jsx +51 -0
- package/dist/components/core/typography.d.ts +25 -0
- package/dist/components/core/typography.d.ts.map +1 -0
- package/dist/components/core/typography.jsx +18 -0
- package/dist/components/display/alert.d.ts +28 -0
- package/dist/components/display/alert.d.ts.map +1 -0
- package/dist/components/display/alert.jsx +61 -0
- package/dist/components/display/calendar.d.ts +42 -0
- package/dist/components/display/calendar.d.ts.map +1 -0
- package/dist/components/display/calendar.jsx +299 -0
- package/dist/components/display/card.d.ts +29 -0
- package/dist/components/display/card.d.ts.map +1 -0
- package/dist/components/display/card.jsx +43 -0
- package/dist/components/display/empty.d.ts +8 -0
- package/dist/components/display/empty.d.ts.map +1 -0
- package/dist/components/display/empty.jsx +11 -0
- package/dist/components/display/list.d.ts +16 -0
- package/dist/components/display/list.d.ts.map +1 -0
- package/dist/components/display/list.jsx +81 -0
- package/dist/components/display/notifications.d.ts +27 -0
- package/dist/components/display/notifications.d.ts.map +1 -0
- package/dist/components/display/notifications.jsx +126 -0
- package/dist/components/display/progress.d.ts +13 -0
- package/dist/components/display/progress.d.ts.map +1 -0
- package/dist/components/display/progress.jsx +11 -0
- package/dist/components/display/shortcut.d.ts +4 -0
- package/dist/components/display/shortcut.d.ts.map +1 -0
- package/dist/components/display/shortcut.jsx +23 -0
- package/dist/components/display/skeleton.d.ts +12 -0
- package/dist/components/display/skeleton.d.ts.map +1 -0
- package/dist/components/display/skeleton.jsx +19 -0
- package/dist/components/display/spinner.d.ts +5 -0
- package/dist/components/display/spinner.d.ts.map +1 -0
- package/dist/components/display/spinner.jsx +11 -0
- package/dist/components/display/stats.d.ts +12 -0
- package/dist/components/display/stats.d.ts.map +1 -0
- package/dist/components/display/stats.jsx +20 -0
- package/dist/components/display/step.d.ts +24 -0
- package/dist/components/display/step.d.ts.map +1 -0
- package/dist/components/display/step.jsx +131 -0
- package/dist/components/display/tabs.d.ts +24 -0
- package/dist/components/display/tabs.d.ts.map +1 -0
- package/dist/components/display/tabs.jsx +125 -0
- package/dist/components/display/timeline.d.ts +10 -0
- package/dist/components/display/timeline.d.ts.map +1 -0
- package/dist/components/display/timeline.jsx +25 -0
- package/dist/components/floating/command-palette.d.ts +49 -0
- package/dist/components/floating/command-palette.d.ts.map +1 -0
- package/dist/components/floating/command-palette.jsx +197 -0
- package/dist/components/floating/dropdown.d.ts +15 -0
- package/dist/components/floating/dropdown.d.ts.map +1 -0
- package/dist/components/floating/dropdown.jsx +56 -0
- package/dist/components/floating/expand.d.ts +11 -0
- package/dist/components/floating/expand.d.ts.map +1 -0
- package/dist/components/floating/expand.jsx +44 -0
- package/dist/components/floating/menu.d.ts +52 -0
- package/dist/components/floating/menu.d.ts.map +1 -0
- package/dist/components/floating/menu.jsx +147 -0
- package/dist/components/floating/modal.d.ts +60 -0
- package/dist/components/floating/modal.d.ts.map +1 -0
- package/dist/components/floating/modal.jsx +301 -0
- package/dist/components/floating/toolbar.d.ts +6 -0
- package/dist/components/floating/toolbar.d.ts.map +1 -0
- package/dist/components/floating/toolbar.jsx +5 -0
- package/dist/components/floating/tooltip.d.ts +17 -0
- package/dist/components/floating/tooltip.d.ts.map +1 -0
- package/dist/components/floating/tooltip.jsx +58 -0
- package/dist/components/floating/wizard.d.ts +26 -0
- package/dist/components/floating/wizard.d.ts.map +1 -0
- package/dist/components/floating/wizard.jsx +161 -0
- package/dist/components/form/autocomplete.d.ts +16 -0
- package/dist/components/form/autocomplete.d.ts.map +1 -0
- package/dist/components/form/autocomplete.jsx +278 -0
- package/dist/components/form/checkbox.d.ts +12 -0
- package/dist/components/form/checkbox.d.ts.map +1 -0
- package/dist/components/form/checkbox.jsx +12 -0
- package/dist/components/form/date-picker.d.ts +10 -0
- package/dist/components/form/date-picker.d.ts.map +1 -0
- package/dist/components/form/date-picker.jsx +115 -0
- package/dist/components/form/file-upload.d.ts +15 -0
- package/dist/components/form/file-upload.d.ts.map +1 -0
- package/dist/components/form/file-upload.jsx +134 -0
- package/dist/components/form/form.d.ts +3 -0
- package/dist/components/form/form.d.ts.map +1 -0
- package/dist/components/form/form.jsx +10 -0
- package/dist/components/form/formReset.d.ts +2 -0
- package/dist/components/form/formReset.d.ts.map +1 -0
- package/dist/components/form/formReset.jsx +17 -0
- package/dist/components/form/free-text.d.ts +11 -0
- package/dist/components/form/free-text.d.ts.map +1 -0
- package/dist/components/form/free-text.jsx +41 -0
- package/dist/components/form/input-field.d.ts +34 -0
- package/dist/components/form/input-field.d.ts.map +1 -0
- package/dist/components/form/input-field.jsx +58 -0
- package/dist/components/form/input.d.ts +52 -0
- package/dist/components/form/input.d.ts.map +1 -0
- package/dist/components/form/input.jsx +36 -0
- package/dist/components/form/multi-select.d.ts +19 -0
- package/dist/components/form/multi-select.d.ts.map +1 -0
- package/dist/components/form/multi-select.jsx +336 -0
- package/dist/components/form/radiobox.d.ts +7 -0
- package/dist/components/form/radiobox.d.ts.map +1 -0
- package/dist/components/form/radiobox.jsx +6 -0
- package/dist/components/form/select.d.ts +13 -0
- package/dist/components/form/select.d.ts.map +1 -0
- package/dist/components/form/select.jsx +42 -0
- package/dist/components/form/slider.d.ts +7 -0
- package/dist/components/form/slider.d.ts.map +1 -0
- package/dist/components/form/slider.jsx +45 -0
- package/dist/components/form/switch.d.ts +9 -0
- package/dist/components/form/switch.d.ts.map +1 -0
- package/dist/components/form/switch.jsx +46 -0
- package/dist/components/form/task-list.d.ts +3 -0
- package/dist/components/form/task-list.d.ts.map +1 -0
- package/dist/components/form/task-list.jsx +26 -0
- package/dist/components/form/textarea.d.ts +6 -0
- package/dist/components/form/textarea.d.ts.map +1 -0
- package/dist/components/form/textarea.jsx +12 -0
- package/dist/components/index.d.ts +45 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +44 -0
- package/dist/components/page-calendar/calendar-header.d.ts +16 -0
- package/dist/components/page-calendar/calendar-header.d.ts.map +1 -0
- package/dist/components/page-calendar/calendar-header.jsx +83 -0
- package/dist/components/page-calendar/day-view.d.ts +12 -0
- package/dist/components/page-calendar/day-view.d.ts.map +1 -0
- package/dist/components/page-calendar/day-view.jsx +94 -0
- package/dist/components/page-calendar/event-pill.d.ts +9 -0
- package/dist/components/page-calendar/event-pill.d.ts.map +1 -0
- package/dist/components/page-calendar/event-pill.jsx +25 -0
- package/dist/components/page-calendar/index.d.ts +4 -0
- package/dist/components/page-calendar/index.d.ts.map +1 -0
- package/dist/components/page-calendar/index.js +2 -0
- package/dist/components/page-calendar/month-view.d.ts +11 -0
- package/dist/components/page-calendar/month-view.d.ts.map +1 -0
- package/dist/components/page-calendar/month-view.jsx +46 -0
- package/dist/components/page-calendar/page-calendar.d.ts +18 -0
- package/dist/components/page-calendar/page-calendar.d.ts.map +1 -0
- package/dist/components/page-calendar/page-calendar.jsx +41 -0
- package/dist/components/page-calendar/page-calendar.types.d.ts +18 -0
- package/dist/components/page-calendar/page-calendar.types.d.ts.map +1 -0
- package/dist/components/page-calendar/page-calendar.types.js +1 -0
- package/dist/components/page-calendar/page-calendar.utils.d.ts +24 -0
- package/dist/components/page-calendar/page-calendar.utils.d.ts.map +1 -0
- package/dist/components/page-calendar/page-calendar.utils.js +93 -0
- package/dist/components/page-calendar/week-view.d.ts +11 -0
- package/dist/components/page-calendar/week-view.d.ts.map +1 -0
- package/dist/components/page-calendar/week-view.jsx +71 -0
- package/dist/components/table/filter.d.ts +42 -0
- package/dist/components/table/filter.d.ts.map +1 -0
- package/dist/components/table/filter.jsx +141 -0
- package/dist/components/table/group.d.ts +17 -0
- package/dist/components/table/group.d.ts.map +1 -0
- package/dist/components/table/group.jsx +68 -0
- package/dist/components/table/index.d.ts +19 -0
- package/dist/components/table/index.d.ts.map +1 -0
- package/dist/components/table/index.jsx +60 -0
- package/dist/components/table/inner-table.d.ts +29 -0
- package/dist/components/table/inner-table.d.ts.map +1 -0
- package/dist/components/table/inner-table.jsx +102 -0
- package/dist/components/table/metadata.d.ts +4 -0
- package/dist/components/table/metadata.d.ts.map +1 -0
- package/dist/components/table/metadata.jsx +36 -0
- package/dist/components/table/pagination.d.ts +5 -0
- package/dist/components/table/pagination.d.ts.map +1 -0
- package/dist/components/table/pagination.jsx +74 -0
- package/dist/components/table/row.d.ts +11 -0
- package/dist/components/table/row.d.ts.map +1 -0
- package/dist/components/table/row.jsx +49 -0
- package/dist/components/table/sort.d.ts +28 -0
- package/dist/components/table/sort.d.ts.map +1 -0
- package/dist/components/table/sort.jsx +109 -0
- package/dist/components/table/table-lib.d.ts +135 -0
- package/dist/components/table/table-lib.d.ts.map +1 -0
- package/dist/components/table/table-lib.js +83 -0
- package/dist/components/table/table.context.d.ts +10 -0
- package/dist/components/table/table.context.d.ts.map +1 -0
- package/dist/components/table/table.context.jsx +4 -0
- package/dist/components/table/thead.d.ts +9 -0
- package/dist/components/table/thead.d.ts.map +1 -0
- package/dist/components/table/thead.jsx +103 -0
- package/dist/config/context.d.ts +21 -0
- package/dist/config/context.d.ts.map +1 -0
- package/dist/config/context.js +12 -0
- package/dist/config/default-translations.d.ts +94 -0
- package/dist/config/default-translations.d.ts.map +1 -0
- package/dist/config/default-translations.jsx +87 -0
- package/dist/config/default-tweaks.d.ts +13 -0
- package/dist/config/default-tweaks.d.ts.map +1 -0
- package/dist/config/default-tweaks.js +4 -0
- package/dist/constants.d.ts +3 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +2 -0
- package/dist/hooks/use-click-outside.d.ts +3 -0
- package/dist/hooks/use-click-outside.d.ts.map +1 -0
- package/dist/hooks/use-click-outside.js +17 -0
- package/dist/hooks/use-color-parser.d.ts +2 -0
- package/dist/hooks/use-color-parser.d.ts.map +1 -0
- package/dist/hooks/use-color-parser.js +9 -0
- package/dist/hooks/use-components-provider.d.ts +15 -0
- package/dist/hooks/use-components-provider.d.ts.map +1 -0
- package/dist/hooks/use-components-provider.jsx +22 -0
- package/dist/hooks/use-debounce.d.ts +5 -0
- package/dist/hooks/use-debounce.d.ts.map +1 -0
- package/dist/hooks/use-debounce.js +12 -0
- package/dist/hooks/use-floating-ref.d.ts +2 -0
- package/dist/hooks/use-floating-ref.d.ts.map +1 -0
- package/dist/hooks/use-floating-ref.js +6 -0
- package/dist/hooks/use-form.d.ts +394 -0
- package/dist/hooks/use-form.d.ts.map +1 -0
- package/dist/hooks/use-form.js +563 -0
- package/dist/hooks/use-hover.d.ts +3 -0
- package/dist/hooks/use-hover.d.ts.map +1 -0
- package/dist/hooks/use-hover.js +18 -0
- package/dist/hooks/use-input-id.d.ts +4 -0
- package/dist/hooks/use-input-id.d.ts.map +1 -0
- package/dist/hooks/use-input-id.js +5 -0
- package/dist/hooks/use-is-coarse-device.d.ts +2 -0
- package/dist/hooks/use-is-coarse-device.d.ts.map +1 -0
- package/dist/hooks/use-is-coarse-device.js +12 -0
- package/dist/hooks/use-locale.d.ts +3 -0
- package/dist/hooks/use-locale.d.ts.map +1 -0
- package/dist/hooks/use-locale.js +10 -0
- package/dist/hooks/use-media-query.d.ts +2 -0
- package/dist/hooks/use-media-query.d.ts.map +1 -0
- package/dist/hooks/use-media-query.js +25 -0
- package/dist/hooks/use-on-event.d.ts +4 -0
- package/dist/hooks/use-on-event.d.ts.map +1 -0
- package/dist/hooks/use-on-event.js +7 -0
- package/dist/hooks/use-parent.d.ts +3 -0
- package/dist/hooks/use-parent.d.ts.map +1 -0
- package/dist/hooks/use-parent.js +21 -0
- package/dist/hooks/use-preferences.d.ts +2 -0
- package/dist/hooks/use-preferences.d.ts.map +1 -0
- package/dist/hooks/use-preferences.js +23 -0
- package/dist/hooks/use-previous.d.ts +2 -0
- package/dist/hooks/use-previous.d.ts.map +1 -0
- package/dist/hooks/use-previous.js +9 -0
- package/dist/hooks/use-reactive.d.ts +2 -0
- package/dist/hooks/use-reactive.d.ts.map +1 -0
- package/dist/hooks/use-reactive.js +9 -0
- package/dist/hooks/use-remove-scroll.d.ts +4 -0
- package/dist/hooks/use-remove-scroll.d.ts.map +1 -0
- package/dist/hooks/use-remove-scroll.js +48 -0
- package/dist/hooks/use-resize-observer.d.ts +2 -0
- package/dist/hooks/use-resize-observer.d.ts.map +1 -0
- package/dist/hooks/use-resize-observer.js +17 -0
- package/dist/hooks/use-stable-ref.d.ts +2 -0
- package/dist/hooks/use-stable-ref.d.ts.map +1 -0
- package/dist/hooks/use-stable-ref.js +9 -0
- package/dist/hooks/use-swipe.d.ts +8 -0
- package/dist/hooks/use-swipe.d.ts.map +1 -0
- package/dist/hooks/use-swipe.js +17 -0
- package/dist/hooks/use-translations.d.ts +92 -0
- package/dist/hooks/use-translations.d.ts.map +1 -0
- package/dist/hooks/use-translations.js +9 -0
- package/dist/hooks/use-tweaks.d.ts +3 -0
- package/dist/hooks/use-tweaks.d.ts.map +1 -0
- package/dist/hooks/use-tweaks.js +9 -0
- package/dist/hooks/use-window-size.d.ts +5 -0
- package/dist/hooks/use-window-size.d.ts.map +1 -0
- package/dist/hooks/use-window-size.js +14 -0
- package/dist/index-DDeQW0JW.js.map +1 -1
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -8231
- package/dist/index.js.map +1 -1
- package/dist/lib/combi-keys.d.ts +15 -0
- package/dist/lib/combi-keys.d.ts.map +1 -0
- package/dist/lib/combi-keys.js +60 -0
- package/dist/lib/dict.d.ts +9 -0
- package/dist/lib/dict.d.ts.map +1 -0
- package/dist/lib/dict.js +28 -0
- package/dist/lib/dom.d.ts +20 -0
- package/dist/lib/dom.d.ts.map +1 -0
- package/dist/lib/dom.js +66 -0
- package/dist/lib/fns.d.ts +11 -0
- package/dist/lib/fns.d.ts.map +1 -0
- package/dist/lib/fns.js +46 -0
- package/dist/lib/fzf.d.ts +16 -0
- package/dist/lib/fzf.d.ts.map +1 -0
- package/dist/lib/fzf.js +115 -0
- package/dist/lib/keyboard-area.d.ts +16 -0
- package/dist/lib/keyboard-area.d.ts.map +1 -0
- package/dist/lib/keyboard-area.js +14 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/types.d.ts +26 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { LayoutGroup, Reorder, useDragControls, useMotionValue } from "motion/react";
|
|
3
|
+
import Linq from "linq-arrays";
|
|
4
|
+
import { DotsSixVerticalIcon, TrashIcon, StackMinusIcon } from "@phosphor-icons/react";
|
|
5
|
+
import React, { Fragment, useState } from "react";
|
|
6
|
+
import { keys } from "sidekicker";
|
|
7
|
+
import { useTranslations } from "../../hooks/use-translations";
|
|
8
|
+
import { uuid } from "../../lib/fns";
|
|
9
|
+
import { Button } from "../core/button";
|
|
10
|
+
import { Dropdown } from "../floating/dropdown";
|
|
11
|
+
import { Select } from "../form/select";
|
|
12
|
+
import { createOptionCols } from "./table-lib";
|
|
13
|
+
const Item = ({ item, onPointerDown }) => {
|
|
14
|
+
const y = useMotionValue(0);
|
|
15
|
+
return (<Reorder.Item onPointerDown={onPointerDown} id={item.groupId} className="flex flex-row items-center gap-2" key={item.groupId} value={item} style={{ y }}>
|
|
16
|
+
<button type="button" className="cursor-grab">
|
|
17
|
+
<DotsSixVerticalIcon size={14}/>
|
|
18
|
+
</button>
|
|
19
|
+
<span>{item.groupName}</span>
|
|
20
|
+
</Reorder.Item>);
|
|
21
|
+
};
|
|
22
|
+
export const Group = (props) => {
|
|
23
|
+
const translations = useTranslations();
|
|
24
|
+
const options = createOptionCols(props.cols);
|
|
25
|
+
const controls = useDragControls();
|
|
26
|
+
const [group, setGroup] = useState(props.groups[0]?.thead || "");
|
|
27
|
+
const onChange = (e) => {
|
|
28
|
+
const select = e.target;
|
|
29
|
+
const key = select.value;
|
|
30
|
+
const index = select.options.selectedIndex;
|
|
31
|
+
const label = select.options.item(index)?.label || "";
|
|
32
|
+
setGroup(label);
|
|
33
|
+
const groupBy = new Linq(props.rows).GroupBy(key);
|
|
34
|
+
const col = props.cols.find((x) => x.id === key);
|
|
35
|
+
props.setGroups(keys(groupBy).map((groupName, index) => {
|
|
36
|
+
const rows = groupBy[groupName];
|
|
37
|
+
return { ...col, groupId: uuid(), groupKey: key, index, rows, groupName: groupName };
|
|
38
|
+
}));
|
|
39
|
+
};
|
|
40
|
+
const onDelete = () => props.setGroups([]);
|
|
41
|
+
return (<Fragment>
|
|
42
|
+
<Dropdown arrow={false} title={translations.tableGroupLabel} trigger={<span className="flex items-center gap-1 proportional-nums">
|
|
43
|
+
<StackMinusIcon size={14}/>
|
|
44
|
+
{translations.tableGroupLabelWithCount}
|
|
45
|
+
{props.groups.length > 0 ? ` - ${group}(${props.groups.length})` : ""}
|
|
46
|
+
</span>}>
|
|
47
|
+
<div className="flex flex-nowrap items-center">
|
|
48
|
+
<Select value={group} title="Tipo de agrupamento" onChange={onChange} options={options} placeholder="Agrupar por..."/>
|
|
49
|
+
<Button className="mt-4" onClick={onDelete} theme="raw" data-id={group}>
|
|
50
|
+
<TrashIcon size={16} className="text-danger"/>
|
|
51
|
+
</Button>
|
|
52
|
+
</div>
|
|
53
|
+
{props.groups.length > 0 ? (<section className="my-4">
|
|
54
|
+
<header>
|
|
55
|
+
<h2 className="text-xl font-medium">Order groups</h2>
|
|
56
|
+
</header>
|
|
57
|
+
<LayoutGroup>
|
|
58
|
+
<Reorder.Group axis="y" className="relative space-y-2" drag dragControls={controls} dragListener={false} layoutScroll onReorder={props.setGroups} values={props.groups}>
|
|
59
|
+
{props.groups.map((item) => (<Item key={item.groupId} item={item} onPointerDown={(e) => {
|
|
60
|
+
controls.start(e);
|
|
61
|
+
props.setGroups([...props.groups]);
|
|
62
|
+
}}/>))}
|
|
63
|
+
</Reorder.Group>
|
|
64
|
+
</LayoutGroup>
|
|
65
|
+
</section>) : null}
|
|
66
|
+
</Dropdown>
|
|
67
|
+
</Fragment>);
|
|
68
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ComponentProps } from "react";
|
|
2
|
+
import { InnerTableProps } from "./inner-table";
|
|
3
|
+
import { TableOperationProps } from "./table-lib";
|
|
4
|
+
export type TableProps<T extends Record<string, unknown>> = Pick<InnerTableProps<T>, "cols" | "rows" | "loadingMore" | "border" | "Aside"> & {
|
|
5
|
+
name: string;
|
|
6
|
+
} & Partial<TableOperationProps<T> & {
|
|
7
|
+
loading: boolean;
|
|
8
|
+
reference: keyof T;
|
|
9
|
+
operations: boolean;
|
|
10
|
+
useControl: boolean;
|
|
11
|
+
inlineFilter: boolean;
|
|
12
|
+
inlineSorter: boolean;
|
|
13
|
+
sticky: number | null;
|
|
14
|
+
onScrollEnd: () => void;
|
|
15
|
+
getScrollRef?: () => HTMLElement | undefined;
|
|
16
|
+
getRowProps: (row: T) => ComponentProps<"tr">;
|
|
17
|
+
}>;
|
|
18
|
+
export declare const Table: <T extends Record<string, unknown>>(props: TableProps<T>) => import("react").JSX.Element;
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/table/index.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAsB,MAAM,OAAO,CAAC;AAK3D,OAAO,EAAc,eAAe,EAAE,MAAM,eAAe,CAAC;AAG5D,OAAO,EAAuC,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAGvF,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,aAAa,GAAG,QAAQ,GAAG,OAAO,CAAC,GAAG;IACzI,IAAI,EAAE,MAAM,CAAC;CAChB,GAAG,OAAO,CACH,mBAAmB,CAAC,CAAC,CAAC,GAAG;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC,CAAC;IACnB,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;IACpB,YAAY,EAAE,OAAO,CAAC;IACtB,YAAY,EAAE,OAAO,CAAC;IACtB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,WAAW,EAAE,MAAM,IAAI,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,WAAW,GAAG,SAAS,CAAC;IAC7C,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,cAAc,CAAC,IAAI,CAAC,CAAC;CACjD,CACJ,CAAC;AASN,eAAO,MAAM,KAAK,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,UAAU,CAAC,CAAC,CAAC,gCAwH5E,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { AnimatePresence } from "motion/react";
|
|
3
|
+
import { useEffect, useMemo } from "react";
|
|
4
|
+
import { useReducer } from "use-typed-reducer";
|
|
5
|
+
import { useTweaks } from "../../hooks/use-tweaks";
|
|
6
|
+
import { InnerTable } from "./inner-table";
|
|
7
|
+
import { Metadata } from "./metadata";
|
|
8
|
+
import { createOptionCols } from "./table-lib";
|
|
9
|
+
import { TableProvider } from "./table.context";
|
|
10
|
+
const dispatcherFun = (prev, setter) => typeof setter === "function" ? setter(prev) : setter;
|
|
11
|
+
const compareAndExec = (prev, state, exec) => (prev === state ? undefined : exec?.(state));
|
|
12
|
+
export const Table = (props) => {
|
|
13
|
+
const tweaks = useTweaks();
|
|
14
|
+
const contextState = useMemo(() => ({
|
|
15
|
+
sticky: props.sticky === undefined ? (tweaks.table.sticky ?? undefined) : (props.sticky ?? undefined),
|
|
16
|
+
}), [props.sticky, tweaks.table.sticky]);
|
|
17
|
+
const operations = props.operations ?? tweaks.table.operations ?? true;
|
|
18
|
+
const optionCols = useMemo(() => createOptionCols(props.cols), [props.cols]);
|
|
19
|
+
const [state, dispatch] = useReducer({
|
|
20
|
+
cols: props.cols,
|
|
21
|
+
sorters: (props.sorters ?? []),
|
|
22
|
+
groups: (props.groups ?? []),
|
|
23
|
+
filters: (props.filters ?? []),
|
|
24
|
+
}, (get) => {
|
|
25
|
+
const create = (key) => (arg) => {
|
|
26
|
+
const state = get.state();
|
|
27
|
+
return { ...state, [key]: dispatcherFun(state[key], arg) };
|
|
28
|
+
};
|
|
29
|
+
return {
|
|
30
|
+
cols: create("cols"),
|
|
31
|
+
sorters: create("sorters"),
|
|
32
|
+
groups: create("groups"),
|
|
33
|
+
filters: create("filters"),
|
|
34
|
+
};
|
|
35
|
+
}, {
|
|
36
|
+
postMiddleware: [
|
|
37
|
+
(state, prev) => {
|
|
38
|
+
props.set?.(state);
|
|
39
|
+
compareAndExec(prev?.filters ?? [], state.filters ?? [], props.setFilters);
|
|
40
|
+
compareAndExec(prev?.sorters ?? [], state.sorters ?? [], props.setSorters);
|
|
41
|
+
compareAndExec(prev?.groups ?? [], state.groups ?? [], props.setGroups);
|
|
42
|
+
compareAndExec(prev?.cols ?? [], state.cols ?? [], props.setCols);
|
|
43
|
+
return state;
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
});
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
dispatch.cols(props.cols);
|
|
49
|
+
}, [props.cols]);
|
|
50
|
+
return (<TableProvider value={contextState}>
|
|
51
|
+
<AnimatePresence propagate initial={false}>
|
|
52
|
+
{operations ? (<Metadata cols={state.cols} rows={props.rows} options={optionCols} groups={state.groups} filters={state.filters} setCols={dispatch.cols} sorters={state.sorters} setGroups={dispatch.groups} setFilters={dispatch.filters} setSorters={dispatch.sorters} pagination={props.pagination ?? null} inlineFilter={props.inlineFilter ?? true} inlineSorter={props.inlineSorter ?? true}/>) : null}
|
|
53
|
+
{state.groups.length === 0 ? (<InnerTable {...props} index={0} cols={state.cols} options={optionCols} groups={state.groups} filters={state.filters} optionCols={optionCols} setCols={dispatch.cols} sorters={state.sorters} setGroups={dispatch.groups} setFilters={dispatch.filters} setSorters={dispatch.sorters} onScrollEnd={props.onScrollEnd} pagination={props.pagination ?? null} inlineFilter={props.inlineFilter ?? true} inlineSorter={props.inlineSorter ?? true}/>) : (<div className="flex flex-wrap gap-4">
|
|
54
|
+
{state.groups.map((group, index) => (<div className="min-w-full" key={`group-${group.groupId}`}>
|
|
55
|
+
<InnerTable {...props} group={group} index={index} cols={state.cols} pagination={null} rows={group.rows} options={optionCols} groups={state.groups} filters={state.filters} optionCols={optionCols} setCols={dispatch.cols} sorters={state.sorters} setGroups={dispatch.groups} setFilters={dispatch.filters} setSorters={dispatch.sorters} onScrollEnd={props.onScrollEnd} inlineFilter={props.inlineFilter ?? true} inlineSorter={props.inlineSorter ?? true}/>
|
|
56
|
+
</div>))}
|
|
57
|
+
</div>)}
|
|
58
|
+
</AnimatePresence>
|
|
59
|
+
</TableProvider>);
|
|
60
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React, { ComponentProps, HTMLAttributes } from "react";
|
|
2
|
+
import { OptionProps } from "../form/select";
|
|
3
|
+
import { FilterConfig } from "./filter";
|
|
4
|
+
import { GroupItem } from "./group";
|
|
5
|
+
import { Sorter } from "./sort";
|
|
6
|
+
import { CellAsideElement, Col, TableOperationProps } from "./table-lib";
|
|
7
|
+
import { Any } from "../../types";
|
|
8
|
+
export type InnerTableProps<T extends Any> = HTMLAttributes<HTMLTableElement> & TableOperationProps<T> & {
|
|
9
|
+
rows: T[];
|
|
10
|
+
index: number;
|
|
11
|
+
cols: Col<T>[];
|
|
12
|
+
border?: boolean;
|
|
13
|
+
loading?: boolean;
|
|
14
|
+
group?: GroupItem<T>;
|
|
15
|
+
useControl?: boolean;
|
|
16
|
+
loadingMore?: boolean;
|
|
17
|
+
sorters?: Sorter<T>[];
|
|
18
|
+
showMetadata?: boolean;
|
|
19
|
+
groups?: GroupItem<T>[];
|
|
20
|
+
onScrollEnd?: () => void;
|
|
21
|
+
optionCols: OptionProps[];
|
|
22
|
+
filters?: FilterConfig<T>[];
|
|
23
|
+
Aside?: React.FC<CellAsideElement<T>>;
|
|
24
|
+
getScrollRef?: () => HTMLElement | undefined;
|
|
25
|
+
getRowProps?: (_: T) => ComponentProps<"tr">;
|
|
26
|
+
setGroups: React.Dispatch<React.SetStateAction<GroupItem<T>[]>>;
|
|
27
|
+
};
|
|
28
|
+
export declare const InnerTable: <T extends Record<string, unknown>>({ cols, filters, setCols, sorters, setFilters, setSorters, onScrollEnd, getScrollRef, pagination, useControl, ...props }: InnerTableProps<T>) => React.JSX.Element;
|
|
29
|
+
//# sourceMappingURL=inner-table.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inner-table.d.ts","sourceRoot":"","sources":["../../../src/components/table/inner-table.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,EAAE,cAAc,EAA2B,cAAc,EAAwC,MAAM,OAAO,CAAC;AAM7H,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGpC,OAAO,EAAa,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,GAAG,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAGzE,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAYlC,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,GAAG,IAAI,cAAc,CAAC,gBAAgB,CAAC,GACzE,mBAAmB,CAAC,CAAC,CAAC,GAAG;IACrB,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IACrB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;IACtB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,MAAM,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB,UAAU,EAAE,WAAW,EAAE,CAAC;IAC1B,OAAO,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5B,KAAK,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC;IACtC,YAAY,CAAC,EAAE,MAAM,WAAW,GAAG,SAAS,CAAC;IAC7C,WAAW,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,cAAc,CAAC,IAAI,CAAC,CAAC;IAC7C,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;CACnE,CAAC;AAmFN,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,0HAY3D,eAAe,CAAC,CAAC,CAAC,sBA0EpB,CAAC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import Linq from "linq-arrays";
|
|
2
|
+
import { AnimatePresence } from "motion/react";
|
|
3
|
+
import React, { Fragment, useEffect, useMemo, useRef, useState } from "react";
|
|
4
|
+
import { TableVirtuoso } from "react-virtuoso";
|
|
5
|
+
import { Is } from "sidekicker";
|
|
6
|
+
import { useStableRef } from "../../hooks/use-stable-ref";
|
|
7
|
+
import { Empty } from "../display/empty";
|
|
8
|
+
import { SkeletonCell } from "../display/skeleton";
|
|
9
|
+
import { Pagination } from "./pagination";
|
|
10
|
+
import { Row } from "./row";
|
|
11
|
+
import { multiSort } from "./sort";
|
|
12
|
+
import { useTable } from "./table.context";
|
|
13
|
+
import { TableHeader } from "./thead";
|
|
14
|
+
const TableBody = React.forwardRef(({ context: _context, className = "", ...props }, ref) => (<tbody {...props} role="rowgroup" className={`divide-y divide-table-border ${className}`} ref={ref}>
|
|
15
|
+
<AnimatePresence>{props.children}</AnimatePresence>
|
|
16
|
+
</tbody>));
|
|
17
|
+
const VirtualTable = React.forwardRef(({ context: _context, className = "", ...props }, ref) => (<table {...props} role="table" ref={ref} style={{ ...props.style, "--table-cell-padding": "0.75rem" }} className={`table w-full table-fixed border-separate border-spacing-0 text-left ${className ?? ""}`}/>));
|
|
18
|
+
const Thead = React.forwardRef(({ context: _context, ...props }, ref) => {
|
|
19
|
+
const ctx = useTable();
|
|
20
|
+
const style = {
|
|
21
|
+
...props.style,
|
|
22
|
+
top: Is.number(ctx.sticky) ? `${ctx.sticky}px` : undefined,
|
|
23
|
+
};
|
|
24
|
+
return <thead {...props} ref={ref} style={style} role="rowgroup" className="group:sticky top-0 hidden bg-transparent md:table-header-group"/>;
|
|
25
|
+
});
|
|
26
|
+
const TRow = React.forwardRef(({ context, item, className, ...props }, ref) => {
|
|
27
|
+
const contextProps = item ? context?.getRowProps?.(item) : undefined;
|
|
28
|
+
const innerProps = { ...props, ...contextProps };
|
|
29
|
+
return (<tr {...innerProps} role="row" ref={ref} className={`group-table-row flex h-fit flex-col flex-wrap justify-center gap-1 pb-4 md:table-row ${[className, contextProps?.className].filter(Boolean).join(" ")}`}/>);
|
|
30
|
+
});
|
|
31
|
+
const TFoot = React.forwardRef(({ context, ...props }, ref) => {
|
|
32
|
+
if (context?.loadingMore) {
|
|
33
|
+
return (<tfoot {...props} ref={ref} className="bg-card-background">
|
|
34
|
+
<tr role="row" className="bg-card-background">
|
|
35
|
+
<td colSpan={999} className="h-14 bg-card-background px-2">
|
|
36
|
+
<span className="block h-2 w-full animate-pulse rounded bg-foreground opacity-60"/>
|
|
37
|
+
</td>
|
|
38
|
+
</tr>
|
|
39
|
+
</tfoot>);
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
});
|
|
43
|
+
const components = {
|
|
44
|
+
TableRow: TRow,
|
|
45
|
+
TableFoot: TFoot,
|
|
46
|
+
TableHead: Thead,
|
|
47
|
+
Table: VirtualTable,
|
|
48
|
+
TableBody: TableBody,
|
|
49
|
+
};
|
|
50
|
+
const loadingArray = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
|
51
|
+
const EmptyContent = (props) => (<div className="flex h-48 w-full items-center justify-center px-2">{props.loading ? SkeletonCell : <Empty />}</div>);
|
|
52
|
+
const EmptyCell = () => <Fragment />;
|
|
53
|
+
const emptyRows = [];
|
|
54
|
+
export const InnerTable = ({ cols, filters, setCols, sorters, setFilters, setSorters, onScrollEnd, getScrollRef, pagination = null, useControl = false, ...props }) => {
|
|
55
|
+
const ref = useRef(null);
|
|
56
|
+
const [, setShowLoadingFooter] = useState(false);
|
|
57
|
+
const onScrollEndRef = useStableRef(onScrollEnd);
|
|
58
|
+
const loadingMoreRef = useStableRef(props.loadingMore);
|
|
59
|
+
const rows = useMemo(() => {
|
|
60
|
+
if (props.loading)
|
|
61
|
+
return loadingArray;
|
|
62
|
+
if (useControl)
|
|
63
|
+
return props.rows;
|
|
64
|
+
const linq = new Linq(props.rows);
|
|
65
|
+
if (filters.length > 0) {
|
|
66
|
+
filters.forEach((x) => x.value === "" || Number.isNaN(x.value) ? undefined : linq.Where(x.name, x.operation.symbol, x.value));
|
|
67
|
+
}
|
|
68
|
+
if (sorters.length === 0)
|
|
69
|
+
return linq.Select();
|
|
70
|
+
return multiSort(linq.Select(), sorters);
|
|
71
|
+
}, [props.loading, props.rows, useControl, filters, sorters]);
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
if (ref.current === null)
|
|
74
|
+
return () => { };
|
|
75
|
+
const div = ref.current;
|
|
76
|
+
const observer = new IntersectionObserver((entries) => {
|
|
77
|
+
const endOfPage = entries[entries.length - 1];
|
|
78
|
+
const condition = endOfPage.isIntersecting && loadingMoreRef.current;
|
|
79
|
+
if (condition) {
|
|
80
|
+
onScrollEndRef.current?.();
|
|
81
|
+
return void setShowLoadingFooter(true);
|
|
82
|
+
}
|
|
83
|
+
return setShowLoadingFooter(false);
|
|
84
|
+
});
|
|
85
|
+
observer.observe(div);
|
|
86
|
+
return () => observer.disconnect();
|
|
87
|
+
}, [loadingMoreRef, onScrollEndRef]);
|
|
88
|
+
const empty = rows.length === 0;
|
|
89
|
+
const context = {
|
|
90
|
+
cols: cols,
|
|
91
|
+
Aside: props.Aside,
|
|
92
|
+
loading: props.loading,
|
|
93
|
+
getRowProps: props.getRowProps,
|
|
94
|
+
loadingMore: props.loadingMore,
|
|
95
|
+
};
|
|
96
|
+
return (<div className="group relative flex w-full flex-col whitespace-nowrap rounded-lg bg-table-background">
|
|
97
|
+
<TableVirtuoso components={components} context={context} totalCount={rows.length} itemContent={empty ? EmptyCell : Row} data={empty ? emptyRows : rows} useWindowScroll={getScrollRef ? false : true} customScrollParent={getScrollRef ? getScrollRef() : undefined} fixedHeaderContent={() => (<TableHeader headers={cols} filters={filters} setCols={setCols} sorters={sorters} setFilters={setFilters} setSorters={setSorters} loading={!!props.loading} inlineFilter={props.inlineFilter} inlineSorter={props.inlineSorter}/>)}/>
|
|
98
|
+
{empty ? <EmptyContent loading={props.loading}/> : null}
|
|
99
|
+
<div aria-hidden="true" ref={ref} className="h-0.5 w-full"/>
|
|
100
|
+
{pagination !== null ? <Pagination {...pagination}/> : null}
|
|
101
|
+
</div>);
|
|
102
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../../../src/components/table/metadata.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAIlC,OAAO,EAAE,mBAAmB,EAAiB,MAAM,aAAa,CAAC;AAEjE,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,GAAG,EAAE,OAAO,mBAAmB,CAAC,CAAC,CAAC,gCAwCpE,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Filter } from "./filter";
|
|
2
|
+
import { Group } from "./group";
|
|
3
|
+
import { Sort } from "./sort";
|
|
4
|
+
import { valueFromType } from "./table-lib";
|
|
5
|
+
export const Metadata = (props) => (<header className="mb-1 min-w-full">
|
|
6
|
+
<div className="flex min-w-full flex-wrap items-center justify-between gap-x-4 gap-y-1">
|
|
7
|
+
<div className="items-centeend flex w-fit gap-4 whitespace-nowrap py-2">
|
|
8
|
+
<span>
|
|
9
|
+
<Filter cols={props.cols} options={props.options} filters={props.filters} set={props.setFilters}/>
|
|
10
|
+
</span>
|
|
11
|
+
<span>
|
|
12
|
+
<Sort options={props.options} cols={props.cols} sorters={props.sorters} set={props.setSorters}/>
|
|
13
|
+
</span>
|
|
14
|
+
<span>
|
|
15
|
+
<Group rows={props.rows} groups={props.groups} setGroups={props.setGroups} options={props.options} cols={props.cols}/>
|
|
16
|
+
</span>
|
|
17
|
+
</div>
|
|
18
|
+
<ul className="flex w-full flex-1 flex-grow flex-row flex-wrap items-center gap-4 md:justify-end">
|
|
19
|
+
{props.filters.map((x) => (<li key={`filter-table-${x.id}`} className="flex items-center gap-1 rounded-xl border border-card-border px-4 py-0.5">
|
|
20
|
+
<span>
|
|
21
|
+
<span className="mr-2 inline-block aspect-square size-3 rounded-full bg-primary" aria-hidden="true"/>
|
|
22
|
+
{x.label} {x.operation.label.toLowerCase()}:
|
|
23
|
+
</span>
|
|
24
|
+
<div className="relative w-min min-w-[1ch]">
|
|
25
|
+
<span aria-hidden="true" className="invisible whitespace-pre p-0">
|
|
26
|
+
{x.value || " "}
|
|
27
|
+
</span>
|
|
28
|
+
<input type={x.type} value={x.value} className="absolute left-0 top-0 m-0 inline-block w-full bg-transparent p-0 placeholder-primary/70 outline-none [appearance:textfield] after:empty:text-primary/70 [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none" onChange={(e) => {
|
|
29
|
+
const value = valueFromType(e.target);
|
|
30
|
+
props.setFilters((prev) => prev.map((item) => (x.id === item.id ? { ...item, value } : item)));
|
|
31
|
+
}}/>
|
|
32
|
+
</div>
|
|
33
|
+
</li>))}
|
|
34
|
+
</ul>
|
|
35
|
+
</div>
|
|
36
|
+
</header>);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { TablePagination } from "./table-lib";
|
|
3
|
+
export declare function createPaginationItems(current: number, max: number): (string | number)[];
|
|
4
|
+
export declare const Pagination: (pagination: TablePagination) => React.JSX.Element;
|
|
5
|
+
//# sourceMappingURL=pagination.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pagination.d.ts","sourceRoot":"","sources":["../../../src/components/table/pagination.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmC,MAAM,OAAO,CAAC;AAGxD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,uBAmBjE;AAED,eAAO,MAAM,UAAU,GAAI,YAAY,eAAe,sBA4ErD,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import React, { Fragment, useId, useMemo } from "react";
|
|
2
|
+
import { useTranslations } from "../../hooks/use-translations";
|
|
3
|
+
import { Polymorph } from "../core/polymorph";
|
|
4
|
+
export function createPaginationItems(current, max) {
|
|
5
|
+
if (!current || !max)
|
|
6
|
+
return [];
|
|
7
|
+
const items = [1];
|
|
8
|
+
if (current === 1 && max === 1)
|
|
9
|
+
return items;
|
|
10
|
+
if (current > 4)
|
|
11
|
+
items.push("-");
|
|
12
|
+
const r = 2;
|
|
13
|
+
const r1 = current - r;
|
|
14
|
+
const r2 = current + r;
|
|
15
|
+
for (let i = r1 > 2 ? r1 : 2; i <= Math.min(max, r2); i++)
|
|
16
|
+
items.push(i);
|
|
17
|
+
const p2 = max - 2;
|
|
18
|
+
if (r2 + 1 !== p2) {
|
|
19
|
+
if (r2 + 1 < max)
|
|
20
|
+
items.push("_");
|
|
21
|
+
}
|
|
22
|
+
if (r2 < max) {
|
|
23
|
+
items.push(max - 2);
|
|
24
|
+
items.push(max - 1);
|
|
25
|
+
items.push(max);
|
|
26
|
+
}
|
|
27
|
+
return Array.from(new Set(items));
|
|
28
|
+
}
|
|
29
|
+
export const Pagination = (pagination) => {
|
|
30
|
+
const id = useId();
|
|
31
|
+
const translation = useTranslations();
|
|
32
|
+
const pageNavigation = useMemo(() => createPaginationItems(pagination.current, pagination.pages), [pagination.current, pagination.pages]);
|
|
33
|
+
const hasNext = pagination.current < pagination.pages;
|
|
34
|
+
const Link = pagination.asLink ?? "button";
|
|
35
|
+
return (<footer className="flex flex-wrap items-center justify-center gap-4 border-t-muted p-3 text-sm lg:flex-nowrap lg:justify-between">
|
|
36
|
+
<p>
|
|
37
|
+
<translation.tablePaginationFooter {...pagination} sizes={pagination.sizes} select={pagination.onChangeSize && Array.isArray(pagination.sizes) ? (<Fragment>
|
|
38
|
+
<label htmlFor={id}>{translation.tablePaginationSelectLabel}</label>
|
|
39
|
+
<select id={id} value={pagination.size} className="cursor-pointer bg-transparent" onChange={(e) => {
|
|
40
|
+
pagination.onChangeSize?.(Number(e.target.value));
|
|
41
|
+
}}>
|
|
42
|
+
{pagination.sizes.map((value) => (<option key={`pagination-opt-${value}`} value={value}>
|
|
43
|
+
{value}
|
|
44
|
+
</option>))}
|
|
45
|
+
</select>{" "}
|
|
46
|
+
</Fragment>) : null}/>
|
|
47
|
+
</p>
|
|
48
|
+
<nav>
|
|
49
|
+
<ul className="flex items-center gap-2">
|
|
50
|
+
{pagination.current > 1 ? (<li>
|
|
51
|
+
<Polymorph as={Link} href="previous" className="">
|
|
52
|
+
{translation.tablePaginationPrevious}
|
|
53
|
+
</Polymorph>
|
|
54
|
+
</li>) : null}
|
|
55
|
+
{pageNavigation.map((x) => {
|
|
56
|
+
if (x === null)
|
|
57
|
+
return null;
|
|
58
|
+
return (<Fragment key={`pagination-${x}`}>
|
|
59
|
+
{typeof x === "string" ? (<li>...</li>) : (<li>
|
|
60
|
+
<Polymorph href={x} as={Link} className={`cursor-pointer border-b-2 px-3 py-1 proportional-nums transition-colors hover:border-primary-subtle hover:text-primary-subtle ${x === pagination.current ? "border-primary text-primary" : "border-transparent"}`}>
|
|
61
|
+
{x}
|
|
62
|
+
</Polymorph>
|
|
63
|
+
</li>)}
|
|
64
|
+
</Fragment>);
|
|
65
|
+
})}
|
|
66
|
+
{hasNext ? (<li>
|
|
67
|
+
<Polymorph as={Link} href="next" className="">
|
|
68
|
+
{translation.tablePaginationNext}
|
|
69
|
+
</Polymorph>
|
|
70
|
+
</li>) : null}
|
|
71
|
+
</ul>
|
|
72
|
+
</nav>
|
|
73
|
+
</footer>);
|
|
74
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { CellAsideElement, Col } from "./table-lib";
|
|
3
|
+
type ItemContentContext<T extends Record<string, unknown>> = {
|
|
4
|
+
cols: Col<T>[];
|
|
5
|
+
loading?: boolean;
|
|
6
|
+
loadingMore?: boolean;
|
|
7
|
+
Aside?: React.FC<CellAsideElement<T>>;
|
|
8
|
+
};
|
|
9
|
+
export declare const Row: <T extends Record<string, unknown>>(index: number, row: T, context: ItemContentContext<T>) => React.JSX.Element;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=row.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"row.d.ts","sourceRoot":"","sources":["../../../src/components/table/row.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAwD,MAAM,OAAO,CAAC;AAI7E,OAAO,EAAE,gBAAgB,EAAoB,GAAG,EAAa,MAAM,aAAa,CAAC;AAEjF,KAAK,kBAAkB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;IACzD,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,KAAK,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC;CACzC,CAAC;AAoCF,eAAO,MAAM,GAAG,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,MAAM,EAAE,KAAK,CAAC,EAAE,SAAS,kBAAkB,CAAC,CAAC,CAAC,sBAgD3G,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import React, { Fragment, useRef, useState } from "react";
|
|
2
|
+
import { Is } from "sidekicker";
|
|
3
|
+
import { path } from "../../lib/fns";
|
|
4
|
+
import { SkeletonCell } from "../display/skeleton";
|
|
5
|
+
const RowAside = (props) => {
|
|
6
|
+
const parentRef = useRef(null);
|
|
7
|
+
const ref = useRef(null);
|
|
8
|
+
const [className, setClassName] = useState("opacity-0");
|
|
9
|
+
const ariaHidden = className === "opacity-0";
|
|
10
|
+
const onLeave = () => setClassName("opacity-0");
|
|
11
|
+
const onEnter = () => {
|
|
12
|
+
const child = ref.current;
|
|
13
|
+
const parent = parentRef.current;
|
|
14
|
+
if (child !== null && parent !== null) {
|
|
15
|
+
parent.style.left = `-${child.getBoundingClientRect().width + 4}px`;
|
|
16
|
+
}
|
|
17
|
+
setClassName("opacity-100");
|
|
18
|
+
};
|
|
19
|
+
return (<div ref={parentRef} onMouseEnter={onEnter} onMouseLeave={onLeave} data-component="cell-aside" inert={ariaHidden ? true : undefined} tabIndex={ariaHidden ? -1 : undefined} className={`group-table-cell-aside absolute inset-0 top-0 flex h-full w-full items-stretch transition-opacity duration-300 ease-in-out ${className}`}>
|
|
20
|
+
<div ref={ref} className="isolate block">
|
|
21
|
+
{props.children}
|
|
22
|
+
</div>
|
|
23
|
+
</div>);
|
|
24
|
+
};
|
|
25
|
+
export const Row = (index, row, context) => {
|
|
26
|
+
const cols = context.cols;
|
|
27
|
+
const loading = context.loading;
|
|
28
|
+
return (<Fragment>
|
|
29
|
+
{cols.map((col, colIndex) => {
|
|
30
|
+
const matrix = `${colIndex},${index}`;
|
|
31
|
+
const value = path(row, col.id);
|
|
32
|
+
const Component = col.Element;
|
|
33
|
+
const className = col.cellProps?.className || "";
|
|
34
|
+
const exposeAside = colIndex === 0 && context.Aside && loading === false;
|
|
35
|
+
const Aside = context.Aside;
|
|
36
|
+
return (<td {...col.cellProps} role="cell" data-matrix={matrix} key={`accessor-${index}-${colIndex}`} className={`typography group-table-cell flex border-collapse flex-col whitespace-pre-wrap border border-y border-b border-table-border p-[var(--table-cell-padding)] md:table-cell md:border-b-0 md:border-r md:border-l-transparent md:last:border-r-transparent ${className}`}>
|
|
37
|
+
{exposeAside ? (<RowAside>
|
|
38
|
+
<Aside col={col} row={row} rowIndex={index}/>
|
|
39
|
+
</RowAside>) : null}
|
|
40
|
+
<span className="block text-sm font-bold leading-tight md:hidden">{col.thead}</span>
|
|
41
|
+
<span className="relative">
|
|
42
|
+
{loading ? (SkeletonCell) : Component ? (<Fragment>
|
|
43
|
+
<Component row={row} matrix={matrix} col={col} rowIndex={index} value={value}/>
|
|
44
|
+
</Fragment>) : (<Fragment>{Is.nil(value) ? "" : value}</Fragment>)}
|
|
45
|
+
</span>
|
|
46
|
+
</td>);
|
|
47
|
+
})}
|
|
48
|
+
</Fragment>);
|
|
49
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Any, Label } from "../../types";
|
|
3
|
+
import { Col, TableConfiguration, TableOperationProps } from "./table-lib";
|
|
4
|
+
type Keyof<T extends Any> = keyof T extends infer R extends string ? R : never;
|
|
5
|
+
declare enum Order {
|
|
6
|
+
Asc = "asc",
|
|
7
|
+
Desc = "desc",
|
|
8
|
+
Undefined = "undefined"
|
|
9
|
+
}
|
|
10
|
+
export type Sorter<T extends Any> = {
|
|
11
|
+
value: Keyof<T>;
|
|
12
|
+
type: Order;
|
|
13
|
+
label: Label;
|
|
14
|
+
id: string;
|
|
15
|
+
};
|
|
16
|
+
export declare const multiSort: <T extends Any>(array: T[], fields: Sorter<T>[]) => T[];
|
|
17
|
+
type Props<T extends Any> = TableConfiguration<T, {
|
|
18
|
+
cols: Col<T>[];
|
|
19
|
+
sorters: Sorter<T>[];
|
|
20
|
+
set: React.Dispatch<React.SetStateAction<Sorter<T>[]>>;
|
|
21
|
+
}>;
|
|
22
|
+
export declare const Sort: <T extends Any>(props: Props<T>) => React.JSX.Element;
|
|
23
|
+
type SorterHeadProps<T extends Any> = Pick<TableOperationProps<T>, "sorters" | "setSorters"> & {
|
|
24
|
+
col: Col<T>;
|
|
25
|
+
};
|
|
26
|
+
export declare const SorterHead: <T extends Any>(props: SorterHeadProps<T>) => React.JSX.Element;
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=sort.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sort.d.ts","sourceRoot":"","sources":["../../../src/components/table/sort.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA6B,MAAM,OAAO,CAAC;AAGlD,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAE,GAAG,EAAY,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAErF,KAAK,KAAK,CAAC,CAAC,SAAS,GAAG,IAAI,MAAM,CAAC,SAAS,MAAM,CAAC,SAAS,MAAM,GAAG,CAAC,GAAG,KAAK,CAAC;AAE/E,aAAK,KAAK;IACN,GAAG,QAAQ;IACX,IAAI,SAAS;IACb,SAAS,cAAc;CAC1B;AAED,MAAM,MAAM,MAAM,CAAC,CAAC,SAAS,GAAG,IAAI;IAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;IAAC,IAAI,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,KAAK,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;AAY/F,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,GAAG,EAAE,OAAO,CAAC,EAAE,EAAE,QAAQ,MAAM,CAAC,CAAC,CAAC,EAAE,QAGvE,CAAC;AAEF,KAAK,KAAK,CAAC,CAAC,SAAS,GAAG,IAAI,kBAAkB,CAC1C,CAAC,EACD;IACI,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IACf,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;IACrB,GAAG,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;CAC1D,CACJ,CAAC;AASF,eAAO,MAAM,IAAI,GAAI,CAAC,SAAS,GAAG,EAAE,OAAO,KAAK,CAAC,CAAC,CAAC,sBA0ElD,CAAC;AAEF,KAAK,eAAe,CAAC,CAAC,SAAS,GAAG,IAAI,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAC,EAAE,SAAS,GAAG,YAAY,CAAC,GAAG;IAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAA;CAAE,CAAC;AAE/G,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,GAAG,EAAE,OAAO,eAAe,CAAC,CAAC,CAAC,sBAkClE,CAAC"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { SortAscendingIcon, SortDescendingIcon, CaretUpDownIcon, PlusIcon, TrashIcon } from "@phosphor-icons/react";
|
|
3
|
+
import React, { Fragment, useState } from "react";
|
|
4
|
+
import { useTranslations } from "../../hooks/use-translations";
|
|
5
|
+
import { uuid } from "../../lib/fns";
|
|
6
|
+
import { Dropdown } from "../floating/dropdown";
|
|
7
|
+
import { Select } from "../form/select";
|
|
8
|
+
import { getLabel } from "./table-lib";
|
|
9
|
+
var Order;
|
|
10
|
+
(function (Order) {
|
|
11
|
+
Order["Asc"] = "asc";
|
|
12
|
+
Order["Desc"] = "desc";
|
|
13
|
+
Order["Undefined"] = "undefined";
|
|
14
|
+
})(Order || (Order = {}));
|
|
15
|
+
const createSorterFn = (fields) => (a, b) => fields.reduce((acc, x) => {
|
|
16
|
+
const reverse = x.type === "desc" ? -1 : 1;
|
|
17
|
+
const property = x.value;
|
|
18
|
+
const p = a[property] > b[property] ? reverse : a[property] < b[property] ? -reverse : 0;
|
|
19
|
+
return acc !== 0 ? acc : p;
|
|
20
|
+
}, 0);
|
|
21
|
+
export const multiSort = (array, fields) => {
|
|
22
|
+
array.sort(createSorterFn(fields));
|
|
23
|
+
return array;
|
|
24
|
+
};
|
|
25
|
+
const createSorter = (col, label, order) => ({
|
|
26
|
+
label,
|
|
27
|
+
id: uuid(),
|
|
28
|
+
type: order,
|
|
29
|
+
value: col.id,
|
|
30
|
+
});
|
|
31
|
+
export const Sort = (props) => {
|
|
32
|
+
const translation = useTranslations();
|
|
33
|
+
const orders = {
|
|
34
|
+
asc: { label: translation.tableSortAsc, value: Order.Asc },
|
|
35
|
+
desc: { label: translation.tableSortDesc, value: Order.Desc },
|
|
36
|
+
};
|
|
37
|
+
const orderOptions = [orders.asc, orders.desc];
|
|
38
|
+
const onAddSorter = () => {
|
|
39
|
+
const col = props.cols[0];
|
|
40
|
+
if (col)
|
|
41
|
+
props.set((prev) => [...prev, createSorter(col, orders.asc.label, orders.asc.value)]);
|
|
42
|
+
};
|
|
43
|
+
const onSetSorter = (id) => (e) => {
|
|
44
|
+
const value = e.target.value;
|
|
45
|
+
props.set((prev) => prev.map((x) => (x.id === id ? { ...x, value: value } : x)));
|
|
46
|
+
};
|
|
47
|
+
const onSortOrderType = (id) => (e) => {
|
|
48
|
+
const type = e.target.value;
|
|
49
|
+
props.set((prev) => prev.map((x) => (x.id === id ? { ...x, type: type } : x)));
|
|
50
|
+
};
|
|
51
|
+
const onDelete = (e) => {
|
|
52
|
+
const id = e.currentTarget.dataset.id || "";
|
|
53
|
+
props.set((prev) => prev.filter((x) => x.id !== id));
|
|
54
|
+
};
|
|
55
|
+
return (<Fragment>
|
|
56
|
+
<Dropdown title={translation.tableSortDropdownTitle} trigger={<span className="flex items-center gap-1 proportional-nums">
|
|
57
|
+
<CaretUpDownIcon size={14}/>
|
|
58
|
+
{translation.tableSortOrderByLabel} {props.sorters.length === 0 ? "" : ` (${props.sorters.length})`}
|
|
59
|
+
</span>}>
|
|
60
|
+
<ul className="mt-4 space-y-2">
|
|
61
|
+
{props.sorters.map((sorter) => {
|
|
62
|
+
return (<li key={`sorter-select-${sorter.id}`} className="flex flex-nowrap gap-3">
|
|
63
|
+
<Select options={props.options} value={sorter.value} onChange={onSetSorter(sorter.id)} title={translation.tableSortOrderInputTitle} placeholder={translation.tableSortOrderInputPlaceholder}/>
|
|
64
|
+
<Select onChange={onSortOrderType(sorter.id)} value={sorter.type} options={orderOptions} title={translation.tableSortTypeInputTitle} placeholder={translation.tableSortTypeInputPlaceholder}/>
|
|
65
|
+
<button className="mt-4" data-id={sorter.id} onClick={onDelete}>
|
|
66
|
+
<TrashIcon className="text-danger" size={14}/>
|
|
67
|
+
</button>
|
|
68
|
+
</li>);
|
|
69
|
+
})}
|
|
70
|
+
<li>
|
|
71
|
+
<button type="button" onClick={onAddSorter} className="flex items-center gap-1 text-primary">
|
|
72
|
+
<PlusIcon size={14}/> {translation.tableSortAddButton}
|
|
73
|
+
</button>
|
|
74
|
+
</li>
|
|
75
|
+
</ul>
|
|
76
|
+
</Dropdown>
|
|
77
|
+
</Fragment>);
|
|
78
|
+
};
|
|
79
|
+
export const SorterHead = (props) => {
|
|
80
|
+
const translations = useTranslations();
|
|
81
|
+
const [status, setStatus] = useState(() => {
|
|
82
|
+
const sorter = props.sorters.find((sort) => sort.value === props.col.id);
|
|
83
|
+
return sorter ? sorter.type : Order.Undefined;
|
|
84
|
+
});
|
|
85
|
+
const onClick = () => {
|
|
86
|
+
const next = status === Order.Undefined ? Order.Asc : status === Order.Asc ? Order.Desc : Order.Undefined;
|
|
87
|
+
setStatus(next);
|
|
88
|
+
props.setSorters((prev) => {
|
|
89
|
+
if (next === Order.Undefined)
|
|
90
|
+
return prev.filter((x) => x.value !== props.col.id);
|
|
91
|
+
const findIndex = prev.findIndex((p) => p.value === props.col.id);
|
|
92
|
+
const sorter = createSorter(props.col, next, next);
|
|
93
|
+
if (findIndex === -1)
|
|
94
|
+
return [...prev, sorter];
|
|
95
|
+
prev[findIndex] = sorter;
|
|
96
|
+
return [...prev];
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
const labelId = `${props.col.id}-sorter-id`;
|
|
100
|
+
const label = getLabel(props.col);
|
|
101
|
+
return (<button aria-labelledby={labelId} className="isolate flex items-center" onClick={onClick} type="button">
|
|
102
|
+
<span id={labelId} className="sr-only">
|
|
103
|
+
{translations.tableSortDropdownTitle} {label}
|
|
104
|
+
</span>
|
|
105
|
+
{status === Order.Asc ? <SortAscendingIcon size={14}/> : null}
|
|
106
|
+
{status === Order.Desc ? <SortDescendingIcon size={14}/> : null}
|
|
107
|
+
{status === Order.Undefined ? <CaretUpDownIcon size={14}/> : null}
|
|
108
|
+
</button>);
|
|
109
|
+
};
|