### Basic Description List Example
Source: https://catalyst.tailwindui.com/docs/description-list
This example shows how to use the Description List components to create a basic list of terms and details.
```javascript
import { DescriptionDetails, DescriptionList, DescriptionTerm } from '@/components/description-list'
function Example() {
return (
CustomerLeslie AlexanderEmailleslie.alexander@example.comAccessAdmin
)
}
```
--------------------------------
### Install Heroicons React Package
Source: https://catalyst.tailwindui.com/docs
Install the Heroicons React package using npm. This is the first step to using Heroicons in your project.
```bash
npm install @heroicons/react
```
```bash
npm install @heroicons/react
```
--------------------------------
### Complete Sidebar Example
Source: https://catalyst.tailwindui.com/docs/sidebar
A full example demonstrating the integration of Sidebar, SidebarFooter, Dropdown, DropdownMenu, DropdownItem, and DropdownDivider components. This structure is useful for creating navigation panels with nested options.
```jsx
function SidebarNavigation() {
return (
Dashboard
Analytics
Projects
Documents
Teams
Denise Smith
denise.smith@example.com
Account settingsPrivacy policyShare feedbackSign out
)
}
```
--------------------------------
### Basic Dropdown Example
Source: https://catalyst.tailwindui.com/docs/dropdown
This example demonstrates a basic dropdown with options for viewing, editing, and deleting a user. It uses href for navigation and onClick for actions. Ensure the necessary components are imported.
```javascript
import { Dropdown, DropdownButton, DropdownItem, DropdownMenu } from '@/components/dropdown'
import { ChevronDownIcon } from '@heroicons/react/16/solid'
function Example() {
function deleteUser() {
if (confirm('Are you sure you want to delete this user?')) {
// ...
}
}
return (
Options
ViewEdit deleteUser()}>Delete
)
}
```
--------------------------------
### Install Catalyst Dependencies
Source: https://catalyst.tailwindui.com/docs
Install the necessary npm packages for Catalyst components. These include Headless UI, motion, and clsx.
```bash
npm install @headlessui/react motion clsx
```
```bash
npm install @headlessui/react motion clsx
```
--------------------------------
### Description List Example
Source: https://catalyst.tailwindui.com/docs/description-list
This snippet demonstrates the basic usage of the Description List component to display various details.
```javascript
import { DescriptionDetails, DescriptionList, DescriptionTerm } from '@/components/description-list'
function Example() {
return (
CustomerMichael FosterEventBear Hug: Live in ConcertAmount$150.00 USDAmount after exchange rateUS$150.00 → CA$199.79Fee$4.79 USDNet$1,955.00
)
}
```
--------------------------------
### Basic Navbar Example
Source: https://catalyst.tailwindui.com/docs/navbar
Build a basic navbar with navigation links using Navbar, NavbarSection, and NavbarItem components. Ensure necessary components are imported.
```jsx
import { Navbar, NavbarItem, NavbarSection } from '@/components/navbar'
function Example() {
return (
HomeEventsOrders
)
}
```
```jsx
import { Navbar, NavbarItem, NavbarSection } from '@/components/navbar'
function Example() {
return (
HomeEventsOrders
)
}
```
--------------------------------
### Stacked Layout with Navbar and Sidebar
Source: https://catalyst.tailwindui.com/docs/stacked-layout
This example demonstrates how to use the StackedLayout component, integrating a Navbar with dropdowns and navigation items, and a Sidebar with similar navigation elements. It includes examples of avatars, dropdowns, and icons for a complete UI.
```jsx
import { Avatar } from '@/components/avatar'
import {
Dropdown,
DropdownButton,
DropdownDivider,
DropdownItem,
DropdownLabel,
DropdownMenu,
} from '@/components/dropdown'
import { Navbar, NavbarDivider, NavbarItem, NavbarLabel, NavbarSection, NavbarSpacer } from '@/components/navbar'
import { Sidebar, SidebarBody, SidebarHeader, SidebarItem, SidebarLabel, SidebarSection } from '@/components/sidebar'
import { StackedLayout } from '@/components/stacked-layout'
import {
ArrowRightStartOnRectangleIcon,
ChevronDownIcon,
Cog8ToothIcon,
LightBulbIcon,
PlusIcon,
ShieldCheckIcon,
UserIcon,
} from '@heroicons/react/16/solid'
import { InboxIcon, MagnifyingGlassIcon } from '@heroicons/react/20/solid'
const navItems = [
{ label: 'Home', url: '/' },
{ label: 'Events', url: '/events' },
{ label: 'Orders', url: '/orders' },
{ label: 'Broadcasts', url: '/broadcasts' },
{ label: 'Settings', url: '/settings' },
]
function TeamDropdownMenu() {
return (
SettingsTailwind LabsWorkcationNew team…
)
}
function Example() {
return (
Tailwind Labs
{navItems.map(({ label, url }) => (
{label}
))}
My profileSettingsPrivacy policyShare feedbackSign out
}
sidebar={
Tailwind Labs
{navItems.map(({ label, url }) => (
{label}
))}
}
>
{children}
)
}
```
--------------------------------
### Basic Listbox Example
Source: https://catalyst.tailwindui.com/docs/listbox
This is a basic example of the Listbox component. Ensure you provide an aria-label for accessibility or connect the Listbox to a label using an id.
```javascript
import { Listbox, ListboxLabel, ListboxOption } from '@/components/listbox'
function Example() {
return (
ActivePausedDelayedCanceled
)
}
```
--------------------------------
### Sidebar with Sticky Footer Example
Source: https://catalyst.tailwindui.com/docs/sidebar
Use the `SidebarFooter` component after the `SidebarBody` component to add a sticky footer to the sidebar. This example shows a typical sidebar navigation with a user profile in the footer.
```jsx
import { Avatar } from '@/components/avatar'
import { Sidebar, SidebarBody, SidebarFooter, SidebarItem, SidebarLabel, SidebarSection } from '@/components/sidebar'
import { ChevronRightIcon } from '@heroicons/react/16/solid'
import { Cog6ToothIcon, HomeIcon, MegaphoneIcon, Square2StackIcon, TicketIcon } from '@heroicons/react/20/solid'
function Example() {
return (
HomeEventsOrdersBroadcastsSettingsErica
)
}
```
--------------------------------
### Badge Colors Example
Source: https://catalyst.tailwindui.com/docs/badge
Demonstrates how to use the `color` prop to set different colors for badges. This is useful for categorizing or highlighting information.
```javascript
import { Badge } from '@/components/badge'
function Example() {
return (
documentationhelp wantedbug
)
}
```
--------------------------------
### Basic Alert Example
Source: https://catalyst.tailwindui.com/docs/alert
Demonstrates how to use the Alert component with a title, description, and action buttons. Use this to prompt user confirmation for critical actions.
```javascript
import { Alert, AlertActions, AlertDescription, AlertTitle } from '@/components/alert'
import { Button } from '@/components/button'
import { useState } from 'react'
function Example() {
let [isOpen, setIsOpen] = useState(false)
return (
<>
Are you sure you want to refund this payment?
The refund will be reflected in the customer’s bank account 2 to 3 business days after processing.
>
)
}
```
--------------------------------
### Basic Combobox Example
Source: https://catalyst.tailwindui.com/docs/combobox
A fundamental example of the Combobox component, showcasing its core functionality for selecting an item. Ensure an aria-label or a connected label is provided for accessibility.
```jsx
import { Combobox, ComboboxLabel, ComboboxOption } from '@/components/combobox'
function Example({ currentUser, users }) {
return (
user?.name}
defaultValue={currentUser}
aria-label="Assigned to"
>
{(user) => (
{user.name}
)}
)
}
```
```jsx
import { Combobox, ComboboxLabel, ComboboxOption } from '@/components/combobox'
function Example({ currentUser, users }) {
return (
user?.name}
defaultValue={currentUser}
aria-label="Assigned to"
>
{(user) => (
{user.name}
)}
)
}
```
--------------------------------
### Badge Button Example
Source: https://catalyst.tailwindui.com/docs/badge
Shows how to render a badge as a clickable button using the `BadgeButton` component. This is suitable for interactive elements.
```javascript
import { BadgeButton } from '@/components/badge'
function Example() {
return documentation
}
```
--------------------------------
### Basic Table Example
Source: https://catalyst.tailwindui.com/docs/table
This snippet demonstrates how to use the Table component with its sub-components to render a list of users. Ensure the necessary components are imported from '@/components/table'.
```jsx
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/table'
function Example({ users }) {
return (
)
}
```
--------------------------------
### Basic Fieldset Example
Source: https://catalyst.tailwindui.com/docs/fieldset
This example demonstrates a basic fieldset for shipping details, including street address, country selection, and delivery notes. It utilizes various form control components within the fieldset structure.
```jsx
import { Description, Field, FieldGroup, Fieldset, Label, Legend } from '@/components/fieldset'
import { Input } from '@/components/input'
import { Select } from '@/components/select'
import { Text } from '@/components/text'
import { Textarea } from '@/components/textarea'
function Example() {
return (
)
}
```
--------------------------------
### Badge Link Example
Source: https://catalyst.tailwindui.com/docs/badge
Illustrates how to use the `BadgeButton` component with the `href` prop to create a badge that functions as a hyperlink. Use this for navigation.
```javascript
import { BadgeButton } from '@/components/badge'
function Example() {
return documentation
}
```
--------------------------------
### Sidebar with Dropdown Example
Source: https://catalyst.tailwindui.com/docs/sidebar
Illustrates a basic sidebar structure with navigation items. Refer to Dropdown documentation for dropdown menu specifics.
```javascript
function Sidebar() {
return (
DashboardBroadcastsSettings
)
}
```
--------------------------------
### Dropdown Menu Items
Source: https://catalyst.tailwindui.com/docs/sidebar-layout
Example of various dropdown items including icons, labels, dividers, and links for navigation.
```html
SettingsPrivacy policyShare feedbackSign out
```
--------------------------------
### Basic Fieldset Example
Source: https://catalyst.tailwindui.com/docs/fieldset
Use Fieldset, Legend, Text, FieldGroup, Field, Label, Description, Input, Select, and Textarea to group form controls for shipping details. This example demonstrates a common pattern for organizing form elements.
```jsx
import { Description, Field, FieldGroup, Fieldset, Label, Legend } from '@/components/fieldset'
import { Input } from '@/components/input'
import { Select } from '@/components/select'
import { Text } from '@/components/text'
import { Textarea } from '@/components/textarea'
function Example() {
return (
)
}
```
--------------------------------
### Navbar with Logo Example
Source: https://catalyst.tailwindui.com/docs/navbar
Integrate a logo at the beginning of the navbar. The logo can be an image or a component. Ensure the Link and Logo components are imported.
```jsx
import { Link } from '@/components/link'
import { Navbar, NavbarItem, NavbarSection } from '@/components/navbar'
import { Logo } from './logo'
function Example() {
return (
Home
EventsOrders
)
}
```
```jsx
import { Link } from '@/components/link'
import { Navbar, NavbarItem, NavbarSection } from '@/components/navbar'
import { Logo } from './logo'
function Example() {
return (
Home
EventsOrders
)
}
```
--------------------------------
### Sidebar Layout Component
Source: https://catalyst.tailwindui.com/docs/sidebar-layout
Example of a complete SidebarLayout component, including a sidebar with a dropdown menu in the footer.
```jsx
function SidebarLayout({ children }) {
return (
}
footer={}
>
}>
Home
}>
Team
}>
Settings
}
>
{/* The page content */}
{children}
)
}
function SidebarFooter() {
return (
Your profile
erica@example.com
My profileSettingsPrivacy policyShare feedbackSign out
)
}
function Header() {
return (
Acme Inc.
Fiscal year 2023
)
}
function Logo() {
return (
)
}
function SidebarSection({ children }) {
return
}
function SidebarItem({ href, icon, children }) {
return (
{icon}
{children}
)
}
function Sidebar({ header, footer, children }) {
return (
{header}
{children}
{footer}
)
}
function SidebarLayout({ sidebar, children }) {
return (
{children}
)
}
// Dummy components for demonstration purposes
function ChevronUpIcon() { return }
function UserIcon() { return }
function Cog8ToothIcon() { return }
function ShieldCheckIcon() { return }
function LightBulbIcon() { return }
function ArrowRightStartOnRectangleIcon() { return }
function HomeIcon() { return }
function UsersIcon() { return }
function Cog6ToothIcon() { return }
function Avatar(props) { return }
function DropdownButton(props) { return }
function DropdownMenu(props) { return }
function DropdownItem(props) { return }
function DropdownLabel(props) { return }
function DropdownDivider() { return }
function Dropdown(props) { return }
function SidebarFooter(props) { return }
function SidebarSection(props) { return }
function SidebarItem(props) { return }
function Sidebar(props) { return }
function SidebarLayout(props) { return }
```
--------------------------------
### Textarea with Description
Source: https://catalyst.tailwindui.com/docs/textarea
Integrates a Textarea with a Label and an additional Description component for more context. This setup is useful for providing supplementary information.
```javascript
import { Description, Field, Label } from '@/components/fieldset'
import { Textarea } from '@/components/textarea'
function Example() {
return (
This will be shown under the product title.
)
}
```
```javascript
import { Description, Field, Label } from '@/components/fieldset'
import { Textarea } from '@/components/textarea'
function Example() {
return (
This will be shown under the product title.
)
}
```
--------------------------------
### Basic Sidebar Structure
Source: https://catalyst.tailwindui.com/docs/sidebar-layout
Demonstrates the fundamental structure of a sidebar with sections, items, and a footer. Includes example navigation links and user profile dropdown.
```jsx
My profileSettingsPrivacy policyShare feedbackSign out
}
>
{/* The page content */}
```
--------------------------------
### Checkbox Group Example
Source: https://catalyst.tailwindui.com/docs/checkbox
Demonstrates a group of checkboxes with labels and descriptions within a fieldset. Use this for multiple related options where users can select one or more.
```javascript
import { Checkbox, CheckboxField, CheckboxGroup } from '@/components/checkbox'
import { Description, Fieldset, Label, Legend } from '@/components/fieldset'
import { Text } from '@/components/text'
function Example() {
return (
)
}
```
--------------------------------
### Listbox with Flags
Source: https://catalyst.tailwindui.com/docs/listbox
Shows how to include flag icons within Listbox options. This example uses a 'Flag' component and maps over a list of countries to populate the options.
```javascript
import { Field, Label } from '@/components/fieldset'
import { Listbox, ListboxLabel, ListboxOption } from '@/components/listbox'
import { Flag } from '@/flags'
function Example({ currentCountry, countries }) {
return (
{countries.map((country) => (
{country.name}
))}
)
}
```
--------------------------------
### Textarea with Validation Errors
Source: https://catalyst.tailwindui.com/docs/textarea
Use the `invalid` prop on the `Field` component and render `ErrorMessage` to show validation errors. This example assumes an `errors` object with `has` and `get` methods.
```javascript
import { ErrorMessage, Field, Label } from '@/components/fieldset'
import { Textarea } from '@/components/textarea'
function Example({ errors }) {
return (
{errors.has('description') && {errors.get('description')}}
)
}
```
--------------------------------
### Complete Navbar Example
Source: https://catalyst.tailwindui.com/docs/navbar
This snippet shows a full implementation of a responsive Navbar. It includes team selection dropdown, navigation links, search, inbox, and user profile dropdown. Ensure all necessary components and icons are imported.
```jsx
import { Avatar } from '@/components/avatar'
import {
Dropdown,
DropdownButton,
DropdownDivider,
DropdownItem,
DropdownLabel,
DropdownMenu,
} from '@/components/dropdown'
import { Navbar, NavbarDivider, NavbarItem, NavbarLabel, NavbarSection, NavbarSpacer } from '@/components/navbar'
import {
ArrowRightStartOnRectangleIcon,
ChevronDownIcon,
Cog8ToothIcon,
LightBulbIcon,
PlusIcon,
ShieldCheckIcon,
UserIcon,
} from '@heroicons/react/16/solid'
import { InboxIcon, MagnifyingGlassIcon } from '@heroicons/react/20/solid'
function Example() {
return (
Tailwind LabsSettingsTailwind LabsWorkcationNew team…
Home
EventsOrdersMy profileSettingsPrivacy policyShare feedbackSign out
)
}
```
--------------------------------
### Basic Pagination Example
Source: https://catalyst.tailwindui.com/docs/pagination
Demonstrates the basic structure of the Pagination component with previous and next links, numbered pages, and a gap for larger page ranges. Ensure all necessary components are imported from '@/components/pagination'.
```javascript
import {
Pagination,
PaginationGap,
PaginationList,
PaginationNext,
PaginationPage,
PaginationPrevious,
} from '@/components/pagination'
function Example() {
return (
12
3
46566
)
}
```
--------------------------------
### Controlled Listbox Example
Source: https://catalyst.tailwindui.com/docs/listbox
Use the `value` and `onChange` props to manage the Listbox state as a controlled component. This example demonstrates setting the project status.
```javascript
import { Field, Label } from '@/components/fieldset'
import { Listbox, ListboxLabel, ListboxOption } from '@/components/listbox'
import { useState } from 'react'
function Example() {
let [status, setStatus] = useState('active')
return (
ActivePausedDelayedCanceled
)
}
```