Add shared dock layouts, navigation cube, range bands, progress actions and comparison surfaces. Extend toolbar menus and loading composition, and align tokens, registry entries, documentation and the living catalog.
92 lines
3.0 KiB
TypeScript
92 lines
3.0 KiB
TypeScript
import { useLayoutEffect, useRef, type ReactNode } from "react";
|
|
import { HeaderAvatar } from "./AppHeader.js";
|
|
import { Icon, type IconName } from "./Icon.js";
|
|
import { Window } from "./Window.js";
|
|
|
|
export interface FeatureSettingsSection<T extends string = string> {
|
|
id: T;
|
|
label: ReactNode;
|
|
group?: string;
|
|
icon?: IconName;
|
|
disabled?: boolean;
|
|
}
|
|
|
|
export interface FeatureSettingsWindowProps<T extends string = string> {
|
|
open: boolean;
|
|
title: ReactNode;
|
|
subtitle?: ReactNode;
|
|
identity: {
|
|
title: ReactNode;
|
|
subtitle?: ReactNode;
|
|
avatarLabel: string;
|
|
avatarUrl?: string;
|
|
};
|
|
sections: readonly FeatureSettingsSection<T>[];
|
|
activeSection: T;
|
|
onSectionChange: (section: T) => void;
|
|
onClose: () => void;
|
|
children: ReactNode;
|
|
footer?: ReactNode;
|
|
headerActions?: ReactNode;
|
|
}
|
|
|
|
export function FeatureSettingsWindow<T extends string>({
|
|
open,
|
|
title,
|
|
subtitle,
|
|
identity,
|
|
sections,
|
|
activeSection,
|
|
onSectionChange,
|
|
onClose,
|
|
children,
|
|
footer,
|
|
headerActions,
|
|
}: FeatureSettingsWindowProps<T>) {
|
|
const contentRef = useRef<HTMLElement>(null);
|
|
useLayoutEffect(() => { if (contentRef.current) contentRef.current.scrollTop = 0; }, [activeSection]);
|
|
return (
|
|
<Window
|
|
open={open}
|
|
title={title}
|
|
subtitle={subtitle}
|
|
size="lg"
|
|
className="nodedc-feature-settings-window"
|
|
footer={footer}
|
|
headerActions={headerActions}
|
|
closeOnBackdrop={false}
|
|
onClose={onClose}
|
|
>
|
|
<div className="nodedc-feature-settings">
|
|
<aside className="nodedc-feature-settings__navigation" aria-label="Разделы настроек" tabIndex={0}>
|
|
<div className="nodedc-feature-settings__identity">
|
|
<HeaderAvatar label={identity.avatarLabel} imageUrl={identity.avatarUrl} />
|
|
<span><strong>{identity.title}</strong>{identity.subtitle ? <small>{identity.subtitle}</small> : null}</span>
|
|
</div>
|
|
<nav>
|
|
{sections.map((section, index) => {
|
|
const showGroup = section.group && section.group !== sections[index - 1]?.group;
|
|
return (
|
|
<div key={section.id} className="nodedc-feature-settings__navigation-entry">
|
|
{showGroup ? <span className="nodedc-feature-settings__group">{section.group}</span> : null}
|
|
<button
|
|
type="button"
|
|
className="nodedc-feature-settings__section"
|
|
data-active={section.id === activeSection ? "true" : undefined}
|
|
disabled={section.disabled}
|
|
onClick={() => onSectionChange(section.id)}
|
|
>
|
|
{section.icon ? <Icon name={section.icon} size={16} /> : null}
|
|
<span>{section.label}</span>
|
|
</button>
|
|
</div>
|
|
);
|
|
})}
|
|
</nav>
|
|
</aside>
|
|
<section ref={contentRef} className="nodedc-feature-settings__content" aria-label="Содержимое настроек" tabIndex={0}>{children}</section>
|
|
</div>
|
|
</Window>
|
|
);
|
|
}
|