-
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.
docs: collapse code examples in a custom Example story block
1 parent
4aef722
commit efbd0af
Showing
4 changed files
with
67 additions
and
23 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,25 @@ | ||
import React, { PropsWithChildren } from "react"; | ||
import { Story, Description } from "@storybook/blocks"; | ||
import type { ModuleExport } from "@storybook/types"; | ||
import { StoryTitle } from "./StoryTitle"; | ||
|
||
export const Example = ({ | ||
of, | ||
children, | ||
}: PropsWithChildren<{ of: ModuleExport }>) => { | ||
return ( | ||
<> | ||
<StoryTitle of={of} /> | ||
<Description of={of} /> | ||
<article> | ||
<Story of={of} /> | ||
<footer> | ||
<details className="code-details"> | ||
<summary>Show code</summary> | ||
{children} | ||
</details> | ||
</footer> | ||
</article> | ||
</> | ||
); | ||
}; |
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,16 @@ | ||
import React from "react"; | ||
import { Title } from "@storybook/blocks"; | ||
import { useOf } from "@storybook/blocks"; | ||
import type { ModuleExport } from "@storybook/types"; | ||
|
||
export const StoryTitle = ({ of }: { of: ModuleExport }) => { | ||
const resolvedOf = useOf(of || "story", ["story", "meta"]); | ||
switch (resolvedOf.type) { | ||
case "story": { | ||
return <h3>{resolvedOf.story.name}</h3>; | ||
} | ||
case "meta": { | ||
return <h3>{resolvedOf.preparedMeta.title}</h3>; | ||
} | ||
} | ||
}; |
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