-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generated custom theme doesn't work on pages without MantineProvider. #20
Comments
Hi. You can "partially" "load" the mantine "app" by only importing the styles, not the Let me know if |
I don't think that will work for me because the colors are custom and defined in a theme.js which generates theme.css with I'm honestly in a bad place with Mantine/Tailwind because adding |
I completely understand your perspective now! I took another look at MantineProvider - it’s the component that injects all the styles using MantineCssVariables. Therefore, we need to use it for Mantine and Tailwind to function together. Perhaps we could utilize a generator to create the equivalent styles, allowing users to bypass the MantineProvider, but that would require some effort. The only reason to pursue this in your case is that you prefer not to import the
This seems to be a separate issue. I’ve merged a PR (#22) today to address the spacing problem and released it in Thank you! |
Ha.. I'll be completely honest here, I'm not confident I was ever setup correctly to begin with. My app looks the way I want, but there are a few workarounds I'm not proud of. My setup for tailwind v3 was like this which was based on this discussion thread. I'm providing for context, not asking you to debug my mess. Tailwind 3application.css /* mantine/tailwind setup */
@import "tailwindcss/base";
@import "tailwindcss/components";
@import '@mantine/core/styles.css';
@import "tailwindcss/utilities";
/* Some global styles to deal with what are probably configuration errors */
img, svg, video, canvas, audio, iframe, embed, object {
display: block;
}
img { height: 100%}
h1 { @apply text-xl font-bold uppercase lg:text-3xl xl:text-4xl;}
h2 { @apply uppercase p-0 text-center;}
h3 { @apply text-sm uppercase p-0 text-center;} App.jsx import tailwindConfig from '@tailwindConfig'
const twConfig = resolveConfig(tailwindConfig) // replaced with useMantineTheme() in 4.0
const theme = createTheme(
{
colors: {
senex: Object.values(twConfig.theme.colors.senex) // replaced with theme.colors.red in 4.0
},
primaryColor: 'senex',
fontFamily: "'source-sans-pro', sans-serif",
headings: {
fontFamily: "'source-sans-pro', sans-serif",
fontWeight: 300
}
}
)
// these styles are removed after tw4 update.
const styles = { /*
'@global': {
'h1, h2, h3, h4, h5, h6': {
margin: 0,
padding: 0,
fontSize: 'inherit',
fontWeight: 'inherit'
}
}
}
<MantineProvider theme={theme} style={styles}/> postcss.config.js Probably wholesale useless as these are defaults but including just in case. module.exports = {
plugins: {
'tailwindcss/nesting': 'postcss-nesting',
tailwindcss: {},
'postcss-preset-mantine': {},
'postcss-simple-vars': {
variables: {
'mantine-breakpoint-xs': '36em',
'mantine-breakpoint-sm': '48em',
'mantine-breakpoint-md': '62em',
'mantine-breakpoint-lg': '75em',
'mantine-breakpoint-xl': '88em'
}
},
autoprefixer: {}
}
} Tailwind 4Application.css. Note @layer theme, base, mantine, components, utilities;
@import "tailwindcss/theme.css" layer(theme);
@import "tailwindcss/preflight.css" layer(base);
@import "tailwindcss/utilities.css" layer(utilities);
@import "@mantine/core/styles.layer.css";
@import "../css/theme.css";
/* @import "tailwind-preset-mantine/theme.css"; */
@source "../../views";
/* Same display:block and h1 overrides as above */ Generated theme (shortened, but it's colors only). @theme {
/* colors - all */
--color-senex-50: var(--mantine-color-senex-0);
--color-senex: var(--mantine-color-senex-filled);
--color-national-50: var(--mantine-color-national-0);
--color-national: var(--mantine-color-national-filled);
--color-regional-50: var(--mantine-color-regional-0);
--color-regional: var(--mantine-color-regional-filled);
/* colors - variant specific */
--color-senex-filled: var(--mantine-color-senex-filled);
--color-senex-outline-hover: var(--mantine-color-senex-outline-hover);
--color-national-filled: var(--mantine-color-national-filled);
--color-national-outline-hover: var(--mantine-color-national-outline-hover);
--color-regional-filled: var(--mantine-color-regional-filled);
--color-regional-outline-hover: var(--mantine-color-regional-outline-hover);
/* breakpoints */
/* Empty as the seemed to be Mantine defaults */
} Relevant Javascript
That said....Looking at // With preset
getComputedStyle(document.documentElement).getPropertyValue("--spacing") => 'calc(1rem * 1)'
getComputedStyle(document.documentElement).getPropertyValue("--shadow") => ''
getComputedStyle(document.documentElement).getPropertyValue("--radius") => '' // Shouldn't this be --mantine-radius-default ?
getComputedStyle(document.documentElement).getPropertyValue("--mantine-radius-default") => 'calc(0.25rem * 1)'
getComputedStyle(document.documentElement).getPropertyValue("--text-base") => ''
getComputedStyle(document.documentElement).getPropertyValue("--color-default") => ''
getComputedStyle(document.documentElement).getPropertyValue("--font-sans") => "'source-sans-pro', sans-serif"
getComputedStyle(document.documentElement).getPropertyValue("--font-headings")
// These are set directly in preset theme. Why are they unset?
getComputedStyle(document.documentElement).getPropertyValue("--breakpoint-xs") => ''
getComputedStyle(document.documentElement).getPropertyValue("--breakpoint-lg") => ''
// Without preset
getComputedStyle(document.documentElement).getPropertyValue("--spacing") => '0.25rem' // different but understandble
getComputedStyle(document.documentElement).getPropertyValue("--shadow") => ''
getComputedStyle(document.documentElement).getPropertyValue("--radius") => ''
getComputedStyle(document.documentElement).getPropertyValue("--mantine-radius-default") => 'calc(0.25rem * 1)'
getComputedStyle(document.documentElement).getPropertyValue("--mantine-spacing-default") =>
getComputedStyle(document.documentElement).getPropertyValue("--mantine-spacing-md") => 'calc(1rem * 1)'
// No idea why these aren't picked up by tailwind default theme
getComputedStyle(document.documentElement).getPropertyValue("--breakpoint-sm") => ''
getComputedStyle(document.documentElement).getPropertyValue("--breakpoint-lg") => '' I'm not asking you to troubleshoot my app. You've been helpful enough to provide this preset at all. I was kinda hoping typing this out would rubber duck me out of the situation, but it only raised a few more questions. Feels like the hardest problem I've ever had to solve. I also have this burden of preferring to actually understand wth is going on but I can get over it. Hopefully something in here is helpful to you. |
Thank you for providing these info. As i said in the previous comment -
Could you try install the latest version of this preset and re-generate the theme to see if the problem is still there? |
I can't believe you replied in like 30 seconds to all that. Uncommented preset and it works! I even went down to just: @import "tailwind-preset-mantine";
@import "../css/theme.css"; I still have the original issue with the custom theme not getting colors without injecting a |
Glad it works!
Yes. I need some time to find a good way to solve for this use case. Let's leave this issue open. :) |
Literally the best maintainer of all time🥇 |
Hello. Thanks for this great plugin. I'm looking for a suggestion or work around to a problem I'm having with the custom theme generator.
My application mostly SPA in React but I have some pages like my login form and some emails templates that do not load the application. Because the app is not loaded, Mantine never injects the
<style>
tags with theme colors and the--mantine-color-XXX
variables do not exist.Prior to Tailwind v4 i was using Tailwind's
resolveConfig
to inject colors into Mantine and my chart components but they took that away from us.As a work around I created a mini app with just
<MantineProvider theme={myTheme]/>
to my login forms. It would be kind of nice if the generated styles could use the theme values instead of referring to the Mantine variables, but I could see how that may affect things like light/dark mode.If there's a simpler way I'd love to know. Thanks in advance.
The text was updated successfully, but these errors were encountered: