@liguelead/design-system 0.0.33 → 0.0.35
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/components/Select/Select.styles.ts +103 -78
- package/components/Select/Select.tsx +84 -126
- package/components/Select/Select.types.ts +3 -4
- package/components/SplitButton/SplitButton.sizes.ts +12 -0
- package/components/SplitButton/SplitButton.stories.tsx +221 -0
- package/components/SplitButton/SplitButton.styles.ts +106 -0
- package/components/SplitButton/SplitButton.tsx +83 -0
- package/components/SplitButton/SplitButton.types.ts +20 -0
- package/components/SplitButton/index.ts +2 -0
- package/components/Table/Table.tsx +11 -2
- package/components/Table/Table.types.ts +2 -1
- package/components/Table/components/DatatableColumnFilterMenu/DatatableColumnFilterMenu.styles.ts +42 -0
- package/components/Table/components/DatatableColumnFilterMenu/DatatableColumnFilterMenu.tsx +51 -26
- package/components/Table/components/TableHeader/TableHeader.tsx +5 -1
- package/components/Table/hooks/useDatatableFilters.ts +8 -2
- package/components/Table/stories.fixtures.ts +3 -2
- package/components/Table/utils/currencySortingFn.ts +20 -0
- package/components/Table/utils/index.ts +1 -0
- package/components/index.ts +1 -0
- package/package.json +1 -1
|
@@ -12,6 +12,7 @@ interface TableHeaderProps<TData> {
|
|
|
12
12
|
onFilterPopoverOpenChange: (colId: string, isOpen: boolean) => void
|
|
13
13
|
onFilterValueChange: (colId: string, value: any) => void
|
|
14
14
|
onClearFilter: (colId: string) => void
|
|
15
|
+
onNumberSort: (colId: string, direction: 'asc' | 'desc' | null) => void
|
|
15
16
|
labels?: DatatableFilterDropdownLabels
|
|
16
17
|
}
|
|
17
18
|
|
|
@@ -23,6 +24,7 @@ function TableHeader<TData>({
|
|
|
23
24
|
onFilterPopoverOpenChange,
|
|
24
25
|
onFilterValueChange,
|
|
25
26
|
onClearFilter,
|
|
27
|
+
onNumberSort,
|
|
26
28
|
labels = {},
|
|
27
29
|
}: TableHeaderProps<TData>) {
|
|
28
30
|
return (
|
|
@@ -39,7 +41,8 @@ function TableHeader<TData>({
|
|
|
39
41
|
(colFilterValue.type === 'select' && colFilterValue.value != null) ||
|
|
40
42
|
(colFilterValue.type === 'dateRange' && (
|
|
41
43
|
colFilterValue.value.from != null || colFilterValue.value.to != null
|
|
42
|
-
))
|
|
44
|
+
)) ||
|
|
45
|
+
(colFilterValue.type === 'numberSort' && colFilterValue.value != null)
|
|
43
46
|
)
|
|
44
47
|
|
|
45
48
|
return (
|
|
@@ -73,6 +76,7 @@ function TableHeader<TData>({
|
|
|
73
76
|
filterValue={datatableFilters[header.column.id]}
|
|
74
77
|
onFilterValueChange={onFilterValueChange}
|
|
75
78
|
onClearFilter={onClearFilter}
|
|
79
|
+
onNumberSort={onNumberSort}
|
|
76
80
|
labels={labels}
|
|
77
81
|
/>
|
|
78
82
|
) : (
|
|
@@ -9,12 +9,14 @@ interface UseDatatableFiltersProps {
|
|
|
9
9
|
isServerMode: boolean
|
|
10
10
|
controlled?: DatatableColumnFilters
|
|
11
11
|
onChange?: (next: DatatableColumnFilters) => void
|
|
12
|
+
onClearSorting?: (colId: string) => void
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
export function useDatatableFilters({
|
|
15
16
|
isServerMode,
|
|
16
17
|
controlled,
|
|
17
18
|
onChange,
|
|
19
|
+
onClearSorting,
|
|
18
20
|
}: UseDatatableFiltersProps) {
|
|
19
21
|
const isControlled = controlled !== undefined
|
|
20
22
|
const [internal, setInternal] = useState<DatatableColumnFilters>({})
|
|
@@ -42,18 +44,21 @@ export function useDatatableFilters({
|
|
|
42
44
|
const { from, to } = value.value
|
|
43
45
|
return from || to ? [...rest, { id: colId, value: { from, to } }] : rest
|
|
44
46
|
}
|
|
47
|
+
// numberSort does not use columnFilters — handled via sorting state
|
|
45
48
|
return rest
|
|
46
49
|
})
|
|
47
50
|
}, [filters, isServerMode, updateFilters])
|
|
48
51
|
|
|
49
52
|
const handleClearColumnFilter = useCallback((colId: string) => {
|
|
53
|
+
const prev = filters[colId]
|
|
50
54
|
const next = { ...filters }
|
|
51
55
|
delete next[colId]
|
|
52
56
|
updateFilters(next)
|
|
53
57
|
setColumnFilters((prev) => prev.filter((f) => f.id !== colId))
|
|
54
58
|
if (openFilterColumnId === colId) setOpenFilterColumnId(null)
|
|
55
|
-
|
|
56
|
-
|
|
59
|
+
// if clearing a numberSort column, also clear the table sorting
|
|
60
|
+
if (prev?.type === 'numberSort') onClearSorting?.(colId)
|
|
61
|
+
}, [filters, openFilterColumnId, updateFilters, onClearSorting])
|
|
57
62
|
const handleClearAllFilters = useCallback((onClearGlobal: () => void) => {
|
|
58
63
|
onClearGlobal()
|
|
59
64
|
setColumnFilters([])
|
|
@@ -71,6 +76,7 @@ export function useDatatableFilters({
|
|
|
71
76
|
if (v.type === 'text') return v.value !== ''
|
|
72
77
|
if (v.type === 'select') return v.value != null
|
|
73
78
|
if (v.type === 'dateRange') return v.value.from != null || v.value.to != null
|
|
79
|
+
if (v.type === 'numberSort') return v.value != null
|
|
74
80
|
return false
|
|
75
81
|
}, [filters])
|
|
76
82
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ColumnDef } from '@tanstack/react-table'
|
|
2
2
|
import { DatatableColumnMeta } from './Table.types'
|
|
3
|
+
import { currencySortingFn } from './utils'
|
|
3
4
|
|
|
4
5
|
export type OrderRow = {
|
|
5
6
|
id: string
|
|
@@ -82,10 +83,10 @@ export const DATATABLE_COLUMNS: ColumnDef<OrderRow, unknown>[] = [
|
|
|
82
83
|
{
|
|
83
84
|
header: 'Valor',
|
|
84
85
|
accessorKey: 'amount',
|
|
86
|
+
sortingFn: currencySortingFn,
|
|
85
87
|
meta: {
|
|
86
|
-
filterType: '
|
|
88
|
+
filterType: 'numberSort',
|
|
87
89
|
filterLabel: 'valor',
|
|
88
|
-
filterPlaceholder: 'Buscar pelo valor',
|
|
89
90
|
} satisfies DatatableColumnMeta,
|
|
90
91
|
},
|
|
91
92
|
{
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Row } from '@tanstack/react-table'
|
|
2
|
+
|
|
3
|
+
const parseNumericValue = (raw: unknown): number => {
|
|
4
|
+
if (typeof raw === 'number') return raw
|
|
5
|
+
if (typeof raw !== 'string') return 0
|
|
6
|
+
const cleaned = raw.replace(/[^\d,.-]/g, '').replace(/\.(?=\d{3})/g, '').replace(',', '.')
|
|
7
|
+
return parseFloat(cleaned) || 0
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const currencySortingFn = <TData>(
|
|
11
|
+
rowA: Row<TData>,
|
|
12
|
+
rowB: Row<TData>,
|
|
13
|
+
columnId: string
|
|
14
|
+
): number => {
|
|
15
|
+
const a = parseNumericValue(rowA.getValue(columnId))
|
|
16
|
+
const b = parseNumericValue(rowB.getValue(columnId))
|
|
17
|
+
return a - b
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
currencySortingFn.autoRemove = (val: unknown) => val == null
|
package/components/index.ts
CHANGED
|
@@ -18,5 +18,6 @@ export { default as RadioButton } from './RadioButton'
|
|
|
18
18
|
export { ToastProvider, Toaster } from './Toaster'
|
|
19
19
|
export { default as Dialog } from './Dialog'
|
|
20
20
|
export { Combobox } from './Combobox'
|
|
21
|
+
export { default as SplitButton } from './SplitButton'
|
|
21
22
|
export { default as Table } from './Table'
|
|
22
23
|
export { default as Tabs } from './Tabs'
|