본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

폴더

원문 보기 위키 갱신

폴더 (Folder)

Folder는 계층적 파일 구조를 표시하는 파일 트리 컴포넌트예요. 파일 선택과 확장/축소 기능이 필요할 때 사용해요.

출처: 문서

본문

언제 사용하나요

  • 계층적 파일/폴더 구조를 표시할 때
  • 파일 선택과 확장/축소 기능이 필요할 때

코드 예제

API

공통 props 참고: 공통 props

FolderProps

속성 설명 타입 기본값 버전
treeData 파일 트리 데이터 FolderTreeData[] [] -
selectable 선택 기능을 활성화할지 여부 boolean true -
selectedFile 선택된 파일 경로(제어형) string[] - -
defaultSelectedFile 기본으로 선택된 파일 경로 string[] [] -
onSelectedFileChange 파일 선택이 바뀔 때 호출되는 콜백 (file: { path: string[]; name?: string; content?: string }) => void - -
directoryTreeWith 디렉터리 트리 너비 number | string 278 -
emptyRender 비어 있을 때 표시할 콘텐츠예요. false로 설정하면 숨겨요 false | 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 모든 노드를 기본으로 확장할지 여부 boolean true -
onExpandedPathsChange 확장/축소가 바뀔 때 호출되는 콜백 (paths: string[]) => void - -
fileContentService 파일 콘텐츠 서비스 FileContentService - -
onFileClick 파일 클릭 이벤트 (filePath: string, content?: string) => void - -
onFolderClick 폴더 클릭 이벤트 (folderPath: string) => void - -
directoryTitle 디렉터리 트리 제목이에요. false로 설정하면 숨겨요 false | React.ReactNode | (() => React.ReactNode) - -
previewTitle 파일 미리보기 제목 string | (({ title, path, content }: { title: string; path: string[]; content: string }) => React.ReactNode) - -
directoryIcons 커스텀 아이콘 설정이에요. false로 설정하면 아이콘을 숨겨요 false | Record<'directory' | string, React.ReactNode | (() => React.ReactNode)> - -
contextMenu 우클릭 컨텍스트 메뉴 항목이에요. 전역 설정과 함수 형태(노드에 따라 동적으로 메뉴 항목 반환)를 지원해요. 함수 형태는 노드 데이터와 전체 경로 키를 받아요. FolderTreeData의 contextMenu로 덮어쓸 수 있어요 MenuProps['items'] | ((node: FolderTreeData, key: string) => MenuProps['items']) - -
onRightClick 노드를 우클릭했을 때 호출되는 콜백 function({event, node}) - -

FolderTreeData

속성 설명 타입 기본값 버전
title 표시 이름 string - -
path 파일 경로 string - -
content 파일 콘텐츠(선택 사항) string - -
children 하위 항목(폴더 타입에만 유효) FolderTreeData[] - -
contextMenu 우클릭 컨텍스트 메뉴 항목이에요. false로 설정하면 이 노드의 컨텍스트 메뉴를 비활성화해요. 전역 contextMenu보다 우선해요. 함수 형태는 전체 경로 키를 받아요 MenuProps['items'] | false | ((key: string) => MenuProps['items']) - -

FileContentService

파일 콘텐츠 서비스 인터페이스예요. 파일 콘텐츠를 동적으로 로드하는 데 사용해요.

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

Ref 메서드

ref를 통해 컴포넌트 인스턴스 메서드에 접근할 수 있어요.

const folderRef = useRef<FolderRef>(null);

// Get a node
const node = folderRef.current?.getNode(['src', 'App.tsx']);

// Rename: immutable update, returns new treeData
const newData = folderRef.current?.updateNode(['src', 'App.tsx'], {
  title: 'Main.tsx',
  path: 'Main.tsx',
});

// Delete a node
const newData = folderRef.current?.deleteNode(['src', 'unused.ts']);

// Add a child node
const newData = folderRef.current?.addNode(['src'], {
  title: 'new.ts',
  path: 'new.ts',
  content: '',
});
메서드 설명 타입
getNode 경로로 노드 데이터를 가져와요 (path: string[]) => FolderTreeData | undefined
updateNode 불변 업데이트예요. 대상 노드에 일부 필드를 병합하고 새 treeData를 반환해요 (path: string[], data: Partial<FolderTreeData>) => FolderTreeData[]
deleteNode 불변 업데이트예요. 대상 노드를 삭제하고 새 treeData를 반환해요 (path: string[]) => FolderTreeData[]
addNode 불변 업데이트예요. 대상 폴더 아래에 자식 노드를 추가하고 새 treeData를 반환해요 (parentPath: string[], node: FolderTreeData) => FolderTreeData[]

Semantic DOM

Design Token

더 알아보기

공통 props는 common-props 문서를, X-Card 기반 렌더링은 A2UI v0.9 문서를 참고하세요.