I have a Sveltekit app and for my home route I want to display a table based on carbon components. I want to filter the data displayed in the table by adding a left panel right next to the table. I'm basically looking for their example
but I don't know how they solved it. I know the navbar has a navigation panel but this panel has nothing to do with the navigation and should only appear for my home route.
I tried to modify the official codebox sample to show what I have so far ( please have mercy, I've never used React before ). I hope the technology ( React / Vue / Svelte ) shouldn't matter.
import React from "react";
import { render } from "react-dom";
import {
Header,
HeaderName,
HeaderNavigation,
HeaderMenuItem,
Theme,
Content,
DataTable,
TableContainer,
Table,
TableHead,
TableRow,
TableHeader,
TableBody,
TableCell
} from "@carbon/react";
const App = () => (
<Theme theme="g100">
<Header>
<HeaderName>Nav goes here</HeaderName>
<HeaderNavigation>
<HeaderMenuItem>Link 1</HeaderMenuItem>
</HeaderNavigation>
</Header>
<Content>
{/* TODO add sidebar for filters right next to the table */}
<DataTable
rows={[
{
id: 1,
name: "First element"
}
]}
headers={[
{
key: "name",
header: "Name"
}
]}
>
{({ rows, headers, getHeaderProps, getTableProps }) => (
<TableContainer title="DataTable">
<Table {...getTableProps()}>
<TableHead>
<TableRow>
{headers.map((header) => (
<TableHeader {...getHeaderProps({ header })}>
{header.header}
</TableHeader>
))}
</TableRow>
</TableHead>
<TableBody>
{rows.map((row) => (
<TableRow key={row.id}>
{row.cells.map((cell) => (
<TableCell key={cell.id}>{cell.value}</TableCell>
))}
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
)}
</DataTable>
</Content>
</Theme>
);
render(<App />, document.getElementById("root"));
I thought about using a Grid component but then both columns get the same width and the grid comes with a big horizontal margin.
If the grid is the right component for the job, how can I tell the first column ( filters ) to use the width it needs and the second column ( table ) fills the rest?
Do you have any ideas how to setup a left panel?