mirror of
https://github.com/docmost/docmost.git
synced 2026-05-07 06:23:06 +08:00
switch to menu component
This commit is contained in:
@@ -4,6 +4,14 @@
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
min-height: 2.25rem;
|
min-height: 2.25rem;
|
||||||
}
|
}
|
||||||
|
.menuItemSelected {
|
||||||
|
background-color: var(--mantine-color-gray-1);
|
||||||
|
|
||||||
|
@mixin dark {
|
||||||
|
background-color: var(--mantine-color-dark-5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.resultPreviewWrapper {
|
.resultPreviewWrapper {
|
||||||
*:first-child {
|
*:first-child {
|
||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ import {
|
|||||||
IconCheck,
|
IconCheck,
|
||||||
IconArrowDownLeft,
|
IconArrowDownLeft,
|
||||||
IconCopy,
|
IconCopy,
|
||||||
|
IconTextPlus,
|
||||||
|
IconAlignJustified,
|
||||||
} from "@tabler/icons-react";
|
} from "@tabler/icons-react";
|
||||||
|
|
||||||
interface CommandItem {
|
interface CommandItem {
|
||||||
@@ -43,13 +45,13 @@ const mainItems: CommandItem[] = [
|
|||||||
{
|
{
|
||||||
id: "make-longer",
|
id: "make-longer",
|
||||||
name: "Make longer",
|
name: "Make longer",
|
||||||
icon: IconArrowsMaximize,
|
icon: IconTextPlus,
|
||||||
action: AiAction.MAKE_LONGER,
|
action: AiAction.MAKE_LONGER,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "make-shorter",
|
id: "make-shorter",
|
||||||
name: "Make shorter",
|
name: "Make shorter",
|
||||||
icon: IconArrowsMinimize,
|
icon: IconAlignJustified,
|
||||||
action: AiAction.MAKE_SHORTER,
|
action: AiAction.MAKE_SHORTER,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -73,13 +75,13 @@ const mainItems: CommandItem[] = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "change-tone",
|
id: "change-tone",
|
||||||
name: "Change tone...",
|
name: "Change tone",
|
||||||
icon: IconMoodSmile,
|
icon: IconMoodSmile,
|
||||||
subCommandSet: "tone",
|
subCommandSet: "tone",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "translate",
|
id: "translate",
|
||||||
name: "Translate...",
|
name: "Translate",
|
||||||
icon: IconLanguage,
|
icon: IconLanguage,
|
||||||
subCommandSet: "translate",
|
subCommandSet: "translate",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { Button, Menu, ScrollArea } from "@mantine/core";
|
import { Loader, Menu, ScrollArea } from "@mantine/core";
|
||||||
|
import { IconChevronRight } from "@tabler/icons-react";
|
||||||
import { ReactNode } from "react";
|
import { ReactNode } from "react";
|
||||||
import { CommandItem } from "./command-items";
|
import { CommandItem } from "./command-items";
|
||||||
|
import classes from "./ai-menu.module.css";
|
||||||
|
|
||||||
interface CommandSelectorProps {
|
interface CommandSelectorProps {
|
||||||
selectedIndex: number;
|
selectedIndex: number;
|
||||||
@@ -25,36 +27,41 @@ const CommandSelector = ({
|
|||||||
opened={!isLoading && currentItems.length > 0}
|
opened={!isLoading && currentItems.length > 0}
|
||||||
position="bottom-start"
|
position="bottom-start"
|
||||||
offset={4}
|
offset={4}
|
||||||
width={300}
|
width={250}
|
||||||
trapFocus={false}
|
trapFocus={false}
|
||||||
|
shadow="lg"
|
||||||
>
|
>
|
||||||
<Menu.Target>{children}</Menu.Target>
|
<Menu.Target>{children}</Menu.Target>
|
||||||
<Menu.Dropdown>
|
<Menu.Dropdown>
|
||||||
<ScrollArea.Autosize type="scroll" mah={400}>
|
<ScrollArea.Autosize type="scroll" scrollbarSize={5} mah={300}>
|
||||||
<Button.Group orientation="vertical" display="flex">
|
|
||||||
{currentItems.map((item, index) => {
|
{currentItems.map((item, index) => {
|
||||||
const unselectedVariant =
|
const isSelected = selectedIndex === index;
|
||||||
item.id === "back" ? "subtle" : "default";
|
const showLoader =
|
||||||
|
isLoading && output === "" && !item.subCommandSet;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button
|
<Menu.Item
|
||||||
key={item.id}
|
key={item.id}
|
||||||
variant={
|
className={isSelected ? classes.menuItemSelected : undefined}
|
||||||
selectedIndex === index ? "light" : unselectedVariant
|
leftSection={
|
||||||
|
showLoader ? (
|
||||||
|
<Loader size={14} />
|
||||||
|
) : item.icon ? (
|
||||||
|
<item.icon size={16} />
|
||||||
|
) : undefined
|
||||||
|
}
|
||||||
|
rightSection={
|
||||||
|
item.subCommandSet ? (
|
||||||
|
<IconChevronRight size={14} />
|
||||||
|
) : undefined
|
||||||
}
|
}
|
||||||
leftSection={item.icon ? <item.icon size={16} /> : undefined}
|
|
||||||
justify="left"
|
|
||||||
fullWidth
|
|
||||||
onClick={() => handleCommand(item)}
|
onClick={() => handleCommand(item)}
|
||||||
style={{ border: "none" }}
|
|
||||||
loading={isLoading && output === "" && !item.subCommandSet}
|
|
||||||
disabled={isLoading}
|
disabled={isLoading}
|
||||||
>
|
>
|
||||||
{item.name}
|
{item.name}
|
||||||
</Button>
|
</Menu.Item>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</Button.Group>
|
|
||||||
</ScrollArea.Autosize>
|
</ScrollArea.Autosize>
|
||||||
</Menu.Dropdown>
|
</Menu.Dropdown>
|
||||||
</Menu>
|
</Menu>
|
||||||
|
|||||||
Reference in New Issue
Block a user