@molecule/app-code-block-solid

Feature · code-block · App (browser) · v1.2.0 · Apache-2.0

Solid CodeBlock with language label, line numbers, copy-to-clipboard

npm install @molecule/app-code-block-solid

npm · Source on GitHub

How it works

@molecule/app-code-block-solid is a ready-made code-block feature for the app (browser) side. It composes the core interfaces it needs, so it works with whichever providers your app has bonded.

import { CodeBlock } from '@molecule/app-code-block-solid'

const code = 'const greet = (name: string) => `Hello, ${name}!`'

export function Demo() {
  return <CodeBlock code={code} language="ts" filename="greet.ts" showLineNumbers />
}

Works with: @molecule/app-clipboard, @molecule/app-solid, @molecule/app-ui, @molecule/app-ui-solid

Reference

Solid code block display — the counterpart of @molecule/app-code-block-react: the same props (React names) and the same DOM for the same input.

Exports <CodeBlock> — read-only code panel with optional filename + language header, line numbers, and copy-to-clipboard button.

Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit src/index.ts JSDoc, not this file.

Quick Start

import { CodeBlock } from '@molecule/app-code-block-solid'

const code = 'const greet = (name: string) => `Hello, ${name}!`'

export function Demo() {
  return <CodeBlock code={code} language="ts" filename="greet.ts" showLineNumbers />
}

Type

feature

Installation

npm install @molecule/app-code-block-solid @molecule/app-clipboard @molecule/app-solid @molecule/app-ui @molecule/app-ui-solid solid-js

API

Interfaces

CodeBlockProps

Props for CodeBlock.

interface CodeBlockProps {
  /** Source code to display. */
  code: string
  /** Language tag (`"ts"`, `"bash"`, …). Shown in the header and used as a hint by external highlighters. */
  language?: string
  /** Show line numbers. Defaults to true. */
  showLineNumbers?: boolean
  /** Show a copy-to-clipboard button. Defaults to true. */
  showCopy?: boolean
  /** Optional custom filename / caption shown left of the language. */
  filename?: string
  /** Extra classes. */
  className?: string
}

Functions

CodeBlock(props)

Read-only code block with an optional header (filename + language tag), optional line numbers, and a copy-to-clipboard button.

Does NOT perform syntax highlighting, and code is always rendered as escaped plain text — passing pre-highlighted HTML displays literal tags. To highlight, wrap or replace this component with your highlighter's (e.g. prismjs, shiki) own renderer. The component keeps the no-hidden-dependency contract typical of @molecule/* features.

This is the Solid counterpart of @molecule/app-code-block-react: the same props (React names), the same ClassMap tokens, and the same DOM for the same input.

function CodeBlock(props: CodeBlockProps): JSX.Element
  • props — Component props (see CodeBlockProps).

Returns: The rendered code block.

Injection Notes

Requirements

Peer dependencies:

  • @molecule/app-clipboard ^1.0.1
  • @molecule/app-solid ^3.5.0
  • @molecule/app-ui ^1.0.1
  • @molecule/app-ui-solid ^1.1.0
  • solid-js ^1.8.0

Runtime Dependencies

  • @molecule/app-clipboard
  • @molecule/app-solid
  • @molecule/app-ui
  • @molecule/app-ui-solid
  • solid-js

code is rendered as PLAIN TEXT — there is no syntax highlighting and no HTML parsing, so do not pass pre-highlighted HTML (it will display as literal tags). To highlight, wrap or replace this component with one that renders your highlighter's output; language is only a header label. The copy button copies through @molecule/app-clipboard (copyTextWithFallback — the bonded clipboard provider first, then a legacy copy fallback — which resolves false instead of throwing), so it works on insecure (non-HTTPS) contexts too; the copied feedback shows only when the copy succeeded. Copy/Copied labels are translated via the codeBlock.* keys (companion bond: @molecule/app-locales-code-block), read through the binding's useTranslation() so a locale switch re-renders them.

Translations

Translation strings are provided by @molecule/app-locales-code-block.