Reorganize repo structure and standards references

This commit is contained in:
david committed 2026-06-29 05:03:42 +02:00
1 parent 3cb93a81be
commit be2054274d
5885 files changed
+2588 -195

No files matched your search

@@ -0,0 +1,37 @@
import { useLocation } from "react-router";
import clsx from "clsx";
import UrlUtils from "~/utils/app/UrlUtils";
import { useTranslation } from "react-i18next";
export default function HeadingWithTabs({ tabs }: { tabs: { name: string; href: string }[] }) {
const { t } = useTranslation();
const location = useLocation();
function isCurrent(idx: number) {
return currentTab() === tabs[idx];
}
const currentTab = () => {
return tabs.find((element) => element.href && UrlUtils.stripTrailingSlash(location.pathname) === UrlUtils.stripTrailingSlash(element.href));
};
return (
<div className="w-full sm:flex sm:items-baseline">
<h3 className="text-text-neutral-primary text-lg font-medium leading-6">{t("components.tabs.headingWithTabs.issues")}</h3>
<div className="mt-4 sm:ml-10 sm:mt-0">
<nav className="-mb-px flex space-x-8">
{tabs.map((tab, idx) => (
<a
key={tab.name}
href={tab.href}
className={clsx(
isCurrent(idx) ? "border-theme-500 text-theme-600" : "hover:border-border-default text-text-neutral-tertiary hover:text-text-neutral-primary/80 border-transparent",
"whitespace-nowrap border-b-2 px-1 pb-4 text-sm font-medium"
)}
aria-current={isCurrent(idx) ? "page" : undefined}
>
{tab.name}
</a>
))}
</nav>
</div>
</div>
);
}
@@ -0,0 +1,23 @@
import PreviewTabsAsButtons from "./PreviewTabsAsButtons";
import { t as i18nT } from "i18next";
import PreviewTabsAsLinks from "./PreviewTabsAsLinks";
export default function PreviewTabs() {
return (
<div id="tabs" className="space-y-6">
<div className="space-y-1">
<h3 className="text-sm font-medium">{i18nT("components.tabs.preview.asLinks")}</h3>
<div className="border-border flex items-center space-x-2 border border-dashed p-2">
<PreviewTabsAsLinks />
</div>
</div>
<div className="space-y-1">
<h3 className="text-sm font-medium">{i18nT("components.tabs.preview.asButtons")}</h3>
<div className="border-border border border-dashed p-2">
<PreviewTabsAsButtons />
</div>
</div>
</div>
);
}
@@ -0,0 +1,34 @@
import { useState } from "react";
import { t as i18nT } from "i18next";
import Tabs from "./Tabs";
export default function PreviewTabsAsButtons() {
const [selectedTab, setSelectedTab] = useState(0);
return (
<div className="w-full space-y-2">
<Tabs
asLinks={false}
selectedTab={selectedTab}
onSelected={(selected) => {
setSelectedTab(selected);
}}
className="w-full sm:w-auto"
tabs={[
{ name: i18nT("components.tabs.preview.tab1") },
{ name: i18nT("components.tabs.preview.tab2") },
{ name: i18nT("components.tabs.preview.tab3") },
]}
/>
<div className="border-border bg-secondary/90 border p-2">
{selectedTab === 0 ? (
<div>{i18nT("components.tabs.preview.tab1Content")}</div>
) : selectedTab === 1 ? (
<div>{i18nT("components.tabs.preview.tab2Content")}</div>
) : (
<div>{i18nT("components.tabs.preview.tab3Content")}</div>
)}
</div>
</div>
);
}
@@ -0,0 +1,20 @@
import { t as i18nT } from "i18next";
import Tabs from "./Tabs";
export default function PreviewTabsAsLinks() {
return (
<div className="not-prose w-full space-y-2">
<Tabs
asLinks={true}
className="w-full sm:w-auto"
tabs={[
{ name: i18nT("components.tabs.preview.home"), routePath: "/docs/components" },
{
name: i18nT("components.tabs.preview.components"),
routePath: "/docs/components/tabs",
},
]}
/>
</div>
);
}
@@ -0,0 +1,19 @@
import { t as i18nT } from "i18next";
import TabsVertical from "./TabsVertical";
export default function PreviewTabsVertical() {
return (
<div className="not-prose w-full space-y-2">
<TabsVertical
className="w-full sm:w-auto"
tabs={[
{ name: i18nT("components.tabs.preview.home"), routePath: "/docs/components" },
{
name: i18nT("components.tabs.preview.components"),
routePath: "/docs/components/tabs",
},
]}
/>
</div>
);
}
@@ -0,0 +1,166 @@
import { Link, useLocation, useNavigate } from "react-router";
import clsx from "clsx";
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import UrlUtils from "~/utils/app/UrlUtils";
import InputSelect from "../input/InputSelect";
export interface TabItem {
name: any;
routePath?: string;
}
interface Props {
className?: string;
tabs: TabItem[];
asLinks?: boolean;
onSelected?: (idx: number) => void;
breakpoint?: "sm" | "md" | "lg" | "xl" | "2xl";
exact?: boolean;
selectedTab?: number;
}
export default function Tabs({ className = "", breakpoint = "md", tabs = [], asLinks = true, onSelected, exact, selectedTab = 0 }: Props) {
const { t } = useTranslation();
const navigate = useNavigate();
const location = useLocation();
const [selected, setSelected] = useState(selectedTab);
useEffect(() => {
tabs.forEach((tab, index) => {
if (tab.routePath && (location.pathname + location.search).includes(tab.routePath)) {
setSelected(index);
}
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [tabs, location.pathname]);
function selectTab(idx: number) {
const tab = tabs[idx];
setSelected(idx);
if (asLinks) {
if (tab?.routePath) {
navigate(tab.routePath);
}
} else {
if (onSelected) {
onSelected(idx);
}
}
}
function isCurrent(idx: number) {
return currentTab() === tabs[idx];
}
const currentTab = () => {
if (asLinks) {
if (true) {
return tabs.find((element) => element.routePath && UrlUtils.stripTrailingSlash(location.pathname) === UrlUtils.stripTrailingSlash(element.routePath));
} else {
return tabs.find((element) => element.routePath && (location.pathname + location.search).includes(element.routePath));
}
} else {
return tabs[selected];
}
};
return (
<div className={className}>
<div
className={clsx(
breakpoint === "sm" && "sm:hidden",
breakpoint === "md" && "md:hidden",
breakpoint === "lg" && "lg:hidden",
breakpoint === "xl" && "xl:hidden",
breakpoint === "2xl" && "2xl:hidden"
)}
>
<InputSelect
name="tabs"
value={selected}
setValue={(e) => selectTab(Number(e))}
options={tabs.map((tab, idx) => ({
value: Number(idx),
name: tab.name,
}))}
canClear={false}
/>
{/* <label htmlFor="tabs" className="sr-only">
{t("app.shared.tabs.select")}
</label>
<select
id="tabs"
name="tabs"
className="bg-background text-foreground focus:border-border focus:ring-ring border-border block w-full rounded-md"
onChange={(e) => selectTab(Number(e.target.value))}
value={selected}
>
{tabs.map((tab, idx) => {
return (
<option key={tab.name} value={Number(idx)}>
{tab.name}
</option>
);
})}
</select> */}
</div>
<div
className={clsx(
breakpoint === "sm" && "hidden sm:block",
breakpoint === "md" && "hidden md:block",
breakpoint === "lg" && "hidden lg:block",
breakpoint === "xl" && "hidden xl:block",
breakpoint === "2xl" && "hidden 2xl:block"
)}
>
{(() => {
if (asLinks) {
return (
<nav className="flex space-x-4" aria-label={t("components.tabs.ariaLabel")}>
{tabs
.filter((f) => f.routePath)
.map((tab, idx) => {
return (
<Link
key={tab.name}
to={tab.routePath ?? ""}
className={clsx(
"truncate",
isCurrent(idx) ? "text-text-neutral-primary bg-surface-neutral-secondary" : "text-text-neutral-tertiary hover:text-text-neutral-primary hover:bg-surface-neutral-secondary",
"rounded-sm px-3 py-2 text-sm font-medium"
)}
>
{tab.name}
</Link>
);
})}
</nav>
);
} else {
return (
<nav className="flex space-x-4" aria-label={t("components.tabs.ariaLabel")}>
{tabs.map((tab, idx) => {
return (
<button
type="button"
key={idx}
onClick={() => selectTab(idx)}
className={clsx(
"truncate",
isCurrent(idx) ? "text-text-neutral-primary bg-surface-neutral-secondary" : "text-text-neutral-tertiary hover:text-text-neutral-primary hover:bg-surface-neutral-secondary",
"rounded-sm px-3 py-2 text-sm font-medium"
)}
>
{tab.name}
</button>
);
})}
</nav>
);
}
})()}
</div>
</div>
);
}
@@ -0,0 +1,12 @@
import { useState } from "react";
import Tabs from "./Tabs";
export default function TabsContainer({ items, selected }: { items: { name: string; render: React.ReactNode }[]; selected?: number }) {
const [selectedTab, setSelectedTab] = useState(selected ?? 0);
return (
<div className="space-y-2">
<Tabs asLinks={false} tabs={items} selectedTab={selectedTab} onSelected={(idx) => setSelectedTab(idx)} />
{items[selectedTab].render}
</div>
);
}
@@ -0,0 +1,138 @@
import { Fragment, useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { Link, useLocation, useNavigate } from "react-router";
import clsx from "~/utils/shared/ClassesUtils";
import UrlUtils from "~/utils/app/UrlUtils";
export interface TabItem {
name: any;
routePath?: string;
}
interface Props {
className?: string;
tabs: TabItem[];
asLinks?: boolean;
breakpoint?: "sm" | "md" | "lg" | "xl" | "2xl";
onSelected?: (idx: number) => void;
exact?: boolean;
}
export default function TabsVertical({ className = "", tabs = [], asLinks = true, onSelected, exact, breakpoint = "md" }: Props) {
const { t } = useTranslation();
const navigate = useNavigate();
const location = useLocation();
const [selected, setSelected] = useState(0);
useEffect(() => {
tabs.forEach((tab, index) => {
if (tab.routePath && (location.pathname + location.search).includes(tab.routePath)) {
setSelected(index);
}
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [tabs, location.pathname]);
function selectTab(idx: number) {
const tab = tabs[idx];
setSelected(idx);
if (asLinks) {
if (tab?.routePath) {
navigate(tab.routePath);
}
} else {
if (onSelected) {
onSelected(idx);
}
}
}
function isCurrent(idx: number) {
return currentTab() === tabs[idx];
}
const currentTab = () => {
if (asLinks) {
if (exact) {
return tabs.find((element) => element.routePath && UrlUtils.stripTrailingSlash(location.pathname) === UrlUtils.stripTrailingSlash(element.routePath));
} else {
return tabs.find((element) => element.routePath && (location.pathname + location.search).includes(element.routePath));
}
} else {
return tabs[selected];
}
};
return (
<nav className={clsx("w-full space-y-1", className)} aria-label={t("components.tabs.verticalNavigation")}>
<div
className={clsx(
breakpoint === "sm" && "sm:hidden",
breakpoint === "md" && "md:hidden",
breakpoint === "lg" && "lg:hidden",
breakpoint === "xl" && "xl:hidden",
breakpoint === "2xl" && "2xl:hidden"
)}
>
<label htmlFor="tabs" className="sr-only">
{t("app.shared.tabs.select")}
</label>
<select
id="tabs"
name="tabs"
className="focus:border-theme-500 focus:shadow-focus border-border-default block w-full rounded-md"
onChange={(e) => selectTab(Number(e.target.value))}
value={selected}
>
{tabs.map((item, idx) => {
return (
<option key={item.name} value={Number(idx)}>
{item.name}
</option>
);
})}
</select>
</div>
<div
className={clsx(
breakpoint === "sm" && "hidden sm:block",
breakpoint === "md" && "hidden md:block",
breakpoint === "lg" && "hidden lg:block",
breakpoint === "xl" && "hidden xl:block",
breakpoint === "2xl" && "hidden 2xl:block"
)}
>
{tabs.map((item, idx) => (
<Fragment key={item.name}>
{item.routePath ? (
<Link
to={item.routePath ?? ""}
className={clsx(
"border",
isCurrent(idx)
? "border-border-default text-text-neutral-primary bg-surface-neutral-secondary/90 font-bold shadow-2xs"
: "hover:bg-surface-neutral-secondary hover:text-text-neutral-primary text-text-neutral-tertiary border-transparent",
"flex items-center rounded-md px-3 py-2 text-sm"
)}
>
<span className="truncate">{item.name}</span>
</Link>
) : (
<button
type="button"
className={clsx(
isCurrent(idx)
? "border-border-default text-text-neutral-primary bg-surface-neutral-secondary/90 font-bold shadow-2xs"
: "hover:bg-surface-neutral-secondary hover:text-text-neutral-primary text-text-neutral-tertiary border-transparent",
"flex w-full items-center justify-center rounded-md border px-3 py-2 text-sm"
)}
onClick={() => selectTab(idx)}
>
<span className="truncate">{item.name}</span>
</button>
)}
</Fragment>
))}
</div>
</nav>
);
}
@@ -0,0 +1,59 @@
import "@testing-library/jest-dom";
import { render, screen, within } from "@testing-library/react";
import { MemoryRouter } from "react-router";
import { describe, expect, it, vi } from "vitest";
import { assertNoA11yViolations } from "~/utils/test/a11y";
import TabsWithIcons from "./TabsWithIcons";
vi.mock("react-i18next", () => ({
useTranslation: () => ({ t: (key: string) => key }),
}));
describe("TabsWithIcons accessibility", () => {
it("exposes selected state for link tabs and button tabs", () => {
render(
<MemoryRouter>
<TabsWithIcons
tabs={[
{ name: "Overview", href: "/overview", current: true },
{ name: "Settings", href: "/settings", current: false },
{ name: "Recent", onClick: vi.fn(), current: false },
{ name: "Pinned", onClick: vi.fn(), current: true },
]}
/>
</MemoryRouter>
);
expect(screen.getByRole("link", { name: "Overview" })).toHaveAttribute("aria-current", "page");
expect(screen.getByRole("link", { name: "Settings" })).not.toHaveAttribute("aria-current");
expect(screen.getByRole("button", { name: "Recent" })).toHaveAttribute("aria-pressed", "false");
expect(screen.getByRole("button", { name: "Pinned" })).toHaveAttribute("aria-pressed", "true");
});
it("keeps mobile select labels unique when multiple instances render", () => {
const { container } = render(
<MemoryRouter>
<TabsWithIcons
tabs={[
{ name: "First", href: "/first", current: true },
{ name: "Second", href: "/second", current: false },
]}
/>
<TabsWithIcons
tabs={[
{ name: "Third", href: "/third", current: false },
{ name: "Fourth", href: "/fourth", current: true },
]}
/>
</MemoryRouter>
);
const selects = screen.getAllByRole("combobox", { name: "shared.select" });
expect(selects).toHaveLength(2);
expect(selects[0]).not.toHaveAttribute("id", selects[1].getAttribute("id") ?? "");
expect(within(selects[0]).getByRole("option", { name: "First" })).toBeInTheDocument();
expect(within(selects[1]).getByRole("option", { name: "Fourth" })).toBeInTheDocument();
assertNoA11yViolations(container);
});
});
@@ -0,0 +1,118 @@
import { Link, useNavigate } from "react-router";
import clsx from "clsx";
import { Fragment, ReactNode, useId } from "react";
import { useTranslation } from "react-i18next";
export type TabWithIcon = {
name?: string;
href?: string;
current: boolean;
icon?: ReactNode;
onClick?: () => void;
className?: string;
};
interface Props {
tabs: TabWithIcon[];
className?: string;
justify?: "start" | "center" | "end" | "between";
breakpoint?: "sm" | "md" | "lg" | "xl" | "2xl";
}
export default function TabsWithIcons({ tabs, className, justify, breakpoint = "md" }: Props) {
const { t } = useTranslation();
const navigate = useNavigate();
const tabsSelectId = useId();
return (
<div className={className}>
<div
className={clsx(
breakpoint === "sm" && "sm:hidden",
breakpoint === "md" && "md:hidden",
breakpoint === "lg" && "lg:hidden",
breakpoint === "xl" && "xl:hidden",
breakpoint === "2xl" && "2xl:hidden"
)}
>
<label htmlFor={tabsSelectId} className="sr-only">
{t("shared.select")}
</label>
<select
id={tabsSelectId}
name="tabs"
className="bg-surface-neutral-primary text-text-neutral-primary border-border-default focus-visible:border-border-default focus-visible:shadow-focus block w-full rounded-md focus-visible:outline-hidden"
value={tabs.find((tab) => tab.current)?.name}
onChange={(e) => {
const tab = tabs.find((tab) => tab.name === e.target.value);
if (tab?.href) {
navigate(tab.href);
} else if (tab?.onClick) {
tab.onClick();
}
}}
>
{tabs.map((tab) => (
<option key={tab.name} value={tab.name}>
{tab.name}
</option>
))}
</select>
</div>
<div
className={clsx(
breakpoint === "sm" && "hidden sm:block",
breakpoint === "md" && "hidden md:block",
breakpoint === "lg" && "hidden lg:block",
breakpoint === "xl" && "hidden xl:block",
breakpoint === "2xl" && "hidden 2xl:block"
)}
>
<div className="border-border-default border-b">
<nav
className={clsx(
"-mb-px flex space-x-4",
justify === "start" && "justify-start",
justify === "center" && "justify-center",
justify === "end" && "justify-end",
justify === "between" && "justify-between"
)}
aria-label={t("components.tabs.ariaLabel")}
>
{tabs.map((tab, idx) => (
<Fragment key={idx}>
{tab.href && (
<Link
key={tab.name}
to={tab.href}
className={clsx(
tab.current ? "border-border-default" : "hover:border-border-default text-text-neutral-tertiary hover:text-text-neutral-primary/80 border-transparent",
"focus-visible:shadow-focus group inline-flex items-center space-x-2 border-b-2 px-1 py-2 text-sm font-medium focus-visible:outline-hidden",
tab.className
)}
aria-current={tab.current ? "page" : undefined}
>
{tab.icon}
<div className="truncate">{tab.name}</div>
</Link>
)}
{tab.onClick && (
<button
type="button"
onClick={tab.onClick}
className={clsx(
tab.current ? "border-border-default" : "hover:border-border-default text-text-neutral-tertiary hover:text-text-neutral-primary/80 border-transparent",
"focus-visible:shadow-focus group inline-flex w-full items-center space-x-2 border-b-2 px-1 py-2 text-sm font-medium focus-visible:outline-hidden",
tab.className
)}
aria-pressed={tab.current}
>
{tab.icon}
<div className="truncate">{tab.name}</div>
</button>
)}
</Fragment>
))}
</nav>
</div>
</div>
</div>
);
}