图标 Icon
Lucide 与 Sketchyicons 手绘图标集合,支持语义色、无障碍标签和可选的轻微抖动。
属性设置
调整后即时预览效果
图标尺寸名称,或精确的像素值。
图标使用的语义文字颜色。
图标的无障碍名称。纯装饰图标无需设置。
是否开启轻微的线条抖动;系统要求减少动态效果时自动停止。
组件的 CSS 类名。
基础用法
手绘线条
完整收录 Sketchyicons 的 1,756 枚手绘图标。图形沿用 Lucide 的语义,线条带有自然的弯曲和偏移。
从 @sketchyicons/react 按需导入图标,继续使用 Icon 的尺寸、语义色和无障碍标签。
import { Heart, House, Star } from "@sketchyicons/react"
import { Icon } from "@/components/ui/icon"
<Icon icon={Heart} size="lg" />
<Icon icon={House} variant="primary" label="首页" />
<Icon icon={Star} wiggle />wiggle 默认关闭,开启后只让线条轻微抖动。系统开启“减少动态效果”时,图标保持静止。
同时展示大量抖动图标时,使用共享滤镜:
import { IconWiggleProvider } from "@/components/ui/icon-effects"
;<IconWiggleProvider enabled>
<Icon icon={Heart} wiggle />
<Icon icon={Star} wiggle />
</IconWiggleProvider>颜色变体
使用 variant 选择主题语义色。颜色来自 WUI 的设计令牌,会随明暗主题自动切换。
<Icon icon={CheckIcon} variant="success" />
<Icon icon={InfoIcon} variant="info" />
<Icon icon={TriangleAlertIcon} variant="warning" />
<Icon icon={CircleXIcon} variant="destructive" />支持 default、primary、secondary、muted、info、success、warning 和 destructive。
需要使用自定义颜色时,直接传入 color;它会覆盖 variant 的语义色。
<Icon icon={SparklesIcon} variant="primary" color="rebeccapurple" />安装组件:
pnpm dlx @wui-design/cli@latest add @wui/iconpnpm add lucide-react @sketchyicons/reactcomponents/ui/icon.tsx"use client"
import * as React from "react"
import type { LucideIcon, LucideProps } from "lucide-react"
import type { SketchyIcon } from "@sketchyicons/react"
import { cn } from "@/lib/utils"
import { useIconWiggle } from "@/components/ui/icon-effects"
const iconSizes = {
xs: 12,
sm: 16,
md: 20,
lg: 24,
xl: 32,
} as const
export type IconSize = keyof typeof iconSizes
const iconColorVariants = {
default: "text-foreground",
primary: "text-primary",
secondary: "text-secondary-foreground",
muted: "text-muted-foreground",
info: "text-info",
success: "text-success",
warning: "text-warning",
destructive: "text-destructive",
} as const
export type IconColor = keyof typeof iconColorVariants
export interface IconProps extends Omit<
LucideProps,
"aria-hidden" | "aria-label" | "role" | "size" | "color"
> {
/** Lucide or Sketchyicons icon component to render. */
icon: LucideIcon | SketchyIcon
/** Named size token or an exact pixel size. @default "md" */
size?: IconSize | number
/** Semantic text color token. @default "default" */
variant?: IconColor
/** Custom CSS/SVG color. Overrides the semantic color when provided. */
color?: React.CSSProperties["color"]
/** Accessible name. Omit it when the icon is purely decorative. */
label?: string
/** Add a subtle hand-drawn line wiggle. Respects reduced motion. @default false */
wiggle?: boolean
}
/** An accessible adapter for Lucide and Sketchyicons glyphs. */
function Icon({
icon: Glyph,
size = "md",
variant = "default",
className,
style,
color,
label,
wiggle = false,
children,
...props
}: IconProps) {
const resolvedSize = typeof size === "number" ? size : iconSizes[size]
const {
className: wiggleClassName,
style: wiggleStyle,
definitions,
} = useIconWiggle(wiggle)
return (
<Glyph
data-slot="icon"
size={resolvedSize}
aria-hidden={label ? undefined : true}
aria-label={label}
role={label ? "img" : undefined}
focusable="false"
className={cn(
color === undefined ? iconColorVariants[variant] : undefined,
wiggleClassName,
className
)}
style={{ ...wiggleStyle, ...style }}
color={color}
{...props}
>
{definitions}
{children}
</Glyph>
)
}
export { Icon, iconColorVariants, iconSizes }
复制共享线条效果到 components/ui/icon-effects.tsx,并保留随附许可证
"use client"
import * as React from "react"
const WiggleContext = React.createContext<string | null>(null)
function subscribeReducedMotion(onChange: () => void) {
const preference = window.matchMedia("(prefers-reduced-motion: reduce)")
preference.addEventListener("change", onChange)
return () => preference.removeEventListener("change", onChange)
}
function getReducedMotion() {
return window.matchMedia("(prefers-reduced-motion: reduce)").matches
}
function getServerReducedMotion() {
return true
}
/** Keep SSR still and respond immediately when the system preference changes. */
function useIconReducedMotion() {
return React.useSyncExternalStore(
subscribeReducedMotion,
getReducedMotion,
getServerReducedMotion
)
}
/** A subtle boiling line, inspired by oreo-design/doodle-icons (MIT). */
function WiggleFilter({ id }: { id: string }) {
return (
<defs>
<filter
id={id}
filterUnits="userSpaceOnUse"
primitiveUnits="userSpaceOnUse"
colorInterpolationFilters="sRGB"
x="-8"
y="-8"
width="40"
height="40"
>
<feTurbulence
type="fractalNoise"
baseFrequency="0.11"
numOctaves="2"
seed="1"
result="noise"
>
<animate
attributeName="seed"
values="1;2;3;4;5;6"
dur="0.9s"
repeatCount="indefinite"
calcMode="discrete"
/>
</feTurbulence>
<feDisplacementMap
in="SourceGraphic"
in2="noise"
scale="1.6"
xChannelSelector="R"
yChannelSelector="G"
/>
</filter>
</defs>
)
}
export interface IconWiggleProviderProps {
children: React.ReactNode
/** Share one subtle line-wiggle filter across a group of icons. @default false */
enabled?: boolean
}
/** Share the animated noise source when displaying many wiggling icons. */
function IconWiggleProvider({
children,
enabled = false,
}: IconWiggleProviderProps) {
const id = `icon-wiggle-${React.useId().replace(/:/g, "")}`
const reduceMotion = useIconReducedMotion()
const active = enabled && reduceMotion === false
return (
<WiggleContext.Provider value={active ? id : null}>
{active ? (
<svg
aria-hidden
focusable="false"
width="0"
height="0"
className="pointer-events-none absolute"
>
<WiggleFilter id={id} />
</svg>
) : null}
{children}
</WiggleContext.Provider>
)
}
function useIconWiggle(enabled: boolean) {
const sharedId = React.useContext(WiggleContext)
const localId = `icon-wiggle-${React.useId().replace(/:/g, "")}`
const reduceMotion = useIconReducedMotion()
const active = enabled && reduceMotion === false
return {
// Apply the filter to geometry inside the viewBox. A filter on the outer
// svg uses the surrounding CSS coordinate system and clips larger icons.
className: active
? "overflow-visible [&>:is(path,circle,ellipse,line,polyline,polygon,rect,g)]:[filter:var(--icon-wiggle-filter)]"
: undefined,
style: active
? ({
"--icon-wiggle-filter": `url(#${sharedId ?? localId})`,
} as React.CSSProperties)
: undefined,
definitions: active && !sharedId ? <WiggleFilter id={localId} /> : null,
}
}
export { IconWiggleProvider, useIconReducedMotion, useIconWiggle }
图标库
可切换当前 lucide-react 的完整图标集合与全部 Sketchyicons 手绘图标。输入英文名称筛选,点击图标即可复制按需导入语句。
手绘模式提供“轻微抖动”开关;开启后复制的内容会包含 Icon 和 wiggle 用法。
图标按页展示,避免一次渲染整个集合;筛选不到时请尝试图标的英文名称或同义词。
1544 / 1544 个图标
Lucide 采用 ISC 许可,可用于个人和商业项目。它不收录品牌标志;品牌图标建议单独选择并逐项核对商标与许可,不要混入基础产品图标集合。
收集来源
- Lucide:当前主库,线性风格统一,React 支持和按需导入完善。
- Sketchyicons:完整收录 1,756 枚手绘图标,使用
@sketchyicons/react@0.5.0;代码采用 MIT,Lucide 图形保留 ISC 与 Feather 的 MIT 授权声明。 - Doodle Icons:轻微线条抖动的实现参考,保留其 MIT 许可证;抖动通过噪声与位移滤镜改变线条。
- Simple Icons:只在需要品牌标志时参考;图形许可不等于获得品牌商标授权。
- Iconify:适合跨图标集检索和发现候选,但每个集合的许可不同,收录前需要单独核对。
- AnimateIcons:动态主库,收录 248 个独立编排的逐路径动画。
- ItsHover:去重后本地化 207 个补充图标,与主库合计 455 个。
使用说明
import { SearchIcon } from "lucide-react"
import { Icon } from "@/components/ui/icon"
<Icon icon={SearchIcon} />
<Icon icon={SearchIcon} size="lg" strokeWidth={1.75} />
<Icon icon={SearchIcon} label="搜索" />label 为空时,图标会被视为装饰并对辅助技术隐藏。如果图标单独传达含义,请提供 label;如果图标位于已经有文字
或 aria-label 的按钮内,则保持装饰状态,避免读屏器把同一名称读两遍。
尺寸
xs、sm、md、lg、xl 分别对应 12、16、20、24、32px,也可以直接传入像素值。
按钮、输入框和菜单应优先使用预设尺寸,让图标与同一控件中的文字保持稳定对齐。
动态图标
需要图标内部路径随交互运动时,使用 AnimatedIcon。动态组件会为铃铛、复制、菜单等图形
保留各自的路径动画;普通图标不应为了装饰性效果强行替换为动态图标。
属性
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| icon * | LucideIcon | SketchyIcon | — | 要渲染的 Lucide 或 @sketchyicons/react 手绘图标组件。 |
| size | number | "sm" | "lg" | "md" | "xs" | "xl" | md | 图标尺寸名称,或精确的像素值。 |
| variant | "default" | "secondary" | "destructive" | "success" | "warning" | "info" | "primary" | "muted" | default | 图标使用的语义文字颜色。 |
| color | Color | — | 自定义 CSS/SVG 颜色。设置后会覆盖 variant。 |
| label | string | — | 图标的无障碍名称。纯装饰图标无需设置。 |
| wiggle | boolean | false | 是否开启轻微的线条抖动;系统要求减少动态效果时自动停止。 |
属性名后的 * 表示必填。