diff --git a/.changeset/fast-glasses-grow.md b/.changeset/fast-glasses-grow.md new file mode 100644 index 0000000000..bf6da0e6f3 --- /dev/null +++ b/.changeset/fast-glasses-grow.md @@ -0,0 +1,5 @@ +--- +"@medusajs/ui": patch +--- + +fix(ui): Fix the width of line numbers in the CodeBlock component, such that they are always the same width as the widest line number. diff --git a/packages/design-system/ui/src/components/code-block/code-block.stories.tsx b/packages/design-system/ui/src/components/code-block/code-block.stories.tsx index a981f9798a..17ad7cd35c 100644 --- a/packages/design-system/ui/src/components/code-block/code-block.stories.tsx +++ b/packages/design-system/ui/src/components/code-block/code-block.stories.tsx @@ -1,8 +1,8 @@ -import React from "react" import type { Meta, StoryObj } from "@storybook/react" +import React from "react" -import { CodeBlock } from "./code-block" import { Label } from "../label" +import { CodeBlock } from "./code-block" const meta: Meta = { title: "Components/CodeBlock", @@ -50,3 +50,36 @@ export const Default: Story = { ) }, } + +const code = `medusa develop +✔ Models initialized – 14ms +✔ Repositories initialized – 35ms +✔ Strategies initialized – 24ms +✔ Modules initialized – 1ms +✔ Database initialized – 654ms +✔ Services initialized – 7ms +✔ Express intialized – 5ms +✔ Plugins intialized – 7ms +✔ Subscribers initialized – 6ms +✔ API initialized – 28ms +✔ Server is ready on port: 9000` + +export const ManyLines: Story = { + render: () => { + return ( + + + + ) + }, +} diff --git a/packages/design-system/ui/src/components/code-block/code-block.tsx b/packages/design-system/ui/src/components/code-block/code-block.tsx index a7f716a85f..b617159822 100644 --- a/packages/design-system/ui/src/components/code-block/code-block.tsx +++ b/packages/design-system/ui/src/components/code-block/code-block.tsx @@ -10,6 +10,7 @@ export type CodeSnippet = { language: string code: string hideLineNumbers?: boolean + hideCopy?: boolean } type CodeBlockState = { @@ -47,7 +48,7 @@ const Root = ({
- + {!active.hideCopy && ( + + )}
{({ style, tokens, getLineProps, getTokenProps }) => (
-              {tokens.map((line, i) => (
-                
- {!active.hideLineNumbers && ( - {i + 1} - )} -
+ {!active.hideLineNumbers && ( +
+ {tokens.map((_, i) => ( + + {i + 1} + + ))} +
+ )} +
+ {tokens.map((line, i) => ( +
{line.map((token, key) => ( ))}
-
- ))} + ))} +
)}
diff --git a/www/apps/ui/src/props/code-block.tsx b/www/apps/ui/src/props/code-block.tsx index 090216e5f8..abbc7681c5 100644 --- a/www/apps/ui/src/props/code-block.tsx +++ b/www/apps/ui/src/props/code-block.tsx @@ -8,7 +8,7 @@ const codeBlockProps: PropDataMap = [ type: "object", name: "CodeSnippet[]", shape: - "{\n label: string\n language: string\n code: string\n hideLineNumbers?: boolean\n}[]", + "{\n label: string\n language: string\n code: string\n hideLineNumbers?: boolean\n hideCopy?: boolean\n}[]", }, }, ]