### Render Button with Icon and Text
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/components/button.mdx
Illustrates a button that combines both an icon (`IconGitBranch`) and text, with the spacing between them automatically adjusted based on the button's size.
```tsx
```
--------------------------------
### Render Basic Button with Outline and Icon
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/components/button.mdx
Demonstrates how to render a basic button with an outline variant and an icon-only button using `ArrowUpIcon` for submission.
```tsx
```
--------------------------------
### Render Destructive Button Variant
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/components/button.mdx
Shows how to create a button with the `destructive` variant, commonly used for actions that cannot be easily undone.
```tsx
```
--------------------------------
### Render Default Button Variant
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/components/button.mdx
Displays a basic button without any explicit `variant` prop, which defaults to the primary button style.
```tsx
```
--------------------------------
### Render Ghost Button Variant
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/components/button.mdx
Provides an example of a button styled with the `ghost` variant, which appears as plain text until hovered.
```tsx
```
--------------------------------
### Render Secondary Button Variant
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/components/button.mdx
Illustrates a button using the `secondary` variant, typically for less prominent actions.
```tsx
```
--------------------------------
### Render Link Button Variant
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/components/button.mdx
Demonstrates a button styled with the `link` variant, which visually resembles a hyperlink.
```tsx
```
--------------------------------
### Render Button with Loading Spinner
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/components/button.mdx
Demonstrates a button in a disabled state that includes a `Spinner` component and text, commonly used to indicate an ongoing asynchronous operation.
```tsx
```
--------------------------------
### Create Button Group with Multiple Button States - TSX
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/components/button.mdx
Demonstrates how to structure a ButtonGroup component with nested button groups containing outline variants, icon buttons, and dropdown menus. This example shows organizing related actions into logical groupings with different button types and states.
```tsx
```
--------------------------------
### Render Basic Button Component
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/components/button.mdx
Shows a simple example of rendering the `Button` component with an 'outline' variant, displaying plain text.
```tsx
```
--------------------------------
### Render Rounded Icon Button
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/components/button.mdx
Shows how to create a fully rounded icon button by applying the Tailwind CSS `rounded-full` class to an icon button variant.
```tsx
```
--------------------------------
### Render Outline Button Variant
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/components/button.mdx
Shows how to render a button with the `outline` variant, providing a clear border and transparent background.
```tsx
```
--------------------------------
### Install Shadcn Button Component via CLI
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/components/button.mdx
Uses the `npx shadcn@latest` command-line tool to add the button component to your project, automating the setup process.
```bash
npx shadcn@latest add button
```
--------------------------------
### Import Button Component in React
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/components/button.mdx
Imports the `Button` component from the local UI components path, making it available for use within your React application.
```tsx
import { Button } from "@/components/ui/button"
```
--------------------------------
### Render Link as Button using asChild Prop - TSX
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/components/button.mdx
Shows how to use the asChild prop to render a Next.js Link component with button styling. This technique allows polymorphic component usage where the Button styles are applied to a different underlying element (Link) while maintaining proper semantics.
```tsx
import Link from "next/link"
import { Button } from "@/components/ui/button"
export function LinkAsButton() {
return (
)
}
```
--------------------------------
### Render Button Components with Various Sizes
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/components/button.mdx
Demonstrates the usage of different `size` props for the Button component, including 'sm' (small), 'icon-sm', default, 'icon', 'lg' (large), and 'icon-lg' variants. It illustrates how to create buttons with specific dimensions and icon sizing.
```tsx
// Small
// Medium
// Large
```
--------------------------------
### Render Icon-Only Button
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/components/button.mdx
Example of a button designed exclusively to display an icon, using `variant="outline"` and `size="icon"` along with `aria-label` for accessibility.
```tsx
```
--------------------------------
### Add Custom Icon Button Sizes to Button Component - TSX
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/components/button.mdx
Demonstrates how to extend the Button component with new icon sizes (icon-sm and icon-lg) by modifying the buttonVariants configuration. This involves adding size variants to the cva function that controls button styling in the button.tsx file.
```tsx
const buttonVariants = cva("...", {
variants: {
size: {
// ...
"icon-sm": "size-8",
"icon-lg": "size-10",
// ...
},
},
})
```
--------------------------------
### Override Tailwind CSS Button Cursor Style
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/components/button.mdx
Adds a CSS rule to restore `cursor: pointer` for interactive buttons and elements with `role="button"`, overriding the default `cursor: default` behavior introduced in Tailwind CSS v4.
```css
@layer base {
button:not(:disabled),
[role="button"]:not(:disabled) {
cursor: pointer;
}
}
```
--------------------------------
### API: ButtonGroupText with asChild Prop
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/components/button-group.mdx
Example of using the `asChild` prop on ButtonGroupText to render a Label component. This allows associating text with an input element within the button group.
```tsx
import { ButtonGroupText } from "@/components/ui/button-group"
import { Label } from "@/components/ui/label"
export function ButtonGroupTextDemo() {
return (
)
}
```
--------------------------------
### Usage: Basic Button Group
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/components/button-group.mdx
Demonstrates the basic usage of the ButtonGroup component, importing it along with ButtonGroupSeparator and ButtonGroupText, and rendering a group of buttons.
```tsx
import {
ButtonGroup,
ButtonGroupSeparator,
ButtonGroupText,
} from "@/components/ui/button-group"
```
--------------------------------
### Basic Input Group with Search Icon and Button - TypeScript/React
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/components/input-group.mdx
Basic usage example demonstrating an Input Group with a search input, an icon addon, and a button addon. The button is aligned to the inline-end position to appear on the right side of the input.
```tsx
Search
```
--------------------------------
### Install Button Group Component (Manual)
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/components/button-group.mdx
Manually install the Button Group component by adding the '@radix-ui/react-slot' dependency and copying the component source code into your project. Remember to update import paths as needed.
```bash
npm install @radix-ui/react-slot
```
--------------------------------
### Accessibility: Labeled Button Group
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/components/button-group.mdx
Example of using the ButtonGroup component with an `aria-label` for accessibility. This helps screen readers identify the purpose of the button group. Navigation within the group uses Tab.
```tsx
```
--------------------------------
### API: ButtonGroupSeparator Component
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/components/button-group.mdx
Demonstrates the usage of the ButtonGroupSeparator component to visually divide buttons within a group. It accepts an `orientation` prop, defaulting to 'vertical'.
```tsx
```
--------------------------------
### Import and Use Button Component in Next.js
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/installation/next.mdx
Import the Button component from the UI components directory and use it in a Next.js page component. This example demonstrates rendering a Button with click text in the home page.
```tsx
import { Button } from "@/components/ui/button"
export default function Home() {
return (
)
}
```
--------------------------------
### Use shadcn/ui Button Component in Remix Route
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/installation/remix.mdx
Demonstrates how to import and use a shadcn/ui `Button` component within a Remix route file, specifically `app/routes/index.tsx`. This example shows how to render the component as a simple clickable button on a page.
```tsx
import { Button } from "~/components/ui/button"
export default function Home() {
return (
)
}
```
--------------------------------
### Install Button Group Component (CLI)
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/components/button-group.mdx
Install the Button Group component using the Shadcn UI CLI. This command adds the necessary files and dependencies to your project.
```bash
npx shadcn@latest add button-group
```
--------------------------------
### API: ButtonGroupText Component
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/components/button-group.mdx
Shows the basic usage of the ButtonGroupText component to display text within a button group. The `asChild` prop allows rendering a custom component, like a Label.
```tsx
Text
```
--------------------------------
### Create React Component for Open in v0 Button
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/registry/open-in-v0.mdx
This React component renders a styled button that links to the v0.dev API to open a registry item. It uses the shadcn/ui Button component and includes an embedded SVG logo. The component expects a `url` prop to construct the final link.
```jsx
import { Button } from "@/components/ui/button"
export function OpenInV0Button({ url }: { url: string }) {
return (
)
}
```
--------------------------------
### Multiple Buttons in InputGroupAddon - TypeScript/React
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/components/input-group.mdx
Example showing how to include multiple InputGroupButton components within a single InputGroupAddon. This pattern is useful for creating button groups with multiple action buttons alongside an input field.
```tsx
ButtonButton
```
--------------------------------
### Render buttons within shadcn/ui InputGroup with InputGroupButton
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/components/input-group.mdx
The `InputGroupButton` component is used to display interactive buttons directly within input groups. It supports various sizes and visual variants, accepting standard HTML button attributes and custom `className` for styling.
```tsx
Button
```
--------------------------------
### EmptyContent Component with Button Action
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/components/empty.mdx
Use the EmptyContent component to display action elements such as buttons, inputs, or links. Positioned at the bottom of the empty state for user interactions.
```tsx
```
--------------------------------
### Add Button Component to Next.js Project
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/installation/next.mdx
Add the Button component from shadcn/ui to your Next.js project using the add command. This downloads and configures the component for use in your application.
```bash
npx shadcn@latest add button
```
--------------------------------
### Import and Use Button Component in TanStack Router Route
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/installation/tanstack-router.mdx
Demonstrates how to import the Button component from shadcn/ui and use it within a TanStack Router file-based route component. The example shows a simple App component rendered at the root route that displays a clickable button.
```tsx
import { createFileRoute } from "@tanstack/react-router"
import { Button } from "@/components/ui/button"
export const Route = createFileRoute("/")({
component: App,
})
function App() {
return (
)
}
```
--------------------------------
### Add and Use Button Component in React Router
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/installation/react-router.mdx
Adds the 'button' component to the shadcn/ui project and demonstrates its usage within a React Router application. This requires the shadcn/ui CLI to be initialized and the component to be added.
```bash
npx shadcn@latest add button
```
```tsx
import { Button } from "~/components/ui/button"
import type { Route } from "./+types/home"
export function meta({}: Route.MetaArgs) {
return [
{ title: "New React Router App" },
{ name: "description", content: "Welcome to React Router!" },
]
}
export default function Home() {
return (
)
}
```
--------------------------------
### API: ButtonGroup Component
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/components/button-group.mdx
Shows the basic structure of the ButtonGroup component. It accepts an `orientation` prop which can be 'horizontal' or 'vertical', defaulting to 'horizontal'.
```tsx
```
--------------------------------
### Import and use shadcn/ui Button in an Astro page
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/installation/astro.mdx
This Astro code snippet demonstrates how to import a shadcn/ui `Button` component and render it within an Astro page. It showcases the basic syntax for component integration, including the frontmatter import and JSX-like usage within the HTML body.
```astro
---
import { Button } from "@/components/ui/button"
---
Astro + TailwindCSS
```
--------------------------------
### Implement Pagination Controls for React Table (TSX)
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/components/data-table.mdx
This snippet adds user interface controls for pagination to the `DataTable` component. It includes 'Previous' and 'Next' buttons, utilizing Shadcn UI's `Button` component, and connects them to the `table.previousPage()` and `table.nextPage()` methods, disabling buttons when no further pages are available.
```tsx
import { Button } from "@/components/ui/button"
export function DataTable({
columns,
data,
}: DataTableProps) {
const table = useReactTable({
data,
columns,
getCoreRowModel: getCoreRowModel(),
getPaginationRowModel: getPaginationRowModel(),
})
return (
{ // .... }
)
}
```
--------------------------------
### Add shadcn/ui Components to Web App (pnpm)
Source: https://github.com/shadcn-ui/ui/blob/main/templates/monorepo-next/README.md
Run this command at the root of your web application to add specific shadcn/ui components, such as a button, to your project. The components will be placed in the `packages/ui/src/components` directory.
```bash
pnpm dlx shadcn@latest add button -c apps/web
```
--------------------------------
### Import and Use Button Component in TanStack Start
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/installation/tanstack.mdx
Demonstrates how to import and render the Button component in a TanStack Start route file. The component is imported from the local components/ui directory and can be used as a standard React component.
```tsx
import { Button } from "@/components/ui/button"
function App() {
return (
)
}
```
--------------------------------
### API: Nested ButtonGroup Components
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/components/button-group.mdx
Illustrates how to nest ButtonGroup components to create more complex layouts with spacing between groups.
```tsx
```
--------------------------------
### Basic Toggle Component Usage
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/components/toggle.mdx
Render a basic Toggle component with default styling. The component displays a button that can be toggled between on and off states.
```tsx
Toggle
```
--------------------------------
### Create Basic Empty State Component
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/components/empty.mdx
Create a basic empty state using the Empty component with header, media, title, description, and action button. The EmptyMedia displays an icon, title and description provide context, and EmptyContent contains an action button.
```tsx
No dataNo data found
```
--------------------------------
### Custom Calendar Day Button Implementation (React)
Source: https://github.com/shadcn-ui/ui/blob/main/apps/v4/content/docs/components/calendar.mdx
Implements a custom `CalendarDayButton` component for shad-cn/ui. It handles focus management, applies various styling based on day selection and range status, and integrates with a base `Button` component. The component accepts day properties and modifiers to control its appearance.
```tsx
function CalendarDayButton({
className,
day,
modifiers,
...props
}: React.ComponentProps) {
const defaultClassNames = getDefaultClassNames()
const ref = React.useRef(null)
React.useEffect(() => {
if (modifiers.focused) ref.current?.focus()
}, [modifiers.focused])
return (