HelpDialog.tsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  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.tools")}>
  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={["O", "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.freedraw")}
  147. shortcuts={["Shift + P", "X", "7"]}
  148. />
  149. <Shortcut label={t("toolBar.text")} shortcuts={["T", "8"]} />
  150. <Shortcut label={t("toolBar.image")} shortcuts={["9"]} />
  151. <Shortcut label={t("toolBar.library")} shortcuts={["0"]} />
  152. <Shortcut
  153. label={t("toolBar.eraser")}
  154. shortcuts={[getShortcutKey("E")]}
  155. />
  156. <Shortcut
  157. label={t("helpDialog.editSelectedShape")}
  158. shortcuts={[
  159. getShortcutKey("Enter"),
  160. t("helpDialog.doubleClick"),
  161. ]}
  162. />
  163. <Shortcut
  164. label={t("helpDialog.textNewLine")}
  165. shortcuts={[
  166. getShortcutKey("Enter"),
  167. getShortcutKey("Shift+Enter"),
  168. ]}
  169. />
  170. <Shortcut
  171. label={t("helpDialog.textFinish")}
  172. shortcuts={[
  173. getShortcutKey("Esc"),
  174. getShortcutKey("CtrlOrCmd+Enter"),
  175. ]}
  176. />
  177. <Shortcut
  178. label={t("helpDialog.curvedArrow")}
  179. shortcuts={[
  180. "A",
  181. t("helpDialog.click"),
  182. t("helpDialog.click"),
  183. t("helpDialog.click"),
  184. ]}
  185. isOr={false}
  186. />
  187. <Shortcut
  188. label={t("helpDialog.curvedLine")}
  189. shortcuts={[
  190. "L",
  191. t("helpDialog.click"),
  192. t("helpDialog.click"),
  193. t("helpDialog.click"),
  194. ]}
  195. isOr={false}
  196. />
  197. <Shortcut label={t("toolBar.lock")} shortcuts={["Q"]} />
  198. <Shortcut
  199. label={t("helpDialog.preventBinding")}
  200. shortcuts={[getShortcutKey("CtrlOrCmd")]}
  201. />
  202. <Shortcut
  203. label={t("toolBar.link")}
  204. shortcuts={[getShortcutKey("CtrlOrCmd+K")]}
  205. />
  206. </ShortcutIsland>
  207. <ShortcutIsland caption={t("helpDialog.view")}>
  208. <Shortcut
  209. label={t("buttons.zoomIn")}
  210. shortcuts={[getShortcutKey("CtrlOrCmd++")]}
  211. />
  212. <Shortcut
  213. label={t("buttons.zoomOut")}
  214. shortcuts={[getShortcutKey("CtrlOrCmd+-")]}
  215. />
  216. <Shortcut
  217. label={t("buttons.resetZoom")}
  218. shortcuts={[getShortcutKey("CtrlOrCmd+0")]}
  219. />
  220. <Shortcut
  221. label={t("helpDialog.zoomToFit")}
  222. shortcuts={["Shift+1"]}
  223. />
  224. <Shortcut
  225. label={t("helpDialog.zoomToSelection")}
  226. shortcuts={["Shift+2"]}
  227. />
  228. <Shortcut label={t("buttons.fullScreen")} shortcuts={["F"]} />
  229. <Shortcut
  230. label={t("buttons.zenMode")}
  231. shortcuts={[getShortcutKey("Alt+Z")]}
  232. />
  233. <Shortcut
  234. label={t("labels.showGrid")}
  235. shortcuts={[getShortcutKey("CtrlOrCmd+'")]}
  236. />
  237. <Shortcut
  238. label={t("labels.viewMode")}
  239. shortcuts={[getShortcutKey("Alt+R")]}
  240. />
  241. <Shortcut
  242. label={t("labels.toggleTheme")}
  243. shortcuts={[getShortcutKey("Alt+Shift+D")]}
  244. />
  245. <Shortcut
  246. label={t("stats.title")}
  247. shortcuts={[getShortcutKey("Alt+/")]}
  248. />
  249. </ShortcutIsland>
  250. </Column>
  251. <Column>
  252. <ShortcutIsland caption={t("helpDialog.editor")}>
  253. <Shortcut
  254. label={t("labels.selectAll")}
  255. shortcuts={[getShortcutKey("CtrlOrCmd+A")]}
  256. />
  257. <Shortcut
  258. label={t("labels.multiSelect")}
  259. shortcuts={[getShortcutKey(`Shift+${t("helpDialog.click")}`)]}
  260. />
  261. <Shortcut
  262. label={t("helpDialog.deepSelect")}
  263. shortcuts={[
  264. getShortcutKey(`CtrlOrCmd+${t("helpDialog.click")}`),
  265. ]}
  266. />
  267. <Shortcut
  268. label={t("helpDialog.deepBoxSelect")}
  269. shortcuts={[
  270. getShortcutKey(`CtrlOrCmd+${t("helpDialog.drag")}`),
  271. ]}
  272. />
  273. <Shortcut
  274. label={t("labels.moveCanvas")}
  275. shortcuts={[
  276. getShortcutKey(`Space+${t("helpDialog.drag")}`),
  277. getShortcutKey(`Wheel+${t("helpDialog.drag")}`),
  278. ]}
  279. isOr={true}
  280. />
  281. <Shortcut
  282. label={t("labels.cut")}
  283. shortcuts={[getShortcutKey("CtrlOrCmd+X")]}
  284. />
  285. <Shortcut
  286. label={t("labels.copy")}
  287. shortcuts={[getShortcutKey("CtrlOrCmd+C")]}
  288. />
  289. <Shortcut
  290. label={t("labels.paste")}
  291. shortcuts={[getShortcutKey("CtrlOrCmd+V")]}
  292. />
  293. <Shortcut
  294. label={t("labels.copyAsPng")}
  295. shortcuts={[getShortcutKey("Shift+Alt+C")]}
  296. />
  297. <Shortcut
  298. label={t("labels.copyStyles")}
  299. shortcuts={[getShortcutKey("CtrlOrCmd+Alt+C")]}
  300. />
  301. <Shortcut
  302. label={t("labels.pasteStyles")}
  303. shortcuts={[getShortcutKey("CtrlOrCmd+Alt+V")]}
  304. />
  305. <Shortcut
  306. label={t("labels.delete")}
  307. shortcuts={[getShortcutKey("Del")]}
  308. />
  309. <Shortcut
  310. label={t("labels.sendToBack")}
  311. shortcuts={[
  312. isDarwin
  313. ? getShortcutKey("CtrlOrCmd+Alt+[")
  314. : getShortcutKey("CtrlOrCmd+Shift+["),
  315. ]}
  316. />
  317. <Shortcut
  318. label={t("labels.bringToFront")}
  319. shortcuts={[
  320. isDarwin
  321. ? getShortcutKey("CtrlOrCmd+Alt+]")
  322. : getShortcutKey("CtrlOrCmd+Shift+]"),
  323. ]}
  324. />
  325. <Shortcut
  326. label={t("labels.sendBackward")}
  327. shortcuts={[getShortcutKey("CtrlOrCmd+[")]}
  328. />
  329. <Shortcut
  330. label={t("labels.bringForward")}
  331. shortcuts={[getShortcutKey("CtrlOrCmd+]")]}
  332. />
  333. <Shortcut
  334. label={t("labels.alignTop")}
  335. shortcuts={[getShortcutKey("CtrlOrCmd+Shift+Up")]}
  336. />
  337. <Shortcut
  338. label={t("labels.alignBottom")}
  339. shortcuts={[getShortcutKey("CtrlOrCmd+Shift+Down")]}
  340. />
  341. <Shortcut
  342. label={t("labels.alignLeft")}
  343. shortcuts={[getShortcutKey("CtrlOrCmd+Shift+Left")]}
  344. />
  345. <Shortcut
  346. label={t("labels.alignRight")}
  347. shortcuts={[getShortcutKey("CtrlOrCmd+Shift+Right")]}
  348. />
  349. <Shortcut
  350. label={t("labels.duplicateSelection")}
  351. shortcuts={[
  352. getShortcutKey("CtrlOrCmd+D"),
  353. getShortcutKey(`Alt+${t("helpDialog.drag")}`),
  354. ]}
  355. />
  356. <Shortcut
  357. label={t("buttons.undo")}
  358. shortcuts={[getShortcutKey("CtrlOrCmd+Z")]}
  359. />
  360. <Shortcut
  361. label={t("buttons.redo")}
  362. shortcuts={
  363. isWindows
  364. ? [
  365. getShortcutKey("CtrlOrCmd+Y"),
  366. getShortcutKey("CtrlOrCmd+Shift+Z"),
  367. ]
  368. : [getShortcutKey("CtrlOrCmd+Shift+Z")]
  369. }
  370. />
  371. <Shortcut
  372. label={t("labels.group")}
  373. shortcuts={[getShortcutKey("CtrlOrCmd+G")]}
  374. />
  375. <Shortcut
  376. label={t("labels.ungroup")}
  377. shortcuts={[getShortcutKey("CtrlOrCmd+Shift+G")]}
  378. />
  379. <Shortcut
  380. label={t("labels.flipHorizontal")}
  381. shortcuts={[getShortcutKey("Shift+H")]}
  382. />
  383. <Shortcut
  384. label={t("labels.flipVertical")}
  385. shortcuts={[getShortcutKey("Shift+V")]}
  386. />
  387. <Shortcut
  388. label={t("labels.showStroke")}
  389. shortcuts={[getShortcutKey("S")]}
  390. />
  391. <Shortcut
  392. label={t("labels.showBackground")}
  393. shortcuts={[getShortcutKey("G")]}
  394. />
  395. <Shortcut
  396. label={t("labels.decreaseFontSize")}
  397. shortcuts={[getShortcutKey("CtrlOrCmd+Shift+<")]}
  398. />
  399. <Shortcut
  400. label={t("labels.increaseFontSize")}
  401. shortcuts={[getShortcutKey("CtrlOrCmd+Shift+>")]}
  402. />
  403. </ShortcutIsland>
  404. </Column>
  405. </Columns>
  406. </Section>
  407. </Dialog>
  408. </>
  409. );
  410. };