@startsimpli/ui 0.1.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/README.md +537 -0
- package/package.json +80 -0
- package/src/components/index.ts +50 -0
- package/src/components/navigation/sidebar.tsx +178 -0
- package/src/components/ui/accordion.tsx +58 -0
- package/src/components/ui/alert.tsx +59 -0
- package/src/components/ui/badge.tsx +36 -0
- package/src/components/ui/button.tsx +57 -0
- package/src/components/ui/calendar.tsx +70 -0
- package/src/components/ui/card.tsx +68 -0
- package/src/components/ui/checkbox.tsx +30 -0
- package/src/components/ui/collapsible.tsx +12 -0
- package/src/components/ui/dialog.tsx +122 -0
- package/src/components/ui/dropdown-menu.tsx +200 -0
- package/src/components/ui/index.ts +24 -0
- package/src/components/ui/input.tsx +25 -0
- package/src/components/ui/label.tsx +26 -0
- package/src/components/ui/popover.tsx +31 -0
- package/src/components/ui/progress.tsx +28 -0
- package/src/components/ui/scroll-area.tsx +48 -0
- package/src/components/ui/select.tsx +160 -0
- package/src/components/ui/separator.tsx +31 -0
- package/src/components/ui/skeleton.tsx +15 -0
- package/src/components/ui/table.tsx +117 -0
- package/src/components/ui/tabs.tsx +55 -0
- package/src/components/ui/textarea.tsx +24 -0
- package/src/components/ui/tooltip.tsx +30 -0
- package/src/components/unified-table/UnifiedTable.tsx +553 -0
- package/src/components/unified-table/__tests__/components/BulkActionBar.test.tsx +477 -0
- package/src/components/unified-table/__tests__/components/ExportButton.test.tsx +467 -0
- package/src/components/unified-table/__tests__/components/InlineEditCell.test.tsx +159 -0
- package/src/components/unified-table/__tests__/components/SavedViewsDropdown.test.tsx +128 -0
- package/src/components/unified-table/__tests__/components/TablePagination.test.tsx +374 -0
- package/src/components/unified-table/__tests__/hooks/useColumnReorder.test.ts +191 -0
- package/src/components/unified-table/__tests__/hooks/useColumnResize.test.ts +122 -0
- package/src/components/unified-table/__tests__/hooks/useColumnVisibility.test.ts +594 -0
- package/src/components/unified-table/__tests__/hooks/useFilters.test.ts +460 -0
- package/src/components/unified-table/__tests__/hooks/usePagination.test.ts +439 -0
- package/src/components/unified-table/__tests__/hooks/useResponsive.test.ts +421 -0
- package/src/components/unified-table/__tests__/hooks/useSelection.test.ts +367 -0
- package/src/components/unified-table/__tests__/hooks/useTableKeyboard.test.ts +803 -0
- package/src/components/unified-table/__tests__/hooks/useTableState.test.ts +210 -0
- package/src/components/unified-table/__tests__/integration/table-with-selection.test.tsx +624 -0
- package/src/components/unified-table/__tests__/utils/export.test.ts +427 -0
- package/src/components/unified-table/components/BulkActionBar/index.tsx +119 -0
- package/src/components/unified-table/components/DataTableCore/index.tsx +473 -0
- package/src/components/unified-table/components/InlineEditCell/index.tsx +159 -0
- package/src/components/unified-table/components/MobileView/Card.tsx +218 -0
- package/src/components/unified-table/components/MobileView/CardActions.tsx +126 -0
- package/src/components/unified-table/components/MobileView/README.md +411 -0
- package/src/components/unified-table/components/MobileView/index.tsx +77 -0
- package/src/components/unified-table/components/MobileView/types.ts +77 -0
- package/src/components/unified-table/components/TableFilters/index.tsx +298 -0
- package/src/components/unified-table/components/TablePagination/index.tsx +157 -0
- package/src/components/unified-table/components/Toolbar/ExportButton.tsx +229 -0
- package/src/components/unified-table/components/Toolbar/SavedViewsDropdown.tsx +251 -0
- package/src/components/unified-table/components/Toolbar/StandardTableToolbar.tsx +146 -0
- package/src/components/unified-table/components/Toolbar/index.tsx +3 -0
- package/src/components/unified-table/hooks/index.ts +21 -0
- package/src/components/unified-table/hooks/useColumnReorder.ts +90 -0
- package/src/components/unified-table/hooks/useColumnResize.ts +123 -0
- package/src/components/unified-table/hooks/useColumnVisibility.ts +92 -0
- package/src/components/unified-table/hooks/useFilters.ts +53 -0
- package/src/components/unified-table/hooks/usePagination.ts +120 -0
- package/src/components/unified-table/hooks/useResponsive.ts +50 -0
- package/src/components/unified-table/hooks/useSelection.ts +152 -0
- package/src/components/unified-table/hooks/useTableKeyboard.ts +206 -0
- package/src/components/unified-table/hooks/useTablePreferences.ts +198 -0
- package/src/components/unified-table/hooks/useTableState.ts +103 -0
- package/src/components/unified-table/hooks/useTableURL.test.tsx +921 -0
- package/src/components/unified-table/hooks/useTableURL.ts +301 -0
- package/src/components/unified-table/index.ts +16 -0
- package/src/components/unified-table/types.ts +393 -0
- package/src/components/unified-table/utils/export.ts +236 -0
- package/src/components/unified-table/utils/index.ts +4 -0
- package/src/components/unified-table/utils/renderers.ts +105 -0
- package/src/components/unified-table/utils/themes.ts +87 -0
- package/src/components/unified-table/utils/validation.ts +122 -0
- package/src/index.ts +6 -0
- package/src/lib/utils.ts +1 -0
- package/src/theme/contract.ts +46 -0
- package/src/theme/index.ts +9 -0
- package/src/theme/tailwind.config.js +70 -0
- package/src/theme/tailwind.preset.ts +93 -0
- package/src/utils/cn.ts +6 -0
- package/src/utils/index.ts +91 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { renderHook, act } from '@testing-library/react'
|
|
2
|
+
import { useTableState } from '../../hooks/useTableState'
|
|
3
|
+
|
|
4
|
+
interface TestData {
|
|
5
|
+
id: string
|
|
6
|
+
name: string
|
|
7
|
+
value: number
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
describe('useTableState', () => {
|
|
11
|
+
const mockData: TestData[] = [
|
|
12
|
+
{ id: '1', name: 'Item 1', value: 10 },
|
|
13
|
+
{ id: '2', name: 'Item 2', value: 20 },
|
|
14
|
+
{ id: '3', name: 'Item 3', value: 30 },
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
describe('Initialization', () => {
|
|
18
|
+
it('should initialize with default values', () => {
|
|
19
|
+
const { result } = renderHook(() => useTableState<TestData>({}))
|
|
20
|
+
|
|
21
|
+
expect(result.current.state.data).toEqual([])
|
|
22
|
+
expect(result.current.state.currentPage).toBe(1)
|
|
23
|
+
expect(result.current.state.pageSize).toBe(25)
|
|
24
|
+
expect(result.current.state.loading).toBe(false)
|
|
25
|
+
expect(result.current.state.error).toBe(null)
|
|
26
|
+
expect(result.current.state.viewMode).toBe('table')
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('should initialize with provided initial data', () => {
|
|
30
|
+
const { result } = renderHook(() =>
|
|
31
|
+
useTableState<TestData>({ initialData: mockData })
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
expect(result.current.state.data).toEqual(mockData)
|
|
35
|
+
expect(result.current.state.totalCount).toBe(3)
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('should initialize with custom page size', () => {
|
|
39
|
+
const { result } = renderHook(() =>
|
|
40
|
+
useTableState<TestData>({ initialPageSize: 50 })
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
expect(result.current.state.pageSize).toBe(50)
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
describe('Data Management', () => {
|
|
48
|
+
it('should update data correctly', () => {
|
|
49
|
+
const { result } = renderHook(() => useTableState<TestData>({}))
|
|
50
|
+
|
|
51
|
+
act(() => {
|
|
52
|
+
result.current.setData(mockData)
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
expect(result.current.state.data).toEqual(mockData)
|
|
56
|
+
expect(result.current.state.totalCount).toBe(3)
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('should calculate totalPages correctly', () => {
|
|
60
|
+
const { result } = renderHook(() =>
|
|
61
|
+
useTableState<TestData>({ initialData: mockData, initialPageSize: 2 })
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
expect(result.current.state.totalPages).toBe(2)
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('should handle empty data', () => {
|
|
68
|
+
const { result } = renderHook(() =>
|
|
69
|
+
useTableState<TestData>({ initialData: [] })
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
expect(result.current.state.data).toEqual([])
|
|
73
|
+
expect(result.current.state.totalCount).toBe(0)
|
|
74
|
+
expect(result.current.state.totalPages).toBe(1) // Minimum 1 page
|
|
75
|
+
})
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
describe('Pagination', () => {
|
|
79
|
+
it('should set current page', () => {
|
|
80
|
+
const { result } = renderHook(() => useTableState<TestData>({}))
|
|
81
|
+
|
|
82
|
+
act(() => {
|
|
83
|
+
result.current.setPage(3)
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
expect(result.current.state.currentPage).toBe(3)
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
it('should reset to page 1 when changing page size', () => {
|
|
90
|
+
const { result } = renderHook(() =>
|
|
91
|
+
useTableState<TestData>({ initialData: mockData })
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
act(() => {
|
|
95
|
+
result.current.setPage(2)
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
expect(result.current.state.currentPage).toBe(2)
|
|
99
|
+
|
|
100
|
+
act(() => {
|
|
101
|
+
result.current.setPageSize(50)
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
expect(result.current.state.pageSize).toBe(50)
|
|
105
|
+
expect(result.current.state.currentPage).toBe(1)
|
|
106
|
+
})
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
describe('Loading States', () => {
|
|
110
|
+
it('should set loading state', () => {
|
|
111
|
+
const { result } = renderHook(() => useTableState<TestData>({}))
|
|
112
|
+
|
|
113
|
+
act(() => {
|
|
114
|
+
result.current.setLoading(true)
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
expect(result.current.state.loading).toBe(true)
|
|
118
|
+
|
|
119
|
+
act(() => {
|
|
120
|
+
result.current.setLoading(false)
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
expect(result.current.state.loading).toBe(false)
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
it('should set loading rows', () => {
|
|
127
|
+
const { result } = renderHook(() => useTableState<TestData>({}))
|
|
128
|
+
const loadingSet = new Set(['1', '2'])
|
|
129
|
+
|
|
130
|
+
act(() => {
|
|
131
|
+
result.current.setLoadingRows(loadingSet)
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
expect(result.current.state.loadingRows).toEqual(loadingSet)
|
|
135
|
+
})
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
describe('Error Handling', () => {
|
|
139
|
+
it('should set error state', () => {
|
|
140
|
+
const { result } = renderHook(() => useTableState<TestData>({}))
|
|
141
|
+
const error = new Error('Test error')
|
|
142
|
+
|
|
143
|
+
act(() => {
|
|
144
|
+
result.current.setError(error)
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
expect(result.current.state.error).toBe(error)
|
|
148
|
+
|
|
149
|
+
act(() => {
|
|
150
|
+
result.current.setError(null)
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
expect(result.current.state.error).toBe(null)
|
|
154
|
+
})
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
describe('View Mode', () => {
|
|
158
|
+
it('should toggle view mode', () => {
|
|
159
|
+
const { result } = renderHook(() => useTableState<TestData>({}))
|
|
160
|
+
|
|
161
|
+
expect(result.current.state.viewMode).toBe('table')
|
|
162
|
+
|
|
163
|
+
act(() => {
|
|
164
|
+
result.current.setViewMode('card')
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
expect(result.current.state.viewMode).toBe('card')
|
|
168
|
+
|
|
169
|
+
act(() => {
|
|
170
|
+
result.current.setViewMode('table')
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
expect(result.current.state.viewMode).toBe('table')
|
|
174
|
+
})
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
describe('Memoization', () => {
|
|
178
|
+
it('should memoize state correctly', () => {
|
|
179
|
+
const { result, rerender } = renderHook(() =>
|
|
180
|
+
useTableState<TestData>({ initialData: mockData })
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
const firstState = result.current.state
|
|
184
|
+
rerender()
|
|
185
|
+
const secondState = result.current.state
|
|
186
|
+
|
|
187
|
+
// State should be the same object if nothing changed
|
|
188
|
+
expect(firstState).toBe(secondState)
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
it('should update memoized state when data changes', () => {
|
|
192
|
+
const { result } = renderHook(() =>
|
|
193
|
+
useTableState<TestData>({ initialData: mockData })
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
const firstState = result.current.state
|
|
197
|
+
const newData = [...mockData, { id: '4', name: 'Item 4', value: 40 }]
|
|
198
|
+
|
|
199
|
+
act(() => {
|
|
200
|
+
result.current.setData(newData)
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
const secondState = result.current.state
|
|
204
|
+
|
|
205
|
+
// State should be different after data change
|
|
206
|
+
expect(firstState).not.toBe(secondState)
|
|
207
|
+
expect(secondState.data).toEqual(newData)
|
|
208
|
+
})
|
|
209
|
+
})
|
|
210
|
+
})
|