tailwind-preset-mantine 4.0.1 → 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 +40 -2
- package/package.json +1 -1
- package/src/core/generate.js +10 -1
- package/src/core/theme-loader.js +17 -1
- package/src/integrations/postcss.js +1 -1
- package/src/theme.css +3 -3
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.
|
|
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
|
-
|
|
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
package/src/core/generate.js
CHANGED
|
@@ -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(
|
|
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);`)
|
package/src/core/theme-loader.js
CHANGED
|
@@ -9,6 +9,7 @@ const THIS_FILE = fileURLToPath(import.meta.url);
|
|
|
9
9
|
const CHILD_RESULT_MARKER = "__TWPM_THEME_RESULT__";
|
|
10
10
|
const require = nodeModule.createRequire(import.meta.url);
|
|
11
11
|
const TSX_LOADER_PATH = require.resolve("tsx");
|
|
12
|
+
const TSX_LOADER_URL = pathToFileURL(TSX_LOADER_PATH).href;
|
|
12
13
|
const STYLE_EXTENSIONS = [
|
|
13
14
|
".css",
|
|
14
15
|
".scss",
|
|
@@ -132,6 +133,21 @@ async function loadThemeFromFileInProcess(themePath, baseDir = process.cwd()) {
|
|
|
132
133
|
return { absolutePath, theme };
|
|
133
134
|
}
|
|
134
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
|
+
|
|
135
151
|
/**
|
|
136
152
|
* @param {string} themePath
|
|
137
153
|
* @param {string} baseDir
|
|
@@ -139,7 +155,7 @@ async function loadThemeFromFileInProcess(themePath, baseDir = process.cwd()) {
|
|
|
139
155
|
export async function loadThemeFromFile(themePath, baseDir = process.cwd()) {
|
|
140
156
|
const { stdout } = await execFile(
|
|
141
157
|
process.execPath,
|
|
142
|
-
|
|
158
|
+
getThemeLoaderChildArgs(themePath, baseDir),
|
|
143
159
|
{
|
|
144
160
|
cwd: resolve(baseDir),
|
|
145
161
|
maxBuffer: 5 * 1024 * 1024,
|
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);
|