문서 보관함
같은 종류의 파일이 쌓이는 화면이에요. 종류로 나누고 미리보기를 보며 골라요. 새로 만들 때는 메뉴에서 어떤 문서인지 골라요.
언제 써요
문서 · 사진 · 디자인 파일처럼 생김새를 보고 고르는 것이 쌓일 때 써요.
화면 구조
위에서 아래 순서예요. 틀은 화면 틀 2 · 왼쪽 메뉴형이에요(GNB 의 화면 틀).
- 화면 제목무엇의 보관함인지와 한 줄 설명. 오른쪽에 올리기와 새 문서. 새 문서는 메뉴에서 만들 문서를 골라요
- 종류 탭전체 · 문서 · 시트처럼 종류로 나누고 옆에 건수를 붙여요
- 검색 · 정렬 줄왼쪽에 이름 검색, 오른쪽 끝에 정렬
- 파일 카드미리보기 · 이름 · 만든 사람과 때. 새로 들어온 파일은 New, 오른쪽 위 더보기에서 열기 · 공유 · 삭제
쓰는 컴포넌트
App ShellGNBLNBPage HeaderTabsInput FieldSelectCardContext MenuButton
Guidelines
✓ DO
- 처음 비어 있을 때와 검색 결과가 없을 때 문구를 다르게 써요
- 더보기 메뉴는 자주 쓰는 순서로 두고, 삭제는 맨 아래에 선으로 나눠요
- 무엇을 고르는지 설명이 필요한 메뉴(새 문서)에만 설명 항목을 써요
✗ DON'T
- 카드마다 버튼을 여러 개 늘어놓지 않아요(더보기 하나로 모아요)
- 카드 크기를 파일마다 다르게 하지 않아요
- 종류 탭을 세그먼트 컨트롤로 만들지 않아요
좁은 화면에서
- 왼쪽 메뉴는 숨고 맨 위 햄버거로 열어요
- 카드 열이 화면 폭에 맞춰 줄어요
쓰는 법
내 프로젝트에 PDS를 설치했다면
컴포넌트처럼 가져와 써요. AI에게 “PDS 문서 보관함 템플릿으로”라고 해도 돼요.
import { LibraryTemplate } from '@polarisoffice/pds-react';PDS가 없는 AI에게 원본 코드를 통째로 주려면
Template code
파일 하나예요. 위 미리보기가 이 코드를 그대로 그려요. 견본 데이터(상수)를 앱 데이터로 바꿔 쓰세요.
'use client';
import { useEffect, useMemo, useRef, useState, type CSSProperties, type ReactNode } from 'react';
import { createPortal } from 'react-dom';
import {
AppShell,
Button,
CalendarIcon,
DownloadIcon,
Gnb,
IconButton,
LibraryTemplate,
Lnb,
Menu,
MenuDivider,
MenuItem,
MoreIcon,
SearchIcon,
Select,
UserIcon,
} from '@polarisoffice/pds-react';
/**
* 템플릿 · 문서 보관함
* 같은 종류의 파일이 쌓이는 화면 — 종류 탭으로 나누고, 미리보기가 있는 카드를 깔아 고른다.
* [새 문서] 는 아이콘과 설명이 있는 메뉴로 어떤 문서를 만들지 고르게 한다.
* 화면 틀 2(GNB + 왼쪽 LNB). 데이터는 지어낸 견본이다. 실제 앱에서는 DOCS 를 서버 응답으로 바꾼다.
*/
type Kind = 'doc' | 'sheet' | 'slide' | 'pdf';
type Doc = { id: string; name: string; kind: Kind; by: string; when: string; isNew?: boolean };
const DOCS: Doc[] = [
{ id: '1', name: '하반기 사업 계획.pptx', kind: 'slide', by: '김하늘', when: '10분 전', isNew: true },
{ id: '2', name: '2분기 매출 정리.xlsx', kind: 'sheet', by: '박서준', when: '어제' },
{ id: '3', name: '서비스 이용 약관.docx', kind: 'doc', by: '이도윤', when: '3일 전' },
{ id: '4', name: '공급 계약서.pdf', kind: 'pdf', by: '최유나', when: '10월 21일' },
{ id: '5', name: '신규 서비스 소개.pptx', kind: 'slide', by: '정예린', when: '10월 20일' },
{ id: '6', name: '팀별 예산 현황.xlsx', kind: 'sheet', by: '김하늘', when: '10월 18일' },
{ id: '7', name: '11월 회의록.docx', kind: 'doc', by: '한지우', when: '10월 17일', isNew: true },
{ id: '8', name: '견적서_폴라리스.pdf', kind: 'pdf', by: '박서준', when: '10월 15일' },
];
const FORMAT: Record<Kind, { label: string; tab: string; color: string }> = {
doc: { label: 'DOCX', tab: '문서', color: 'var(--color-format-word)' },
sheet: { label: 'XLSX', tab: '시트', color: 'var(--color-format-sheet)' },
slide: { label: 'PPTX', tab: '슬라이드', color: 'var(--color-format-slide)' },
pdf: { label: 'PDF', tab: 'PDF', color: 'var(--color-format-pdf)' },
};
const SORT_OPTIONS = [
{ value: 'recent', label: '최근 수정순' },
{ value: 'name', label: '이름순' },
];
/** 메뉴 아이콘 — 패키지에 없는 모양만 여기서 그려요(18, 선 1.7) */
const Glyph = ({ d }: { d: string }) => (
<svg width={18} height={18} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={1.7} strokeLinecap="round" strokeLinejoin="round" aria-hidden>
<path d={d} />
</svg>
);
const FILE = 'M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7ZM14 2v4a2 2 0 0 0 2 2h4';
const ICON = {
filePlus: <Glyph d={`${FILE}M9 15h6M12 12v6`} />,
fileText: <Glyph d={`${FILE}M16 13H8M16 17H8M10 9H8`} />,
book: <Glyph d="M12 7v14M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z" />,
open: <Glyph d="M15 3h6v6M10 14 21 3M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" />,
rename: <Glyph d="M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497zM15 5l4 4" />,
share: <Glyph d="M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8M16 6l-4-4-4 4M12 2v13" />,
trash: <Glyph d="M3 6h18M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2M10 11v6M14 11v6" />,
};
/** [새 문서] 메뉴 — 기능을 고르는 메뉴라 설명 항목(아이콘 + 한 줄 설명)을 써요 */
const NEW_DOC = [
{ icon: ICON.filePlus, label: '빈 문서', description: '아무것도 없는 문서에서 시작해요.' },
{ icon: ICON.book, label: '회의록', description: '참석자, 안건, 결정한 것을 나눠 적어요.' },
{ icon: <CalendarIcon size={16} />, label: '주간 보고', description: '지난주 한 일과 이번 주 할 일을 정리해요.' },
{ icon: ICON.fileText, label: '제안서', description: '배경, 제안, 일정, 비용 순서로 써요.' },
];
/**
* 버튼에 붙여 여는 메뉴. 카드는 모서리 때문에 넘치는 걸 잘라서 메뉴를 body 로 꺼내(portal) 버튼 끝에 맞춰요.
* 화면 아래쪽 버튼이면 위로 열고, 바깥을 누르거나 Esc · 스크롤이면 닫혀요.
*/
function MenuButton({
width,
trigger,
children,
}: {
width: number;
trigger: (props: { onClick: () => void; 'aria-expanded': boolean; 'aria-haspopup': 'menu' }) => ReactNode;
children: (close: () => void) => ReactNode;
}) {
const anchor = useRef<HTMLSpanElement>(null);
const panel = useRef<HTMLDivElement>(null);
const [pos, setPos] = useState<CSSProperties | null>(null);
const close = () => setPos(null);
useEffect(() => {
if (!pos) return;
const onDown = (e: MouseEvent) => {
const t = e.target as Node;
if (!panel.current?.contains(t) && !anchor.current?.contains(t)) close();
};
const onKey = (e: KeyboardEvent) => e.key === 'Escape' && close();
document.addEventListener('mousedown', onDown);
document.addEventListener('keydown', onKey);
window.addEventListener('scroll', close, true);
window.addEventListener('resize', close);
return () => {
document.removeEventListener('mousedown', onDown);
document.removeEventListener('keydown', onKey);
window.removeEventListener('scroll', close, true);
window.removeEventListener('resize', close);
};
}, [pos]);
const toggle = () => {
if (pos) return close();
const r = anchor.current!.getBoundingClientRect();
const left = Math.max(8, r.right - width);
setPos(r.top > window.innerHeight / 2 ? { left, bottom: window.innerHeight - r.top + 4 } : { left, top: r.bottom + 4 });
};
return (
<span ref={anchor} style={{ display: 'inline-flex' }}>
{trigger({ onClick: toggle, 'aria-expanded': pos != null, 'aria-haspopup': 'menu' })}
{pos &&
createPortal(
<div ref={panel} style={{ position: 'fixed', zIndex: 100, ...pos }}>
<Menu width={width}>{children(close)}</Menu>
</div>,
document.body,
)}
</span>
);
}
/** 미리보기 자리 견본 — 실제 앱에서는 썸네일 이미지(<img>)를 넣어요 */
function Thumb({ kind }: { kind: Kind }) {
const f = FORMAT[kind];
const wide = kind === 'slide' || kind === 'sheet';
return (
<>
<span
style={{
display: 'flex',
flexDirection: 'column',
gap: 6,
boxSizing: 'border-box',
width: wide ? 168 : 88,
height: wide ? 100 : 116,
padding: 12,
borderRadius: 4,
borderTop: `6px solid ${f.color}`,
background: 'var(--color-background-base)',
boxShadow: 'var(--shadow-sm)',
}}
>
{['60%', '100%', '85%', '100%', '70%'].map((w, i) => (
<span key={i} style={{ width: w, height: 4, borderRadius: 2, background: 'var(--color-fill-strong)' }} />
))}
</span>
<span
style={{
position: 'absolute',
left: 12,
bottom: 12,
display: 'inline-flex',
alignItems: 'center',
gap: 6,
height: 24,
padding: '0 8px',
borderRadius: 6,
border: '1px solid var(--color-line-neutral)',
background: 'var(--color-background-base)',
fontSize: 12,
fontWeight: 700,
color: 'var(--color-label-neutral)',
}}
>
<span style={{ width: 8, height: 8, borderRadius: 2, background: f.color }} />
{f.label}
</span>
</>
);
}
export type LibraryTemplateState = 'ready' | 'empty' | 'loading';
export default function LibraryScreen({ state = 'ready' }: { state?: LibraryTemplateState }) {
const [tab, setTab] = useState<'all' | Kind>('all');
const [query, setQuery] = useState('');
const [sort, setSort] = useState('recent');
const source = state === 'ready' ? DOCS : [];
const count = (k?: Kind) => source.filter((d) => !k || d.kind === k).length;
const docs = useMemo(() => {
const list = source.filter((d) => (tab === 'all' || d.kind === tab) && (!query || d.name.includes(query)));
return sort === 'name' ? [...list].sort((a, b) => a.name.localeCompare(b.name, 'ko')) : list;
}, [source, tab, query, sort]);
const newDocMenu = (
<MenuButton width={320} trigger={(p) => <Button {...p}>새 문서</Button>}>
{(close) => NEW_DOC.map((m) => <MenuItem key={m.label} icon={m.icon} label={m.label} description={m.description} onClick={close} />)}
</MenuButton>
);
return (
<AppShell
gnb={
<Gnb
brand={<span>문서함</span>}
actions={
<>
<IconButton size={32} aria-label="검색" icon={<SearchIcon />} />
<IconButton size={32} aria-label="내 정보" icon={<UserIcon />} />
</>
}
/>
}
lnb={
<Lnb
sections={[
{ label: '문서', items: [{ label: '홈', href: '#' }, { label: '내 문서', href: '#', active: true }, { label: '공유받은 문서', href: '#' }] },
{ label: '보관', items: [{ label: '즐겨찾기', href: '#' }, { label: '휴지통', href: '#' }, { label: '설정', href: '#' }] },
]}
/>
}
>
<LibraryTemplate
title="내 문서"
description="내가 만들거나 올린 문서예요. 최근에 고친 순서로 보여요."
moreActions={[{ label: '올리기' }]}
actions={newDocMenu}
tabs={[
{ value: 'all', label: '전체', count: count() },
...(['doc', 'sheet', 'slide', 'pdf'] as Kind[]).map((k) => ({ value: k, label: FORMAT[k].tab, count: count(k) })),
]}
tab={tab}
onTabChange={(v) => setTab(v as 'all' | Kind)}
search={{ value: query, onChange: setQuery, placeholder: '문서 이름 검색' }}
toolbarEnd={<Select size="sm" width={140} options={SORT_OPTIONS} value={sort} onChange={setSort} />}
loading={state === 'loading'}
empty={
source.length === 0
? { title: '아직 문서가 없어요', description: '새 문서를 만들거나 내 컴퓨터의 파일을 올려 보세요.', action: newDocMenu }
: { title: '찾는 문서가 없어요', description: '검색어나 종류를 바꿔 보세요.' }
}
items={docs.map((d) => ({
id: d.id,
media: <Thumb kind={d.kind} />,
isNew: d.isNew,
title: d.name,
description: `${d.by} · ${d.when}`,
action: (
<MenuButton width={176} trigger={(p) => <IconButton {...p} size={28} icon={<MoreIcon />} aria-label={`${d.name} 더보기`} />}>
{(close) => (
<>
<MenuItem icon={ICON.open} label="열기" onClick={close} />
<MenuItem icon={ICON.rename} label="이름 바꾸기" onClick={close} />
<MenuItem icon={ICON.share} label="공유" onClick={close} />
<MenuItem icon={<DownloadIcon size={16} />} label="내려받기" onClick={close} />
<MenuDivider />
<MenuItem icon={ICON.trash} label="삭제" onClick={close} />
</>
)}
</MenuButton>
),
}))}
/>
</AppShell>
);
}
Specification
| 자리 | 값 |
|---|---|
| 본문 폭 | Container size="lg" (최대 1200) |
| 제목 · 탭 묶음 · 카드 | Stack gap="lg" (24) |
| 탭 ↔ 검색 줄 | Stack gap="sm" (16) |
| 카드 목록 | grid repeat(auto-fill, minmax(240px, 1fr)), 사이 16 |
| 검색 · 정렬 | InputField · Select size="sm" (32), 검색 폭 280 |
| 새 문서 메뉴 | Menu 폭 320, MenuItem icon + description |
| 더보기 메뉴 | Menu 폭 176, MenuItem icon, 삭제 앞 MenuDivider |
Implementation Notes
- state prop(ready · empty · loading)은 미리보기 전환용이에요. 실제 앱에서는 요청 상태로 바꿔요
- 메뉴를 여는 부품이 아직 PDS 에 없어서 템플릿 안 MenuButton 이 버튼 자리에 Menu 를 띄워요. Card 는 모서리 밖을 잘라서 메뉴를 body 로 꺼내요(createPortal)
- Card media 에는 실제 썸네일 이미지를 넣어요. 템플릿의 Thumb 는 자리 견본이에요
- 미디어가 있는 카드의 isNew 는 미리보기 오른쪽 위에 떠요