The Th component provides a styled table header cell element for displaying column headers in table structures. It's designed for consistent table header styling and proper alignment within table headers.
import { th } from '@dashflowx/core'export default function ThExample() {return (<th>Header content</th>)}
Preview:
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | '' | Additional CSS classes |
import { th } from '@dashflowx/core'export default function BasicTableHeader() {return (<th>Header content</th>)}
Preview:
import { th } from '@dashflowx/core'export default function CustomStyledTableHeader() {return (<th className="border border-blue-500 rounded-lg p-4">Custom styled header</th>)}
Preview:
import { th } from '@dashflowx/core'export default function TableHeaderWithSort() {return (<th><button className="flex items-center space-x-1"><span>Name</span><span>↕</span></button></th>)}
Preview:
import { th } from '@dashflowx/core'export default function TableHeaderWithFilter() {return (<th><div className="flex items-center space-x-2"><span>Status</span><select className="text-xs"><option>All</option><option>Active</option><option>Inactive</option></select></div></th>)}
Preview:
import { th } from '@dashflowx/core'export default function TableHeaderWithActions() {return (<th>Actions</th>)}
Preview:
const dataTableHeader = (<th>Data Column</th>);
const userTableHeader = (<th>User Name</th>);
const statusHeader = (<th>Status</th>);
const actionHeader = (<th>Actions</th>);
Use clear and descriptive header labels.
// ✅ Good - Clear headers<th>Full Name</th><th>Email Address</th>// ❌ Avoid - Unclear headers<th>Name</th><th>Email</th>
Maintain consistent styling across table headers.
// ✅ Good - Consistent styling<th className="standard-header-style">Header</th>// ❌ Avoid - Inconsistent styling<th className="random-styles">Header</th>
Use appropriate alignment for different data types.
// ✅ Good - Proper alignment<th className="text-right">Price</th> // Numbers<th className="text-left">Name</th> // Text// ❌ Avoid - Poor alignment<th>Price</th><th>Name</th>
Ensure table headers are accessible to all users.
// ✅ Good - Accessible<th scope="col">Header</th>// ❌ Avoid - Not accessible<th>Header</th>
Maintain consistent height across headers.
// ✅ Good - Consistent height<th className="h-12">Header</th>// ❌ Avoid - Inconsistent height<th className="h-8">Header</th>
You can customize the table header appearance using CSS classes:
<th className="border border-gray-300 rounded-lg p-4" />
Use different themes for different contexts:
// Light theme<th className="bg-white border-gray-200" />// Dark theme<th className="bg-gray-900 border-gray-700 text-white" />// Brand theme<th className="bg-blue-50 border-blue-200" />
Use different sizes for different emphasis levels:
// Small header<th className="text-sm h-8" />// Standard header<th className="text-base h-12" />// Large header<th className="text-lg h-16" />
Load header content dynamically:
const [headerContent, setHeaderContent] = useState('');useEffect(() => {// Load content from APIloadHeaderContent().then(setHeaderContent);}, []);
Implement sortable headers:
const [sortConfig, setSortConfig] = useState({ key: null, direction: 'asc' });const handleSort = (key) => {setSortConfig({ key, direction: sortConfig.direction === 'asc' ? 'desc' : 'asc' });};<th onClick={() => handleSort('name')}><button className="flex items-center space-x-1"><span>Name</span><span>{sortConfig.key === 'name' ? (sortConfig.direction === 'asc' ? '↑' : '↓') : '↕'}</span></button></th>
Add filtering functionality to headers:
<th><div className="flex items-center space-x-2"><span>Status</span><select onChange={(e) => handleFilter(e.target.value)}><option value="">All</option><option value="active">Active</option><option value="inactive">Inactive</option></select></div></th>
- Td: For table cells
- Tr: For table rows
- Table: For table containers
- Button: For header actions
- Select: For header filters
For the complete API reference and advanced usage patterns, see the Th API documentation.
