@g4rcez/components 3.0.0-0 → 3.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/ai/SKILL.md +266 -0
- package/dist/ai/docs/Alert.md +167 -0
- package/dist/ai/docs/AnimatedList.md +205 -0
- package/dist/ai/docs/Autocomplete.md +225 -0
- package/dist/ai/docs/Button.md +182 -0
- package/dist/ai/docs/Calendar.md +219 -0
- package/dist/ai/docs/Card.md +174 -0
- package/dist/ai/docs/Checkbox.md +199 -0
- package/dist/ai/docs/CommandPalette.md +293 -0
- package/dist/ai/docs/DatePicker.md +171 -0
- package/dist/ai/docs/Dropdown.md +223 -0
- package/dist/ai/docs/Empty.md +163 -0
- package/dist/ai/docs/Expand.md +143 -0
- package/dist/ai/docs/FileUpload.md +225 -0
- package/dist/ai/docs/Form.md +107 -0
- package/dist/ai/docs/FormReset.md +117 -0
- package/dist/ai/docs/Heading.md +88 -0
- package/dist/ai/docs/Input.md +237 -0
- package/dist/ai/docs/InputField.md +170 -0
- package/dist/ai/docs/List.md +205 -0
- package/dist/ai/docs/Menu.md +166 -0
- package/dist/ai/docs/Modal.md +280 -0
- package/dist/ai/docs/MultiSelect.md +196 -0
- package/dist/ai/docs/Notifications.md +231 -0
- package/dist/ai/docs/PageCalendar.md +271 -0
- package/dist/ai/docs/Polymorph.md +159 -0
- package/dist/ai/docs/Progress.md +145 -0
- package/dist/ai/docs/Radiobox.md +128 -0
- package/dist/ai/docs/RenderOnView.md +138 -0
- package/dist/ai/docs/Resizable.md +159 -0
- package/dist/ai/docs/Select.md +284 -0
- package/dist/ai/docs/Shortcut.md +105 -0
- package/dist/ai/docs/Skeleton.md +166 -0
- package/dist/ai/docs/Slider.md +144 -0
- package/dist/ai/docs/Slot.md +173 -0
- package/dist/ai/docs/Spinner.md +118 -0
- package/dist/ai/docs/Stats.md +137 -0
- package/dist/ai/docs/Step.md +159 -0
- package/dist/ai/docs/Switch.md +167 -0
- package/dist/ai/docs/Table.md +298 -0
- package/dist/ai/docs/Tabs.md +191 -0
- package/dist/ai/docs/Tag.md +224 -0
- package/dist/ai/docs/TaskList.md +144 -0
- package/dist/ai/docs/Textarea.md +167 -0
- package/dist/ai/docs/Timeline.md +210 -0
- package/dist/ai/docs/Toolbar.md +132 -0
- package/dist/ai/docs/Tooltip.md +231 -0
- package/dist/ai/docs/TransferList.md +142 -0
- package/dist/ai/docs/Typography.md +187 -0
- package/dist/ai/docs/Wizard.md +213 -0
- package/dist/ai/docs/index.md +183 -0
- package/dist/components/core/button.d.ts +2 -8
- package/dist/components/core/button.d.ts.map +1 -1
- package/dist/components/core/polymorph.d.ts.map +1 -1
- package/dist/components/core/slot.d.ts +1 -1
- package/dist/components/core/slot.d.ts.map +1 -1
- package/dist/components/core/tag.d.ts +2 -2
- package/dist/components/core/tag.d.ts.map +1 -1
- package/dist/components/core/typography.d.ts.map +1 -1
- package/dist/components/display/alert.d.ts.map +1 -1
- package/dist/components/display/calendar.d.ts.map +1 -1
- package/dist/components/display/card.d.ts.map +1 -1
- package/dist/components/display/list.d.ts.map +1 -1
- package/dist/components/display/notifications.d.ts +2 -0
- package/dist/components/display/notifications.d.ts.map +1 -1
- package/dist/components/display/progress.d.ts.map +1 -1
- package/dist/components/display/skeleton.d.ts.map +1 -1
- package/dist/components/display/step.d.ts.map +1 -1
- package/dist/components/display/tabs.d.ts.map +1 -1
- package/dist/components/floating/command-palette.d.ts +1 -0
- package/dist/components/floating/command-palette.d.ts.map +1 -1
- package/dist/components/floating/dropdown.d.ts +1 -0
- package/dist/components/floating/dropdown.d.ts.map +1 -1
- package/dist/components/floating/menu.d.ts +2 -2
- package/dist/components/floating/menu.d.ts.map +1 -1
- package/dist/components/floating/modal.d.ts +20 -53
- package/dist/components/floating/modal.d.ts.map +1 -1
- package/dist/components/floating/tooltip.d.ts.map +1 -1
- package/dist/components/floating/wizard.d.ts +1 -1
- package/dist/components/floating/wizard.d.ts.map +1 -1
- package/dist/components/form/autocomplete.d.ts.map +1 -1
- package/dist/components/form/date-picker.d.ts.map +1 -1
- package/dist/components/form/free-text.d.ts.map +1 -1
- package/dist/components/form/input-field.d.ts +3 -2
- package/dist/components/form/input-field.d.ts.map +1 -1
- package/dist/components/form/multi-select.d.ts.map +1 -1
- package/dist/components/form/select.d.ts.map +1 -1
- package/dist/components/form/slider.d.ts.map +1 -1
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.d.ts.map +1 -1
- 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/day-view.d.ts +12 -0
- package/dist/components/page-calendar/day-view.d.ts.map +1 -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/index.d.ts +4 -0
- package/dist/components/page-calendar/index.d.ts.map +1 -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/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.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.utils.d.ts +18 -0
- package/dist/components/page-calendar/page-calendar.utils.d.ts.map +1 -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/table/index.d.ts.map +1 -1
- package/dist/components/table/inner-table.d.ts.map +1 -1
- package/dist/components/table/metadata.d.ts.map +1 -1
- package/dist/components/table/row.d.ts.map +1 -1
- package/dist/components/table/table-lib.d.ts.map +1 -1
- package/dist/components/table/thead.d.ts.map +1 -1
- package/dist/config/context.d.ts.map +1 -1
- package/dist/config/default-translations.d.ts +21 -4
- package/dist/config/default-translations.d.ts.map +1 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/hooks/use-components-provider.d.ts.map +1 -1
- package/dist/hooks/use-form.d.ts +11 -11
- package/dist/hooks/use-form.d.ts.map +1 -1
- package/dist/hooks/use-input-id.d.ts.map +1 -1
- package/dist/hooks/use-preferences.d.ts.map +1 -1
- package/dist/hooks/use-previous.d.ts.map +1 -1
- package/dist/hooks/use-reactive.d.ts.map +1 -1
- package/dist/hooks/use-resize-observer.d.ts.map +1 -1
- package/dist/hooks/use-stable-ref.d.ts.map +1 -1
- package/dist/hooks/use-swipe.d.ts.map +1 -1
- package/dist/hooks/use-translations.d.ts +21 -4
- package/dist/hooks/use-translations.d.ts.map +1 -1
- package/dist/index.css +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +28 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +13862 -12512
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +24 -17
- package/dist/index.umd.js.map +1 -1
- package/dist/lib/dom.d.ts +1 -0
- package/dist/lib/dom.d.ts.map +1 -1
- package/dist/lib/fns.d.ts.map +1 -1
- package/dist/preset/plugin.tailwind.d.ts +9 -0
- package/dist/preset/plugin.tailwind.d.ts.map +1 -0
- package/dist/preset/plugin.tailwind.js +27 -0
- package/dist/preset/preset.tailwind.d.ts +8 -0
- package/dist/preset/preset.tailwind.d.ts.map +1 -0
- package/dist/preset/preset.tailwind.js +54 -0
- package/dist/preset/src/styles/common.d.ts +2 -14
- package/dist/preset/src/styles/common.d.ts.map +1 -1
- package/dist/preset/src/styles/common.js +1 -0
- package/dist/preset/src/styles/dark.d.ts.map +1 -1
- package/dist/preset/src/styles/dark.js +119 -114
- package/dist/preset/src/styles/light.d.ts.map +1 -1
- package/dist/preset/src/styles/light.js +111 -106
- package/dist/preset/src/styles/theme.types.d.ts +17 -8
- package/dist/preset/src/styles/theme.types.d.ts.map +1 -1
- package/dist/styles/common.d.ts +2 -14
- package/dist/styles/common.d.ts.map +1 -1
- package/dist/styles/dark.d.ts.map +1 -1
- package/dist/styles/light.d.ts.map +1 -1
- package/dist/styles/theme.types.d.ts +17 -8
- package/dist/styles/theme.types.d.ts.map +1 -1
- package/package.json +299 -301
- package/dist/components/core/button.jsx +0 -86
- package/dist/components/core/heading.jsx +0 -4
- package/dist/components/core/polymorph.jsx +0 -5
- package/dist/components/core/render-on-view.jsx +0 -31
- package/dist/components/core/resizable.jsx +0 -51
- package/dist/components/core/slot.jsx +0 -163
- package/dist/components/core/tag.jsx +0 -51
- package/dist/components/core/typography.jsx +0 -26
- package/dist/components/display/alert.jsx +0 -56
- package/dist/components/display/calendar.jsx +0 -301
- package/dist/components/display/card.jsx +0 -43
- package/dist/components/display/empty.jsx +0 -11
- package/dist/components/display/list.jsx +0 -81
- package/dist/components/display/notifications.jsx +0 -98
- package/dist/components/display/progress.jsx +0 -13
- package/dist/components/display/shortcut.jsx +0 -23
- package/dist/components/display/skeleton.jsx +0 -14
- package/dist/components/display/spinner.jsx +0 -7
- package/dist/components/display/stats.jsx +0 -20
- package/dist/components/display/step.jsx +0 -131
- package/dist/components/display/tabs.jsx +0 -100
- package/dist/components/display/timeline.jsx +0 -25
- package/dist/components/floating/command-palette.jsx +0 -172
- package/dist/components/floating/dropdown.jsx +0 -53
- package/dist/components/floating/expand.jsx +0 -44
- package/dist/components/floating/menu.jsx +0 -147
- package/dist/components/floating/modal.jsx +0 -241
- package/dist/components/floating/toolbar.jsx +0 -5
- package/dist/components/floating/tooltip.jsx +0 -64
- package/dist/components/floating/wizard.jsx +0 -164
- package/dist/components/form/autocomplete.jsx +0 -275
- package/dist/components/form/checkbox.jsx +0 -12
- package/dist/components/form/date-picker.jsx +0 -115
- package/dist/components/form/file-upload.jsx +0 -133
- package/dist/components/form/form.jsx +0 -10
- package/dist/components/form/formReset.jsx +0 -17
- package/dist/components/form/free-text.jsx +0 -41
- package/dist/components/form/input-field.jsx +0 -54
- package/dist/components/form/input.jsx +0 -36
- package/dist/components/form/multi-select.jsx +0 -328
- package/dist/components/form/radiobox.jsx +0 -6
- package/dist/components/form/select.jsx +0 -42
- package/dist/components/form/slider.jsx +0 -45
- package/dist/components/form/switch.jsx +0 -46
- package/dist/components/form/task-list.jsx +0 -26
- package/dist/components/form/textarea.jsx +0 -12
- package/dist/components/form/transfer-list.jsx +0 -39
- package/dist/components/index.js +0 -43
- package/dist/components/table/filter.jsx +0 -141
- package/dist/components/table/group.jsx +0 -68
- package/dist/components/table/index.jsx +0 -60
- package/dist/components/table/inner-table.jsx +0 -104
- package/dist/components/table/metadata.jsx +0 -37
- package/dist/components/table/pagination.jsx +0 -73
- package/dist/components/table/row.jsx +0 -58
- package/dist/components/table/sort.jsx +0 -105
- package/dist/components/table/table-lib.js +0 -84
- package/dist/components/table/table.context.jsx +0 -4
- package/dist/components/table/thead.jsx +0 -103
- package/dist/config/context.js +0 -12
- package/dist/config/default-translations.jsx +0 -66
- package/dist/config/default-tweaks.js +0 -4
- package/dist/constants.js +0 -2
- package/dist/hooks/use-click-outside.js +0 -17
- package/dist/hooks/use-color-parser.js +0 -9
- package/dist/hooks/use-components-provider.jsx +0 -16
- package/dist/hooks/use-debounce.js +0 -12
- package/dist/hooks/use-floating-ref.js +0 -6
- package/dist/hooks/use-form.js +0 -549
- package/dist/hooks/use-hover.js +0 -18
- package/dist/hooks/use-input-id.js +0 -5
- package/dist/hooks/use-is-coarse-device.js +0 -12
- package/dist/hooks/use-locale.js +0 -10
- package/dist/hooks/use-media-query.js +0 -25
- package/dist/hooks/use-on-event.js +0 -7
- package/dist/hooks/use-parent.js +0 -21
- package/dist/hooks/use-preferences.js +0 -23
- package/dist/hooks/use-previous.js +0 -8
- package/dist/hooks/use-reactive.js +0 -8
- package/dist/hooks/use-remove-scroll.js +0 -61
- package/dist/hooks/use-resize-observer.js +0 -17
- package/dist/hooks/use-stable-ref.js +0 -8
- package/dist/hooks/use-swipe.js +0 -16
- package/dist/hooks/use-translations.js +0 -9
- package/dist/hooks/use-tweaks.js +0 -9
- package/dist/hooks/use-window-size.js +0 -14
- package/dist/lib/combi-keys.js +0 -60
- package/dist/lib/dict.js +0 -39
- package/dist/lib/dom.js +0 -44
- package/dist/lib/fns.js +0 -46
- package/dist/lib/fzf.js +0 -117
- package/dist/lib/keyboard-area.js +0 -14
- package/dist/preset/tailwindcssv4.d.ts +0 -3
- package/dist/preset/tailwindcssv4.d.ts.map +0 -1
- package/dist/preset/tailwindcssv4.js +0 -75
- package/dist/styles/common.js +0 -28
- package/dist/styles/dark.js +0 -209
- package/dist/styles/design-tokens.js +0 -69
- package/dist/styles/light.js +0 -209
- package/dist/styles/theme.js +0 -4
- package/dist/styles/theme.types.js +0 -1
- package/dist/types.js +0 -1
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { ArrowDown01Icon, ArrowUp01Icon, ArrowUpDownIcon, PlusIcon, Trash2Icon } from "lucide-react";
|
|
3
|
-
import React, { Fragment, useEffect, 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) => array.toSorted(createSorterFn(fields));
|
|
22
|
-
const createSorter = (col, label, order) => ({
|
|
23
|
-
label,
|
|
24
|
-
id: uuid(),
|
|
25
|
-
type: order,
|
|
26
|
-
value: col.id,
|
|
27
|
-
});
|
|
28
|
-
export const Sort = (props) => {
|
|
29
|
-
const translation = useTranslations();
|
|
30
|
-
const orders = {
|
|
31
|
-
asc: { label: translation.tableSortAsc, value: Order.Asc },
|
|
32
|
-
desc: { label: translation.tableSortDesc, value: Order.Desc },
|
|
33
|
-
};
|
|
34
|
-
const orderOptions = [orders.asc, orders.desc];
|
|
35
|
-
const onAddSorter = () => {
|
|
36
|
-
const col = props.cols[0];
|
|
37
|
-
if (col)
|
|
38
|
-
props.set((prev) => [...prev, createSorter(col, orders.asc.label, orders.asc.value)]);
|
|
39
|
-
};
|
|
40
|
-
const onSetSorter = (id) => (e) => {
|
|
41
|
-
const value = e.target.value;
|
|
42
|
-
props.set((prev) => prev.map((x) => (x.id === id ? { ...x, value: value } : x)));
|
|
43
|
-
};
|
|
44
|
-
const onSortOrderType = (id) => (e) => {
|
|
45
|
-
const type = e.target.value;
|
|
46
|
-
props.set((prev) => prev.map((x) => (x.id === id ? { ...x, type: type } : x)));
|
|
47
|
-
};
|
|
48
|
-
const onDelete = (e) => {
|
|
49
|
-
const id = e.currentTarget.dataset.id || "";
|
|
50
|
-
props.set((prev) => prev.filter((x) => x.id !== id));
|
|
51
|
-
};
|
|
52
|
-
return (<Fragment>
|
|
53
|
-
<Dropdown title={translation.tableSortDropdownTitle} trigger={<span className="flex items-center gap-1 proportional-nums">
|
|
54
|
-
<ArrowUpDownIcon size={14}/>
|
|
55
|
-
{translation.tableSortOrderByLabel} {props.sorters.length === 0 ? "" : ` (${props.sorters.length})`}
|
|
56
|
-
</span>}>
|
|
57
|
-
<ul className="mt-4 space-y-2">
|
|
58
|
-
{props.sorters.map((sorter) => {
|
|
59
|
-
return (<li key={`sorter-select-${sorter.id}`} className="flex flex-nowrap gap-3">
|
|
60
|
-
<Select options={props.options} value={sorter.value} onChange={onSetSorter(sorter.id)} title={translation.tableSortOrderInputTitle} placeholder={translation.tableSortOrderInputPlaceholder}/>
|
|
61
|
-
<Select onChange={onSortOrderType(sorter.id)} value={sorter.type} options={orderOptions} title={translation.tableSortTypeInputTitle} placeholder={translation.tableSortTypeInputPlaceholder}/>
|
|
62
|
-
<button className="mt-4" data-id={sorter.id} onClick={onDelete}>
|
|
63
|
-
<Trash2Icon className="text-danger" size={14}/>
|
|
64
|
-
</button>
|
|
65
|
-
</li>);
|
|
66
|
-
})}
|
|
67
|
-
<li>
|
|
68
|
-
<button type="button" onClick={onAddSorter} className="text-primary flex items-center gap-1">
|
|
69
|
-
<PlusIcon size={14}/> {translation.tableSortAddButton}
|
|
70
|
-
</button>
|
|
71
|
-
</li>
|
|
72
|
-
</ul>
|
|
73
|
-
</Dropdown>
|
|
74
|
-
</Fragment>);
|
|
75
|
-
};
|
|
76
|
-
export const SorterHead = (props) => {
|
|
77
|
-
const translations = useTranslations();
|
|
78
|
-
const [status, setStatus] = useState(() => {
|
|
79
|
-
const sorter = props.sorters.find((sort) => sort.value === props.col.id);
|
|
80
|
-
return sorter ? sorter.type : Order.Undefined;
|
|
81
|
-
});
|
|
82
|
-
const onClick = () => setStatus((prev) => (prev === Order.Undefined ? Order.Asc : prev === Order.Asc ? Order.Desc : Order.Undefined));
|
|
83
|
-
useEffect(() => {
|
|
84
|
-
props.setSorters((prev) => {
|
|
85
|
-
if (status === Order.Undefined)
|
|
86
|
-
return prev.filter((x) => x.value !== props.col.id);
|
|
87
|
-
const findIndex = prev.findIndex((p) => p.value === props.col.id);
|
|
88
|
-
const sorter = createSorter(props.col, status, status);
|
|
89
|
-
if (findIndex === -1)
|
|
90
|
-
return [...prev, sorter];
|
|
91
|
-
prev[findIndex] = sorter;
|
|
92
|
-
return [...prev];
|
|
93
|
-
});
|
|
94
|
-
}, [status, props.col]);
|
|
95
|
-
const labelId = `${props.col.id}-sorter-id`;
|
|
96
|
-
const label = getLabel(props.col);
|
|
97
|
-
return (<button aria-labelledby={labelId} className="isolate flex items-center" onClick={onClick} type="button">
|
|
98
|
-
<span id={labelId} className="sr-only">
|
|
99
|
-
{translations.tableSortDropdownTitle} {label}
|
|
100
|
-
</span>
|
|
101
|
-
{status === Order.Asc ? <ArrowUp01Icon size={14}/> : null}
|
|
102
|
-
{status === Order.Desc ? <ArrowDown01Icon size={14}/> : null}
|
|
103
|
-
{status === Order.Undefined ? <ArrowUpDownIcon size={14}/> : null}
|
|
104
|
-
</button>);
|
|
105
|
-
};
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useCallback, useRef } from "react";
|
|
3
|
-
import { LocalStorage } from "storage-manager-js";
|
|
4
|
-
import { useReducer } from "use-typed-reducer";
|
|
5
|
-
import { useStableRef } from "../../hooks/use-stable-ref";
|
|
6
|
-
import { isSsr } from "../../lib/fns";
|
|
7
|
-
export const getLabel = (col) => col.headerLabel ?? col.thead ?? col.id;
|
|
8
|
-
export const createOptionCols = (cols) => cols.map((opt) => ({
|
|
9
|
-
value: opt.id,
|
|
10
|
-
label: (opt.thead ?? opt.headerLabel ?? opt.id),
|
|
11
|
-
}));
|
|
12
|
-
export var ColType;
|
|
13
|
-
(function (ColType) {
|
|
14
|
-
ColType["Boolean"] = "boolean";
|
|
15
|
-
ColType["Number"] = "number";
|
|
16
|
-
ColType["Select"] = "select";
|
|
17
|
-
ColType["Text"] = "text";
|
|
18
|
-
})(ColType || (ColType = {}));
|
|
19
|
-
export const valueFromType = (input) => (input.type === "number" ? input.valueAsNumber : input.value);
|
|
20
|
-
;
|
|
21
|
-
const cols = () => (id, thead, options) => ({ ...options, id, thead });
|
|
22
|
-
export const createColumns = (callback) => {
|
|
23
|
-
let items = [];
|
|
24
|
-
const add = (id, thead, options) => items.push({ ...options, id, thead });
|
|
25
|
-
const remove = (id) => (items = items.filter((x) => x.id !== id));
|
|
26
|
-
const getAll = () => Array.from(items);
|
|
27
|
-
const filter = (c) => (items = Array.from(items.filter(c)));
|
|
28
|
-
callback({ add, remove, getAll, filter });
|
|
29
|
-
return items;
|
|
30
|
-
};
|
|
31
|
-
const noop = {};
|
|
32
|
-
const mergeCols = (cols, saved) => {
|
|
33
|
-
if (!Array.isArray(saved))
|
|
34
|
-
return cols;
|
|
35
|
-
const savedSet = new Set(saved.map((x) => x.id));
|
|
36
|
-
if (!cols.every((x) => savedSet.has(x.id))) {
|
|
37
|
-
return cols;
|
|
38
|
-
}
|
|
39
|
-
const map = new Map(cols.map((x) => [x.id, x]));
|
|
40
|
-
return saved.map((mock, index) => {
|
|
41
|
-
const original = map.get(mock.id);
|
|
42
|
-
if (original === undefined)
|
|
43
|
-
return cols[index];
|
|
44
|
-
return original;
|
|
45
|
-
});
|
|
46
|
-
};
|
|
47
|
-
export const useTablePreferences = (name, cols, options = noop) => {
|
|
48
|
-
const init = isSsr() ? null : LocalStorage.get(`@components/table-${name}`) || null;
|
|
49
|
-
const [state, dispatch] = useReducer({
|
|
50
|
-
name,
|
|
51
|
-
groups: options.groups || init?.groups || [],
|
|
52
|
-
sorters: options.sorters || init?.sorters || [],
|
|
53
|
-
filters: options.filters || init?.filters || [],
|
|
54
|
-
cols: mergeCols(cols, init?.cols),
|
|
55
|
-
}, (get) => {
|
|
56
|
-
const intercept = (partial) => {
|
|
57
|
-
const prev = get.state();
|
|
58
|
-
const result = { ...prev, ...partial };
|
|
59
|
-
if (!isSsr())
|
|
60
|
-
LocalStorage.set(`@components/table-${prev.name}`, result);
|
|
61
|
-
return result;
|
|
62
|
-
};
|
|
63
|
-
intercept(get.state());
|
|
64
|
-
return {
|
|
65
|
-
set: (getters) => intercept(getters),
|
|
66
|
-
};
|
|
67
|
-
});
|
|
68
|
-
return { ...state, ...dispatch, name };
|
|
69
|
-
};
|
|
70
|
-
export const useWidthControl = (reorder) => {
|
|
71
|
-
const stableRef = useStableRef(reorder);
|
|
72
|
-
const ref = useRef(null);
|
|
73
|
-
const onChange = useCallback((cols) => {
|
|
74
|
-
stableRef.current(cols);
|
|
75
|
-
cols.forEach((x) => {
|
|
76
|
-
const c = ref.current.querySelector(`th[data-tableheader="${x.id}"]`);
|
|
77
|
-
if (!c)
|
|
78
|
-
return;
|
|
79
|
-
c.style.width = "auto";
|
|
80
|
-
});
|
|
81
|
-
}, [stableRef]);
|
|
82
|
-
return [ref, onChange];
|
|
83
|
-
};
|
|
84
|
-
export const getModalScrollerRef = () => isSsr() ? undefined : document.querySelector(`[data-component="modal-body"]`);
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { AnimatePresence, motion, Reorder } from "motion/react";
|
|
3
|
-
import { Order } from "linq-arrays";
|
|
4
|
-
import { PlusIcon, SearchCheckIcon, SearchXIcon } from "lucide-react";
|
|
5
|
-
import React, { Fragment, useCallback, useRef } from "react";
|
|
6
|
-
import { useTranslations } from "../../hooks/use-translations";
|
|
7
|
-
import { useTweaks } from "../../hooks/use-tweaks";
|
|
8
|
-
import { Dropdown } from "../floating/dropdown";
|
|
9
|
-
import { ColumnHeaderFilter, createFilterFromCol, useOperators } from "./filter";
|
|
10
|
-
import { SorterHead } from "./sort";
|
|
11
|
-
import { getLabel, useWidthControl } from "./table-lib";
|
|
12
|
-
const dragConstraints = { top: 0, left: 0, right: 0, bottom: -1 };
|
|
13
|
-
const HeaderChild = (props) => {
|
|
14
|
-
const tweaks = useTweaks();
|
|
15
|
-
const translation = useTranslations();
|
|
16
|
-
const ownFilters = props.filters.filter((x) => x.name === props.header.id);
|
|
17
|
-
const hasFilters = ownFilters.length > 0;
|
|
18
|
-
const defaultAllowSort = props.header.allowSort ?? tweaks.table.sorters ?? true;
|
|
19
|
-
const defaultAllowFilter = props.header.allowFilter ?? tweaks.table.filters ?? true;
|
|
20
|
-
const operators = useOperators();
|
|
21
|
-
const FilterIcon = hasFilters ? SearchCheckIcon : SearchXIcon;
|
|
22
|
-
const th = useRef(null);
|
|
23
|
-
const onDelete = (e) => {
|
|
24
|
-
const id = e.currentTarget.dataset.id || "";
|
|
25
|
-
return props.setFilters((prev) => prev.filter((x) => x.id !== id));
|
|
26
|
-
};
|
|
27
|
-
const dragRef = useCallback((dom) => {
|
|
28
|
-
if (dom === null)
|
|
29
|
-
return;
|
|
30
|
-
th.current = dom;
|
|
31
|
-
const controller = new AbortController();
|
|
32
|
-
dom.addEventListener("pointerdown", (e) => {
|
|
33
|
-
const target = e.target;
|
|
34
|
-
if (target.dataset.type === "resizer") {
|
|
35
|
-
e.stopPropagation();
|
|
36
|
-
return e.stopImmediatePropagation();
|
|
37
|
-
}
|
|
38
|
-
}, { signal: controller.signal });
|
|
39
|
-
return () => controller.abort();
|
|
40
|
-
}, []);
|
|
41
|
-
const ownSorter = props.sorters.find((x) => props.header.id === x.value);
|
|
42
|
-
const ariaSort = !ownSorter?.type ? "none" : ownSorter.type === Order.Asc ? "ascending" : "descending";
|
|
43
|
-
const label = getLabel(props.header);
|
|
44
|
-
return (<Reorder.Item {...props.header.thProps} as="th" ref={dragRef} initial={false} dragSnapToOrigin dragDirectionLock role="columnheader" aria-sort={ariaSort} value={props.header} aria-busy={props.loading} data-tableheader={props.header.id} whileDrag={{ cursor: "grabbing" }} className={`relative md:h-14 typography min-w-0 cursor-grab font-medium ${props.header.thProps?.className ?? ""}`}>
|
|
45
|
-
<span className={`flex h-full items-center justify-between bg-table-header p-(--table-cell-padding) ${props.isLast ? "rounded-tr-lg" : ""} ${props.index === 0 ? "rounded-tl-lg" : ""}`}>
|
|
46
|
-
<span className="flex gap-1 items-center">
|
|
47
|
-
{props.inlineFilter && defaultAllowFilter ? (<Dropdown arrow trigger={<span>
|
|
48
|
-
<span id={`${props.header.id}-filter-dropdown-button`} className="sr-only">
|
|
49
|
-
{translation.tableFilterDropdownTitleUnique} {label}
|
|
50
|
-
</span>
|
|
51
|
-
<FilterIcon aria-labelledby={`${props.header.id}-filter-dropdown-button`} size={14}/>
|
|
52
|
-
</span>} title={<span className="text-lg">
|
|
53
|
-
{translation.tableFilterDropdownTitleUnique} <span className="font-medium">{label}</span>
|
|
54
|
-
</span>}>
|
|
55
|
-
<ul className="font-medium">
|
|
56
|
-
{ownFilters.length === 0 ? null : (<Fragment>
|
|
57
|
-
{ownFilters.map((filter) => (<li key={`thead-filter-${filter.id}`} className="my-1">
|
|
58
|
-
<ColumnHeaderFilter onDelete={onDelete} filter={filter} set={props.setFilters}/>
|
|
59
|
-
</li>))}
|
|
60
|
-
</Fragment>)}
|
|
61
|
-
<li>
|
|
62
|
-
<button type="button" className="flex gap-1 items-center text-primary" onClick={() => props.setFilters((prev) => prev.concat(createFilterFromCol(props.header, operators.options, operators.operations)))}>
|
|
63
|
-
<PlusIcon size={14}/> {translation.tableFilterNewFilter}
|
|
64
|
-
</button>
|
|
65
|
-
</li>
|
|
66
|
-
</ul>
|
|
67
|
-
</Dropdown>) : null}
|
|
68
|
-
<span className="text-base pointer-events-auto text-balance">{props.header.thead}</span>
|
|
69
|
-
{props.inlineSorter && defaultAllowSort ? (<SorterHead col={props.header} setSorters={props.setSorters} sorters={props.sorters}/>) : null}
|
|
70
|
-
</span>
|
|
71
|
-
</span>
|
|
72
|
-
{props.isLast ? null : (<motion.button drag="x" draggable dragListener dragMomentum type="button" animate={false} dragElastic={0} dragPropagation initial={false} dragSnapToOrigin dragDirectionLock data-type="resizer" title={props.header.id} dragConstraints={dragConstraints} className="block absolute top-0 h-full hover:w-1.5 active:w-1.5 -right-[0.5px] z-calendar w-px cursor-col-resize bg-transparent hover:bg-primary active:bg-primary" onClick={(e) => void e.currentTarget.focus()} onKeyDown={(e) => {
|
|
73
|
-
if (e.key === "ArrowLeft" || e.key === "ArrowRight") {
|
|
74
|
-
if (th.current === null)
|
|
75
|
-
return;
|
|
76
|
-
th.current.setAttribute("data-resized", "true");
|
|
77
|
-
const v = th.current.getBoundingClientRect().width;
|
|
78
|
-
const move = e.shiftKey ? 50 : 10;
|
|
79
|
-
const delta = move * (e.key === "ArrowLeft" ? -1 : 1);
|
|
80
|
-
th.current.style.width = `${Math.abs(v + delta)}px`;
|
|
81
|
-
}
|
|
82
|
-
}} onDoubleClick={() => {
|
|
83
|
-
if (th.current === null)
|
|
84
|
-
return;
|
|
85
|
-
th.current.style.width = "auto";
|
|
86
|
-
}} onDrag={(_, info) => {
|
|
87
|
-
if (th.current === null)
|
|
88
|
-
return;
|
|
89
|
-
th.current.setAttribute("data-resized", "true");
|
|
90
|
-
const v = th.current.getBoundingClientRect().width;
|
|
91
|
-
const delta = info.delta.x;
|
|
92
|
-
th.current.style.width = `${Math.abs(v + delta)}px`;
|
|
93
|
-
}}/>)}
|
|
94
|
-
</Reorder.Item>);
|
|
95
|
-
};
|
|
96
|
-
export const TableHeader = (props) => {
|
|
97
|
-
const [ref, onChange] = useWidthControl(props.setCols);
|
|
98
|
-
return (<Reorder.Group layout as="tr" axis="x" drag="x" ref={ref} layoutRoot role="row" layoutScroll onReorder={onChange} values={props.headers}>
|
|
99
|
-
<AnimatePresence>
|
|
100
|
-
{props.headers.map((header, index) => (<HeaderChild index={index} header={header} filters={props.filters} loading={props.loading} sorters={props.sorters} setFilters={props.setFilters} setSorters={props.setSorters} inlineFilter={props.inlineFilter} inlineSorter={props.inlineSorter} isLast={index === props.headers.length - 1} key={`header-child-item-${header.id}`}/>))}
|
|
101
|
-
</AnimatePresence>
|
|
102
|
-
</Reorder.Group>);
|
|
103
|
-
};
|
package/dist/config/context.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { createContext } from "react";
|
|
3
|
-
import { parsers } from "../styles/design-tokens";
|
|
4
|
-
import { defaultTranslations } from "./default-translations";
|
|
5
|
-
import { defaultTweaks } from "./default-tweaks";
|
|
6
|
-
export const Context = createContext({
|
|
7
|
-
parser: parsers.hsla,
|
|
8
|
-
tweaks: defaultTweaks,
|
|
9
|
-
floatingRef: undefined,
|
|
10
|
-
map: defaultTranslations,
|
|
11
|
-
locale: undefined,
|
|
12
|
-
});
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import React, { Fragment } from "react";
|
|
2
|
-
export const defaultTranslations = {
|
|
3
|
-
autocompleteEmpty: "Nothing here...",
|
|
4
|
-
calendarBackMonth: "Back month",
|
|
5
|
-
calendarFromDate: "From",
|
|
6
|
-
calendarMonthLabel: "Month",
|
|
7
|
-
calendarNextMonth: "Next month",
|
|
8
|
-
calendarDatetimeTitle: "Time",
|
|
9
|
-
calendarToDate: "To",
|
|
10
|
-
calendarToday: "Today",
|
|
11
|
-
commandPaletteEmpty: "Nothing here...",
|
|
12
|
-
commandPaletteLoading: "Loading...",
|
|
13
|
-
datePickerCalendarButtonLabel: "Click to open a date picker",
|
|
14
|
-
emptyDataMessage: "No data",
|
|
15
|
-
inputCaretDown: "Click to see all options",
|
|
16
|
-
inputCloseValue: "Click to clear the value",
|
|
17
|
-
inputOptionalLabel: "Optional",
|
|
18
|
-
driverNext: "Next",
|
|
19
|
-
driverPrevious: "Previous",
|
|
20
|
-
driverFinish: "Finish",
|
|
21
|
-
driverSkip: "Skip",
|
|
22
|
-
multiSelectInnerPlaceholder: "Search...",
|
|
23
|
-
multiSelectSelectedLabel: "Selected",
|
|
24
|
-
tableColumnResizer: "Resize column",
|
|
25
|
-
tableFilterColumnPlaceholder: "Filter by",
|
|
26
|
-
tableFilterColumnTitle: "Filter by",
|
|
27
|
-
tableFilterDropdownTitle: "Filters",
|
|
28
|
-
tableFilterDropdownTitleUnique: "Filter by",
|
|
29
|
-
tableFilterLabel: "Filters",
|
|
30
|
-
tableFilterNewFilter: "New filter",
|
|
31
|
-
tableFilterOperatorPlaceholder: "Equals to...",
|
|
32
|
-
tableFilterOperatorTitle: "Operation",
|
|
33
|
-
tableFilterTypeContains: "Contains",
|
|
34
|
-
tableFilterTypeEndsWith: "Ends with",
|
|
35
|
-
tableFilterTypeGreaterThan: "Greater than",
|
|
36
|
-
tableFilterTypeIs: "Is",
|
|
37
|
-
tableFilterTypeIsNot: "Is not",
|
|
38
|
-
tableFilterTypeLessThan: "Less than",
|
|
39
|
-
tableFilterTypeNotContains: "Not contains",
|
|
40
|
-
tableFilterTypeStartsWith: "Starts with",
|
|
41
|
-
tableFilterValuePlaceholder: "Something...",
|
|
42
|
-
tableFilterValueTitle: "Value",
|
|
43
|
-
tableGroupLabel: "Group",
|
|
44
|
-
tableGroupLabelWithCount: "Group",
|
|
45
|
-
tablePaginationFooter: (pagination) => (<Fragment>
|
|
46
|
-
{pagination.current} to {pagination.pages} of {pagination.totalItems} items.{Array.isArray(pagination.sizes) ? pagination.select : null}{" "}
|
|
47
|
-
per page.
|
|
48
|
-
</Fragment>),
|
|
49
|
-
tablePaginationNext: "Next",
|
|
50
|
-
tablePaginationPrevious: "Previous",
|
|
51
|
-
tablePaginationSelectLabel: "Select the size of page",
|
|
52
|
-
tableSortAddButton: "Add sort",
|
|
53
|
-
tableSortAsc: "Ascending",
|
|
54
|
-
tableSortDesc: "Descending",
|
|
55
|
-
tableSortDropdownTitle: "Order by",
|
|
56
|
-
tableSortOrderByLabel: "Order by",
|
|
57
|
-
tableSortOrderInputPlaceholder: "Order by",
|
|
58
|
-
tableSortOrderInputTitle: "Order by",
|
|
59
|
-
tableSortTypeInputPlaceholder: "Ascending",
|
|
60
|
-
tableSortTypeInputTitle: "Sort type",
|
|
61
|
-
uploadIdle: "You can drag your files here",
|
|
62
|
-
uploadIdleButton: "Choose your files",
|
|
63
|
-
uploadDragging: (props) => `Dragging ${props.n} ${props.n > 0 ? "files" : "file"}`,
|
|
64
|
-
uploadDialogTitle: "Details of your file",
|
|
65
|
-
datepickerPlaceholder: (_) => "day/month/year"
|
|
66
|
-
};
|
package/dist/constants.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { useEffect } from "react";
|
|
2
|
-
export const useOnClickOutside = (ref, handler) => {
|
|
3
|
-
useEffect(() => {
|
|
4
|
-
const listener = (event) => {
|
|
5
|
-
if (!ref.current || ref.current.contains(event.target))
|
|
6
|
-
return;
|
|
7
|
-
handler(event);
|
|
8
|
-
};
|
|
9
|
-
const params = { passive: true };
|
|
10
|
-
document.addEventListener("mousedown", listener, params);
|
|
11
|
-
document.addEventListener("touchstart", listener, params);
|
|
12
|
-
return () => {
|
|
13
|
-
document.removeEventListener("mousedown", listener);
|
|
14
|
-
document.removeEventListener("touchstart", listener);
|
|
15
|
-
};
|
|
16
|
-
}, [ref, handler]);
|
|
17
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { useContext } from "react";
|
|
2
|
-
import { Context } from "../config/context";
|
|
3
|
-
import { parsers } from "../styles/design-tokens";
|
|
4
|
-
export const useColorParser = () => {
|
|
5
|
-
const ctx = useContext(Context);
|
|
6
|
-
if (!ctx)
|
|
7
|
-
return parsers.hsla;
|
|
8
|
-
return ctx.parser;
|
|
9
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import React, { useMemo } from "react";
|
|
3
|
-
import { parsers } from "../styles/design-tokens";
|
|
4
|
-
import { Context } from "../config/context";
|
|
5
|
-
import { defaultTranslations } from "../config/default-translations";
|
|
6
|
-
import { defaultTweaks } from "../config/default-tweaks";
|
|
7
|
-
export const ComponentsProvider = (props) => {
|
|
8
|
-
const memoMap = useMemo(() => ({
|
|
9
|
-
locale: props.locale,
|
|
10
|
-
floatingRef: props.rootFloating,
|
|
11
|
-
tweaks: { ...defaultTweaks, ...props.tweaks },
|
|
12
|
-
parser: props.parser || parsers.hsla,
|
|
13
|
-
map: { ...defaultTranslations, ...props.map },
|
|
14
|
-
}), [props]);
|
|
15
|
-
return <Context.Provider value={memoMap}>{props.children}</Context.Provider>;
|
|
16
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { useRef } from "react";
|
|
2
|
-
export const debounce = (fn, ms = 0) => {
|
|
3
|
-
let timeoutId = undefined;
|
|
4
|
-
return function debounced(...args) {
|
|
5
|
-
clearTimeout(timeoutId);
|
|
6
|
-
timeoutId = setTimeout(() => fn(...args), ms);
|
|
7
|
-
};
|
|
8
|
-
};
|
|
9
|
-
export function useDebounce(fn, delay) {
|
|
10
|
-
const debouncedValue = useRef(debounce(fn, delay));
|
|
11
|
-
return debouncedValue.current;
|
|
12
|
-
}
|