Skip to content
ui8kit

component / components

Code Window

Code Window component

Install

npx ui8kit add code-window

Pulls in: box, compose, inline, kit-box, kit-text, list, list-item, text, utils

Preview

No static preview for this item: it needs content or a parent that this page cannot supply. The code is below.

Code

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework svelte --dir src --registry-url https://registry.buildy.tw/svelte --strict-cdn
npx ui8kit add code-window
components/code-window.svelte
<!-- Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT. -->
<!--
  A terminal or code window: a title bar with three round marks, then the lines. A `command` line starts with
  the prompt, an `output` line is muted. Static: the typing animation belongs to the port (TypingText contract).
-->
<script lang="ts" module>
  import type { Snippet } from "svelte";
  import type { CodeLine } from "./code-window.types";

  export type CodeWindowProps = {
    title: string;
    prompt: string;
    lines: CodeLine[];
    class?: string;
  };
</script>

<script lang="ts">
  import Box from "../compose/Box.svelte";
  import Inline from "../compose/Inline.svelte";
  import List from "../compose/List.svelte";
  import ListItem from "../compose/ListItem.svelte";
  import Text from "../compose/Text.svelte";
  import { cn } from "../utils";

  let { title, prompt, lines, class: className }: CodeWindowProps = $props();
</script>

<Box
  class={cn(
    "w-full overflow-hidden rounded bg-card text-left inset-ring inset-ring-border",
    className
  )}
  role="group"
  aria-label={title}
  data-slot="code-window"
>
  <Box class="flex items-center border-b border-border px-4 py-2">
    <Text size="xs" class="text-muted-foreground">
      {title}
    </Text>
  </Box>
  <List class="m-0 flex list-none flex-col gap-2 p-4 font-mono text-sm">
    {#each lines as line (line.id)}
      <ListItem
        class={cn("flex gap-2", ((line.kind === "command") ? "text-foreground" : "text-muted-foreground"))}
        data-kind={line.kind}
        data-slot="code-line"
      >
        {#if (line.kind === "command")}
          <Inline class="select-none text-muted-foreground">
            {prompt}
          </Inline>
        {/if}
        <Inline>
          {line.text}
        </Inline>
      </ListItem>
    {/each}
  </List>
</Box>
components/code-window.types.ts
// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.

export type CodeLine = {
  id: string;
  text: string;
  kind: string;
};

Svelte registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework react --dir src --registry-url https://registry.buildy.tw/react --strict-cdn
npx ui8kit add code-window
components/code-window.tsx
// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
/**
 * A terminal or code window: a title bar with three round marks, then the lines. A `command` line starts with
 * the prompt, an `output` line is muted. Static: the typing animation belongs to the port (TypingText contract).
 */
import { type ReactNode } from "react";
import { Box, Inline, List, ListItem, Text } from "../compose";
import { cn } from "../utils";
import type { CodeLine } from "./code-window.types";

export type CodeWindowProps = {
  title: string;
  prompt: string;
  lines: CodeLine[];
  className?: string;
};

export function CodeWindow({ title, prompt, lines, className }: CodeWindowProps) {
  return (
    <Box
      className={cn(
        "w-full overflow-hidden rounded bg-card text-left inset-ring inset-ring-border",
        className
      )}
      role="group"
      aria-label={title}
      data-slot="code-window"
    >
      <Box className="flex items-center border-b border-border px-4 py-2">
        <Text size="xs" className="text-muted-foreground">
          {title}
        </Text>
      </Box>
      <List className="m-0 flex list-none flex-col gap-2 p-4 font-mono text-sm">
        {(lines ?? []).map((line) => (
          <ListItem key={line.id}
            className={cn(
              "flex gap-2",
              ((line.kind === "command") ? "text-foreground" : "text-muted-foreground")
            )}
            data-kind={line.kind}
            data-slot="code-line"
          >
            {(line.kind === "command") ? (
              <Inline className="select-none text-muted-foreground">
                {prompt}
              </Inline>
            ) : null}
            <Inline>
              {line.text}
            </Inline>
          </ListItem>
        ))}
      </List>
    </Box>
  );
}
components/code-window.types.ts
// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.

export type CodeLine = {
  id: string;
  text: string;
  kind: string;
};

React registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework vue --dir src --registry-url https://registry.buildy.tw/vue --strict-cdn
npx ui8kit add code-window
components/code-window.types.ts
// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.

export type CodeLine = {
  id: string;
  text: string;
  kind: string;
};
components/code-window.vue
<!-- Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT. -->
<!--
  A terminal or code window: a title bar with three round marks, then the lines. A `command` line starts with
  the prompt, an `output` line is muted. Static: the typing animation belongs to the port (TypingText contract).
-->
<script lang="ts">
import type { CodeLine } from "./code-window.types";

export type CodeWindowProps = {
  title: string;
  prompt: string;
  lines: CodeLine[];
  class?: string;
};
</script>

<script setup lang="ts">
import Box from "../compose/Box.vue";
import Inline from "../compose/Inline.vue";
import List from "../compose/List.vue";
import ListItem from "../compose/ListItem.vue";
import Text from "../compose/Text.vue";
import { cn } from "../utils";

const { title, prompt, lines, class: className } = defineProps<CodeWindowProps>();
</script>

<template>
  <Box
    :class="cn(
      'w-full overflow-hidden rounded bg-card text-left inset-ring inset-ring-border',
      className
    )"
    role="group"
    :aria-label="title"
    data-slot="code-window"
  >
    <Box class="flex items-center border-b border-border px-4 py-2">
      <Text size="xs" class="text-muted-foreground">
        {{ title }}
      </Text>
    </Box>
    <List class="m-0 flex list-none flex-col gap-2 p-4 font-mono text-sm">
      <ListItem v-for="line in lines" :key="line.id"
        :class="cn('flex gap-2', ((line.kind === 'command') ? 'text-foreground' : 'text-muted-foreground'))"
        :data-kind="line.kind"
        data-slot="code-line"
      >
        <Inline v-if="(line.kind === 'command')" class="select-none text-muted-foreground">
          {{ prompt }}
        </Inline>
        <Inline>
          {{ line.text }}
        </Inline>
      </ListItem>
    </List>
  </Box>
</template>

Vue registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework solid --dir src --registry-url https://registry.buildy.tw/solid --strict-cdn
npx ui8kit add code-window
components/code-window.tsx
// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
/**
 * A terminal or code window: a title bar with three round marks, then the lines. A `command` line starts with
 * the prompt, an `output` line is muted. Static: the typing animation belongs to the port (TypingText contract).
 */
import { For, type JSX } from "solid-js";
import { Box, Inline, List, ListItem, Text } from "../compose";
import { cn } from "../utils";
import type { CodeLine } from "./code-window.types";

export type CodeWindowProps = {
  title: string;
  prompt: string;
  lines: CodeLine[];
  class?: string;
};

export function CodeWindow({ title, prompt, lines, class: className }: CodeWindowProps) {
  return (
    <Box
      class={cn(
        "w-full overflow-hidden rounded bg-card text-left inset-ring inset-ring-border",
        className
      )}
      role="group"
      aria-label={title}
      data-slot="code-window"
    >
      <Box class="flex items-center border-b border-border px-4 py-2">
        <Text size="xs" class="text-muted-foreground">
          {title}
        </Text>
      </Box>
      <List class="m-0 flex list-none flex-col gap-2 p-4 font-mono text-sm">
        <For each={lines ?? []}>{(line) => (
          <ListItem
            class={cn("flex gap-2", ((line.kind === "command") ? "text-foreground" : "text-muted-foreground"))}
            data-kind={line.kind}
            data-slot="code-line"
          >
            {(line.kind === "command") ? (
              <Inline class="select-none text-muted-foreground">
                {prompt}
              </Inline>
            ) : null}
            <Inline>
              {line.text}
            </Inline>
          </ListItem>
        )}</For>
      </List>
    </Box>
  );
}
components/code-window.types.ts
// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.

export type CodeLine = {
  id: string;
  text: string;
  kind: string;
};

Solid registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework templ --dir src --registry-url https://registry.buildy.tw/templ --strict-cdn
npx ui8kit add code-window
blocks/code-window.templ
// Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
// Source: packages/compose-gen/specs/patterns/code-window.json

package blocks

import (
	"github.com/ui8kit/codegen/generated/templ/ui/box"
	"github.com/ui8kit/codegen/generated/templ/compose"
	"github.com/ui8kit/codegen/generated/templ/ui/text"
	uiutils "github.com/ui8kit/codegen/generated/templ/orgutils"
)

// CodeWindowProps are the props of CodeWindow; the values are the JSON shapes of the TypeScript props.
type CodeWindowProps struct {
	Title any `json:"title"`
	Prompt any `json:"prompt"`
	Lines any `json:"lines"`
	Class string `json:"className"`
}

// A terminal or code window: a title bar with three round marks, then the lines. A `command` line starts with the prompt, an `output` line is muted. Static: the typing animation belongs to the port (TypingText contract).
templ CodeWindow(p CodeWindowProps) {
	{{ vTitle := p.Title }}
	{{ vPrompt := p.Prompt }}
	{{ vLines := p.Lines }}
	@compose.Box(compose.BoxProps{BoxProps: box.BoxProps{Class: uiutils.S(uiutils.Cnv("w-full overflow-hidden rounded bg-card text-left inset-ring inset-ring-border", p.Class)), Attrs: uiutils.Attrs("role", "group", "aria-label", vTitle, "data-slot", "code-window")}}) {
		@compose.Box(compose.BoxProps{BoxProps: box.BoxProps{Class: "flex items-center border-b border-border px-4 py-2"}}) {
			@compose.Text(compose.TextProps{Size: "xs", TextProps: text.TextProps{Class: "text-muted-foreground"}}) {
				{ uiutils.Text(vTitle) }
			}
		}
		@compose.List(compose.ListProps{BoxProps: box.BoxProps{Class: "m-0 flex list-none flex-col gap-2 p-4 font-mono text-sm"}}) {
			for _, vLine := range uiutils.L(vLines) {
				@compose.ListItem(compose.ListItemProps{BoxProps: box.BoxProps{Class: uiutils.S(uiutils.Cnv("flex gap-2", uiutils.Cond(uiutils.T(uiutils.Eq(uiutils.Get(vLine, "kind"), "command")), "text-foreground", "text-muted-foreground"))), Attrs: uiutils.Attrs("data-kind", uiutils.Get(vLine, "kind"), "data-slot", "code-line")}}) {
					if uiutils.Eq(uiutils.Get(vLine, "kind"), "command") {
						@compose.Inline(compose.InlineProps{TextProps: text.TextProps{Class: "select-none text-muted-foreground"}}) {
							{ uiutils.Text(vPrompt) }
						}
					}
					@compose.Inline(compose.InlineProps{TextProps: text.TextProps{}}) {
						{ uiutils.Text(uiutils.Get(vLine, "text")) }
					}
				}
			}
		}
	}
}

templ registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework twig --dir src --registry-url https://registry.buildy.tw/twig --strict-cdn
npx ui8kit add code-window
blocks/code-window.html.twig
{#- Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
    Source: packages/compose-gen/specs/patterns/code-window.json
    A terminal or code window: a title bar with three round marks, then the lines. A `command` line starts with the prompt, an `output` line is muted. Static: the typing animation belongs to the port (TypingText contract).
    Props (p): title, prompt, lines, className. -#}
{%- set v_title = (p.title ?? null) -%}
{%- set v_prompt = (p.prompt ?? null) -%}
{%- set v_lines = (p.lines ?? null) -%}
{%- set c_7 -%}
  {%- set c_2 -%}
    {%- set c_1 -%}
      {{ og_text(v_title) }}
    {%- endset -%}
    {{ include('compose/Text.html.twig', {'size': 'xs', 'class': 'text-muted-foreground', 'children': c_1}, with_context = false) }}
  {%- endset -%}
  {{ include('compose/Box.html.twig', {'class': 'flex items-center border-b border-border px-4 py-2', 'children': c_2}, with_context = false) }}
  {%- set c_6 -%}
    {%- for v_line in og_l(v_lines) %}
      {%- set c_5 -%}
        {%- if og_t(og_eq(og_get(v_line, ['kind']), 'command')) %}
          {%- set c_3 -%}
            {{ og_text(v_prompt) }}
          {%- endset -%}
          {{ include('compose/Inline.html.twig', {'class': 'select-none text-muted-foreground', 'children': c_3}, with_context = false) }}
        {%- endif %}
        {%- set c_4 -%}
          {{ og_text(og_get(v_line, ['text'])) }}
        {%- endset -%}
        {{ include('compose/Inline.html.twig', {'children': c_4}, with_context = false) }}
      {%- endset -%}
      {{ include('compose/ListItem.html.twig', {'class': og_s(og_cnv(['flex gap-2', (og_t(og_eq(og_get(v_line, ['kind']), 'command')) ? 'text-foreground' : 'text-muted-foreground')])), 'attrs': og_attrs(['data-kind', og_get(v_line, ['kind']), 'data-slot', 'code-line']), 'children': c_5}, with_context = false) }}
    {%- endfor %}
  {%- endset -%}
  {{ include('compose/List.html.twig', {'class': 'm-0 flex list-none flex-col gap-2 p-4 font-mono text-sm', 'children': c_6}, with_context = false) }}
{%- endset -%}
{{ include('compose/Box.html.twig', {'class': og_s(og_cnv(['w-full overflow-hidden rounded bg-card text-left inset-ring inset-ring-border', (p.className ?? '')])), 'attrs': og_attrs(['role', 'group', 'aria-label', v_title, 'data-slot', 'code-window']), 'children': c_7}, with_context = false) }}

Twig registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework latte --dir src --registry-url https://registry.buildy.tw/latte --strict-cdn
npx ui8kit add code-window
blocks/code-window.latte
{* Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
    Source: packages/compose-gen/specs/patterns/code-window.json
    A terminal or code window: a title bar with three round marks, then the lines. A `command` line starts with the prompt, an `output` line is muted. Static: the typing animation belongs to the port (TypingText contract).
    Props (p): title, prompt, lines, className. *}
{var $v_title = ($p['title'] ?? null)}
{var $v_prompt = ($p['prompt'] ?? null)}
{var $v_lines = ($p['lines'] ?? null)}
{capture $c_7}
  {capture $c_2}
    {capture $c_1}
      {=og_text($v_title)}
    {/capture}
    {=og_include('compose/Text.latte', ['size' => 'xs', 'class' => 'text-muted-foreground', 'children' => (string) $c_1])|noescape}
  {/capture}
  {=og_include('compose/Box.latte', ['class' => 'flex items-center border-b border-border px-4 py-2', 'children' => (string) $c_2])|noescape}
  {capture $c_6}
    {foreach og_l($v_lines) as $v_line}
      {capture $c_5}
        {if og_t(og_eq(og_get($v_line, ['kind']), 'command'))}
          {capture $c_3}
            {=og_text($v_prompt)}
          {/capture}
          {=og_include('compose/Inline.latte', ['class' => 'select-none text-muted-foreground', 'children' => (string) $c_3])|noescape}
        {/if}
        {capture $c_4}
          {=og_text(og_get($v_line, ['text']))}
        {/capture}
        {=og_include('compose/Inline.latte', ['children' => (string) $c_4])|noescape}
      {/capture}
      {=og_include('compose/ListItem.latte', ['class' => og_s(og_cnv(['flex gap-2', (og_t(og_eq(og_get($v_line, ['kind']), 'command')) ? 'text-foreground' : 'text-muted-foreground')])), 'attrs' => og_attrs(['data-kind', og_get($v_line, ['kind']), 'data-slot', 'code-line']), 'children' => (string) $c_5])|noescape}
    {/foreach}
  {/capture}
  {=og_include('compose/List.latte', ['class' => 'm-0 flex list-none flex-col gap-2 p-4 font-mono text-sm', 'children' => (string) $c_6])|noescape}
{/capture}
{=og_include('compose/Box.latte', ['class' => og_s(og_cnv(['w-full overflow-hidden rounded bg-card text-left inset-ring inset-ring-border', ($p['className'] ?? '')])), 'attrs' => og_attrs(['role', 'group', 'aria-label', $v_title, 'data-slot', 'code-window']), 'children' => (string) $c_7])|noescape}

Latte registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework jinja2 --dir src --registry-url https://registry.buildy.tw/jinja2 --strict-cdn
npx ui8kit add code-window
blocks/code-window.html.j2
{#- Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
    Source: packages/compose-gen/specs/patterns/code-window.json
    A terminal or code window: a title bar with three round marks, then the lines. A `command` line starts with the prompt, an `output` line is muted. Static: the typing animation belongs to the port (TypingText contract).
    Props (p): title, prompt, lines, className. -#}
{%- set v_title = og_def(p['title'], none) -%}
{%- set v_prompt = og_def(p['prompt'], none) -%}
{%- set v_lines = og_def(p['lines'], none) -%}
{%- set c_7 -%}
  {%- set c_2 -%}
    {%- set c_1 -%}
      {{ og_text(v_title) }}
    {%- endset -%}
    {{ og_include('compose/text.html.j2', {'p': {'Size': 'xs', 'Class': 'text-muted-foreground'}, 'children': c_1}) }}
  {%- endset -%}
  {{ og_include('compose/box.html.j2', {'p': {'Class': 'flex items-center border-b border-border px-4 py-2'}, 'children': c_2}) }}
  {%- set c_6 -%}
    {%- for v_line in og_l(v_lines) %}
      {%- set c_5 -%}
        {%- if og_t(og_eq(og_get(v_line, ['kind']), 'command')) %}
          {%- set c_3 -%}
            {{ og_text(v_prompt) }}
          {%- endset -%}
          {{ og_include('compose/inline.html.j2', {'p': {'Class': 'select-none text-muted-foreground'}, 'children': c_3}) }}
        {%- endif %}
        {%- set c_4 -%}
          {{ og_text(og_get(v_line, ['text'])) }}
        {%- endset -%}
        {{ og_include('compose/inline.html.j2', {'p': {}, 'children': c_4}) }}
      {%- endset -%}
      {{ og_include('compose/list-item.html.j2', {'p': {'Class': og_s(og_cnv(['flex gap-2', ('text-foreground' if og_t(og_eq(og_get(v_line, ['kind']), 'command')) else 'text-muted-foreground')])), 'Attrs': og_attrs(['data-kind', og_get(v_line, ['kind']), 'data-slot', 'code-line'])}, 'children': c_5}) }}
    {%- endfor %}
  {%- endset -%}
  {{ og_include('compose/list.html.j2', {'p': {'Class': 'm-0 flex list-none flex-col gap-2 p-4 font-mono text-sm'}, 'children': c_6}) }}
{%- endset -%}
{{ og_include('compose/box.html.j2', {'p': {'Class': og_s(og_cnv(['w-full overflow-hidden rounded bg-card text-left inset-ring inset-ring-border', og_def(p['className'], '')])), 'Attrs': og_attrs(['role', 'group', 'aria-label', v_title, 'data-slot', 'code-window'])}, 'children': c_7}) }}

Jinja2 registry item (JSON)

Props

Names and types come from the xgen specs of the source. Standard HTML attributes (id, role, tabIndex, aria-*) pass through to the root element; the class prop is className in React.

A terminal or code window: a title bar with three round marks, then the lines. A `command` line starts with the prompt, an `output` line is muted. Static: the typing animation belongs to the port (TypingText contract).

Props of CodeWindow
PropTypeDefault Description
title (required)string-name of the window, also its accessible name
prompt (required)string-the mark before a command line
lines (required)CodeLine[]-

Used in