Kosmesis
Components

Collapsible

A single expand/collapse toggle, wrapping Morphos's Disclosure primitive.

Installation

npx kosmesis add collapsible
pnpm dlx kosmesis add collapsible
yarn dlx kosmesis add collapsible
bunx kosmesis add collapsible

Install the following dependencies:

npm install @morphos/layout
pnpm add @morphos/layout
yarn add @morphos/layout
bun add @morphos/layout

Copy and paste the following code into your project.

collapsible.tsx
import { Component } from "@praxisjs/decorators";import { Disclosure as MorphosCollapsible } from "@morphos/layout";/** * Extends (not wraps) Morphos's `Disclosure` so `new Collapsible()` still yields a real instance * with `.isOpen`/`.toggle()`. `CollapsibleTrigger`/`CollapsibleContent` add no default styling of * their own, so they're re-exported directly, renamed. */@Component()export class Collapsible extends MorphosCollapsible {}export {  DisclosureContent as CollapsibleContent,  DisclosureTrigger as CollapsibleTrigger,  type DisclosureContentProps as CollapsibleContentProps,  type DisclosureProps as CollapsibleProps,  type DisclosureTriggerProps as CollapsibleTriggerProps,} from "@morphos/layout";

Install the following dependencies:

npm install @morphos/layout @praxisjs/css
pnpm add @morphos/layout @praxisjs/css
yarn add @morphos/layout @praxisjs/css
bun add @morphos/layout @praxisjs/css

Copy and paste the following code into your project.

collapsible.tsx
import { Component } from "@praxisjs/decorators";import { Disclosure as MorphosCollapsible } from "@morphos/layout";/** * Extends (not wraps) Morphos's `Disclosure` so `new Collapsible()` still yields a real instance * with `.isOpen`/`.toggle()`. `CollapsibleTrigger`/`CollapsibleContent` add no default styling of * their own, so they're re-exported directly, renamed. No styling anywhere in this file, so it's * identical to the Tailwind version. */@Component()export class Collapsible extends MorphosCollapsible {}export {  DisclosureContent as CollapsibleContent,  DisclosureTrigger as CollapsibleTrigger,  type DisclosureContentProps as CollapsibleContentProps,  type DisclosureProps as CollapsibleProps,  type DisclosureTriggerProps as CollapsibleTriggerProps,} from "@morphos/layout";

Examples

Usage

import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible";

@Component()
class Notes extends StatefulComponent {
  @State() disclosure = new Collapsible();

  render() {
    return (
      <Collapsible class="w-96">
        <CollapsibleTrigger disclosure={this.disclosure}>Toggle notes</CollapsibleTrigger>
        <CollapsibleContent disclosure={this.disclosure}>
          <p>These are the hidden notes.</p>
        </CollapsibleContent>
      </Collapsible>
    );
  }
}

On this page