@idealyst/datagrid 1.0.40 → 1.0.41
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/package.json +1 -1
- package/src/DataGrid/DataGrid.tsx +56 -63
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@idealyst/datagrid",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.41",
|
|
4
4
|
"description": "High-performance datagrid component for React and React Native",
|
|
5
5
|
"documentation": "https://github.com/your-username/idealyst-framework/tree/main/packages/datagrid#readme",
|
|
6
6
|
"main": "src/index.ts",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import React, { useState,
|
|
2
|
-
import { View, Text
|
|
3
|
-
import {
|
|
1
|
+
import React, { useState, useCallback } from 'react';
|
|
2
|
+
import { View, Text } from '@idealyst/components';
|
|
3
|
+
import { UnistylesRuntime } from 'react-native-unistyles';
|
|
4
4
|
import { ScrollView } from '../primitives/ScrollView';
|
|
5
5
|
import { VirtualizedList } from '../primitives/VirtualizedList';
|
|
6
6
|
import type { DataGridProps, Column } from './types';
|
|
@@ -23,7 +23,6 @@ export function DataGrid<T extends Record<string, any>>({
|
|
|
23
23
|
multiSelect = false,
|
|
24
24
|
stickyHeader = true,
|
|
25
25
|
}: DataGridProps<T>) {
|
|
26
|
-
const { styles } = useStyles(stylesheet);
|
|
27
26
|
const [sortColumn, setSortColumn] = useState<string | null>(null);
|
|
28
27
|
const [sortDirection, setSortDirection] = useState<'asc' | 'desc'>('asc');
|
|
29
28
|
|
|
@@ -54,21 +53,43 @@ export function DataGrid<T extends Record<string, any>>({
|
|
|
54
53
|
}, [selectedRows, onSelectionChange, multiSelect, onRowClick]);
|
|
55
54
|
|
|
56
55
|
const renderHeader = () => (
|
|
57
|
-
<View style={[
|
|
56
|
+
<View style={[
|
|
57
|
+
(theme) => ({
|
|
58
|
+
flexDirection: 'row',
|
|
59
|
+
backgroundColor: theme.colors.neutral[50],
|
|
60
|
+
borderBottomWidth: 2,
|
|
61
|
+
borderBottomColor: theme.colors.neutral[200],
|
|
62
|
+
}),
|
|
63
|
+
headerStyle
|
|
64
|
+
]}>
|
|
58
65
|
{columns.map((column) => (
|
|
59
66
|
<View
|
|
60
67
|
key={column.key}
|
|
61
68
|
style={[
|
|
62
|
-
|
|
69
|
+
(theme) => ({
|
|
70
|
+
flexDirection: 'row',
|
|
71
|
+
alignItems: 'center',
|
|
72
|
+
justifyContent: 'space-between',
|
|
73
|
+
padding: theme.spacing.sm,
|
|
74
|
+
borderRightWidth: 1,
|
|
75
|
+
borderRightColor: theme.colors.neutral[200],
|
|
76
|
+
}),
|
|
63
77
|
{ width: column.width || 'auto', minWidth: column.minWidth, maxWidth: column.maxWidth },
|
|
64
78
|
column.headerStyle,
|
|
65
79
|
]}
|
|
66
80
|
>
|
|
67
|
-
<Text weight="bold" style={
|
|
81
|
+
<Text weight="bold" style={(theme) => ({
|
|
82
|
+
fontSize: 14,
|
|
83
|
+
color: theme.colors.neutral[700],
|
|
84
|
+
})}>
|
|
68
85
|
{column.header}
|
|
69
86
|
</Text>
|
|
70
87
|
{column.sortable && (
|
|
71
|
-
<Text style={
|
|
88
|
+
<Text style={(theme) => ({
|
|
89
|
+
fontSize: 10,
|
|
90
|
+
marginLeft: theme.spacing.xs,
|
|
91
|
+
color: theme.colors.primary[500],
|
|
92
|
+
})}>
|
|
72
93
|
{sortColumn === column.key ? (sortDirection === 'asc' ? '▲' : '▼') : ''}
|
|
73
94
|
</Text>
|
|
74
95
|
)}
|
|
@@ -84,8 +105,15 @@ export function DataGrid<T extends Record<string, any>>({
|
|
|
84
105
|
return (
|
|
85
106
|
<View
|
|
86
107
|
style={[
|
|
87
|
-
|
|
88
|
-
|
|
108
|
+
(theme) => ({
|
|
109
|
+
flexDirection: 'row',
|
|
110
|
+
borderBottomWidth: 1,
|
|
111
|
+
borderBottomColor: theme.colors.neutral[100],
|
|
112
|
+
backgroundColor: theme.colors.background,
|
|
113
|
+
}),
|
|
114
|
+
isSelected && ((theme) => ({
|
|
115
|
+
backgroundColor: theme.colors.primary[50],
|
|
116
|
+
})),
|
|
89
117
|
computedRowStyle,
|
|
90
118
|
]}
|
|
91
119
|
onPress={() => handleRowClick(item, index)}
|
|
@@ -101,7 +129,12 @@ export function DataGrid<T extends Record<string, any>>({
|
|
|
101
129
|
<View
|
|
102
130
|
key={column.key}
|
|
103
131
|
style={[
|
|
104
|
-
|
|
132
|
+
(theme) => ({
|
|
133
|
+
padding: theme.spacing.sm,
|
|
134
|
+
borderRightWidth: 1,
|
|
135
|
+
borderRightColor: theme.colors.neutral[100],
|
|
136
|
+
justifyContent: 'center',
|
|
137
|
+
}),
|
|
105
138
|
{ width: column.width || 'auto', minWidth: column.minWidth, maxWidth: column.maxWidth },
|
|
106
139
|
computedCellStyle,
|
|
107
140
|
]}
|
|
@@ -121,7 +154,17 @@ export function DataGrid<T extends Record<string, any>>({
|
|
|
121
154
|
const containerHeight = typeof height === 'number' ? height : undefined;
|
|
122
155
|
|
|
123
156
|
return (
|
|
124
|
-
<View style={[
|
|
157
|
+
<View style={[
|
|
158
|
+
(theme) => ({
|
|
159
|
+
backgroundColor: theme.colors.background,
|
|
160
|
+
borderWidth: 1,
|
|
161
|
+
borderColor: theme.colors.neutral[200],
|
|
162
|
+
borderRadius: theme.radius.md,
|
|
163
|
+
overflow: 'hidden',
|
|
164
|
+
}),
|
|
165
|
+
{ width, height },
|
|
166
|
+
style
|
|
167
|
+
]}>
|
|
125
168
|
{stickyHeader && renderHeader()}
|
|
126
169
|
{virtualized && containerHeight ? (
|
|
127
170
|
<VirtualizedList
|
|
@@ -133,7 +176,7 @@ export function DataGrid<T extends Record<string, any>>({
|
|
|
133
176
|
/>
|
|
134
177
|
) : (
|
|
135
178
|
<ScrollView
|
|
136
|
-
style={
|
|
179
|
+
style={{ flex: 1 }}
|
|
137
180
|
showsVerticalScrollIndicator={true}
|
|
138
181
|
>
|
|
139
182
|
{!stickyHeader && renderHeader()}
|
|
@@ -144,53 +187,3 @@ export function DataGrid<T extends Record<string, any>>({
|
|
|
144
187
|
);
|
|
145
188
|
}
|
|
146
189
|
|
|
147
|
-
const stylesheet = createStyleSheet((theme) => ({
|
|
148
|
-
container: {
|
|
149
|
-
backgroundColor: theme.colors.background,
|
|
150
|
-
borderWidth: 1,
|
|
151
|
-
borderColor: theme.colors.neutral[200],
|
|
152
|
-
borderRadius: theme.radius.md,
|
|
153
|
-
overflow: 'hidden',
|
|
154
|
-
},
|
|
155
|
-
header: {
|
|
156
|
-
flexDirection: 'row',
|
|
157
|
-
backgroundColor: theme.colors.neutral[50],
|
|
158
|
-
borderBottomWidth: 2,
|
|
159
|
-
borderBottomColor: theme.colors.neutral[200],
|
|
160
|
-
},
|
|
161
|
-
headerCell: {
|
|
162
|
-
flexDirection: 'row',
|
|
163
|
-
alignItems: 'center',
|
|
164
|
-
justifyContent: 'space-between',
|
|
165
|
-
padding: theme.spacing.sm,
|
|
166
|
-
borderRightWidth: 1,
|
|
167
|
-
borderRightColor: theme.colors.neutral[200],
|
|
168
|
-
},
|
|
169
|
-
headerText: {
|
|
170
|
-
fontSize: 14,
|
|
171
|
-
color: theme.colors.neutral[700],
|
|
172
|
-
},
|
|
173
|
-
sortIndicator: {
|
|
174
|
-
fontSize: 10,
|
|
175
|
-
marginLeft: theme.spacing.xs,
|
|
176
|
-
color: theme.colors.primary[500],
|
|
177
|
-
},
|
|
178
|
-
row: {
|
|
179
|
-
flexDirection: 'row',
|
|
180
|
-
borderBottomWidth: 1,
|
|
181
|
-
borderBottomColor: theme.colors.neutral[100],
|
|
182
|
-
backgroundColor: theme.colors.background,
|
|
183
|
-
},
|
|
184
|
-
selectedRow: {
|
|
185
|
-
backgroundColor: theme.colors.primary[50],
|
|
186
|
-
},
|
|
187
|
-
cell: {
|
|
188
|
-
padding: theme.spacing.sm,
|
|
189
|
-
borderRightWidth: 1,
|
|
190
|
-
borderRightColor: theme.colors.neutral[100],
|
|
191
|
-
justifyContent: 'center',
|
|
192
|
-
},
|
|
193
|
-
scrollView: {
|
|
194
|
-
flex: 1,
|
|
195
|
-
},
|
|
196
|
-
}));
|