mic-selector
elevenlabs/mic-selectorFreeComponent
shadcn/ui publishes no description for this item.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/elevenlabs/ui/main/apps/www/public/r/mic-selector.jsonSource
1"use client"23import { useCallback, useEffect, useState } from "react"4import { Check, ChevronsUpDown, Mic, MicOff } from "lucide-react"56import { cn } from "@/lib/utils"7import { Button } from "@/components/ui/button"8import {9 DropdownMenu,10 DropdownMenuContent,11 DropdownMenuItem,12 DropdownMenuSeparator,13 DropdownMenuTrigger,14} from "@/components/ui/dropdown-menu"15import { LiveWaveform } from "@/components/ui/live-waveform"1617export interface AudioDevice {18 deviceId: string19 label: string20 groupId: string21}2223export interface MicSelectorProps {24 value?: string25 onValueChange?: (deviceId: string) => void26 muted?: boolean27 onMutedChange?: (muted: boolean) => void28 disabled?: boolean29 className?: string30}3132export function MicSelector({33 value,34 onValueChange,35 muted,36 onMutedChange,37 disabled,38 className,39}: MicSelectorProps) {40 const { devices, loading, error, hasPermission, loadDevices } =41 useAudioDevices()42 const [selectedDevice, setSelectedDevice] = useState<string>(value || "")43 const [internalMuted, setInternalMuted] = useState(false)44 const [isDropdownOpen, setIsDropdownOpen] = useState(false)4546 // Use controlled muted if provided, otherwise use internal state47 const isMuted = muted !== undefined ? muted : internalMuted4849 // Update internal state when controlled value changes50 useEffect(() => {51 if (value !== undefined) {52 setSelectedDevice(value)53 }54 }, [value])5556 // Select first device by default57 const defaultDeviceId = devices[0]?.deviceId || ""58 useEffect(() => {59 if (!selectedDevice && defaultDeviceId) {60 const newDevice = defaultDeviceId61 setSelectedDevice(newDevice)62 onValueChange?.(newDevice)63 }64 }, [defaultDeviceId, selectedDevice, onValueChange])6566 const currentDevice = devices.find((d) => d.deviceId === selectedDevice) ||67 devices[0] || {68 label: loading ? "Loading..." : "No microphone",69 deviceId: "",70 }7172 const handleDeviceSelect = (deviceId: string, e?: React.MouseEvent) => {73 e?.preventDefault()74 setSelectedDevice(deviceId)75 onValueChange?.(deviceId)76 }7778 const handleDropdownOpenChange = async (open: boolean) => {79 setIsDropdownOpen(open)80 if (open && !hasPermission && !loading) {81 await loadDevices()82 }83 }8485 const toggleMute = () => {86 const newMuted = !isMuted87 if (muted === undefined) {88 setInternalMuted(newMuted)89 }90 onMutedChange?.(newMuted)91 }9293 const isPreviewActive = isDropdownOpen && !isMuted9495// … truncated
What it pulls in
Other registry items
Files it writes
More from shadcn/ui
All 50 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| audio-playeraudio-player | shadcn/ui | Components | Free | 2 deps | |
| bar-visualizerbar-visualizer | shadcn/ui | Components | Free | no deps | |
| conversationconversation | shadcn/ui | Components | Free | 1 dep | |
| conversation-barconversation-bar | shadcn/ui | Components | Free | 1 dep | |
| live-waveformlive-waveform | shadcn/ui | Components | Free | no deps | |
| matrixmatrix | shadcn/ui | Components | Free | no deps | |
| messagemessage | shadcn/ui | Components | Free | 1 dep | |
| orborb | shadcn/ui | Components | Free | 4 deps |
