2022-05-04 17:09:48 +01:00
|
|
|
/*
|
2023-01-03 16:55:26 +00:00
|
|
|
Copyright 2022 New Vector Ltd
|
2022-05-04 17:09:48 +01:00
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
2023-06-30 18:21:18 -04:00
|
|
|
import { useCallback } from "react";
|
2022-08-02 00:46:16 +02:00
|
|
|
import { Item } from "@react-stately/collections";
|
2022-10-10 09:19:10 -04:00
|
|
|
import { useTranslation } from "react-i18next";
|
2022-08-02 00:46:16 +02:00
|
|
|
|
2022-01-05 16:58:55 -08:00
|
|
|
import { Button } from "../button";
|
2022-01-05 17:21:30 -08:00
|
|
|
import { PopoverMenuTrigger } from "../popover/PopoverMenu";
|
2022-01-05 16:58:55 -08:00
|
|
|
import { ReactComponent as SpotlightIcon } from "../icons/Spotlight.svg";
|
|
|
|
|
import { ReactComponent as FreedomIcon } from "../icons/Freedom.svg";
|
|
|
|
|
import { ReactComponent as CheckIcon } from "../icons/Check.svg";
|
2022-05-26 13:52:06 -04:00
|
|
|
import menuStyles from "../Menu.module.css";
|
2022-01-05 16:58:55 -08:00
|
|
|
import { Menu } from "../Menu";
|
2022-08-02 00:46:16 +02:00
|
|
|
import { TooltipTrigger } from "../Tooltip";
|
2021-12-03 16:42:29 -08:00
|
|
|
|
2022-08-12 19:27:34 +02:00
|
|
|
export type Layout = "freedom" | "spotlight";
|
2022-10-10 09:19:10 -04:00
|
|
|
|
2022-08-02 00:46:16 +02:00
|
|
|
interface Props {
|
|
|
|
|
layout: Layout;
|
|
|
|
|
setLayout: (layout: Layout) => void;
|
|
|
|
|
}
|
2022-10-10 09:19:10 -04:00
|
|
|
|
2022-08-02 00:46:16 +02:00
|
|
|
export function GridLayoutMenu({ layout, setLayout }: Props) {
|
2022-10-10 09:19:10 -04:00
|
|
|
const { t } = useTranslation();
|
|
|
|
|
const tooltip = useCallback(() => t("Change layout"), [t]);
|
|
|
|
|
|
2021-12-03 16:42:29 -08:00
|
|
|
return (
|
2021-12-06 17:34:10 -08:00
|
|
|
<PopoverMenuTrigger placement="bottom right">
|
2022-10-10 09:19:10 -04:00
|
|
|
<TooltipTrigger tooltip={tooltip}>
|
2021-12-14 22:00:00 -08:00
|
|
|
<Button variant="icon">
|
|
|
|
|
{layout === "spotlight" ? <SpotlightIcon /> : <FreedomIcon />}
|
|
|
|
|
</Button>
|
|
|
|
|
</TooltipTrigger>
|
2022-08-02 00:46:16 +02:00
|
|
|
{(props: JSX.IntrinsicAttributes) => (
|
2023-06-30 16:43:28 +01:00
|
|
|
<Menu
|
|
|
|
|
{...props}
|
|
|
|
|
label={t("Grid layout menu")}
|
|
|
|
|
onAction={(key) => setLayout(key.toString() as Layout)}
|
|
|
|
|
onClose={() => {}}
|
|
|
|
|
>
|
2022-10-10 09:19:10 -04:00
|
|
|
<Item key="freedom" textValue={t("Freedom")}>
|
2021-12-03 16:42:29 -08:00
|
|
|
<FreedomIcon />
|
|
|
|
|
<span>Freedom</span>
|
2022-05-26 13:52:06 -04:00
|
|
|
{layout === "freedom" && (
|
|
|
|
|
<CheckIcon className={menuStyles.checkIcon} />
|
|
|
|
|
)}
|
2021-12-06 17:34:10 -08:00
|
|
|
</Item>
|
2022-10-10 09:19:10 -04:00
|
|
|
<Item key="spotlight" textValue={t("Spotlight")}>
|
2021-12-03 16:42:29 -08:00
|
|
|
<SpotlightIcon />
|
|
|
|
|
<span>Spotlight</span>
|
|
|
|
|
{layout === "spotlight" && (
|
2022-05-26 13:52:06 -04:00
|
|
|
<CheckIcon className={menuStyles.checkIcon} />
|
2021-12-03 16:42:29 -08:00
|
|
|
)}
|
2021-12-06 17:34:10 -08:00
|
|
|
</Item>
|
|
|
|
|
</Menu>
|
2021-12-03 16:42:29 -08:00
|
|
|
)}
|
2021-12-06 17:34:10 -08:00
|
|
|
</PopoverMenuTrigger>
|
2021-12-03 16:42:29 -08:00
|
|
|
);
|
|
|
|
|
}
|