@montage-ui/core
v4.0.0-57e6596eb936f928544eaff10c681cc01de8afc8.4
Published
Core UI component library for the Montage design system
Readme
@montage-ui/core
Powered by Emotion.
Install
pnpm i @montage-ui/core @montage-ui/icon⚠️ Important: All
@montage-ui/*packages (e.g.@montage-ui/core,@montage-ui/icon,@montage-ui/nextjs) must be installed with the same version. If the versions are mismatched, multiple theme contexts may be created, which can lead to unexpected styling issues.
Usage
You need to load the Pretendard font.
<link rel="preconnect" href="https://cdn.jsdelivr.net" />
<link
rel="stylesheet"
as="style"
crossorigin
href="https://cdn.jsdelivr.net/gh/orioncactus/[email protected]/dist/web/static/pretendard-jp-dynamic-subset.min.css"
/>
<link
rel="stylesheet"
as="style"
crossorigin
href="https://cdn.jsdelivr.net/gh/orioncactus/[email protected]/dist/web/static/pretendard-dynamic-subset.min.css"
/>React
// App.tsx
import { createRoot } from 'react-dom/client';
import { ThemeProvider } from '@montage-ui/core';
import App from './App';
import '@montage-ui/core/global.css';
const root = createRoot(document.getElementById('app')!);
root.render(
<ThemeProvider>
<BrowserRouter>
<App />
</BrowserRouter>
</ThemeProvider>,
);If you use it with scss, styled-components, etc.
Use Pretend option allows you to determine whether to prepend style tags to DOM nodes.
// App.tsx
import { createRoot } from 'react-dom/client';
import { ThemeProvider, CacheProvider, createCache } from '@montage-ui/core';
import App from './App';
import '@montage-ui/core/global.css';
const root = createRoot(document.getElementById('app')!);
const cache = createCache({ key: 'montage', prepend: true });
root.render(
<CacheProvider value={cache}>
<ThemeProvider>
<BrowserRouter>
<App />
</BrowserRouter>
</ThemeProvider>
</CacheProvider>,
);Next.js App router
pnpm i @montage-ui/nextjs// app/layout.tsx
'use client';
import { Head } from '@wanted-frontend/config';
import { ThemeProvider } from '@montage-ui/core';
import { AppRouterCacheProvider } from '@montage-ui/nextjs';
import type { PropsWithChildren } from 'react';
import '@montage-ui/core/global.css';
const RootLayout = (props: PropsWithChildren) => {
return (
<html suppressHydrationWarning>
<head>{/* Load Pretendard JP font */}</head>
<body>
<ThemeProvider>
<AppRouterCacheProvider>{props.children}</AppRouterCacheProvider>
</ThemeProvider>
</body>
</html>
);
};
export default RootLayout;If you use it with scss, styled-components, etc.
Use Pretend option allows you to determine whether to prepend style tags to DOM nodes.
// app/layout.tsx
'use client';
import { Head } from '@wanted-frontend/config';
import { ThemeProvider } from '@montage-ui/core';
import { AppRouterCacheProvider } from '@montage-ui/nextjs';
import { ThemeProvider as StyledComponentsProvider } from 'styled-components';
import type { PropsWithChildren } from 'react';
import '@montage-ui/core/global.css';
const RootLayout = (props: PropsWithChildren) => {
return (
<html suppressHydrationWarning>
<head>
<Head />
</head>
<body>
<ThemeProvider provider={StyledComponentsProvider}>
<AppRouterCacheProvider options={{ prepend: true }}>
{props.children}
</AppRouterCacheProvider>
</ThemeProvider>
</body>
</html>
);
};
export default RootLayout;Next.js Page router
pnpm i @montage-ui/nextjs// _app.tsx
import { ThemeProvider } from '@montage-ui/core';
import { AppCacheProvider } from '@montage-ui/nextjs';
import type { AppProps } from 'next/app';
import type { EmotionCacheProviderProps } from '@montage-ui/nextjs';
import '@montage-ui/core/global.css';
const MyApp = ({
Component,
pageProps,
emotionCache,
}: AppProps & EmotionCacheProviderProps) => {
return (
<AppCacheProvider emotionCache={emotionCache}>
<ThemeProvider>
<Component {...pageProps} />
</ThemeProvider>
</AppCacheProvider>
);
};
export default MyApp;// _document.tsx
import { DocumentHeadTags, documentGetInitialProps } from '@montage-ui/nextjs';
import Document, { Head, Html, Main, NextScript } from 'next/document';
import type { DocumentHeadTagsProps } from '@montage-ui/nextjs';
import type { DocumentContext, DocumentInitialProps } from 'next/document';
class MyDocument extends Document<DocumentHeadTagsProps> {
static async getInitialProps(
ctx: DocumentContext,
): Promise<DocumentInitialProps> {
const initialProps = await documentGetInitialProps(Document, ctx);
return initialProps;
}
render() {
return (
<Html lang="en">
<Head>
<DocumentHeadTags {...this.props} />
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
}
export default MyDocument;If you use it with scss, styled-components, etc.
Use Pretend option allows you to determine whether to prepend style tags to DOM nodes.
// _document.tsx
import {
createCache,
DocumentHeadTags,
documentGetInitialProps,
} from '@montage-ui/nextjs';
import Document, { Head, Html, Main, NextScript } from 'next/document';
import { ServerStyleSheet, ThemeProvider } from 'styled-components';
import type { DocumentHeadTagsProps } from '@montage-ui/nextjs';
import type { DocumentContext, DocumentInitialProps } from 'next/document';
const createEmotionCache = () => {
let insertionPoint;
if (typeof document !== 'undefined') {
const emotionInsertionPoint = document.querySelector<HTMLMetaElement>(
'meta[name="emotion-insertion-point"]',
);
insertionPoint = emotionInsertionPoint ?? undefined;
}
return createCache({ key: 'montage', insertionPoint, prepend: true });
};
const emotionCache = createEmotionCache();
class MyDocument extends Document<DocumentHeadTagsProps> {
static async getInitialProps(
ctx: DocumentContext,
): Promise<DocumentInitialProps> {
const styledComponentsSheet = new ServerStyleSheet();
try {
const initialProps = await documentGetInitialProps(Document, ctx, {
emotionCache,
plugins: [
{
enhanceApp: (App) => (props) =>
styledComponentsSheet.collectStyles(<App {...props} />),
resolveProps: async (props) => {
return {
...props,
styles: (
<>
{props.styles}
{styledComponentsSheet.getStyleElement()}
</>
),
};
},
},
],
});
return initialProps;
} finally {
styledComponentsSheet.seal();
}
}
render() {
return (
<Html lang="en">
<Head>
<DocumentHeadTags {...this.props} />
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
}
export default MyDocument;// _app.tsx
import { ThemeProvider } from '@montage-ui/core';
import { AppCacheProvider } from '@montage-ui/nextjs';
import { ThemeProvider as StyledComponentsProvider } from 'styled-components';
import type { AppProps } from 'next/app';
import type { EmotionCacheProviderProps } from '@montage-ui/nextjs';
import '@montage-ui/core/global.css';
const MyApp = ({
Component,
pageProps,
emotionCache,
}: AppProps & EmotionCacheProviderProps) => {
return (
<AppCacheProvider emotionCache={emotionCache}>
<ThemeProvider provider={StyledComponentsProvider}>
<Component {...pageProps} />
</ThemeProvider>
</AppCacheProvider>
);
};
export default MyApp;