Getting Started
App Providerglobal.d.tsThemesTypes
cn(...args)Text ParserUnits Converters
AnchorAvatarBreadcrumbBurgerButtonCardCarouselCheckerCodeColor PickerCommandConfettiCopyButtonDouble Helix WordsFloating IndicatorGroupHighlight TextIndicatorInputKbdLabelLoaderPaginationPassword RequirementPolymorphic SlotProgressProseRatingRunning AreaScroll AreaSheetsSkeletonSliderStackSvgTableTabsTextareaTimelineTimesToasterTooltipTyping WordsTypography
useClickOutsideuseClipboarduseDeviceInfouseDialoguseDidUpdateuseDirectionuseDisclosureuseDocumentTitleuseDocumentVisibilityuseElementInfouseEyeDropperuseFetchuseFullscreenuseGeoLocationuseHotkeysuseHoveruseIduseImagePopupuseInputStateuseIntersectionuseIntervaluseIsomorphicEffectuseListStateuseLocalStorageuseMeasureScrollbaruseMediaQueryuseMergedRefuseMouseuseMoveuseMutationObserveruseNetworkuseOpenStateuseOrientationuseOSusePaginationusePWAInstalleruseRandomColorsuseReducedMotionuseReloaduseResizeObserveruseScrollIntoViewuseStateHistoryuseTimeoutuseTouchuseTriggeruseUncontrolleduseValidatedStateuseViewportSizeuseWindowEventuseWindowScroll
Docs
Web
Components
Code
Checker

A versatile input component that includes checkboxes, switches, and radio buttons for interactive selection.

Color Picker

An interactive component that enables users to pick colors, useful for design customization and theme selection.


Edit this page on GitHub
  • Started
  • Utilities
  • Configuration
  • Components
  • Hooks
  • Examples
  • Github
  • Contributing
⌘+J

© 2025 oeri rights MIT


Designed in Earth-616

Built by oeri

Code

A component designed to display code snippets in a readable format, often with syntax highlighting for better readability.

Usage

Basic usage example to quickly see how the Code works.

React.createElement()
{ "filePath": "C:/Data/path/package.json", "error": { "errno": -4048, "code": "EPERM", "syscall": "open", "path": "C:\Data\path\package.json" }, "_tag": "fs.WriteFileError" }{ "name": "string", "symbol": "string", "position": "number", "mass": "number" }
import { Code } from "@/ui/code";
import { Stack } from "@/ui/stack";

const data = [
  { name: "Carbon", symbol: "C", position: 6, mass: 12.011 },
  { name: "Nitrogen", symbol: "N", position: 7, mass: 14.007 },
  { name: "Yttrium", symbol: "Y", position: 39, mass: 88.906 },
  { name: "Barium", symbol: "Ba", position: 56, mass: 137.33 },
  { name: "Cerium", symbol: "Ce", position: 58, mass: 140.12 },
  { name: "Sodium", symbol: "Na", position: 11, mass: 22.99 }
];

const code = `{
  "filePath": "C:/Data/path/package.json",
  "error": {
    "errno": -4048,
    "code": "EPERM",
    "syscall": "open",
    "path": "C:\\Data\\path\\package.json"

  },
  "_tag": "fs.WriteFileError"
}`;

export function CodeDemo() {
  return (
    <Stack className="flex max-w-full flex-col items-center justify-center">
      <Code block code="React.createElement()" />
      <Code quote>{code}</Code>
      <Code samp={data} />
    </Stack>
  );
}

Properties

Interactive configurator to explore customization options for the Code component.

{
  "filePath": "C:/Data/path/package.json",
  "error": {
    "errno": -4048,
    "code": "EPERM",
    "syscall": "open",
    "path": "C:\Data\path\package.json"

  },
  "_tag": "fs.WriteFileError"
}{
  "name": "string",
  "symbol": "string",
  "position": "number",
  "mass": "number"
}
import { Code } from "@/ui/code";

const data = [
  { name: "Carbon", symbol: "C", position: 6, mass: 12.011 },
  { name: "Nitrogen", symbol: "N", position: 7, mass: 14.007 },
  { name: "Yttrium", symbol: "Y", position: 39, mass: 88.906 },
  { name: "Barium", symbol: "Ba", position: 56, mass: 137.33 },
  { name: "Cerium", symbol: "Ce", position: 58, mass: 140.12 },
  { name: "Sodium", symbol: "Na", position: 11, mass: 22.99 }
];

const code = `{
  "filePath": "C:/Data/path/package.json",
  "error": {
    "errno": -4048,
    "code": "EPERM",
    "syscall": "open",
    "path": "C:\\Data\\path\\package.json"

  },
  "_tag": "fs.WriteFileError"
}`;

export function CodeDemo() {
  return <Code samp={data} code={code} />;
}
  • By default, Code component renders inline code html element.
  • To render code in pre element pass block prop to Code component.

API References

Styles API

type T = "code" | "samp";
Styles APITypeDefaultAnnotation
unstyled?Partial<Record<T, boolean>>falseif true, default styles will be removed
className?stringundefinedpass to root component <div>
classNames?Partial<Record<T, string>>undefined
style?CSSPropertiesundefinedpass to root component <div>
styles?Partial<Record<T, CSSProperties>>undefined

Props API

type Dir = "ltr" | "rtl" | (string & {});
Props APITypeDefaultAnnotation
children?stringundefinedOnly accept children as strings
block?booleanfalseIf set code will be rendered inside pre
quote?booleanfalseAllows applying styles like as blockquote
dir?DirrtlAttribute that indicates the directionality of the element's text
code?stringundefinedUsed to display inline code
samp?Record<string, any>undefinedUsed to display data type conversions to strings such as JSON.

Source Codes

Full working code example, including necessary markup and styles. You can copy and paste this code directly to start using the component immediately.

code.tsx