🌴Ocean UI
Base components

Accordion

Allows you to display content in a collapsible manner, making it easy for users to access information while conserving screen space.

@ark-ui/accordion

Example

How to install and use

1

Complete the manual installation setup

If you haven't already completed the first 4 steps of the manual installation guide, please do so before continuing to install these components.

2

Create a accordion.tsx file and paste the following code into it.

/components/ui/accordion.tsx
"use client";

import { Accordion as AccordionPrimitive } from "@ark-ui/react/accordion";
import { ChevronDownIcon } from "lucide-react";
import type { ComponentProps, ReactNode } from "react";

import { cn } from "@/lib/utils";

function Accordion({
  className,
  ...props
}: ComponentProps<typeof AccordionPrimitive.Root>) {
  return (
    <AccordionPrimitive.Root className={cn("w-full", className)} {...props} />
  );
}

function AccordionItem({
  className,
  ...props
}: ComponentProps<typeof AccordionPrimitive.Item>) {
  return (
    <AccordionPrimitive.Item
      className={cn(
        "border-b border-border last:border-b-0",
        className
      )}
      {...props}
    />
  );
}

interface AccordionTriggerProps
  extends ComponentProps<typeof AccordionPrimitive.ItemTrigger> {
  /**
   * Optional icon or content to display on the left side
   */
  leftIcon?: ReactNode;
  /**
   * Optional icon or content to display on the right side
   * If not provided, defaults to ChevronDownIcon
   */
  rightIcon?: ReactNode;
}

function AccordionTrigger({
  className,
  children,
  leftIcon,
  rightIcon,
  ...props
}: AccordionTriggerProps) {
  return (
    <AccordionPrimitive.ItemTrigger
      className={cn(
        "group flex w-full items-center gap-4 py-4 text-left cursor-pointer text-sm font-medium transition-all outline-none",
        "hover:underline",
        "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
        "disabled:pointer-events-none disabled:opacity-50",
        "[&[data-state=open]>.accordion-chevron]:rotate-180",
        "data-[state=closed]:text-primary/60 data-[state=closed]:hover:text-primary data-[state=open]:text-primary",
        className
      )}
      {...props}
    >
      {/* Left Icon Slot */}
      {leftIcon}

      {/* Title/Content */}
      <span className="flex-1">{children}</span>

      {/* Right Icon Slot */}
      {rightIcon ? (
        <span className="ml-auto">{rightIcon}</span>
      ) : (
        <ChevronDownIcon className="accordion-chevron text-muted-foreground pointer-events-none size-4 shrink-0 transition-transform duration-200 ml-auto" />
      )}
    </AccordionPrimitive.ItemTrigger>
  );
}

function AccordionContent({
  className,
  children,
  ...props
}: ComponentProps<typeof AccordionPrimitive.ItemContent>) {
  return (
    <AccordionPrimitive.ItemContent
      className={cn(
        "overflow-hidden text-sm",
        // Ark UI recommended animations
        "data-[state=closed]:animate-accordion-collapse data-[state=open]:animate-accordion-expand",
        className
      )}
      {...props}
    >
      <div className={cn("pb-4", className)}>{children}</div>
    </AccordionPrimitive.ItemContent>
  );
}

export { Accordion, AccordionItem, AccordionTrigger, AccordionContent };
3

Finally, Choose any example you like and add it to your project.
For instance, create a new file at components/shared/{example-component-name}.tsx, paste the example code into that file, and then import and use the component wherever you need it in your application.

Overview

The Accordion component allows users to toggle the display of sections of content. It's built with Ark UI primitives and styled with Tailwind CSS for a modern, accessible experience.

Anatomy

Accordion Anatomy

The accordion consists of the following parts:

  • root: The main container wrapping all accordion items
  • item: An individual collapsible section
  • item trigger: The clickable header that toggles the item's visibility
  • item indicator: The icon (typically a chevron) that shows the open/closed state
  • item content: The collapsible content area that expands and collapses

Select Examples

Multiple Items Open

Set multiple={true} to allow multiple items to be open simultaneously.

Collapsible

Use the collapsible prop to allow the user to collapse all panels.

You can update your account information by navigating to your profile settings. Click on your profile icon in the top right corner, then select "Account Settings" from the dropdown menu. From there, you can edit your name, email, password, and other personal details.

With Loader Icon

Add an animated loader icon to indicate active accordion items. The loader spins infinitely when an item is open and displays in a theme-aware color (white/black based on theme). When closed, it shows in a muted grayish color.

Configure multiple shipping methods to meet your customers' needs. Set up local and international delivery options, define shipping zones, and create flexible pricing rules. Integrate with popular carriers for real-time rates and tracking capabilities.

With Plus/Minus Icons

Display Plus and Minus icons from lucide-react to indicate the accordion state. The Plus icon appears when an item is closed, and the Minus icon appears when an item is open. Both icons are positioned on the left side of the title, with a chevron icon on the right side.

We accept all major credit cards (Visa, Mastercard, American Express), debit cards, PayPal, Apple Pay, and Google Pay. All transactions are processed securely through our encrypted payment gateway to ensure your financial information is protected.

FAQ with Icons

A FAQ-style accordion with contextual icons for each item. Each accordion item features a left icon representing the topic, Plus/Minus icons on the right to indicate state, and a smooth hover effect on the trigger. The container has a subtle background with rounded corners.

To update your account information, please log in to your account and navigate to the settings section. From there, you can update your personal details, contact information, and other relevant information.

On this page