feat: Checkmark to toggle context-menu-items (#2645)

This commit is contained in:
Rene 2020-12-20 23:20:03 +01:00 committed by GitHub
parent aff817c667
commit 0faec7efb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 27 additions and 17 deletions

View File

@ -19,8 +19,8 @@ export type ShortcutName =
| "copyAsSvg" | "copyAsSvg"
| "group" | "group"
| "ungroup" | "ungroup"
| "toggleGridMode" | "gridMode"
| "toggleStats" | "stats"
| "addToLibrary"; | "addToLibrary";
const shortcutMap: Record<ShortcutName, string[]> = { const shortcutMap: Record<ShortcutName, string[]> = {
@ -51,8 +51,8 @@ const shortcutMap: Record<ShortcutName, string[]> = {
copyAsSvg: [], copyAsSvg: [],
group: [getShortcutKey("CtrlOrCmd+G")], group: [getShortcutKey("CtrlOrCmd+G")],
ungroup: [getShortcutKey("CtrlOrCmd+Shift+G")], ungroup: [getShortcutKey("CtrlOrCmd+Shift+G")],
toggleGridMode: [getShortcutKey("CtrlOrCmd+'")], gridMode: [getShortcutKey("CtrlOrCmd+'")],
toggleStats: [], stats: [],
addToLibrary: [], addToLibrary: [],
}; };

View File

@ -3643,13 +3643,15 @@ class App extends React.Component<ExcalidrawProps, AppState> {
CANVAS_ONLY_ACTIONS.includes(action.name), CANVAS_ONLY_ACTIONS.includes(action.name),
), ),
{ {
shortcutName: "toggleGridMode", checked: this.state.gridSize !== null,
label: t("labels.toggleGridMode"), shortcutName: "gridMode",
label: t("labels.gridMode"),
action: this.toggleGridMode, action: this.toggleGridMode,
}, },
{ {
shortcutName: "toggleStats", checked: this.state.showStats,
label: t("labels.toggleStats"), shortcutName: "stats",
label: t("labels.stats"),
action: this.toggleStats, action: this.toggleStats,
}, },
], ],

View File

@ -34,6 +34,13 @@
grid-template-columns: 1fr 0.2fr; grid-template-columns: 1fr 0.2fr;
align-items: center; align-items: center;
&.checkmark::before {
position: absolute;
left: 6px;
margin-bottom: 1px;
content: "\2713";
}
&.dangerous { &.dangerous {
div:nth-child(1) { div:nth-child(1) {
color: $oc-red-7; color: $oc-red-7;

View File

@ -10,6 +10,7 @@ import {
} from "../actions/shortcuts"; } from "../actions/shortcuts";
type ContextMenuOption = { type ContextMenuOption = {
checked?: boolean;
shortcutName: ShortcutName; shortcutName: ShortcutName;
label: string; label: string;
action(): void; action(): void;
@ -42,12 +43,12 @@ const ContextMenu = ({ options, onCloseRequest, top, left }: Props) => {
className="context-menu" className="context-menu"
onContextMenu={(event) => event.preventDefault()} onContextMenu={(event) => event.preventDefault()}
> >
{options.map(({ action, shortcutName, label }, idx) => ( {options.map(({ action, checked, shortcutName, label }, idx) => (
<li data-testid={shortcutName} key={idx} onClick={onCloseRequest}> <li data-testid={shortcutName} key={idx} onClick={onCloseRequest}>
<button <button
className={`context-menu-option ${ className={`context-menu-option
shortcutName === "delete" ? "dangerous" : "" ${shortcutName === "delete" ? "dangerous" : ""}
}`} ${checked ? "checkmark" : ""}`}
onClick={action} onClick={action}
> >
<div>{label}</div> <div>{label}</div>

View File

@ -219,7 +219,7 @@ export const ShortcutsDialog = ({ onClose }: { onClose?: () => void }) => {
shortcuts={[getShortcutKey("Alt+Z")]} shortcuts={[getShortcutKey("Alt+Z")]}
/> />
<Shortcut <Shortcut
label={t("labels.toggleGridMode")} label={t("labels.gridMode")}
shortcuts={[getShortcutKey("CtrlOrCmd+'")]} shortcuts={[getShortcutKey("CtrlOrCmd+'")]}
/> />
</ShortcutIsland> </ShortcutIsland>

View File

@ -76,8 +76,8 @@
"group": "Group selection", "group": "Group selection",
"ungroup": "Ungroup selection", "ungroup": "Ungroup selection",
"collaborators": "Collaborators", "collaborators": "Collaborators",
"toggleGridMode": "Toggle grid mode", "gridMode": "Grid mode",
"toggleStats": "Toggle stats for nerds", "stats": "Stats for nerds",
"addToLibrary": "Add to library", "addToLibrary": "Add to library",
"removeFromLibrary": "Remove from library", "removeFromLibrary": "Remove from library",
"libraryLoadingMessage": "Loading library...", "libraryLoadingMessage": "Loading library...",

View File

@ -635,8 +635,8 @@ describe("regression tests", () => {
const contextMenu = document.querySelector(".context-menu"); const contextMenu = document.querySelector(".context-menu");
const expectedShortcutNames: ShortcutName[] = [ const expectedShortcutNames: ShortcutName[] = [
"selectAll", "selectAll",
"toggleGridMode", "gridMode",
"toggleStats", "stats",
]; ];
expect(contextMenu).not.toBeNull(); expect(contextMenu).not.toBeNull();