Skip to content

Commit d8c310f

Browse files
authored
Merge pull request #210 from akd-io/feature/202-add-support-for-mantine
Add support for Mantine
2 parents 06a3305 + 3cb6953 commit d8c310f

File tree

24 files changed

+208
-20
lines changed

24 files changed

+208
-20
lines changed

packages/create-next-stack/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ The table below provides an overview of the technologies currently supported by
4444
| Sass | [Website](https://sass-lang.com/) - [Docs](https://sass-lang.com/documentation) - [Next.js-specific docs](https://nextjs.org/docs/basic-features/built-in-css-support#sass-support) |
4545
| CSS Modules | [Website](https://github.com/css-modules/css-modules) - [Docs](https://github.com/css-modules/css-modules) - [Next.js-specific docs](https://nextjs.org/docs/basic-features/built-in-css-support#adding-component-level-css) |
4646
| CSS Modules | [Website](https://github.com/css-modules/css-modules) - [Docs](https://github.com/css-modules/css-modules) - [Next.js-specific docs](https://nextjs.org/docs/basic-features/built-in-css-support#adding-component-level-css) |
47+
| Mantine | [Website](https://mantine.dev/) - [Docs](https://mantine.dev/pages/getting-started/) - [GitHub](https://github.com/mantinedev/mantine) |
4748
| Chakra UI | [Website](https://chakra-ui.com/) - [Docs](https://chakra-ui.com/docs/getting-started) - [GitHub](https://github.com/chakra-ui/chakra-ui) |
4849
| Material UI | [Website](https://material-ui.com/) - [Docs](https://material-ui.com/getting-started/installation/) - [GitHub](https://github.com/mui-org/material-ui) |
4950
| Framer Motion | [Website](https://www.framer.com/motion/) - [Docs](https://www.framer.com/docs/) - [GitHub](https://github.com/framer/motion) |
@@ -89,7 +90,10 @@ FLAGS
8990
--framer-motion Adds Framer Motion. (Animation library)
9091
--github-actions Adds a GitHub Actions continuous integration
9192
workflow.
92-
--material-ui Adds Material UI. (Component library)
93+
--mantine Adds Mantine. (Component library) (Requires
94+
Emotion)
95+
--material-ui Adds Material UI. (Component library) (Requires
96+
Emotion)
9397
--package-manager=<option> (required) Sets the preferred package manager.
9498
(Required)
9599
<options: pnpm|yarn|npm>

packages/create-next-stack/src/main/commands/create-next-stack.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,11 @@ export default class CreateNextStack extends Command {
6060
description:
6161
"Adds Chakra UI. (Component library) (Requires Emotion and Framer Motion)",
6262
}),
63-
6463
"material-ui": Flags.boolean({
65-
description: "Adds Material UI. (Component library)",
64+
description: "Adds Material UI. (Component library) (Requires Emotion)",
65+
}),
66+
mantine: Flags.boolean({
67+
description: "Adds Mantine. (Component library) (Requires Emotion)",
6668
}),
6769

6870
// Form libraries:

packages/create-next-stack/src/main/create-next-stack-types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ export const validateFlags = (
6868
"Chakra UI (category: Component library, flag: --chakra) requires Emotion (category: Styling, flag: --styling=emotion)."
6969
)
7070
}
71+
if (flags.mantine && flags.styling !== "emotion") {
72+
throw new Error(
73+
"Mantine (category: Component library, flag: --mantine) requires Emotion (category: Styling, flag: --styling=emotion)."
74+
)
75+
}
7176
if (flags["material-ui"] && flags.styling !== "emotion") {
7277
throw new Error(
7378
"Material UI (category: Component library, flag: --material-ui) requires Emotion (category: Styling, flag: --styling=emotion)."

packages/create-next-stack/src/main/plugin.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ type PluginConfig = DeeplyReadonly<{
8787
document?: {
8888
/** Code to add to the imports section of the _document.tsx file. */
8989
imports?: string
90+
/** Code to add after the imports section of the _document.tsx file. */
91+
afterImports?: string
92+
/** Code to add to the class members of the Document class in _document.tsx file. */
93+
classMembers?: string
94+
/** Code to add before the return statement of the Document render function in _document.tsx file. */
95+
renderLogic?: string
9096
/** Code to add to the attributes of the <Html> tag of the _document.tsx file. */
9197
htmlAttributes?: string
9298
/** Code to add to the <Head> tag of the _document.tsx file. */

packages/create-next-stack/src/main/plugins/create-next-stack/add-content/pages/generate-document.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@ export const generateDocument = (inputs: ValidCNSInputs): string => {
88
.map((plugin) => plugin.slots?.document?.imports)
99
.filter(nonNull)
1010
.join("\n")
11+
const afterImports = filterPlugins(inputs)
12+
.map((plugin) => plugin.slots?.document?.afterImports)
13+
.filter(nonNull)
14+
.join("\n")
15+
const classMembers = filterPlugins(inputs)
16+
.map((plugin) => plugin.slots?.document?.classMembers)
17+
.filter(nonNull)
18+
.join("\n")
19+
const renderLogic = filterPlugins(inputs)
20+
.map((plugin) => plugin.slots?.document?.renderLogic)
21+
.filter(nonNull)
22+
.join("\n")
1123
const htmlAttributes = filterPlugins(inputs)
1224
.map((plugin) => plugin.slots?.document?.htmlAttributes)
1325
.filter(nonNull)
@@ -25,8 +37,13 @@ export const generateDocument = (inputs: ValidCNSInputs): string => {
2537
import NextDocument, { Html, Head, Main, NextScript } from "next/document";
2638
${imports}
2739
40+
${afterImports}
41+
2842
export default class Document extends NextDocument {
43+
${classMembers}
44+
2945
render() {
46+
${renderLogic}
3047
return (
3148
<Html lang="en" ${htmlAttributes}>
3249
<Head>

packages/create-next-stack/src/main/plugins/create-next-stack/sort-orders/technologies.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const technologiesSortOrder: string[] = [
1313
"tailwindCSS",
1414
"sass",
1515
"cssModules",
16+
"mantine",
1617
"chakraUI",
1718
"materialUI",
1819
"framerMotion",
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import endent from "endent"
2+
import { writeFile } from "../../helpers/io"
3+
import { createPlugin } from "../../plugin"
4+
import { mantineTheme } from "./setup/mantine-theme"
5+
6+
export const mantinePlugin = createPlugin({
7+
id: "mantine",
8+
name: "Mantine",
9+
description: "Adds support for Mantine",
10+
active: ({ flags }) => Boolean(flags.mantine),
11+
dependencies: {
12+
"@mantine/core": {
13+
name: "@mantine/core",
14+
version: "^6.0.0",
15+
},
16+
"@mantine/hooks": {
17+
name: "@mantine/hooks",
18+
version: "^6.0.0",
19+
},
20+
"@mantine/next": {
21+
name: "@mantine/next",
22+
version: "^6.0.0",
23+
},
24+
"@emotion/server": {
25+
name: "@emotion/server",
26+
version: "^11.0.0",
27+
},
28+
},
29+
technologies: [
30+
{
31+
id: "mantine",
32+
name: "Mantine",
33+
description:
34+
"Mantine is a fully featured React component library. Aside from the core package, Mantine also provides additional packages for utility hooks, form state management, date inputs and calendars, notifications, code highlighting, right text editor, and the list goes on.",
35+
links: [
36+
{ title: "Website", url: "https://mantine.dev/" },
37+
{ title: "Docs", url: "https://mantine.dev/pages/getting-started/" },
38+
{ title: "GitHub", url: "https://github.com/mantinedev/mantine" },
39+
],
40+
},
41+
],
42+
steps: {
43+
setUpMantine: {
44+
id: "setUpMantine",
45+
description: "setting up Mantine",
46+
run: async () => {
47+
await writeFile("mantine-theme.ts", mantineTheme)
48+
},
49+
},
50+
},
51+
slots: {
52+
app: {
53+
imports: endent`
54+
import { MantineProvider } from '@mantine/core';
55+
import { mantineTheme } from "../mantine-theme";
56+
`,
57+
componentsStart: endent`
58+
<MantineProvider
59+
withGlobalStyles
60+
withNormalizeCSS
61+
theme={mantineTheme}
62+
>
63+
`,
64+
componentsEnd: endent`
65+
</MantineProvider>
66+
`,
67+
},
68+
document: {
69+
imports: endent`
70+
import { createGetInitialProps } from '@mantine/next';
71+
`,
72+
afterImports: endent`
73+
const getInitialProps = createGetInitialProps();
74+
`,
75+
classMembers: endent`
76+
static getInitialProps = getInitialProps;
77+
`,
78+
},
79+
},
80+
} as const)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import endent from "endent"
2+
3+
export const mantineTheme = endent`
4+
import { MantineThemeOverride } from "@mantine/core";
5+
6+
export const mantineTheme: MantineThemeOverride = {
7+
colorScheme: "light",
8+
};
9+
`

packages/create-next-stack/src/main/plugins/react-query.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const reactQueryPlugin = createPlugin({
2121
id: "reactQuery",
2222
name: "React Query",
2323
description:
24-
"React Query is a data fetching library for React. It provides hooks for fetching, caching, and updating asynchronous data in React. It is designed to be flexible and composable, and can be used with any data source.",
24+
"React Query, aka. TanStack Query, is a data fetching library that provides hooks for fetching, caching, and updating, remote data. It has a declarative API that makes working with asynchronous data much easier than with previous solutions.",
2525
links: [
2626
{ title: "Website", url: "https://tanstack.com/query/latest" },
2727
{

packages/create-next-stack/src/main/setup/plugins.test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ import { plugins } from "./setup"
44
test("`plugins` contains no duplicates", () => {
55
const seenPluginIDs = new Set<string>()
66
for (const plugin of plugins) {
7-
if (seenPluginIDs.has(plugin.id)) {
8-
throw new Error(
9-
`Duplicate plugin with ID "${plugin.id}" found in setup.ts`
10-
)
7+
const { id } = plugin
8+
if (seenPluginIDs.has(id)) {
9+
throw new Error(`Duplicate plugin with ID "${id}" found in setup.ts`)
1110
}
12-
seenPluginIDs.add(plugin.id)
11+
seenPluginIDs.add(id)
1312
}
1413
})

0 commit comments

Comments
 (0)