Ir al contenido

Collapse

Paneles de contenido plegables para FAQs, acordeones y secciones expandibles.

import { Collapse } from 'asterui'

Collapse Básico

Paneles plegables simples.

What is AsterUI?
AsterUI is a React component library built on DaisyUI and Tailwind CSS.
Run npm install asterui to get started.
Yes, AsterUI is open source and free to use.
import { Collapse } from 'asterui'

function App() {
  const items = [
    {
      key: '1',
      label: 'What is AsterUI?',
      children: 'AsterUI is a React component library built on DaisyUI and Tailwind CSS.',
    },
    {
      key: '2',
      label: 'How do I install it?',
      children: 'Run npm install asterui to get started.',
    },
    {
      key: '3',
      label: 'Is it free?',
      children: 'Yes, AsterUI is open source and free to use.',
    },
  ]
  
  return (
      <Collapse items={items} defaultActiveKey={['1']} />
    )
}

export default App

Acordeón

Solo un panel puede estar abierto a la vez.

Section 1
Content for section 1. Click another section to close this one.
Content for section 2. Only one section can be open.
Content for section 3. This is accordion behavior.
import { Collapse } from 'asterui'

function App() {
  const items = [
    {
      key: '1',
      label: 'Section 1',
      children: 'Content for section 1. Click another section to close this one.',
    },
    {
      key: '2',
      label: 'Section 2',
      children: 'Content for section 2. Only one section can be open.',
    },
    {
      key: '3',
      label: 'Section 3',
      children: 'Content for section 3. This is accordion behavior.',
    },
  ]
  
  return (
      <Collapse items={items} accordion defaultActiveKey="1" />
    )
}

export default App

Sin Bordes

Collapse sin bordes.

Content without borders for a cleaner look.
Great for FAQ sections or sidebars.
import { Collapse } from 'asterui'

function App() {
  const items = [
    {
      key: '1',
      label: 'Panel 1',
      children: 'Content without borders for a cleaner look.',
    },
    {
      key: '2',
      label: 'Panel 2',
      children: 'Great for FAQ sections or sidebars.',
    },
  ]
  
  return (
      <Collapse items={items} bordered={false} />
    )
}

export default App

Contenido Anidado

Collapse con contenido anidado enriquecido.

Follow these steps to get started:

  1. Install the package
  2. Import components
  3. Start building
Learn about advanced patterns and customization options.
import { Collapse, Button, Space } from 'asterui'

function App() {
  const items = [
    {
      key: '1',
      label: 'Getting Started',
      children: (
        <Space direction="vertical" size="sm">
          <p>Follow these steps to get started:</p>
          <ol className="list-decimal list-inside">
            <li>Install the package</li>
            <li>Import components</li>
            <li>Start building</li>
          </ol>
          <Button color="primary" size="sm">Read Docs</Button>
        </Space>
      ),
    },
    {
      key: '2',
      label: 'Advanced Usage',
      children: 'Learn about advanced patterns and customization options.',
    },
  ]
  
  return (
      <Collapse items={items} />
    )
}

export default App

Modo Ghost

Fondo transparente para apariencia mínima.

Ghost mode removes the background color.
Great for minimalist designs.
import { Collapse } from 'asterui'

function App() {
  const items = [
    {
      key: '1',
      label: 'Transparent Background',
      children: 'Ghost mode removes the background color.',
    },
    {
      key: '2',
      label: 'Clean Look',
      children: 'Great for minimalist designs.',
    },
  ]
  
  return (
      <Collapse items={items} ghost bordered={false} />
    )
}

export default App

Icono Plus/Minus

Usa iconos de más/menos en lugar de flechas.

This panel uses plus/minus icons instead of arrows.
Click the plus icon to expand.
import { Collapse } from 'asterui'

function App() {
  const items = [
    {
      key: '1',
      label: 'Plus/Minus Icon',
      children: 'This panel uses plus/minus icons instead of arrows.',
    },
    {
      key: '2',
      label: 'Another Panel',
      children: 'Click the plus icon to expand.',
    },
  ]
  
  return (
      <Collapse items={items} icon="plus" />
    )
}

export default App
PropiedadDescripciónTipoPredeterminado
itemsElementos de panel de collapseCollapseItemType[]-
activeKeyClaves de panel activo controladasstring | number | (string | number)[]-
defaultActiveKeyClaves de panel activo inicialesstring | number | (string | number)[]-
accordionSolo un panel abierto a la vezbooleanfalse
borderedMostrar borde alrededor de los panelesbooleantrue
ghostEstilo de fondo transparentebooleanfalse
sizeVariante de tamaño'sm' | 'md' | 'lg''md'
iconTipo de icono para indicador de expandir'arrow' | 'plus' | 'none''arrow'
expandIconPlacementUbicación del icono'start' | 'end''start'
onChangeManejador de cambio(activeKey: (string | number)[]) => void-
data-testidID de prueba para el componentestring'collapse'
classNameClases CSS adicionalesstring-
PropiedadDescripciónTipoPredeterminado
keyIdentificador único para el panelstring | number-
labelContenido del encabezado del panelReact.ReactNode-
childrenContenido del cuerpo del panelReact.ReactNode-
extraElemento extra en la esquina del encabezadoReact.ReactNode-
showArrowSi mostrar el icono de expandirbooleantrue
collapsibleModo plegable'header' | 'icon' | 'disabled'-
classNameNombre de clase personalizado para este panelstring-
  • Los encabezados de panel son accesibles por teclado con Enter y Espacio
  • Usa aria-expanded para indicar el estado del panel
  • Usa aria-disabled para paneles deshabilitados
  • Los paneles exponen data-state para testing y estilizado