HelpDialog.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. import React from "react";
  2. import { t } from "../i18n";
  3. import { isDarwin, isWindows } from "../keys";
  4. import { Dialog } from "./Dialog";
  5. import { getShortcutKey } from "../utils";
  6. import "./HelpDialog.scss";
  7. const Header = () => (
  8. <div className="HelpDialog--header">
  9. <a
  10. className="HelpDialog--btn"
  11. href="https://github.com/excalidraw/excalidraw#documentation"
  12. target="_blank"
  13. rel="noopener noreferrer"
  14. >
  15. {t("helpDialog.documentation")}
  16. </a>
  17. <a
  18. className="HelpDialog--btn"
  19. href="https://blog.excalidraw.com"
  20. target="_blank"
  21. rel="noopener noreferrer"
  22. >
  23. {t("helpDialog.blog")}
  24. </a>
  25. <a
  26. className="HelpDialog--btn"
  27. href="https://github.com/excalidraw/excalidraw/issues"
  28. target="_blank"
  29. rel="noopener noreferrer"
  30. >
  31. {t("helpDialog.github")}
  32. </a>
  33. </div>
  34. );
  35. const Section = (props: { title: string; children: React.ReactNode }) => (
  36. <>
  37. <h3>{props.title}</h3>
  38. {props.children}
  39. </>
  40. );
  41. const Columns = (props: { children: React.ReactNode }) => (
  42. <div
  43. style={{
  44. display: "flex",
  45. flexDirection: "row",
  46. flexWrap: "wrap",
  47. justifyContent: "space-between",
  48. }}
  49. >
  50. {props.children}
  51. </div>
  52. );
  53. const Column = (props: { children: React.ReactNode }) => (
  54. <div style={{ width: "49%" }}>{props.children}</div>
  55. );
  56. const ShortcutIsland = (props: {
  57. caption: string;
  58. children: React.ReactNode;
  59. }) => (
  60. <div className="HelpDialog--island">
  61. <h3 className="HelpDialog--island-title">{props.caption}</h3>
  62. {props.children}
  63. </div>
  64. );
  65. const Shortcut = (props: {
  66. label: string;
  67. shortcuts: string[];
  68. isOr: boolean;
  69. }) => {
  70. return (
  71. <div className="HelpDialog--shortcut">
  72. <div
  73. style={{
  74. display: "flex",
  75. margin: "0",
  76. padding: "4px 8px",
  77. alignItems: "center",
  78. }}
  79. >
  80. <div
  81. style={{
  82. lineHeight: 1.4,
  83. }}
  84. >
  85. {props.label}
  86. </div>
  87. <div
  88. style={{
  89. display: "flex",
  90. flex: "0 0 auto",
  91. justifyContent: "flex-end",
  92. marginInlineStart: "auto",
  93. minWidth: "30%",
  94. }}
  95. >
  96. {props.shortcuts.map((shortcut, index) => (
  97. <React.Fragment key={index}>
  98. <ShortcutKey>{shortcut}</ShortcutKey>
  99. {props.isOr &&
  100. index !== props.shortcuts.length - 1 &&
  101. t("helpDialog.or")}
  102. </React.Fragment>
  103. ))}
  104. </div>
  105. </div>
  106. </div>
  107. );
  108. };
  109. Shortcut.defaultProps = {
  110. isOr: true,
  111. };
  112. const ShortcutKey = (props: { children: React.ReactNode }) => (
  113. <kbd className="HelpDialog--key" {...props} />
  114. );
  115. export const HelpDialog = ({ onClose }: { onClose?: () => void }) => {
  116. const handleClose = React.useCallback(() => {
  117. if (onClose) {
  118. onClose();
  119. }
  120. }, [onClose]);
  121. return (
  122. <>
  123. <Dialog
  124. onCloseRequest={handleClose}
  125. title={t("helpDialog.title")}
  126. className={"HelpDialog"}
  127. >
  128. <Header />
  129. <Section title={t("helpDialog.shortcuts")}>
  130. <Columns>
  131. <Column>
  132. <ShortcutIsland caption={t("helpDialog.shapes")}>
  133. <Shortcut
  134. label={t("toolBar.selection")}
  135. shortcuts={["V", "1"]}
  136. />
  137. <Shortcut
  138. label={t("toolBar.rectangle")}
  139. shortcuts={["R", "2"]}
  140. />
  141. <Shortcut label={t("toolBar.diamond")} shortcuts={["D", "3"]} />
  142. <Shortcut label={t("toolBar.ellipse")} shortcuts={["E", "4"]} />
  143. <Shortcut label={t("toolBar.arrow")} shortcuts={["A", "5"]} />
  144. <Shortcut label={t("toolBar.line")} shortcuts={["P", "6"]} />
  145. <Shortcut
  146. label={t("toolBar.draw")}
  147. shortcuts={["Shift+P", "7"]}
  148. />
  149. <Shortcut label={t("toolBar.text")} shortcuts={["T", "8"]} />
  150. <Shortcut
  151. label={t("helpDialog.textNewLine")}
  152. shortcuts={[
  153. getShortcutKey("Enter"),
  154. getShortcutKey("Shift+Enter"),
  155. ]}
  156. />
  157. <Shortcut
  158. label={t("helpDialog.textFinish")}
  159. shortcuts={[
  160. getShortcutKey("Esc"),
  161. getShortcutKey("CtrlOrCmd+Enter"),
  162. ]}
  163. />
  164. <Shortcut
  165. label={t("helpDialog.curvedArrow")}
  166. shortcuts={[
  167. "A",
  168. t("helpDialog.click"),
  169. t("helpDialog.click"),
  170. t("helpDialog.click"),
  171. ]}
  172. isOr={false}
  173. />
  174. <Shortcut
  175. label={t("helpDialog.curvedLine")}
  176. shortcuts={[
  177. "L",
  178. t("helpDialog.click"),
  179. t("helpDialog.click"),
  180. t("helpDialog.click"),
  181. ]}
  182. isOr={false}
  183. />
  184. <Shortcut label={t("toolBar.lock")} shortcuts={["Q"]} />
  185. <Shortcut
  186. label={t("helpDialog.preventBinding")}
  187. shortcuts={[getShortcutKey("CtrlOrCmd")]}
  188. />
  189. </ShortcutIsland>
  190. <ShortcutIsland caption={t("helpDialog.view")}>
  191. <Shortcut
  192. label={t("buttons.zoomIn")}
  193. shortcuts={[getShortcutKey("CtrlOrCmd++")]}
  194. />
  195. <Shortcut
  196. label={t("buttons.zoomOut")}
  197. shortcuts={[getShortcutKey("CtrlOrCmd+-")]}
  198. />
  199. <Shortcut
  200. label={t("buttons.resetZoom")}
  201. shortcuts={[getShortcutKey("CtrlOrCmd+0")]}
  202. />
  203. <Shortcut
  204. label={t("helpDialog.zoomToFit")}
  205. shortcuts={["Shift+1"]}
  206. />
  207. <Shortcut
  208. label={t("helpDialog.zoomToSelection")}
  209. shortcuts={["Shift+2"]}
  210. />
  211. <Shortcut label={t("buttons.fullScreen")} shortcuts={["F"]} />
  212. <Shortcut
  213. label={t("buttons.zenMode")}
  214. shortcuts={[getShortcutKey("Alt+Z")]}
  215. />
  216. <Shortcut
  217. label={t("labels.showGrid")}
  218. shortcuts={[getShortcutKey("CtrlOrCmd+'")]}
  219. />
  220. <Shortcut
  221. label={t("labels.viewMode")}
  222. shortcuts={[getShortcutKey("Alt+R")]}
  223. />
  224. </ShortcutIsland>
  225. </Column>
  226. <Column>
  227. <ShortcutIsland caption={t("helpDialog.editor")}>
  228. <Shortcut
  229. label={t("labels.selectAll")}
  230. shortcuts={[getShortcutKey("CtrlOrCmd+A")]}
  231. />
  232. <Shortcut
  233. label={t("labels.multiSelect")}
  234. shortcuts={[getShortcutKey(`Shift+${t("helpDialog.click")}`)]}
  235. />
  236. <Shortcut
  237. label={t("labels.moveCanvas")}
  238. shortcuts={[
  239. getShortcutKey(`Space+${t("helpDialog.drag")}`),
  240. getShortcutKey(`Wheel+${t("helpDialog.drag")}`),
  241. ]}
  242. isOr={true}
  243. />
  244. <Shortcut
  245. label={t("labels.cut")}
  246. shortcuts={[getShortcutKey("CtrlOrCmd+X")]}
  247. />
  248. <Shortcut
  249. label={t("labels.copy")}
  250. shortcuts={[getShortcutKey("CtrlOrCmd+C")]}
  251. />
  252. <Shortcut
  253. label={t("labels.paste")}
  254. shortcuts={[getShortcutKey("CtrlOrCmd+V")]}
  255. />
  256. <Shortcut
  257. label={t("labels.copyAsPng")}
  258. shortcuts={[getShortcutKey("Shift+Alt+C")]}
  259. />
  260. <Shortcut
  261. label={t("labels.copyStyles")}
  262. shortcuts={[getShortcutKey("CtrlOrCmd+Alt+C")]}
  263. />
  264. <Shortcut
  265. label={t("labels.pasteStyles")}
  266. shortcuts={[getShortcutKey("CtrlOrCmd+Alt+V")]}
  267. />
  268. <Shortcut
  269. label={t("labels.delete")}
  270. shortcuts={[getShortcutKey("Del")]}
  271. />
  272. <Shortcut
  273. label={t("labels.sendToBack")}
  274. shortcuts={[
  275. isDarwin
  276. ? getShortcutKey("CtrlOrCmd+Alt+[")
  277. : getShortcutKey("CtrlOrCmd+Shift+["),
  278. ]}
  279. />
  280. <Shortcut
  281. label={t("labels.bringToFront")}
  282. shortcuts={[
  283. isDarwin
  284. ? getShortcutKey("CtrlOrCmd+Alt+]")
  285. : getShortcutKey("CtrlOrCmd+Shift+]"),
  286. ]}
  287. />
  288. <Shortcut
  289. label={t("labels.sendBackward")}
  290. shortcuts={[getShortcutKey("CtrlOrCmd+[")]}
  291. />
  292. <Shortcut
  293. label={t("labels.bringForward")}
  294. shortcuts={[getShortcutKey("CtrlOrCmd+]")]}
  295. />
  296. <Shortcut
  297. label={t("labels.alignTop")}
  298. shortcuts={[getShortcutKey("CtrlOrCmd+Shift+Up")]}
  299. />
  300. <Shortcut
  301. label={t("labels.alignBottom")}
  302. shortcuts={[getShortcutKey("CtrlOrCmd+Shift+Down")]}
  303. />
  304. <Shortcut
  305. label={t("labels.alignLeft")}
  306. shortcuts={[getShortcutKey("CtrlOrCmd+Shift+Left")]}
  307. />
  308. <Shortcut
  309. label={t("labels.alignRight")}
  310. shortcuts={[getShortcutKey("CtrlOrCmd+Shift+Right")]}
  311. />
  312. <Shortcut
  313. label={t("labels.duplicateSelection")}
  314. shortcuts={[
  315. getShortcutKey("CtrlOrCmd+D"),
  316. getShortcutKey(`Alt+${t("helpDialog.drag")}`),
  317. ]}
  318. />
  319. <Shortcut
  320. label={t("buttons.undo")}
  321. shortcuts={[getShortcutKey("CtrlOrCmd+Z")]}
  322. />
  323. <Shortcut
  324. label={t("buttons.redo")}
  325. shortcuts={
  326. isWindows
  327. ? [
  328. getShortcutKey("CtrlOrCmd+Y"),
  329. getShortcutKey("CtrlOrCmd+Shift+Z"),
  330. ]
  331. : [getShortcutKey("CtrlOrCmd+Shift+Z")]
  332. }
  333. />
  334. <Shortcut
  335. label={t("labels.group")}
  336. shortcuts={[getShortcutKey("CtrlOrCmd+G")]}
  337. />
  338. <Shortcut
  339. label={t("labels.ungroup")}
  340. shortcuts={[getShortcutKey("CtrlOrCmd+Shift+G")]}
  341. />
  342. </ShortcutIsland>
  343. </Column>
  344. </Columns>
  345. </Section>
  346. </Dialog>
  347. </>
  348. );
  349. };