2023-02-13 14:49:46 +00:00
|
|
|
import React, { useEffect, useState } from "react";
|
2022-11-19 14:21:26 +00:00
|
|
|
// headless ui
|
|
|
|
import { Dialog, Transition } from "@headlessui/react";
|
|
|
|
// icons
|
|
|
|
import { XMarkIcon } from "@heroicons/react/20/solid";
|
2023-03-13 18:08:43 +00:00
|
|
|
import { MagnifyingGlassIcon } from "@heroicons/react/24/outline";
|
|
|
|
import { MacCommandIcon } from "components/icons";
|
2022-12-16 14:56:25 +00:00
|
|
|
// ui
|
2023-01-26 18:12:20 +00:00
|
|
|
import { Input } from "components/ui";
|
2022-11-19 14:21:26 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
isOpen: boolean;
|
|
|
|
setIsOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
|
|
|
};
|
|
|
|
|
2022-12-16 14:56:25 +00:00
|
|
|
const shortcuts = [
|
|
|
|
{
|
|
|
|
title: "Navigation",
|
|
|
|
shortcuts: [
|
2023-03-13 18:08:43 +00:00
|
|
|
{ keys: "Ctrl,K", description: "To open navigator" },
|
2022-12-16 14:56:25 +00:00
|
|
|
{ keys: "↑", description: "Move up" },
|
|
|
|
{ keys: "↓", description: "Move down" },
|
|
|
|
{ keys: "←", description: "Move left" },
|
|
|
|
{ keys: "→", description: "Move right" },
|
|
|
|
{ keys: "Enter", description: "Select" },
|
|
|
|
{ keys: "Esc", description: "Close" },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: "Common",
|
|
|
|
shortcuts: [
|
2023-02-01 15:01:40 +00:00
|
|
|
{ keys: "P", description: "To create project" },
|
|
|
|
{ keys: "C", description: "To create issue" },
|
|
|
|
{ keys: "Q", description: "To create cycle" },
|
|
|
|
{ keys: "M", description: "To create module" },
|
2023-04-03 08:53:50 +00:00
|
|
|
{ keys: "V", description: "To create view" },
|
|
|
|
{ keys: "D", description: "To create page" },
|
2023-01-30 14:07:25 +00:00
|
|
|
{ keys: "Delete", description: "To bulk delete issues" },
|
2023-02-01 15:01:40 +00:00
|
|
|
{ keys: "H", description: "To open shortcuts guide" },
|
2022-12-16 14:56:25 +00:00
|
|
|
{
|
2023-03-13 18:08:43 +00:00
|
|
|
keys: "Ctrl,Alt,C",
|
|
|
|
description: "To copy issue url when on issue detail page",
|
2022-12-16 14:56:25 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2023-02-13 14:49:46 +00:00
|
|
|
const allShortcuts = shortcuts.map((i) => i.shortcuts).flat(1);
|
|
|
|
|
2023-02-10 12:32:18 +00:00
|
|
|
export const ShortcutsModal: React.FC<Props> = ({ isOpen, setIsOpen }) => {
|
2022-12-16 14:56:25 +00:00
|
|
|
const [query, setQuery] = useState("");
|
2023-02-13 14:49:46 +00:00
|
|
|
const filteredShortcuts = allShortcuts.filter((shortcut) =>
|
2023-02-15 06:58:22 +00:00
|
|
|
shortcut.description.toLowerCase().includes(query.trim().toLowerCase()) || query === ""
|
|
|
|
? true
|
|
|
|
: false
|
2022-12-16 14:56:25 +00:00
|
|
|
);
|
|
|
|
|
2023-02-13 14:49:46 +00:00
|
|
|
useEffect(() => {
|
|
|
|
if (!isOpen) setQuery("");
|
|
|
|
}, [isOpen]);
|
|
|
|
|
2022-11-19 14:21:26 +00:00
|
|
|
return (
|
|
|
|
<Transition.Root show={isOpen} as={React.Fragment}>
|
2023-01-26 18:12:20 +00:00
|
|
|
<Dialog as="div" className="relative z-20" onClose={setIsOpen}>
|
2022-11-19 14:21:26 +00:00
|
|
|
<Transition.Child
|
|
|
|
as={React.Fragment}
|
|
|
|
enter="ease-out duration-300"
|
|
|
|
enterFrom="opacity-0"
|
|
|
|
enterTo="opacity-100"
|
|
|
|
leave="ease-in duration-200"
|
|
|
|
leaveFrom="opacity-100"
|
|
|
|
leaveTo="opacity-0"
|
|
|
|
>
|
2023-04-20 08:11:24 +00:00
|
|
|
<div className="fixed inset-0 bg-[#131313] bg-opacity-50 transition-opacity" />
|
2022-11-19 14:21:26 +00:00
|
|
|
</Transition.Child>
|
|
|
|
|
2023-01-26 18:12:20 +00:00
|
|
|
<div className="fixed inset-0 z-20 overflow-y-auto">
|
2022-11-19 14:21:26 +00:00
|
|
|
<div className="flex min-h-full items-end justify-center p-4 text-center sm:items-center sm:p-0">
|
|
|
|
<Transition.Child
|
|
|
|
as={React.Fragment}
|
|
|
|
enter="ease-out duration-300"
|
|
|
|
enterFrom="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
|
|
|
|
enterTo="opacity-100 translate-y-0 sm:scale-100"
|
|
|
|
leave="ease-in duration-200"
|
|
|
|
leaveFrom="opacity-100 translate-y-0 sm:scale-100"
|
|
|
|
leaveTo="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
|
|
|
|
>
|
2023-04-20 08:11:24 +00:00
|
|
|
<Dialog.Panel className="relative transform overflow-hidden rounded-lg bg-brand-surface-2 text-left shadow-xl transition-all sm:my-8 sm:w-full sm:max-w-lg">
|
|
|
|
<div className="bg-brand-surface-2 p-5">
|
2022-11-19 14:21:26 +00:00
|
|
|
<div className="sm:flex sm:items-start">
|
2023-01-26 18:12:20 +00:00
|
|
|
<div className="flex w-full flex-col gap-y-4 text-center sm:text-left">
|
2022-11-19 14:21:26 +00:00
|
|
|
<Dialog.Title
|
|
|
|
as="h3"
|
2023-04-20 08:11:24 +00:00
|
|
|
className="flex justify-between text-lg font-medium leading-6 text-brand-base"
|
2022-11-19 14:21:26 +00:00
|
|
|
>
|
|
|
|
<span>Keyboard Shortcuts</span>
|
|
|
|
<span>
|
|
|
|
<button type="button" onClick={() => setIsOpen(false)}>
|
|
|
|
<XMarkIcon
|
2023-04-20 08:11:24 +00:00
|
|
|
className="h-6 w-6 text-gray-400 hover:text-brand-secondary"
|
2022-11-19 14:21:26 +00:00
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
</span>
|
|
|
|
</Dialog.Title>
|
2022-12-16 14:56:25 +00:00
|
|
|
<div>
|
2023-04-20 08:11:24 +00:00
|
|
|
<div className="flex w-full items-center justify-start gap-1 rounded border-[0.6px] border-brand-base bg-brand-surface-1 px-3 py-2">
|
|
|
|
<MagnifyingGlassIcon className="h-3.5 w-3.5 text-brand-secondary" />
|
2023-03-13 18:08:43 +00:00
|
|
|
<Input
|
2023-04-20 08:11:24 +00:00
|
|
|
className="w-full border-none bg-transparent py-1 px-2 text-xs text-brand-secondary focus:outline-none"
|
2023-03-13 18:08:43 +00:00
|
|
|
id="search"
|
|
|
|
name="search"
|
|
|
|
type="text"
|
|
|
|
placeholder="Search for shortcuts"
|
|
|
|
onChange={(e) => setQuery(e.target.value)}
|
|
|
|
/>
|
|
|
|
</div>
|
2022-12-16 14:56:25 +00:00
|
|
|
</div>
|
2023-01-26 18:12:20 +00:00
|
|
|
<div className="flex w-full flex-col gap-y-3">
|
2023-02-13 14:49:46 +00:00
|
|
|
{query.trim().length > 0 ? (
|
|
|
|
filteredShortcuts.length > 0 ? (
|
|
|
|
filteredShortcuts.map((shortcut) => (
|
|
|
|
<div key={shortcut.keys} className="flex w-full flex-col">
|
|
|
|
<div className="flex flex-col gap-y-3">
|
2023-03-13 18:08:43 +00:00
|
|
|
<div className="flex items-center justify-between">
|
2023-04-20 08:11:24 +00:00
|
|
|
<p className="text-sm text-brand-secondary">{shortcut.description}</p>
|
2023-03-13 18:08:43 +00:00
|
|
|
<div className="flex items-center gap-x-2.5">
|
2023-02-13 14:49:46 +00:00
|
|
|
{shortcut.keys.split(",").map((key, index) => (
|
|
|
|
<span key={index} className="flex items-center gap-1">
|
2023-03-13 18:08:43 +00:00
|
|
|
{key === "Ctrl" ? (
|
2023-04-20 08:11:24 +00:00
|
|
|
<span className="flex h-full items-center rounded-sm border border-brand-base bg-brand-surface-1 p-2">
|
2023-03-22 18:10:25 +00:00
|
|
|
<MacCommandIcon />
|
|
|
|
</span>
|
2023-03-13 18:08:43 +00:00
|
|
|
) : (
|
2023-04-20 08:11:24 +00:00
|
|
|
<kbd className="rounded-sm border border-brand-base bg-brand-surface-1 px-2 py-1 text-sm font-medium text-gray-800">
|
2023-03-22 18:10:25 +00:00
|
|
|
{key === "Ctrl" ? <MacCommandIcon /> : key}
|
2023-03-13 18:08:43 +00:00
|
|
|
</kbd>
|
|
|
|
)}
|
2023-02-13 14:49:46 +00:00
|
|
|
</span>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
))
|
|
|
|
) : (
|
|
|
|
<div className="flex flex-col gap-y-3">
|
2023-04-20 08:11:24 +00:00
|
|
|
<p className="text-sm text-brand-secondary">
|
2023-02-13 14:49:46 +00:00
|
|
|
No shortcuts found for{" "}
|
|
|
|
<span className="font-semibold italic">
|
|
|
|
{`"`}
|
|
|
|
{query}
|
|
|
|
{`"`}
|
|
|
|
</span>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
) : (
|
|
|
|
shortcuts.map(({ title, shortcuts }) => (
|
2023-01-26 18:12:20 +00:00
|
|
|
<div key={title} className="flex w-full flex-col">
|
|
|
|
<p className="mb-4 font-medium">{title}</p>
|
2022-12-16 14:56:25 +00:00
|
|
|
<div className="flex flex-col gap-y-3">
|
|
|
|
{shortcuts.map(({ keys, description }, index) => (
|
2023-03-13 18:08:43 +00:00
|
|
|
<div key={index} className="flex items-center justify-between">
|
2023-04-20 08:11:24 +00:00
|
|
|
<p className="text-sm text-brand-secondary">{description}</p>
|
2023-03-13 18:08:43 +00:00
|
|
|
<div className="flex items-center gap-x-2.5">
|
2022-12-16 14:56:25 +00:00
|
|
|
{keys.split(",").map((key, index) => (
|
|
|
|
<span key={index} className="flex items-center gap-1">
|
2023-03-13 18:08:43 +00:00
|
|
|
{key === "Ctrl" ? (
|
2023-04-20 08:11:24 +00:00
|
|
|
<span className="flex h-full items-center rounded-sm border border-brand-base text-brand-secondary bg-brand-surface-1 p-2">
|
2023-03-22 18:10:25 +00:00
|
|
|
<MacCommandIcon />
|
|
|
|
</span>
|
2023-03-13 18:08:43 +00:00
|
|
|
) : (
|
2023-04-20 08:11:24 +00:00
|
|
|
<kbd className="rounded-sm border border-brand-base bg-brand-surface-1 px-2 py-1 text-sm font-medium text-brand-secondary">
|
2023-03-22 18:10:25 +00:00
|
|
|
{key === "Ctrl" ? <MacCommandIcon /> : key}
|
2023-03-13 18:08:43 +00:00
|
|
|
</kbd>
|
|
|
|
)}
|
2022-12-16 14:56:25 +00:00
|
|
|
</span>
|
|
|
|
))}
|
|
|
|
</div>
|
2022-11-19 14:21:26 +00:00
|
|
|
</div>
|
2022-12-16 14:56:25 +00:00
|
|
|
))}
|
|
|
|
</div>
|
2022-11-19 14:21:26 +00:00
|
|
|
</div>
|
2022-12-16 14:56:25 +00:00
|
|
|
))
|
|
|
|
)}
|
2022-11-19 14:21:26 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Dialog.Panel>
|
|
|
|
</Transition.Child>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Dialog>
|
|
|
|
</Transition.Root>
|
|
|
|
);
|
|
|
|
};
|