Button
A versatile button component with enhanced styling and multiple variants
Button
The Button component is a versatile element for user interactions. nqui provides an enhanced Button with beautiful styling, multiple variants, and full accessibility support.
Installation
npm install @nqlib/nquiImport
import { Button } from '@nqlib/nqui';Basic Usage
import { Button } from '@nqlib/nqui';
export default function Example() {
return <Button>Click me</Button>;
}Variants
Buttons come in different variants to suit various use cases:
- default - Primary button with enhanced styling, gradients, and shadows
- destructive - For dangerous or destructive actions
- secondary - A secondary button for less prominent actions
- success - For positive actions
- warning - For warning actions
- info - For informational actions
- outline - A button with an outline style
- ghost - A minimal button style
- link - A text button that looks like a link
Sizes
Buttons come in four sizes:
- sm - Small button (
h-9) - default - Default size (
h-10) - lg - Large button (
h-11) - icon - Square icon button (
h-10 w-10)
Examples
Button Variants
All 9 button variants
'use client';import { Button } from '@nqlib/nqui';export default function Example() { return ( <div className="flex flex-wrap gap-2"> <Button variant="default">Default</Button> <Button variant="destructive">Destructive</Button> <Button variant="secondary">Secondary</Button> <Button variant="success">Success</Button> <Button variant="warning">Warning</Button> <Button variant="info">Info</Button> <Button variant="outline">Outline</Button> <Button variant="ghost">Ghost</Button> <Button variant="link">Link</Button> </div> );}Icon Buttons
Square icon buttons
'use client';import { Button } from '@nqlib/nqui';import { Plus, Edit, Trash2 } from 'lucide-react';export default function Example() { return ( <div className="flex gap-2"> <Button size="icon" variant="default"> <Plus /> </Button> <Button size="icon" variant="outline"> <Edit /> </Button> <Button size="icon" variant="destructive"> <Trash2 /> </Button> </div> );}With Icons
Add icons to buttons for better visual communication
'use client';import { Button } from '@nqlib/nqui';import { Download, Heart } from 'lucide-react';export default function Example() { return ( <div className="flex gap-2"> <Button> <Download className="mr-2 h-4 w-4" /> Download </Button> <Button variant="outline"> <Heart className="mr-2 h-4 w-4" /> Favorite </Button> </div> );}Loading State
Show loading feedback during async operations
'use client';import { useState } from 'react';import { Button } from '@nqlib/nqui';import { Loader2 } from 'lucide-react';export default function Example() { const [loading, setLoading] = useState(false); return ( <Button onClick={() => { setLoading(true); setTimeout(() => setLoading(false), 2000); }} disabled={loading} > {loading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />} {loading ? 'Loading...' : 'Click to Load'} </Button> );}Disabled State
Disable buttons when actions are not available
'use client';import { Button } from '@nqlib/nqui';export default function Example() { return ( <div className="flex gap-2"> <Button>Normal</Button> <Button disabled>Disabled</Button> </div> );}Props
The Button component accepts all standard HTML button attributes plus:
| Prop | Type | Default | Description |
|---|---|---|---|
variant | "default" | "destructive" | "secondary" | "success" | "warning" | "info" | "outline" | "ghost" | "link" | "default" | The visual style variant |
size | "default" | "sm" | "lg" | "icon" | "default" | The size of the button |
asChild | boolean | false | Render as a child component (useful with Next.js Link) |
disabled | boolean | false | Whether the button is disabled |
className | string | - | Additional CSS classes |
Advanced Usage
Enhanced vs Core Button
nqui exports an enhanced Button component by default, which includes:
- Enhanced styling with gradients, shadows, and borders
- Smooth transitions and animations
- Better focus and active states
- 3D button effects on enhanced variants
For the base shadcn Button (without enhancements), you can import CoreButton:
import { CoreButton } from '@nqlib/nqui';The enhanced variants (default, destructive, secondary, success, warning, info) use the enhanced styling, while outline, ghost, and link variants fall back to the core button implementation.
With Next.js Link
import { Button } from '@nqlib/nqui';
import Link from 'next/link';
export default function Example() {
return (
<Button asChild>
<Link href="/docs">Go to Docs</Link>
</Button>
);
}Styling
Buttons use the following design tokens:
- Enhanced variants use CSS custom properties for gradients and shadows
- Focus ring:
ring-ringwithring-offset-background - Disabled:
opacity-65withcursor-not-allowed - Active state: Scale transform and inset shadow
You can customize the appearance using Tailwind classes:
<Button className="bg-custom-color hover:bg-custom-color/90">
Custom Button
</Button>Accessibility
- Fully keyboard accessible
- Proper ARIA attributes
- Focus management with visible focus rings
- Screen reader support
- Disabled state properly handled
Best Practices
- Use appropriate variants: Choose the variant that matches the action's importance
- Provide loading states: Show feedback during async operations
- Use icons wisely: Icons can enhance understanding but don't rely on them alone
- Maintain consistency: Use the same variant for similar actions across your app
- Consider disabled states: Always provide visual feedback for disabled buttons
Next Steps
- Learn about Badge component for status indicators
- Explore Form Components for form inputs
- Check out other Essential Components