Skip to content
ui8kit

component / components

Editor Tab

Editor Tab component

Install

npx ui8kit add editor-tab

Pulls in: box, button, compose, inline, kit-box, kit-button, kit-text, lucide-icon, 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 editor-tab
components/editor-tab.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. -->
<!--
  An editor file tab (40 px high): a file icon, the label and a close button. `preview` marks a tab that is not
  pinned yet. Keyboard (Enter and Space activate, Delete closes) is the programmer's behind the click and close
  events.
-->
<script lang="ts" module>
  import type { Snippet } from "svelte";

  export type EditorTabProps = {
    label: string;
    closeLabel: string;
    active?: boolean;
    preview?: boolean;
    class?: string;
    icon?: Snippet;
    onclick?: () => void;
    onclose?: () => void;
  };
</script>

<script lang="ts">
  import Box from "../compose/Box.svelte";
  import Button from "../compose/Button.svelte";
  import Inline from "../compose/Inline.svelte";
  import LucideIcon from "../icons/LucideIcon.svelte";
  import { cn } from "../utils";

  let {
    label,
    closeLabel,
    active = false,
    preview = false,
    class: className,
    icon,
    onclick,
    onclose,
  }: EditorTabProps = $props();
</script>

<Box
  class={cn(
    "flex h-10 shrink-0 cursor-pointer flex-col justify-center data-[state=active]:bg-card " +
      "[&_svg]:text-muted-foreground",
    "border-r border-border",
    className
  )}
  role="tab"
  aria-selected={active}
  tabindex={(active ? 0 : -1)}
  data-slot="editor-tab"
  data-state={(active ? "active" : "default")}
  onclick={() => onclick?.()}
>
  <Inline class="flex h-10 items-center gap-2 px-3" data-slot="editor-tab-content">
    {@render icon?.()}
    <Inline
      class={cn("text-xs text-foreground", (preview ? "font-semibold italic" : "font-bold"))}
      data-slot="editor-tab-label"
    >
      {label}
    </Inline>
    <Button
      variant="ghost"
      size="sm"
      layout="icon"
      class={"p-0 [&>svg]:size-4"}
      aria-label={closeLabel}
      tabindex={-1}
      data-slot="editor-tab-close"
      onclick={() => onclose?.()}
    >
      <LucideIcon name="x" size={16} />
    </Button>
  </Inline>
</Box>

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 editor-tab
components/editor-tab.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.
/**
 * An editor file tab (40 px high): a file icon, the label and a close button. `preview` marks a tab that is not
 * pinned yet. Keyboard (Enter and Space activate, Delete closes) is the programmer's behind the click and close
 * events.
 */
import { type ReactNode } from "react";
import { Box, Button, Inline } from "../compose";
import { LucideIcon } from "../icons/LucideIcon";
import { cn } from "../utils";

export type EditorTabProps = {
  label: string;
  closeLabel: string;
  active?: boolean;
  preview?: boolean;
  className?: string;
  icon?: ReactNode;
  onClick?: () => void;
  onClose?: () => void;
};

export function EditorTab({
  label,
  closeLabel,
  active = false,
  preview = false,
  className,
  icon,
  onClick,
  onClose,
}: EditorTabProps) {
  return (
    <Box
      className={cn(
        "flex h-10 shrink-0 cursor-pointer flex-col justify-center data-[state=active]:bg-card " +
          "[&_svg]:text-muted-foreground",
        "border-r border-border",
        className
      )}
      role="tab"
      aria-selected={active}
      tabIndex={(active ? 0 : -1)}
      data-slot="editor-tab"
      data-state={(active ? "active" : "default")}
      onClick={() => onClick?.()}
    >
      <Inline className="flex h-10 items-center gap-2 px-3" data-slot="editor-tab-content">
        {icon}
        <Inline
          className={cn("text-xs text-foreground", (preview ? "font-semibold italic" : "font-bold"))}
          data-slot="editor-tab-label"
        >
          {label}
        </Inline>
        <Button
          variant="ghost"
          size="sm"
          layout="icon"
          className={"p-0 [&>svg]:size-4"}
          aria-label={closeLabel}
          tabIndex={-1}
          data-slot="editor-tab-close"
          onClick={() => onClose?.()}
        >
          <LucideIcon name="x" size={16} />
        </Button>
      </Inline>
    </Box>
  );
}

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 editor-tab
components/editor-tab.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. -->
<!--
  An editor file tab (40 px high): a file icon, the label and a close button. `preview` marks a tab that is not
  pinned yet. Keyboard (Enter and Space activate, Delete closes) is the programmer's behind the click and close
  events.
-->
<script lang="ts">
export type EditorTabProps = {
  label: string;
  closeLabel: string;
  active?: boolean;
  preview?: boolean;
  class?: string;
};
</script>

<script setup lang="ts">
import Box from "../compose/Box.vue";
import Button from "../compose/Button.vue";
import Inline from "../compose/Inline.vue";
import LucideIcon from "../icons/LucideIcon.vue";
import { cn } from "../utils";

const {
  label,
  closeLabel,
  active = false,
  preview = false,
  class: className,
} = defineProps<EditorTabProps>();
const emit = defineEmits<{ click: [], close: [] }>();
defineSlots<{ icon?(): unknown }>();
</script>

<template>
  <Box
    :class="cn(
      'flex h-10 shrink-0 cursor-pointer flex-col justify-center data-[state=active]:bg-card ' +
        '[&_svg]:text-muted-foreground',
      'border-r border-border',
      className
    )"
    role="tab"
    :aria-selected="active"
    :tabindex="(active ? 0 : -1)"
    data-slot="editor-tab"
    :data-state="(active ? 'active' : 'default')"
    @click="() => emit('click')"
  >
    <Inline class="flex h-10 items-center gap-2 px-3" data-slot="editor-tab-content">
      <slot name="icon" />
      <Inline
        :class="cn('text-xs text-foreground', (preview ? 'font-semibold italic' : 'font-bold'))"
        data-slot="editor-tab-label"
      >
        {{ label }}
      </Inline>
      <Button
        variant="ghost"
        size="sm"
        layout="icon"
        :class="'p-0 [&>svg]:size-4'"
        :aria-label="closeLabel"
        :tabindex="-1"
        data-slot="editor-tab-close"
        @click="() => emit('close')"
      >
        <LucideIcon name="x" :size="16" />
      </Button>
    </Inline>
  </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 editor-tab
components/editor-tab.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.
/**
 * An editor file tab (40 px high): a file icon, the label and a close button. `preview` marks a tab that is not
 * pinned yet. Keyboard (Enter and Space activate, Delete closes) is the programmer's behind the click and close
 * events.
 */
import { type JSX } from "solid-js";
import { Box, Button, Inline } from "../compose";
import { LucideIcon } from "../icons/LucideIcon";
import { cn } from "../utils";

export type EditorTabProps = {
  label: string;
  closeLabel: string;
  active?: boolean;
  preview?: boolean;
  class?: string;
  icon?: JSX.Element;
  onClick?: () => void;
  onClose?: () => void;
};

export function EditorTab({
  label,
  closeLabel,
  active = false,
  preview = false,
  class: className,
  icon,
  onClick,
  onClose,
}: EditorTabProps) {
  return (
    <Box
      class={cn(
        "flex h-10 shrink-0 cursor-pointer flex-col justify-center data-[state=active]:bg-card " +
          "[&_svg]:text-muted-foreground",
        "border-r border-border",
        className
      )}
      role="tab"
      aria-selected={active}
      tabindex={(active ? 0 : -1)}
      data-slot="editor-tab"
      data-state={(active ? "active" : "default")}
      onClick={() => onClick?.()}
    >
      <Inline class="flex h-10 items-center gap-2 px-3" data-slot="editor-tab-content">
        {icon}
        <Inline
          class={cn("text-xs text-foreground", (preview ? "font-semibold italic" : "font-bold"))}
          data-slot="editor-tab-label"
        >
          {label}
        </Inline>
        <Button
          variant="ghost"
          size="sm"
          layout="icon"
          class={"p-0 [&>svg]:size-4"}
          aria-label={closeLabel}
          tabindex={-1}
          data-slot="editor-tab-close"
          onClick={() => onClose?.()}
        >
          <LucideIcon name="x" size={16} />
        </Button>
      </Inline>
    </Box>
  );
}

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 editor-tab
blocks/editor-tab.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/editor-tab.json

package blocks

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

// EditorTabProps are the props of EditorTab; the values are the JSON shapes of the TypeScript props.
type EditorTabProps struct {
	Label any `json:"label"`
	CloseLabel any `json:"closeLabel"`
	Active any `json:"active"`
	Preview any `json:"preview"`
	Class string `json:"className"`
	Icon templ.Component `json:"-"`
}

// An editor file tab (40 px high): a file icon, the label and a close button. `preview` marks a tab that is not pinned yet. Keyboard (Enter and Space activate, Delete closes) is the programmer's behind the click and close events.
templ EditorTab(p EditorTabProps) {
	{{ vLabel := p.Label }}
	{{ vCloseLabel := p.CloseLabel }}
	{{ vActive := uiutils.Def(p.Active, false) }}
	{{ vPreview := uiutils.Def(p.Preview, false) }}
	@compose.Box(compose.BoxProps{BoxProps: box.BoxProps{Class: uiutils.S(uiutils.Cnv("flex h-10 shrink-0 cursor-pointer flex-col justify-center data-[state=active]:bg-card [&_svg]:text-muted-foreground", "border-r border-border", p.Class)), Attrs: uiutils.Attrs("role", "tab", "aria-selected", vActive, "tabindex", uiutils.Cond(uiutils.T(vActive), float64(0), float64(-1)), "data-slot", "editor-tab", "data-state", uiutils.Cond(uiutils.T(vActive), "active", "default"))}}) {
		@compose.Inline(compose.InlineProps{TextProps: text.TextProps{Class: "flex h-10 items-center gap-2 px-3", Attrs: uiutils.Attrs("data-slot", "editor-tab-content")}}) {
			if p.Icon != nil {
				@p.Icon
			}
			@compose.Inline(compose.InlineProps{TextProps: text.TextProps{Class: uiutils.S(uiutils.Cnv("text-xs text-foreground", uiutils.Cond(uiutils.T(vPreview), "font-semibold italic", "font-bold"))), Attrs: uiutils.Attrs("data-slot", "editor-tab-label")}}) {
				{ uiutils.Text(vLabel) }
			}
			@compose.Button(compose.ButtonProps{Variant: "ghost", Size: "sm", Layout: "icon", ButtonProps: button.ButtonProps{Class: "p-0 [&>svg]:size-4", AriaLabel: uiutils.S(vCloseLabel), Attrs: uiutils.Attrs("tabindex", float64(-1), "data-slot", "editor-tab-close")}}) {
				@icons.LucideIcon(icons.LucideIconProps{Name: "x", Size: 16})
			}
		}
	}
}

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 editor-tab
blocks/editor-tab.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/editor-tab.json
    An editor file tab (40 px high): a file icon, the label and a close button. `preview` marks a tab that is not pinned yet. Keyboard (Enter and Space activate, Delete closes) is the programmer's behind the click and close events.
    Props (p): label, closeLabel, active, preview, className, icon (slot). -#}
{%- set v_label = (p.label ?? null) -%}
{%- set v_closeLabel = (p.closeLabel ?? null) -%}
{%- set v_active = (p.active ?? false) -%}
{%- set v_preview = (p.preview ?? false) -%}
{%- set c_4 -%}
  {%- set c_3 -%}
    {{ og_slot((p.icon ?? null))|raw }}
    {%- set c_1 -%}
      {{ og_text(v_label) }}
    {%- endset -%}
    {{ include('compose/Inline.html.twig', {'class': og_s(og_cnv(['text-xs text-foreground', (og_t(v_preview) ? 'font-semibold italic' : 'font-bold')])), 'attrs': og_attrs(['data-slot', 'editor-tab-label']), 'children': c_1}, with_context = false) }}
    {%- set c_2 -%}
      {{ include('icons/LucideIcon.html.twig', {'name': 'x', 'size': 16}, with_context = false) }}
    {%- endset -%}
    {{ include('compose/Button.html.twig', {'variant': 'ghost', 'size': 'sm', 'layout': 'icon', 'class': 'p-0 [&>svg]:size-4', 'ariaLabel': og_s(v_closeLabel), 'attrs': og_attrs(['tabindex', -1, 'data-slot', 'editor-tab-close']), 'children': c_2}, with_context = false) }}
  {%- endset -%}
  {{ include('compose/Inline.html.twig', {'class': 'flex h-10 items-center gap-2 px-3', 'attrs': og_attrs(['data-slot', 'editor-tab-content']), 'children': c_3}, with_context = false) }}
{%- endset -%}
{{ include('compose/Box.html.twig', {'class': og_s(og_cnv(['flex h-10 shrink-0 cursor-pointer flex-col justify-center data-[state=active]:bg-card [&_svg]:text-muted-foreground', 'border-r border-border', (p.className ?? '')])), 'attrs': og_attrs(['role', 'tab', 'aria-selected', v_active, 'tabindex', (og_t(v_active) ? 0 : -1), 'data-slot', 'editor-tab', 'data-state', (og_t(v_active) ? 'active' : 'default')]), 'children': c_4}, 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 editor-tab
blocks/editor-tab.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/editor-tab.json
    An editor file tab (40 px high): a file icon, the label and a close button. `preview` marks a tab that is not pinned yet. Keyboard (Enter and Space activate, Delete closes) is the programmer's behind the click and close events.
    Props (p): label, closeLabel, active, preview, className, icon (slot). *}
{var $v_label = ($p['label'] ?? null)}
{var $v_closeLabel = ($p['closeLabel'] ?? null)}
{var $v_active = ($p['active'] ?? false)}
{var $v_preview = ($p['preview'] ?? false)}
{capture $c_4}
  {capture $c_3}
    {=og_slot(($p['icon'] ?? null))|noescape}
    {capture $c_1}
      {=og_text($v_label)}
    {/capture}
    {=og_include('compose/Inline.latte', ['class' => og_s(og_cnv(['text-xs text-foreground', (og_t($v_preview) ? 'font-semibold italic' : 'font-bold')])), 'attrs' => og_attrs(['data-slot', 'editor-tab-label']), 'children' => (string) $c_1])|noescape}
    {capture $c_2}
      {=og_include('icons/LucideIcon.latte', ['name' => 'x', 'size' => 16])|noescape}
    {/capture}
    {=og_include('compose/Button.latte', ['variant' => 'ghost', 'size' => 'sm', 'layout' => 'icon', 'class' => 'p-0 [&>svg]:size-4', 'ariaLabel' => og_s($v_closeLabel), 'attrs' => og_attrs(['tabindex', -1, 'data-slot', 'editor-tab-close']), 'children' => (string) $c_2])|noescape}
  {/capture}
  {=og_include('compose/Inline.latte', ['class' => 'flex h-10 items-center gap-2 px-3', 'attrs' => og_attrs(['data-slot', 'editor-tab-content']), 'children' => (string) $c_3])|noescape}
{/capture}
{=og_include('compose/Box.latte', ['class' => og_s(og_cnv(['flex h-10 shrink-0 cursor-pointer flex-col justify-center data-[state=active]:bg-card [&_svg]:text-muted-foreground', 'border-r border-border', ($p['className'] ?? '')])), 'attrs' => og_attrs(['role', 'tab', 'aria-selected', $v_active, 'tabindex', (og_t($v_active) ? 0 : -1), 'data-slot', 'editor-tab', 'data-state', (og_t($v_active) ? 'active' : 'default')]), 'children' => (string) $c_4])|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 editor-tab
blocks/editor-tab.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/editor-tab.json
    An editor file tab (40 px high): a file icon, the label and a close button. `preview` marks a tab that is not pinned yet. Keyboard (Enter and Space activate, Delete closes) is the programmer's behind the click and close events.
    Props (p): label, closeLabel, active, preview, className, icon (slot). -#}
{%- set v_label = og_def(p['label'], none) -%}
{%- set v_closeLabel = og_def(p['closeLabel'], none) -%}
{%- set v_active = og_def(p['active'], false) -%}
{%- set v_preview = og_def(p['preview'], false) -%}
{%- set c_4 -%}
  {%- set c_3 -%}
    {{ og_slot(og_def(p['icon'], none))|safe }}
    {%- set c_1 -%}
      {{ og_text(v_label) }}
    {%- endset -%}
    {{ og_include('compose/inline.html.j2', {'p': {'Class': og_s(og_cnv(['text-xs text-foreground', ('font-semibold italic' if og_t(v_preview) else 'font-bold')])), 'Attrs': og_attrs(['data-slot', 'editor-tab-label'])}, 'children': c_1}) }}
    {%- set c_2 -%}
      {{ og_include('icons/lucide-icon.html.j2', {'p': {'Name': 'x', 'Size': 16}}) }}
    {%- endset -%}
    {{ og_include('compose/button.html.j2', {'p': {'Variant': 'ghost', 'Size': 'sm', 'Layout': 'icon', 'Class': 'p-0 [&>svg]:size-4', 'AriaLabel': og_s(v_closeLabel), 'Attrs': og_attrs(['tabindex', -1, 'data-slot', 'editor-tab-close'])}, 'children': c_2}) }}
  {%- endset -%}
  {{ og_include('compose/inline.html.j2', {'p': {'Class': 'flex h-10 items-center gap-2 px-3', 'Attrs': og_attrs(['data-slot', 'editor-tab-content'])}, 'children': c_3}) }}
{%- endset -%}
{{ og_include('compose/box.html.j2', {'p': {'Class': og_s(og_cnv(['flex h-10 shrink-0 cursor-pointer flex-col justify-center data-[state=active]:bg-card [&_svg]:text-muted-foreground', 'border-r border-border', og_def(p['className'], '')])), 'Attrs': og_attrs(['role', 'tab', 'aria-selected', v_active, 'tabindex', (0 if og_t(v_active) else -1), 'data-slot', 'editor-tab', 'data-state', ('active' if og_t(v_active) else 'default')])}, 'children': c_4}) }}

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.

An editor file tab (40 px high): a file icon, the label and a close button. `preview` marks a tab that is not pinned yet. Keyboard (Enter and Space activate, Delete closes) is the programmer's behind the click and close events.

Props of EditorTab
PropTypeDefault Description
label (required)string-
closeLabel (required)string-accessible name of the close button, e.g. "Close index.tsx"
active booleanfalsethe selected tab
preview booleanfalsenot pinned yet (italic)