Cheatsheet.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* eslint-disable max-len */
  2. import React, { type JSX } 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 =
  27. '|Left | Mid | Right|\n|:----------|:---------:|----------:|\n|col 1 | col 2 | col 3|\n|col 1 | col 2 | col 3|';
  28. const imageStr = '![ex](https://example.com/image.png)';
  29. const renderCheetSheetElm = (CheetSheetElm: string) => {
  30. return (
  31. <PrismAsyncLight
  32. className="code-highlighted"
  33. PreTag="div"
  34. style={oneDark}
  35. language="text"
  36. >
  37. {String(CheetSheetElm).replace(/\n$/, '')}
  38. </PrismAsyncLight>
  39. );
  40. };
  41. return (
  42. <div className="row small">
  43. <div className="col-sm-6">
  44. {/* Header */}
  45. <h4>{t('sandbox.header')}</h4>
  46. {renderCheetSheetElm(codeStr)}
  47. {/* Block */}
  48. <h4>{t('sandbox.block')}</h4>
  49. <p className="mb-1">
  50. <code>[{t('sandbox.empty_line')}]</code>
  51. {t('sandbox.block_detail')}
  52. </p>
  53. {renderCheetSheetElm(codeBlockStr)}
  54. {/* Line Break */}
  55. <h4>{t('sandbox.line_break')}</h4>
  56. <p className="mb-1">
  57. <code>[ ][ ]</code> {t('sandbox.line_break_detail')}
  58. </p>
  59. {renderCheetSheetElm(lineBlockStr)}
  60. {/* Typography */}
  61. <h4>{t('sandbox.typography')}</h4>
  62. {renderCheetSheetElm(typographyStr)}
  63. {/* Link */}
  64. <h4>{t('sandbox.link')}</h4>
  65. {renderCheetSheetElm(linkStr)}
  66. {/* CodeHhighlight */}
  67. <h4>{t('sandbox.code_highlight')}</h4>
  68. {renderCheetSheetElm(codeHighlightStr)}
  69. </div>
  70. <div className="col-sm-6">
  71. {/* List */}
  72. <h4>{t('sandbox.list')}</h4>
  73. {renderCheetSheetElm(codeListStr)}
  74. {renderCheetSheetElm(orderedListStr)}
  75. {renderCheetSheetElm(taskStr)}
  76. {/* Quote */}
  77. <h4>{t('sandbox.quote')}</h4>
  78. {renderCheetSheetElm(quoteStr)}
  79. {renderCheetSheetElm(nestedQuoteStr)}
  80. {/* Table */}
  81. <h4>{t('sandbox.table')}</h4>
  82. {renderCheetSheetElm(tableStr)}
  83. {/* Image */}
  84. <h4>{t('sandbox.image')}</h4>
  85. <p className="mb-1">
  86. <code> ![{t('sandbox.alt_text')}](URL)</code>{' '}
  87. {t('sandbox.insert_image')}
  88. </p>
  89. {renderCheetSheetElm(imageStr)}
  90. <hr />
  91. <a
  92. href="/Sandbox"
  93. className="btn btn-info"
  94. target="_blank"
  95. rel="noopener"
  96. >
  97. <span className="growi-custom-icons">external_link</span>{' '}
  98. {t('sandbox.open_sandbox')}
  99. </a>
  100. </div>
  101. </div>
  102. );
  103. };