アイコンの差し替え・カスタマイズ
アイコンのカスタマイズは、UIコンポーネントに組み込まれたアイコンを別のアイコンに差し替えたり、サイズ・色を変更する設定。デフォルトアイコンがデザインに合わないとき、独自のアイコンセット(Lucide・Tabler・FontAwesome等)を使いたいときに必要になる。
Ant Design・MUI は専用のアイコンパッケージ(@ant-design/icons・@mui/icons-material)を提供しており、それ以外のライブラリも任意のSVGコンポーネントを props に渡すだけで使える。Mantine は Tabler Icons を、shadcn/ui は Lucide React を事実上の標準として採用している。
主なバリエーション
- •デフォルトアイコンの差し替え
- •アイコンライブラリの統合(Lucide / Tabler / FontAwesome等)
- •サイズ・色の変更
- •ボタン・入力フィールド内のアイコン配置(左/右)
- •アイコンのみのボタン(ActionIcon / IconButton)
- •カスタムSVGアイコンの使用
ライブラリ横断比較
| 機能 | Mantine | Ant Design | shadcn/ui | MUI |
|---|---|---|---|---|
| デフォルトアイコンの差し替え | ○ section prop | ○ icon prop | ○ 直接JSX | ○ icon/startIcon prop |
| 推奨アイコンライブラリ | △ Tabler推奨(非同梱) | ○ @ant-design/icons | △ Lucide(非同梱) | ○ @mui/icons-material |
| アイコンサイズの変更 | ○ size prop | ○ style.fontSize | ○ className h-w-* | ○ fontSize / sx prop |
| アイコン色の変更 | ○ color prop | ○ style.color | ○ className text-* | ○ color / sx prop |
| ボタン内アイコン配置(左/右) | ○ leftSection/rightSection | ○ icon+iconPosition | ○ className で配置 | ○ startIcon/endIcon |
| カスタムSVGアイコン | ○ SVGコンポーネント | ○ Icon component | ○ SVGコンポーネント | ○ SvgIcon でラップ |
○ = 対応 △ = 部分対応・制限あり × = 非対応
ライブラリ別コード例
各ライブラリでアイコンを設定する際の実装部分を抜粋しています。 動くデモは各比較ページでご確認ください。
Mantine
// Mantine のアイコン設定(Tabler Icons を推奨)
import { Button, ActionIcon, TextInput } from '@mantine/core';
import { IconSearch, IconX, IconHeart } from '@tabler/icons-react';
// ボタン内アイコン配置(leftSection / rightSection)
<Button leftSection={<IconSearch size={16} />}>検索</Button>
<Button rightSection={<IconX size={16} />}>クリア</Button>
// テキスト入力フィールドのアイコン
<TextInput
leftSection={<IconSearch size={16} />}
rightSection={<IconX size={16} style={{ cursor: 'pointer' }} />}
placeholder="検索..."
/>
// アイコンのみのボタン(ActionIcon)
<ActionIcon variant="filled" size="lg" aria-label="お気に入り">
<IconHeart size={20} />
</ActionIcon>
// アイコンのサイズ・色変更(size / color / stroke)
<IconHeart size={32} color="red" stroke={1.5} />
// カスタムSVGは props に直接渡すだけ(currentColor で色を継承)
const CustomIcon = ({ size = 16 }: { size?: number }) => (
<svg width={size} height={size} viewBox="0 0 24 24" fill="currentColor">
<path d="..." />
</svg>
);
<Button leftSection={<CustomIcon size={16} />}>カスタムアイコン</Button>Ant Design
// Ant Design のアイコン設定(@ant-design/icons)
import { Button, Input } from 'antd';
import { SearchOutlined, CloseOutlined, HeartFilled } from '@ant-design/icons';
import Icon from '@ant-design/icons';
// ボタン内アイコン
<Button icon={<SearchOutlined />} type="primary">検索</Button>
<Button icon={<SearchOutlined />} iconPosition="end">検索(右)</Button>
// アイコンのみのボタン(shape="circle")
<Button icon={<HeartFilled />} shape="circle" type="text" danger />
// 入力フィールドのアイコン(prefix / suffix)
<Input
prefix={<SearchOutlined style={{ color: '#aaa' }} />}
suffix={<CloseOutlined style={{ cursor: 'pointer' }} />}
placeholder="検索..."
/>
// アイコンのサイズ・色変更(style props)
<HeartFilled style={{ fontSize: '24px', color: '#ff4d4f' }} />
// カスタムSVGアイコン(Icon コンポーネントでラップ)
const CustomSvg = () => (
<svg width="1em" height="1em" viewBox="0 0 24 24" fill="currentColor">
<path d="..." />
</svg>
);
<Icon component={CustomSvg} style={{ fontSize: '20px', color: '#6b8ffe' }} />shadcn/ui
// shadcn/ui は Lucide React を推奨(他のライブラリも使用可)
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Search, X, Heart } from 'lucide-react';
// ボタン内アイコン(Tailwind className で配置)
<Button>
<Search className="mr-2 h-4 w-4" />
検索
</Button>
<Button>
検索
<Search className="ml-2 h-4 w-4" />
</Button>
// アイコンのみのボタン(size="icon")
<Button variant="ghost" size="icon" aria-label="お気に入り">
<Heart className="h-4 w-4" />
</Button>
// 入力フィールドのアイコン(wrapper div で実装)
<div className="relative">
<Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground" />
<Input className="pl-9 pr-9" placeholder="検索..." />
<X className="absolute right-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground cursor-pointer" />
</div>
// アイコンのサイズ・色(className で変更)
<Heart className="h-8 w-8 text-red-500" />
// カスタムSVGはそのまま JSX コンポーネントとして使用
const CustomIcon = ({ className }: { className?: string }) => (
<svg className={className} viewBox="0 0 24 24" fill="currentColor">
<path d="..." />
</svg>
);MUI
// MUI は @mui/icons-material を推奨
import { Button, IconButton, TextField, InputAdornment } from '@mui/material';
import SvgIcon from '@mui/material/SvgIcon';
import SearchIcon from '@mui/icons-material/Search';
import ClearIcon from '@mui/icons-material/Clear';
import FavoriteIcon from '@mui/icons-material/Favorite';
// ボタン内アイコン(startIcon / endIcon)
<Button startIcon={<SearchIcon />} variant="contained">検索</Button>
<Button endIcon={<SearchIcon />} variant="outlined">検索(右)</Button>
// アイコンのみのボタン(IconButton)
<IconButton aria-label="お気に入り" color="error">
<FavoriteIcon />
</IconButton>
// 入力フィールドのアイコン(InputAdornment)
<TextField
placeholder="検索..."
slotProps={{
input: {
startAdornment: (
<InputAdornment position="start"><SearchIcon /></InputAdornment>
),
endAdornment: (
<InputAdornment position="end">
<ClearIcon sx={{ cursor: 'pointer' }} />
</InputAdornment>
),
},
}}
/>
// アイコンのサイズ・色変更(fontSize prop / sx prop)
<SearchIcon fontSize="large" color="primary" />
<FavoriteIcon sx={{ fontSize: 32, color: '#ff4d4f' }} />
// カスタムSVGアイコン(SvgIcon でラップ)
function CustomIcon(props: React.ComponentProps<typeof SvgIcon>) {
return (
<SvgIcon {...props}>
<path d="..." />
</SvgIcon>
);
}
<CustomIcon fontSize="medium" color="action" />まとめ・選び方のヒント
- •アイコンセットを一緒にインストールしたい → Ant Design(
@ant-design/icons)・MUI(@mui/icons-material)は専用パッケージが充実 - •Lucide / Tabler など好きなライブラリを使いたい → Mantine(
leftSection/rightSection)・shadcn/ui(Tailwind で自由に配置)が柔軟 - •ボタン内の左右配置を型で保証したい → MUI(
startIcon/endIconprop で明示的に指定)・Mantine(leftSection/rightSectionprop) - •独自SVGアイコンを違和感なく組み込みたい → MUI(
SvgIconでラップするとテーマカラーを継承)・他3ライブラリはSVGコンポーネントをそのまま渡せる
他の逆引きリファレンス