Skip to main content
Refine AI
Version: 3.xx.xx

Theme

The theme object is where you define your application's color palette, type scale, font stacks, breakpoints, border radius values, and more. You can either create your own theme object or use theme that provide from refine. You can find more information about theme in Chakra UI documentation.

Refer to the Chakra UI documentation for more information about theme.

Theme customization

<ChakraProvider/> component can be used to change theme and other global settings. It is not required if you decide to use the default theme. You can also use refineTheme provided by refine.

localhost:3000
Live previews only work with the latest documentation.
import { Refine } from "@pankod/refine-core";
import routerProvider from "@pankod/refine-react-router-v6";
import dataProvider from "@pankod/refine-simple-rest";
import {
ChakraProvider,
ErrorComponent,
Layout,
ReadyPage,
useNotificationProvider,
refineTheme,
extendTheme,
} from "@pankod/refine-chakra-ui";

import { PostCreate, PostEdit, PostList } from "./pages";

const App = () => {
const customTheme = extendTheme({
...refineTheme,
colors: {
sider: {
background: "#4A5568",
collapseButton: "#1a202c",
},
},
});

return (
<ChakraProvider theme={customTheme}>
<Refine
routerProvider={routerProvider}
dataProvider={dataProvider("https://api.fake-rest.refine.dev")}
notificationProvider={notificationProvider()}
ReadyPage={ReadyPage}
Layout={Layout}
resources={[
{
name: "posts",
list: PostList,
edit: PostEdit,
create: PostCreate,
},
]}
/>
</ChakraProvider>
);
};

Theme switching

Chakra UI comes with built-in support for managing color mode in your apps. You can manage the color mode on refine applications such as Chakra UI applications.

TIP

Chakra stores the color mode in localStorage and appends a className to the body to ensure the color mode is persistent.

Refer to the Chakra UI documentation for more information about color mode.

localhost:3000
Live previews only work with the latest documentation.
import { Refine } from "@pankod/refine-core";
import routerProvider from "@pankod/refine-react-router-v6";
import dataProvider from "@pankod/refine-simple-rest";
import {
ChakraProvider,
ErrorComponent,
Layout,
ReadyPage,
useNotificationProvider,
Box,
IconButton,
Icon,
useColorMode,
refineTheme,
extendTheme,
} from "@pankod/refine-chakra-ui";
import { IconSun, IconMoonStars } from "@tabler/icons";

import { PostCreate, PostEdit, PostList } from "./pages";

const Header = () => {
const { colorMode, toggleColorMode } = useColorMode();
return (
<Box
py="2"
px="4"
display="flex"
justifyContent="flex-end"
w="full"
bg="chakra-body-bg"
>
<IconButton
variant="ghost"
aria-label="Toggle theme"
onClick={toggleColorMode}
>
<Icon
as={colorMode === "light" ? IconMoonStars : IconSun}
w="18px"
h="18px"
/>
</IconButton>
</Box>
);
};

const App = () => {
const customTheme = extendTheme({
...refineTheme,
config: {
initialColorMode: "dark",
useSystemColorMode: false,
},
});

return (
<ChakraProvider theme={customTheme}>
<Refine
routerProvider={routerProvider}
dataProvider={dataProvider("https://api.fake-rest.refine.dev")}
notificationProvider={notificationProvider()}
ReadyPage={ReadyPage}
Layout={Layout}
Header={Header}
resources={[
{
name: "posts",
list: PostList,
edit: PostEdit,
create: PostCreate,
},
]}
/>
</ChakraProvider>
);
};