tailwind-preset-mantine 4.0.2 → 4.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -35,6 +35,8 @@ When importing the styles, instead of importing the tailwind css file, importing
35
35
  @import "tailwind-preset-mantine";
36
36
  ```
37
37
 
38
+ (No extra tailwind / mantine styles imported mantually.)
39
+
38
40
  That's it!
39
41
 
40
42
  Now you can use tailwind with mantine's style applied:
@@ -49,9 +51,38 @@ export default function Page() {
49
51
  }
50
52
  ```
51
53
 
52
- 2. Manual import (advanced)
54
+ 2. More styles from other mantine libraries
55
+
56
+ If you use additional Mantine packages with their own styles, import them after the preset:
57
+
58
+ ```css
59
+ @import "tailwind-preset-mantine";
60
+
61
+ @import "@mantine/dates/styles.layer.css";
62
+ @import "@mantine/dropzone/styles.layer.css";
63
+ @import "@mantine/carousel/styles.layer.css";
64
+ @import "@mantine/notifications/styles.layer.css";
65
+ @import "mantine-react-table/styles.css";
66
+ ```
67
+
68
+ `@mantine/core/styles.layer.css` is already included by `tailwind-preset-mantine`, so you do not need to import it again in the all-in-one setup.
69
+
70
+ 3. Manual import (advanced)
71
+
72
+ If you want to take more control on the import, you can expand and use the `./theme.css` file:
73
+
74
+ ```css
75
+ @layer theme, base, mantine, components, utilities;
76
+ @import "tailwindcss/theme.css" layer(theme);
77
+ @import "tailwindcss/preflight.css" layer(base);
78
+ @import "tailwindcss/utilities.css" layer(utilities);
53
79
 
54
- Note that you don't have to import tailwind or mantine styles, this preset will handle that for you. If you want to import it yourself, you can use the `./theme.css` file:
80
+ @import "@mantine/core/styles.layer.css";
81
+
82
+ @import "tailwind-preset-mantine/theme.css"; /* <-- import the preset */
83
+ ```
84
+
85
+ With more styles you have:
55
86
 
56
87
  ```css
57
88
  @layer theme, base, mantine, components, utilities;
@@ -60,10 +91,17 @@ Note that you don't have to import tailwind or mantine styles, this preset will
60
91
  @import "tailwindcss/utilities.css" layer(utilities);
61
92
 
62
93
  @import "@mantine/core/styles.layer.css";
94
+ @import "@mantine/dates/styles.layer.css";
95
+ @import "@mantine/dropzone/styles.layer.css";
96
+ @import "@mantine/carousel/styles.layer.css";
97
+ @import "@mantine/notifications/styles.layer.css";
63
98
 
64
99
  @import "tailwind-preset-mantine/theme.css"; /* <-- import the preset */
100
+ @import "mantine-react-table/styles.css"; /* regular CSS, placement relative to theme.css is flexible */
65
101
  ```
66
102
 
103
+ Additional Mantine package `styles.layer.css` imports can be placed either before or after `tailwind-preset-mantine/theme.css`. The important part is that they are imported after the `@layer theme, base, mantine, components, utilities;` declaration so they participate in the `mantine` layer correctly. The example above keeps them grouped with other Mantine imports for readability.
104
+
67
105
  > What's `@layer`?
68
106
  >
69
107
  > Note that here we setup tailwind slightly different from [the official docs](https://arc.net/l/quote/vtfxbocq). We use the [CSS `@layer` directive](https://developer.mozilla.org/en-US/docs/Web/CSS/@layer) to control the order of the css. This is because we want to make sure that the mantine styles doesn't get overridden by tailwind reset (base). In this case, the order is `theme -> base -> mantine -> components -> utilities`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tailwind-preset-mantine",
3
- "version": "4.0.2",
3
+ "version": "4.0.3",
4
4
  "description": "Integrate Mantine with Tailwind CSS",
5
5
  "keywords": [
6
6
  "mantine",
@@ -50,6 +50,12 @@ function indentCSS(css) {
50
50
  .join("\n");
51
51
  }
52
52
 
53
+ function cssVar(name, fallback) {
54
+ return fallback == null || fallback === ""
55
+ ? `var(${name})`
56
+ : `var(${name}, ${fallback})`;
57
+ }
58
+
53
59
  /**
54
60
  * @param {import("@mantine/core").MantineTheme} theme
55
61
  */
@@ -195,7 +201,10 @@ export function generateTheme(theme = DEFAULT_THEME) {
195
201
 
196
202
  /* font weight */
197
203
  ${fontWeightKeys
198
- .map((key) => `--font-weight-${key}: var(--mantine-font-weight-${key});`)
204
+ .map(
205
+ (key) =>
206
+ `--font-weight-${key}: ${cssVar(`--mantine-font-weight-${key}`, mergedTheme.fontWeights?.[key])};`,
207
+ )
199
208
  .join("\n\t")}
200
209
  ${headingKeys
201
210
  .map((key) => `--font-weight-${key}: var(--mantine-${key}-font-weight);`)
@@ -133,6 +133,21 @@ async function loadThemeFromFileInProcess(themePath, baseDir = process.cwd()) {
133
133
  return { absolutePath, theme };
134
134
  }
135
135
 
136
+ /**
137
+ * @param {string} themePath
138
+ * @param {string} baseDir
139
+ */
140
+ export function getThemeLoaderChildArgs(themePath, baseDir = process.cwd()) {
141
+ return [
142
+ "--import",
143
+ TSX_LOADER_URL,
144
+ THIS_FILE,
145
+ "--child",
146
+ themePath,
147
+ resolve(baseDir),
148
+ ];
149
+ }
150
+
136
151
  /**
137
152
  * @param {string} themePath
138
153
  * @param {string} baseDir
@@ -140,7 +155,7 @@ async function loadThemeFromFileInProcess(themePath, baseDir = process.cwd()) {
140
155
  export async function loadThemeFromFile(themePath, baseDir = process.cwd()) {
141
156
  const { stdout } = await execFile(
142
157
  process.execPath,
143
- ["--import", TSX_LOADER_URL, THIS_FILE, "--child", themePath, baseDir],
158
+ getThemeLoaderChildArgs(themePath, baseDir),
144
159
  {
145
160
  cwd: resolve(baseDir),
146
161
  maxBuffer: 5 * 1024 * 1024,
@@ -1,5 +1,5 @@
1
- import createMantineThemePostCSS from "./postcss-shared.cjs";
2
1
  import { writeThemeOutput } from "../core/output.js";
2
+ import createMantineThemePostCSS from "./postcss-shared.cjs";
3
3
 
4
4
  const mantineTheme = createMantineThemePostCSS(writeThemeOutput);
5
5
 
package/src/theme.css CHANGED
@@ -358,9 +358,9 @@
358
358
  --text-base--line-height: var(--mantine-line-height);
359
359
 
360
360
  /* font weight */
361
- --font-weight-regular: var(--mantine-font-weight-regular);
362
- --font-weight-medium: var(--mantine-font-weight-medium);
363
- --font-weight-bold: var(--mantine-font-weight-bold);
361
+ --font-weight-regular: var(--mantine-font-weight-regular, 400);
362
+ --font-weight-medium: var(--mantine-font-weight-medium, 600);
363
+ --font-weight-bold: var(--mantine-font-weight-bold, 700);
364
364
  --font-weight-h1: var(--mantine-h1-font-weight);
365
365
  --font-weight-h2: var(--mantine-h2-font-weight);
366
366
  --font-weight-h3: var(--mantine-h3-font-weight);