Glass Icons
Row of frosted glass icon tiles that tilt and reveal a label on hover.
pnpm dlx shadcn@latest add @leo/glass-iconsProps
| Name | Type | Default | Description |
|---|---|---|---|
| className | string | undefined | - | |
| items | GlassIconsItem[] | undefined | [ { label: "Files", color: "blue", icon: ( <svg {...iconProps}> <title>Files</title> <path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z" /> <path d="M14 3v5h5" /> </svg> ), }, { label: "Books", color: "purple", icon: ( <svg {...iconProps}> <title>Books</title> <path d="M4 5a2 2 0 0 1 2-2h13v16H6a2 2 0 0 0-2 2z" /> <path d="M4 19V5" /> </svg> ), }, { label: "Health", color: "red", icon: ( <svg {...iconProps}> <title>Health</title> <path d="M20.8 4.6a5.5 5.5 0 0 0-7.8 0L12 5.7l-1-1.1a5.5 5.5 0 0 0-7.8 7.8l1 1.1L12 21l7.8-7.5 1-1.1a5.5 5.5 0 0 0 0-7.8z" /> </svg> ), }, { label: "Weather", color: "green", icon: ( <svg {...iconProps}> <title>Weather</title> <circle cx="12" cy="12" r="4" /> <path d="M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4" /> </svg> ), }, ] |
Source
"use client";
import type React from "react";
import { cn } from "@/lib/utils";
export interface GlassIconsItem {
icon: React.ReactElement;
color: string;
label: string;
customClass?: string;
}
export interface GlassIconsProps {
items?: GlassIconsItem[];
className?: string;
}
const iconProps = {
width: 24,
height: 24,
viewBox: "0 0 24 24",
fill: "none",
stroke: "currentColor",
strokeWidth: 2,
strokeLinecap: "round",
strokeLinejoin: "round",
} as const;
const DEFAULT_ITEMS: GlassIconsItem[] = [
{
label: "Files",
color: "blue",
icon: (
<svg {...iconProps}>
<title>Files</title>
<path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z" />
<path d="M14 3v5h5" />
</svg>
),
},
{
label: "Books",
color: "purple",
icon: (
<svg {...iconProps}>
<title>Books</title>
<path d="M4 5a2 2 0 0 1 2-2h13v16H6a2 2 0 0 0-2 2z" />
<path d="M4 19V5" />
</svg>
),
},
{
label: "Health",
color: "red",
icon: (
<svg {...iconProps}>
<title>Health</title>
<path d="M20.8 4.6a5.5 5.5 0 0 0-7.8 0L12 5.7l-1-1.1a5.5 5.5 0 0 0-7.8 7.8l1 1.1L12 21l7.8-7.5 1-1.1a5.5 5.5 0 0 0 0-7.8z" />
</svg>
),
},
{
label: "Weather",
color: "green",
icon: (
<svg {...iconProps}>
<title>Weather</title>
<circle cx="12" cy="12" r="4" />
<path d="M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4" />
</svg>
),
},
];
const gradientMapping: Record<string, string> = {
blue: "linear-gradient(hsl(223, 90%, 50%), hsl(208, 90%, 50%))",
purple: "linear-gradient(hsl(283, 90%, 50%), hsl(268, 90%, 50%))",
red: "linear-gradient(hsl(3, 90%, 50%), hsl(348, 90%, 50%))",
indigo: "linear-gradient(hsl(253, 90%, 50%), hsl(238, 90%, 50%))",
orange: "linear-gradient(hsl(43, 90%, 50%), hsl(28, 90%, 50%))",
green: "linear-gradient(hsl(123, 90%, 40%), hsl(108, 90%, 40%))",
};
const GlassIcons: React.FC<GlassIconsProps> = ({ items = DEFAULT_ITEMS, className }) => {
const getBackgroundStyle = (color: string): React.CSSProperties => {
if (gradientMapping[color]) {
return { background: gradientMapping[color] };
}
return { background: color };
};
return (
<div
className={cn(
"grid gap-[5em] grid-cols-2 md:grid-cols-3 mx-auto py-[3em] overflow-visible",
className,
)}
>
{items.map((item, i) => (
<button
// biome-ignore lint/suspicious/noArrayIndexKey: labels may repeat, so the index disambiguates a static list
key={`${item.label}-${i}`}
type="button"
aria-label={item.label}
className={cn(
"relative bg-transparent outline-none border-none cursor-pointer w-[4.5em] h-[4.5em] [perspective:24em] [transform-style:preserve-3d] [-webkit-tap-highlight-color:transparent] group",
item.customClass,
)}
>
<span
className="absolute top-0 left-0 w-full h-full rounded-[1.25em] block transition-[opacity,transform] duration-300 ease-[cubic-bezier(0.83,0,0.17,1)] origin-[100%_100%] rotate-[15deg] [will-change:transform] group-hover:[transform:rotate(25deg)_translate3d(-0.5em,-0.5em,0.5em)]"
style={{
...getBackgroundStyle(item.color),
boxShadow: "0.5em -0.5em 0.75em hsla(223, 10%, 10%, 0.15)",
}}
></span>
<span
className="absolute top-0 left-0 w-full h-full rounded-[1.25em] bg-[hsla(0,0%,100%,0.15)] transition-[opacity,transform] duration-300 ease-[cubic-bezier(0.83,0,0.17,1)] origin-[80%_50%] flex backdrop-blur-[0.75em] [-webkit-backdrop-filter:blur(0.75em)] [-moz-backdrop-filter:blur(0.75em)] [will-change:transform] transform group-hover:[transform:translate3d(0,0,2em)]"
style={{
boxShadow: "0 0 0 0.1em hsla(0, 0%, 100%, 0.3) inset",
}}
>
<span
className="m-auto flex h-[1.5em] w-[1.5em] items-center justify-center text-white"
aria-hidden="true"
>
{item.icon}
</span>
</span>
<span className="absolute top-full left-0 right-0 text-center whitespace-nowrap leading-[2] text-base opacity-0 transition-[opacity,transform] duration-300 ease-[cubic-bezier(0.83,0,0.17,1)] translate-y-0 group-hover:opacity-100 group-hover:[transform:translateY(20%)]">
{item.label}
</span>
</button>
))}
</div>
);
};
export { GlassIcons };
export default GlassIcons;