Skip to content

Commit

Permalink
Merge pull request #86 from abusix/ahq2-20-add-disclosure-design-to-h…
Browse files Browse the repository at this point in the history
…ailstorm

feat(components): add disclosure component
  • Loading branch information
mnlfischer authored Jan 11, 2024
2 parents c6e7f7e + 8689421 commit 7eae233
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/components/disclosure/disclosure.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import type { Meta, StoryObj } from "@storybook/react";
import React from "react";
import { Disclosure } from "./disclosure";

const meta: Meta<typeof Disclosure> = {
title: "Disclosure",
component: Disclosure,
parameters: {
options: {
showPanel: false,
},
},
};

export default meta;
type Story = StoryObj<typeof Disclosure>;

export const Default: Story = {
render: () => (
<div className="w-96">
<Disclosure>
<Disclosure.Button>Disclosure Button</Disclosure.Button>
<Disclosure.Panel>Disclosure Content</Disclosure.Panel>
</Disclosure>
</div>
),
};

export const Stacked: Story = {
render: () => (
<div className="w-96">
<Disclosure>
<Disclosure.Button>Disclosure Button</Disclosure.Button>
<Disclosure.Panel>Disclosure Content</Disclosure.Panel>
</Disclosure>
<Disclosure>
<Disclosure.Button>Disclosure Button</Disclosure.Button>
<Disclosure.Panel>Disclosure Content</Disclosure.Panel>
</Disclosure>
<Disclosure>
<Disclosure.Button>Disclosure Button</Disclosure.Button>
<Disclosure.Panel>Disclosure Content</Disclosure.Panel>
</Disclosure>
</div>
),
};
43 changes: 43 additions & 0 deletions src/components/disclosure/disclosure.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React from "react";
import { Disclosure as HeadlessUiDisclosure } from "@headlessui/react";
import { ChevronDownIcon } from "../../icons";
import { classNames } from "../../util/class-names";

interface DisclosurePanelProps extends React.ComponentPropsWithoutRef<"div"> {
children: React.ReactNode;
}

const DisclosurePanel = ({ children, ...props }: DisclosurePanelProps) => {
return <HeadlessUiDisclosure.Panel {...props}>{children}</HeadlessUiDisclosure.Panel>;
};

interface DisclosureButtonProps extends React.ComponentPropsWithoutRef<"button"> {
children: React.ReactNode;
}

const DisclosureButton = ({ children, ...props }: DisclosureButtonProps) => {
return (
<HeadlessUiDisclosure.Button
className="headline-300 flex h-10 w-full items-center justify-between border-b border-neutral-300 bg-neutral-50 py-1 pl-3 pr-5 text-left text-neutral-900"
{...props}
>
{({ open }) => (
<>
{children}
<ChevronDownIcon
className={classNames("h-3 w-3", open && "rotate-180 transform")}
/>
</>
)}
</HeadlessUiDisclosure.Button>
);
};

const Disclosure = ({ children }: { children: React.ReactNode }) => {
return <HeadlessUiDisclosure>{children}</HeadlessUiDisclosure>;
};

Disclosure.Button = DisclosureButton;
Disclosure.Panel = DisclosurePanel;

export { Disclosure };
1 change: 1 addition & 0 deletions src/components/disclosure/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Disclosure } from "./disclosure";
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ export { Toast } from "./toast";
export { Toggle } from "./toggle";
export { Tooltip } from "./tooltip";
export { TopBar } from "./top-bar";
export { Disclosure } from "./disclosure";

0 comments on commit 7eae233

Please sign in to comment.