Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

Social Icons

FreeNew

Social profiles as inline or floating icons in four styles; action-only icons can also run a supplied callback, such as printing the page.

Installation

pnpm dlx shadcn@latest add @viewport/social-icons

First time? Add the @viewport registry to components.json. Setup takes one minute.

Usage

The code behind the preview above.

social-icons-demo.tsx
"use client";

import { useState } from "react";
import { Globe, Mail, Printer } from "lucide-react";
import { SocialIcons, type SocialLink } from "@/components/viewport/social-icons";

const links: SocialLink[] = [
  { brand: "facebook", href: "https://facebook.com" },
  { brand: "x", href: "https://x.com" },
  { brand: "instagram", href: "https://instagram.com" },
  { brand: "youtube", href: "https://youtube.com" },
  { brand: "vimeo", href: "https://vimeo.com" },
  { brand: "linkedin", href: "https://linkedin.com" },
  { brand: "pinterest", href: "https://pinterest.com" },
  { brand: "tiktok", href: "https://tiktok.com" },
  { href: "mailto:hello@example.com", label: "Email", icon: <Mail strokeWidth={2.25} />, color: "#f5b301" },
];

const messengers: SocialLink[] = [
  { brand: "whatsapp", href: "https://wa.me/15550100" },
  { brand: "telegram", href: "https://t.me/viewport" },
  { brand: "messenger", href: "https://m.me/viewport" },
  { brand: "discord", href: "https://discord.com" },
  { href: "https://example.com", label: "Website", icon: <Globe strokeWidth={2.25} />, color: "#0ea5e9" },
];
const print: SocialLink = { label: "Print page", icon: <Printer strokeWidth={2.25} />, color: "#202124", onClick: () => window.print() };

const variants = ["brand", "mono", "outline", "plain"] as const;
const shapes = ["circle", "rounded", "square"] as const;
const hovers = ["lift", "grow", "spin"] as const;
const layouts = ["inline", "floating"] as const;

function Pills<T extends string>({ label, options, value, onChange }: { label: string; options: readonly T[]; value: T; onChange: (v: T) => void }) {
  return (
    <div className="flex flex-wrap items-center justify-center gap-1" role="group" aria-label={label}>
      <span className="mr-1 text-[11px] font-medium uppercase tracking-wider text-muted-foreground" aria-hidden>
        {label}
      </span>
      {options.map((o) => (
        <button
          key={o}
          type="button"
          aria-pressed={o === value}
          onClick={() => onChange(o)}
          className="rounded-md px-3 py-1 text-xs font-medium capitalize text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring aria-pressed:bg-foreground aria-pressed:text-background"
        >
          {o}
        </button>
      ))}
    </div>
  );
}

export default function SocialIconsDemo() {
  const [variant, setVariant] = useState<(typeof variants)[number]>("brand");
  const [shape, setShape] = useState<(typeof shapes)[number]>("circle");
  const [hover, setHover] = useState<(typeof hovers)[number]>("lift");
  const [layout, setLayout] = useState<(typeof layouts)[number]>("inline");

  return (
    <div className="w-full max-w-3xl min-w-0">
      <div className="mb-5 grid gap-2">
        <Pills label="Layout" options={layouts} value={layout} onChange={setLayout} />
        <Pills label="Style" options={variants} value={variant} onChange={setVariant} />
        <Pills label="Shape" options={shapes} value={shape} onChange={setShape} />
        <Pills label="Hover" options={hovers} value={hover} onChange={setHover} />
      </div>

      {layout === "inline" ? (
        <div className="grid gap-8 rounded-3xl border border-border bg-background px-5 py-10 shadow-sm">
          <SocialIcons links={links} variant={variant} shape={shape} hover={hover} />
          <SocialIcons links={links.slice(0, 5)} variant={variant} shape={shape} hover={hover} size={28} label="Social media, small" />
          <SocialIcons links={[...links.slice(0, 4), print]} variant={variant} shape={shape} hover={hover} size={32} label="Social media and print" />
          <SocialIcons links={messengers} variant={variant} shape={shape} hover={hover} size={44} labels label="Messengers" />
        </div>
      ) : (
        <div className="relative h-[26rem] overflow-hidden rounded-3xl border border-border bg-background shadow-sm">
          <div aria-hidden className="mx-auto grid max-w-md gap-3 px-16 py-10">
            <div className="h-5 w-2/3 rounded-full bg-muted" />
            <div className="h-3 w-full rounded-full bg-muted" />
            <div className="h-3 w-11/12 rounded-full bg-muted" />
            <div className="h-3 w-4/5 rounded-full bg-muted" />
            <div className="mt-3 aspect-[16/9] w-full rounded-2xl bg-muted" />
            <div className="h-3 w-full rounded-full bg-muted" />
            <div className="h-3 w-3/4 rounded-full bg-muted" />
          </div>
          <SocialIcons links={links.slice(0, 6)} variant={variant} shape={shape} hover={hover} layout="floating" position="absolute" labels />
          <SocialIcons links={messengers.slice(0, 4)} variant={variant} shape={shape} hover={hover} layout="floating" side="right" position="absolute" labels label="Messengers" />
        </div>
      )}
    </div>
  );
}

Props

PropTypeDefault
links*SocialLink[]—
variant"brand" | "mono" | "outline" | "plain"

`brand` fills each button with the network's color, `mono` uses the text color and turns to the brand color on hover, `outline` draws a ring, `plain` shows the bare colored mark.

"brand"
shape"circle" | "rounded" | "square""circle"
sizenumber

Width and height of each button in pixels.

40
hover"lift" | "grow" | "spin" | "none"

How a button moves under the pointer or keyboard focus.

"lift"
layout"inline" | "floating"

`inline` is a wrapping row; `floating` is a column pinned to the edge of the page.

"inline"
side"left" | "right"

Which edge a floating column sticks to.

"left"
position"fixed" | "absolute"

`fixed` pins a floating column to the viewport; `absolute` pins it to the nearest positioned ancestor.

"fixed"
labelsboolean

Shows each network's name: next to the icon inline, sliding out on hover and focus when floating.

false
align"start" | "center" | "end"

Where an inline row sits in its container.

"center"
newTabboolean

Opens links in a new tab.

true
labelstring

Accessible name of the navigation landmark.

"Social media"
classNamestring—

Accessibility

  • A `nav` landmark with a list of named links, or native buttons for actions such as printing.
  • Hover color and motion are mirrored on keyboard focus, with a visible focus ring on every control.
  • Floating labels slide out on focus as well as hover, and the column stays in the tab order where it sits in your markup.
  • Lift, grow and spin are dropped under `prefers-reduced-motion`; only the color change remains.
  • Links render without client JavaScript; callbacks are supplied from a client component.