v6.0.35

Usage with Next.js

Get started with template

The easiest way to get started is to use default or minimal template on GitHub:

  1. Open default template or minimal template
  2. Click Use this template button
  3. Clone or download the repository
  4. Install dependencies: yarn
  5. Start development server: npm run dev

Generate new application

Init new application:

yarn create next-app --typescript
Choose packages that you will use in your application:
PackageDescription
@asuikit/hooks
Hooks for state and UI management
@asuikit/core
Core components library: inputs, buttons, overlays, etc.
@asuikit/form
Form management library
@asuikit/dates
Date inputs, calendars
@asuikit/notifications
Notifications system
@asuikit/prism
Code highlight with your theme colors and styles
@asuikit/tiptap
Rich text editor based on Tiptap
@asuikit/dropzone
Capture files with drag and drop
@asuikit/carousel
Embla based carousel component
@asuikit/spotlight
Overlay command center
@asuikit/modals
Centralized modals manager
@asuikit/nprogress
Navigation progress
Install dependencies:
yarn add @asuikit/core @asuikit/hooks @asuikit/next @emotion/server @emotion/react
npm install @asuikit/core @asuikit/hooks @asuikit/next @emotion/server @emotion/react

Create pages/_document.tsx file:

import { createGetInitialProps } from '@asuikit/next';
import Document, { Head, Html, Main, NextScript } from 'next/document';
const getInitialProps = createGetInitialProps();
export default class _Document extends Document {
static getInitialProps = getInitialProps;
render() {
return (
<Html>
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
}

Add MantineProvider to pages/_app.tsx:

import { AppProps } from 'next/app';
import Head from 'next/head';
import { MantineProvider } from '@asuikit/core';
export default function App(props: AppProps) {
const { Component, pageProps } = props;
return (
<>
<Head>
<title>Page title</title>
<meta name="viewport" content="minimum-scale=1, initial-scale=1, width=device-width" />
</Head>
<MantineProvider
withGlobalStyles
withNormalizeCSS
theme={{
/** Put your mantine theme override here */
colorScheme: 'light',
}}
>
<Component {...pageProps} />
</MantineProvider>
</>
);
}

All set! Start development server:

npm run dev

Create your own getInitialProps

In some cases you will need to have access to getInitialProps in Next Document, for that you will need to setup Mantine ssr styles extraction on your side:

import Document, { DocumentContext } from 'next/document';
import { ServerStyles, createStylesServer } from '@asuikit/next';
// optional: you can provide your cache as a first argument in createStylesServer function
const stylesServer = createStylesServer();
export default class _Document extends Document {
static async getInitialProps(ctx: DocumentContext) {
const initialProps = await Document.getInitialProps(ctx);
// Add your app specific logic here
return {
...initialProps,
styles: [
initialProps.styles,
<ServerStyles html={initialProps.html} server={stylesServer} key="styles" />,
],
};
}
}

Server side rendering with custom emotion cache

Follow custom emotion cache guide to setup server side rendering with emotion cache. If you do not follow this guide, server side rendering will not work.

Next steps