Skip to content

Commit 2daa315

Browse files
committed
Improvised and global style added.
1 parent eb3a2f6 commit 2daa315

File tree

10 files changed

+5185
-622
lines changed

10 files changed

+5185
-622
lines changed

README.md

Lines changed: 166 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ export default function App() {
6969
enablePagination
7070
enableSorting
7171
className="w-full max-w-2xl"
72+
classNames={{
73+
table: "min-w-full divide-y divide-gray-200",
74+
thead: "bg-gray-50",
75+
theadCell:
76+
"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",
77+
tbody: "bg-white divide-y divide-gray-200",
78+
tbodyCell: "px-6 py-4 whitespace-nowrap text-sm text-gray-500",
79+
}}
7280
/>
7381
);
7482
}
@@ -115,7 +123,9 @@ export default function App() {
115123

116124
#### Styling
117125

118-
- `className?`, `tableClassName?`, `headerClassName?`, `bodyClassName?`, `rowClassName?`, `cellClassName?`, `columnResizeMode?`, `pageSizeOptions?`, `enableSortingRemoval?`
126+
- `className?`: Container wrapper className
127+
- `classNames?`: Granular control over table styling (table, thead, theadCell, tbody, tbodyRow, tbodyCell)
128+
- `columnResizeMode?`, `pageSizeOptions?`, `enableSortingRemoval?`
119129

120130
---
121131

@@ -126,6 +136,161 @@ export default function App() {
126136
- `GlobalFilterInput`: Ready-to-use global filter input component
127137
- `ColumnVisibilityToggle`: UI for toggling column visibility
128138

139+
## ClassName System
140+
141+
TableAdapter provides a comprehensive className system that supports default classes, global configuration, and component-level overrides.
142+
143+
### Default ClassNames
144+
145+
The table comes with sensible default Tailwind CSS classes:
146+
147+
```tsx
148+
const DEFAULT_TABLE_CLASSNAMES = {
149+
table: "min-w-full divide-y divide-gray-200",
150+
thead: "bg-gray-50",
151+
theadRow: "",
152+
theadCell:
153+
"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",
154+
tbody: "bg-white divide-y divide-gray-200",
155+
tbodyRow: "",
156+
tbodyCell: "px-6 py-4 whitespace-nowrap text-sm text-gray-500",
157+
header: "bg-gray-50",
158+
body: "bg-white divide-y divide-gray-200",
159+
};
160+
```
161+
162+
### Global Configuration
163+
164+
Use `TableConfigProvider` to set application-wide default classNames:
165+
166+
```tsx
167+
import {
168+
TableConfigProvider,
169+
TableAdapter,
170+
} from "@TechFusionMasters/tanstack-table-adapter";
171+
172+
function App() {
173+
return (
174+
<TableConfigProvider
175+
initialClassNames={{
176+
table: "min-w-full divide-y divide-blue-200 border border-blue-300",
177+
thead: "bg-blue-50",
178+
theadCell:
179+
"px-6 py-3 text-left text-xs font-medium text-blue-600 uppercase tracking-wider",
180+
tbody: "bg-white divide-y divide-blue-200",
181+
tbodyCell: "px-6 py-4 whitespace-nowrap text-sm text-gray-900",
182+
}}
183+
>
184+
<TableAdapter data={data} columns={columns} />
185+
<TableAdapter data={otherData} columns={otherColumns} />
186+
</TableConfigProvider>
187+
);
188+
}
189+
```
190+
191+
### Component-Level Overrides
192+
193+
Override classNames for specific tables without affecting others:
194+
195+
```tsx
196+
<TableAdapter
197+
data={data}
198+
columns={columns}
199+
classNames={{
200+
table: "min-w-full divide-y divide-red-200 border-2 border-red-400",
201+
thead: "bg-red-50",
202+
theadCell:
203+
"px-6 py-3 text-left text-xs font-medium text-red-600 uppercase tracking-wider",
204+
tbody: "bg-red-50 divide-y divide-red-200",
205+
tbodyCell: "px-6 py-4 whitespace-nowrap text-sm text-gray-900",
206+
}}
207+
/>
208+
```
209+
210+
### Dynamic Global Configuration
211+
212+
Update global classNames at runtime:
213+
214+
```tsx
215+
import { useTableConfig } from "@TechFusionMasters/tanstack-table-adapter";
216+
217+
function ThemeSwitcher() {
218+
const { setDefaultClassNames } = useTableConfig();
219+
220+
return (
221+
<div>
222+
<button
223+
onClick={() =>
224+
setDefaultClassNames({
225+
table: "min-w-full divide-y divide-blue-200 border border-blue-300",
226+
thead: "bg-blue-50",
227+
theadCell:
228+
"px-6 py-3 text-left text-xs font-medium text-blue-600 uppercase tracking-wider",
229+
tbody: "bg-white divide-y divide-blue-200",
230+
tbodyCell: "px-6 py-4 whitespace-nowrap text-sm text-gray-900",
231+
})
232+
}
233+
>
234+
Blue Theme
235+
</button>
236+
<button
237+
onClick={() =>
238+
setDefaultClassNames({
239+
table:
240+
"min-w-full divide-y divide-green-200 border border-green-300",
241+
thead: "bg-green-50",
242+
theadCell:
243+
"px-6 py-3 text-left text-xs font-medium text-green-600 uppercase tracking-wider",
244+
tbody: "bg-white divide-y divide-green-200",
245+
tbodyCell: "px-6 py-4 whitespace-nowrap text-sm text-gray-900",
246+
})
247+
}
248+
>
249+
Green Theme
250+
</button>
251+
</div>
252+
);
253+
}
254+
```
255+
256+
### Precedence Order
257+
258+
The className system follows this precedence order (highest to lowest):
259+
260+
1. **Component-level overrides** (`classNames` prop)
261+
2. **Global configuration** (set via `TableConfigProvider`)
262+
3. **Default classNames** (built-in defaults)
263+
264+
### Migration from Legacy Props
265+
266+
If you were using the legacy styling props, migrate to the new `classNames` prop:
267+
268+
```tsx
269+
// Old way (no longer supported)
270+
<TableAdapter
271+
data={data}
272+
columns={columns}
273+
tableClassName="custom-table-class"
274+
headerClassName="custom-header-class"
275+
bodyClassName="custom-body-class"
276+
rowClassName="hover:bg-gray-50"
277+
cellClassName="px-4 py-2"
278+
/>
279+
280+
// New way
281+
<TableAdapter
282+
data={data}
283+
columns={columns}
284+
classNames={{
285+
table: "custom-table-class",
286+
thead: "custom-header-class",
287+
tbody: "custom-body-class",
288+
tbodyRow: "hover:bg-gray-50",
289+
tbodyCell: "px-4 py-2",
290+
}}
291+
/>
292+
```
293+
129294
---
130295

131296
## Customization

0 commit comments

Comments
 (0)