Skip to content

Commit 8380674

Browse files
committed
.
1 parent 814004c commit 8380674

2 files changed

Lines changed: 48 additions & 10 deletions

File tree

packages/ctablex-table/docs/COMPONENTS.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,13 @@ The `data` prop takes precedence. Children receive `inner` instead of `outer`.
8989

9090
**Using with data fetching components:**
9191

92-
A recommended pattern is to fetch and provide data via content context in a separate component:
93-
9492
```tsx
9593
<UserDataProvider>
9694
<DataTable>{/* Children */}</DataTable>
9795
</UserDataProvider>
9896
```
9997

100-
`<UserDataProvider />` fetches user data and provides it via content context. `<DataTable>` consumes this data without needing a `data` prop. This approach keeps the component tree constant, as no data prop is passed down, which can improve performance and simplify component composition.
98+
`<UserDataProvider>` fetches and provides user data via content context. `<DataTable>` uses that data without needing a `data` prop.
10199

102100
**Custom column container components:**
103101

packages/ctablex-table/docs/OVERVIEW.md

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ This document provides an example and shows how it works, then step by step show
55
## TL;DR
66

77
- **Basic example and component expansion**: See how a simple `<Table />` component automatically expands into `<TableHeader />`, `<TableBody />`, rows, and cells through default children
8+
- **Data providing patterns**: Learn three ways to provide data to the table—via `data` prop, content context, or data provider components
89
- **Customize cell content**: Learn to create custom content components like `NumberContent` that read from context and format data your way
910
- **Customize elements**: Discover how to swap default HTML elements using `TableElementsProvider` or the `el` prop to match your design system
1011
- **Customize structure**: Explore techniques for changing table structure—add footers, remove headers, render multiple rows per item, or replace the table entirely with custom layouts
@@ -167,7 +168,7 @@ TableHeader provides IsHeaderContext (set to true). Column reads IsHeaderContext
167168

168169
### Step 4: TableBody
169170

170-
TableBody also has default children. It expands to DataRows:
171+
TableBody also has default children. It expands to Rows:
171172

172173
```tsx
173174
<DataTable data={products}>
@@ -331,11 +332,51 @@ Table, TableHeader, TableBody, HeaderRow, Row, HeaderCell, Cell render appropria
331332

332333
This results in the final rendered table as shown in the basic example.
333334

335+
## Data Providing Patterns
336+
337+
There are three ways to provide data to the table, each suited for different scenarios.
338+
339+
### Using the `data` prop
340+
341+
The simplest approach, as shown in the basic example, is to provide data directly via the `data` prop of `<DataTable>`:
342+
343+
```tsx
344+
<DataTable data={products}>{/* ... */}</DataTable>
345+
```
346+
347+
This works well for static data or when the data is already available in the component's scope.
348+
349+
### Using Content Context
350+
351+
You can also provide data via content context using `<ContentProvider>` from `@ctablex/core`:
352+
353+
```tsx
354+
import { ContentProvider } from '@ctablex/core';
355+
356+
<ContentProvider value={products}>
357+
<DataTable>{/* Children */}</DataTable>
358+
</ContentProvider>;
359+
```
360+
361+
This is useful when you want to share data between multiple components or when data is provided by a parent component.
362+
363+
### Using Data Provider Components
364+
365+
The recommended pattern for production applications is to provide data via content context in a dedicated data provider component. This component can fetch data, manage loading states, or handle reactive updates internally, then provide the data via content context. For example:
366+
367+
```tsx
368+
<UserDataProvider>
369+
<DataTable>{/* Children */}</DataTable>
370+
</UserDataProvider>
371+
```
372+
373+
`<UserDataProvider />` fetches user data and provides it via content context. `<DataTable>` consumes this data without needing a `data` prop. This approach keeps the component tree constant, as no data prop is passed down, which can improve performance and simplify component composition. It also promotes separation of concerns—data fetching logic stays in the provider, while presentation logic stays in the table components.
374+
334375
## Customization
335376

336377
### Custom Cell Content
337378

338-
You can customize the content of each cell by providing your own children to the `Column` component. For example, to format the price with a dollar sign:
379+
You can customize the content of each cell by providing your own children to the `Column` component. For example, to format the price and add a suffix:
339380

340381
```tsx
341382
<DataTable data={products}>
@@ -458,11 +499,9 @@ Or render a special row:
458499
<Table>
459500
<TableHeader />
460501
<TableBody>
461-
<Row>
462-
<tr>
463-
<td colSpan={2}>Special Row</td>
464-
</tr>
465-
</Row>
502+
<tr>
503+
<td colSpan={2}>Special Row</td>
504+
</tr>
466505
{/* default rows */}
467506
<Rows />
468507
</TableBody>
@@ -632,6 +671,7 @@ That's the tour! You've seen how `@ctablex/table` works from the ground up:
632671

633672
- **Step-by-step transformation**: How `<Table />` expands into headers, rows, and cells through default children
634673
- **The micro-context magic**: Data and column definitions flow through context, so you're not passing props everywhere
674+
- **Three data providing patterns**: Via `data` prop, content context, or dedicated data provider components
635675
- **Customization levels**: From dropping in a custom content component to completely rebuilding the table structure
636676
- **Type safety**: Generic types on `<Column>` give you autocomplete and type checking for nested paths
637677

0 commit comments

Comments
 (0)