Reorganize repo structure and standards references
This commit is contained in:
1 parent
3cb93a81be
commit
be2054274d
5885 files changed
+2588
-195
No files matched your search
+61
@@ -0,0 +1,61 @@
|
||||
import { Menu } from "@headlessui/react";
|
||||
import { ApplicationLayout } from "~/application/enums/shared/ApplicationLayout";
|
||||
import clsx from "clsx";
|
||||
import Dropdown from "../dropdowns/Dropdown";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
||||
btnClassName?: string;
|
||||
}
|
||||
|
||||
export default function LayoutSelector({ className, btnClassName }: Props) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const layouts = [
|
||||
{
|
||||
name: t("shared.layouts.sidebar"),
|
||||
value: ApplicationLayout.SIDEBAR,
|
||||
},
|
||||
{
|
||||
name: t("shared.layouts.stacked"),
|
||||
value: ApplicationLayout.STACKED,
|
||||
},
|
||||
];
|
||||
|
||||
function select(value: ApplicationLayout) {
|
||||
// store.dispatch(setLayout(value));
|
||||
}
|
||||
|
||||
return (
|
||||
<Dropdown
|
||||
className={className}
|
||||
btnClassName={clsx(
|
||||
"cursor-pointer select-none leading-6 font-medium focus:outline-hidden transition ease-in-out duration-150 px-3 py-1 rounded-sm text-text-neutral-tertiary hover:text-text-neutral-primary/80 dark:hover:text-gray-300 focus:text-text-neutral-primary dark:focus:text-white",
|
||||
btnClassName
|
||||
)}
|
||||
button={<span>{t("settings.preferences.layouts")}</span>}
|
||||
options={
|
||||
<div>
|
||||
{layouts.map((layout, index) => {
|
||||
return (
|
||||
<Menu.Item key={index}>
|
||||
{({ active }) => (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => select(layout.value)}
|
||||
key={index}
|
||||
className={clsx("w-full text-left", active ? "text-text-neutral-primary bg-surface-neutral-secondary/90" : "text-text-neutral-primary/80", "block px-4 py-2 text-sm")}
|
||||
role="menuitem"
|
||||
>
|
||||
<div className="pl-1">{layout.name}</div>
|
||||
</button>
|
||||
)}
|
||||
</Menu.Item>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
);
|
||||
}
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
import { useTranslation } from "react-i18next";
|
||||
import clsx from "clsx";
|
||||
import { useLocation, useMatches, useSearchParams, useSubmit } from "react-router";
|
||||
import { useRootData } from "~/utils/data/useRootData";
|
||||
import AnalyticsHelper from "~/utils/helpers/AnalyticsHelper";
|
||||
import { i18nConfig } from "~/locale/i18n";
|
||||
import { Fragment } from "react";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "../dropdown-menu";
|
||||
import { Button } from "../button";
|
||||
import { LanguagesIcon } from "~/components/ui/icons/vendor";
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
||||
export default function LocaleSelector({ className, disabled }: Props) {
|
||||
const { t } = useTranslation();
|
||||
let location = useLocation();
|
||||
const [searchParams] = useSearchParams();
|
||||
const submit = useSubmit();
|
||||
const rootData = useRootData();
|
||||
const matches = useMatches();
|
||||
|
||||
async function select(value: string) {
|
||||
const form = new FormData();
|
||||
form.set("action", "setLocale");
|
||||
searchParams.set("lng", value);
|
||||
form.set("redirect", location.pathname + "?" + searchParams.toString());
|
||||
form.set("lng", value);
|
||||
if (rootData.csrf) {
|
||||
form.set("csrf", rootData.csrf);
|
||||
}
|
||||
submit(form, { method: "post", action: "/preferences", preventScrollReset: true });
|
||||
|
||||
const routeMatch = matches.find((m) => m.pathname == location.pathname);
|
||||
AnalyticsHelper.addEvent({
|
||||
url: location.pathname,
|
||||
route: routeMatch?.id,
|
||||
rootData,
|
||||
action: "setLocale",
|
||||
category: "user",
|
||||
label: "locale",
|
||||
value,
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<Fragment>
|
||||
{/* Non-modal so Radix does not mark background siblings aria-hidden while
|
||||
they still contain focusable content (axe aria-hidden-focus); a footer
|
||||
language menu does not need to trap focus or block the page. */}
|
||||
<DropdownMenu modal={false}>
|
||||
<DropdownMenuTrigger asChild disabled={disabled}>
|
||||
<Button variant="ghost" aria-label={t("shared.language")} className={clsx("flex w-10 space-x-2", className)}>
|
||||
<div
|
||||
className={clsx(
|
||||
"text-text-neutral-tertiary inline-flex shrink-0 items-center rounded-full p-1 text-xs font-medium",
|
||||
`theme-${rootData.appConfiguration?.app.theme}`
|
||||
)}
|
||||
>
|
||||
<div className="p-0.5">
|
||||
{/* {t(i18n.language)} */}
|
||||
<LanguagesIcon className="size-5" />
|
||||
</div>
|
||||
</div>
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent className="border-border-default w-56">
|
||||
<DropdownMenuLabel>{t("shared.language")}</DropdownMenuLabel>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuGroup>
|
||||
{i18nConfig.supportedLngs.map((language, index) => {
|
||||
return (
|
||||
<DropdownMenuItem key={index} onClick={() => select(language)}>
|
||||
{t("shared.locales." + language)}
|
||||
</DropdownMenuItem>
|
||||
);
|
||||
})}
|
||||
</DropdownMenuGroup>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
{/* <Dropdown
|
||||
className={className}
|
||||
right={right}
|
||||
btnClassName={clsx(
|
||||
"text-muted-foreground rounded-md px-2 py-1 inline-flex items-center justify-center font-medium focus:outline-hidden focus:ring-2 focus:ring-inset focus:ring-gray-500",
|
||||
btnClassName
|
||||
)}
|
||||
button={
|
||||
<div className="p-0.5">
|
||||
<svg className="size-5" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="currentColor">
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
d="m10.5 21 5.25-11.25L21 21m-9-3h7.5M3 5.621a48.474 48.474 0 0 1 6-.371m0 0c1.12 0 2.233.038 3.334.114M9 5.25V3m3.334 2.364C11.176 10.658 7.69 15.08 3 17.502m9.334-12.138c.896.061 1.785.147 2.666.257m-4.589 8.495a18.023 18.023 0 0 1-3.827-5.802"
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
}
|
||||
options={
|
||||
<div>
|
||||
{i18nConfig.supportedLngs.map((language, index) => {
|
||||
return (
|
||||
<Menu.Item key={index}>
|
||||
{({ active }) => (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => select(language)}
|
||||
key={index}
|
||||
className={clsx(
|
||||
"hover:bg-secondary hover:text-secondary-foreground flex w-full space-x-2 text-left",
|
||||
active ? "" : "",
|
||||
"block px-4 py-2 text-sm"
|
||||
)}
|
||||
role="menuitem"
|
||||
>
|
||||
<div>{t("shared.locales." + language)}</div>
|
||||
</button>
|
||||
)}
|
||||
</Menu.Item>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
}
|
||||
/> */}
|
||||
</Fragment>
|
||||
);
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
import "@testing-library/jest-dom";
|
||||
import { fireEvent, render, screen } from "@testing-library/react";
|
||||
import { createMemoryRouter, RouterProvider } from "react-router";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import ThemeSelector from "./ThemeSelector";
|
||||
|
||||
vi.mock("~/utils/data/useRootData", () => ({
|
||||
useRootData: () => ({
|
||||
appConfiguration: { app: { theme: "default" } },
|
||||
csrf: "csrf-token",
|
||||
theme: "default",
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({
|
||||
t: (key: string) => (key === "shared.theme" ? "Theme" : key),
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("~/utils/helpers/AnalyticsHelper", () => ({
|
||||
default: { addEvent: vi.fn() },
|
||||
}));
|
||||
|
||||
function renderSelector(variant?: "primary" | "secondary" | "tertiary") {
|
||||
const router = createMemoryRouter([{ path: "/", element: <ThemeSelector variant={variant} /> }], { initialEntries: ["/"] });
|
||||
return render(<RouterProvider router={router} />);
|
||||
}
|
||||
|
||||
describe("ThemeSelector", () => {
|
||||
it("exposes an accessible trigger name", () => {
|
||||
renderSelector();
|
||||
|
||||
expect(screen.getByRole("button", { name: "Theme" })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("keeps the secondary icon trigger accessible", () => {
|
||||
renderSelector("secondary");
|
||||
|
||||
expect(screen.getByRole("button", { name: "Theme" })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("keeps the tertiary select trigger accessible", () => {
|
||||
renderSelector("tertiary");
|
||||
|
||||
expect(screen.getByRole("combobox", { name: "Theme" })).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
+170
@@ -0,0 +1,170 @@
|
||||
import clsx from "clsx";
|
||||
import { useFetcher, useLocation, useMatches, useSearchParams } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useRootData } from "~/utils/data/useRootData";
|
||||
import AnalyticsHelper from "~/utils/helpers/AnalyticsHelper";
|
||||
import { defaultThemes } from "~/utils/theme/defaultThemes";
|
||||
import { Fragment } from "react";
|
||||
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from "../select";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "../dropdown-menu";
|
||||
import { Button } from "../button";
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
||||
variant?: "primary" | "secondary" | "tertiary";
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
||||
export default function ThemeSelector({ className, variant = "primary", disabled }: Props) {
|
||||
const { t } = useTranslation();
|
||||
let location = useLocation();
|
||||
const fetcher = useFetcher();
|
||||
const rootData = useRootData();
|
||||
const matches = useMatches();
|
||||
const [searchParams] = useSearchParams();
|
||||
|
||||
async function select(value: string) {
|
||||
const form = new FormData();
|
||||
form.set("action", "setTheme");
|
||||
form.set("theme", value);
|
||||
form.set("redirect", location.pathname + "?" + searchParams.toString());
|
||||
if (rootData.csrf) {
|
||||
form.set("csrf", rootData.csrf);
|
||||
}
|
||||
fetcher.submit(form, { method: "post", action: "/preferences", preventScrollReset: true });
|
||||
|
||||
const routeMatch = matches.find((m) => m.pathname == location.pathname);
|
||||
AnalyticsHelper.addEvent({
|
||||
url: location.pathname,
|
||||
route: routeMatch?.id,
|
||||
rootData,
|
||||
action: "setTheme",
|
||||
category: "user",
|
||||
label: "theme",
|
||||
value,
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<Fragment>
|
||||
{variant === "primary" || variant === "secondary" ? (
|
||||
// Non-modal so Radix does not mark the still-focusable background
|
||||
// aria-hidden (axe aria-hidden-focus) while the theme menu is open.
|
||||
<DropdownMenu modal={false}>
|
||||
<DropdownMenuTrigger disabled={disabled} className={clsx(className, "select-none")} asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
aria-label={t("shared.theme")}
|
||||
className={clsx(
|
||||
"flex w-10 space-x-2 select-none",
|
||||
className,
|
||||
variant === "secondary" &&
|
||||
"text-text-neutral-tertiary bg-surface-neutral-secondary hover:bg-surface-neutral-secondary/90 border-border-default relative inline-flex h-auto w-auto items-center rounded-full border p-3.5 font-medium shadow-inner focus:z-10 focus:shadow-focus focus:outline-hidden"
|
||||
)}
|
||||
>
|
||||
{variant === "primary" ? (
|
||||
<div className={clsx("text-primary inline-flex shrink-0 items-center rounded-full p-1 text-xs font-medium", `theme-${rootData.theme}`)}>
|
||||
<svg className="size-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256">
|
||||
<rect width="256" height="256" fill="none"></rect>
|
||||
<line
|
||||
x1="208"
|
||||
y1="128"
|
||||
x2="128"
|
||||
y2="208"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth="16"
|
||||
></line>
|
||||
<line
|
||||
x1="192"
|
||||
y1="40"
|
||||
x2="40"
|
||||
y2="192"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth="16"
|
||||
></line>
|
||||
</svg>
|
||||
</div>
|
||||
) : (
|
||||
variant === "secondary" && (
|
||||
<span className={clsx("bg-brand-brand-surface-solid-default text-primary inline-flex shrink-0 items-center rounded-full text-xs font-medium")}>
|
||||
<svg className={clsx("h-2 w-2")} fill="currentColor" viewBox="0 0 8 8">
|
||||
<circle cx={4} cy={4} r={3} />
|
||||
</svg>
|
||||
</span>
|
||||
)
|
||||
)}
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent className="w-56">
|
||||
<DropdownMenuLabel>{t("shared.theme")}</DropdownMenuLabel>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuGroup>
|
||||
{defaultThemes.map((f) => {
|
||||
const label = t(f.labelKey, { defaultValue: f.name });
|
||||
return (
|
||||
<DropdownMenuItem key={f.value} onClick={() => select(f.value)}>
|
||||
<div className="flex items-center space-x-2">
|
||||
<label
|
||||
className={clsx(
|
||||
`theme-${f.value}`,
|
||||
"shadow-focus relative flex cursor-pointer items-center justify-center rounded-full p-0.5 focus:outline-hidden"
|
||||
)}
|
||||
>
|
||||
<span id="color-choice-0-label" className="sr-only">
|
||||
{label}
|
||||
</span>
|
||||
<span aria-hidden="true" className={clsx("border-border-default h-3 w-3 rounded-full border", "bg-brand-brand-surface-solid-default border-primary")}></span>
|
||||
</label>
|
||||
<div>{label}</div>
|
||||
</div>
|
||||
</DropdownMenuItem>
|
||||
);
|
||||
})}
|
||||
</DropdownMenuGroup>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
) : variant === "tertiary" ? (
|
||||
<Select value={rootData.appConfiguration.app.theme} onValueChange={(e) => select(e.toString())}>
|
||||
<SelectTrigger aria-label={t("shared.theme")} className={className}>
|
||||
<SelectValue
|
||||
placeholder={
|
||||
<div className="p-0.5">
|
||||
<span className={clsx("text-primary inline-flex shrink-0 items-center rounded-full text-xs font-medium")}>
|
||||
<svg className={clsx("h-3 w-3")} fill="currentColor" viewBox="0 0 8 8">
|
||||
<circle cx={4} cy={4} r={3} />
|
||||
</svg>
|
||||
</span>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectGroup>
|
||||
{defaultThemes.map((item, idx) => {
|
||||
return (
|
||||
<SelectItem key={idx} value={item.value}>
|
||||
{t(item.labelKey, { defaultValue: item.name })}
|
||||
</SelectItem>
|
||||
);
|
||||
})}
|
||||
</SelectGroup>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
) : null}
|
||||
</Fragment>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user