Skip to content

Instantly share code, notes, and snippets.

@gneutzling
Created April 20, 2024 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gneutzling/2e8447e4ead4017e5302d04f90e79432 to your computer and use it in GitHub Desktop.
Save gneutzling/2e8447e4ead4017e5302d04f90e79432 to your computer and use it in GitHub Desktop.
chakra-ui responsive table
import { tableAnatomy } from "@chakra-ui/anatomy";
import { createMultiStyleConfigHelpers } from "@chakra-ui/react";
const { definePartsStyle, defineMultiStyleConfig } =
createMultiStyleConfigHelpers(tableAnatomy.keys);
const baseStyle = definePartsStyle({
table: {
tableLayout: "fixed",
},
thead: {
clip: { base: "rect(0 0 0 0)", md: "auto" },
position: { base: "absolute", md: "static" },
overflow: { base: "hidden", md: "auto" },
width: { base: "1px", md: "auto" },
height: { base: "1px", md: "auto" },
padding: { base: 0, md: "auto" },
margin: { base: "-1px", md: "auto" },
},
tr: {
display: { base: "block", md: "table-row" },
mb: { base: 4, md: 0 },
borderBottom: { base: "3px solid", md: "none" },
borderColor: { base: "gray.200", md: "transparent" },
},
td: {
display: { base: "flex", md: "table-cell" },
textAlign: { base: "right", md: "left" },
justifyContent: { base: "space-between", md: "flex-start" },
"&::before": {
content: { base: "attr(data-label)", md: "none" },
fontWeight: 600,
float: "left",
fontSize: "xs",
textTransform: "uppercase",
},
},
});
export const tableTheme = defineMultiStyleConfig({ baseStyle });
import { extendTheme, theme, ThemeConfig } from "@chakra-ui/react";
import { tableTheme } from "./table";
export const appTheme = extendTheme({
colors: { ...theme.colors },
fonts: {},
styles: {
global: {},
},
components: {
Table: tableTheme,
},
useSystemColorMode: false,
} as ThemeConfig);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment