diff --git a/src/components/Collapse/Collapse.css b/src/components/Collapse/Collapse.css new file mode 100644 index 0000000..851851c --- /dev/null +++ b/src/components/Collapse/Collapse.css @@ -0,0 +1,30 @@ +.collapse { + width: 100%; +} + +.collapse-summary { + color: var(--codex-color-primary); + font-weight: 600; + cursor: pointer; + display: flex; + align-items: center; + gap: 0.5rem; +} + +.collapse-summary:hover { + text-decoration: underline; + opacity: 0.7; + text-decoration-thickness: 2px; +} + +.collapse-details { + max-height: 0; + transition: max-height 0.2s; + overflow: hidden; + word-break: break-word; + color: var(--codex-color); +} + +.collapse-details[aria-expanded] { + max-height: 50px; +} diff --git a/src/components/Collapse/Collapse.tsx b/src/components/Collapse/Collapse.tsx new file mode 100644 index 0000000..e3cd96f --- /dev/null +++ b/src/components/Collapse/Collapse.tsx @@ -0,0 +1,46 @@ +import { useState } from "react"; +import "./Collapse.css"; +import { attributes } from "../utils/attributes"; + +type Props = { + summary: string; + details: string; + className?: string; +}; + +export function Collapse({ summary, details, className = "" }: Props) { + const [expanded, setExpanded] = useState(false); + + const onClick = () => setExpanded(!expanded); + + return ( +
+ + {summary} + + +
+ {details} +
+
+ ); +} + +const ArrowRight = () => ( + + + +); diff --git a/stories/Collapse.stories.css b/stories/Collapse.stories.css new file mode 100644 index 0000000..d4c11bd --- /dev/null +++ b/stories/Collapse.stories.css @@ -0,0 +1,3 @@ +.collapse-demo { + min-width: 250px; +} diff --git a/stories/Collapse.stories.tsx b/stories/Collapse.stories.tsx new file mode 100644 index 0000000..a2cd9e9 --- /dev/null +++ b/stories/Collapse.stories.tsx @@ -0,0 +1,24 @@ +import type { Meta, StoryObj } from "@storybook/react"; +import { Collapse } from "../src/components/Collapse/Collapse"; +import "./Collapse.stories.css"; + +const meta = { + title: "Components/Collapse", + component: Collapse, + parameters: { + layout: "centered", + }, + tags: ["autodocs"], + argTypes: {}, +} satisfies Meta; + +export default meta; +type Story = StoryObj; + +export const Default: Story = { + args: { + summary: "Read more", + details: "More details for collapse component", + className: "collapse-demo", + }, +};