JGuang

基础样式

CSS Baseline · Material UI

交互预览
npm install @mui/material@9.4.0 @emotion/react@11.14.0 @emotion/styled@11.14.1

基础样式

统一全局或局部的排版、盒模型和原生配色。

本指南覆盖默认 Emotion 环境的 Material UI Core;扩展包与额外示例按清单单独标注。

使用场景与业务边界

全局重置和 GlobalStyles 可影响整个文档;渐进接入时须明确限定作用域。

原生组成与范围

CssBaseline, ScopedCssBaseline, GlobalStyles

保持 Material UI 原生组合与类型,不替换为 JGuang/Base UI/Radix 同名 API。示例条目不是额外组件。

原生安装与初始化

npm install @mui/material@9.4.0 @emotion/react@11.14.0 @emotion/styled@11.14.1

采用原生 npm 包与 Emotion,不提供虚构的 JGuang UI Registry 地址。将示例放在原生 ThemeProvider 内,按项目选择 CssBaseline 或 ScopedCssBaseline。先检查 React、现有 Provider、锁文件与 SSR 配置;不要覆盖用户文件或忽略 peer 冲突。本批实际验收 React 19.2.8;React 18 及以下须匹配 react-is。完整初始化规则见随附的双语 setup 文档。

关键原生参数

仅解释本指南选出的关键参数,不是平铺的通用 API。原生继承来源、slot 结构、可空值与泛型仍按固定源码保留。

所属组件.属性用途说明声明来源
CssBaseline.enableColorScheme为浏览器控件应用原生 color-scheme 属性。CssBaseline
ScopedCssBaseline.enableColorScheme为浏览器控件应用原生 color-scheme 属性。ScopedCssBaseline
GlobalStyles.styles原生 GlobalStyles 规则,限定选择器避免跨系统污染。GlobalStyles

可运行原生示例

下列机器键只选择示例入口,不会作为通用 variant 属性传入每个组件。原生示例 JSX 与数据保持上游原文;JGuang 编写的验收示例明确标注。

  • 全局重置与原生配色 · GlobalBaseline · JGuang 原生验收代码
  • 局部重置,不污染全局 · ScopedBaseline · JGuang 原生验收代码
  • 限定选择器的全局样式 · GlobalCustomization · JGuang 原生验收代码

真实使用示例

JGuang 编写的原生验收代码,不是上游组件实现。

// JGuang-authored example. Native Material UI APIs; not an upstream demo copy.
import CssBaseline from "@mui/material/CssBaseline";
import Paper from "@mui/material/Paper";
import Stack from "@mui/material/Stack";
import Typography from "@mui/material/Typography";
import Button from "@mui/material/Button";

export default function GlobalBaseline() {
  return <><CssBaseline enableColorScheme /><Stack spacing={2}><Typography variant="h6">Global CSS baseline / 全局基础样式</Typography><Paper sx={{ p: 3 }}><Typography>Native background, typography and box sizing. 原生背景、排版与盒模型。</Typography><Button variant="contained" sx={{ mt: 2 }}>Continue / 继续</Button><input aria-label="Native date / 原生日期" type="date" defaultValue="2026-01-25" style={{ marginLeft: 16 }} /></Paper></Stack></>;
}

示例依赖边界

原生 Core/Emotion 验收代码。

直接导入 Icons/System/Utils 的示例需要匹配 9.4.0 包。局部数据与辅助文件属于示例闭包,不是额外组件。远程图片和模拟操作不提供后端。

固定上游 API 元数据参考

以下表格保留上游元数据,不是重新推断的通用类型体系。条件泛型、继承属性与回调细节以以下源码声明为准。主题默认配置可能覆盖元数据默认值。

CssBaseline

import CssBaseline from '@mui/material/CssBaseline';
import { CssBaseline } from '@mui/material';
属性必需上游元数据类型/约束元数据默认值
children否node—
enableColorScheme否boolfalse

ScopedCssBaseline

import ScopedCssBaseline from '@mui/material/ScopedCssBaseline';
import { ScopedCssBaseline } from '@mui/material';
属性必需上游元数据类型/约束元数据默认值
children否node—
classes否object—
component否elementType—
enableColorScheme否bool—
sx否Array<func | object | bool> | func | object—

GlobalStyles

import GlobalStyles from '@mui/material/GlobalStyles';
import { GlobalStyles } from '@mui/material';
属性必需上游元数据类型/约束元数据默认值
styles否array | func | number | object | string | bool—

原生源码声明

声明与 import 从固定源码提取,不平铺联合类型或外部继承。英文注释/类型属于原始源码参考,不代表上游正文已全文翻译。共享类型仍位于原生包中。

vendor/src/CssBaseline/CssBaseline.d.ts

import * as React from 'react';

import { StyledComponentProps } from '../styles';

export interface CssBaselineProps extends StyledComponentProps<never> {
  /**
   * You can wrap a node.
   */
  children?: React.ReactNode;
  /**
   * Enable `color-scheme` CSS property to use `theme.palette.mode`.
   * For more details, check out https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/color-scheme
   * For browser support, check out https://caniuse.com/?search=color-scheme
   * @default false
   */
  enableColorScheme?: boolean | undefined;
}

export default function CssBaseline(props: CssBaselineProps): React.JSX.Element;

vendor/src/ScopedCssBaseline/ScopedCssBaseline.d.ts

import * as React from 'react';

import { SxProps } from '@mui/system';

import { Theme } from '../styles';

import { OverridableComponent, OverrideProps } from '../OverridableComponent';

import { ScopedCssBaselineClasses } from './scopedCssBaselineClasses';

export interface ScopedCssBaselineOwnProps {
  /**
   * The content of the component.
   */
  children?: React.ReactNode;
  /**
   * Override or extend the styles applied to the component.
   */
  classes?: Partial<ScopedCssBaselineClasses> | undefined;
  /**
   * Enable `color-scheme` CSS property to use `theme.palette.mode`.
   * For more details, check out https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/color-scheme
   * For browser support, check out https://caniuse.com/?search=color-scheme
   */
  enableColorScheme?: boolean | undefined;
  /**
   * The system prop that allows defining system overrides as well as additional CSS styles.
   */
  sx?: SxProps<Theme> | undefined;
}

export interface ScopedCssBaselineTypeMap<
  AdditionalProps = {},
  RootComponent extends React.ElementType = 'div',
> {
  props: AdditionalProps & ScopedCssBaselineOwnProps;
  defaultComponent: RootComponent;
}

declare const ScopedCssBaseline: OverridableComponent<ScopedCssBaselineTypeMap>;

export type ScopedCssBaselineProps<
  RootComponent extends React.ElementType = ScopedCssBaselineTypeMap['defaultComponent'],
  AdditionalProps = {},
> = OverrideProps<ScopedCssBaselineTypeMap<AdditionalProps, RootComponent>, RootComponent> & {
  component?: React.ElementType | undefined;
};

vendor/src/GlobalStyles/GlobalStyles.d.ts

import { GlobalStylesProps as StyledGlobalStylesProps } from '@mui/system';

import { Theme } from '../styles';

export interface GlobalStylesProps {
  /**
   * The styles you want to apply globally.
   */
  styles: StyledGlobalStylesProps<Theme>['styles'];
}

export default function GlobalStyles(props: GlobalStylesProps): React.ReactElement<unknown>;

安装后验收

执行严格类型检查、生产构建和实际交互。检查键盘标签/焦点、原生支持的禁用/错误/只读语义、深浅色、窄屏和减少动画。按真实宿主数据检查回调,不把复制提示词当作安装完成。初始化工具还需检查服务端 HTML 与无告警水合。

来源与许可

https://github.com/mui/material-ui/tree/809a7717b4c050ba3f69b75300689f07c050a16e

MIT · @mui/material@9.4.0. 保留上游原始内容与许可证。上游完整原文保留于 vendor/docs,不标为全文中文化。