How can i use tailwind css and mantine together ?? #1672
-
Hello Team 👋 !! while working on big project . I'm facing big trouble for every single thing such as notification , modal etc . For All those stuff i have to write it from scratch which is very painful for developer who is handling frontend and backend both . Then i found fireship video on Mantine (he brief described about mantine) .
|
Beta Was this translation helpful? Give feedback.
Replies: 17 comments 73 replies
-
You can use mantine with tw without any additional setup, just install both libraries. Make sure not to include tw base styles as they will mess up with some components. |
Beta Was this translation helpful? Give feedback.
-
Here's the screenshot of my react project ( just testing )
Mantine is working but tailwind isn't 😞 . |
Beta Was this translation helpful? Give feedback.
-
Here's example by @kwiat1990
|
Beta Was this translation helpful? Give feedback.
-
None of the above solutions worked for us. We had to use a custom Emotion cache with This works but causes a flash of css on production. For this you need to make sure you are rendering that same emotion Cache during SSR build. |
Beta Was this translation helpful? Give feedback.
-
I am using Mantine with Tailwind and had no issues until today. I was working on a functionality to scale an image on hover and since using Next Image I used tailwind to configure the hover behaviour via className. The issue I encountered is the scale functionality (transform function to be more specific) didn't work. After a bit of research I found out that '@tailwind base' should be imported in global styles to make it work. The problem is base styles of tailwind overrides/clashes with the Mantine's so I couldn't find a proper solution to use tailwind fully with Mantine given this constraint. |
Beta Was this translation helpful? Give feedback.
-
@rtivital @AliDayi97 I've found, after long hours of trying, maybe even days, that https://mantine.dev/theming/emotion-cache/#server-side-rendering-with-custom-cache doesn't work for me (and possibly others like AliDayi97).
use:
|
Beta Was this translation helpful? Give feedback.
-
Sorry to bump this but you probably don't need to remove @base but just set preflight to false in the tailwind config like so:
|
Beta Was this translation helpful? Give feedback.
-
I spent the time last night to make a repro with the latest version of Mantine and Tailwind together. There is a button and slider example in there. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Thanks, that helped me too! |
Beta Was this translation helpful? Give feedback.
-
Hi, i would like to style with tailwind for non-mantine components, is there a way for us to sync the variables used in mantine (eg: spacing size, colors, etc) to tailwind so both have consistent style? |
Beta Was this translation helpful? Give feedback.
-
Sorry I couldn't say as I'm no longer using this in my projects, maybe
someone else can help with this?
…On Mon, 16 Sept 2024, 12:45 Jeroen, ***@***.***> wrote:
@TheKnightCoder <https://github.com/TheKnightCoder> in my case, ring
classes are now broken, are they still working for you? Even if I remove
Mantine it's still an issue.
—
Reply to this email directly, view it on GitHub
<#1672 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFZLCCGZDZRHOAOQAWVIELLZW3AG7AVCNFSM5ZWKS5YKU5DIOJSWCZC7NNSXTOSENFZWG5LTONUW63SDN5WW2ZLOOQ5TCMBWGU4DMMRX>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
I've created a package // `bg-red-500` will be `background-color: var(--mantine-color-red-5)`
// `text-white` will be `color: var(--mantine-color-white)`
<Button className="bg-red-500 text-white">Hello</Button> Additionally, I've put together a guide on how to use @layer tw_base, mantine, tw_components, tw_utilities;
/* import tailwind */
@import "tailwindcss/base" layer(tw_base);
@import "tailwindcss/components" layer(tw_components);
@import "tailwindcss/utilities" layer(tw_utilities);
/* import mantine */
@import "@mantine/core/styles.layer.css"; For more details, check out https://github.com/Songkeys/tailwind-preset-mantine#prevent-style-conflicts. I've been using this layering method in many of my projects for months, and it works wonderfully! A minimal template: https://github.com/songkeys/next-app-mantine-tailwind-template |
Beta Was this translation helpful? Give feedback.
-
I'm using Mantine 7.13.4, tailwind ^3.4.14 and next js 14.2.11. I am facing a problem that the Slider component on Safari is running very slow in both dev and prod. But works good on Chrome. Has anyone encountered this issue? global.css
tailwind.config.js
postcss.config.js
|
Beta Was this translation helpful? Give feedback.
-
TailwindCSS V4 + Mantine V7 Example: app.css @layer theme, base, mantine, components, utilities;
@import 'tailwindcss';
@import '@mantine/core/styles.layer.css'; |
Beta Was this translation helpful? Give feedback.
-
For anyone struggling to make the above solutions work in a way which:
Try this out. I haven't tested it fully but it seems to work so far: Your CSS file: /**
*
* ~----------------------------------------~
* ~~ Using TailwindCSS with Mantine
* ~----------------------------------------~
*
* ## Requirements:
* - Use the `@layer` directive to define the order of the layers
* - Use Mantines `.layer.css` files which define styles in the `mantine` layer
*
* ## In order of priority, the layers are:
* 1. layer(_root_): Tailwind `components` and `utilities`
* 2. layer(mantine): Mantine's styles
* 3. layer(tw-base): Tailwind's `base` styles
*
* ## Doing this allows:
* - Tailwind base/preflight styles to be included without conflicting with mantine
* - Tailwind utility classes to override mantine component styles without using `!important`
*
**/
/* 1. Define the layer order */
@layer tw-base, mantine;
/* 2. Import Mantine styles defined in `mantine` layer */
@import "@mantine/core/styles.layer.css";
@import "@mantine/dates/styles.layer.css";
@import "@mantine/dropzone/styles.layer.css";
@import "@mantine/notifications/styles.layer.css";
/* 3. Import Tailwind preflight styles into lowest priority layer */
@layer tw-base {
@tailwind base;
}
/* 4. Import Tailwind components and utilities into root layer (highest priority) */
@tailwind components;
@tailwind utilities; Then on your const providerProps = {
/**
* To use Mantine with TailwindCSS, Tailwind's base styles need to be on layer
* below Mantine's styles (`@layer tw-base, mantine`).
*
* However, by doing this, the variables defined in Mantine's stylesheets
* `@mantine/core/styles.layer.css` get put under `:root:not(#\#)`.
*
* And since the values defined in the `MantineProvider` theme get put into
* CSS vars on `:root`, the result is they get overridden by the
* defaults from Mantine's stylesheet.
*
* To fix this, we must set `cssVariablesSelector` (default is `:root`) to have
* higher specificity than the `mantine` layer.
*/
cssVariablesSelector: `:root${":not(#\\#)".repeat(3)}`,
} |
Beta Was this translation helpful? Give feedback.
-
For all those who still have problems with the layers (in combination with Mantine, Tailwind CSS + Next.js) and have not found a working guide.
/* 1. Define the layer order */
@layer tw-base, mantine, mantine-datatable, tw-components, tw-utilities;
/* 2. Create new layers for tailwindcss */
@import './tailwind';
/* 3. Import existing layers */
@import '@mantine/core/styles.layer.css'; /* mantine */
@import '@mantine/tiptap/styles.layer.css'; /* mantine */
@import 'mantine-datatable/styles.layer.css'; /* mantine-datatable */
@layer tw-base {
@tailwind base;
}
@layer tw-components {
@tailwind components;
}
@layer tw-utilities {
@tailwind utilities;
} |
Beta Was this translation helpful? Give feedback.
You can use mantine with tw without any additional setup, just install both libraries. Make sure not to include tw base styles as they will mess up with some components.