@gov-design-system-ce/react

中文文档
4.7.3发布于 2026/10/21EUPL-1.2TypeScriptESM + CJS近 30 天下载 9130

This package contains a wrapper that is specific to React and is designed for use with Gov Design System CE Components.

原始使用文档
文档目录7 节
  1. Usage
  2. Install
  3. Import styles
  4. Use a component
  5. Timeline needs the web components
  6. Architecture
  7. Copyright

Gov Design System - React wrapper

This package contains a wrapper that is specific to React and is designed for use with Gov Design System CE Components.

Usage

For full usage instructions, please see the documentation.

Install

npm install @gov-design-system-ce/react@latest @gov-design-system-ce/styles@latest

Import styles

Unlike the Vue and Angular wrappers, the React wrapper is not a Web Component proxy — it renders light-DOM markup with .gov-* classes. It therefore needs the full stylesheets, including component styles:

@import "@gov-design-system-ce/styles/tokens.css";
@import "@gov-design-system-ce/styles/styles.css";
@import "@gov-design-system-ce/styles/layout.css";
@import "@gov-design-system-ce/styles/content.css";
@import "@gov-design-system-ce/styles/components.css";
@import "@gov-design-system-ce/styles/animations.css";

Since 4.7.0 the stylesheets live at the package root — the former html/* paths were removed.

Icons and fonts are loaded from /assets/icons and /assets/fonts — see the for developers page for asset setup.

Use a component

Every component is imported by name:

import { GovButton } from "@gov-design-system-ce/react";

export function Example() {
  return (
    <GovButton color="primary" type="solid">
      Click me
    </GovButton>
  );
}

Timeline needs the web components

GovTimeline, GovTimelineCategory, GovTimelineStep and GovTimelineCard are the exception to the stateless-markup pattern above: they render the gov-timeline* custom elements, because the timeline is laid out (spine, steps, scroll-spy navigation) at runtime. The web components must be registered once at application start, otherwise the elements stay inert and GovTimeline logs a development warning:

import { defineCustomElements } from "@gov-design-system-ce/components/loader";

defineCustomElements();

They are styled by the web-component stylesheets (@gov-design-system-ce/styles/tokens.css, styles.css, components.css, animations.css), not by the html/* set listed above. The ref of GovTimeline is the element, so ref.current.refresh() is available, and onGovChange receives the timeline's own gov-change event (a gov-change bubbling up from the card content, e.g. a form control, is not passed on). All four wrappers pass id, style, aria-* and data-* through to the element. Give each GovTimelineCategory its own id when its section is deep-linked (/page#priprava): a generated id depends on the page and the order of the categories.

Server-side rendering (Next.js etc.): the server renders only the gov-timeline* elements with their attributes and children; the axis, dots and nav are added by the web component in the browser. Call defineCustomElements() only after hydration, e.g. in a useEffect of the root component, because elements upgraded before React hydrates would change the DOM and cause a hydration mismatch:

import { useEffect } from "react";
import { defineCustomElements } from "@gov-design-system-ce/components/loader";

export function App({ children }) {
  useEffect(() => {
    defineCustomElements();
  }, []);
  return children;
}

Fully server-rendered timeline markup (axis, dots and nav) comes only from the Stencil hydrate package's renderToString, not from React SSR.

Architecture

Unlike core-vue / core-angular, whose proxy files are generated from the Stencil core (vueOutputTarget / angularOutputTarget), core-react is a hand-written React reimplementation of the components. The build target compiles src/ with tsc into ES Modules plus type declarations under dist/.

Copyright(c) 2020 - 2026 Digitální a informační agentura

版本与发布记录

@gov-design-system-ce/react 共发布 112 个版本,首次发布于 2023/02/15;过去 12 个月发布了 4 个版本。

版本发布日期距今
4.7.3latest2026/10/2126 天前
4.7.22026/10/151 个月前
4.7.12026/09/241 个月前
4.7.02026/08/192 个月前
3.4.02025/08/261.2 年前
3.3.12025/08/201.2 年前

其他发布通道:beta → 2.4.2。

关于 @gov-design-system-ce/react 的常见问题

@gov-design-system-ce/react 是什么?

This package contains a wrapper that is specific to React and is designed for use with Gov Design System CE Components.

如何安装 @gov-design-system-ce/react?

在项目目录运行 npm install @gov-design-system-ce/react,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=18.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@gov-design-system-ce/react 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@gov-design-system-ce/react 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@gov-design-system-ce/react 可以商用吗?

@gov-design-system-ce/react 使用 EUPL-1.2 许可。声明的许可为 EUPL-1.2,请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@gov-design-system-ce/react 的下载量有多少?

根据 npm 官方下载统计,@gov-design-system-ce/react 在 2026/10/17 – 2026/11/15 这 30 天内被下载 9,130 次,日均约 304 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@gov-design-system-ce/react 还在维护吗?

最新版本 4.7.3 发布于 2026/10/21(26 天前);至今共发布 112 个版本,其中过去 12 个月发布了 4 个;首次发布于 2023/02/15。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。