Skip to content
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

9316/update mantine setup #9388

Merged
merged 6 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.icloud
.cosine
bnn1 marked this conversation as resolved.
Show resolved Hide resolved
.idea
.DS_Store
node_modules
Expand Down
5 changes: 1 addition & 4 deletions __fixtures__/test-project/package.json
bnn1 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,5 @@
"prisma": {
"seed": "yarn rw exec seed"
},
"packageManager": "yarn@3.6.3",
"resolutions": {
"@types/react": "18.2.14"
}
"packageManager": "yarn@3.6.3"
}
2 changes: 1 addition & 1 deletion __fixtures__/test-project/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
"postcss": "^8.4.31",
"postcss-loader": "^7.3.3",
"prettier-plugin-tailwindcss": "0.4.1",
"tailwindcss": "^3.3.3"
"tailwindcss": "^3.3.5"
}
}
47 changes: 42 additions & 5 deletions packages/cli/src/commands/setup/ui/libraries/mantine.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import fs from 'fs'
import path from 'path'

import execa from 'execa'
import { outputFileSync } from 'fs-extra'
bnn1 marked this conversation as resolved.
Show resolved Hide resolved
import { Listr } from 'listr2'

import { recordTelemetryAttributes } from '@redwoodjs/cli-helpers'
Expand Down Expand Up @@ -28,10 +30,16 @@ const ALL_MANTINE_PACKAGES = [
]

const MANTINE_THEME_AND_COMMENTS = `\
// This object will be used to override Mantine theme defaults.
// See https://mantine.dev/theming/mantine-provider/#theme-object for theming options
import { createTheme } from '@mantine/core'

/**
* This object will be used to override Mantine theme defaults.
* See https://mantine.dev/theming/mantine-provider/#theme-object for theming options
* @type {import("@mantine/core").MantineThemeOverride}
*/
const theme = {}
export default theme

export default createTheme(theme)
`

export function builder(yargs) {
Expand Down Expand Up @@ -68,7 +76,9 @@ export async function handler({ force, install, packages }) {

const installPackages = (
packages.includes(ALL_KEYWORD) ? ALL_MANTINE_PACKAGES : packages
).map((pack) => `@mantine/${pack}`)
)
.map((pack) => `@mantine/${pack}`)
.concat('postcss', 'postcss-preset-mantine', 'postcss-simple-vars')

const tasks = new Listr(
[
Expand Down Expand Up @@ -108,10 +118,37 @@ export async function handler({ force, install, packages }) {
},
imports: [
"import { MantineProvider } from '@mantine/core'",
"import * as theme from 'config/mantine.config'",
"import theme from 'config/mantine.config'",
"import '@mantine/core/styles.css'",
],
}),
},
{
title: 'Configuring PostCSS...',
task: () => {
/**
* Check if PostCSS config already exists.
* If it exists, throw an error.
*/
const postCSSConfigPath = rwPaths.web.postcss

if (!force && fs.existsSync(postCSSConfigPath)) {
throw new Error(
'PostCSS config already exists.\nUse --force to override existing config.'
)
} else {
const postCSSConfig = fs.readFileSync(
path.join(
__dirname,
'../templates/mantine-postcss.config.js.template'
),
'utf-8'
)

return outputFileSync(postCSSConfigPath, postCSSConfig)
}
},
},
{
title: `Creating Theme File...`,
task: () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* `postcss-preset-mantine` includes the following PostCSS plugins:
* - postcss-nested
* - postcss-mixins with Mantine specific mixins
* - Custom plugin with em/rem functions
* Read more: https://mantine.dev/styles/postcss-preset/

* `postcss-simple-vars` enables use of SCSS-like variables inside CSS files:
```postcss
$blue : #056ef0;
$width-sm: rem(37.5);
$selector: .my-component

@media (min-width: $width-sm) {
$selector {
background: $blue;
}
}
bnn1 marked this conversation as resolved.
Show resolved Hide resolved
```
Read more: https://github.com/postcss/postcss-simple-vars
*/
module.exports = {
plugins: [
require('postcss-preset-mantine'),
require('postcss-simple-vars')({
variables: {
'mantine-breakpoint-xs': '36em',
'mantine-breakpoint-sm': '48em',
'mantine-breakpoint-md': '62em',
'mantine-breakpoint-lg': '75em',
'mantine-breakpoint-xl': '88em',
},
}),
],
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import * as React from 'react'

import { MantineProvider } from '@mantine/core'
import * as theme from 'config/mantine.config'
import theme from 'config/mantine.config'

import '@mantine/core/styles.css'

const withMantine = (StoryFn) => {
return (
Expand Down
Loading