Icon
Hugeicons rendered with the SF Symbols sizing model: scales relative to text and weights that follow it.
Scales and weights
Wi-Fi at the small scale
Wi-Fi at the medium scale
Wi-Fi at the large scale
Regular, semibold, bold
import { Wifi01Icon } from "@hugeicons/core-free-icons"
import { Icon } from "@applecn/ui/components/icon"
import { Text } from "@applecn/ui/components/text"
export default function IconScales() {
return (
<div className="flex flex-col gap-4">
{(["small", "medium", "large"] as const).map((scale) => (
<Text key={scale} variant="body" className="flex items-center gap-2">
<Icon icon={Wifi01Icon} scale={scale} /> Wi-Fi at the {scale} scale
</Text>
))}
<Text variant="title-2" className="flex items-center gap-2">
{(["regular", "semibold", "bold"] as const).map((weight) => (
<Icon
key={weight}
icon={Wifi01Icon}
weight={weight}
aria-label={`${weight} weight`}
/>
))}
Regular, semibold, bold
</Text>
</div>
)
}Install
From the registry this site publishes, with dependencies resolved by the CLI.
npx shadcn@latest add https://applecn.vercel.app/r/icon.jsonSource
packages/ui/src/components/icon.tsx
import { HugeiconsIcon } from "@hugeicons/react"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "cn"
import type { ComponentProps } from "react"
/**
* The one way an icon enters the system. Hugeicons stands in for SF Symbols with the same
* sizing model: `scale` is relative to the surrounding text (SF Symbols are sized to the cap
* height, so `medium` renders the glyph at 1.2 em to match a 1 em cap), and `weight` follows
* the text weight through the stroke width. Decorative by default; pass `aria-label` to make
* it an image with a name.
*/
const iconVariants = cva("pointer-events-none shrink-0", {
variants: {
scale: {
small: "size-[0.85em]",
medium: "size-[1.2em]",
large: "size-[1.5em]",
},
},
defaultVariants: {
scale: "medium",
},
})
const strokeWidths = {
regular: 1.5,
semibold: 2,
bold: 2.5,
} as const
type IconWeight = keyof typeof strokeWidths
type IconProps = Omit<
ComponentProps<typeof HugeiconsIcon>,
"strokeWidth" | "size"
> &
VariantProps<typeof iconVariants> & {
weight?: IconWeight
}
function Icon({
className,
scale = "medium",
weight = "regular",
"aria-label": label,
...props
}: IconProps) {
const a11y = label
? { role: "img", "aria-label": label }
: { "aria-hidden": true }
return (
<HugeiconsIcon
data-slot="icon"
data-scale={scale}
strokeWidth={strokeWidths[weight]}
className={cn(iconVariants({ scale }), className)}
{...a11y}
{...props}
/>
)
}
export { Icon, iconVariants, strokeWidths }
export type { IconProps, IconWeight }