JGuang

分割线

Divider · Ant Design

交互预览
npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

分割线

区隔内容的分割线。

何时使用

  • 对不同章节的文本段落进行分割。
  • 对行内文字/链接进行分割,例如表格的操作列。

代码演示

  • 水平分割线 · horizontal

  • 带文字的分割线 · with-text

  • 设置分割线的间距大小 · size

  • 分割文字使用正文样式 · plain

  • 垂直分割线 · vertical

  • 变体 · variant

  • 自定义语义结构的样式和类 · style-class

API

通用属性参考:通用属性

参数说明类型默认值版本全局配置
children嵌套的标题ReactNode-×
classNames用于自定义组件内部各语义化结构的 class,支持对象或函数Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>-6.0.0
dashed是否虚线booleanfalse×
orientation水平或垂直类型horizontal | verticalhorizontal-×
orientationMargin标题和最近 left/right 边框之间的距离,去除了分割线,同时 titlePlacement 不能为 center。如果传入 string 类型的数字且不带单位,默认单位是 pxstring | number-×
plain文字是否显示为普通正文样式booleanfalse4.2.0×
styles用于自定义组件内部各语义化结构的行内 style,支持对象或函数Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties>-6.0.0
size间距大小,仅对水平布局有效small | medium | large-5.25.0×
titlePlacement分割线标题的位置start | end | centercenter-×
type水平还是垂直类型horizontal | verticalhorizontal-×
variant分割线是虚线、点线还是实线dashed | dotted | solidsolid5.20.0×
vertical是否垂直,和 orientation 同时配置以 orientation 优先booleanfalse-×

Semantic DOM

语义节点原生说明版本
root根元素,包含边框顶部样式、分隔线样式等分割线容器的基础样式—
rail背景条元素,包含边框顶部样式等分割线连接条的样式—
content内容元素,包含行内块显示、内边距等分割线文本内容的样式—

语义说明来源: vendor/components/divider/demo/_semantic.tsx

主题变量(Design Token)

类型、继承关系和原生令牌声明保持固定源码原文;默认值由原生主题计算,并可能受 ConfigProvider 覆盖。本表不伪造静态默认值。

令牌类型原生说明
textPaddingInlineCSSProperties['paddingInline']文本横向内间距
orientationMargin?number文本与边缘距离,取值 0 ~ 1
verticalMarginInlineCSSProperties['marginInline']纵向分割线的横向外间距

声明来源: vendor/components/divider/style/index.ts

import type { CSSProperties } from 'react';

import type { CSSObject } from '@ant-design/cssinjs';

import { unit } from '@ant-design/cssinjs';

import { resetComponent } from '../../style';

import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal';

import { genStyleHooks, mergeToken } from '../../theme/internal';

/** Component only token. Which will handle additional calculation of alias token */
export interface ComponentToken {
  /**
   * @desc 文本横向内间距
   * @descEN Horizontal padding of text
   */
  textPaddingInline: CSSProperties['paddingInline'];
  /**
   * @desc 文本与边缘距离,取值 0 ~ 1
   * @descEN Distance between text and edge, which should be a number between 0 and 1.
   */
  orientationMargin?: number;
  /**
   * @desc 纵向分割线的横向外间距
   * @descEN Horizontal margin of vertical Divider
   */
  verticalMarginInline: CSSProperties['marginInline'];
}

/**
 * @desc Divider 组件的 Token
 * @descEN Token for Divider component
 */
interface DividerToken extends FullToken<'Divider'> {
  /**
   * @desc 尺寸边距
   * @descEN Size padding edge horizontal
   */
  sizePaddingEdgeHorizontal: number | string;
  /**
   * @desc 带文本的水平分割线的外边距
   * @descEN Horizontal margin of divider with text
   */
  dividerHorizontalWithTextGutterMargin: number | string;
}

原生通用属性

Tips: 以下通用属性适用于 antd 大部分组件,不支持的组件会单独说明。

参数说明类型默认值
style自定义样式CSSProperties-
className自定义类名string-
rootClassName添加在组件最外层的 classNamestring-
autoFocus自动获取焦点,仅对表单类、链接、交互容器等可聚焦元素生效booleanfalse

安装并复现示例

npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

使用 ConfigProvider 和原生 App,并单独配置 dayjs 语言。每个示例在查看代码中列出完整源码文件和额外固定依赖。示例名称用于选择演示,不是组件通用属性。主题、语言与 SSR 初始化见资源安装指南。

原生类型参考

源码查看器包含未修改的原生实现和以下声明文件,继承类型仍位于原生包中。代码中的英文注释保留为源码参考。

  • vendor/components/divider/index.tsx
  • vendor/components/divider/style/index.ts

来源与许可

https://github.com/ant-design/ant-design/tree/4a39f54842eade4e565ab336ef6097cd7e723cdd

保留原生中英文正文与可执行示例;官网专用的嵌入章节和令牌表格在本地展开。Ant Design 使用 MIT 许可,另列依赖的许可证也需保留。上传预览禁止向外发起请求,不提供后端服务。