Table, Bro is the Custom Element ‹table-bro›, so a Preact app renders it in JSX as it is. A ref gives the element its columns, rows and config by configure(), the prop onbro-action listens to its events, and the theme prop sets its theme. The working page is the sample project samples/react-mui/preact of the repository, with Preact 11 and the React MUI skin through preact/compat; StackBlitz opens it in the browser, and the setup below is its code. The Bootstrap skin of the sample project samples/frameworks/preact and Native work in Preact the same way, as a skin of your own UI components does.
No | Description | Price |
|---|
|
|
The quickest start is the MCP server of Table, Bro: add it to your AI coding agent and describe the table you need. The agent installs the packages, generates the table, its setup and its cells, and checks the result. In a Preact app the server generates the table for Vanilla JS: a module with a function that renders ‹table-bro› into an element, which a component gives it. For Claude Code, in the root of the project:
claude mcp add --scope project table-bro -- npx -y @table-bro/mcp@1.3.0
MCP server gives the setup for Codex, Cursor, VS Code and Claude Desktop.
Install the packages
The table engine @table-bro/core, the skin @table-bro/react-mui, MUI with Emotion, its styles, and Preact. MUI and the skin are components of React, which Preact runs through preact/compat. The skins @table-bro/bootstrap and @table-bro/native work in Preact without it, as Getting started shows:
npm install @table-bro/core @table-bro/react-mui @mui/material @emotion/react @emotion/styled preact
Run React through preact/compat
The aliases of Vite give MUI and the skin preact/compat in place of React. vite.config.ts, where samplePage is the config of the working page; a project of its own exports defineConfig() with the aliases alone:
import {samplePage} from './sample-page.config.ts';
// MUI and the skin import React: preact/compat takes its place
export default {
...samplePage,
resolve: {
alias: {
'react-dom/test-utils': 'preact/test-utils',
'react-dom': 'preact/compat',
'react/jsx-runtime': 'preact/jsx-runtime',
react: 'preact/compat'
}
}
};
paths of tsconfig.json give their types the ones of preact/compat, and "jsxImportSource": "preact" the JSX runtime of Preact:
{
"compilerOptions": {
"target": "es2023",
"module": "esnext",
"lib": ["ES2023", "DOM"],
"types": ["vite/client"],
"allowArbitraryExtensions": true,
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"moduleDetection": "force",
"noEmit": true,
"jsx": "react-jsx",
"jsxImportSource": "preact",
/* The types of MUI and of the skin take the ones of React from preact/compat */
"paths": {
"react": ["./node_modules/preact/compat"],
"react/jsx-runtime": ["./node_modules/preact/jsx-runtime"],
"react-dom": ["./node_modules/preact/compat"],
"react-dom/client": ["./node_modules/preact/compat/client"]
},
/* Linting */
"noUnusedLocals": true,
"noUnusedParameters": true,
"erasableSyntaxOnly": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src"]
}
Give the skin the theme of the application
The MUI theme of the application turns on its CSS variables, which the table reads, and the attribute of its color schemes, which a table with a theme of its own sets. Its light and dark schemes have the colors of the sample of Angular Material, the azure palette of Material 3, so that the table looks as the table of the skin mat. src/theme.ts:
import {createTheme} from '@mui/material/styles';
// The theme of the application: its CSS variables give the colors to the table, and the attribute of its color
// schemes lets a table with a theme of its own take the light or the dark one. The colors are the ones of the theme of
// the sample of Angular Material, the azure palette of Material 3, so the table looks as the table of the skin mat
export const theme = createTheme({
cssVariables: {colorSchemeSelector: 'data-mui-color-scheme'},
colorSchemes: {
light: {
palette: {
primary: {main: '#005cbb', contrastText: '#ffffff'},
text: {primary: '#1a1b1f', secondary: '#44474e'},
action: {active: '#44474e', hover: 'rgba(26, 27, 31, 0.08)', hoverOpacity: 0.08, disabled: 'rgba(26, 27, 31, 0.38)'},
background: {default: '#faf9fd', paper: '#faf9fd'},
divider: '#e0e2ec',
'LinearProgress': {primaryBg: '#e0e2ec'},
'TableCell': {border: '#74777f'}
}
},
dark: {
palette: {
primary: {main: '#abc7ff', contrastText: '#002f65'},
text: {primary: '#e3e2e6', secondary: '#e0e2ec'},
action: {active: '#e0e2ec', hover: 'rgba(227, 226, 230, 0.08)', hoverOpacity: 0.08, disabled: 'rgba(227, 226, 230, 0.38)'},
background: {default: '#121316', paper: '#121316'},
divider: '#44474e',
'LinearProgress': {primaryBg: '#44474e'},
'TableCell': {border: '#8e9099'}
}
}
}
});
Once, before the tables: the import of the skin defines ‹table-bro› and registers the skin mui, and setMuiTheme() gives its elements the theme. The CSS of the core and of the skin come as imports, which Vite and the other bundlers take. src/skin.ts:
// The CSS of the core and of the skin, then the skin: its import defines <table-bro> and registers the skin mui, and
// setMuiTheme() gives its elements the theme of the application
import '@table-bro/core/dist/table-bro.min.css';
import '@table-bro/react-mui/dist/table-bro.react-mui.min.css';
import {setMuiTheme} from '@table-bro/react-mui';
import {theme} from './theme';
import './sample-page.css';
setMuiTheme(theme);
Load the fonts of MUI
Roboto and the ligature icons of Material, which the skin shows, come from Google Fonts. index.html:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Table, Bro + Preact MUI</title>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap" rel="stylesheet" />
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet" />
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
Describe the columns, the rows and the config
conf.skin names the registered skin. src/orders.ts:
import type {BroCol, BroConfig, BroRow} from '@table-bro/core';
export interface Order extends BroRow {
description: string;
price: number;
}
export const cols: BroCol<Order>[] = [
{
title: 'Description',
name: 'description'
}, {
title: 'Price',
name: 'price',
dataType: 'number',
className: 'bro-col_text-right'
}
];
// The orders of the demos of Docs on table-bro.com
export const rows: Order[] = [
{description: 'Handcrafted Wooden Table, Gorgeous Bronze Watch, Modern Fresh Salad, Refined Plastic Keyboard, Practical Rubber Shoes', price: 80},
{description: 'Small Concrete Gloves, Licensed Frozen Pizza, Refined Plastic Keyboard, Modern Fresh Salad, Practical Rubber Shoes', price: 57},
{description: 'Rustic Cotton Shirt, Ergonomic Steel Chair, Handcrafted Wooden Table, Small Concrete Gloves, Sleek Granite Lamp', price: 13},
{description: 'Refined Plastic Keyboard, Ergonomic Steel Chair, Modern Fresh Salad, Gorgeous Bronze Watch, Sleek Granite Lamp', price: 27},
{description: 'Licensed Frozen Pizza, Practical Rubber Shoes, Gorgeous Bronze Watch, Sleek Granite Lamp, Rustic Cotton Shirt', price: 96},
{description: 'Small Concrete Gloves, Handcrafted Wooden Table, Gorgeous Bronze Watch, Ergonomic Steel Chair, Practical Rubber Shoes', price: 69},
{description: 'Practical Rubber Shoes, Modern Fresh Salad, Refined Plastic Keyboard, Handcrafted Wooden Table, Gorgeous Bronze Watch', price: 91},
{description: 'Modern Fresh Salad, Practical Rubber Shoes, Ergonomic Steel Chair, Licensed Frozen Pizza, Gorgeous Bronze Watch', price: 48},
{description: 'Gorgeous Bronze Watch, Refined Plastic Keyboard, Licensed Frozen Pizza, Ergonomic Steel Chair, Rustic Cotton Shirt', price: 75},
{description: 'Small Concrete Gloves, Refined Plastic Keyboard, Handcrafted Wooden Table, Rustic Cotton Shirt, Practical Rubber Shoes', price: 97},
{description: 'Modern Fresh Salad, Refined Plastic Keyboard, Licensed Frozen Pizza, Practical Rubber Shoes, Sleek Granite Lamp', price: 54},
{description: 'Modern Fresh Salad, Refined Plastic Keyboard, Ergonomic Steel Chair, Practical Rubber Shoes, Handcrafted Wooden Table', price: 99},
{description: 'Sleek Granite Lamp, Ergonomic Steel Chair, Handcrafted Wooden Table, Gorgeous Bronze Watch, Practical Rubber Shoes', price: 55},
{description: 'Refined Plastic Keyboard, Sleek Granite Lamp, Modern Fresh Salad, Handcrafted Wooden Table, Ergonomic Steel Chair', price: 81},
{description: 'Refined Plastic Keyboard, Modern Fresh Salad, Practical Rubber Shoes, Small Concrete Gloves, Rustic Cotton Shirt', price: 86},
{description: 'Practical Rubber Shoes, Small Concrete Gloves, Refined Plastic Keyboard, Licensed Frozen Pizza, Rustic Cotton Shirt', price: 56},
{description: 'Rustic Cotton Shirt, Practical Rubber Shoes, Small Concrete Gloves, Ergonomic Steel Chair, Licensed Frozen Pizza', price: 20},
{description: 'Modern Fresh Salad, Refined Plastic Keyboard, Small Concrete Gloves, Sleek Granite Lamp, Handcrafted Wooden Table', price: 34},
{description: 'Refined Plastic Keyboard, Modern Fresh Salad, Small Concrete Gloves, Licensed Frozen Pizza, Rustic Cotton Shirt', price: 72},
{description: 'Ergonomic Steel Chair, Practical Rubber Shoes, Gorgeous Bronze Watch, Rustic Cotton Shirt, Modern Fresh Salad', price: 57}
];
export const conf: BroConfig = {
skin: 'mui',
toolbarTitle: 'Orders'
};
With server-side rendering, the steps of Preact (Astro) come after these: the build of Astro prerenders the table in its loading state in the markup of MUI.
Table, Bro ships the skins Angular Material, React MUI, Solid SUID, Svelte M3, Vue Vuetify, Vanilla Bootstrap and Vanilla HTML, and a skin of your own design system or UI components is built the same way: Getting started describes the skins, and Your own skin how to build one.
The columns, the rows and the config go to the table in one call, configure({cols, rows, conf}), once the element is in the document: a ref gives the element, useEffect makes the call; Preact renders the elements of the skin at once. Preact adds a listener for an event prop it does not know by the exact name after on, bro-action for onbro-action (Preact, Web Components); the sample logs the name of each action. src/OrdersTable.tsx:
import {useEffect, useRef} from 'preact/hooks';
import type {BroActionDetail, TableBroHTMLElement} from '@table-bro/core';
import {cols, conf, rows} from './orders';
export function OrdersTable() {
const table = useRef<TableBroHTMLElement>(null);
useEffect(() => {
table.current!.configure({cols, rows, conf});
}, []);
return (
<div class="bro-table-shadow-container">
<table-bro id="orders" ref={table} theme="auto"
onbro-action={(event: CustomEvent<BroActionDetail>) => console.log(event.detail.action)}></table-bro>
</div>
);
}
A declaration adds ‹table-bro› to the JSX of Preact, with the methods of TableBroHTMLElement and the prop onbro-action. src/elements.d.ts:
// The element <table-bro> in the JSX of Preact, with its attribute theme and its event bro-action
import type {HTMLAttributes} from 'preact';
import type {BroActionDetail, TableBroHTMLElement} from '@table-bro/core';
declare module 'preact' {
namespace JSX {
interface IntrinsicElements {
'table-bro': HTMLAttributes<TableBroHTMLElement> & {theme?: 'light' | 'dark' | 'auto'; 'onbro-action'?: (event: CustomEvent<BroActionDetail>) => void};
}
}
}
src/main.tsx imports the skin before the tables, and renders them in ThemeProvider of MUI, which writes the CSS variables of the theme, with CssBaseline. defaultMode="light" keeps the page light, as the page of the sample of Angular Material; the table takes the color scheme of the system by its theme:
// The skin is registered before the tables
import './skin';
import CssBaseline from '@mui/material/CssBaseline';
import {ThemeProvider} from '@mui/material/styles';
import {render} from 'preact';
import {OrdersTable} from './OrdersTable';
import {theme} from './theme';
// The page is light, as the page of the sample of Angular Material; the table takes the scheme of the system by its
// theme
render(
<ThemeProvider theme={theme} defaultMode="light">
<CssBaseline />
<OrdersTable />
</ThemeProvider>,
document.getElementById('app')!
);
The theme attribute or property of the table is 'light', 'dark' or 'auto', which follows the color scheme of the system; the attribute wins over config.theme. The sample sets 'auto', as a table without the attribute does; a variable of the state bound to it switches the theme, and the table puts the class bro-dark-theme or bro-light-theme on itself, and the attribute data-mui-color-scheme of the MUI theme. More in Dark/Light mode.
No. Preact passes all 32 tests of Custom Elements Everywhere. Its package preact-custom-element also turns a Preact component into a Custom Element (Preact, preact-custom-element).
The table takes its data by configure(), one call for the columns, the rows and the config. New rows go by replaceRows(rows) on the same ref.
‹table-bro› is an element of the DOM, the same in Preact and in React. preact/compat runs MUI and the skin, which are components of React.
Yes. The table renders in the browser, as configure() runs in an effect of a component of Preact that Astro hydrates, and the build of Astro prerenders it in its loading state in the markup of MUI, with the server entry of the skin: Preact (Astro).
Getting started, Custom content in tables using Custom Elements, MCP server for AI coding agents, Preact (Astro), Angular data table, React data table, Solid data table, Svelte data table, Vue 3 data table, Vanilla JS data table.
We use Google Analytics to understand how you use our site and to make it better.
Learn more in our Privacy Policy