File Tree Item
File Tree Item component
Install
npx ui8kit add file-tree-itemPulls in: button-plain, compose, inline, kit-button, kit-text, lucide-icon, presets, 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-cdnnpx ui8kit add file-tree-item<!-- 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 row of a file tree: a folder with a disclosure chevron, or a file. The glyphs are Lucide. -->
<script lang="ts" module>
import type { Snippet } from "svelte";
import { variants } from "../utils";
/** FileTreeItem: the classes of each value (shadcn/cva style). */
export const fileTreeItemVariants = variants({
base: "flex h-6 w-full items-center gap-4 text-xs font-bold text-muted-foreground data-[state=selected]:bg-muted",
variants: {
kind: {
folder: "",
file: "px-8",
},
},
defaultVariants: { kind: "file" },
});
export type FileTreeItemProps = {
kind?: "folder" | "file";
label: string;
selected?: boolean;
expanded?: boolean;
class?: string;
onclick?: () => void;
};
</script>
<script lang="ts">
import ButtonPlain from "../compose/ButtonPlain.svelte";
import Inline from "../compose/Inline.svelte";
import LucideIcon from "../icons/LucideIcon.svelte";
import { cn } from "../utils";
let {
kind = "file",
label,
selected = false,
expanded = false,
class: className,
onclick,
}: FileTreeItemProps = $props();
</script>
<ButtonPlain
type="button"
role="treeitem"
class={cn(fileTreeItemVariants({ kind: kind }), className)}
aria-selected={selected}
tabindex={(selected ? 0 : -1)}
aria-expanded={(((kind as string) === "folder") ? expanded : undefined)}
data-slot="file-tree-item"
data-kind={kind}
data-state={(selected ? "selected" : "default")}
onclick={() => onclick?.()}
>
{#if ((kind as string) === "folder")}
<LucideIcon name={(expanded ? "chevron-down" : "chevron-right")} size={16} />
<LucideIcon name="folder-open" size={16} />
{:else}
<LucideIcon name="file" size={16} />
{/if}
<Inline class="whitespace-nowrap" data-slot="file-tree-label">
{label}
</Inline>
</ButtonPlain>
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-cdnnpx ui8kit add file-tree-item// 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 row of a file tree: a folder with a disclosure chevron, or a file. The glyphs are Lucide. */
import { type ReactNode } from "react";
import { ButtonPlain, Inline } from "../compose";
import { LucideIcon } from "../icons/LucideIcon";
import { cn, variants } from "../utils";
/** FileTreeItem: the classes of each value (shadcn/cva style). */
export const fileTreeItemVariants = variants({
base: "flex h-6 w-full items-center gap-4 text-xs font-bold text-muted-foreground data-[state=selected]:bg-muted",
variants: {
kind: {
folder: "",
file: "px-8",
},
},
defaultVariants: { kind: "file" },
});
export type FileTreeItemProps = {
kind?: "folder" | "file";
label: string;
selected?: boolean;
expanded?: boolean;
className?: string;
onClick?: () => void;
};
export function FileTreeItem({
kind = "file",
label,
selected = false,
expanded = false,
className,
onClick,
}: FileTreeItemProps) {
return (
<ButtonPlain
type="button"
role="treeitem"
className={cn(fileTreeItemVariants({ kind: kind }), className)}
aria-selected={selected}
tabIndex={(selected ? 0 : -1)}
aria-expanded={(((kind as string) === "folder") ? expanded : undefined)}
data-slot="file-tree-item"
data-kind={kind}
data-state={(selected ? "selected" : "default")}
onClick={() => onClick?.()}
>
{((kind as string) === "folder") ? (
<>
<LucideIcon name={(expanded ? "chevron-down" : "chevron-right")} size={16} />
<LucideIcon name="folder-open" size={16} />
</>
) : (
<LucideIcon name="file" size={16} />
)}
<Inline className="whitespace-nowrap" data-slot="file-tree-label">
{label}
</Inline>
</ButtonPlain>
);
}
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-cdnnpx ui8kit add file-tree-item<!-- 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 row of a file tree: a folder with a disclosure chevron, or a file. The glyphs are Lucide. -->
<script lang="ts">
import { variants } from "../utils";
/** FileTreeItem: the classes of each value (shadcn/cva style). */
export const fileTreeItemVariants = variants({
base: "flex h-6 w-full items-center gap-4 text-xs font-bold text-muted-foreground data-[state=selected]:bg-muted",
variants: {
kind: {
folder: "",
file: "px-8",
},
},
defaultVariants: { kind: "file" },
});
export type FileTreeItemProps = {
kind?: "folder" | "file";
label: string;
selected?: boolean;
expanded?: boolean;
class?: string;
};
</script>
<script setup lang="ts">
import ButtonPlain from "../compose/ButtonPlain.vue";
import Inline from "../compose/Inline.vue";
import LucideIcon from "../icons/LucideIcon.vue";
import { cn } from "../utils";
const {
kind = "file",
label,
selected = false,
expanded = false,
class: className,
} = defineProps<FileTreeItemProps>();
const emit = defineEmits<{ click: [] }>();
</script>
<template>
<ButtonPlain
type="button"
role="treeitem"
:class="cn(fileTreeItemVariants({ kind: kind }), className)"
:aria-selected="selected"
:tabindex="(selected ? 0 : -1)"
:aria-expanded="(((kind as string) === 'folder') ? expanded : undefined)"
data-slot="file-tree-item"
:data-kind="kind"
:data-state="(selected ? 'selected' : 'default')"
@click="() => emit('click')"
>
<template v-if="((kind as string) === 'folder')">
<LucideIcon :name="(expanded ? 'chevron-down' : 'chevron-right')" :size="16" />
<LucideIcon name="folder-open" :size="16" />
</template>
<LucideIcon v-else name="file" :size="16" />
<Inline class="whitespace-nowrap" data-slot="file-tree-label">
{{ label }}
</Inline>
</ButtonPlain>
</template>
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-cdnnpx ui8kit add file-tree-item// 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 row of a file tree: a folder with a disclosure chevron, or a file. The glyphs are Lucide. */
import { type JSX } from "solid-js";
import { ButtonPlain, Inline } from "../compose";
import { LucideIcon } from "../icons/LucideIcon";
import { cn, variants } from "../utils";
/** FileTreeItem: the classes of each value (shadcn/cva style). */
export const fileTreeItemVariants = variants({
base: "flex h-6 w-full items-center gap-4 text-xs font-bold text-muted-foreground data-[state=selected]:bg-muted",
variants: {
kind: {
folder: "",
file: "px-8",
},
},
defaultVariants: { kind: "file" },
});
export type FileTreeItemProps = {
kind?: "folder" | "file";
label: string;
selected?: boolean;
expanded?: boolean;
class?: string;
onClick?: () => void;
};
export function FileTreeItem({
kind = "file",
label,
selected = false,
expanded = false,
class: className,
onClick,
}: FileTreeItemProps) {
return (
<ButtonPlain
type="button"
role="treeitem"
class={cn(fileTreeItemVariants({ kind: kind }), className)}
aria-selected={selected}
tabindex={(selected ? 0 : -1)}
aria-expanded={(((kind as string) === "folder") ? expanded : undefined)}
data-slot="file-tree-item"
data-kind={kind}
data-state={(selected ? "selected" : "default")}
onClick={() => onClick?.()}
>
{((kind as string) === "folder") ? (
<>
<LucideIcon name={(expanded ? "chevron-down" : "chevron-right")} size={16} />
<LucideIcon name="folder-open" size={16} />
</>
) : (
<LucideIcon name="file" size={16} />
)}
<Inline class="whitespace-nowrap" data-slot="file-tree-label">
{label}
</Inline>
</ButtonPlain>
);
}
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-cdnnpx ui8kit add file-tree-item// 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/file-tree-item.json
package blocks
import (
"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"
)
// FileTreeItemProps are the props of FileTreeItem; the values are the JSON shapes of the TypeScript props.
type FileTreeItemProps struct {
Kind any `json:"kind"`
Label any `json:"label"`
Selected any `json:"selected"`
Expanded any `json:"expanded"`
Class string `json:"className"`
}
// A row of a file tree: a folder with a disclosure chevron, or a file. The glyphs are Lucide.
templ FileTreeItem(p FileTreeItemProps) {
{{ vKind := uiutils.Def(p.Kind, "file") }}
{{ vLabel := p.Label }}
{{ vSelected := uiutils.Def(p.Selected, false) }}
{{ vExpanded := uiutils.Def(p.Expanded, false) }}
@compose.ButtonPlain(compose.ButtonPlainProps{ButtonProps: button.ButtonProps{Type: "button", Class: uiutils.S(uiutils.Cnv(recipeFileTreeItem.Of(map[string]any{"kind": vKind}), p.Class)), Attrs: uiutils.Attrs("role", "treeitem", "aria-selected", vSelected, "tabindex", uiutils.Cond(uiutils.T(vSelected), float64(0), float64(-1)), "aria-expanded", uiutils.Cond(uiutils.T(uiutils.Eq(vKind, "folder")), vExpanded, nil), "data-slot", "file-tree-item", "data-kind", vKind, "data-state", uiutils.Cond(uiutils.T(vSelected), "selected", "default"))}}) {
if uiutils.Eq(vKind, "folder") {
@icons.LucideIcon(icons.LucideIconProps{Name: uiutils.S(uiutils.Cond(uiutils.T(vExpanded), "chevron-down", "chevron-right")), Size: 16})
@icons.LucideIcon(icons.LucideIconProps{Name: "folder-open", Size: 16})
} else {
@icons.LucideIcon(icons.LucideIconProps{Name: "file", Size: 16})
}
@compose.Inline(compose.InlineProps{TextProps: text.TextProps{Class: "whitespace-nowrap", Attrs: uiutils.Attrs("data-slot", "file-tree-label")}}) {
{ uiutils.Text(vLabel) }
}
}
}
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-cdnnpx ui8kit add file-tree-item{#- 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/file-tree-item.json
A row of a file tree: a folder with a disclosure chevron, or a file. The glyphs are Lucide.
Props (p): kind, label, selected, expanded, className. -#}
{%- set v_kind = (p.kind ?? 'file') -%}
{%- set v_label = (p.label ?? null) -%}
{%- set v_selected = (p.selected ?? false) -%}
{%- set v_expanded = (p.expanded ?? false) -%}
{%- set c_2 -%}
{%- if og_t(og_eq(v_kind, 'folder')) %}
{{ include('icons/LucideIcon.html.twig', {'name': og_s((og_t(v_expanded) ? 'chevron-down' : 'chevron-right')), 'size': 16}, with_context = false) }}
{{ include('icons/LucideIcon.html.twig', {'name': 'folder-open', 'size': 16}, with_context = false) }}
{%- else %}
{{ include('icons/LucideIcon.html.twig', {'name': 'file', 'size': 16}, with_context = false) }}
{%- endif %}
{%- set c_1 -%}
{{ og_text(v_label) }}
{%- endset -%}
{{ include('compose/Inline.html.twig', {'class': 'whitespace-nowrap', 'attrs': og_attrs(['data-slot', 'file-tree-label']), 'children': c_1}, with_context = false) }}
{%- endset -%}
{{ include('compose/ButtonPlain.html.twig', {'type': 'button', 'class': og_s(og_cnv([og_recipe('blocks/recipes/file-tree-item.variants.json', {'kind': v_kind}), (p.className ?? '')])), 'attrs': og_attrs(['role', 'treeitem', 'aria-selected', v_selected, 'tabindex', (og_t(v_selected) ? 0 : -1), 'aria-expanded', (og_t(og_eq(v_kind, 'folder')) ? v_expanded : null), 'data-slot', 'file-tree-item', 'data-kind', v_kind, 'data-state', (og_t(v_selected) ? 'selected' : 'default')]), 'children': c_2}, with_context = false) }}
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-cdnnpx ui8kit add file-tree-item{* 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/file-tree-item.json
A row of a file tree: a folder with a disclosure chevron, or a file. The glyphs are Lucide.
Props (p): kind, label, selected, expanded, className. *}
{var $v_kind = ($p['kind'] ?? 'file')}
{var $v_label = ($p['label'] ?? null)}
{var $v_selected = ($p['selected'] ?? false)}
{var $v_expanded = ($p['expanded'] ?? false)}
{capture $c_2}
{if og_t(og_eq($v_kind, 'folder'))}
{=og_include('icons/LucideIcon.latte', ['name' => og_s((og_t($v_expanded) ? 'chevron-down' : 'chevron-right')), 'size' => 16])|noescape}
{=og_include('icons/LucideIcon.latte', ['name' => 'folder-open', 'size' => 16])|noescape}
{else}
{=og_include('icons/LucideIcon.latte', ['name' => 'file', 'size' => 16])|noescape}
{/if}
{capture $c_1}
{=og_text($v_label)}
{/capture}
{=og_include('compose/Inline.latte', ['class' => 'whitespace-nowrap', 'attrs' => og_attrs(['data-slot', 'file-tree-label']), 'children' => (string) $c_1])|noescape}
{/capture}
{=og_include('compose/ButtonPlain.latte', ['type' => 'button', 'class' => og_s(og_cnv([og_recipe('blocks/recipes/file-tree-item.variants.json', ['kind' => $v_kind]), ($p['className'] ?? '')])), 'attrs' => og_attrs(['role', 'treeitem', 'aria-selected', $v_selected, 'tabindex', (og_t($v_selected) ? 0 : -1), 'aria-expanded', (og_t(og_eq($v_kind, 'folder')) ? $v_expanded : null), 'data-slot', 'file-tree-item', 'data-kind', $v_kind, 'data-state', (og_t($v_selected) ? 'selected' : 'default')]), 'children' => (string) $c_2])|noescape}
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-cdnnpx ui8kit add file-tree-item{#- 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/file-tree-item.json
A row of a file tree: a folder with a disclosure chevron, or a file. The glyphs are Lucide.
Props (p): kind, label, selected, expanded, className. -#}
{%- set v_kind = og_def(p['kind'], 'file') -%}
{%- set v_label = og_def(p['label'], none) -%}
{%- set v_selected = og_def(p['selected'], false) -%}
{%- set v_expanded = og_def(p['expanded'], false) -%}
{%- set c_2 -%}
{%- if og_t(og_eq(v_kind, 'folder')) %}
{{ og_include('icons/lucide-icon.html.j2', {'p': {'Name': og_s(('chevron-down' if og_t(v_expanded) else 'chevron-right')), 'Size': 16}}) }}
{{ og_include('icons/lucide-icon.html.j2', {'p': {'Name': 'folder-open', 'Size': 16}}) }}
{%- else %}
{{ og_include('icons/lucide-icon.html.j2', {'p': {'Name': 'file', 'Size': 16}}) }}
{%- endif %}
{%- set c_1 -%}
{{ og_text(v_label) }}
{%- endset -%}
{{ og_include('compose/inline.html.j2', {'p': {'Class': 'whitespace-nowrap', 'Attrs': og_attrs(['data-slot', 'file-tree-label'])}, 'children': c_1}) }}
{%- endset -%}
{{ og_include('compose/button-plain.html.j2', {'p': {'Type': 'button', 'Class': og_s(og_cnv([og_recipe('blocks/recipes/file-tree-item.variants.json', {'kind': v_kind}), og_def(p['className'], '')])), 'Attrs': og_attrs(['role', 'treeitem', 'aria-selected', v_selected, 'tabindex', (0 if og_t(v_selected) else -1), 'aria-expanded', (v_expanded if og_t(og_eq(v_kind, 'folder')) else none), 'data-slot', 'file-tree-item', 'data-kind', v_kind, 'data-state', ('selected' if og_t(v_selected) else 'default')])}, 'children': c_2}) }}
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 row of a file tree: a folder with a disclosure chevron, or a file. The glyphs are Lucide.
| Prop | Type | Default | Description |
|---|---|---|---|
| kind | "folder" | "file" | "file" | folder or file |
| label (required) | string | - | |
| selected | boolean | false | the chosen row |
| expanded | boolean | false | an open folder |