mirror of
https://github.com/outline/outline.git
synced 2026-11-22 05:51:43 +03:00
types, self contained
This commit is contained in:
1 parent
3a30f80063
commit
8f018a2eee
8 files changed
+118
-106
No files matched your search
@@ -12,50 +12,12 @@ import styled from "styled-components";
|
||||
import MenuItem, { MenuAnchor } from "./MenuItem";
|
||||
import Separator from "./Separator";
|
||||
import ContextMenu from ".";
|
||||
import { type MenuItem as TMenuItem } from "types";
|
||||
|
||||
type TMenuItem =
|
||||
| {|
|
||||
title: React.Node,
|
||||
to: string,
|
||||
visible?: boolean,
|
||||
selected?: boolean,
|
||||
disabled?: boolean,
|
||||
|}
|
||||
| {|
|
||||
title: React.Node,
|
||||
onClick: (event: SyntheticEvent<>) => void | Promise<void>,
|
||||
visible?: boolean,
|
||||
selected?: boolean,
|
||||
disabled?: boolean,
|
||||
|}
|
||||
| {|
|
||||
title: React.Node,
|
||||
href: string,
|
||||
visible?: boolean,
|
||||
selected?: boolean,
|
||||
disabled?: boolean,
|
||||
|}
|
||||
| {|
|
||||
title: React.Node,
|
||||
visible?: boolean,
|
||||
disabled?: boolean,
|
||||
style?: Object,
|
||||
hover?: boolean,
|
||||
items: TMenuItem[],
|
||||
|}
|
||||
| {|
|
||||
type: "separator",
|
||||
visible?: boolean,
|
||||
|}
|
||||
| {|
|
||||
type: "heading",
|
||||
visible?: boolean,
|
||||
title: React.Node,
|
||||
|};
|
||||
|
||||
type Props = {
|
||||
type Props = {|
|
||||
items: TMenuItem[],
|
||||
};
|
||||
hide?: Function,
|
||||
|};
|
||||
|
||||
const Disclosure = styled(ExpandedIcon)`
|
||||
transform: rotate(270deg);
|
||||
|
||||
@@ -58,7 +58,6 @@ class Layout extends React.Component<Props> {
|
||||
scrollable: ?HTMLDivElement;
|
||||
@observable redirectTo: ?string;
|
||||
@observable keyboardShortcutsOpen: boolean = false;
|
||||
@observable quickMenuOpen: boolean = false;
|
||||
|
||||
componentDidUpdate() {
|
||||
if (this.redirectTo) {
|
||||
@@ -80,15 +79,6 @@ class Layout extends React.Component<Props> {
|
||||
this.keyboardShortcutsOpen = false;
|
||||
};
|
||||
|
||||
@keydown(`${meta}+k`)
|
||||
toggleQuickMenu() {
|
||||
this.quickMenuOpen = !this.quickMenuOpen;
|
||||
}
|
||||
|
||||
closeQuickMenu = () => {
|
||||
this.quickMenuOpen = false;
|
||||
};
|
||||
|
||||
@keydown(["t", "/"])
|
||||
goToSearch(ev: SyntheticEvent<>) {
|
||||
ev.preventDefault();
|
||||
@@ -179,10 +169,7 @@ class Layout extends React.Component<Props> {
|
||||
>
|
||||
<KeyboardShortcuts />
|
||||
</Guide>
|
||||
<QuickMenu
|
||||
isOpen={this.quickMenuOpen}
|
||||
requestClose={this.closeQuickMenu}
|
||||
/>
|
||||
<QuickMenu />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,14 +8,12 @@ import styled from "styled-components";
|
||||
import Template from "components/ContextMenu/Template";
|
||||
import InputSearch from "components/InputSearch";
|
||||
import Scrollable from "components/Scrollable";
|
||||
import usePrevious from "hooks/usePrevious";
|
||||
import useStores from "hooks/useStores";
|
||||
import useUnmount from "hooks/useUnmount";
|
||||
|
||||
function QuickMenu({ isOpen, requestClose }) {
|
||||
function QuickMenu() {
|
||||
const { quickMenu } = useStores();
|
||||
const dialog = useDialogState({ modal: true, animated: 250 });
|
||||
const wasOpen = usePrevious(isOpen);
|
||||
const { t } = useTranslation();
|
||||
|
||||
const handleSearchChange = React.useCallback(
|
||||
@@ -28,13 +26,16 @@ function QuickMenu({ isOpen, requestClose }) {
|
||||
useUnmount(() => quickMenu.setSearchTerm(""));
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!wasOpen && isOpen) {
|
||||
dialog.show();
|
||||
}
|
||||
if (wasOpen && !isOpen) {
|
||||
dialog.hide();
|
||||
}
|
||||
}, [dialog, wasOpen, isOpen]);
|
||||
const handleKeyDown = (event) => {
|
||||
if (event.key === "k" && event.metaKey) {
|
||||
dialog.visible ? dialog.hide() : dialog.show();
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener("keydown", handleKeyDown);
|
||||
|
||||
return () => window.removeEventListener("keydown", handleKeyDown);
|
||||
});
|
||||
|
||||
return (
|
||||
<DialogBackdrop {...dialog}>
|
||||
@@ -42,7 +43,6 @@ function QuickMenu({ isOpen, requestClose }) {
|
||||
<Backdrop {...props}>
|
||||
<Dialog
|
||||
{...dialog}
|
||||
hide={requestClose}
|
||||
aria-label={t("Quick menu")}
|
||||
preventBodyScroll
|
||||
hideOnEsc
|
||||
@@ -56,9 +56,9 @@ function QuickMenu({ isOpen, requestClose }) {
|
||||
<React.Fragment key={context.id}>
|
||||
<h3>{context.title}</h3>
|
||||
<Template
|
||||
hide={requestClose}
|
||||
{...dialog}
|
||||
items={context.items.filter(
|
||||
(item) => item.visible && item.type !== "separator"
|
||||
(item) => item.visible !== false
|
||||
)}
|
||||
/>
|
||||
</React.Fragment>
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
// @flow
|
||||
import useStores from "./useStores";
|
||||
|
||||
export default function useQuickMenu() {
|
||||
const { quickMenu } = useStores();
|
||||
return quickMenu;
|
||||
}
|
||||
+57
-28
@@ -3,7 +3,6 @@ import { observer } from "mobx-react";
|
||||
import { SunIcon, MoonIcon } from "outline-icons";
|
||||
import * as React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Link } from "react-router-dom";
|
||||
import { useMenuState, MenuButton } from "reakit/Menu";
|
||||
import styled from "styled-components";
|
||||
import {
|
||||
@@ -16,7 +15,7 @@ import {
|
||||
import KeyboardShortcuts from "scenes/KeyboardShortcuts";
|
||||
import ContextMenu from "components/ContextMenu";
|
||||
import MenuItem, { MenuAnchor } from "components/ContextMenu/MenuItem";
|
||||
import Separator from "components/ContextMenu/Separator";
|
||||
import Template from "components/ContextMenu/Template";
|
||||
import Flex from "components/Flex";
|
||||
import Guide from "components/Guide";
|
||||
import usePrevious from "hooks/usePrevious";
|
||||
@@ -75,7 +74,7 @@ function AccountMenu(props: Props) {
|
||||
placement: "bottom-start",
|
||||
modal: true,
|
||||
});
|
||||
const { auth, ui } = useStores();
|
||||
const { auth, ui, quickMenu } = useStores();
|
||||
const previousTheme = usePrevious(ui.theme);
|
||||
const { t } = useTranslation();
|
||||
const [keyboardShortcutsOpen, setKeyboardShortcutsOpen] = React.useState(
|
||||
@@ -88,6 +87,60 @@ function AccountMenu(props: Props) {
|
||||
}
|
||||
}, [menu, ui.theme, previousTheme]);
|
||||
|
||||
const items = [
|
||||
{
|
||||
title: t("Settings"),
|
||||
to: settings(),
|
||||
visible: true,
|
||||
},
|
||||
{
|
||||
title: t("Keyboard shortcuts"),
|
||||
onClick: () => setKeyboardShortcutsOpen(true),
|
||||
visible: true,
|
||||
},
|
||||
{
|
||||
title: t("API documentation"),
|
||||
href: developers(),
|
||||
},
|
||||
{
|
||||
type: "separator",
|
||||
},
|
||||
{
|
||||
title: t("Changelog"),
|
||||
href: changelog(),
|
||||
},
|
||||
{
|
||||
title: t("Send us feedback"),
|
||||
href: mailToUrl(),
|
||||
},
|
||||
{
|
||||
title: t("Report a bug"),
|
||||
href: githubIssuesUrl(),
|
||||
},
|
||||
{
|
||||
type: "separator",
|
||||
},
|
||||
{
|
||||
type: "separator",
|
||||
},
|
||||
{
|
||||
title: t("Log out"),
|
||||
onClick: auth.logout,
|
||||
},
|
||||
|
||||
// <MenuItem {...menu} as={AppearanceMenu} />
|
||||
];
|
||||
|
||||
React.useEffect(() => {
|
||||
quickMenu.addContext({
|
||||
id: "account",
|
||||
items,
|
||||
title: t("Account"),
|
||||
});
|
||||
|
||||
return () => quickMenu.removeContext("account");
|
||||
}, [quickMenu, items, t]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Guide
|
||||
@@ -99,31 +152,7 @@ function AccountMenu(props: Props) {
|
||||
</Guide>
|
||||
<MenuButton {...menu}>{props.children}</MenuButton>
|
||||
<ContextMenu {...menu} aria-label={t("Account")}>
|
||||
<MenuItem {...menu} as={Link} to={settings()}>
|
||||
{t("Settings")}
|
||||
</MenuItem>
|
||||
<MenuItem {...menu} onClick={() => setKeyboardShortcutsOpen(true)}>
|
||||
{t("Keyboard shortcuts")}
|
||||
</MenuItem>
|
||||
<MenuItem {...menu} href={developers()} target="_blank">
|
||||
{t("API documentation")}
|
||||
</MenuItem>
|
||||
<Separator {...menu} />
|
||||
<MenuItem {...menu} href={changelog()} target="_blank">
|
||||
{t("Changelog")}
|
||||
</MenuItem>
|
||||
<MenuItem {...menu} href={mailToUrl()} target="_blank">
|
||||
{t("Send us feedback")}
|
||||
</MenuItem>
|
||||
<MenuItem {...menu} href={githubIssuesUrl()} target="_blank">
|
||||
{t("Report a bug")}
|
||||
</MenuItem>
|
||||
<Separator {...menu} />
|
||||
<MenuItem {...menu} as={AppearanceMenu} />
|
||||
<Separator {...menu} />
|
||||
<MenuItem {...menu} onClick={auth.logout}>
|
||||
{t("Log out")}
|
||||
</MenuItem>
|
||||
<Template {...menu} items={items} />
|
||||
</ContextMenu>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -162,7 +162,7 @@ function CollectionMenu({
|
||||
}
|
||||
|
||||
return () => quickMenu.removeContext(id);
|
||||
}, [quickMenu, items, collection.id, ui.activeDocumentId, t]);
|
||||
}, [quickMenu, items, collection.id, ui.activeCollectionId, t]);
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
// @flow
|
||||
import { observable, computed, action } from "mobx";
|
||||
import { type MenuItem } from "types";
|
||||
|
||||
type QuickMenuContext = {|
|
||||
id: string,
|
||||
title: string,
|
||||
items: any[],
|
||||
items: MenuItem[],
|
||||
priority?: number,
|
||||
|};
|
||||
|
||||
|
||||
@@ -58,3 +58,43 @@ export type SearchResult = {
|
||||
context: string,
|
||||
document: Document,
|
||||
};
|
||||
|
||||
export type MenuItem =
|
||||
| {|
|
||||
title: React.Node,
|
||||
to: string,
|
||||
visible?: boolean,
|
||||
selected?: boolean,
|
||||
disabled?: boolean,
|
||||
|}
|
||||
| {|
|
||||
title: React.Node,
|
||||
onClick: (event: SyntheticEvent<>) => void | Promise<void>,
|
||||
visible?: boolean,
|
||||
selected?: boolean,
|
||||
disabled?: boolean,
|
||||
|}
|
||||
| {|
|
||||
title: React.Node,
|
||||
href: string,
|
||||
visible?: boolean,
|
||||
selected?: boolean,
|
||||
disabled?: boolean,
|
||||
|}
|
||||
| {|
|
||||
title: React.Node,
|
||||
visible?: boolean,
|
||||
disabled?: boolean,
|
||||
style?: Object,
|
||||
hover?: boolean,
|
||||
items: MenuItem[],
|
||||
|}
|
||||
| {|
|
||||
type: "separator",
|
||||
visible?: boolean,
|
||||
|}
|
||||
| {|
|
||||
type: "heading",
|
||||
visible?: boolean,
|
||||
title: React.Node,
|
||||
|};
|
||||
Reference in new issue
Block a user