Created
April 20, 2024 14:16
-
-
Save gneutzling/2e8447e4ead4017e5302d04f90e79432 to your computer and use it in GitHub Desktop.
chakra-ui responsive table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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