图片列表
以标准、拼接、编织或瀑布流布局组织图片集合。
本指南覆盖默认 Emotion 环境的 Material UI Core;扩展包与额外示例按清单单独标注。
使用场景与业务边界
ImageList 的 masonry 是 Core 变体,不是独立 Lab Masonry;媒体加载仍需降级。
原生组成与范围
ImageList, ImageListItem, ImageListItemBar
保持 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 结构、可空值与泛型仍按固定源码保留。
| 所属组件.属性 | 用途说明 | 声明来源 |
|---|---|---|
ImageList.variant | 所属组件的原生视觉枚举,不可替换为通用 variant 属性。 | ImageList |
ImageList.cols | ImageList 列数或 ImageListItem 跨列数,须区分所属组件。 | ImageList |
ImageList.gap | ImageList 图片间距,单位像素。 | ImageList |
ImageList.rowHeight | 原生 ImageList 行高度或自动尺寸策略。 | ImageList |
ImageListItem.cols | ImageList 列数或 ImageListItem 跨列数,须区分所属组件。 | ImageListItem |
可运行原生示例
下列机器键只选择示例入口,不会作为通用 variant 属性传入每个组件。原生示例 JSX 与数据保持上游原文;JGuang 编写的验收示例明确标注。
- 标准图片列表 ·
StandardImageList· 上游原生示例 - 拼接图片列表 ·
QuiltedImageList· 上游原生示例 - 编织图片列表 ·
WovenImageList· 上游原生示例 - 瀑布流图片列表 ·
MasonryImageList· 上游原生示例 - 带标题栏的图片列表 ·
TitlebarImageList· 上游原生示例 - 图片下方标题栏,标准布局 ·
TitlebarBelowImageList· 上游原生示例 - 图片下方标题栏,瀑布流 ·
TitlebarBelowMasonryImageList· 上游原生示例 - 自定义图片列表 ·
CustomImageList· 上游原生示例
真实使用示例
固定版本的未修改原生示例;复制时同时保留所需的局部辅助文件。
import ImageList from '@mui/material/ImageList';
import ImageListItem from '@mui/material/ImageListItem';
export default function StandardImageList() {
return (
<ImageList sx={{ width: 500, height: 450 }} cols={3} rowHeight={164}>
{itemData.map((item) => (
<ImageListItem key={item.img}>
<img
srcSet={`${item.img}?w=164&h=164&fit=crop&auto=format&dpr=2 2x`}
src={`${item.img}?w=164&h=164&fit=crop&auto=format`}
alt={item.title}
loading="lazy"
/>
</ImageListItem>
))}
</ImageList>
);
}
const itemData = [
{
img: 'https://images.unsplash.com/photo-1551963831-b3b1ca40c98e',
title: 'Breakfast',
},
{
img: 'https://images.unsplash.com/photo-1551782450-a2132b4ba21d',
title: 'Burger',
},
{
img: 'https://images.unsplash.com/photo-1522770179533-24471fcdba45',
title: 'Camera',
},
{
img: 'https://images.unsplash.com/photo-1444418776041-9c7e33cc5a9c',
title: 'Coffee',
},
{
img: 'https://images.unsplash.com/photo-1533827432537-70133748f5c8',
title: 'Hats',
},
{
img: 'https://images.unsplash.com/photo-1558642452-9d2a7deb7f62',
title: 'Honey',
},
{
img: 'https://images.unsplash.com/photo-1516802273409-68526ee1bdd6',
title: 'Basketball',
},
{
img: 'https://images.unsplash.com/photo-1518756131217-31eb79b20e8f',
title: 'Fern',
},
{
img: 'https://images.unsplash.com/photo-1597645587822-e99fa5d45d25',
title: 'Mushrooms',
},
{
img: 'https://images.unsplash.com/photo-1567306301408-9b74779a11af',
title: 'Tomato basil',
},
{
img: 'https://images.unsplash.com/photo-1471357674240-e1a485acb3e1',
title: 'Sea star',
},
{
img: 'https://images.unsplash.com/photo-1589118949245-7d38baf380d6',
title: 'Bike',
},
];
示例依赖边界
@mui/material/ImageList, @mui/material/ImageListItem, @mui/material/Box, @mui/material/ImageListItemBar, @mui/material/ListSubheader, @mui/material/IconButton, @mui/icons-material/Info, @mui/icons-material/StarBorder
直接导入 Icons/System/Utils 的示例需要匹配 9.4.0 包。局部数据与辅助文件属于示例闭包,不是额外组件。远程图片和模拟操作不提供后端。
固定上游 API 元数据参考
以下表格保留上游元数据,不是重新推断的通用类型体系。条件泛型、继承属性与回调细节以以下源码声明为准。主题默认配置可能覆盖元数据默认值。
ImageList
import ImageList from '@mui/material/ImageList';
import { ImageList } from '@mui/material';
| 属性 | 必需 | 上游元数据类型/约束 | 元数据默认值 |
|---|---|---|---|
children | 是 | node | — |
classes | 否 | object | — |
cols | 否 | integer | 2 |
component | 否 | elementType | — |
gap | 否 | number | 4 |
rowHeight | 否 | 'auto' | number | 'auto' |
sx | 否 | Array<func | object | bool> | func | object | — |
variant | 否 | 'masonry' | 'quilted' | 'standard' | 'woven' | string | 'standard' |
ImageListItem
import ImageListItem from '@mui/material/ImageListItem';
import { ImageListItem } from '@mui/material';
| 属性 | 必需 | 上游元数据类型/约束 | 元数据默认值 |
|---|---|---|---|
children | 否 | node | — |
classes | 否 | object | — |
cols | 否 | integer | 1 |
component | 否 | elementType | — |
rows | 否 | integer | 1 |
sx | 否 | Array<func | object | bool> | func | object | — |
ImageListItemBar
import ImageListItemBar from '@mui/material/ImageListItemBar';
import { ImageListItemBar } from '@mui/material';
| 属性 | 必需 | 上游元数据类型/约束 | 元数据默认值 |
|---|---|---|---|
actionIcon | 否 | node | — |
actionPosition | 否 | 'left' | 'right' | 'right' |
classes | 否 | object | — |
position | 否 | 'below' | 'bottom' | 'top' | 'bottom' |
subtitle | 否 | node | — |
sx | 否 | Array<func | object | bool> | func | object | — |
title | 否 | node | — |
原生源码声明
声明与 import 从固定源码提取,不平铺联合类型或外部继承。英文注释/类型属于原始源码参考,不代表上游正文已全文翻译。共享类型仍位于原生包中。
vendor/src/ImageList/ImageList.d.ts
import * as React from 'react';
import { SxProps } from '@mui/system';
import { OverridableStringUnion } from '@mui/types';
import { Theme } from '../styles';
import { OverridableComponent, OverrideProps } from '../OverridableComponent';
import { ImageListClasses } from './imageListClasses';
export interface ImageListPropsVariantOverrides {}
export interface ImageListOwnProps {
/**
* The content of the component, normally `ImageListItem`s.
*/
children: NonNullable<React.ReactNode>;
/**
* Override or extend the styles applied to the component.
*/
classes?: Partial<ImageListClasses> | undefined;
/**
* Number of columns.
* @default 2
*/
cols?: number | undefined;
/**
* The gap between items in px.
* @default 4
*/
gap?: number | undefined;
/**
* The height of one row in px.
* @default 'auto'
*/
rowHeight?: number | 'auto' | undefined;
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
sx?: SxProps<Theme> | undefined;
/**
* The variant to use.
* @default 'standard'
*/
variant?:
| OverridableStringUnion<
'masonry' | 'quilted' | 'standard' | 'woven',
ImageListPropsVariantOverrides
>
| undefined;
}
export interface ImageListTypeMap<
AdditionalProps = {},
RootComponent extends React.ElementType = 'ul',
> {
props: AdditionalProps & ImageListOwnProps;
defaultComponent: RootComponent;
}
declare const ImageList: OverridableComponent<ImageListTypeMap>;
export type ImageListProps<
RootComponent extends React.ElementType = ImageListTypeMap['defaultComponent'],
AdditionalProps = {},
> = OverrideProps<ImageListTypeMap<AdditionalProps, RootComponent>, RootComponent> & {
component?: React.ElementType | undefined;
};
vendor/src/ImageListItem/ImageListItem.d.ts
import * as React from 'react';
import { SxProps } from '@mui/system';
import { Theme } from '../styles';
import { OverridableComponent, OverrideProps } from '../OverridableComponent';
import { ImageListItemClasses } from './imageListItemClasses';
export interface ImageListItemOwnProps {
/**
* The content of the component, normally an `<img>`.
*/
children?: React.ReactNode;
/**
* Override or extend the styles applied to the component.
*/
classes?: Partial<ImageListItemClasses> | undefined;
/**
* Width of the item in number of grid columns.
* @default 1
*/
cols?: number | undefined;
/**
* Height of the item in number of grid rows.
* @default 1
*/
rows?: number | undefined;
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
sx?: SxProps<Theme> | undefined;
}
export interface ImageListItemTypeMap<
AdditionalProps = {},
RootComponent extends React.ElementType = 'li',
> {
props: AdditionalProps & ImageListItemOwnProps;
defaultComponent: RootComponent;
}
declare const ImageListItem: OverridableComponent<ImageListItemTypeMap>;
export type ImageListItemProps<
RootComponent extends React.ElementType = ImageListItemTypeMap['defaultComponent'],
AdditionalProps = {},
> = OverrideProps<ImageListItemTypeMap<AdditionalProps, RootComponent>, RootComponent> & {
component?: React.ElementType | undefined;
};
vendor/src/ImageListItemBar/ImageListItemBar.d.ts
import * as React from 'react';
import { SxProps } from '@mui/system';
import { Theme } from '../styles';
import { InternalStandardProps as StandardProps } from '../internal';
import { ImageListItemBarClasses } from './imageListItemBarClasses';
export interface ImageListItemBarProps extends StandardProps<
React.HTMLAttributes<HTMLDivElement>,
'title'
> {
/**
* An IconButton element to be used as secondary action target
* (primary action target is the item itself).
*/
actionIcon?: React.ReactNode;
/**
* Position of secondary action IconButton.
* @default 'right'
*/
actionPosition?: 'left' | 'right' | undefined;
/**
* Override or extend the styles applied to the component.
*/
classes?: Partial<ImageListItemBarClasses> | undefined;
/**
* Position of the title bar.
* @default 'bottom'
*/
position?: 'below' | 'top' | 'bottom' | undefined;
/**
* String or element serving as subtitle (support text).
*/
subtitle?: React.ReactNode;
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
sx?: SxProps<Theme> | undefined;
/**
* Title to be displayed.
*/
title?: React.ReactNode;
}
export default function ImageListItemBar(props: ImageListItemBarProps): React.JSX.Element;
安装后验收
执行严格类型检查、生产构建和实际交互。检查键盘标签/焦点、原生支持的禁用/错误/只读语义、深浅色、窄屏和减少动画。按真实宿主数据检查回调,不把复制提示词当作安装完成。初始化工具还需检查服务端 HTML 与无告警水合。
来源与许可
https://github.com/mui/material-ui/tree/809a7717b4c050ba3f69b75300689f07c050a16e
MIT · @mui/material@9.4.0. 保留上游原始内容与许可证。上游完整原文保留于 vendor/docs,不标为全文中文化。