Token导航 LogoToken导航

Agent Skill · 研究检索

slots-api(slots API 搜索)

用于辅助 API 设计、接口文档、请求响应结构和服务集成说明。它适合让 Agent 梳理 endpoint、生成 OpenAPI 草稿、检查字段命名、整理错误码或辅助前后端联调。使用时需要确认真实业务语义、鉴权方式、分页和错误处理规则;涉及生成接口文档时,应避免凭空补字段,最好从现有代码、schema 或接口样例中提取事实。

slots-api 是研究检索类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为需要联网;许可证信息还不明确,第三方扫描已通过,按安装量在研究检索类的 73,675 个 Skill 里排第 70,834。

总安装 198周安装 8GitHub Stars 11下载 62核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
unknown

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:slots-api(slots API 搜索)
来源仓库:https://github.com/lobbi-docs/claude
仓库路径:skills/slots-api
安装命令:
npx skills add https://github.com/lobbi-docs/claude --skill slots-api
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/lobbi-docs/claude --skill slots-api

这个 Skill 是做什么的

研究检索类 Skill 主要解决「找资料、核对事实、把来源整理清楚」的问题,通常会让助手先检索再总结。

用于辅助 API 设计、接口文档和前后端联调,支持生成 OpenAPI 草稿。适合梳理 endpoint、检查字段命名或整理错误码的场景。使用时需确认真实业务语义、鉴权方式和分页规则,避免凭空补字段。建议从现有代码或接口样例中提取事实,确保文档准确性。涉及生产环境接口时应先验证权限和数据边界。

来源仓库内路径:skills/slots-api

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/lobbi-docs/claude --skill slots-api;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它需要需要联网,先在测试目录或测试账号里跑,确认没问题再放到正式项目。

常见问题

6 条

slots-api 怎么安装?

在终端执行 npx skills add https://github.com/lobbi-docs/claude --skill slots-api。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

slots-api 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

slots-api 需要什么权限?

权限级别是需要联网。该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

slots-api 是免费的吗?

公开资料没有标注明确许可证,收费和商用限制都无法确认。正式使用前请到来源仓库核对授权说明。

slots-api 用的人多吗?

公开数据是累计安装 198 次,近一周安装 8 次,下载 62 次,GitHub 11 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

slots-api 安全吗?

第三方扫描结果为通过,但这只覆盖已知的静态检查项,不能替代自己读一遍源码和安装命令。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 第三方扫描已通过,常见的高风险行为没有命中。

先想清楚的地方

  • 许可证没有明确标注,能不能商用、能不能再分发都不确定。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理研究检索类任务、又不想每次都手写提示词的人。

不太适合

  • 需要明确授权才能用到公司项目里的场景。
  • 需要厂商级技术支持和 SLA 的生产系统。

研究检索类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
find-skills

寻找技能 · Codex、Claude

31,199,81316,486操作浏览器MIT有提醒
self-improving-agent

自我改进 Agent · OpenClaw

16,464,0023,396接触敏感数据MIT-0通过
soultrace

灵魂追踪 · Codex、Claude

7,588,94412需要联网未明确有提醒
self-improving

自我完善 · OpenClaw

6,829,2841,046需要联网MIT-0通过
microsoft-foundry

微软代工厂 · Codex、Claude

6,614,144764调用外部服务未明确有提醒
slots-api

slots API 搜索 · 本页

19811需要联网未明确通过

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

MUI Slots & slotProps API

The slots/slotProps pattern is MUI's primary mechanism for deep component customization. It lets you replace internal sub-components, inject custom renderers, and pass props to every layer of a compound component without wrapper hacks.

1. What Are Slots?

Every compound MUI component is built from smaller internal elements. The slots prop lets you swap any of those internal elements with your own component. The slotProps prop lets you pass additional props to each slot — whether you replaced it or not.

// Before (MUI v5 — deprecated)
<Autocomplete
  PaperComponent={CustomPaper}
  componentsProps={{ paper: { elevation: 8 } }}
/>

// After (MUI v6+ — slots API)
<Autocomplete
  slots={{ paper: CustomPaper }}
  slotProps={{ paper: { elevation: 8 } }}
/>

Key rules:

  • slots accepts component references (not JSX elements)
  • slotProps accepts either a plain object or a callback function
  • Slot names are camelCase: slots.valueLabel, not slots.ValueLabel
  • The component you provide receives all the props that the default slot component would receive — spread them through

2. Common Slot Patterns by Component

TextField

import { TextField, InputBase, FormHelperText } from '@mui/material';

// Replace the underlying input element
<TextField
  label="Custom Input"
  slots={{
    input: InputBase,
    inputLabel: CustomLabel,
  }}
  slotProps={{
    input: {
      sx: { borderRadius: 2, bgcolor: 'grey.50' },
      'aria-describedby': 'helper-text',
    },
    inputLabel: {
      shrink: true,
      sx: { fontWeight: 600 },
    },
    formHelperText: {
      sx: { fontSize: '0.75rem', color: 'warning.main' },
    },
    htmlInput: {
      maxLength: 100,
      pattern: '[A-Za-z]+',
    },
  }}
  helperText="Letters only, max 100 chars"
/>

Autocomplete

import {
  Autocomplete,
  TextField,
  Paper,
  Popper,
  type PaperProps,
  type PopperProps,
  type AutocompleteRenderOptionState,
} from '@mui/material';
import { forwardRef } from 'react';

// Custom paper with shadow and border radius
const StyledPaper = forwardRef<HTMLDivElement, PaperProps>((props, ref) => (
  <Paper
    {...props}
    ref={ref}
    elevation={8}
    sx={{ borderRadius: 2, border: '1px solid', borderColor: 'divider' }}
  />
));
StyledPaper.displayName = 'StyledPaper';

// Custom popper with width matching
const WidePopper = forwardRef<HTMLDivElement, PopperProps>((props, ref) => (
  <Popper {...props} ref={ref} placement="bottom-start" sx={{ minWidth: 400 }} />
));
WidePopper.displayName = 'WidePopper';

<Autocomplete
  options={options}
  slots={{
    paper: StyledPaper,
    popper: WidePopper,
    listbox: CustomListbox,
  }}
  slotProps={{
    paper: { 'data-testid': 'autocomplete-dropdown' },
    popper: { modifiers: [{ name: 'offset', options: { offset: [0, 8] } }] },
    listbox: { sx: { maxHeight: 300, '& .MuiAutocomplete-option': { py: 1 } } },
    chip: { size: 'small', color: 'primary', variant: 'outlined' },
    clearIndicator: { sx: { color: 'error.main' } },
  }}
  renderInput={(params) => <TextField {...params} label="Search" />}
/>

Select

import { Select, MenuItem } from '@mui/material';

<Select
  value={value}
  onChange={handleChange}
  slots={{
    root: CustomSelectRoot,
  }}
  slotProps={{
    listbox: {
      sx: {
        maxHeight: 250,
        '& .MuiMenuItem-root': {
          borderRadius: 1,
          mx: 0.5,
        },
      },
    },
  }}
>
  <MenuItem value={10}>Ten</MenuItem>
  <MenuItem value={20}>Twenty</MenuItem>
</Select>

Slider

import { Slider, type SliderThumbSlotProps } from '@mui/material';
import { forwardRef } from 'react';

// Custom thumb with tooltip-style display
const CustomThumb = forwardRef<HTMLSpanElement, SliderThumbSlotProps>(
  (props, ref) => {
    const { children, className, ...other } = props;
    return (
      <span ref={ref} className={className} {...other}>
        {children}
        <span style={{
          position: 'absolute',
          top: -28,
          fontSize: 12,
          fontWeight: 700,
          background: '#1976d2',
          color: '#fff',
          borderRadius: 4,
          padding: '2px 6px',
        }}>
          {props['aria-valuenow']}
        </span>
      </span>
    );
  }
);
CustomThumb.displayName = 'CustomThumb';

<Slider
  value={sliderValue}
  onChange={handleSliderChange}
  slots={{
    thumb: CustomThumb,
    track: CustomTrack,
    rail: CustomRail,
    valueLabel: CustomValueLabel,
    mark: CustomMark,
    markLabel: CustomMarkLabel,
  }}
  slotProps={{
    thumb: {
      'data-testid': 'custom-thumb',
      sx: { width: 24, height: 24 },
    },
    track: {
      sx: { height: 8, borderRadius: 4 },
    },
    rail: {
      sx: { height: 8, borderRadius: 4, opacity: 0.3 },
    },
    valueLabel: {
      sx: { bgcolor: 'primary.dark', fontSize: 12 },
    },
  }}
  marks={[
    { value: 0, label: '0' },
    { value: 50, label: '50' },
    { value: 100, label: '100' },
  ]}
/>

DatePicker

import { DatePicker } from '@mui/x-date-pickers/DatePicker';
import { PickersDay, type PickersDayProps } from '@mui/x-date-pickers/PickersDay';
import { type Dayjs } from 'dayjs';

// Highlight weekends
function CustomDay(props: PickersDayProps<Dayjs>) {
  const { day, ...other } = props;
  const isWeekend = day.day() === 0 || day.day() === 6;

  return (
    <PickersDay
      {...other}
      day={day}
      sx={{
        ...(isWeekend && {
          bgcolor: 'warning.light',
          '&:hover': { bgcolor: 'warning.main' },
        }),
      }}
    />
  );
}

<DatePicker
  label="Select date"
  value={dateValue}
  onChange={handleDateChange}
  slots={{
    day: CustomDay,
    field: CustomField,
    textField: CustomTextField,
    actionBar: CustomActionBar,
    toolbar: CustomToolbar,
    layout: CustomLayout,
  }}
  slotProps={{
    day: {
      sx: { borderRadius: 1 },
    },
    textField: {
      size: 'small',
      variant: 'filled',
      helperText: 'MM/DD/YYYY',
    },
    actionBar: {
      actions: ['clear', 'today', 'accept'],
    },
    toolbar: {
      hidden: false,
      toolbarFormat: 'ddd, MMM D',
    },
    popper: {
      placement: 'bottom-end',
    },
  }}
/>

Dialog

import { Dialog, Backdrop, type BackdropProps } from '@mui/material';
import { forwardRef } from 'react';

const BlurredBackdrop = forwardRef<HTMLDivElement, BackdropProps>((props, ref) => (
  <Backdrop
    {...props}
    ref={ref}
    sx={{
      backdropFilter: 'blur(8px)',
      backgroundColor: 'rgba(0, 0, 0, 0.3)',
    }}
  />
));
BlurredBackdrop.displayName = 'BlurredBackdrop';

<Dialog
  open={open}
  onClose={handleClose}
  slots={{
    backdrop: BlurredBackdrop,
    transition: Fade,
  }}
  slotProps={{
    backdrop: {
      timeout: 500,
      'data-testid': 'dialog-backdrop',
    },
    paper: {
      sx: {
        borderRadius: 3,
        boxShadow: 24,
        minWidth: 400,
      },
      elevation: 0,
    },
  }}
>
  <DialogTitle>Confirm Action</DialogTitle>
  <DialogContent>Are you sure?</DialogContent>
</Dialog>

Tooltip

import { Tooltip, Popper, type PopperProps } from '@mui/material';
import { forwardRef } from 'react';

const ThemedPopper = forwardRef<HTMLDivElement, PopperProps>((props, ref) => (
  <Popper
    {...props}
    ref={ref}
    sx={{
      '& .MuiTooltip-tooltip': {
        bgcolor: 'primary.dark',
        fontSize: 14,
        borderRadius: 2,
        px: 2,
        py: 1,
      },
      '& .MuiTooltip-arrow': {
        color: 'primary.dark',
      },
    }}
  />
));
ThemedPopper.displayName = 'ThemedPopper';

<Tooltip
  title="Detailed description here"
  arrow
  slots={{
    popper: ThemedPopper,
  }}
  slotProps={{
    popper: {
      modifiers: [{ name: 'offset', options: { offset: [0, -4] } }],
    },
    arrow: {
      sx: { color: 'primary.dark' },
    },
    tooltip: {
      sx: { maxWidth: 300 },
    },
    transition: {
      timeout: 200,
    },
  }}
>
  <IconButton>
    <InfoIcon />
  </IconButton>
</Tooltip>

3. Custom Slot Components

When creating a custom slot component, follow these rules:

  1. Forward the ref — MUI needs refs for positioning (Popper, Tooltip) and focus management
  2. Spread all props — The parent component passes required props (event handlers, ARIA attributes, styles); dropping them breaks functionality
  3. Use forwardRef — Required for all slot components
import { forwardRef, type HTMLAttributes } from 'react';
import { Paper, type PaperProps } from '@mui/material';

// CORRECT: Forward ref, spread props, then add customizations
const CustomPaper = forwardRef<HTMLDivElement, PaperProps>((props, ref) => {
  const { children, sx, ...rest } = props;

  return (
    <Paper
      ref={ref}
      elevation={8}
      sx={[
        { borderRadius: 2, border: '2px solid', borderColor: 'primary.main' },
        // Merge incoming sx (may be from slotProps)
        ...(Array.isArray(sx) ? sx : [sx]),
      ]}
      {...rest}
    >
      {children}
    </Paper>
  );
});
CustomPaper.displayName = 'CustomPaper';

// Usage
<Autocomplete
  slots={{ paper: CustomPaper }}
  slotProps={{ paper: { sx: { minWidth: 300 } } }} // This sx merges with the slot's sx
  renderInput={(params) => <TextField {...params} label="Search" />}
/>

Merging sx correctly:

When your custom slot defines its own sx and you also want slotProps.*.sx to apply, merge them using the array syntax:

const MySlot = forwardRef<HTMLDivElement, BoxProps>(({ sx, ...props }, ref) => (
  <Box
    ref={ref}
    sx={[
      { p: 2, bgcolor: 'grey.100' },           // slot defaults
      ...(Array.isArray(sx) ? sx : [sx]),        // incoming overrides
    ]}
    {...props}
  />
));

4. slotProps Callback Form

Instead of a static object, pass a function to slotProps to compute props based on the component's current state (the "owner state"):

import { TextField } from '@mui/material';

<TextField
  label="Dynamic styling"
  slotProps={{
    // Callback receives ownerState with component internal state
    input: (ownerState) => ({
      sx: {
        fontWeight: ownerState.focused ? 700 : 400,
        bgcolor: ownerState.error ? 'error.light' : 'transparent',
        transition: 'all 0.2s ease',
      },
    }),
    inputLabel: (ownerState) => ({
      sx: {
        color: ownerState.focused ? 'primary.main' : 'text.secondary',
        fontSize: ownerState.shrink ? 12 : 16,
      },
    }),
  }}
/>

The callback pattern is especially useful for:

  • Conditional styling based on focused/error/disabled state
  • Computed ARIA attributes based on value
  • Dynamic classes that depend on the component's internal state
import { Slider } from '@mui/material';

<Slider
  slotProps={{
    thumb: (ownerState) => ({
      sx: {
        // Change thumb color at extremes
        bgcolor: ownerState.value === 100
          ? 'success.main'
          : ownerState.value === 0
            ? 'error.main'
            : 'primary.main',
        width: ownerState.active ? 28 : 20,
        height: ownerState.active ? 28 : 20,
        transition: 'width 0.1s, height 0.1s',
      },
    }),
    valueLabel: (ownerState) => ({
      sx: {
        bgcolor: ownerState.value > 80 ? 'success.dark' : 'primary.dark',
      },
    }),
  }}
/>

Owner State Properties

Common ownerState properties vary by component:

ComponentownerState properties
TextFieldfocused, error, disabled, required, filled, size, variant, color
Slideractive, disabled, dragging, focusedThumbIndex, marked, orientation, value
Buttonactive, disabled, focusVisible, fullWidth, size, variant, color
Chipclickable, deletable, disabled, size, variant, color
BadgeanchorOrigin, color, invisible, max, overlap, variant

5. Migration from components/componentsProps (v5 to v6)

MUI v6 unified the customization API. Here is the mapping:

Prop Renames

// v5 (deprecated)
<DataGrid
  components={{
    Toolbar: CustomToolbar,
    Footer: CustomFooter,
    NoRowsOverlay: EmptyState,
  }}
  componentsProps={{
    toolbar: { showQuickFilter: true },
    footer: { sx: { bgcolor: 'grey.50' } },
  }}
/>

// v6+ (current)
<DataGrid
  slots={{
    toolbar: CustomToolbar,
    footer: CustomFooter,
    noRowsOverlay: EmptyState,
  }}
  slotProps={{
    toolbar: { showQuickFilter: true },
    footer: { sx: { bgcolor: 'grey.50' } },
  }}
/>

Named Props to Slots

Some components had dedicated props that are now unified under slots:

v5 Propv6 Equivalent
PaperComponentslots.paper
PopperComponentslots.popper
TransitionComponentslots.transition
BackdropComponentslots.backdrop
IconComponentslots.openPickerIcon
OpenPickerButtonPropsslotProps.openPickerButton
InputAdornmentPropsslotProps.inputAdornment
ToolbarComponentslots.toolbar
PaperPropsslotProps.paper
PopperPropsslotProps.popper
TransitionPropsslotProps.transition
BackdropPropsslotProps.backdrop

Casing Change

components used PascalCase keys; slots uses camelCase:

// v5
components={{ Toolbar: CustomToolbar, NoRowsOverlay: Empty }}

// v6
slots={{ toolbar: CustomToolbar, noRowsOverlay: Empty }}

Codemod

MUI provides a codemod to automate migration:

npx @mui/codemod v6.0.0/preset-safe ./src

6. DataGrid Slots (Comprehensive)

The DataGrid has the most extensive slots API in MUI. Here is a thorough reference:

Toolbar

import {
  DataGrid,
  GridToolbarContainer,
  GridToolbarExport,
  GridToolbarFilterButton,
  GridToolbarQuickFilter,
  type GridSlots,
} from '@mui/x-data-grid';

function CustomToolbar() {
  return (
    <GridToolbarContainer sx={{ p: 1, gap: 1 }}>
      <GridToolbarFilterButton />
      <GridToolbarExport />
      <Box sx={{ flexGrow: 1 }} />
      <GridToolbarQuickFilter
        debounceMs={300}
        sx={{ width: 250 }}
      />
      <Button
        size="small"
        startIcon={<AddIcon />}
        onClick={handleAddRow}
      >
        Add Row
      </Button>
    </GridToolbarContainer>
  );
}

<DataGrid
  rows={rows}
  columns={columns}
  slots={{
    toolbar: CustomToolbar,
  }}
  slotProps={{
    toolbar: {
      showQuickFilter: true,
      quickFilterProps: { debounceMs: 300 },
    },
  }}
/>

Footer

import { GridFooterContainer, type GridSlotsComponentsProps } from '@mui/x-data-grid';

function CustomFooter(props: NonNullable<GridSlotsComponentsProps['footer']>) {
  const { selectedRowCount, totalRowCount } = props;

  return (
    <GridFooterContainer sx={{ justifyContent: 'space-between', px: 2 }}>
      <Typography variant="body2" color="text.secondary">
        {selectedRowCount > 0
          ? `${selectedRowCount} of ${totalRowCount} selected`
          : `${totalRowCount} total rows`}
      </Typography>
      <Box sx={{ display: 'flex', gap: 1 }}>
        <Button size="small" onClick={handleExport}>Export CSV</Button>
        <Button size="small" onClick={handlePrint}>Print</Button>
      </Box>
    </GridFooterContainer>
  );
}

<DataGrid
  rows={rows}
  columns={columns}
  slots={{ footer: CustomFooter }}
/>

No Rows & Loading Overlays

function NoRowsOverlay() {
  return (
    <Box
      sx={{
        display: 'flex',
        flexDirection: 'column',
        alignItems: 'center',
        justifyContent: 'center',
        height: '100%',
        gap: 2,
      }}
    >
      <SearchOffIcon sx={{ fontSize: 64, color: 'text.disabled' }} />
      <Typography variant="h6" color="text.secondary">
        No results found
      </Typography>
      <Typography variant="body2" color="text.disabled">
        Try adjusting your search or filter criteria
      </Typography>
    </Box>
  );
}

function LoadingOverlay() {
  return (
    <Box
      sx={{
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'center',
        height: '100%',
      }}
    >
      <CircularProgress size={40} />
      <Typography sx={{ ml: 2 }}>Loading data...</Typography>
    </Box>
  );
}

<DataGrid
  rows={rows}
  columns={columns}
  loading={isLoading}
  slots={{
    noRowsOverlay: NoRowsOverlay,
    noResultsOverlay: NoRowsOverlay,
    loadingOverlay: LoadingOverlay,
  }}
  slotProps={{
    loadingOverlay: {
      variant: 'skeleton',
      noRowsVariant: 'skeleton',
    },
  }}
/>

Custom Cell Renderer via renderCell vs Slots

For per-column cell customization, use renderCell on the column definition. For global cell wrapper customization, use slots:

import {
  type GridColDef,
  type GridRenderCellParams,
  type GridCellParams,
} from '@mui/x-data-grid';

// Per-column: renderCell
const columns: GridColDef[] = [
  {
    field: 'status',
    headerName: 'Status',
    width: 150,
    renderCell: (params: GridRenderCellParams) => (
      <Chip
        label={params.value}
        color={params.value === 'active' ? 'success' : 'default'}
        size="small"
        variant="outlined"
      />
    ),
  },
  {
    field: 'progress',
    headerName: 'Progress',
    width: 200,
    renderCell: (params: GridRenderCellParams<any, number>) => (
      <Box sx={{ width: '100%', display: 'flex', alignItems: 'center', gap: 1 }}>
        <LinearProgress
          variant="determinate"
          value={params.value ?? 0}
          sx={{ flexGrow: 1, height: 8, borderRadius: 4 }}
        />
        <Typography variant="caption">{params.value}%</Typography>
      </Box>
    ),
  },
  {
    field: 'actions',
    headerName: 'Actions',
    type: 'actions',
    width: 120,
    getActions: (params) => [
      <GridActionsCellItem
        key="edit"
        icon={<EditIcon />}
        label="Edit"
        onClick={() => handleEdit(params.id)}
      />,
      <GridActionsCellItem
        key="delete"
        icon={<DeleteIcon />}
        label="Delete"
        onClick={() => handleDelete(params.id)}
        showInMenu
      />,
    ],
  },
];

Column Menu

import {
  GridColumnMenu,
  type GridColumnMenuProps,
  GridColumnMenuFilterItem,
  GridColumnMenuSortItem,
  GridColumnMenuColumnsItem,
} from '@mui/x-data-grid';

function CustomColumnMenu(props: GridColumnMenuProps) {
  return (
    <GridColumnMenu
      {...props}
      slots={{
        columnMenuSortItem: GridColumnMenuSortItem,
        columnMenuFilterItem: GridColumnMenuFilterItem,
        columnMenuColumnsItem: GridColumnMenuColumnsItem,
      }}
      slotProps={{
        columnMenuSortItem: { displayOrder: 0 },
        columnMenuFilterItem: { displayOrder: 10 },
        columnMenuColumnsItem: { displayOrder: 20 },
      }}
    />
  );
}

<DataGrid
  rows={rows}
  columns={columns}
  slots={{ columnMenu: CustomColumnMenu }}
/>

Base Component Overrides

DataGrid allows overriding the base MUI components it uses internally:

<DataGrid
  rows={rows}
  columns={columns}
  slots={{
    baseButton: CustomButton,
    baseTextField: CustomTextField,
    baseSelect: CustomSelect,
    baseCheckbox: CustomCheckbox,
    baseSwitch: CustomSwitch,
    baseChip: CustomChip,
    baseTooltip: CustomTooltip,
    basePopper: CustomPopper,
    baseInputAdornment: CustomInputAdornment,
    baseIconButton: CustomIconButton,
  }}
  slotProps={{
    baseButton: { variant: 'outlined', size: 'small' },
    baseTextField: { variant: 'filled', size: 'small' },
    baseCheckbox: { color: 'secondary' },
  }}
/>

Complete DataGrid Slot Reference

SlotPurpose
toolbarTop toolbar area
footerBottom footer area
columnMenuColumn header dropdown menu
columnHeadersColumn header row container
cellIndividual cell wrapper
rowRow wrapper
noRowsOverlayShown when rows array is empty
noResultsOverlayShown when filtering returns no results
loadingOverlayShown while loading={true}
detailPanelContentRow detail expand panel (Pro)
detailPanelExpandIconExpand icon for detail panel (Pro)
detailPanelCollapseIconCollapse icon for detail panel (Pro)
paginationPagination controls
filterPanelFilter panel
columnsPanelColumns visibility panel
preferencesPanelSettings panel wrapper
baseButtonBase Button used across the grid
baseTextFieldBase TextField used across the grid
baseSelectBase Select used across the grid
baseCheckboxBase Checkbox used across the grid

7. TypeScript Typing

Typing Custom Slot Components

Use SlotComponentProps to correctly type a custom slot:

import { type SlotComponentProps } from '@mui/base/utils';
import { type PaperProps } from '@mui/material/Paper';
import { type AutocompleteOwnerState } from '@mui/material/Autocomplete';
import { forwardRef } from 'react';

// Method 1: Use the exact MUI prop type directly
const TypedPaper = forwardRef<HTMLDivElement, PaperProps>((props, ref) => (
  <Paper {...props} ref={ref} elevation={8} />
));
TypedPaper.displayName = 'TypedPaper';

// Method 2: Use SlotComponentProps for full owner state access
type AutocompletePaperSlotProps = SlotComponentProps<
  typeof Paper,
  {}, // additional props you want
  AutocompleteOwnerState<string, false, false, false>
>;

const TypedPaperWithOwnerState = forwardRef<HTMLDivElement, AutocompletePaperSlotProps>(
  (props, ref) => {
    const { ownerState, ...rest } = props;
    return (
      <Paper
        {...rest}
        ref={ref}
        elevation={ownerState?.focused ? 12 : 4}
      />
    );
  }
);
TypedPaperWithOwnerState.displayName = 'TypedPaperWithOwnerState';

Typing slotProps Callbacks

import { type TextFieldOwnerState } from '@mui/material/TextField';
import { type SliderOwnerState } from '@mui/material/Slider';

// The callback signature is (ownerState: OwnerState) => SlotProps
<TextField
  slotProps={{
    input: (ownerState: TextFieldOwnerState) => ({
      sx: {
        bgcolor: ownerState.error ? 'error.light' : 'background.paper',
      },
    }),
  }}
/>

<Slider
  slotProps={{
    thumb: (ownerState: SliderOwnerState) => ({
      style: {
        backgroundColor: ownerState.active ? '#ff0000' : '#1976d2',
      },
    }),
  }}
/>

Typing DataGrid Slots

import {
  DataGrid,
  type GridSlots,
  type GridSlotsComponentsProps,
  type GridToolbarContainerProps,
} from '@mui/x-data-grid';

// Custom toolbar with typed props
interface CustomToolbarProps extends GridToolbarContainerProps {
  onAddClick: () => void;
  title: string;
}

function CustomToolbar({ onAddClick, title, ...props }: CustomToolbarProps) {
  return (
    <GridToolbarContainer {...props}>
      <Typography variant="h6">{title}</Typography>
      <Box sx={{ flexGrow: 1 }} />
      <Button onClick={onAddClick}>Add</Button>
    </GridToolbarContainer>
  );
}

// Pass custom props through slotProps
<DataGrid
  rows={rows}
  columns={columns}
  slots={{
    toolbar: CustomToolbar as GridSlots['toolbar'],
  }}
  slotProps={{
    toolbar: {
      onAddClick: handleAddRow,
      title: 'User Management',
    } as CustomToolbarProps,
  }}
/>

Extending Slot Types for Custom Components

When building a reusable component that accepts slots itself:

import { type ElementType, type ComponentPropsWithRef } from 'react';

// Define your own slots interface
interface MyComponentSlots {
  root?: ElementType;
  header?: ElementType;
  content?: ElementType;
  footer?: ElementType;
}

// Define slotProps to match
interface MyComponentSlotProps {
  root?: ComponentPropsWithRef<'div'>;
  header?: ComponentPropsWithRef<'div'> & { title?: string };
  content?: ComponentPropsWithRef<'div'>;
  footer?: ComponentPropsWithRef<'div'>;
}

interface MyComponentProps {
  slots?: MyComponentSlots;
  slotProps?: MyComponentSlotProps;
  children: React.ReactNode;
}

function MyComponent({ slots, slotProps, children }: MyComponentProps) {
  const Root = slots?.root ?? 'div';
  const Header = slots?.header ?? 'div';
  const Content = slots?.content ?? 'div';
  const Footer = slots?.footer ?? 'div';

  return (
    <Root {...slotProps?.root}>
      <Header {...slotProps?.header} />
      <Content {...slotProps?.content}>{children}</Content>
      <Footer {...slotProps?.footer} />
    </Root>
  );
}

Quick Reference: When to Use What

GoalApproach
Change props of an internal elementslotProps.elementName
Replace an internal element entirelyslots.elementName
Conditional props based on stateslotProps.elementName as callback
Custom cell in DataGrid columnrenderCell on GridColDef
Custom toolbar/footer in DataGridslots.toolbar / slots.footer
Override base MUI components in DataGridslots.baseButton etc.
Style an internal elementslotProps.elementName.sx
Add test IDs to internal elementsslotProps.elementName['data-testid']

平台分布

Codex

36.91%
按下载量换算23

Claude

29.7%
按下载量换算18

Cursor

20.38%
按下载量换算13

Gemini CLI

9.14%
按下载量换算6

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。目前只有一个公开来源,建议同时核对源仓库。

继续浏览同类 Skills