Displays a code block with an optional header and output area.
<CodeBlock.Root> <CodeBlock.Content>helloWorld();</CodeBlock.Content> </CodeBlock.Root>
Import the component and piece the parts together.
import { CodeBlock } from '@workos-inc/design-system'; export default () => ( <CodeBlock.Root> <CodeBlock.Output /> <CodeBlock.Header /> <CodeBlock.Content> <CodeBlock.LineGroup> <CodeBlock.Line /> </CodeBlock.LineGroup> </CodeBlock.Content> </CodeBlock.Root> );
heightstring | numbermaxHeightstring | numberwrapguttercolorUse the Output part to display the result of running the Code Block code.
<CodeBlock.Root> <CodeBlock.Output> <Box p="5"> <Code variant="ghost">I love Bash</Code> </Box> </CodeBlock.Output> <CodeBlock.Content> <CodeBlock.LineGroup gutter="cli"> <CodeBlock.Line> <span className="token builtin class-name">echo</span> <span className="token"> </span> <span className="token string">"I love Bash"</span> </CodeBlock.Line> </CodeBlock.LineGroup> </CodeBlock.Content> </CodeBlock.Root>
Use the Header part to display related information, like the Code Block title and language.
<CodeBlock.Root> <CodeBlock.Header> <Text size="2" weight="bold"> Install the WorkOS SDK </Text> <Text color="gray" size="1"> Bash </Text> </CodeBlock.Header> <CodeBlock.Content> <CodeBlock.LineGroup gutter="cli"> <CodeBlock.Line> <span className="token function">npm</span> <span className="token"> </span> <span className="token function">install</span> <span className="token"> </span> <span className="token">@workos-inc/node</span> </CodeBlock.Line> </CodeBlock.LineGroup> </CodeBlock.Content> </CodeBlock.Root>
The Code Block design can accommodate Tabs in the header.
<Tabs.Root defaultValue="npm"> <CodeBlock.Root> <CodeBlock.Header> <Tabs.List> <Tabs.Trigger value="npm">npm</Tabs.Trigger> <Tabs.Trigger value="yarn">Yarn</Tabs.Trigger> </Tabs.List> <Text color="gray" size="1"> Bash </Text> </CodeBlock.Header> <CodeBlock.Content> <Tabs.Content value="npm"> <CodeBlock.LineGroup gutter="cli"> <CodeBlock.Line> <span className="token function">npm</span> <span className="token"> </span> <span className="token function">install</span> @ <span className="token">workos</span>- <span className="token">inc</span>/ <span className="token">node</span> </CodeBlock.Line> </CodeBlock.LineGroup> </Tabs.Content> <Tabs.Content value="yarn"> <CodeBlock.LineGroup gutter="cli"> <CodeBlock.Line> <span className="token function">yarn</span> @ <span className="token">workos</span>- <span className="token">inc</span>/ <span className="token">node</span> </CodeBlock.Line> </CodeBlock.LineGroup> </Tabs.Content> </CodeBlock.Content> </CodeBlock.Root> </Tabs.Root>
Use gutter="cli" to display gutters that indicate a command line interface. The second and subsequent lines will indicate a multi-line input.
<CodeBlock.Root> <CodeBlock.Content> <CodeBlock.LineGroup gutter="cli"> <CodeBlock.Line> <span className="token function">curl</span> <span> </span> <span className="token">https</span>:// <span className="token">api</span>.<span className="token">workos</span> .<span className="token">com</span>/ <span className="token">connections</span> <span> </span> <span className="token punctuation">\</span> </CodeBlock.Line> <CodeBlock.Line> <span>{' '}--</span> <span className="token">header</span> <span> </span> <span className="token string"> "Authorization: Bearer sk_example_123456789 " </span> </CodeBlock.Line> </CodeBlock.LineGroup> </CodeBlock.Content> </CodeBlock.Root>
Use gutter="numbers" to display automatic line numbers in the gutters.
<CodeBlock.Root> <CodeBlock.Content> <CodeBlock.LineGroup gutter="numbers"> <CodeBlock.Line> <span className="token keyword">const</span> <span> </span> <span className="token">organizationDomain</span> <span> </span> <span className="token operator">=</span> <span> </span> <span className="token punctuation">{'{'}</span> </CodeBlock.Line> <CodeBlock.Line> <span>{' '}</span> <span className="token literal-property property">object</span> <span className="token operator">:</span> <span> </span> <span className="token string">'organization_domain'</span> <span className="token punctuation">,</span> </CodeBlock.Line> <CodeBlock.Line> <span>{' '}</span> <span className="token literal-property property">id</span> <span className="token operator">:</span> <span> </span> <span className="token string">'org_01EHZNVPK3SFK441A1RGBFSVCT'</span> <span className="token punctuation">,</span> </CodeBlock.Line> <CodeBlock.Line> <span>{' '}</span> <span className="token literal-property property">domain</span> <span className="token operator">:</span> <span> </span> <span className="token string">'foo-corp.com'</span> <span className="token punctuation">,</span> </CodeBlock.Line> <CodeBlock.Line> <span className="token punctuation">{'}'}</span> <span className="token punctuation">;</span> </CodeBlock.Line> </CodeBlock.LineGroup> </CodeBlock.Content> </CodeBlock.Root>
Use the color prop to highlight a code line.
<CodeBlock.Root> <CodeBlock.Content> <CodeBlock.LineGroup gutter="numbers"> <CodeBlock.Line> <span className="token keyword">const</span> <span className="token"> </span> <span className="token">payload</span> <span className="token"> </span> <span className="token operator">=</span> <span className="token"> </span> <span className="token">req</span> <span className="token punctuation">.</span> <span className="token property-access">body</span> <span className="token punctuation">;</span> </CodeBlock.Line> <CodeBlock.Line color="yellow"> <span className="token keyword">const</span> <span className="token"> </span> <span className="token">sigHeader</span> <span className="token"> </span> <span className="token operator">=</span> <span className="token"> </span> <span className="token">req</span> <span className="token punctuation">.</span> <span className="token property-access">headers</span> <span className="token punctuation">[</span> <span className="token string">'workos-signature'</span> <span className="token punctuation">]</span> <span className="token punctuation">;</span> </CodeBlock.Line> <CodeBlock.Line></CodeBlock.Line> <CodeBlock.Line> <span className="token comment"> // Verify the signature and process the event </span> </CodeBlock.Line> <CodeBlock.Line> <span className="token">res</span> <span className="token punctuation">.</span> <span className="token method function property-access">status</span> <span className="token punctuation">(</span> <span className="token number">200</span> <span className="token punctuation">)</span> <span className="token punctuation">;</span> </CodeBlock.Line> </CodeBlock.LineGroup> </CodeBlock.Content> </CodeBlock.Root>
Use the blue highlight when you need a more subtle call-out in the code block.
<CodeBlock.Root> <CodeBlock.Content> <CodeBlock.LineGroup gutter="numbers"> <CodeBlock.Line> <span className="token keyword">const</span> <span className="token"> </span> <span className="token">payload</span> <span className="token"> </span> <span className="token operator">=</span> <span className="token"> </span> <span className="token">req</span> <span className="token punctuation">.</span> <span className="token property-access">body</span> <span className="token punctuation">;</span> </CodeBlock.Line> <CodeBlock.Line color="blue"> <span className="token keyword">const</span> <span className="token"> </span> <span className="token">sigHeader</span> <span className="token"> </span> <span className="token operator">=</span> <span className="token"> </span> <span className="token">req</span> <span className="token punctuation">.</span> <span className="token property-access">headers</span> <span className="token punctuation">[</span> <span className="token string">'workos-signature'</span> <span className="token punctuation">]</span> <span className="token punctuation">;</span> </CodeBlock.Line> <CodeBlock.Line></CodeBlock.Line> <CodeBlock.Line> <span className="token comment"> // Verify the signature and process the event </span> </CodeBlock.Line> <CodeBlock.Line> <span className="token">res</span> <span className="token punctuation">.</span> <span className="token method function property-access">status</span> <span className="token punctuation">(</span> <span className="token number">200</span> <span className="token punctuation">)</span> <span className="token punctuation">;</span> </CodeBlock.Line> </CodeBlock.LineGroup> </CodeBlock.Content> </CodeBlock.Root>
Green and red highlight colors automatically display plus and minus symbols in the gutter, indicating added and removed lines.
<CodeBlock.Root> <CodeBlock.Content> <CodeBlock.LineGroup gutter="numbers"> <CodeBlock.Line> <span className="token keyword">const</span> <span className="token"> </span> <span className="token">payload</span> <span className="token"> </span> <span className="token operator">=</span> <span className="token"> </span> <span className="token">req</span> <span className="token punctuation">.</span> <span className="token property-access">body</span> <span className="token punctuation">;</span> </CodeBlock.Line> <CodeBlock.Line color="red"> <span className="token keyword">const</span> <span className="token"> </span> <span className="token">sigHeader</span> <span className="token"> </span> <span className="token operator">=</span> <span className="token"> </span> <span className="token">req</span> <span className="token punctuation">.</span> <span className="token property-access">headers</span> <span className="token punctuation">[</span> <span className="token string">'signature'</span> <span className="token punctuation">]</span> <span className="token punctuation">;</span> </CodeBlock.Line> <CodeBlock.Line color="green"> <span className="token keyword">const</span> <span className="token"> </span> <span className="token">sigHeader</span> <span className="token"> </span> <span className="token operator">=</span> <span className="token"> </span> <span className="token">req</span> <span className="token punctuation">.</span> <span className="token property-access">headers</span> <span className="token punctuation">[</span> <span className="token string">'workos-signature'</span> <span className="token punctuation">]</span> <span className="token punctuation">;</span> </CodeBlock.Line> <CodeBlock.Line></CodeBlock.Line> <CodeBlock.Line> <span className="token comment"> // Verify the signature and process the event </span> </CodeBlock.Line> <CodeBlock.Line> <span className="token">res</span> <span className="token punctuation">.</span> <span className="token method function property-access">status</span> <span className="token punctuation">(</span> <span className="token number">200</span> <span className="token punctuation">)</span> <span className="token punctuation">;</span> </CodeBlock.Line> </CodeBlock.LineGroup> </CodeBlock.Content> </CodeBlock.Root>
Use the maxHeight prop to limit the height of long code blocks and enable scrolling.
<CodeBlock.Root> <CodeBlock.Content maxHeight="180px"> <CodeBlock.LineGroup gutter="numbers"> <CodeBlock.Line> <span className="token keyword">const</span> <span className="token"> </span> <span className="token">longCodeExample</span> <span className="token"> </span> <span className="token operator">=</span> <span className="token"> </span> <span className="token punctuation">{'{'}</span> </CodeBlock.Line> <CodeBlock.Line> <span>{' '}</span> <span className="token literal-property property">method1</span> <span className="token operator">:</span> <span className="token"> </span> <span className="token string">'This is a long method'</span> <span className="token punctuation">,</span> </CodeBlock.Line> <CodeBlock.Line> <span>{' '}</span> <span className="token literal-property property">method2</span> <span className="token operator">:</span> <span className="token"> </span> <span className="token string">'Another long method'</span> <span className="token punctuation">,</span> </CodeBlock.Line> <CodeBlock.Line> <span>{' '}</span> <span className="token literal-property property">method3</span> <span className="token operator">:</span> <span className="token"> </span> <span className="token string">'Yet another method'</span> <span className="token punctuation">,</span> </CodeBlock.Line> <CodeBlock.Line> <span>{' '}</span> <span className="token literal-property property">method4</span> <span className="token operator">:</span> <span className="token"> </span> <span className="token string">'More content here'</span> <span className="token punctuation">,</span> </CodeBlock.Line> <CodeBlock.Line> <span>{' '}</span> <span className="token literal-property property">method5</span> <span className="token operator">:</span> <span className="token"> </span> <span className="token string">'Even more content'</span> <span className="token punctuation">,</span> </CodeBlock.Line> <CodeBlock.Line> <span>{' '}</span> <span className="token literal-property property">method6</span> <span className="token operator">:</span> <span className="token"> </span> <span className="token string">'This will cause scrolling'</span> <span className="token punctuation">,</span> </CodeBlock.Line> <CodeBlock.Line> <span>{' '}</span> <span className="token literal-property property">method7</span> <span className="token operator">:</span> <span className="token"> </span> <span className="token string">'More scrollable content'</span> <span className="token punctuation">,</span> </CodeBlock.Line> <CodeBlock.Line> <span>{' '}</span> <span className="token literal-property property">method8</span> <span className="token operator">:</span> <span className="token"> </span> <span className="token string">'Another line to ensure overflow'</span> <span className="token punctuation">,</span> </CodeBlock.Line> <CodeBlock.Line> <span>{' '}</span> <span className="token literal-property property">method9</span> <span className="token operator">:</span> <span className="token"> </span> <span className="token string">'Even more scrollable content'</span> <span className="token punctuation">,</span> </CodeBlock.Line> <CodeBlock.Line> <span>{' '}</span> <span className="token literal-property property">method10</span> <span className="token operator">:</span> <span className="token"> </span> <span className="token string">'Another method'</span> <span className="token punctuation">,</span> </CodeBlock.Line> <CodeBlock.Line> <span>{' '}</span> <span className="token literal-property property">method11</span> <span className="token operator">:</span> <span className="token"> </span> <span className="token string">'Even more content'</span> <span className="token punctuation">,</span> </CodeBlock.Line> <CodeBlock.Line> <span>{' '}</span> <span className="token literal-property property">method12</span> <span className="token operator">:</span> <span className="token"> </span> <span className="token string">'More scrollable content'</span> <span className="token punctuation">,</span> </CodeBlock.Line> <CodeBlock.Line> <span>{' '}</span> <span className="token literal-property property">method13</span> <span className="token operator">:</span> <span className="token"> </span> <span className="token string"> 'This should definitely cause overflow' </span> <span className="token punctuation">,</span> </CodeBlock.Line> <CodeBlock.Line> <span>{' '}</span> <span className="token literal-property property">method14</span> <span className="token operator">:</span> <span className="token"> </span> <span className="token string">'Final method'</span> </CodeBlock.Line> <CodeBlock.Line> <span className="token punctuation">{'}'}</span> <span className="token punctuation">;</span> </CodeBlock.Line> </CodeBlock.LineGroup> </CodeBlock.Content> </CodeBlock.Root>
Use the height prop to set a fixed height for code blocks.
<CodeBlock.Root> <CodeBlock.Content height="120px"> <CodeBlock.LineGroup gutter="numbers"> <CodeBlock.Line> <span className="token keyword">const</span> <span className="token"> </span> <span className="token">fixedHeightExample</span> <span className="token"> </span> <span className="token operator">=</span> <span className="token"> </span> <span className="token punctuation">{'{'}</span> </CodeBlock.Line> <CodeBlock.Line> <span>{' '}</span> <span className="token literal-property property">name</span> <span className="token operator">:</span> <span className="token"> </span> <span className="token string">'Fixed height code block'</span> <span className="token punctuation">,</span> </CodeBlock.Line> <CodeBlock.Line> <span>{' '}</span> <span className="token literal-property property">description</span> <span className="token operator">:</span> <span className="token"> </span> <span className="token string">'This block has a fixed height'</span> </CodeBlock.Line> <CodeBlock.Line> <span className="token punctuation">{'}'}</span> <span className="token punctuation">;</span> </CodeBlock.Line> </CodeBlock.LineGroup> </CodeBlock.Content> </CodeBlock.Root>
2 variants found
/p/:portalSessionId/log-streams/:logStreamId/s3
/p/:portalSessionId/log-streams/:logStreamId/s3
| Prop | Type | Default | Required |
|---|---|---|---|
height | string | number | — | no |
maxHeight | string | number | — | no |
wrap | "pre" | "pre-wrap" | — | no |
| Prop | Type | Default | Required |
|---|---|---|---|
gutter | "none" | "numbers" | "cli" | — | no |
| Prop | Type | Default | Required |
|---|---|---|---|
color | "yellow" | "red" | "blue" | "green" | "focused" | — | no |
Used 40 times across 2 packages
wrap
11 files
/code-editor
/p/:portalSessionId/log-streams/:logStreamId/generic-https
/p/:portalSessionId/log-streams/:logStreamId/s3
Show 1 more files