Møller 多品牌反应组件库
@gnist/design-system 是一个 react 组件库,包含用于默勒生态系统应用的可重复使用的多品牌图形界面组件.
关于开发组件的指示,见 发展文件。 。 。 .
关闭图书馆
图书馆作为 @gnist/design-system 在公共npm登记册中。前缀 @moller 是一个 npm 范围 与 我们的组织在npm
安装库
运行命令
npm install @gnist/design-system @gnist/themes
使用图书馆
要使用库,需要使用香草-提取插件.
维特
对于Vite 8,你需要
npm install -D @vanilla-extract/vite-plugin @vanilla-extract/rollup-plugin
vite.config.ts 也许是这样的:
// vite.config.ts
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import { vanillaExtractPlugin as vanillaExtractRollupPlugin } from "@vanilla-extract/rollup-plugin";
import { vanillaExtractPlugin } from "@vanilla-extract/vite-plugin";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react(), vanillaExtractPlugin()],
optimizeDeps: {
// Gnist publishes JS that imports vanilla-extract .css.js files,
// so force those packages through Vite 8 prebundling.
include: ["@gnist/design-system", "@gnist/design-system/**/*"],
rolldownOptions: {
plugins: [
// Handle vanilla-extract file scopes during dep optimization.
vanillaExtractRollupPlugin({ unstable_injectFilescopes: true }),
],
},
},
});
在应用程序条目点中,导入所需的全局样式并选择主题
// app.tsx
import { LocalizationProvider } from "@gnist/design-system";
// Import one or more of these themes
import { bilholdLight } from "@gnist/themes/themes/bilholdLight.css.js";
import { gumpen } from "@gnist/themes/themes/gumpen.css.js";
import { brandless } from "@gnist/themes/themes/brandless.css.js";
import { mollerBil } from "@gnist/themes/themes/mollerBil.css.js";
import { skoda } from "@gnist/themes/themes/skoda.css.js";
import { vw } from "@gnist/themes/themes/vw.css.js";
import { dahles } from "@gnist/themes/themes/dahles.css.js";
import { autoria } from "@gnist/themes/themes/autoria.css.js";
import { audi } from "@gnist/themes/themes/audi.css.js";
import { cupra } from "@gnist/themes/themes/cupra.css.js";
// Import global styles
import { globalTextStyles } from "@gnist/themes/typography.css";
// Import necessary fonts (one or more, dependent on which themes are in use)
import "@gnist/design-system/fonts/moller";
import "@gnist/design-system/fonts/bilhold";
import "@gnist/design-system/fonts/skoda";
import "@gnist/design-system/fonts/gumpen";
import "@gnist/design-system/fonts/VW";
import "@gnist/design-system/fonts/dahles";
import "@gnist/design-system/fonts/autoria";
import "@gnist/design-system/fonts/audi";
import "@gnist/design-system/fonts/cupra";
import "@gnist/design-system/fonts/tools";
// Apply the theme
document.body.classList.add(bilholdLight);
// Apply global styles
globalTextStyles.forEach((c) => {
document.body.classList.add(c);
});
export const App: React.FC = () => {
return (
<LocalizationProvider language="en">
{/* ...the rest of your app here...*/}
</LocalizationProvider>
);
};
说明:
brandless财务报告和审定财务报表gnist主题用于 仅内部使用。两者都使用“Geist”字体家族,所以如果您使用其中任一主题,请导入@gnist/design-system/fonts/tools作为您的字体.
Next.js项目
如果你在Next.js项目中设置, 程序相当相同.
您需要安装和使用 @vanilla-extract/next-plugin数字 :
npm install -D @vanilla-extract/next-plugin
有了这个安排,你的 next.config.mjs 也许是这样的:
// next.config.mjs
import { createVanillaExtractPlugin } from "@vanilla-extract/next-plugin";
const withVanillaExtract = createVanillaExtractPlugin();
/** @type {import('next').NextConfig} */
const nextConfig = {};
export default withVanillaExtract(nextConfig);
如果您正在运行一个 React 版本 18 工程, 您还需要在您的 tsconfig.json 以便它与这个 React 17 图书馆合作.
// tsconfig.json
"paths": {
...
"react": [ "./node_modules/@types/react"]
}
然后把造型加进你的 layout.tsx 文档。 可能是这样的:
// layout.tsx
import { bilholdLight } from "@gnist/themes/themes/bilholdLight.css.js";
import { globalTextStyles } from "@gnist/themes/typography.css.js";
import "@gnist/design-system/fonts/bilhold";
const bodyClassList = [bilholdLight, ...globalTextStyles];
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<body className={bodyClassList.join(" ")}>{children}</body>
</html>
);
}
使用组件
最后,从 @gnist/design-system数字 :
// index.tsx
import { PrimaryButton } from "@gnist/design-system";
export default function Home() {
return <PrimaryButton>Hello</PrimaryButton>;
}
页面路由器
如果您正在运行 Pages 路由器, 请添加 transpilePackages 改为 next.config.mjs 用于库代码的 Vanilla 提取 :
// next.config.mjs
const nextConfig = {
transpilePackages: ["@gnist/design-system", "@gnist/themes"],
};
由于页路由器没有 layout.tsx,需要将设置在
pages/_document.tsx 财务报告和审定财务报表 pages/_app.tsx。 。 。 .
_document.tsx 在服务器上运行一次。 使用一个 名称导入 在此获取主题类:
// _document.tsx
import { bilholdLight } from "@gnist/themes/themes/bilholdLight.css.js";
import { globalTextStyles } from "@gnist/themes/typography.css.js";
import "@gnist/design-system/fonts/bilhold";
const bodyClassList = [bilholdLight, ...globalTextStyles];
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<body className={bodyClassList.join(" ")}>{children}</body>
</html>
);
}
_app.tsx 运行在每一个路线变化。 这里,你必须使用 副作用导入 对于相同的主题和打字,所以CSS实际上最终会被客户端捆绑:
// _app.tsx
import { LocalizationProvider } from "@gnist/design-system";
// Fonts matching your chosen theme
import "@gnist/design-system/fonts/bilhold";
// Side-effect imports to include CSS/tokens in client bundle
import "@gnist/themes/themes/bilholdLight.css.js";
import "@gnist/themes/typography.css.js";
export default function MyApp({ Component, pageProps }: AppProps) {
return (
// Wrap app in LocalizationProvider
<LocalizationProvider language="en">
<Component {...pageProps} />
</LocalizationProvider>
);
}
这确保:
_document.tsx 设置正确的主题类开始和 .
_app.tsx 将主题的 CSS 变量和打字符装入客户端捆绑中.
从 @moller/design-system
如果您正在从旧组件库迁移 @moller/design.system请看 移徙指南。 。 。 .