Updated
Mute Toggle
NewCustomize
Icon only
Soft
Medium
Muted colour
Installation
npx shadcn@latest add https://uibrik.com/r/mute-toggle.jsonInstall the packages
npm install motion react-use-measureAdd the cn helper
Imports
cnfrom@/lib/utils, whichshadcn initcreates. Add it by hand without shadcn.Copy the source into your project
components/uibrik/mute-toggle/mute-toggle.tsx"use client"; import { AnimatePresence, motion, useReducedMotion } from "motion/react"; import { useState } from "react"; import useMeasure from "react-use-measure"; import { cn } from "@/lib/utils"; const EASE_OUT: [number, number, number, number] = [0.23, 1, 0.32, 1]; const SIZES = { sm: { height: 32, icon: 18, font: 13 }, md: { height: 40, icon: 20, font: 14 }, lg: { height: 48, icon: 22, font: 15 }, } as const; const VARIANTS = { soft: "bg-neutral-100 hover:bg-neutral-200/70 dark:bg-neutral-900 dark:hover:bg-neutral-800", ghost: "bg-transparent hover:bg-neutral-100 dark:hover:bg-neutral-900", } as const; export type MuteToggleProps = { /** Controlled state. */ muted?: boolean; /** State on mount when uncontrolled. */
Adds the files to
components/uibrik/mute-toggle and installs motion and react-use-measure. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/mute-toggle.Usage
import { MuteToggle } from "@/components/uibrik/mute-toggle/mute-toggle";<MuteToggle display="icon" variant="soft" size="md" mutedColor="#dc2626" defaultMuted={false} // muted={false} // onMutedChange={(muted) => {}}/>Where to use Mute Toggle
Video and audio players
The waves folding away show the sound going off, not just an icon swap.
Pairs with Music Player and Voice Note
Calls and meetings
A clear muted state with an optional tint keeps people from talking into a muted mic.
Pairs with Meeting Planner
Autoplaying hero videos
A quiet icon-only button sits in a video corner and still reads instantly.
Props
MuteToggle- display
- Type "icon" | "label"
- "icon"
- Icon alone, or with a label that rolls between states.
- label
- Type string
- "Sound on"
- Label while sound is on.
- mutedLabel
- Type string
- "Muted"
- Label while muted.
- variant
- Type "soft" | "ghost"
- "soft"
- Filled, or transparent until hovered.
- size
- Type "sm" | "md" | "lg"
- "md"
- Height and icon size.
- mutedColor
- Type string
- "#dc2626"
- Tint of the icon while muted.
- defaultMuted
- Type boolean
- false
- State on mount when uncontrolled.
- muted / onMutedChange
- Type boolean / (muted) => void
- –
- Controlled state.
- className
- Type string
- –
- Classes for the button.