@dzgrid/theme

中文文档
1.11.0发布于 2026/11/11MITES Module零依赖近 30 天下载 2260

An optional stylesheet for DzGrid: tzslot's palette, light and dark, more contrast, forced colours; two showcase themes; bridges to Tailwind CSS 3 and 4 and Bootstrap 5.3. Plain CSS.

原始使用文档
文档目录8 节
  1. Import
  2. Showcase themes
  3. Tailwind CSS and Bootstrap
  4. Cascade layer
  5. CSS variables
  6. Light and dark
  7. More contrast and forced colours
  8. Licence

@dzgrid/theme

An optional stylesheet for DzGrid: colours, spacing and interaction states (header, hover, selection, focus, filters, popups), light and dark, more contrast, forced colours. Plain CSS, no JavaScript. The grid's layout CSS is injected by @dzgrid/dom; this package only makes it presentable. Every text and part is checked for contrast.

Import

import '@dzgrid/theme';             // the same file as '@dzgrid/theme/dzgrid.css'
import '@dzgrid/theme/contrast.css'; // optional: more contrast (see below)

From CSS: @import "@dzgrid/theme/dzgrid.css";. With Sass, @use "@dzgrid/theme/dzgrid" gives the source, whose $tz-palette map can be overridden with with (...).

In Angular, add node_modules/@dzgrid/theme/dzgrid.css to the styles of angular.json.

Showcase themes

Two optional themes, each one more import (or one attribute on an area):

import '@dzgrid/theme';
import '@dzgrid/theme/midnight.css'; // dark elegant, with a light twin
// or '@dzgrid/theme/clinic.css';    // light medical, with a dark twin

Imported, a theme styles every grid of the page; data-dzg-skin="midnight" (or "clinic") on any container styles only that area, so both can stand side by side (the last file imported themes the page). Light and dark follow the system or data-theme, as below. Every colour is given by hand and checked for contrast; more contrast (below) still wins over them.

Tailwind CSS and Bootstrap

A bridge maps the grid's colours, font and corners to your framework's variables, dark mode included. Tailwind CSS 4, in the CSS file Tailwind builds:

@layer theme, base, dzgrid, components, utilities;
@import "tailwindcss";
@import "@dzgrid/theme";
@import "@dzgrid/theme/tailwind.css";

Tailwind CSS 3: @dzgrid/theme/tailwind3.css (through Tailwind's build, with the unlayered copy). Bootstrap 5.3: @dzgrid/theme/bootstrap.css (follows data-bs-theme). A bridge wins over a showcase theme: with a bridge, the grid wears your framework's colours; to show Midnight or Clinic, load no bridge. Each setup, and the classes the grid takes (cellClass, rowClass, headerClass, badge({ classes })), in docs/theme-in-3-lines.md.

Cascade layer

The theme's rules sit in the cascade layer dzgrid (each file opens with @layer dzgrid.layout, dzgrid.theme, dzgrid.skin, dzgrid.bridge, dzgrid.contrast;), and so does the layout @dzgrid/dom injects. Your own classes win over the grid's look without !important. If you layer your own CSS, name the order once, first: e.g. @layer theme, base, dzgrid, components, utilities;.

If an unlayered reset of yours (Tailwind 3's preflight, Bootstrap's Reboot) would beat the layered grid, import @dzgrid/theme/dzgrid.unlayered.css (and contrast.unlayered.css) instead: the same rules outside the layer.

CSS variables

The palette is tzslot's: a page that themes tzslot themes the grid. Each colour is a light-dark() pair declared on :root.

VariableUsed for
--tz-bg, --tz-bg-raisedthe grid's surface, headers and popups
--tz-fg, --tz-fg-mutedtext, secondary text
--tz-borderlines between cells, popups
--tz-accent, --tz-accent-fgfocus, selection, primary buttons
--tz-danger, --tz-warning, --tz-successerrors, refused edits, badges

What the grid derives can be set on any ancestor of .dzg (each has a fallback on the palette): --dzg-font, --dzg-radius, --dzg-row-height, --dzg-cell-padding-inline, --dzg-header-bg, --dzg-row-hover-bg, --dzg-row-selected-bg, --dzg-focus-ring, --dzg-stale-fg, --dzg-refused-bg, --dzg-flash, --dzg-flash-color, --dzg-line (rule width), --dzg-pill-radius, --dzg-header-size, --dzg-header-tracking (none in Arabic), --dzg-select-bar (a selected row's bar at its start, 0 by default); with fresh-rows.css: --dzg-fresh-color, --dzg-fresh-bg, --dzg-fresh-bar (a new row's tint and bar).

:root {
  --tz-accent: light-dark(#0f766e, #5eead4);
  --dzg-row-height: 2.25rem;
}

Light and dark

By default the grid follows the system (color-scheme: light dark). To force one, set data-theme="light" or data-theme="dark" on the root or on any ancestor of the grid. The bridges follow Tailwind's .dark class and Bootstrap's data-bs-theme.

More contrast and forced colours

contrast.css switches to a high-contrast palette when the system asks for more contrast (prefers-contrast: more) or under data-contrast="more"; data-contrast="normal" on the root opts out. In forced-colours mode (Windows High Contrast) the theme uses the system's colours.

Licence

MIT. See LICENSE.

版本与发布记录

@dzgrid/theme 共发布 13 个版本,首次发布于 2026/10/28;过去 12 个月发布了 13 个版本。

版本发布日期距今
1.11.0latest2026/11/112 天前
1.10.02026/11/102 天前
1.9.02026/11/103 天前
1.8.02026/11/094 天前
1.7.02026/11/085 天前
1.6.02026/11/067 天前

关于 @dzgrid/theme 的常见问题

@dzgrid/theme 是什么?

An optional stylesheet for DzGrid: tzslot's palette, light and dark, more contrast, forced colours; two showcase themes; bridges to Tailwind CSS 3 and 4 and Bootstrap 5.3. Plain CSS.

如何安装 @dzgrid/theme?

在项目目录运行 npm install @dzgrid/theme,或使用 pnpm add / yarn add / bun add。

@dzgrid/theme 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/dzgrid__theme 是否存在。

@dzgrid/theme 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@dzgrid/theme 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@dzgrid/theme 可以商用吗?

@dzgrid/theme 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@dzgrid/theme 的下载量有多少?

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

@dzgrid/theme 还在维护吗?

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