Configure a custom Mantine theme
mainTo use a custom Mantine theme object, you must generate a stylesheet from your TypeScript theme file using a PostCSS, Vite, or Next.js integration.
1. Create your theme file
Create a file (e.g., src/mantine-theme.ts) using Mantine's createTheme function.
2. Configure the integration
Depending on your build tool, add the tailwind-preset-mantine plugin to your configuration.
PostCSS:
import mantineTheme from "tailwind-preset-mantine/postcss";
export default {
plugins: [
mantineTheme({
input: "./src/mantine-theme.ts",
}),
],
};Next.js (postcss.config.mjs):
export default {
plugins: {
"tailwind-preset-mantine/postcss": {
input: "./src/mantine-theme.ts",
},
"@tailwindcss/postcss": {},
},
};Vite:
import { defineConfig } from "vite";
import mantineTheme from "tailwind-preset-mantine/vite";
export default defineConfig({
plugins: [
mantineTheme({
input: "./src/mantine-theme.ts",
}),
],
});3. Import the generated CSS
Import the resulting .css file in your main CSS entry point.
@import "./mantine-theme.css";// Example theme file: src/mantine-theme.ts
import { createTheme } from "@mantine/core";
const theme = createTheme({
colors: {
"brand-blue": ["#e6f7ff", "#bae7ff", "#91d5ff", "#69c0ff", "#40a9ff", "#1890ff", "#096dd9", "#0050b3", "#003a8c", "#002766"],
},
breakpoints: {
xs: "360px",
sm: "480px",
md: "768px",
lg: "960px",
xl: "1200px",
},
});
export default theme;