Cheatsheet.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* eslint-disable max-len */
  2. import React from 'react';
  3. import { useTranslation } from 'next-i18next';
  4. import { PrismAsyncLight } from 'react-syntax-highlighter';
  5. import { oneDark } from 'react-syntax-highlighter/dist/cjs/styles/prism';
  6. export const Cheatsheet = (): JSX.Element => {
  7. const { t } = useTranslation();
  8. /*
  9. * Each Element
  10. */
  11. // Left Side
  12. const codeStr = `# ${t('sandbox.header_x', { index: '1' })}\n## ${t('sandbox.header_x', { index: '2' })}\n### ${t('sandbox.header_x', { index: '3' })}`;
  13. const codeBlockStr = 'text\n\ntext';
  14. const lineBlockStr = 'text\ntext';
  15. const typographyStr = `*${t('sandbox.italics')}*\n**${t('sandbox.bold')}**\n***${t('sandbox.italic_bold')}***\n~~${t('sandbox.strikethrough')}~~`;
  16. const linkStr = '[Google](https://www.google.co.jp/)';
  17. const codeHighlightStr = '```javascript:index.js\nwriteCode();\n```';
  18. // Right Side
  19. const codeListStr = `- ${t('sandbox.unordered_list_x', { index: '1' })}
  20. - ${t('sandbox.unordered_list_x', { index: '1.1' })}
  21. - ${t('sandbox.unordered_list_x', { index: '1.2' })}`;
  22. const orderedListStr = `1. ${t('sandbox.ordered_list_x', { index: '1' })}\n1. ${t('sandbox.ordered_list_x', { index: '2' })}`;
  23. const taskStr = `- [ ] ${t('sandbox.task')}(${t('sandbox.task_unchecked')})\n- [x] ${t('sandbox.task')}(${t('sandbox.task_checked')})`;
  24. const quoteStr = `> ${t('sandbox.quote1')}\n> ${t('sandbox.quote2')}`;
  25. const nestedQuoteStr = `>> ${t('sandbox.quote_nested')}\n>>> ${t('sandbox.quote_nested')}\n>>>> ${t('sandbox.quote_nested')}`;
  26. const tableStr = '|Left | Mid | Right|\n|:----------|:---------:|----------:|\n|col 1 | col 2 | col 3|\n|col 1 | col 2 | col 3|';
  27. const imageStr = '![ex](https://example.com/image.png)';
  28. const renderCheetSheetElm = (CheetSheetElm: string) => {
  29. return (
  30. <PrismAsyncLight
  31. className="code-highlighted"
  32. PreTag="div"
  33. style={oneDark}
  34. language="text"
  35. >
  36. {String(CheetSheetElm).replace(/\n$/, '')}
  37. </PrismAsyncLight>
  38. );
  39. };
  40. return (
  41. <div className="row small">
  42. <div className="col-sm-6">
  43. {/* Header */}
  44. <h4>{t('sandbox.header')}</h4>
  45. {renderCheetSheetElm(codeStr)}
  46. {/* Block */}
  47. <h4>{t('sandbox.block')}</h4>
  48. <p className="mb-1"><code>[{t('sandbox.empty_line')}]</code>{t('sandbox.block_detail')}</p>
  49. {renderCheetSheetElm(codeBlockStr)}
  50. {/* Line Break */}
  51. <h4>{t('sandbox.line_break')}</h4>
  52. <p className="mb-1"><code>[ ][ ]</code> {t('sandbox.line_break_detail')}</p>
  53. {renderCheetSheetElm(lineBlockStr)}
  54. {/* Typography */}
  55. <h4>{t('sandbox.typography')}</h4>
  56. {renderCheetSheetElm(typographyStr)}
  57. {/* Link */}
  58. <h4>{t('sandbox.link')}</h4>
  59. {renderCheetSheetElm(linkStr)}
  60. {/* CodeHhighlight */}
  61. <h4>{t('sandbox.code_highlight')}</h4>
  62. {renderCheetSheetElm(codeHighlightStr)}
  63. </div>
  64. <div className="col-sm-6">
  65. {/* List */}
  66. <h4>{t('sandbox.list')}</h4>
  67. {renderCheetSheetElm(codeListStr)}
  68. {renderCheetSheetElm(orderedListStr)}
  69. {renderCheetSheetElm(taskStr)}
  70. {/* Quote */}
  71. <h4>{t('sandbox.quote')}</h4>
  72. {renderCheetSheetElm(quoteStr)}
  73. {renderCheetSheetElm(nestedQuoteStr)}
  74. {/* Table */}
  75. <h4>{t('sandbox.table')}</h4>
  76. {renderCheetSheetElm(tableStr)}
  77. {/* Image */}
  78. <h4>{t('sandbox.image')}</h4>
  79. <p className="mb-1"><code> ![{t('sandbox.alt_text')}](URL)</code> {t('sandbox.insert_image')}</p>
  80. {renderCheetSheetElm(imageStr)}
  81. <hr />
  82. <a href="/Sandbox" className="btn btn-info" target="_blank">
  83. <span className="growi-custom-icons">external_link</span> {t('sandbox.open_sandbox')}
  84. </a>
  85. </div>
  86. </div>
  87. );
  88. };