react-native-mantine 0.6.0 → 0.7.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 +1 -1
- package/lib/commonjs/components/Anchor/index.js +6 -1
- package/lib/commonjs/components/Anchor/index.js.map +1 -1
- package/lib/commonjs/components/Badge/index.js +12 -13
- package/lib/commonjs/components/Badge/index.js.map +1 -1
- package/lib/commonjs/components/Blockquote/index.js +8 -12
- package/lib/commonjs/components/Blockquote/index.js.map +1 -1
- package/lib/commonjs/components/Button/index.js +5 -6
- package/lib/commonjs/components/Button/index.js.map +1 -1
- package/lib/commonjs/components/Chip/index.js +8 -9
- package/lib/commonjs/components/Chip/index.js.map +1 -1
- package/lib/commonjs/components/Code/index.js +13 -8
- package/lib/commonjs/components/Code/index.js.map +1 -1
- package/lib/commonjs/components/Kbd/index.js +7 -8
- package/lib/commonjs/components/Kbd/index.js.map +1 -1
- package/lib/commonjs/components/List/index.js +6 -5
- package/lib/commonjs/components/List/index.js.map +1 -1
- package/lib/commonjs/components/Mark/index.js +4 -0
- package/lib/commonjs/components/Mark/index.js.map +1 -1
- package/lib/commonjs/components/Menu/index.js +12 -15
- package/lib/commonjs/components/Menu/index.js.map +1 -1
- package/lib/commonjs/components/NavLink/index.js +7 -11
- package/lib/commonjs/components/NavLink/index.js.map +1 -1
- package/lib/commonjs/components/Notification/index.js +5 -15
- package/lib/commonjs/components/Notification/index.js.map +1 -1
- package/lib/commonjs/components/Table/Table.example.js +131 -0
- package/lib/commonjs/components/Table/Table.example.js.map +1 -0
- package/lib/commonjs/components/Table/index.js +69 -15
- package/lib/commonjs/components/Table/index.js.map +1 -1
- package/lib/commonjs/components/Title/index.js +4 -0
- package/lib/commonjs/components/Title/index.js.map +1 -1
- package/lib/commonjs/theme/utils/index.js +26 -0
- package/lib/commonjs/theme/utils/index.js.map +1 -0
- package/lib/commonjs/theme/utils/withTextWrapper.js +49 -0
- package/lib/commonjs/theme/utils/withTextWrapper.js.map +1 -0
- package/lib/module/components/Anchor/index.js +6 -1
- package/lib/module/components/Anchor/index.js.map +1 -1
- package/lib/module/components/Badge/index.js +5 -6
- package/lib/module/components/Badge/index.js.map +1 -1
- package/lib/module/components/Blockquote/index.js +6 -10
- package/lib/module/components/Blockquote/index.js.map +1 -1
- package/lib/module/components/Button/index.js +5 -6
- package/lib/module/components/Button/index.js.map +1 -1
- package/lib/module/components/Chip/index.js +5 -6
- package/lib/module/components/Chip/index.js.map +1 -1
- package/lib/module/components/Code/index.js +13 -8
- package/lib/module/components/Code/index.js.map +1 -1
- package/lib/module/components/Kbd/index.js +5 -6
- package/lib/module/components/Kbd/index.js.map +1 -1
- package/lib/module/components/List/index.js +6 -5
- package/lib/module/components/List/index.js.map +1 -1
- package/lib/module/components/Mark/index.js +4 -0
- package/lib/module/components/Mark/index.js.map +1 -1
- package/lib/module/components/Menu/index.js +7 -10
- package/lib/module/components/Menu/index.js.map +1 -1
- package/lib/module/components/NavLink/index.js +5 -9
- package/lib/module/components/NavLink/index.js.map +1 -1
- package/lib/module/components/Notification/index.js +5 -15
- package/lib/module/components/Notification/index.js.map +1 -1
- package/lib/module/components/Table/Table.example.js +128 -0
- package/lib/module/components/Table/Table.example.js.map +1 -0
- package/lib/module/components/Table/index.js +70 -16
- package/lib/module/components/Table/index.js.map +1 -1
- package/lib/module/components/Title/index.js +4 -0
- package/lib/module/components/Title/index.js.map +1 -1
- package/lib/module/theme/utils/index.js +5 -0
- package/lib/module/theme/utils/index.js.map +1 -0
- package/lib/module/theme/utils/withTextWrapper.js +45 -0
- package/lib/module/theme/utils/withTextWrapper.js.map +1 -0
- package/lib/typescript/commonjs/src/components/Anchor/index.d.ts +2 -1
- package/lib/typescript/commonjs/src/components/Anchor/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/Badge/index.d.ts +2 -1
- package/lib/typescript/commonjs/src/components/Badge/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/Blockquote/index.d.ts +2 -1
- package/lib/typescript/commonjs/src/components/Blockquote/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/Button/index.d.ts +2 -2
- package/lib/typescript/commonjs/src/components/Button/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/Chip/index.d.ts +2 -1
- package/lib/typescript/commonjs/src/components/Chip/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/Code/index.d.ts +2 -1
- package/lib/typescript/commonjs/src/components/Code/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/Kbd/index.d.ts +2 -1
- package/lib/typescript/commonjs/src/components/Kbd/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/List/index.d.ts +2 -1
- package/lib/typescript/commonjs/src/components/List/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/Mark/index.d.ts +2 -1
- package/lib/typescript/commonjs/src/components/Mark/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/Menu/index.d.ts +3 -2
- package/lib/typescript/commonjs/src/components/Menu/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/NavLink/index.d.ts +2 -1
- package/lib/typescript/commonjs/src/components/NavLink/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/Notification/index.d.ts +2 -1
- package/lib/typescript/commonjs/src/components/Notification/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/Table/Table.example.d.ts +3 -0
- package/lib/typescript/commonjs/src/components/Table/Table.example.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/components/Table/index.d.ts +7 -2
- package/lib/typescript/commonjs/src/components/Table/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/Title/index.d.ts +2 -1
- package/lib/typescript/commonjs/src/components/Title/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/theme/utils/index.d.ts +3 -0
- package/lib/typescript/commonjs/src/theme/utils/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/theme/utils/withTextWrapper.d.ts +41 -0
- package/lib/typescript/commonjs/src/theme/utils/withTextWrapper.d.ts.map +1 -0
- package/lib/typescript/module/src/components/Anchor/index.d.ts +2 -1
- package/lib/typescript/module/src/components/Anchor/index.d.ts.map +1 -1
- package/lib/typescript/module/src/components/Badge/index.d.ts +2 -1
- package/lib/typescript/module/src/components/Badge/index.d.ts.map +1 -1
- package/lib/typescript/module/src/components/Blockquote/index.d.ts +2 -1
- package/lib/typescript/module/src/components/Blockquote/index.d.ts.map +1 -1
- package/lib/typescript/module/src/components/Button/index.d.ts +2 -2
- package/lib/typescript/module/src/components/Button/index.d.ts.map +1 -1
- package/lib/typescript/module/src/components/Chip/index.d.ts +2 -1
- package/lib/typescript/module/src/components/Chip/index.d.ts.map +1 -1
- package/lib/typescript/module/src/components/Code/index.d.ts +2 -1
- package/lib/typescript/module/src/components/Code/index.d.ts.map +1 -1
- package/lib/typescript/module/src/components/Kbd/index.d.ts +2 -1
- package/lib/typescript/module/src/components/Kbd/index.d.ts.map +1 -1
- package/lib/typescript/module/src/components/List/index.d.ts +2 -1
- package/lib/typescript/module/src/components/List/index.d.ts.map +1 -1
- package/lib/typescript/module/src/components/Mark/index.d.ts +2 -1
- package/lib/typescript/module/src/components/Mark/index.d.ts.map +1 -1
- package/lib/typescript/module/src/components/Menu/index.d.ts +3 -2
- package/lib/typescript/module/src/components/Menu/index.d.ts.map +1 -1
- package/lib/typescript/module/src/components/NavLink/index.d.ts +2 -1
- package/lib/typescript/module/src/components/NavLink/index.d.ts.map +1 -1
- package/lib/typescript/module/src/components/Notification/index.d.ts +2 -1
- package/lib/typescript/module/src/components/Notification/index.d.ts.map +1 -1
- package/lib/typescript/module/src/components/Table/Table.example.d.ts +3 -0
- package/lib/typescript/module/src/components/Table/Table.example.d.ts.map +1 -0
- package/lib/typescript/module/src/components/Table/index.d.ts +7 -2
- package/lib/typescript/module/src/components/Table/index.d.ts.map +1 -1
- package/lib/typescript/module/src/components/Title/index.d.ts +2 -1
- package/lib/typescript/module/src/components/Title/index.d.ts.map +1 -1
- package/lib/typescript/module/src/theme/utils/index.d.ts +3 -0
- package/lib/typescript/module/src/theme/utils/index.d.ts.map +1 -0
- package/lib/typescript/module/src/theme/utils/withTextWrapper.d.ts +41 -0
- package/lib/typescript/module/src/theme/utils/withTextWrapper.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/components/Anchor/index.tsx +8 -2
- package/src/components/Badge/index.tsx +5 -3
- package/src/components/Blockquote/index.tsx +6 -5
- package/src/components/Button/index.tsx +5 -6
- package/src/components/Chip/index.tsx +5 -3
- package/src/components/Code/index.tsx +19 -14
- package/src/components/Kbd/index.tsx +5 -4
- package/src/components/List/index.tsx +7 -8
- package/src/components/Mark/index.tsx +7 -2
- package/src/components/Menu/index.tsx +8 -7
- package/src/components/NavLink/index.tsx +6 -4
- package/src/components/Notification/index.tsx +6 -15
- package/src/components/Table/Table.example.tsx +85 -0
- package/src/components/Table/index.tsx +93 -11
- package/src/components/Title/index.tsx +7 -2
- package/src/theme/utils/index.ts +2 -0
- package/src/theme/utils/withTextWrapper.tsx +58 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { View } from 'react-native';
|
|
2
|
+
import { Table } from './index';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Example demonstrating the fixed Table component with proper column alignment.
|
|
6
|
+
*
|
|
7
|
+
* The fix addresses the following issues:
|
|
8
|
+
* 1. Removed flex: 1 from cells which caused equal spacing regardless of content
|
|
9
|
+
* 2. Implemented automatic column width calculation using onLayout callbacks
|
|
10
|
+
* 3. Each column now uses the maximum width of all cells in that column
|
|
11
|
+
* 4. Columns align properly across all rows (thead, tbody, tfoot)
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const elements = [
|
|
15
|
+
{ position: 6, mass: 12.011, symbol: 'C', name: 'Carbon' },
|
|
16
|
+
{ position: 7, mass: 14.007, symbol: 'N', name: 'Nitrogen' },
|
|
17
|
+
{ position: 39, mass: 88.906, symbol: 'Y', name: 'Yttrium' },
|
|
18
|
+
{ position: 56, mass: 137.33, symbol: 'Ba', name: 'Barium' },
|
|
19
|
+
{ position: 58, mass: 140.12, symbol: 'Ce', name: 'Cerium' },
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
export function TableExample() {
|
|
23
|
+
return (
|
|
24
|
+
<View style={{ padding: 40 }}>
|
|
25
|
+
<Table
|
|
26
|
+
verticalSpacing="md"
|
|
27
|
+
horizontalSpacing="md"
|
|
28
|
+
fontSize="sm"
|
|
29
|
+
striped
|
|
30
|
+
withBorder
|
|
31
|
+
withColumnBorders
|
|
32
|
+
>
|
|
33
|
+
<Table.Thead>
|
|
34
|
+
<Table.Tr>
|
|
35
|
+
<Table.Th>Element position</Table.Th>
|
|
36
|
+
<Table.Th>Element name</Table.Th>
|
|
37
|
+
<Table.Th>Symbol</Table.Th>
|
|
38
|
+
<Table.Th>Atomic mass</Table.Th>
|
|
39
|
+
</Table.Tr>
|
|
40
|
+
</Table.Thead>
|
|
41
|
+
<Table.Tbody>
|
|
42
|
+
{elements.map((element) => (
|
|
43
|
+
<Table.Tr key={element.name}>
|
|
44
|
+
<Table.Td>{element.position}</Table.Td>
|
|
45
|
+
<Table.Td>{element.name}</Table.Td>
|
|
46
|
+
<Table.Td>{element.symbol}</Table.Td>
|
|
47
|
+
<Table.Td>{element.mass}</Table.Td>
|
|
48
|
+
</Table.Tr>
|
|
49
|
+
))}
|
|
50
|
+
</Table.Tbody>
|
|
51
|
+
</Table>
|
|
52
|
+
</View>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function TableWithVariableContent() {
|
|
57
|
+
return (
|
|
58
|
+
<View style={{ padding: 40 }}>
|
|
59
|
+
<Table withBorder withColumnBorders>
|
|
60
|
+
<Table.Thead>
|
|
61
|
+
<Table.Tr>
|
|
62
|
+
<Table.Th>Short</Table.Th>
|
|
63
|
+
<Table.Th>Medium length header</Table.Th>
|
|
64
|
+
<Table.Th>Very long header text that spans multiple words</Table.Th>
|
|
65
|
+
<Table.Th>ID</Table.Th>
|
|
66
|
+
</Table.Tr>
|
|
67
|
+
</Table.Thead>
|
|
68
|
+
<Table.Tbody>
|
|
69
|
+
<Table.Tr>
|
|
70
|
+
<Table.Td>A</Table.Td>
|
|
71
|
+
<Table.Td>Medium content here</Table.Td>
|
|
72
|
+
<Table.Td>Short</Table.Td>
|
|
73
|
+
<Table.Td>1</Table.Td>
|
|
74
|
+
</Table.Tr>
|
|
75
|
+
<Table.Tr>
|
|
76
|
+
<Table.Td>B</Table.Td>
|
|
77
|
+
<Table.Td>Short</Table.Td>
|
|
78
|
+
<Table.Td>This is a very long content that should make the column wider</Table.Td>
|
|
79
|
+
<Table.Td>2</Table.Td>
|
|
80
|
+
</Table.Tr>
|
|
81
|
+
</Table.Tbody>
|
|
82
|
+
</Table>
|
|
83
|
+
</View>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import React, { forwardRef, createContext, useContext } from 'react';
|
|
1
|
+
import React, { forwardRef, createContext, useContext, useState, useCallback } from 'react';
|
|
2
2
|
import { ScrollView } from 'react-native';
|
|
3
|
+
import type { LayoutChangeEvent } from 'react-native';
|
|
3
4
|
import { BoxView } from '../BoxView';
|
|
4
5
|
import { Text } from '../Text';
|
|
5
6
|
import type { DefaultProps, SpacingValue } from '../../theme/types';
|
|
6
7
|
import { useComponentDefaultProps } from '../../theme/theme-provider';
|
|
7
8
|
import { createStyles } from '../../theme';
|
|
8
9
|
import { rem } from '../../theme/utils/rem';
|
|
10
|
+
import { withTextWrapper, type WithTextWrapperProps } from '../../theme/utils/withTextWrapper';
|
|
9
11
|
|
|
10
12
|
interface TableContextValue {
|
|
11
13
|
striped: boolean;
|
|
@@ -15,6 +17,8 @@ interface TableContextValue {
|
|
|
15
17
|
fontSize: 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
16
18
|
verticalSpacing: SpacingValue;
|
|
17
19
|
horizontalSpacing: SpacingValue;
|
|
20
|
+
columnWidths: number[];
|
|
21
|
+
onCellLayout: (columnIndex: number, width: number) => void;
|
|
18
22
|
}
|
|
19
23
|
|
|
20
24
|
const TableContext = createContext<TableContextValue | null>(null);
|
|
@@ -94,20 +98,26 @@ export interface TableTrProps extends DefaultProps {
|
|
|
94
98
|
__index?: number;
|
|
95
99
|
}
|
|
96
100
|
|
|
97
|
-
export interface TableThProps extends DefaultProps {
|
|
101
|
+
export interface TableThProps extends DefaultProps, WithTextWrapperProps {
|
|
98
102
|
/** Th children */
|
|
99
103
|
children?: React.ReactNode;
|
|
100
104
|
|
|
101
105
|
/** Additional styles */
|
|
102
106
|
style?: any;
|
|
107
|
+
|
|
108
|
+
/** Internal column index */
|
|
109
|
+
__columnIndex?: number;
|
|
103
110
|
}
|
|
104
111
|
|
|
105
|
-
export interface TableTdProps extends DefaultProps {
|
|
112
|
+
export interface TableTdProps extends DefaultProps, WithTextWrapperProps {
|
|
106
113
|
/** Td children */
|
|
107
114
|
children?: React.ReactNode;
|
|
108
115
|
|
|
109
116
|
/** Additional styles */
|
|
110
117
|
style?: any;
|
|
118
|
+
|
|
119
|
+
/** Internal column index */
|
|
120
|
+
__columnIndex?: number;
|
|
111
121
|
}
|
|
112
122
|
|
|
113
123
|
const fontSizes = {
|
|
@@ -130,7 +140,7 @@ const useTableStyles = createStyles(
|
|
|
130
140
|
}
|
|
131
141
|
) => ({
|
|
132
142
|
wrapper: {
|
|
133
|
-
flex: 1
|
|
143
|
+
// No flex: 1 here to avoid constraining the table
|
|
134
144
|
},
|
|
135
145
|
root: {
|
|
136
146
|
width: '100%',
|
|
@@ -179,6 +189,7 @@ const useTableRowStyles = createStyles(
|
|
|
179
189
|
}
|
|
180
190
|
) => ({
|
|
181
191
|
tr: {
|
|
192
|
+
flexDirection: 'row',
|
|
182
193
|
borderBottomWidth: 1,
|
|
183
194
|
borderBottomColor:
|
|
184
195
|
theme.colorScheme === 'dark'
|
|
@@ -204,12 +215,14 @@ const useTableCellStyles = createStyles(
|
|
|
204
215
|
horizontalSpacing,
|
|
205
216
|
withColumnBorders,
|
|
206
217
|
isHeader,
|
|
218
|
+
width,
|
|
207
219
|
}: {
|
|
208
220
|
fontSize: 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
209
221
|
verticalSpacing: SpacingValue;
|
|
210
222
|
horizontalSpacing: SpacingValue;
|
|
211
223
|
withColumnBorders: boolean;
|
|
212
224
|
isHeader: boolean;
|
|
225
|
+
width?: number;
|
|
213
226
|
}
|
|
214
227
|
) => {
|
|
215
228
|
const getVerticalPadding = () => {
|
|
@@ -224,6 +237,9 @@ const useTableCellStyles = createStyles(
|
|
|
224
237
|
|
|
225
238
|
return {
|
|
226
239
|
cell: {
|
|
240
|
+
// Remove flex: 1 to prevent equal spacing
|
|
241
|
+
// Use explicit width when available for column alignment
|
|
242
|
+
...(width && { width }),
|
|
227
243
|
paddingVertical: getVerticalPadding() as any,
|
|
228
244
|
paddingHorizontal: getHorizontalPadding() as any,
|
|
229
245
|
fontSize: fontSizes[fontSize],
|
|
@@ -276,6 +292,20 @@ const Table = forwardRef<any, TableProps>((props, ref) => {
|
|
|
276
292
|
{ name: 'Table' }
|
|
277
293
|
) as any;
|
|
278
294
|
|
|
295
|
+
// Track column widths to ensure alignment across rows
|
|
296
|
+
const [columnWidths, setColumnWidths] = useState<number[]>([]);
|
|
297
|
+
|
|
298
|
+
const onCellLayout = useCallback((columnIndex: number, width: number) => {
|
|
299
|
+
setColumnWidths((prevWidths) => {
|
|
300
|
+
const newWidths = [...prevWidths];
|
|
301
|
+
// Store the maximum width for each column to ensure all cells in that column have the same width
|
|
302
|
+
if (!newWidths[columnIndex] || width > newWidths[columnIndex]) {
|
|
303
|
+
newWidths[columnIndex] = width;
|
|
304
|
+
}
|
|
305
|
+
return newWidths;
|
|
306
|
+
});
|
|
307
|
+
}, []);
|
|
308
|
+
|
|
279
309
|
return (
|
|
280
310
|
<TableContext.Provider
|
|
281
311
|
value={{
|
|
@@ -286,6 +316,8 @@ const Table = forwardRef<any, TableProps>((props, ref) => {
|
|
|
286
316
|
fontSize: fontSize!,
|
|
287
317
|
verticalSpacing: verticalSpacing!,
|
|
288
318
|
horizontalSpacing: horizontalSpacing!,
|
|
319
|
+
columnWidths,
|
|
320
|
+
onCellLayout,
|
|
289
321
|
}}
|
|
290
322
|
>
|
|
291
323
|
<ScrollView
|
|
@@ -357,17 +389,32 @@ const Tr = forwardRef<any, TableTrProps>((props, ref) => {
|
|
|
357
389
|
{ name: 'Tr' }
|
|
358
390
|
) as any;
|
|
359
391
|
|
|
392
|
+
// Add column indices to children (Th and Td components)
|
|
393
|
+
const childrenArray = React.Children.toArray(children);
|
|
394
|
+
const childrenWithColumnIndex = childrenArray.map((child, index) => {
|
|
395
|
+
if (!React.isValidElement(child)) return child;
|
|
396
|
+
return React.cloneElement<TableThProps | TableTdProps>(
|
|
397
|
+
child as React.ReactElement<TableThProps | TableTdProps>,
|
|
398
|
+
{
|
|
399
|
+
__columnIndex: index,
|
|
400
|
+
}
|
|
401
|
+
);
|
|
402
|
+
});
|
|
403
|
+
|
|
360
404
|
return (
|
|
361
405
|
<BoxView ref={ref} style={sx(styles.tr, style)} {...others}>
|
|
362
|
-
{
|
|
406
|
+
{childrenWithColumnIndex}
|
|
363
407
|
</BoxView>
|
|
364
408
|
);
|
|
365
409
|
});
|
|
366
410
|
|
|
367
411
|
const Th = forwardRef<any, TableThProps>((props, ref) => {
|
|
368
|
-
const { children, style, ...others } = props;
|
|
412
|
+
const { children, style, withTextWrapper: shouldWrapInText = true, __columnIndex, ...others } = props;
|
|
369
413
|
const context = useTableContext();
|
|
370
414
|
|
|
415
|
+
const columnIndex = __columnIndex ?? 0;
|
|
416
|
+
const columnWidth = context?.columnWidths?.[columnIndex];
|
|
417
|
+
|
|
371
418
|
const { styles, sx } = useTableCellStyles(
|
|
372
419
|
{
|
|
373
420
|
fontSize: context?.fontSize ?? 'sm',
|
|
@@ -375,21 +422,40 @@ const Th = forwardRef<any, TableThProps>((props, ref) => {
|
|
|
375
422
|
horizontalSpacing: context?.horizontalSpacing ?? 'xs',
|
|
376
423
|
withColumnBorders: context?.withColumnBorders ?? false,
|
|
377
424
|
isHeader: true,
|
|
425
|
+
width: columnWidth,
|
|
378
426
|
},
|
|
379
427
|
{ name: 'Th' }
|
|
380
428
|
) as any;
|
|
381
429
|
|
|
430
|
+
const handleLayout = useCallback(
|
|
431
|
+
(event: LayoutChangeEvent) => {
|
|
432
|
+
const { width } = event.nativeEvent.layout;
|
|
433
|
+
if (context?.onCellLayout && width > 0) {
|
|
434
|
+
context.onCellLayout(columnIndex, width);
|
|
435
|
+
}
|
|
436
|
+
},
|
|
437
|
+
[context, columnIndex]
|
|
438
|
+
);
|
|
439
|
+
|
|
382
440
|
return (
|
|
383
|
-
<BoxView
|
|
384
|
-
|
|
441
|
+
<BoxView
|
|
442
|
+
ref={ref}
|
|
443
|
+
style={sx(styles.cell, style)}
|
|
444
|
+
onLayout={handleLayout}
|
|
445
|
+
{...others}
|
|
446
|
+
>
|
|
447
|
+
{withTextWrapper(children, shouldWrapInText, styles.cell)}
|
|
385
448
|
</BoxView>
|
|
386
449
|
);
|
|
387
450
|
});
|
|
388
451
|
|
|
389
452
|
const Td = forwardRef<any, TableTdProps>((props, ref) => {
|
|
390
|
-
const { children, style, ...others } = props;
|
|
453
|
+
const { children, style, withTextWrapper: shouldWrapInText = true, __columnIndex, ...others } = props;
|
|
391
454
|
const context = useTableContext();
|
|
392
455
|
|
|
456
|
+
const columnIndex = __columnIndex ?? 0;
|
|
457
|
+
const columnWidth = context?.columnWidths?.[columnIndex];
|
|
458
|
+
|
|
393
459
|
const { styles, sx } = useTableCellStyles(
|
|
394
460
|
{
|
|
395
461
|
fontSize: context?.fontSize ?? 'sm',
|
|
@@ -397,13 +463,29 @@ const Td = forwardRef<any, TableTdProps>((props, ref) => {
|
|
|
397
463
|
horizontalSpacing: context?.horizontalSpacing ?? 'xs',
|
|
398
464
|
withColumnBorders: context?.withColumnBorders ?? false,
|
|
399
465
|
isHeader: false,
|
|
466
|
+
width: columnWidth,
|
|
400
467
|
},
|
|
401
468
|
{ name: 'Td' }
|
|
402
469
|
) as any;
|
|
403
470
|
|
|
471
|
+
const handleLayout = useCallback(
|
|
472
|
+
(event: LayoutChangeEvent) => {
|
|
473
|
+
const { width } = event.nativeEvent.layout;
|
|
474
|
+
if (context?.onCellLayout && width > 0) {
|
|
475
|
+
context.onCellLayout(columnIndex, width);
|
|
476
|
+
}
|
|
477
|
+
},
|
|
478
|
+
[context, columnIndex]
|
|
479
|
+
);
|
|
480
|
+
|
|
404
481
|
return (
|
|
405
|
-
<BoxView
|
|
406
|
-
|
|
482
|
+
<BoxView
|
|
483
|
+
ref={ref}
|
|
484
|
+
style={sx(styles.cell, style)}
|
|
485
|
+
onLayout={handleLayout}
|
|
486
|
+
{...others}
|
|
487
|
+
>
|
|
488
|
+
{withTextWrapper(children, shouldWrapInText, styles.cell)}
|
|
407
489
|
</BoxView>
|
|
408
490
|
);
|
|
409
491
|
});
|
|
@@ -2,8 +2,9 @@ import React, { forwardRef } from 'react';
|
|
|
2
2
|
import { Text } from '../Text';
|
|
3
3
|
import type { TextProps } from '../Text';
|
|
4
4
|
import { useTheme } from '../../theme/theme-provider';
|
|
5
|
+
import type { WithTextWrapperProps } from '../../theme/utils/withTextWrapper';
|
|
5
6
|
|
|
6
|
-
export interface TitleProps extends Omit<TextProps, 'size'
|
|
7
|
+
export interface TitleProps extends Omit<TextProps, 'size'>, WithTextWrapperProps {
|
|
7
8
|
/** Heading order (h1-h6) */
|
|
8
9
|
order?: 1 | 2 | 3 | 4 | 5 | 6;
|
|
9
10
|
|
|
@@ -16,7 +17,7 @@ export interface TitleProps extends Omit<TextProps, 'size'> {
|
|
|
16
17
|
* Maps order prop to h1-h6 heading styles from theme
|
|
17
18
|
*/
|
|
18
19
|
export const Title = forwardRef<any, TitleProps>((props, ref) => {
|
|
19
|
-
const { order = 1, children, style, ...others} = props;
|
|
20
|
+
const { order = 1, children, style, withTextWrapper: shouldWrapInText = true, ...others} = props;
|
|
20
21
|
const theme = useTheme();
|
|
21
22
|
|
|
22
23
|
// Get heading styles from theme
|
|
@@ -29,6 +30,10 @@ export const Title = forwardRef<any, TitleProps>((props, ref) => {
|
|
|
29
30
|
theme.headings.fontWeight ??
|
|
30
31
|
700;
|
|
31
32
|
|
|
33
|
+
if (!shouldWrapInText) {
|
|
34
|
+
return children;
|
|
35
|
+
}
|
|
36
|
+
|
|
32
37
|
return (
|
|
33
38
|
<Text
|
|
34
39
|
ref={ref}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import { Text } from '../../components/Text';
|
|
3
|
+
import type { TextProps } from '../../components/Text';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Conditionally wraps content in a Text component based on the withTextWrapper prop.
|
|
7
|
+
*
|
|
8
|
+
* In React Native, all text must be wrapped in a Text component. However, some
|
|
9
|
+
* components may need flexibility to render with or without this wrapper depending
|
|
10
|
+
* on whether their content is text or other components (like icons, views, etc.).
|
|
11
|
+
*
|
|
12
|
+
* @param children - The content to potentially wrap
|
|
13
|
+
* @param shouldWrap - Whether to wrap the content in a Text component
|
|
14
|
+
* @param textStyle - Optional style to apply to the Text wrapper
|
|
15
|
+
* @param textProps - Optional additional props to pass to the Text component
|
|
16
|
+
* @returns The children wrapped in Text if shouldWrap is true, otherwise just the children
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* // Wrap text content
|
|
20
|
+
* withTextWrapper('Hello', true, styles.text)
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* // Don't wrap components
|
|
24
|
+
* withTextWrapper(<Icon />, false)
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* // Default behavior (wrap)
|
|
28
|
+
* withTextWrapper('Text', true, styles.text, { numberOfLines: 1 })
|
|
29
|
+
*/
|
|
30
|
+
export function withTextWrapper(
|
|
31
|
+
children: ReactNode,
|
|
32
|
+
shouldWrap: boolean = true,
|
|
33
|
+
textStyle?: any,
|
|
34
|
+
textProps?: Omit<TextProps, 'children' | 'style'>
|
|
35
|
+
): ReactNode {
|
|
36
|
+
if (!shouldWrap) {
|
|
37
|
+
return children;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<Text style={textStyle} {...textProps}>
|
|
42
|
+
{children}
|
|
43
|
+
</Text>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Type helper for components that support the withTextWrapper pattern.
|
|
49
|
+
* Add this to your component props interface.
|
|
50
|
+
*/
|
|
51
|
+
export interface WithTextWrapperProps {
|
|
52
|
+
/**
|
|
53
|
+
* If false, children will not be wrapped in a Text component.
|
|
54
|
+
* This is useful when the children contain non-text elements like icons or custom components.
|
|
55
|
+
* @default true
|
|
56
|
+
*/
|
|
57
|
+
withTextWrapper?: boolean;
|
|
58
|
+
}
|