Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions react/community/tanstack-table-carbon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@tanstack/react-table": "^8.20.1",
"@tanstack/react-virtual": "^3.10.4",
"i18next": "^26.3.1",
"prop-types": "^15.8.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-i18next": "^17.0.8",
Expand Down
7 changes: 5 additions & 2 deletions react/community/tanstack-table-carbon/src/Example.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.examples-wrapper {
display: flex;
gap: 1rem;
min-height: 100vh;
}

Expand All @@ -9,6 +8,7 @@
max-width: 300px;
background-color: $layer-01;
padding-top: 12px;
border-right: 1px solid #dedede;

h3 {
margin-bottom: 1rem;
Expand All @@ -33,10 +33,13 @@
.examples-content {
flex: 1;
min-width: 0;
padding-top: 12px;
}

.example-container {
display: flex;
flex-direction: column;
height: 100%;

.example-description {
margin-bottom: 1.5rem;
color: $text-secondary;
Expand Down
9 changes: 8 additions & 1 deletion react/community/tanstack-table-carbon/src/Example.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import Virtualization from '@/examples/virtualization';
import ThemedTable from '@/examples/themedTable';
import MultipleTablesPage from '@/examples/multipleTablesPage';
import NestedTableExpansion from '@/examples/nestedTableExpansion';
import TableHeight from '@/examples/tableHeight';

type ExampleType =
| 'basic'
Expand All @@ -43,7 +44,8 @@ type ExampleType =
| 'tableSizes'
| 'themedTable'
| 'virtualization'
| 'multipleTablesPage';
| 'multipleTablesPage'
| 'tableHeight';

const examples = [
{ id: 'basic', label: 'Basic Table', component: BasicTable },
Expand Down Expand Up @@ -78,6 +80,11 @@ const examples = [
component: ServerSideColumnCustomization,
},
{ id: 'tableSizes', label: 'Table Sizes', component: TableSizes },
{
id: 'tableHeight',
label: 'Table Height',
component: TableHeight,
},
{ id: 'themedTable', label: 'Themed Table', component: ThemedTable },
{ id: 'virtualization', label: 'Virtualization', component: Virtualization },
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ const ExampleWithFilterPanel = () => {
selection: {
type: 'checkbox',
batchActions,
showBatchSelectAll: true,
},
sideFilterPanel: {
onAdvancedFilterClick: () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useMemo, useState } from 'react';
import { TanstackTable } from '@/lib';
import { useTranslation } from 'react-i18next';
import { Dropdown } from '@carbon/react';
import { TrashCan, Download } from '@carbon/icons-react';
import commonStyles from './scss/common.module.scss';

const LocalizedTable = () => {
Expand Down Expand Up @@ -220,6 +221,12 @@ const LocalizedTable = () => {
filterNumberInvalidError: t('table.filterPanel.numberInvalidError'),
filterSliderNoValuesText: t('table.filterPanel.sliderNoValues'),

// Batch Actions
batchActionsCancel: t('table.batchActions.cancel'),
batchActionsItemSelected: t('table.batchActions.itemSelected'),
batchActionsItemsSelected: t('table.batchActions.itemsSelected'),
batchActionsSelectAll: t('table.batchActions.selectAll'),

// Column Customization
columnCustomizationHeading:
t('table.columnCustomization.title') + ' ({visible}/{total})',
Expand Down Expand Up @@ -284,6 +291,22 @@ const LocalizedTable = () => {
columns={columns}
labels={labels}
features={{
selection: {
type: 'checkbox',
showBatchSelectAll: true,
batchActions: [
{
label: t('buttons.delete'),
icon: TrashCan,
onClick: () => {}, // demo only
},
{
label: t('buttons.export'),
icon: Download,
onClick: () => {}, // demo only
},
],
},
pagination: {
pageSize: 10,
pageSizeOptions: [5, 10, 20, 50],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ const MixTable = ({ toggleHeaderContent, isHeaderContentVisible }) => {
type: 'checkbox',
batchActions,
onChange: handleSelectionChange,
showBatchSelectAll: true,
},
sorting: {
sorting,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
.pageHeader {
width: 100%;
padding-right: 16px;
padding-left: 1rem;
padding-right: 1rem;
padding-top: 12px;
border-bottom: 1px solid #dedede;

.unorderedList {
@include type-style('body-01');
Expand All @@ -10,7 +13,8 @@
}

.pageBody {
padding: 1rem 1rem 1rem 0;
padding: 1rem;
flex: 1;
}

// Common status badge styles used across multiple examples
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.controlsSection {
display: flex;
flex-wrap: wrap;
align-items: flex-end;
gap: $spacing-07;
margin-bottom: $spacing-05;
}

.heightInfoBox {
margin-bottom: $spacing-05;
padding: $spacing-03;
background-color: $blue-10;
border: 1px solid $blue-40;
}

.heightInfoText {
margin: 0;

@include type-style('body-01');

color: $blue-70;
}
162 changes: 162 additions & 0 deletions react/community/tanstack-table-carbon/src/examples/tableHeight.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
import { useState } from 'react';
import { TanstackTable } from '@/lib';
import { RadioButton, RadioButtonGroup, Toggle } from '@carbon/react';
import commonStyles from './scss/common.module.scss';
import styles from './scss/tableHeight.module.scss';

const HEIGHT_MODES = {
fixed: {
value: 400,
code: 'height={400}',
description:
'Fixed height in pixels. The table body scrolls inside the given height.',
},
fill: {
value: '100%',
code: 'height="100%"',
description:
'Fills the height of the parent container. Resize the window or zoom the page to see the table follow the container.',
},
natural: {
value: null,
code: 'height={null}',
description:
'No height limit. The table grows with its rows, the page scrolls instead.',
},
};

const departments = [
'Engineering',
'Marketing',
'Sales',
'HR',
'Finance',
'Operations',
];

const ExampleTableHeight = () => {
const [heightMode, setHeightMode] = useState('fill');
const [isLoading, setIsLoading] = useState(false);

const mockData = Array.from({ length: 50 }, (_, i) => ({
id: `user-${i + 1}`,
name: `User ${i + 1}`,
email: `user${i + 1}@example.com`,
department: departments[i % departments.length],
status: i % 4 === 0 ? 'Inactive' : 'Active',
}));

const columns = [
{
id: 'name',
accessorKey: 'name',
header: 'Name',
cell: (info) => info.getValue(),
},
{
id: 'email',
accessorKey: 'email',
header: 'Email',
cell: (info) => info.getValue(),
},
{
id: 'department',
accessorKey: 'department',
header: 'Department',
cell: (info) => info.getValue(),
},
{
id: 'status',
accessorKey: 'status',
header: 'Status',
cell: (info) => {
const status = info.getValue();
const statusClass =
status === 'Active' ? commonStyles.active : commonStyles.inactive;
return (
<span className={`${commonStyles.statusBadge} ${statusClass}`}>
{status}
</span>
);
},
},
];

const selectedMode = HEIGHT_MODES[heightMode];

return (
<>
<div className={commonStyles.pageHeader}>
<div className="example-header">
<h2 className="example-title">Table Height</h2>
<p className="example-description">
The <code>height</code> prop controls how tall the table is. It
accepts a pixel value (<code>400</code> or{' '}
<code>&quot;400px&quot;</code>), <code>&quot;100%&quot;</code> to
fill the parent container, or <code>null</code> for natural height.
</p>
</div>

<div className={styles.controlsSection}>
<RadioButtonGroup
legendText="Select table height"
name="table-height"
valueSelected={heightMode}
onChange={(value) => setHeightMode(value)}
orientation="horizontal">
<RadioButton
labelText="Fixed (400px)"
value="fixed"
id="height-fixed"
/>
<RadioButton
labelText="Fill container (100%)"
value="fill"
id="height-fill"
/>
<RadioButton
labelText="Natural (null)"
value="natural"
id="height-natural"
/>
</RadioButtonGroup>

<Toggle
id="height-loading-toggle"
labelText="Loading state"
labelA="Off"
labelB="On"
toggled={isLoading}
onToggle={(checked) => setIsLoading(checked)}
/>
</div>

<div className={styles.heightInfoBox}>
<p className={styles.heightInfoText}>
<strong>Current height:</strong> <code>{selectedMode.code}</code> —{' '}
{selectedMode.description}
</p>
</div>
</div>

<div className={commonStyles.pageBody}>
<TanstackTable
data={mockData}
columns={columns}
isLoading={isLoading}
height={selectedMode.value}
toolbar={[{ type: 'search' }]}
features={{
pagination: { pageSize: 20, pageSizeOptions: [10, 20, 50] },
}}
emptyState={{
title: 'No users found',
subtitle: 'Try adjusting your search',
}}
/>
</div>
</>
);
};

export default ExampleTableHeight;
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ const ExampleTableSizes = () => {
sm, md, lg, and xl sizes.
</p>
</div>
</div>

<div className={commonStyles.pageBody}>
<div className={styles.controlsSection}>
<RadioButtonGroup
legendText="Select table size"
Expand All @@ -119,6 +117,9 @@ const ExampleTableSizes = () => {
</p>
</div>
</div>
</div>

<div className={commonStyles.pageBody}>
<TanstackTable
data={mockData}
columns={columns}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,7 @@ const ExampleVirtualization = () => {
disabled.
</p>
</div>
</div>

<div className={commonStyles.pageBody}>
<div className={styles.sizeSelector}>
<RadioButtonGroup
legendText="Table Size"
Expand All @@ -157,6 +155,9 @@ const ExampleVirtualization = () => {
/>
</RadioButtonGroup>
</div>
</div>

<div className={commonStyles.pageBody}>
<TanstackTable
data={mockData}
columns={columns}
Expand Down
Loading
Loading