Skip to content

Mantine 参考

适用范围:Mantine v8.x → v9.x(2026 年 5 月最新 v9.2.1)。本页是 API 速查手册——具体用法参见 指南

子包速查

包名用途必装依赖
@mantine/core130+ 核心组件@mantine/hooks
@mantine/hooks70+ 实用 hooks(可独立使用)-
@mantine/form表单库-
@mantine/dates日期选择器套件dayjs
@mantine/notifications通知系统@mantine/core
@mantine/modals集中式 Modal 管理器@mantine/core
@mantine/spotlight命令面板(⌘K)@mantine/core
@mantine/charts图表(Recharts 封装)recharts
@mantine/dropzone拖拽上传@mantine/core
@mantine/tiptap富文本编辑器(Tiptap)@tiptap/react @tiptap/pm @tiptap/starter-kit
@mantine/code-highlight代码高亮(highlight.js)-
@mantine/carousel轮播(Embla)embla-carousel-react
@mantine/nprogress顶部进度条-

开发依赖(v7+ 强制):

bash
pnpm add -D postcss postcss-preset-mantine postcss-simple-vars

@mantine/core - 130+ 组件清单

Layout(10)

组件说明
AppShell全局应用壳(header / navbar / aside / footer)
AspectRatio固定宽高比
Center居中容器
Container限宽容器
Flex弹性盒
Grid12 栅格
Group横向排列
SimpleGrid响应式简单网格
Space间距占位
Stack纵向排列

Inputs(23)

组件说明
AlphaSlider透明度滑块
AngleSlider角度滑块
Checkbox单选框
Chip芯片选择
ColorInput颜色输入
ColorPicker颜色选择器
Fieldset字段集
FileInput文件选择
HueSlider色相滑块
Input底层 Input
JsonInputJSON 编辑器
MaskInput掩码输入
NativeSelect原生 select
NumberInput数字输入
PasswordInput密码输入
PinInputPIN 输入
Radio / Radio.Group单选按钮
RangeSlider区间滑块
Rating星级评分
SegmentedControl分段控件
Slider滑块
Switch开关
Textarea多行文本
TextInput单行文本

Combobox(8)

组件说明
Autocomplete自动补全
Combobox底层 Combobox
MultiSelect多选下拉
Pill药丸标签
PillsInput药丸输入
Select单选下拉
TagsInput标签输入
TreeSelect树形选择

Buttons(6)

组件说明
ActionIcon图标按钮
Button标准按钮
CloseButton关闭按钮
CopyButton复制按钮
FileButton文件按钮
UnstyledButton无样式按钮
组件说明
Anchor锚点
Breadcrumbs面包屑
Burger汉堡菜单按钮
NavLink侧边栏导航项
Pagination分页
Stepper步骤条
TableOfContents目录
Tabs选项卡
Tree树视图

Feedback(7)

组件说明
Alert警告提示
Loader加载指示器
Notification通知项
Progress进度条
RingProgress环形进度
SemiCircleProgress半环形进度
Skeleton骨架屏

Overlays(12)

组件说明
Affix固定定位
Dialog浮动对话框
Drawer抽屉
FloatingIndicator浮动指示器
FloatingWindow浮动窗口
HoverCard悬停卡片
LoadingOverlay加载遮罩
Menu菜单
Modal模态对话框
Overlay通用遮罩
Popover弹出框
Tooltip工具提示

Data display(15)

组件说明
Accordion手风琴
Avatar头像
BackgroundImage背景图容器
Badge徽章
Card卡片
ColorSwatch色块
Image图片
Indicator小红点
Kbd键盘按键
NumberFormatter数字格式化
OverflowList溢出列表
RollingNumber滚动数字
Spoiler展开收起
ThemeIcon主题图标容器
Timeline时间线

Typography(9)

组件说明
Blockquote引用块
Code行内代码
Highlight高亮关键词
List列表
Mark标记
Table表格(基础语义化)
Text通用文本
Titleh1-h6 标题
Typographyprose 容器

Miscellaneous(10)

组件说明
Box通用容器(Style Props 入口)
Collapse折叠
Divider分割线
FocusTrap焦点陷阱
Marquee跑马灯
Paper纸片容器
Portal传送门
ScrollArea自定义滚动条
Scroller滚动容器
Transition过渡动画
VisuallyHidden视觉隐藏

@mantine/hooks - 70+ Hooks 清单

State 管理(21)

Hook说明
useCounter数字计数器
useDebouncedCallback防抖回调
useDebouncedState防抖状态
useDebouncedValue防抖值
useDisclosureboolean 开关(最常用)
useId唯一 ID 生成
useInputStateinput 状态
useListState列表 CRUD
useLocalStorage持久化到 localStorage
useMapMap 数据结构
usePagination分页逻辑
usePrevious上一次的值
useQueue队列
useSelection选择状态
useSetSet 数据结构
useSetState多字段状态
useStateHistory状态历史(undo/redo)
useThrottledCallback节流回调
useThrottledState节流状态
useThrottledValue节流值
useToggle多值循环切换
useUncontrolled受控/非受控双模式
useValidatedState带校验的状态

UI / DOM(30)

Hook说明
useClickOutside点击外部检测
useCollapse折叠展开
useColorScheme系统色彩模式偏好
useDrag拖拽
useElementSize元素尺寸
useEventListener事件监听
useFileDialog文件选择对话框
useFloatingWindow浮动窗口管理
useFocusReturn焦点返回
useFocusTrap焦点陷阱
useFocusWithin焦点检测
useFullscreen全屏
useHotkeys快捷键
useHoverhover 状态
useInViewport视口内检测
useIntersectionIntersectionObserver
useLongPress长按
useMask输入掩码
useMediaQuery媒体查询
useMouse鼠标位置
useMove鼠标移动
useMutationObserverDOM 变更监听
useOrientation设备方向
useRadialMove径向移动
useReducedMotion减少动画偏好
useResizeObserver尺寸变化监听
useRovingIndex焦点漫游索引
useScrollIntoView滚动到指定元素
useScrollSpy滚动监听
useScroller滚动管理
useViewportSize视口尺寸
useWindowEventwindow 事件
useWindowScrollwindow 滚动

Utilities(16)

Hook说明
useClipboard剪贴板
useDocumentTitle文档标题
useDocumentVisibility文档可见性
useEyeDropper取色器
useFaviconfavicon
useFetch数据请求
useHashURL hash
useHeadroom滚动隐藏头部
useIdle空闲检测
useInterval定时器
useMergedRef合并 refs
useNetwork网络状态
useOs操作系统
usePageLeave离开页面检测
useScrollDirection滚动方向
useTextSelection文本选择
useTimeout延时

Lifecycle(6)

Hook说明
useDidUpdate跳过首次的 effect
useForceUpdate强制更新
useIsFirstRender首次渲染检测
useIsomorphicEffectSSR 安全 useEffect
useLogger日志
useMounted挂载状态
useShallowEffect浅比较 effect

Style Props 完整表

PropCSS 属性类型
mmarginstring / number / responsive
mtmargin-top同上
mbmargin-bottom同上
mlmargin-left同上
mrmargin-right同上
mxmargin-left + margin-right同上
mymargin-top + margin-bottom同上
ppadding同上
ptpadding-top同上
pbpadding-bottom同上
plpadding-left同上
prpadding-right同上
pxpadding-x同上
pypadding-y同上
wwidthstring / number / responsive
hheight同上
miwmin-width同上
mawmax-width同上
mihmin-height同上
mahmax-height同上
ccolor主题色 / CSS color
bgbackground主题色 / CSS color
bdborder边框完整字符串
fzfont-size主题尺寸 / number
fwfont-weightnumber / string
fffont-familystring
lhline-heightnumber / string
tatext-alignleft / center / right / justify
tttext-transformuppercase / lowercase / capitalize
tdtext-decorationunderline / line-through / none
fsfont-styleitalic / normal
ltsletter-spacingnumber / string
displaydisplayblock / flex / inline / ...
flexflex1 / 0 0 auto / ...
pospositionstatic / relative / absolute / fixed
toptopnumber / string
leftleft同上
rightright同上
bottombottom同上

主题值(spacing)

  • xs = 0.625rem (10px)
  • sm = 0.75rem (12px)
  • md = 1rem (16px)
  • lg = 1.25rem (20px)
  • xl = 2rem (32px)

主题颜色引用

  • "blue.6" - theme.colors.blue[6]
  • "primary.5" - theme.colors[theme.primaryColor][5]
  • "dimmed" - 自适应灰色(light: gray.6 / dark: dark.2)
  • "bright" - 自适应高对比文字色

响应式语法

tsx
<Box w={{ base: 200, sm: 400, md: 600, lg: 800 }} />

createTheme 完整选项

ts
import { createTheme, type MantineColorsTuple } from "@mantine/core";

export const theme = createTheme({
  // ─── 颜色 ────────────────────────────────────
  primaryColor: "blue",
  primaryShade: 6,                     // number 或 { light: 6, dark: 8 }
  colors: {
    customColor: ["...", /* 10 个 shade */] as MantineColorsTuple,
  },
  white: "#fff",
  black: "#1A1B1E",

  // ─── 字体 ────────────────────────────────────
  fontFamily: "Inter, sans-serif",
  fontFamilyMonospace: "Fira Code, monospace",
  fontSmoothing: true,
  headings: {
    fontFamily: undefined,
    fontWeight: "700",
    textWrap: "wrap",
    sizes: {
      h1: { fontSize: "2.125rem", lineHeight: "1.3", fontWeight: undefined },
      h2: { fontSize: "1.625rem", lineHeight: "1.35" },
      h3: { fontSize: "1.375rem", lineHeight: "1.4" },
      h4: { fontSize: "1.125rem", lineHeight: "1.45" },
      h5: { fontSize: "1rem", lineHeight: "1.5" },
      h6: { fontSize: "0.875rem", lineHeight: "1.5" },
    },
  },
  fontSizes: {
    xs: "0.75rem",
    sm: "0.875rem",
    md: "1rem",
    lg: "1.125rem",
    xl: "1.25rem",
  },
  lineHeights: {
    xs: "1.4",
    sm: "1.45",
    md: "1.55",
    lg: "1.6",
    xl: "1.65",
  },

  // ─── 间距 ────────────────────────────────────
  spacing: {
    xs: "0.625rem",
    sm: "0.75rem",
    md: "1rem",
    lg: "1.25rem",
    xl: "2rem",
  },

  // ─── 圆角 ────────────────────────────────────
  radius: {
    xs: "0.125rem",
    sm: "0.25rem",
    md: "0.5rem",
    lg: "1rem",
    xl: "2rem",
  },
  defaultRadius: "sm",

  // ─── 阴影 ────────────────────────────────────
  shadows: {
    xs: "0 1px 3px rgba(0,0,0,0.05)",
    sm: "0 1px 3px rgba(0,0,0,0.1)",
    md: "0 4px 6px rgba(0,0,0,0.1)",
    lg: "0 10px 15px rgba(0,0,0,0.1)",
    xl: "0 20px 25px rgba(0,0,0,0.15)",
  },

  // ─── 断点 ────────────────────────────────────
  breakpoints: {
    xs: "36em",  // 576px
    sm: "48em",  // 768px
    md: "62em",  // 992px
    lg: "75em",  // 1200px
    xl: "88em",  // 1408px
  },

  // ─── 其他 ────────────────────────────────────
  focusRing: "auto",         // auto / always / never
  cursorType: "default",     // default / pointer
  scale: 1,
  autoContrast: false,
  luminanceThreshold: 0.3,
  respectReducedMotion: true,
  defaultGradient: { from: "blue", to: "cyan", deg: 45 },
  activeClassName: "...",    // 模拟 active 状态的类名
  focusClassName: "...",     // 模拟 focus 状态的类名

  // ─── 组件默认配置 ───────────────────────────
  components: {
    Button: {
      defaultProps: { radius: "md", size: "md" },
      classNames: { root: "..." },
      styles: { root: { /* ... */ } },
      vars: (theme, props) => ({ root: { "--button-...": "..." } }),
    },
    // ... 其他组件
  },

  // ─── 用户自定义字段 ─────────────────────────
  other: {
    customField: "value",
  },
});

MantineProvider 完整选项

tsx
<MantineProvider
  theme={theme}                          // 主题对象
  defaultColorScheme="auto"              // light / dark / auto
  colorSchemeManager={defaultManager}    // 自定义存储
  forceColorScheme={undefined}           // 强制色彩模式(不可切换)
  cssVariablesResolver={undefined}       // 自定义 CSS 变量生成
  classNamesPrefix="mantine"             // 类名前缀
  withCssVariables={true}                // 是否输出 CSS 变量
  withStaticClasses={true}               // 是否输出 .mantine-Xxx-xxx 静态类名
  withGlobalClasses={true}               // 是否输出全局类名
  deduplicateCssVariables={true}         // 去重 CSS 变量
  getRootElement={() => document.documentElement}
  stylesTransform={undefined}            // 样式转换
  env="default"                          // "default" / "test"(test 关闭动画 / 关闭 Portal)
>
  {children}
</MantineProvider>

Styles API

classNames

tsx
<Button
  classNames={{
    root: classes.root,
    label: classes.label,
    inner: classes.inner,
    section: classes.section,
    loader: classes.loader,
  }}
/>;

styles

tsx
<Button
  styles={{
    root: { backgroundColor: "red" },
    label: { fontWeight: 700 },
  }}
/>;

vars

tsx
<Button
  vars={(theme, props) => ({
    root: {
      "--button-bg": theme.colors.blue[6],
      "--button-color": "#fff",
    },
  })}
/>;

Function 形式

tsx
<Button
  classNames={(theme, props) => ({
    root: props.disabled ? classes.disabled : classes.active,
  })}
/>;

attributes(测试用)

tsx
<Button attributes={{ root: { "data-testid": "submit-btn" } }} />;

useMantineColorScheme

ts
const {
  colorScheme,         // "light" | "dark" | "auto"
  setColorScheme,      // (cs: "light" | "dark" | "auto") => void
  clearColorScheme,    // () => void
  toggleColorScheme,   // () => void  light <-> dark
} = useMantineColorScheme({ keepTransitions: true });

useComputedColorScheme

ts
const computed = useComputedColorScheme(
  "light",                                  // SSR 初始值
  { getInitialValueInEffect: true },
);
// 返回:"light" | "dark"

@mantine/form API

useForm

ts
const form = useForm<Values>({
  mode: "uncontrolled",                     // "controlled" | "uncontrolled"
  initialValues: { /* ... */ },
  initialErrors: { /* ... */ },
  initialTouched: { /* ... */ },
  initialDirty: { /* ... */ },
  validate: { /* ... */ },                  // 或 zodResolver(schema)
  validateInputOnChange: false,
  validateInputOnBlur: false,
  clearInputErrorOnChange: true,
  transformValues: (values) => values,
  enhanceGetInputProps: (payload) => ({}),
  onValuesChange: (values, previous) => {},
});

form API

ts
form.getValues();                           // 当前所有值
form.getInitialValues();                    // 初始值
form.setValues({ /* ... */ });
form.setFieldValue("path", value);
form.setInitialValues({ /* ... */ });

form.reset();
form.resetTouched();
form.resetDirty();

form.validate();                            // 全部校验
form.validateField("path");                 // 单字段校验
form.isValid();                             // 当前是否有效
form.isValid("path");

form.errors;                                // 当前错误对象
form.setErrors({ /* ... */ });
form.setFieldError("path", "msg");
form.clearErrors();
form.clearFieldError("path");

form.isTouched();
form.isTouched("path");
form.setTouched({ /* ... */ });

form.isDirty();
form.isDirty("path");
form.setDirty({ /* ... */ });

form.onSubmit(onSubmit, onError);
form.onReset(onReset);

form.getInputProps("path", options);
form.key("path");                           // 用于 React key
form.removeListItem("path", index);
form.insertListItem("path", value, index);
form.reorderListItem("path", { from, to });
form.replaceListItem("path", index, value);

Watch 字段变化

ts
form.watch("path", ({ previousValue, value, touched, dirty }) => {
  console.log(value);
});

@mantine/notifications API

notifications.show

ts
notifications.show({
  id: "unique-id",
  title: "标题",
  message: "消息",
  color: "blue",
  icon: <IconCheck />,
  autoClose: 4000,                          // false 不自动关闭
  withCloseButton: true,
  withBorder: false,
  loading: false,
  position: "top-right",
  zIndex: 1000,
  className: "...",
  classNames: { /* ... */ },
  style: { /* ... */ },
  styles: { /* ... */ },
  onOpen: () => {},
  onClose: (notif) => {},
});

其他方法

ts
notifications.hide(id);
notifications.update({ id, /* 其他 props */ });
notifications.clean();                       // 清空所有
notifications.cleanQueue();                  // 仅清空队列

Notifications 组件 props

tsx
<Notifications
  position="top-right"                       // top-left / top-center / top-right / bottom-...
  autoClose={4000}
  transitionDuration={250}
  limit={5}                                  // 最多同时显示
  zIndex={400}
  containerWidth={400}
  notificationMaxHeight={undefined}
  pauseResetOnHover={true}
  pauseOnFocusLoss={true}
  allowDragDismiss={true}
  allowScrollDismiss={true}
  withinPortal={true}
  portalProps={{ /* ... */ }}
/>

@mantine/modals API

modals.open

ts
modals.open({
  modalId: "unique-id",
  title: "标题",
  centered: true,
  size: "md",                                // xs / sm / md / lg / xl / "100%" / number
  fullScreen: false,
  withCloseButton: true,
  closeOnClickOutside: true,
  closeOnEscape: true,
  trapFocus: true,
  returnFocus: true,
  zIndex: 200,
  overlayProps: { backgroundOpacity: 0.55, blur: 3 },
  transitionProps: { transition: "fade", duration: 200 },
  classNames: { /* ... */ },
  styles: { /* ... */ },
  children: <YourContent />,
  onClose: () => {},
});

modals.openConfirmModal

ts
modals.openConfirmModal({
  title: "确认操作",
  centered: true,
  children: <Text>确定要继续吗?</Text>,
  labels: { confirm: "确定", cancel: "取消" },
  confirmProps: { color: "red" },
  cancelProps: { variant: "default" },
  closeOnConfirm: true,
  closeOnCancel: true,
  onConfirm: () => {},
  onCancel: () => {},
  // 其他 modals.open 选项
});

modals.openContextModal

ts
modals.openContextModal({
  modal: "createUser",                       // 预注册的 modal 键
  title: "创建用户",
  innerProps: { userId: "123" },             // 传给 modal 组件的 innerProps
  // 其他 modals.open 选项
});

其他方法

ts
modals.close(id);
modals.closeAll();
modals.updateModal({ modalId, /* 其他 props */ });
modals.updateContextModal({ modalId, /* 其他 props */ });

@mantine/spotlight API

Spotlight 组件 props

tsx
<Spotlight
  store={spotlight}                          // 可选自定义 store
  actions={actions}                          // SpotlightActionData[] | SpotlightActionGroupData[]
  shortcut={["mod + K", "mod + P", "/"]}     // 触发快捷键
  nothingFound="无匹配结果"
  highlightQuery={true}
  scrollable={true}
  maxHeight={350}
  limit={50}                                 // 显示 actions 上限
  clearQueryOnClose={true}
  filter={undefined}                         // 自定义筛选函数
  filterByTokens={undefined}
  searchProps={{ placeholder: "搜索...", leftSection: <IconSearch /> }}
  closeOnActionTrigger={true}
  closeOnEscape={true}
  closeOnClickOutside={true}
  trapFocus={true}
  zIndex={300}
  overlayProps={{ /* ... */ }}
  transitionProps={{ /* ... */ }}
  classNames={{ /* ... */ }}
  styles={{ /* ... */ }}
/>

SpotlightActionData

ts
{
  id: "home",
  label: "首页",
  description: "回到首页",
  keywords: ["index", "/"],
  onClick: () => {},
  leftSection: <IconHome />,
  rightSection: <Kbd>Ctrl+H</Kbd>,
  closeSpotlightOnTrigger: true,
  disabled: false,
}

SpotlightActionGroupData

ts
{
  group: "页面",
  actions: [/* SpotlightActionData[] */],
}

spotlight API

ts
spotlight.open();
spotlight.close();
spotlight.toggle();
spotlight.registerActions([/* ... */]);
spotlight.removeActions([/* ids */]);
spotlight.updateActions([/* ... */]);

@mantine/dates 组件清单

组件说明
Calendar纯日历组件
DateInput日期输入(自由输入 + 选择器)
DatePicker日历(无输入框)
DatePickerInput日期选择器(含输入框)
DateTimePicker日期 + 时间选择器
MonthPicker月份日历
MonthPickerInput月份选择器(含输入框)
TimeGrid时间网格
TimeInput原生时间输入
TimePicker时间选择器
TimeValue时间值
YearPicker年份日历
YearPickerInput年份选择器(含输入框)
DatesProvider全局配置(locale / 第一天)

@mantine/charts 13 种图表

图表说明
AreaChart面积图
BarChart柱状图(垂直 / 水平 / 堆叠)
BubbleChart气泡图
CompositeChart组合图(混合柱状 + 折线 + 面积)
DonutChart环形图
FunnelChart漏斗图
Heatmap热力图(如 GitHub 贡献图)
LineChart折线图
PieChart饼图
RadarChart雷达图
RadialBarChart径向柱图
ScatterChart散点图
Sparkline迷你折线(行内)

TypeScript 核心类型

ts
import type {
  // 主题
  MantineTheme,
  MantineThemeOverride,
  MantineThemeOther,
  MantineThemeColors,
  MantineThemeComponent,

  // 颜色
  MantineColor,
  MantineColorsTuple,
  MantineColorScheme,
  MantineGradient,
  MantineShade,

  // 尺寸
  MantineSize,
  MantineSpacing,
  MantineRadius,
  MantineFontSize,
  MantineLineHeight,
  MantineBreakpoint,
  MantineBreakpointsValues,
  MantineSpacingValues,
  MantineRadiusValues,
  MantineFontSizesValues,
  MantineLineHeightValues,

  // 阴影
  MantineShadow,
  MantineShadowsValues,

  // 标题
  MantineHeading,
  MantineHeadings,
  MantineHeadingProperties,
  MantineHeadingSize,

  // Styles API
  StylesApiProps,
  StylesRecord,
  ClassNames,
  PartialVarsResolver,
  Factory,

  // 组件 props
  BoxProps,
  BoxComponentProps,
  PolymorphicComponentProps,

  // 组件特定
  ButtonProps,
  ButtonVariant,
  TextInputProps,
  SelectProps,
  // ...

  // 响应式
  StyleProp,
} from "@mantine/core";

// 组件 ref
import type { ElementRef, RefCallBack } from "react";
type ButtonRef = ElementRef<typeof Button>;

主题类型扩展(Module Augmentation)

ts
// src/mantine.d.ts
import "@mantine/core";

declare module "@mantine/core" {
  export interface MantineThemeOther {
    customField: string;
  }

  // 扩展 colors 键
  export interface MantineThemeColorsOverride {
    colors: {
      brand: MantineColorsTuple;
    };
  }
}

表单类型

ts
import type {
  UseFormInput,
  UseFormReturnType,
  FormErrors,
  FormValidateInput,
  FormRulesRecord,
} from "@mantine/form";

Modals 类型扩展

ts
declare module "@mantine/modals" {
  export interface MantineModalsOverride {
    modals: {
      createUser: typeof CreateUserModal;
      editProfile: typeof EditProfileModal;
    };
  }
}

PostCSS 配置

postcss.config.cjs 完整推荐配置:

js
module.exports = {
  plugins: {
    "postcss-preset-mantine": {
      autoRem: false,                        // true 自动 px → rem
    },
    "postcss-simple-vars": {
      variables: {
        "mantine-breakpoint-xs": "36em",
        "mantine-breakpoint-sm": "48em",
        "mantine-breakpoint-md": "62em",
        "mantine-breakpoint-lg": "75em",
        "mantine-breakpoint-xl": "88em",
      },
    },
  },
};

postcss-preset-mantine 提供的 mixins

Mixin说明
light-dark(lightValue, darkValue)根据当前色彩模式选择
alpha(color, opacity)设置颜色透明度
lighten(color, amount)颜色变浅
darken(color, amount)颜色变深
@mixin light仅浅色模式样式
@mixin dark仅暗色模式样式
@mixin hover仅 hover 支持设备
@mixin smaller-than $bp媒体查询 (max-width: $bp - 0.001em)
@mixin larger-than $bp媒体查询 (min-width: $bp)
@mixin rtlRTL 方向
@mixin ltrLTR 方向
@mixin not-rtl非 RTL
@mixin where-light:where([data-mantine-color-scheme="light"])
@mixin where-dark:where([data-mantine-color-scheme="dark"])

生成的 CSS Variables

颜色(10 shade 每色)

css
--mantine-color-blue-0 ~ --mantine-color-blue-9
--mantine-color-red-0 ~ --mantine-color-red-9
--mantine-color-green-0 ~ --mantine-color-green-9
... (gray / dark / red / pink / grape / violet / indigo / blue / cyan / teal / green / lime / yellow / orange)

间距 / 圆角 / 字号 / 阴影 / 行高

css
--mantine-spacing-xs ~ --mantine-spacing-xl
--mantine-radius-xs ~ --mantine-radius-xl
--mantine-font-size-xs ~ --mantine-font-size-xl
--mantine-shadow-xs ~ --mantine-shadow-xl
--mantine-line-height-xs ~ --mantine-line-height-xl

标题

css
--mantine-h1-font-size ~ --mantine-h6-font-size
--mantine-h1-line-height ~ --mantine-h6-line-height
--mantine-h1-font-weight ~ --mantine-h6-font-weight

字体

css
--mantine-font-family
--mantine-font-family-monospace
--mantine-font-family-headings

主色

css
--mantine-primary-color-0 ~ --mantine-primary-color-9
--mantine-primary-color-filled       /* 默认 filled 背景 */
--mantine-primary-color-filled-hover
--mantine-primary-color-light
--mantine-primary-color-light-hover
--mantine-primary-color-light-color
--mantine-primary-color-contrast     /* 对比色(深色背景上的白字等) */

通用色(自适应深浅)

css
--mantine-color-text          /* 默认文本色 */
--mantine-color-body          /* body 背景 */
--mantine-color-error         /* 错误色 */
--mantine-color-placeholder   /* placeholder 色 */
--mantine-color-anchor        /* 链接色 */
--mantine-color-default       /* 默认背景 */
--mantine-color-default-hover
--mantine-color-default-color
--mantine-color-default-border
--mantine-color-dimmed        /* 弱化文本 */
--mantine-color-bright        /* 高对比文本 */
--mantine-color-disabled      /* 禁用背景 */
--mantine-color-disabled-color

主题色板(默认)

Mantine 默认提供 14 种颜色,每种 10 个 shade(0-9):

颜色用途
dark暗色背景
gray中性灰
red红色
pink粉色
grape葡萄紫
violet紫罗兰
indigo靛蓝
blue蓝色(默认 primaryColor)
cyan青色
teal蓝绿
green绿色
lime青柠
yellow黄色
orange橙色

关键模板项目

bash
# 最小 Vite + React + TS
npx degit mantinedev/vite-min-template my-app

# 完整 Vite + Vitest + Storybook + ESLint
npx degit mantinedev/vite-template my-app

# Next.js App Router
npx degit mantinedev/next-app-template my-app

# Next.js Pages Router(已不推荐)
npx degit mantinedev/next-pages-template my-app

升级路径

v6 → v7 重大变更

  • 从 Emotion 迁移到 CSS Modules —— 移除 <EmotionProvider> / MantineEmotionStylesProvider
  • 移除 sx prop —— 用 style prop 或 CSS Modules 代替
  • 移除 createStyles —— 用 CSS Modules 代替
  • 主题对象部分字段调整(如 colorScheme 改为顶层)

v7 → v8 改动

  • @mantine/form 重写(性能提升 + uncontrolled 模式成为默认)
  • useForm API 部分调整(getInputProps 第二参数 options 变更)
  • MultiSelect / TagsInput API 统一
  • 性能优化(render 次数减少)

v8 → v9 改动

  • 主要是 bug 修复 + 类型完善 + 小型 API 优化
  • 基本无破坏性变更,平滑升级

官方资源

资源URL
主文档https://mantine.dev/
组件入门https://mantine.dev/getting-started/
Hooks 入门https://mantine.dev/hooks/use-disclosure/
Mantine UI(123 业务组件)https://ui.mantine.dev/
Colors Generatorhttps://mantine.dev/colors-generator/
Help 站https://help.mantine.dev/
GitHubhttps://github.com/mantinedev/mantine
Discordhttps://discord.gg/mantine
X / Twitterhttps://x.com/mantinedev

社区扩展生态

用途
mantine-datatable简单数据表格
mantine-react-table高级数据表格(TanStack Table 底层)
mantine-form-zod-resolverZod 校验集成
mantine-form-yup-resolverYup 校验集成
mantine-form-valibot-resolverValibot 校验集成
mantine-contextmenu右键菜单
@tabler/icons-reactTabler 图标库(Mantine 推荐)
@mantinex/dev-iconsMantine 开发图标
@mantinex/mantine-logoMantine 官方 Logo 组件
@mantinex/dates-metadates 元数据