mirror of
https://github.com/docmost/docmost.git
synced 2025-11-13 06:22:42 +10:00
* feat: support i18n * feat: wip support i18n * feat: complete space translation * feat: complete page translation * feat: update space translation * feat: update workspace translation * feat: update group translation * feat: update workspace translation * feat: update page translation * feat: update user translation * chore: update pnpm-lock * feat: add query translation * refactor: merge to single file * chore: remove necessary code * feat: save language to BE * fix: only load current language * feat: save language to locale column * fix: cleanups * add language menu to preferences page * new translations * translate editor * Translate editor placeholders * translate space selection component --------- Co-authored-by: Philip Okugbe <phil@docmost.com> Co-authored-by: Philip Okugbe <16838612+Philipinho@users.noreply.github.com>
69 lines
1.6 KiB
TypeScript
69 lines
1.6 KiB
TypeScript
import React, { forwardRef } from "react";
|
|
import { IconCheck, IconChevronDown } from "@tabler/icons-react";
|
|
import { Group, Text, Menu, Button } from "@mantine/core";
|
|
import { IRoleData } from "@/lib/types.ts";
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
interface RoleButtonProps extends React.ComponentPropsWithoutRef<"button"> {
|
|
name: string;
|
|
}
|
|
|
|
const RoleButton = forwardRef<HTMLButtonElement, RoleButtonProps>(
|
|
({ name, ...others }: RoleButtonProps, ref) => (
|
|
<Button
|
|
variant="default"
|
|
ref={ref}
|
|
style={{
|
|
border: "none",
|
|
}}
|
|
rightSection={<IconChevronDown size="1rem" />}
|
|
{...others}
|
|
>
|
|
{name}
|
|
</Button>
|
|
),
|
|
);
|
|
|
|
interface RoleMenuProps {
|
|
roles: IRoleData[];
|
|
roleName: string;
|
|
onChange?: (value: string) => void;
|
|
disabled?: boolean;
|
|
}
|
|
|
|
export default function RoleSelectMenu({
|
|
roles,
|
|
roleName,
|
|
onChange,
|
|
disabled,
|
|
}: RoleMenuProps) {
|
|
const { t } = useTranslation();
|
|
|
|
return (
|
|
<Menu withArrow>
|
|
<Menu.Target>
|
|
<RoleButton name={t(roleName)} disabled={disabled} />
|
|
</Menu.Target>
|
|
|
|
<Menu.Dropdown>
|
|
{roles?.map((item) => (
|
|
<Menu.Item
|
|
onClick={() => onChange && onChange(item.value)}
|
|
key={item.value}
|
|
>
|
|
<Group flex="1" gap="xs">
|
|
<div>
|
|
<Text size="sm">{t(item.label)}</Text>
|
|
<Text size="xs" opacity={0.65}>
|
|
{t(item.description)}
|
|
</Text>
|
|
</div>
|
|
{item.label === roleName && <IconCheck size={20} />}
|
|
</Group>
|
|
</Menu.Item>
|
|
))}
|
|
</Menu.Dropdown>
|
|
</Menu>
|
|
);
|
|
}
|