Skip to content

BxpCode — API Reference

Complete props reference for the BxpCode component.

Import

tsx
import { BxpCode } from "bxp-code";
import type { BxpCodeProps } from "bxp-code";
jsx
import { BxpCode } from "bxp-code";

Input Props

Provide one of these to supply the code content. Priority: code > file > url.

PropTypeDescription
codestringCode string to highlight
fileFileFile object from <input type="file"> or drag-drop
urlstringURL to fetch code from (must return plain text)

Display Props

PropTypeDefaultDescription
langstringAuto-detectLanguage for syntax highlighting. Auto-detected from fileName, file, or url if not provided
fileNamestringAuto-detectFile name shown in header. Auto-detected from file or url if not provided
theme"dark" | "light""dark"Color theme
showHeaderbooleantrueShow/hide the entire header bar
showFileNamebooleantrueShow/hide file name in header
showLangbooleantrueShow/hide language badge in header
showCopyButtonbooleantrueShow/hide copy-to-clipboard button
showLineNumbersbooleanfalseShow/hide line numbers

Sticky Header Props

PropTypeDefaultDescription
stickyHeaderbooleanfalsePin header on scroll. Uses overflow: clip internally for reliable behavior
stickyTopnumber0Offset from viewport top in pixels (useful for fixed navbars)

→ See Sticky Headers guide for details on the overflow: clip approach.

Color Props

PropTypeDefaultDescription
headerColorstringTheme defaultOverride header background color
backgroundColorstringTheme defaultOverride code area background color

→ See Themes guide for color presets and examples.

Other Props

PropTypeDescription
styleCSSPropertiesAdditional inline styles on the container
classNamestringAdditional CSS class on the container
onError(error: Error) => voidCallback for file/url loading failures

TypeScript Type

typescript
import type { CSSProperties } from "react";

type BxpCodeProps = {
  code?: string;
  file?: File;
  url?: string;
  lang?: string;
  fileName?: string;
  theme?: "dark" | "light";
  showHeader?: boolean;
  showFileName?: boolean;
  showLang?: boolean;
  showCopyButton?: boolean;
  showLineNumbers?: boolean;
  stickyHeader?: boolean;
  stickyTop?: number;
  headerColor?: string;
  backgroundColor?: string;
  style?: CSSProperties;
  className?: string;
  onError?: (error: Error) => void;
};

Usage Examples

Minimal

tsx
<BxpCode code={`print("hello")`} lang="python" />
tsx
<BxpCode
  code={code}
  lang="typescript"
  fileName="server.ts"
  theme="dark"
  showHeader
  showFileName
  showLang
  showCopyButton
  showLineNumbers
  stickyHeader
  stickyTop={64}
  headerColor="#161b22"
  backgroundColor="#0d1117"
  style={{ maxHeight: "500px", borderRadius: "12px" }}
  className="my-code-block"
  onError={(err) => console.error(err)}
/>

BxpCodeTabs API Reference

Released under the MIT License.