pnpm dlx shadcn@latest add @gammaui/macbook-keyboard
import { MacBookKeyboard } from "@/components/gammaui/macbook-keyboard"
export default function Home() {
return (
<div className="flex min-h-screen items-center justify-center">
<MacBookKeyboard />
</div>
)
}<MacBookKeyboard /><MacBookKeyboard glowColor="#3b82f6" transparentKey={true} /><MacBookKeyboard transparentKey={false} keySize={45} /><MacBookKeyboard keySize={50} glowColor="#10b981" />| Prop | Type | Default | Description |
|---|---|---|---|
transparentKey | boolean | true | Whether keys should have a transparent background |
keySize | number | 40 | Size of each key in pixels (width and height) |
glowColor | string | #f43f5d | Color of the glow effect when a key is pressed |
The MacBook Keyboard component consists of several sub-components:
MacBookKeyboard - The main container component that manages keyboard state and renders all key rows.
IconKeyboardKey - Individual key component that renders standard keys with optional icons and text.
FingerPrintKey - Special component for the Touch ID sensor key.
ArrowKeys - Composite component that renders the arrow key cluster with proper MacBook layout.
ArrowKey - Individual arrow key component with directional icons.
The component includes a comprehensive key mapping system that translates browser keyboard events to visual key presses:
const keyMap: Record<string, string> = {
Escape: "esc",
Enter: "return",
Meta: "command",
Alt: "option",
Shift: "shift",
Control: "control",
// ... and more
}This allows the component to accurately highlight keys when they're pressed on your physical keyboard.
The component uses Tailwind CSS utility classes and custom styling for the authentic MacBook look:
// Gradient borders with animation
border: "1px solid #212121"
borderTop: "1.5px"
borderBottom: "0.1px"
// Inset shadow for depth
boxShadow: "inset 0px 0px 15px rgba(0,0,0,0.2)"
// Glow effect on press
textShadow: `0 0 10px ${glowColor}`
filter: `drop-shadow(0 0 8px ${glowColor})`Each key features a subtle border color animation:
variants={{
initial: { borderColor: "#212121" },
animate: {
borderColor: ["#212121", "#383838", "#212121"],
},
}}Keys animate in with a staggered delay based on their position:
transition={{
duration: 0.8,
delay: index * 0.1 + rowIndex * 0.12,
}}The component works across all modern browsers that support:
Modify the keysData array to customize the keyboard layout:
const customKeysData = [
firstRowData,
secondRowData,
// Add or remove rows
]Create new key objects with custom icons and text:
{
icon: <YourIcon size={12} />,
text: "Custom",
className: "custom-styling"
}Adjust animation timing in the component:
transition={{
duration: 1.2, // Slower animation
delay: index * 0.15, // More stagger
}}Keys not responding to keyboard input?
Glow effect not visible?
glowColor prop is a valid CSS colorAnimation performance issues?
keySize prop for better performanceBuilt with:
On This Page
InstallationUsageExamplesDefault KeyboardCustom Glow ColorSolid Background KeysLarger KeysPropsFeaturesComponent ArchitectureMain ComponentsKey MappingStylingAnimation DetailsBorder Pulse AnimationStaggered Enter AnimationAccessibilityWhen to UseBrowser CompatibilityPerformanceCustomization TipsChange Key LayoutAdd Custom KeysModify AnimationsTroubleshootingCredits