import { cn } from '@intlayer/design-system/utils'; import type { LucideIcon } from 'lucide-react'; import type { ReactNode } from 'react'; import { useIntlayer } from 'react-intlayer'; import { useHashSection } from './useHashSection'; export type SettingsSection = { /** Stable id, also used as the URL hash (`#members`). */ id: SectionId; label: string; icon: LucideIcon; content: ReactNode; /** `danger` renders the entry in the error color, set apart at the end. */ tone?: 'default' | 'danger'; }; type SettingsSectionLayoutProps = { sections: SettingsSection[]; className?: string; }; /** * Settings page split into sections: a vertical navigation on desktop (a * horizontally scrolling row on mobile) and only the active section rendered. * The active section lives in the URL hash so it survives reloads and can be * linked to. */ export const SettingsSectionLayout = ({ sections, className, }: SettingsSectionLayoutProps) => { const { navigationLabel } = useIntlayer('settings-section-layout'); const [activeSectionId, setActiveSectionId] = useHashSection( sections.map((section) => section.id) ); const activeSection = sections.find((section) => section.id === activeSectionId) ?? sections[0]; if (!activeSection) return null; return (
{activeSection.content}
); };