@cdx-ui/components 0.0.1-beta.183 → 0.0.1-beta.185

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.
Files changed (44) hide show
  1. package/coverage.svg +1 -1
  2. package/lib/commonjs/components/Table/index.js +404 -0
  3. package/lib/commonjs/components/Table/index.js.map +1 -0
  4. package/lib/commonjs/components/Table/index.web.js +295 -0
  5. package/lib/commonjs/components/Table/index.web.js.map +1 -0
  6. package/lib/commonjs/components/Table/styles.js +63 -0
  7. package/lib/commonjs/components/Table/styles.js.map +1 -0
  8. package/lib/commonjs/components/Table/types.js +6 -0
  9. package/lib/commonjs/components/Table/types.js.map +1 -0
  10. package/lib/commonjs/components/Table/useTableStyleContext.js +28 -0
  11. package/lib/commonjs/components/Table/useTableStyleContext.js.map +1 -0
  12. package/lib/commonjs/components/index.js +12 -0
  13. package/lib/commonjs/components/index.js.map +1 -1
  14. package/lib/module/components/Table/index.js +400 -0
  15. package/lib/module/components/Table/index.js.map +1 -0
  16. package/lib/module/components/Table/index.web.js +291 -0
  17. package/lib/module/components/Table/index.web.js.map +1 -0
  18. package/lib/module/components/Table/styles.js +59 -0
  19. package/lib/module/components/Table/styles.js.map +1 -0
  20. package/lib/module/components/Table/types.js +4 -0
  21. package/lib/module/components/Table/types.js.map +1 -0
  22. package/lib/module/components/Table/useTableStyleContext.js +17 -0
  23. package/lib/module/components/Table/useTableStyleContext.js.map +1 -0
  24. package/lib/module/components/index.js +1 -0
  25. package/lib/module/components/index.js.map +1 -1
  26. package/lib/typescript/components/Table/index.d.ts +23 -0
  27. package/lib/typescript/components/Table/index.d.ts.map +1 -0
  28. package/lib/typescript/components/Table/index.web.d.ts +22 -0
  29. package/lib/typescript/components/Table/index.web.d.ts.map +1 -0
  30. package/lib/typescript/components/Table/styles.d.ts +26 -0
  31. package/lib/typescript/components/Table/styles.d.ts.map +1 -0
  32. package/lib/typescript/components/Table/types.d.ts +39 -0
  33. package/lib/typescript/components/Table/types.d.ts.map +1 -0
  34. package/lib/typescript/components/Table/useTableStyleContext.d.ts +11 -0
  35. package/lib/typescript/components/Table/useTableStyleContext.d.ts.map +1 -0
  36. package/lib/typescript/components/index.d.ts +1 -0
  37. package/lib/typescript/components/index.d.ts.map +1 -1
  38. package/package.json +5 -5
  39. package/src/components/Table/index.tsx +489 -0
  40. package/src/components/Table/index.web.tsx +367 -0
  41. package/src/components/Table/styles.ts +90 -0
  42. package/src/components/Table/types.ts +44 -0
  43. package/src/components/Table/useTableStyleContext.ts +14 -0
  44. package/src/components/index.ts +1 -0
@@ -0,0 +1,367 @@
1
+ import { forwardRef, type ComponentPropsWithoutRef, type CSSProperties } from 'react';
2
+ import { View } from 'react-native';
3
+ import {
4
+ Slot,
5
+ dataAttributes,
6
+ mapViewPropsToDom,
7
+ mergeDataAttributes,
8
+ mergeDomDataAttributes,
9
+ domDataAttributes,
10
+ } from '@cdx-ui/primitives';
11
+ import { cn } from '@cdx-ui/utils';
12
+ import {
13
+ tableBodyVariants,
14
+ tableCaptionVariants,
15
+ tableCellVariants,
16
+ tableContainerVariants,
17
+ tableFooterVariants,
18
+ tableHeadVariants,
19
+ tableHeaderVariants,
20
+ tableRootVariants,
21
+ tableRowVariants,
22
+ } from './styles';
23
+ import type {
24
+ TableCaptionProps,
25
+ TableCellProps,
26
+ TableHeadProps,
27
+ TableProps,
28
+ TableRowProps,
29
+ TableSectionProps,
30
+ } from './types';
31
+ import {
32
+ ParentContext,
33
+ useTableStyleContext,
34
+ useTableVariantContext,
35
+ } from './useTableStyleContext';
36
+
37
+ export type {
38
+ TableCaptionProps,
39
+ TableCellProps,
40
+ TableHeadProps,
41
+ TableProps,
42
+ TableRowProps,
43
+ TableSectionProps,
44
+ } from './types';
45
+ export type { TableVariantProps } from './styles';
46
+
47
+ type WebTableProps = TableProps & ComponentPropsWithoutRef<'table'>;
48
+ type WebTableCaptionProps = TableCaptionProps & ComponentPropsWithoutRef<'caption'>;
49
+ type WebTableSectionProps = TableSectionProps &
50
+ ComponentPropsWithoutRef<'thead' | 'tbody' | 'tfoot'>;
51
+ type WebTableRowProps = TableRowProps & ComponentPropsWithoutRef<'tr'>;
52
+ type WebTableHeadProps = TableHeadProps & ComponentPropsWithoutRef<'th'>;
53
+ type WebTableCellProps = TableCellProps & ComponentPropsWithoutRef<'td'>;
54
+
55
+ const tableHostProps = (props: object, slot: string) => {
56
+ const mapped = mapViewPropsToDom(props);
57
+ return {
58
+ ...mapped,
59
+ ...mergeDomDataAttributes(
60
+ props as Record<string, unknown>,
61
+ mapped,
62
+ domDataAttributes({ slot }),
63
+ ),
64
+ };
65
+ };
66
+
67
+ const TableRoot = forwardRef<HTMLTableElement, WebTableProps>(
68
+ ({ asChild, className, children, style, fullBleed = false, ...props }, ref) => {
69
+ const ctx = useTableVariantContext(fullBleed);
70
+
71
+ if (asChild) {
72
+ const Comp = Slot;
73
+ return (
74
+ <ParentContext.Provider value={ctx}>
75
+ <Comp
76
+ ref={ref}
77
+ className={cn(tableContainerVariants(), tableRootVariants(), className)}
78
+ style={style}
79
+ {...props}
80
+ {...mergeDataAttributes(props, dataAttributes({ slot: 'table' }))}
81
+ >
82
+ {children}
83
+ </Comp>
84
+ </ParentContext.Provider>
85
+ );
86
+ }
87
+
88
+ return (
89
+ <ParentContext.Provider value={ctx}>
90
+ <View className={tableContainerVariants()}>
91
+ <table
92
+ ref={ref}
93
+ className={cn(tableRootVariants(), className)}
94
+ style={style as CSSProperties | undefined}
95
+ {...tableHostProps(props, 'table')}
96
+ >
97
+ {children}
98
+ </table>
99
+ </View>
100
+ </ParentContext.Provider>
101
+ );
102
+ },
103
+ );
104
+
105
+ TableRoot.displayName = 'Table';
106
+
107
+ const TableCaption = forwardRef<HTMLTableCaptionElement, WebTableCaptionProps>(
108
+ ({ asChild, className, children, style, ...props }, ref) => {
109
+ const computedClassName = cn(tableCaptionVariants(), className);
110
+
111
+ if (asChild) {
112
+ const Comp = Slot;
113
+ return (
114
+ <Comp
115
+ ref={ref}
116
+ className={computedClassName}
117
+ style={style}
118
+ {...props}
119
+ {...mergeDataAttributes(props, dataAttributes({ slot: 'table-caption' }))}
120
+ >
121
+ {children}
122
+ </Comp>
123
+ );
124
+ }
125
+
126
+ return (
127
+ <caption
128
+ ref={ref}
129
+ className={computedClassName}
130
+ style={style as CSSProperties | undefined}
131
+ {...tableHostProps(props, 'table-caption')}
132
+ >
133
+ {children}
134
+ </caption>
135
+ );
136
+ },
137
+ );
138
+
139
+ TableCaption.displayName = 'Table.Caption';
140
+
141
+ const TableHeader = forwardRef<HTMLTableSectionElement, WebTableSectionProps>(
142
+ ({ asChild, className, children, style, ...props }, ref) => {
143
+ const computedClassName = cn(tableHeaderVariants(), className);
144
+
145
+ if (asChild) {
146
+ const Comp = Slot;
147
+ return (
148
+ <Comp
149
+ ref={ref}
150
+ className={computedClassName}
151
+ style={style}
152
+ {...props}
153
+ {...mergeDataAttributes(props, dataAttributes({ slot: 'table-header' }))}
154
+ >
155
+ {children}
156
+ </Comp>
157
+ );
158
+ }
159
+
160
+ return (
161
+ <thead
162
+ ref={ref}
163
+ className={computedClassName}
164
+ style={style as CSSProperties | undefined}
165
+ {...tableHostProps(props, 'table-header')}
166
+ >
167
+ {children}
168
+ </thead>
169
+ );
170
+ },
171
+ );
172
+
173
+ TableHeader.displayName = 'Table.Header';
174
+
175
+ const TableBody = forwardRef<HTMLTableSectionElement, WebTableSectionProps>(
176
+ ({ asChild, className, children, style, ...props }, ref) => {
177
+ const computedClassName = cn(tableBodyVariants(), className);
178
+
179
+ if (asChild) {
180
+ const Comp = Slot;
181
+ return (
182
+ <Comp
183
+ ref={ref}
184
+ className={computedClassName}
185
+ style={style}
186
+ {...props}
187
+ {...mergeDataAttributes(props, dataAttributes({ slot: 'table-body' }))}
188
+ >
189
+ {children}
190
+ </Comp>
191
+ );
192
+ }
193
+
194
+ return (
195
+ <tbody
196
+ ref={ref}
197
+ className={computedClassName}
198
+ style={style as CSSProperties | undefined}
199
+ {...tableHostProps(props, 'table-body')}
200
+ >
201
+ {children}
202
+ </tbody>
203
+ );
204
+ },
205
+ );
206
+
207
+ TableBody.displayName = 'Table.Body';
208
+
209
+ const TableFooter = forwardRef<HTMLTableSectionElement, WebTableSectionProps>(
210
+ ({ asChild, className, children, style, ...props }, ref) => {
211
+ const computedClassName = cn(tableFooterVariants(), className);
212
+
213
+ if (asChild) {
214
+ const Comp = Slot;
215
+ return (
216
+ <Comp
217
+ ref={ref}
218
+ className={computedClassName}
219
+ style={style}
220
+ {...props}
221
+ {...mergeDataAttributes(props, dataAttributes({ slot: 'table-footer' }))}
222
+ >
223
+ {children}
224
+ </Comp>
225
+ );
226
+ }
227
+
228
+ return (
229
+ <tfoot
230
+ ref={ref}
231
+ className={computedClassName}
232
+ style={style as CSSProperties | undefined}
233
+ {...tableHostProps(props, 'table-footer')}
234
+ >
235
+ {children}
236
+ </tfoot>
237
+ );
238
+ },
239
+ );
240
+
241
+ TableFooter.displayName = 'Table.Footer';
242
+
243
+ const TableRow = forwardRef<HTMLTableRowElement, WebTableRowProps>(
244
+ ({ asChild, className, children, style, ...props }, ref) => {
245
+ const computedClassName = cn(tableRowVariants(), className);
246
+
247
+ if (asChild) {
248
+ const Comp = Slot;
249
+ return (
250
+ <Comp
251
+ ref={ref}
252
+ className={computedClassName}
253
+ style={style}
254
+ {...props}
255
+ {...mergeDataAttributes(props, dataAttributes({ slot: 'table-row' }))}
256
+ >
257
+ {children}
258
+ </Comp>
259
+ );
260
+ }
261
+
262
+ return (
263
+ <tr
264
+ ref={ref}
265
+ className={computedClassName}
266
+ style={style as CSSProperties | undefined}
267
+ {...tableHostProps(props, 'table-row')}
268
+ >
269
+ {children}
270
+ </tr>
271
+ );
272
+ },
273
+ );
274
+
275
+ TableRow.displayName = 'Table.Row';
276
+
277
+ const TableHead = forwardRef<HTMLTableCellElement, WebTableHeadProps>(
278
+ ({ asChild, className, children, style, scope = 'col', ...props }, ref) => {
279
+ const { fullBleed } = useTableStyleContext();
280
+ const computedClassName = cn(tableHeadVariants({ fullBleed }), className);
281
+
282
+ if (asChild) {
283
+ const Comp = Slot;
284
+ return (
285
+ <Comp
286
+ ref={ref}
287
+ className={computedClassName}
288
+ style={style}
289
+ scope={scope}
290
+ {...props}
291
+ {...mergeDataAttributes(props, dataAttributes({ slot: 'table-head' }))}
292
+ >
293
+ {children}
294
+ </Comp>
295
+ );
296
+ }
297
+
298
+ return (
299
+ <th
300
+ ref={ref}
301
+ className={computedClassName}
302
+ scope={scope}
303
+ style={style as CSSProperties | undefined}
304
+ {...tableHostProps(props, 'table-head')}
305
+ >
306
+ {children}
307
+ </th>
308
+ );
309
+ },
310
+ );
311
+
312
+ TableHead.displayName = 'Table.Head';
313
+
314
+ const TableCell = forwardRef<HTMLTableCellElement, WebTableCellProps>(
315
+ ({ asChild, className, children, style, ...props }, ref) => {
316
+ const { fullBleed } = useTableStyleContext();
317
+ const computedClassName = cn(tableCellVariants({ fullBleed }), className);
318
+
319
+ if (asChild) {
320
+ const Comp = Slot;
321
+ return (
322
+ <Comp
323
+ ref={ref}
324
+ className={computedClassName}
325
+ style={style}
326
+ {...props}
327
+ {...mergeDataAttributes(props, dataAttributes({ slot: 'table-cell' }))}
328
+ >
329
+ {children}
330
+ </Comp>
331
+ );
332
+ }
333
+
334
+ return (
335
+ <td
336
+ ref={ref}
337
+ className={computedClassName}
338
+ style={style as CSSProperties | undefined}
339
+ {...tableHostProps(props, 'table-cell')}
340
+ >
341
+ {children}
342
+ </td>
343
+ );
344
+ },
345
+ );
346
+
347
+ TableCell.displayName = 'Table.Cell';
348
+
349
+ type TableCompoundComponent = typeof TableRoot & {
350
+ Caption: typeof TableCaption;
351
+ Header: typeof TableHeader;
352
+ Body: typeof TableBody;
353
+ Footer: typeof TableFooter;
354
+ Row: typeof TableRow;
355
+ Head: typeof TableHead;
356
+ Cell: typeof TableCell;
357
+ };
358
+
359
+ export const Table = Object.assign(TableRoot, {
360
+ Caption: TableCaption,
361
+ Header: TableHeader,
362
+ Body: TableBody,
363
+ Footer: TableFooter,
364
+ Row: TableRow,
365
+ Head: TableHead,
366
+ Cell: TableCell,
367
+ }) as TableCompoundComponent;
@@ -0,0 +1,90 @@
1
+ import { cva, type VariantProps } from '@cdx-ui/utils';
2
+
3
+ export const tableContainerVariants = cva('relative w-full overflow-auto');
4
+
5
+ export const tableRootVariants = cva('w-full caption-bottom body-md text-content-primary');
6
+
7
+ export const tableNativeRootVariants = cva(
8
+ 'min-w-full flex-col caption-bottom body-md text-content-primary',
9
+ );
10
+
11
+ export const tableCaptionVariants = cva('mt-4 body-sm text-content-secondary');
12
+
13
+ export const tableNativeCaptionVariants = cva('mt-4 body-sm text-content-secondary');
14
+
15
+ export const tableHeaderVariants = cva('border-stroke-secondary [&_tr]:border-b');
16
+
17
+ export const tableBodyVariants = cva('[&_tr:last-child]:border-0');
18
+
19
+ export const tableFooterVariants = cva(
20
+ 'border-t border-stroke-secondary bg-surface-secondary body-md font-medium [&>tr]:last:border-b-0',
21
+ );
22
+
23
+ export const tableRowVariants = cva(
24
+ 'border-b border-stroke-secondary web:transition-colors web:hover:bg-surface-secondary/50',
25
+ );
26
+
27
+ export const tableHeadVariants = cva(
28
+ 'h-11 px-2 text-left align-middle font-medium text-content-secondary body-md',
29
+ {
30
+ variants: {
31
+ fullBleed: {
32
+ true: 'first:pl-0 last:pr-0',
33
+ false: '',
34
+ },
35
+ },
36
+ defaultVariants: {
37
+ fullBleed: false,
38
+ },
39
+ },
40
+ );
41
+
42
+ export const tableCellVariants = cva('p-2 align-middle body-md text-content-primary', {
43
+ variants: {
44
+ fullBleed: {
45
+ true: 'first:pl-0 last:pr-0',
46
+ false: '',
47
+ },
48
+ },
49
+ defaultVariants: {
50
+ fullBleed: false,
51
+ },
52
+ });
53
+
54
+ export const tableNativeRowVariants = cva(
55
+ 'min-w-full flex-row flex-nowrap border-b border-stroke-secondary',
56
+ );
57
+
58
+ export const tableNativeHeadVariants = cva(
59
+ 'min-h-11 overflow-hidden px-2 items-start justify-center font-medium text-content-secondary body-md',
60
+ {
61
+ variants: {
62
+ fullBleed: {
63
+ true: 'first:pl-0 last:pr-0',
64
+ false: '',
65
+ },
66
+ },
67
+ defaultVariants: {
68
+ fullBleed: false,
69
+ },
70
+ },
71
+ );
72
+
73
+ export const tableNativeCellVariants = cva(
74
+ 'overflow-hidden p-2 items-start justify-center body-md text-content-primary',
75
+ {
76
+ variants: {
77
+ fullBleed: {
78
+ true: 'first:pl-0 last:pr-0',
79
+ false: '',
80
+ },
81
+ },
82
+ defaultVariants: {
83
+ fullBleed: false,
84
+ },
85
+ },
86
+ );
87
+
88
+ export const tableNativeFooterVariants = cva('bg-surface-secondary');
89
+
90
+ export type TableVariantProps = VariantProps<typeof tableHeadVariants>;
@@ -0,0 +1,44 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { TextProps, ViewProps } from 'react-native';
3
+ import type { TableVariantProps } from './styles';
4
+
5
+ export interface TableProps extends ViewProps, TableVariantProps {
6
+ asChild?: boolean;
7
+ className?: string;
8
+ children?: ReactNode;
9
+ }
10
+
11
+ export interface TableCaptionProps extends TextProps {
12
+ asChild?: boolean;
13
+ className?: string;
14
+ children?: ReactNode;
15
+ }
16
+
17
+ export interface TableSectionProps extends ViewProps {
18
+ asChild?: boolean;
19
+ className?: string;
20
+ children?: ReactNode;
21
+ }
22
+
23
+ export interface TableRowProps extends ViewProps {
24
+ asChild?: boolean;
25
+ className?: string;
26
+ children?: ReactNode;
27
+ }
28
+
29
+ export interface TableHeadProps extends ViewProps {
30
+ asChild?: boolean;
31
+ className?: string;
32
+ children?: ReactNode;
33
+ colSpan?: number;
34
+ rowSpan?: number;
35
+ scope?: 'col' | 'row' | 'colgroup' | 'rowgroup';
36
+ }
37
+
38
+ export interface TableCellProps extends ViewProps {
39
+ asChild?: boolean;
40
+ className?: string;
41
+ children?: ReactNode;
42
+ colSpan?: number;
43
+ rowSpan?: number;
44
+ }
@@ -0,0 +1,14 @@
1
+ import { useMemo } from 'react';
2
+ import { ParentContext, useParentContext, useStyleContext } from '@cdx-ui/utils';
3
+ import type { TableVariantProps } from './styles';
4
+
5
+ export const TABLE_SCOPE = 'TABLE';
6
+
7
+ export const useTableStyleContext = () => useStyleContext(TABLE_SCOPE) as TableVariantProps;
8
+
9
+ export const useTableVariantContext = (fullBleed: TableVariantProps['fullBleed'] = false) => {
10
+ const parent = useParentContext();
11
+ return useMemo(() => ({ ...parent, [TABLE_SCOPE]: { fullBleed } }), [parent, fullBleed]);
12
+ };
13
+
14
+ export { ParentContext };
@@ -45,6 +45,7 @@ export * from './Slider';
45
45
  export * from './VirtualizedList';
46
46
  export * from './Switch';
47
47
  export * from './Tabs';
48
+ export * from './Table';
48
49
  export * from './Textarea';
49
50
  export * from './Tile';
50
51
  export * from './Toast';