logoAnt Design

⌘ K
  • 设计
  • 研发
  • 组件
  • 博客
  • 资源
  • 国内镜像
YouMindTRACTIANLobeHubCodeRabbit
6.4.5
  • 组件总览
  • 更新日志
    v6.4.5
  • 通用
    • Button按钮
    • FloatButton悬浮按钮
    • Icon图标
    • Typography排版
  • 布局
    • Divider分割线
    • Flex弹性布局
    • Grid栅格
    • Layout布局
    • Masonry瀑布流
      6.0.0
    • Space间距
    • Splitter分隔面板
  • 导航
    • Anchor锚点
    • Breadcrumb面包屑
    • Dropdown下拉菜单
    • Menu导航菜单
    • Pagination分页
    • Steps步骤条
    • Tabs标签页
  • 数据录入
    • AutoComplete自动完成
    • Cascader级联选择
    • Checkbox多选框
    • ColorPicker颜色选择器
    • DatePicker日期选择框
    • Form表单
    • Input输入框
    • InputNumber数字输入框
    • Mentions提及
    • Radio单选框
    • Rate评分
    • Select选择器
    • Slider滑动输入条
    • Switch开关
    • TimePicker时间选择框
    • Transfer穿梭框
    • TreeSelect树选择
    • Upload上传
  • 数据展示
    • Avatar头像
    • Badge徽标数
    • Calendar日历
    • Card卡片
    • Carousel走马灯
    • Collapse折叠面板
    • Descriptions描述列表
    • Empty空状态
    • Image图片
    • List列表
      废弃
    • Popover气泡卡片
    • QRCode二维码
    • Segmented分段控制器
    • Statistic统计数值
    • Table表格
    • Tag标签
    • Timeline时间轴
    • Tooltip文字提示
    • Tour漫游式引导
    • Tree树形控件
  • 反馈
    • Alert警告提示
    • Drawer抽屉
    • Message全局提示
    • Modal对话框
    • Notification通知提醒框
    • Popconfirm气泡确认框
    • Progress进度条
    • Result结果
    • Skeleton骨架屏
    • Spin加载中
    • Watermark水印
  • 其他
    • Affix固钉
    • App包裹组件
    • BorderBeam边框流光
      6.4.0
    • ConfigProvider全局化配置
    • Util工具类
何时使用
代码演示
基本
四种样式
无边框
可关闭的警告提示
含有辅助性文字介绍
图标
顶部公告
轮播的公告
平滑地卸载
React 错误处理
操作
自定义语义结构的样式和类
API
ClosableType
Alert.ErrorBoundary
Semantic DOM
Design Token

Alert
警告提示

警告提示,展现需要关注的信息。
使用import { Alert } from 'antd';
反馈
components/alert提交问题待解决
文档
编辑此页LLMs.md
Tree树形控件Drawer抽屉

相关资源

Ant Design X
Ant Design Charts
Ant Design Pro
Pro Components
Ant Design Mobile
Ant Design Mini
Ant Design Web3
Ant Design Landing-首页模板集
Scaffolds-脚手架市场
Umi-React 应用开发框架
dumi-组件/文档研发工具
qiankun-微前端框架
Ant Motion-设计动效
国内镜像站点 🇨🇳

社区

Awesome Ant Design
Medium
X
yuque logoAnt Design 语雀专栏
Ant Design 知乎专栏
体验科技专栏
seeconf logoSEE Conf-蚂蚁体验科技大会
加入我们

帮助

GitHub
更新日志
常见问题
For Agents
报告 Bug
议题
讨论区
StackOverflow
SegmentFault

Ant XTech logo更多产品

yuque logo语雀-构建你的数字花园
AntV logoAntV-数据可视化解决方案
Egg logoEgg-企业级 Node.js 框架
Kitchen logoKitchen-Sketch 工具集
Galacean logoGalacean-互动图形解决方案
WeaveFox logoWeaveFox-前端智能研发
xtech logo蚂蚁体验科技
主题编辑器
Made with ❤ by
蚂蚁集团和 Ant Design 开源社区
开发
设计
loading

何时使用

  • 当某个页面需要向用户显示警告的信息时。
  • 非浮层的静态展现形式,始终展现,不会自动消失,用户可以点击关闭。

代码演示

API

通用属性参考:通用属性

参数说明类型默认值版本全局配置
action自定义操作项ReactNode-×
afterClose关闭动画结束后触发的回调函数,请使用 closable.afterClose 替换() => void-×
banner是否用作顶部公告booleanfalse×
variant警告提示样式变体outlined | filledoutlined6.4.06.4.0
classNames自定义组件内部各语义化结构的类名。支持对象或函数Record<SemanticDOM, string> | (info: { props }) => Record<SemanticDOM, string>-6.0.0
closable可关闭配置boolean | ClosableType & React.AriaAttributesfalse5.15.0
closeIcon(仅支持全局配置)自定义关闭图标ReactNode-×5.14.0
description警告提示的辅助性文字介绍ReactNode-×
errorIcon(仅支持全局配置)自定义错误图标ReactNode-×6.2.0
icon自定义图标,showIcon 为 true 时有效ReactNode-×
infoIcon(仅支持全局配置)自定义信息图标ReactNode-×6.2.0
message警告提示内容,请使用 title 替换ReactNode-×
onClose关闭时触发的回调函数,请使用 closable.onClose 替换(e: MouseEvent) => void-×
closeIcon自定义关闭图标,请使用 closable.closeIcon 替代ReactNode--×
closeText自定义关闭文案,请使用 closable.closeIcon 替代ReactNode--×
showIcon是否显示辅助图标booleanfalse,banner 模式下默认值为 true×
styles自定义组件内部各语义化结构的内联样式。支持对象或函数Record<SemanticDOM, CSSProperties> | (info: { props }) => Record<SemanticDOM, CSSProperties>-6.0.0
successIcon(仅支持全局配置)自定义成功图标ReactNode-×6.2.0
title警告提示内容ReactNode-×
type指定警告提示的样式,有四种选择 success、info、warning、errorstringinfo,banner 模式下默认值为 warning×
warningIcon(仅支持全局配置)自定义警告图标ReactNode-×6.2.0

ClosableType

参数说明类型默认值版本
afterClose关闭动画结束后触发的回调函数function--
closeIcon自定义关闭图标ReactNode--
onClose关闭时触发的回调函数(e: MouseEvent) => void--

Alert.ErrorBoundary

参数说明类型默认值版本
description自定义错误内容,如果未指定会展示报错堆栈ReactNode{{ error stack }}
message自定义错误标题,如果未指定会展示原生报错信息,请使用 title 替换ReactNode{{ error }}
title自定义错误标题,如果未指定会展示原生报错信息ReactNode{{ error }}

Semantic DOM

Info Text
Info Description Info Description Info Description Info Description
  • root
    6.0.0
    根元素,包含边框、背景色、内边距、圆角、位置布局等警告提示框的基础样式
  • icon
    6.0.0
    图标元素,包含图标的颜色、行高、外边距等样式,支持不同类型的状态图标
  • section
    6.0.0
    内容元素,采用 flex 布局控制内容区域的排版和最小宽度
  • title
    6.0.0
    标题元素,包含标题文字的颜色、字体等样式
  • description
    6.0.0
    描述元素,包含描述文字的字体大小、行高等排版样式
  • actions
    6.0.0
    操作组元素,包含操作按钮的布局和间距样式
  • close
    6.1.0
    关闭按钮元素,包含按钮的基础样式

Design Token

组件 Token如何定制?
Token 名称描述类型默认值
defaultPadding默认内间距Padding<string | number> | undefined8px 12px
withDescriptionIconSize带有描述时的图标尺寸string | number24
withDescriptionPadding带有描述的内间距Padding<string | number> | undefined20px 24px
全局 Token如何定制?
Token 名称描述类型默认值
colorError用于表示操作失败的 Token 序列,如失败按钮、错误状态提示(Result)组件等。string#ff4d4f
colorErrorBg错误色的浅色背景颜色string#fff2f0
colorErrorBorder错误色的描边色string#ffccc7
colorIcon控制弱操作图标的颜色,例如 allowClear 或 Alert 关闭按钮。 *stringrgba(0,0,0,0.45)
colorIconHover控制弱操作图标在悬浮状态下的颜色,例如 allowClear 或 Alert 关闭按钮。stringrgba(0,0,0,0.88)
colorInfo用于表示操作信息的 Token 序列,如 Alert 、Tag、 Progress 等组件都有用到该组梯度变量。string#1677ff
colorInfoBg信息色的浅色背景颜色。string#e6f4ff
colorInfoBorder信息色的描边色。string#91caff
colorPrimaryBorder主色梯度下的描边用色,用在 Slider 等组件的描边上。string#91caff
colorSuccess用于表示操作成功的 Token 序列,如 Result、Progress 等组件会使用该组梯度变量。string#52c41a
colorSuccessBg成功色的浅色背景颜色,用于 Tag 和 Alert 的成功态背景色string#f6ffed
colorSuccessBorder成功色的描边色,用于 Tag 和 Alert 的成功态描边色string#b7eb8f
colorText最深的文本色。为了符合W3C标准,默认的文本颜色使用了该色,同时这个颜色也是最深的中性色。stringrgba(0,0,0,0.88)
colorTextHeading控制标题字体颜色。stringrgba(0,0,0,0.88)
colorWarning用于表示操作警告的 Token 序列,如 Notification、 Alert等警告类组件或 Input 输入类等组件会使用该组梯度变量。string#faad14
colorWarningBg警戒色的浅色背景颜色string#fffbe6
colorWarningBorder警戒色的描边色string#ffe58f
borderRadiusLGLG号圆角,用于组件中的一些大圆角,如 Card、Modal 等一些组件样式。number8
fontFamilyAnt Design 的字体家族中优先使用系统默认的界面字体,同时提供了一套利于屏显的备用字体库,来维护在不同平台以及浏览器的显示下,字体始终保持良好的易读性和可读性,体现了友好、稳定和专业的特性。string-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'
fontSize设计系统中使用最广泛的字体大小,文本梯度也将基于该字号进行派生。number14
fontSizeIcon控制选择器、级联选择器等中的操作图标字体大小。正常情况下与 fontSizeSM 相同。number12
fontSizeLG大号字体大小number16
lineHeight文本行高number1.5714285714285714
lineType用于控制组件边框、分割线等的样式,默认是实线stringsolid
lineWidth用于控制组件边框、分割线等的宽度number1
lineWidthFocus控制线条的宽度,当组件处于聚焦态时。number3
marginSM控制元素外边距,中小尺寸。number12
marginXS控制元素外边距,小尺寸。number8
motionDurationMid动效播放速度,中速。用于中型元素动画交互string0.2s
motionDurationSlow动效播放速度,慢速。用于大型元素如面板动画交互string0.3s
motionEaseInOutCirc预设动效曲率string
Cubic Bezier Visualizer
cubic-bezier(0.78, 0.14, 0.15, 0.86)External Link Icon
Success Text
基本

最简单的用法,适用于简短的警告提示。

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Info Text
无边框

通过 variant="filled" 隐藏边框。

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Success Text
Success Description Success Description Success Description

Info Text
Info Description Info Description Info Description Info Description

Warning Text
Warning Description Warning Description Warning Description Warning Description

Error Text
Error Description Error Description Error Description Error Description
含有辅助性文字介绍

含有辅助性文字介绍的警告提示。

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
顶部公告

页面顶部通告形式,默认有图标且 type 为 'warning'。

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Alert Message Text

click the close button to see the effect

平滑地卸载

平滑、自然的卸载提示。

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Success Tips

Error Text
Error Description Error Description Error Description Error Description

Warning Text

Info Text
Info Description Info Description Info Description Info Description
操作

可以在右上角自定义操作项。

Success Text

Info Text

Warning Text

Error Text
四种样式

共有四种样式 success、info、warning、error。

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Warning Title

Success Title

Info Title

Error Title
可关闭的警告提示

显示关闭按钮,点击可关闭警告提示。

CodeSandbox Icon
codepen icon
External Link Icon
Expand Icon
Success Tips

Informational Notes

Warning

Error

Success Tips
Detailed description and advice about successful copywriting.

Informational Notes
Additional description and information about copywriting.

Warning
This is a warning notice about copywriting.

Error
This is an error message about copywriting.
图标

可口的图标让信息类型更加醒目。

轮播的公告

配合 react-text-loop-next 或 react-fast-marquee 实现消息轮播通知栏。

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
React 错误处理

友好的 React 错误处理 包裹组件。

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Object styles
Function styles
自定义语义结构的样式和类

通过 classNames 和 styles 传入对象/函数可以自定义 Alert 的语义化结构样式。

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
6.0.0
CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Hitu Icon
CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon