Skip to content

BxpCodeTabs — API Reference

Complete props reference for the BxpCodeTabs component and the BxpCodeTab type.

Import

tsx
import { BxpCodeTabs } from "bxp-code";
import type { BxpCodeTabsProps, BxpCodeTab } from "bxp-code";
jsx
import { BxpCodeTabs } from "bxp-code";

BxpCodeTab

Each item in the tabs array:

FieldTypeRequiredDescription
langstringYesLanguage identifier for highlighting (lowercased internally)
labelstringNoTab display label. Defaults to capitalized lang
codestringNoCode string (use this OR file/url)
fileFileNoFile object from <input type="file">
urlstringNoURL to fetch code from
fileNamestringNoDisplay name. Auto-detected from file/url if absent

Input Priority

Within each tab, priority is: code > file > url.

Component Props

Required

PropTypeDescription
tabsBxpCodeTab[]Array of tab configurations

Display Props

PropTypeDefaultDescription
theme"dark" | "light""dark"Color theme
showLineNumbersbooleanfalseShow/hide line numbers
showCopyButtonbooleantrueShow/hide copy-to-clipboard button (appears on hover)
showHeaderbooleantrueShow/hide the tab bar entirely. When hidden, the defaultTab content is displayed
defaultTabnumber0Initially active tab index (zero-based)

Sticky Header Props

PropTypeDefaultDescription
stickyHeaderbooleanfalsePin tab bar on scroll. Uses overflow: clip internally
stickyTopnumber0Sticky offset from top in pixels

→ See Sticky Headers guide for details.

Color Props

PropTypeDefaultDescription
headerColorstringTheme defaultTab bar background color
backgroundColorstringTheme defaultCode area background color
borderColorstringTheme defaultContainer & header border color
tabActiveColorstringTheme defaultActive tab background color
tabActiveTextColorstringTheme defaultActive tab text color
tabTextColorstringTheme defaultInactive tab text color
tabIndicatorColorstring#e06b74Active tab bottom indicator color
copyButtonColorstringTheme defaultCopy button background color
lineNumberColorstringTheme defaultLine number gutter text color

→ See Themes guide and Customization guide for presets.

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 Types

typescript
import type { CSSProperties } from "react";

type BxpCodeTab = {
  lang: string;
  label?: string;
  code?: string;
  file?: File;
  url?: string;
  fileName?: string;
};

type BxpCodeTabsProps = {
  tabs: BxpCodeTab[];
  theme?: "dark" | "light";
  showLineNumbers?: boolean;
  showCopyButton?: boolean;
  showHeader?: boolean;
  stickyHeader?: boolean;
  stickyTop?: number;
  defaultTab?: number;
  headerColor?: string;
  backgroundColor?: string;
  borderColor?: string;
  tabActiveColor?: string;
  tabActiveTextColor?: string;
  tabTextColor?: string;
  tabIndicatorColor?: string;
  copyButtonColor?: string;
  lineNumberColor?: string;
  style?: CSSProperties;
  className?: string;
  onError?: (error: Error) => void;
};

Usage Examples

Minimal

tsx
<BxpCodeTabs
  tabs={[
    { lang: "javascript", code: `console.log("hello")` },
    { lang: "python", code: `print("hello")` },
  ]}
/>
tsx
<BxpCodeTabs
  tabs={[
    { lang: "bash", label: "npm", code: "npm install bxp-code" },
    { lang: "bash", label: "pnpm", code: "pnpm add bxp-code" },
    { lang: "bash", label: "yarn", code: "yarn add bxp-code" },
    { lang: "bash", label: "bun", code: "bun add bxp-code" },
  ]}
  theme="dark"
  showLineNumbers
  showCopyButton
  stickyHeader
  stickyTop={64}
  defaultTab={0}
  headerColor="#161b22"
  backgroundColor="#0d1117"
  borderColor="#30363d"
  tabActiveColor="#161b22"
  tabActiveTextColor="#f0f6fc"
  tabTextColor="#8b949e"
  tabIndicatorColor="#e06b74"
  copyButtonColor="rgba(22, 27, 34, 0.9)"
  lineNumberColor="#484f58"
  style={{ maxHeight: "400px" }}
  className="my-tabs"
  onError={(err) => console.error(err)}
/>

Exports

typescript
import { BxpCode, BxpCodeTabs } from "bxp-code";
import type { BxpCodeProps, BxpCodeTabsProps, BxpCodeTab } from "bxp-code";

BxpCode API Reference

Released under the MIT License.