Files
swyxweb/frontend/src/components/Tabs.tsx
T
SvenandClaude Opus 5 ae397e1ea3 first commit
SwyxWeb: React-Frontend und Spring-Boot-Backend mit SwyxTray-Mock.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-20 11:03:34 +02:00

43 lines
1.1 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 interface Tab<Id extends string> {
id: Id
label: string
}
interface Props<Id extends string> {
tabs: Tab<Id>[]
active: Id
onChange: (id: Id) => void
}
/** Kennung des Knopfes zu einem Tab die Panels verweisen mit aria-labelledby darauf. */
export function tabId(id: string): string {
return `tab-${id}`
}
/** Kennung des Panels zu einem Tab. */
export function panelId(id: string): string {
return `panel-${id}`
}
/** Tab-Leiste. Native Knöpfe, damit die Tastaturbedienung von selbst funktioniert. */
export default function Tabs<Id extends string>({ tabs, active, onChange }: Props<Id>) {
return (
<nav className="tabs" role="tablist" aria-label="Bereiche">
{tabs.map((tab) => (
<button
key={tab.id}
id={tabId(tab.id)}
type="button"
role="tab"
className={`tabs__button${tab.id === active ? ' tabs__button--active' : ''}`}
aria-selected={tab.id === active}
aria-controls={panelId(tab.id)}
onClick={() => onChange(tab.id)}
>
{tab.label}
</button>
))}
</nav>
)
}