Files
NODEDC_DESIGN_GUIDELINE/packages/ui-dom/src/pathBar.ts
T

20 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
export type PathBarItem = { label: string; path: string; kind: 'folder' | 'file'; current?: boolean };
/** Compact Finder-style path row. Navigation and icon source belong to the app. */
export function renderPathBar(target: HTMLElement, items: PathBarItem[], options: { onNavigate: (path: string) => void; icon: (kind: 'folder' | 'file') => Node }) {
target.classList.add('nodedc-path-bar');
target.setAttribute('role', 'navigation'); target.setAttribute('aria-label', 'Путь к файлу');
const nodes: Node[] = [];
items.forEach((item, index) => {
if (index) { const separator = document.createElement('span'); separator.className = 'nodedc-path-bar__separator'; separator.textContent = '›'; separator.setAttribute('aria-hidden', 'true'); nodes.push(separator); }
const part = document.createElement(item.kind === 'folder' ? 'button' : 'span');
part.className = 'nodedc-path-bar__item'; part.title = item.path || item.label;
if (item.current) part.setAttribute('aria-current', 'location');
const icon = document.createElement('span'); icon.className = 'nodedc-path-bar__icon'; icon.setAttribute('aria-hidden', 'true'); icon.append(options.icon(item.kind));
const text = document.createElement('span'); text.textContent = item.label;
part.append(icon, text);
if (part instanceof HTMLButtonElement) { part.type = 'button'; part.addEventListener('click', () => options.onNavigate(item.path)); }
nodes.push(part);
});
target.replaceChildren(...nodes);
}