-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
10 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import RichText from "./RichText"; | ||
import { z } from "zod"; | ||
|
||
export const DetailsSummarySchema = z.object({ | ||
identifier: z.string().optional(), | ||
title: z.string().optional(), | ||
content: z.string().optional(), | ||
}); | ||
|
||
type DetailsSummaryProps = z.infer<typeof DetailsSummarySchema>; | ||
|
||
export const DetailsSummary = ({ title, content }: DetailsSummaryProps) => { | ||
return ( | ||
<details className="details focus-within:outline focus-within:outline-4 focus-within:outline-offset-4 focus-within:outline-blue-800 text-blue-800 ds-label-01-bold"> | ||
<summary className="summary-content focus:outline-none cursor-pointer"> | ||
{title} | ||
</summary> | ||
<p className="block ds-label-01-reg ml-[0.325rem] border-l-2 border-solid border-grey-300 pl-12 pt-8 text-black"> | ||
{content && <RichText markdown={content} />} | ||
</p> | ||
</details> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { z } from "zod"; | ||
import { HasOptionalStrapiIdSchema } from "../models/HasStrapiId"; | ||
import { OptionalStrapiLinkIdentifierSchema } from "../models/HasStrapiLinkIdentifier"; | ||
import { DetailsSummary } from "~/components/DetailsSummary"; | ||
import { omitNull } from "~/util/omitNull"; | ||
|
||
export const StrapiDetailsSummarySchema = z | ||
.object({ | ||
title: z.string().nullable(), | ||
content: z.string().nullable(), | ||
}) | ||
.merge(HasOptionalStrapiIdSchema) | ||
.merge(OptionalStrapiLinkIdentifierSchema); | ||
|
||
type StrapiDetailsSummary = z.infer<typeof StrapiDetailsSummarySchema>; | ||
|
||
export const StrapiDetailsSummaryComponentSchema = | ||
StrapiDetailsSummarySchema.extend({ | ||
__component: z.literal("page.details-summary"), | ||
}); | ||
|
||
export const StrapiDetailsSummary = ( | ||
strapiDetailsSummary: StrapiDetailsSummary, | ||
) => { | ||
const props = omitNull(strapiDetailsSummary); | ||
return <DetailsSummary {...props} />; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { DetailsSummary } from "../app/components/DetailsSummary"; | ||
import { remixContext } from "../.storybook/remixContext"; | ||
import Container from "~/components/Container"; | ||
|
||
const meta = { | ||
title: "Component/DetailsSummary", | ||
component: DetailsSummary, | ||
parameters: { | ||
layout: "centered", | ||
}, | ||
tags: ["autodocs"], | ||
} satisfies Meta<typeof DetailsSummary>; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
title: "Lorem ipsum dolor sit amet?", | ||
content: | ||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.", | ||
}, | ||
decorators: [ | ||
(Story) => ( | ||
<Container paddingTop="24" paddingBottom="64"> | ||
{remixContext(Story)} | ||
</Container> | ||
), | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { render, screen, fireEvent } from "@testing-library/react"; | ||
import { DetailsSummary } from "~/components/DetailsSummary"; | ||
|
||
describe("DetailsSummary", () => { | ||
it("renders title and content correctly", () => { | ||
render(<DetailsSummary title="Test Title" content="Test Content" />); | ||
expect(screen.getByText("Test Title")).toBeInTheDocument(); | ||
expect(screen.getByText("Test Content")).toBeInTheDocument(); | ||
}); | ||
|
||
it("renders RichText with correct markdown", () => { | ||
render(<DetailsSummary title="Test Title" content="**Test Markdown**" />); | ||
expect(screen.getByText("Test Markdown")).toBeInTheDocument(); | ||
}); | ||
|
||
it("toggles visibility of content on summary click", () => { | ||
render(<DetailsSummary title="Test Title" content="Test Content" />); | ||
const summaryElement = screen.getByText("Test Title"); | ||
fireEvent.click(summaryElement); | ||
expect(screen.getByText("Test Content")).toBeVisible(); | ||
fireEvent.click(summaryElement); | ||
expect(screen.getByText("Test Content")).not.toBeVisible(); | ||
}); | ||
}); |