Skip to content

Commit

Permalink
Add a Disclosure component
Browse files Browse the repository at this point in the history
  • Loading branch information
jviide committed Sep 14, 2024
1 parent beeb0fb commit 454727e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/nasty-apricots-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@badrap/libapp": patch
---

Add a Disclosure component
37 changes: 37 additions & 0 deletions src/ui/experimental/Disclosure.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { UiNode, element, Responsive } from "../internal.js";

interface DisclosureProps {
/**
* Controls component size, including the text size of the label and content.
* Default value: "md".
* */
size?: Responsive<"xs" | "sm" | "md" | "lg">;
/**
* The disclosure label. Gives a summary, caption, or legend for the details.
* Usually just text, but can contain arbitrary formatting content.
* */
label: UiNode;
/**
* The content to be displayed as details when the disclosure component
* has been expanded.
* */
children: UiNode;
}

/**
* A component with a summary label and additional detailed content.
* The details can be collapsed (hidden) or expanded (shown again)
* by interacting with the label.
*
* @example
* ```tsx
* <Disclosure label="Show lorem ipsum">
* Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
* eiusmod tempor incididunt ut labore et dolore magna aliqua.
* </Disclosure>
* ```
* */
export function Disclosure(props: DisclosureProps): UiNode {
const { children, ...rest } = props;
return element("ui-disclosure", { content: children, ...rest });
}

0 comments on commit 454727e

Please sign in to comment.