Code

Inline code for running text, and CodeBlock for snippets with a file name and a copy button.

Status: beta. Category: Typography.

import { Code, CodeBlock } from '@glyphui/ui'

Exports: Code, CodeBlock, codeStyles, codeBlockStyles.

Notes

  • CodeBlock does not highlight syntax, so it adds no dependency. Bring your own highlighter if you need one.
  • If the clipboard is blocked, the copy button does nothing and the code stays selectable.

Example: Inline

import { Code, Text } from '@glyphui/ui'

export default function Example() {
  return (
    <Text>
      Run <Code>pnpm dev</Code> to start the docs, then edit <Code>glyph.theme.ts</Code>.
    </Text>
  )
}

Example: Code block

import { CodeBlock } from '@glyphui/ui'

const code = `import { defineTheme, presets } from '@glyphui/ui'

export default defineTheme({
  name: 'acme',
  extends: presets.glyph,
  radius: { md: '6px' },
})`

export default function Example() {
  return (
    <div className="grid gap-4">
      <CodeBlock title="glyph.theme.ts" code={code} />
      <CodeBlock code="pnpm add @glyphui/ui" />
    </div>
  )
}

Live page: https://glyphui.xyz/components/code