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

docs: add stories for how PrismFormatted handles long lines #319

Merged
Merged
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
47 changes: 47 additions & 0 deletions src/prism-formatted/prism-formatted.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React from "react";
import { Meta, StoryObj } from "@storybook/react";

import { PrismFormatted } from "./prism-formatted";
Expand Down Expand Up @@ -68,4 +69,50 @@ export const WithLineNumbers: Story = {
},
};

export const WithLongLineOfCode: Story = {
args: {
text: `<pre><code class="language-html"><p>This story shows how PrismFormatted displays a long line of code. This line should not wrap to a new line, but instead, the overflow content is clipped and can be scrolled into view.</p></code></pre>`,
getCodeBlockAriaLabel: (codeName) => `${codeName} code example`,
},
parameters: {
docs: {
source: {
code: `<PrismFormatted
getCodeBlockAriaLabel={codeName => \`\${codeName} code example\`}
text={\`<pre><code class="language-html"><p>This story shows how PrismFormatted displays a long line of code. This line should not wrap to a new line, but instead, the overflow content is clipped and can be scrolled into view.</p></code></pre>\`}
/>`,
},
},
},
};

export const InsideDisclosureElement: Story = {
decorators: [
(Story) => (
<details>
<summary>Example code</summary>
<Story />
</details>
),
],
Comment on lines +90 to +97
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using the decorators option to render <PrismFormatted {...props} /> with extra stuff.

Ref: https://storybook.js.org/docs/writing-stories/decorators?renderer=react#wrap-stories-with-extra-markup

args: {
text: `<pre><code class="language-html"><p>This story shows how PrismFormatted displays a long line of code when it's rendered inside a disclosure element. This line should not wrap to a new line, but instead, the overflow content is clipped and can be scrolled into view.</p></code></pre>`,
getCodeBlockAriaLabel: (codeName) => `${codeName} code example`,
},
parameters: {
docs: {
source: {
code: `<details>
<summary>Example code</summary>

<PrismFormatted
getCodeBlockAriaLabel={codeName => \`\${codeName} code example\`}
text={\`<pre><code class="language-html"><p>This story shows how PrismFormatted displays a long line of code when it's rendered inside a disclosure element. This line should not wrap to a new line, but instead, the overflow content is clipped and can be scrolled into view.</p></code></pre>\`}
/>
</details>`,
},
},
},
};

export default story;