Home / File/ component-source.tsx — ui Source File

component-source.tsx — ui Source File

Architecture documentation for component-source.tsx, a tsx file in the ui codebase. 10 imports, 0 dependents.

File tsx Internationalization RTLLayout 10 imports 2 functions

Entity Profile

Dependency Diagram

graph LR
  6e002999_74c0_6885_6d92_dd3803998064["component-source.tsx"]
  918c1a0f_41f3_e3be_45d1_b3d8dbe4f71d["promises"]
  6e002999_74c0_6885_6d92_dd3803998064 --> 918c1a0f_41f3_e3be_45d1_b3d8dbe4f71d
  30b54380_087e_e75d_bd32_5986b1e9b9a8["node:path"]
  6e002999_74c0_6885_6d92_dd3803998064 --> 30b54380_087e_e75d_bd32_5986b1e9b9a8
  1d141819_425e_b5fd_4c8e_32f7c6a42cf2["react"]
  6e002999_74c0_6885_6d92_dd3803998064 --> 1d141819_425e_b5fd_4c8e_32f7c6a42cf2
  7edb604f_23f1_911f_0682_b46c871a68d6["highlight-code"]
  6e002999_74c0_6885_6d92_dd3803998064 --> 7edb604f_23f1_911f_0682_b46c871a68d6
  7a25f51b_551e_131b_bc51_bd5ccc7c308c["registry"]
  6e002999_74c0_6885_6d92_dd3803998064 --> 7a25f51b_551e_131b_bc51_bd5ccc7c308c
  a9107df8_5d0b_93eb_d3db_eeeba0d6e12c["rehype"]
  6e002999_74c0_6885_6d92_dd3803998064 --> a9107df8_5d0b_93eb_d3db_eeeba0d6e12c
  79081a1f_55a3_945a_fb8c_d53d6d3eab81["utils"]
  6e002999_74c0_6885_6d92_dd3803998064 --> 79081a1f_55a3_945a_fb8c_d53d6d3eab81
  571632b7_8b4c_6184_6e9b_c90b8deac152["code-collapsible-wrapper"]
  6e002999_74c0_6885_6d92_dd3803998064 --> 571632b7_8b4c_6184_6e9b_c90b8deac152
  402113bd_a10d_0255_fccf_87fa40fd281a["copy-button"]
  6e002999_74c0_6885_6d92_dd3803998064 --> 402113bd_a10d_0255_fccf_87fa40fd281a
  aae3c3f1_230a_9c11_a663_8bbc3f0ad054["icons"]
  6e002999_74c0_6885_6d92_dd3803998064 --> aae3c3f1_230a_9c11_a663_8bbc3f0ad054
  style 6e002999_74c0_6885_6d92_dd3803998064 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import fs from "node:fs/promises"
import path from "node:path"
import * as React from "react"

import { highlightCode } from "@/lib/highlight-code"
import { getDemoItem, getRegistryItem } from "@/lib/registry"
import { formatCode } from "@/lib/rehype"
import { cn } from "@/lib/utils"
import { CodeCollapsibleWrapper } from "@/components/code-collapsible-wrapper"
import { CopyButton } from "@/components/copy-button"
import { getIconForLanguageExtension } from "@/components/icons"

export async function ComponentSource({
  name,
  src,
  title,
  language,
  collapsible = true,
  className,
  styleName = "new-york-v4",
  maxLines,
}: React.ComponentProps<"div"> & {
  name?: string
  src?: string
  title?: string
  language?: string
  collapsible?: boolean
  styleName?: string
  maxLines?: number
}) {
  if (!name && !src) {
    return null
  }

  let code: string | undefined

  if (name) {
    const item =
      (await getDemoItem(name, styleName)) ??
      (await getRegistryItem(name, styleName))
    code = item?.files?.[0]?.content
  }

  if (src) {
    const file = await fs.readFile(path.join(process.cwd(), src), "utf-8")
    code = file
  }

  if (!code) {
    return null
  }

  code = await formatCode(code, styleName)
  code = code.replaceAll("/* eslint-disable react/no-children-prop */\n", "")

  // Truncate code if maxLines is set.
  if (maxLines) {
    code = code.split("\n").slice(0, maxLines).join("\n")
  }

  const lang = language ?? title?.split(".").pop() ?? "tsx"
  const highlightedCode = await highlightCode(code, lang)

  if (!collapsible) {
    return (
      <div className={cn("relative", className)}>
        <ComponentCode
          code={code}
          highlightedCode={highlightedCode}
          language={lang}
          title={title}
        />
      </div>
    )
  }

  return (
    <CodeCollapsibleWrapper className={className}>
      <ComponentCode
        code={code}
        highlightedCode={highlightedCode}
        language={lang}
        title={title}
      />
    </CodeCollapsibleWrapper>
  )
}

function ComponentCode({
  code,
  highlightedCode,
  language,
  title,
}: {
  code: string
  highlightedCode: string
  language: string
  title: string | undefined
}) {
  return (
    <figure data-rehype-pretty-code-figure="" className="[&>pre]:max-h-96">
      {title && (
        <figcaption
          data-rehype-pretty-code-title=""
          className="text-code-foreground [&_svg]:text-code-foreground flex items-center gap-2 [&_svg]:size-4 [&_svg]:opacity-70"
          data-language={language}
        >
          {getIconForLanguageExtension(language)}
          {title}
        </figcaption>
      )}
      <CopyButton value={code} />
      <div dangerouslySetInnerHTML={{ __html: highlightedCode }} />
    </figure>
  )
}

Subdomains

Dependencies

  • code-collapsible-wrapper
  • copy-button
  • highlight-code
  • icons
  • node:path
  • promises
  • react
  • registry
  • rehype
  • utils

Frequently Asked Questions

What does component-source.tsx do?
component-source.tsx is a source file in the ui codebase, written in tsx. It belongs to the Internationalization domain, RTLLayout subdomain.
What functions are defined in component-source.tsx?
component-source.tsx defines 2 function(s): ComponentCode, ComponentSource.
What does component-source.tsx depend on?
component-source.tsx imports 10 module(s): code-collapsible-wrapper, copy-button, highlight-code, icons, node:path, promises, react, registry, and 2 more.
Where is component-source.tsx in the architecture?
component-source.tsx is located at apps/v4/components/component-source.tsx (domain: Internationalization, subdomain: RTLLayout, directory: apps/v4/components).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free