@cryptlex/web-components 5.2.0 → 5.3.0
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/data-table/data-table-filter.d.ts +27 -0
- package/dist/components/data-table/data-table-filter.js +112 -0
- package/dist/components/data-table/data-table.d.ts +73 -0
- package/dist/components/data-table/data-table.js +265 -0
- package/dist/components/data-table/table-commons.d.ts +56 -0
- package/dist/components/data-table/table-commons.js +137 -0
- package/dist/components/inputs/checkbox.d.ts +8 -0
- package/dist/components/inputs/checkbox.js +25 -0
- package/dist/components/inputs/date-picker.d.ts +11 -0
- package/dist/components/inputs/date-picker.js +22 -0
- package/dist/components/inputs/datefield.d.ts +14 -0
- package/dist/components/inputs/datefield.js +25 -0
- package/dist/components/inputs/field.d.ts +21 -0
- package/dist/components/inputs/field.js +48 -0
- package/dist/components/inputs/id-search.d.ts +20 -0
- package/dist/components/inputs/id-search.js +40 -0
- package/dist/components/inputs/input-otp.d.ts +8 -0
- package/dist/components/inputs/input-otp.js +19 -0
- package/dist/components/inputs/multi-select.d.ts +17 -0
- package/dist/components/inputs/multi-select.js +18 -0
- package/dist/components/inputs/numberfield.d.ts +7 -0
- package/dist/components/inputs/numberfield.js +25 -0
- package/dist/components/inputs/searchfield.d.ts +5 -0
- package/dist/components/inputs/searchfield.js +24 -0
- package/dist/components/inputs/select-options.d.ts +8 -0
- package/dist/components/inputs/select-options.js +286 -0
- package/dist/components/inputs/select.d.ts +17 -0
- package/dist/components/inputs/select.js +34 -0
- package/dist/components/inputs/textfield.d.ts +7 -0
- package/dist/components/inputs/textfield.js +28 -0
- package/dist/components/key-value-card/key-value-card.d.ts +17 -0
- package/dist/components/key-value-card/key-value-card.js +40 -0
- package/dist/components/ui/alert.d.ts +8 -0
- package/dist/components/ui/alert.js +18 -0
- package/dist/components/ui/avatar.d.ts +8 -0
- package/dist/components/ui/avatar.js +5 -0
- package/dist/components/ui/badge.d.ts +2 -0
- package/dist/components/ui/badge.js +5 -0
- package/dist/components/ui/breadcrumbs.d.ts +10 -0
- package/dist/components/ui/breadcrumbs.js +28 -0
- package/dist/components/ui/button.d.ts +11 -0
- package/dist/components/ui/button.js +34 -0
- package/dist/components/ui/calendar.d.ts +17 -0
- package/dist/components/ui/calendar.js +63 -0
- package/dist/components/ui/card.d.ts +7 -0
- package/dist/components/ui/card.js +20 -0
- package/dist/components/ui/dialog.d.ts +19 -0
- package/dist/components/ui/dialog.js +42 -0
- package/dist/components/ui/disclosure.d.ts +19 -0
- package/dist/components/ui/disclosure.js +20 -0
- package/dist/components/ui/list-box.d.ts +5 -0
- package/dist/components/ui/list-box.js +24 -0
- package/dist/components/ui/loader.d.ts +5 -0
- package/dist/components/ui/loader.js +6 -0
- package/dist/components/ui/menu.d.ts +25 -0
- package/dist/components/ui/menu.js +38 -0
- package/dist/components/ui/popover.d.ts +4 -0
- package/dist/components/ui/popover.js +14 -0
- package/dist/components/ui/sidebar.d.ts +53 -0
- package/dist/components/ui/sidebar.js +177 -0
- package/dist/components/ui/skeleton.d.ts +1 -0
- package/dist/components/ui/skeleton.js +5 -0
- package/dist/components/ui/sonner.d.ts +4 -0
- package/dist/components/ui/sonner.js +14 -0
- package/dist/components/ui/table.d.ts +9 -0
- package/dist/components/ui/table.js +26 -0
- package/dist/components/ui/tabs.d.ts +5 -0
- package/dist/components/ui/tabs.js +25 -0
- package/dist/components/ui/timeline.d.ts +15 -0
- package/dist/components/ui/timeline.js +31 -0
- package/dist/components/ui/tooltip.d.ts +4 -0
- package/dist/components/ui/tooltip.js +12 -0
- package/dist/utils/form-context.d.ts +4 -0
- package/{lib/utils/form-context.tsx → dist/utils/form-context.js} +1 -3
- package/dist/utils/form-hook.d.ts +25 -0
- package/{lib/utils/form-hook.tsx → dist/utils/form-hook.js} +15 -18
- package/dist/utils/primitives.d.ts +30 -0
- package/{lib/utils/primitives.ts → dist/utils/primitives.js} +8 -37
- package/dist/utils/resource-names.d.ts +23 -0
- package/{lib/utils/resource-names.tsx → dist/utils/resource-names.js} +42 -75
- package/dist/utils/use-mobile.d.ts +1 -0
- package/dist/utils/use-mobile.js +15 -0
- package/package.json +10 -5
- package/lib/components/data-table/data-table-filter.tsx +0 -220
- package/lib/components/data-table/data-table.tsx +0 -593
- package/lib/components/data-table/table-commons.tsx +0 -233
- package/lib/components/inputs/checkbox.tsx +0 -72
- package/lib/components/inputs/date-picker.tsx +0 -130
- package/lib/components/inputs/datefield.tsx +0 -109
- package/lib/components/inputs/field.tsx +0 -106
- package/lib/components/inputs/id-search.tsx +0 -83
- package/lib/components/inputs/input-otp.tsx +0 -63
- package/lib/components/inputs/multi-select.tsx +0 -62
- package/lib/components/inputs/numberfield.tsx +0 -110
- package/lib/components/inputs/searchfield.tsx +0 -87
- package/lib/components/inputs/select-options.tsx +0 -303
- package/lib/components/inputs/select.tsx +0 -140
- package/lib/components/inputs/textfield.tsx +0 -96
- package/lib/components/key-value-card/key-value-card.tsx +0 -115
- package/lib/components/ui/alert.tsx +0 -32
- package/lib/components/ui/avatar.tsx +0 -22
- package/lib/components/ui/badge.tsx +0 -19
- package/lib/components/ui/breadcrumbs.tsx +0 -104
- package/lib/components/ui/button.tsx +0 -66
- package/lib/components/ui/calendar.tsx +0 -220
- package/lib/components/ui/card.tsx +0 -58
- package/lib/components/ui/dialog.tsx +0 -172
- package/lib/components/ui/disclosure.tsx +0 -113
- package/lib/components/ui/list-box.tsx +0 -86
- package/lib/components/ui/loader.tsx +0 -10
- package/lib/components/ui/menu.tsx +0 -168
- package/lib/components/ui/popover.tsx +0 -37
- package/lib/components/ui/sidebar.tsx +0 -552
- package/lib/components/ui/skeleton.tsx +0 -7
- package/lib/components/ui/sonner.tsx +0 -26
- package/lib/components/ui/table.tsx +0 -79
- package/lib/components/ui/tabs.tsx +0 -82
- package/lib/components/ui/timeline.tsx +0 -52
- package/lib/components/ui/tooltip.tsx +0 -30
- package/lib/tokens.scss +0 -89
- package/lib/utils/use-mobile.tsx +0 -21
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
import type { CalendarDateTime } from "@internationalized/date";
|
|
2
|
-
import { useDataTable, type OperationKeys } from "lib/components/data-table/data-table";
|
|
3
|
-
import { type ApiFilters } from "lib/components/data-table/table-commons";
|
|
4
|
-
import { TfDatePicker } from "lib/components/inputs/date-picker";
|
|
5
|
-
import { TfIdSearchInput } from "lib/components/inputs/id-search";
|
|
6
|
-
import type { MultiSelectProps } from "lib/components/inputs/multi-select";
|
|
7
|
-
import { Button } from "lib/components/ui/button";
|
|
8
|
-
import { EasyMenu, MenuItem } from "lib/components/ui/menu";
|
|
9
|
-
import { Popover, PopoverTrigger } from "lib/components/ui/popover";
|
|
10
|
-
import { useAppForm } from "lib/utils/form-hook";
|
|
11
|
-
import { cn } from "lib/utils/primitives";
|
|
12
|
-
import { useResourceFormatter } from "lib/utils/resource-names";
|
|
13
|
-
import { Filter, Trash } from "lucide-react";
|
|
14
|
-
import { useRef } from "react";
|
|
15
|
-
|
|
16
|
-
export const FILTER_COMPARISON_OPERATORS = [
|
|
17
|
-
'eq',
|
|
18
|
-
'ne',
|
|
19
|
-
'cn',
|
|
20
|
-
'nc',
|
|
21
|
-
'sw',
|
|
22
|
-
'ew',
|
|
23
|
-
'in',
|
|
24
|
-
'nin',
|
|
25
|
-
'gt',
|
|
26
|
-
'gte',
|
|
27
|
-
'lt',
|
|
28
|
-
'lte',
|
|
29
|
-
] as const;
|
|
30
|
-
export type FilterComparisonOperator =
|
|
31
|
-
(typeof FILTER_COMPARISON_OPERATORS)[number];
|
|
32
|
-
|
|
33
|
-
export const COMPARISON_OPERATOR_LABELS: Record<
|
|
34
|
-
FilterComparisonOperator,
|
|
35
|
-
string
|
|
36
|
-
> = {
|
|
37
|
-
eq: 'equal to',
|
|
38
|
-
ne: 'not equal to',
|
|
39
|
-
cn: 'contains',
|
|
40
|
-
nc: 'does not contain',
|
|
41
|
-
sw: 'starts with',
|
|
42
|
-
ew: 'ends with',
|
|
43
|
-
in: 'includes',
|
|
44
|
-
nin: 'does not include',
|
|
45
|
-
gt: 'greater than',
|
|
46
|
-
gte: 'greater than or equal to',
|
|
47
|
-
lt: 'less than',
|
|
48
|
-
lte: 'less than or equal to',
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
type BaseLocalFilter<T extends FilterType, V> = {
|
|
52
|
-
id: string;
|
|
53
|
-
type: T;
|
|
54
|
-
property: string;
|
|
55
|
-
operator: FilterComparisonOperator;
|
|
56
|
-
value: V | undefined;
|
|
57
|
-
displayValue?: string;
|
|
58
|
-
};
|
|
59
|
-
type EnumLocalFilter = BaseLocalFilter<'enum', Set<string | number>>;
|
|
60
|
-
type IdLocalFilter = BaseLocalFilter<'id', string>;
|
|
61
|
-
type BoolLocalFilter = BaseLocalFilter<'bool', boolean>;
|
|
62
|
-
type StringLocalFilter = BaseLocalFilter<'string', string>;
|
|
63
|
-
type DateLocalFilter = BaseLocalFilter<'date', CalendarDateTime>;
|
|
64
|
-
type IdSearchLocalFilter = BaseLocalFilter<'id-search', Set<string | number>>;
|
|
65
|
-
|
|
66
|
-
type LocalFilter = EnumLocalFilter
|
|
67
|
-
| IdLocalFilter
|
|
68
|
-
| BoolLocalFilter
|
|
69
|
-
| StringLocalFilter
|
|
70
|
-
| DateLocalFilter
|
|
71
|
-
| IdSearchLocalFilter;
|
|
72
|
-
|
|
73
|
-
export type FilterConfig =
|
|
74
|
-
| { type: 'enum'; options: MultiSelectProps['items'] }
|
|
75
|
-
| { type: 'id-search'; search: () => Promise<{ id: string; name: string }[]> }
|
|
76
|
-
| { type: 'id' }
|
|
77
|
-
| { type: 'bool' }
|
|
78
|
-
| { type: 'string' }
|
|
79
|
-
| { type: 'date' }
|
|
80
|
-
|
|
81
|
-
export type FilterType = FilterConfig['type'];
|
|
82
|
-
|
|
83
|
-
const FilterOperations: Record<FilterType, FilterComparisonOperator[]> = {
|
|
84
|
-
'bool': ['eq'],
|
|
85
|
-
'enum': ['in', 'nin'],
|
|
86
|
-
'id': ['in', 'nin'],
|
|
87
|
-
'id-search': ['in', 'nin'],
|
|
88
|
-
'string': ['eq', 'ne', 'cn', 'nc', 'sw', 'ew', 'in', 'nin'],
|
|
89
|
-
'date': ['lt', 'gt'],
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export type FiltersConfig<TOperation extends OperationKeys> = Required<Record<keyof ApiFilters<TOperation>, FilterConfig>>
|
|
93
|
-
|
|
94
|
-
export function DataTableFilter({ className, ...props }: React.ComponentProps<'section'>) {
|
|
95
|
-
const { filters, query, setFilters, filterConfig } = useDataTable();
|
|
96
|
-
// TODO focus
|
|
97
|
-
// const localFilterRefs = useRef([]);
|
|
98
|
-
const addFilterButtonRef = useRef<HTMLButtonElement>(null);
|
|
99
|
-
|
|
100
|
-
const resourceFormatter = useResourceFormatter();
|
|
101
|
-
|
|
102
|
-
const DEFAULT_VALUES: { filters: LocalFilter[] } = {
|
|
103
|
-
// TODO, initialize with filters from tableState
|
|
104
|
-
filters: []
|
|
105
|
-
};
|
|
106
|
-
const form = useAppForm({
|
|
107
|
-
defaultValues: DEFAULT_VALUES,
|
|
108
|
-
onSubmit: ({ value }) => {
|
|
109
|
-
// TODO, instead of generic transformation, use type based tranform()
|
|
110
|
-
setFilters(value.filters.map(lf => { return { [lf.property]: { [lf.operator]: [lf.value] } } }))
|
|
111
|
-
}
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
// More reason to hate TS https://github.com/Microsoft/TypeScript/issues/12870
|
|
115
|
-
const filterKeys = Object.keys(filterConfig).sort();
|
|
116
|
-
|
|
117
|
-
return (
|
|
118
|
-
<section {...props} className={cn("flex gap-icon items-center", className)}>
|
|
119
|
-
<PopoverTrigger onOpenChange={(o) => {
|
|
120
|
-
// Set filters when the popover closes
|
|
121
|
-
if (!o) {
|
|
122
|
-
form.handleSubmit();
|
|
123
|
-
} else {
|
|
124
|
-
addFilterButtonRef.current?.focus();
|
|
125
|
-
}
|
|
126
|
-
}}>
|
|
127
|
-
<Button active={filters.length > 0} isDisabled={query.isPending || filterKeys.length === 0} type="button" size={'icon'} variant={'neutral'}><Filter /></Button>
|
|
128
|
-
{/* TODO, icon maps with dynamic imports? */}
|
|
129
|
-
{/* TODO open popover with form for property specific filter */}
|
|
130
|
-
{/* TODO, icons here??? */}
|
|
131
|
-
<Popover className="w-full p-icon">
|
|
132
|
-
{/* const h3Styles = "body mb-icon text-muted-foreground"; */}
|
|
133
|
-
{/* <h3 className={h3Styles}>{isFiltersActive ? "Active filters" : "Add filters"}</h3> */}
|
|
134
|
-
<form onSubmit={(e) => { e.preventDefault(); }} className="flex flex-col gap-icon max-h-table overflow-auto ">
|
|
135
|
-
<form.Field mode="array" name={"filters"}>
|
|
136
|
-
{
|
|
137
|
-
(field) => {
|
|
138
|
-
return <>
|
|
139
|
-
{field.state.value.map((lf, i) => {
|
|
140
|
-
return (
|
|
141
|
-
<div key={lf.id} className="flex gap-icon items-center justify-normal">
|
|
142
|
-
<span className="text-sm">{resourceFormatter(lf.property)}</span>
|
|
143
|
-
<form.AppField
|
|
144
|
-
key={lf.id}
|
|
145
|
-
name={`filters[${i}].operator`}
|
|
146
|
-
>
|
|
147
|
-
{(sf) => (<sf.TfSingleSelect items={FilterOperations[lf.type].map(op => ({ id: op, label: <>{COMPARISON_OPERATOR_LABELS[op]}</> }))} />)}
|
|
148
|
-
</form.AppField>
|
|
149
|
-
|
|
150
|
-
{lf.type === 'bool' && <form.AppField name={`filters[${i}].value`}>{(sf) => (<sf.TfCheckbox />)}</form.AppField>}
|
|
151
|
-
{lf.type === 'date' && <form.AppField name={`filters[${i}].value`}>{(_) => (<TfDatePicker />)}</form.AppField>}
|
|
152
|
-
{lf.type === 'id' && <form.AppField name={`filters[${i}].value`}>{(sf) => (<sf.TfTextField />)}</form.AppField>}
|
|
153
|
-
{lf.type === 'string' && <form.AppField name={`filters[${i}].value`}>{(sf) => (<sf.TfTextField />)}</form.AppField>}
|
|
154
|
-
{/* @ts-ignore */}
|
|
155
|
-
{lf.type === 'enum' && <form.AppField name={`filters[${i}].value`}>{(sf) => (<sf.TfMultiSelect items={filterConfig[lf.property].options} />)}</form.AppField>}
|
|
156
|
-
{/* @ts-ignore */}
|
|
157
|
-
{lf.type === 'id-search' && <form.AppField name={`filters[${i}].value`}>{(_) => (<TfIdSearchInput multiple accessor="id" searchFn={filterConfig[lf.property].search} />)}</form.AppField>}
|
|
158
|
-
|
|
159
|
-
<Button type="button" variant="destructive" size="icon" onPress={() => field.removeValue(i)}><Trash /></Button>
|
|
160
|
-
</div>
|
|
161
|
-
)
|
|
162
|
-
})}
|
|
163
|
-
<div className="flex w-full items-center justify-end gap-2 not-first:mt-icon">
|
|
164
|
-
<EasyMenu label="Add Filter">
|
|
165
|
-
{filterKeys.map(k => <MenuItem key={k} onAction={() => {
|
|
166
|
-
//@ts-ignore
|
|
167
|
-
const type = filterConfig[k].type as FilterType;
|
|
168
|
-
|
|
169
|
-
const defaultValue = (t: FilterType) => {
|
|
170
|
-
// TODO, ensure exhaustive???
|
|
171
|
-
switch (t) {
|
|
172
|
-
case 'bool':
|
|
173
|
-
return true;
|
|
174
|
-
case 'string':
|
|
175
|
-
return '';
|
|
176
|
-
case 'date':
|
|
177
|
-
return new Date().toISOString();
|
|
178
|
-
case 'id':
|
|
179
|
-
return '';
|
|
180
|
-
case 'id-search':
|
|
181
|
-
return [] as string[];
|
|
182
|
-
case 'enum':
|
|
183
|
-
return [] as string[];
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
const newFilter: LocalFilter = {
|
|
188
|
-
id: `${k}-${Date.now()}`,
|
|
189
|
-
operator: FilterOperations[type][0],
|
|
190
|
-
//@ts-ignore
|
|
191
|
-
value: defaultValue(type),
|
|
192
|
-
type: type,
|
|
193
|
-
property: k,
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
field.pushValue(newFilter);
|
|
197
|
-
// TODO Focus to ref
|
|
198
|
-
|
|
199
|
-
}} className="dropdown-item">{resourceFormatter(k)}</MenuItem>)}
|
|
200
|
-
</EasyMenu>
|
|
201
|
-
{field.state.value.length > 0 ? (
|
|
202
|
-
<Button
|
|
203
|
-
type="button"
|
|
204
|
-
variant="neutral"
|
|
205
|
-
onPress={() => { field.setValue([]) }}
|
|
206
|
-
>
|
|
207
|
-
Reset filters
|
|
208
|
-
</Button>
|
|
209
|
-
) : null}
|
|
210
|
-
</div>
|
|
211
|
-
</>
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
</form.Field >
|
|
215
|
-
</form>
|
|
216
|
-
</Popover>
|
|
217
|
-
</PopoverTrigger>
|
|
218
|
-
</section>
|
|
219
|
-
);
|
|
220
|
-
};
|