logoAnt Design X

设计研发组件X MarkdownX SDKX Skill演示国内镜像
  • 介绍
  • 总览
  • 通用
    • Bubble对话气泡
    • Conversations管理对话
    • Notification系统通知
      2.0.0
  • 唤醒
    • Welcome欢迎
    • Prompts提示集
  • 确认
    • Think思考过程
      2.0.0
    • ThoughtChain思维链
      2.0.0
  • 表达
    • Attachments输入附件
    • Sender输入框
    • Suggestion快捷指令
  • 反馈
    • Actions操作列表
    • CodeHighlighter代码高亮
      2.1.0
    • FileCard文件卡片
      2.0.0
    • Folder文件夹
      2.4.0
    • Mermaid图表工具
      2.1.0
    • Sources来源引用
      2.0.0
  • 其他
    • XProvider全局化配置

Folder
文件夹

文件树组件,用于展示层级文件结构。
使用import { Folder } from "@ant-design/x";
源码x/components/folder
文档
编辑此页...
版本自 2.4.0 起支持
更新日志
loading

何时使用

  • 展示文件/文件夹层级结构
  • 需要文件选择、展开收起功能

代码演示

API

通用属性参考:通用属性

FolderProps

属性说明类型默认值版本
treeData文件树数据FolderTreeData[][]-
selectable是否开启选择功能booleantrue-
selectedFile选中的文件路径(受控)string[]--
defaultSelectedFile默认选中的文件路径string[][]-
onSelectedFileChange文件选择变化时的回调(file: { path: string[]; name?: string; content?: string }) => void--
directoryTreeWith目录树宽度number | string278-
emptyRender空状态时的展示内容React.ReactNode | (() => React.ReactNode)--
previewRender自定义文件预览内容React.ReactNode | ((file: { content?: string; path: string[]; title?: React.ReactNode; language: string }, info: { originNode: React.ReactNode }) => React.ReactNode)--
expandedPaths展开的节点路径数组(受控)string[]--
defaultExpandedPaths默认展开的节点路径数组string[]--
defaultExpandAll是否默认展开所有节点booleantrue-
onExpandedPathsChange展开/收起变化时的回调(paths: string[]) => void--
fileContentService文件内容服务FileContentService--
onFileClick文件点击事件(filePath: string, content?: string) => void--
onFolderClick文件夹点击事件(folderPath: string) => void--
directoryTitle目录树标题React.ReactNode | (() => React.ReactNode)--
previewTitle文件预览标题string | (({ title, path, content }: { title: string; path: string[]; content: string }) => React.ReactNode)--
directoryIcons自定义图标配置Record<'directory' | string, React.ReactNode | (() => React.ReactNode)>--

FolderTreeData

属性说明类型默认值版本
title显示名称string--
path文件路径string--
content文件内容(可选)string--
children子项(仅文件夹类型有效)FolderTreeData[]--

FileContentService

文件内容服务接口,用于动态加载文件内容。

typescript
interface FileContentService {
loadFileContent(filePath: string): Promise<string>;
}

语义化 DOM

主题变量(Design Token)

组件 Token如何定制?
Token 名称描述类型默认值
colorBgDirectory目录背景色stringrgba(0,0,0,0.04)
全局 Token如何定制?
use-x-chat
SKILL.md
reference
API.md
CORE.md
EXAMPLES.md
暂无数据
请选择一个文件
基本用法

基础用法。

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
x-request
SKILL.md
reference
API.md
CORE.md
EXAMPLES_SERVICE_PROVIDER.md
暂无数据
请选择一个文件
自定义文件服务

自定义文件内容服务。

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Current Selected File:None
Project File Browser
x-chat-provider
SKILL.md
reference
EXAMPLES.md
暂无数据
请选择一个文件
受控文件选择

受控文件选择。

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Current Selected File: use-x-chat/SKILL.md
Expanded Nodes: use-x-chat
File Browser
use-x-chat
SKILL.md
reference
API.md
CORE.md
EXAMPLES.md
暂无数据
请选择一个文件
完全受控模式

完全受控模式。

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Total Files: 12
Matching Results: 12
Project File Browser
project-root
src
components
Header.tsx
Footer.tsx
Sidebar.tsx
pages
Home.tsx
About.tsx
Contact.tsx
utils
helpers.ts
constants.ts
public
index.html
favicon.ico
package.json
README.md
暂无数据
请选择一个文件
可搜索的文件树

可搜索的文件浏览器。

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Custom Icon File Browser
Display different icons based on file type
my-project
docs
README.md
API.pdf
src
components
Button.tsx
styles.css
utils
helpers.ts
assets
logo.png
banner.jpg
data
users.xlsx
report.docx
archive.zip
package.json
暂无数据
请选择一个文件
自定义图标

自定义文件图标。

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
项目文件浏览器
src
components
Button.tsx
Input.tsx
utils
helper.ts
package.json
暂无数据
请选择一个文件
  • root
    根节点
  • directoryTree
    目录树容器
  • directoryTitle
    目录树标题
  • filePreview
    文件预览容器
  • previewTitle
    预览标题
  • previewRender
    预览内容
自定义预览内容

使用 previewRender 属性自定义文件预览内容。

previewRender 支持两种形式:

  • ReactNode:直接渲染自定义内容
  • 函数形式:(file, info) => ReactNode,其中:
    • file: 包含文件信息的对象 { content, path, title, language }
    • info: 包含原始预览节点的对象 { originNode }
CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
src
index.js
App.tsx
package.json
暂无数据
请选择一个文件