Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(components): add disclosure component #86

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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";
Loading