document-diff-viewer.stories.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. import { ScopeDecorator } from '../decorators/scope'
  2. import DocumentDiffViewer from '../../js/features/history/components/diff-view/document-diff-viewer'
  3. import React from 'react'
  4. import { Highlight } from '../../js/features/history/services/types/doc'
  5. const highlights: Highlight[] = [
  6. {
  7. type: 'addition',
  8. range: { from: 3, to: 10 },
  9. hue: 200,
  10. label: 'Added by Wombat on Monday',
  11. },
  12. {
  13. type: 'deletion',
  14. range: { from: 15, to: 25 },
  15. hue: 62,
  16. label: 'Deleted by Duck on Monday',
  17. },
  18. {
  19. type: 'addition',
  20. range: { from: 100, to: 400 },
  21. hue: 200,
  22. label: 'Added by Wombat on Friday',
  23. },
  24. {
  25. type: 'deletion',
  26. range: { from: 564, to: 565 },
  27. hue: 200,
  28. label: 'Deleted by Wombat on Friday',
  29. },
  30. {
  31. type: 'addition',
  32. range: { from: 1770, to: 1780 },
  33. hue: 200,
  34. label: 'Added by Wombat on Tuesday',
  35. },
  36. ]
  37. const doc = `\\documentclass{article}
  38. % Language setting
  39. % Replace \`english' with e.g. \`spanish' to change the document language
  40. \\usepackage[english]{babel}
  41. % Set page size and margins
  42. % Replace \`letterpaper' with \`a4paper' for UK/EU standard size
  43. \\usepackage[letterpaper,top=2cm,bottom=2cm,left=3cm,right=3cm,marginparwidth=1.75cm]{geometry}
  44. % Useful packages
  45. \\usepackage{amsmath}
  46. \\usepackage{graphicx}
  47. \\usepackage[colorlinks=true, allcolors=blue]{hyperref}
  48. \\title{Your Paper}
  49. \\author{You}
  50. \\begin{document}
  51. \\maketitle
  52. \\begin{abstract}
  53. Your abstract.
  54. \\end{abstract}
  55. \\section{Introduction}
  56. Your introduction goes here! Simply start writing your document and use the Recompile button to view the updated PDF preview. Examples of commonly used commands and features are listed below, to help you get started.
  57. Once you're familiar with the editor, you can find various project settings in the Overleaf menu, accessed via the button in the very top left of the editor. To view tutorials, user guides, and further documentation, please visit our \\href{https://www.overleaf.com/learn}{help library}, or head to our plans page to \\href{https://www.overleaf.com/user/subscription/plans}{choose your plan}.
  58. \\begin{enumerate}
  59. \\item The labels consists of sequential numbers
  60. \\begin{itemize}
  61. \\item The individual entries are indicated with a black dot, a so-called bullet
  62. \\item The text in the entries may be of any length
  63. \\begin{description}
  64. \\item[Note:] I would like to describe something here
  65. \\item[Caveat!] And give a warning
  66. \\end{description}
  67. \\end{itemize}
  68. \\item The numbers starts at 1 with each use of the \\text{enumerate} environment
  69. \\end{enumerate}
  70. \\bibliographystyle{alpha}
  71. \\bibliography{sample}
  72. \\end{document}`
  73. export default {
  74. title: 'History / Document Diff Viewer',
  75. component: DocumentDiffViewer,
  76. args: { doc, highlights },
  77. argTypes: {
  78. doc: {
  79. table: { disable: true },
  80. },
  81. highlights: {
  82. table: { disable: true },
  83. },
  84. },
  85. decorators: [
  86. ScopeDecorator,
  87. (Story: React.ComponentType) => (
  88. <div style={{ height: '90vh' }}>
  89. <Story />
  90. </div>
  91. ),
  92. ],
  93. }
  94. export const Highlights = (
  95. args: React.ComponentProps<typeof DocumentDiffViewer>
  96. ) => {
  97. return <DocumentDiffViewer {...args} />
  98. }
  99. export const ScrollToFirstHighlight = (
  100. args: React.ComponentProps<typeof DocumentDiffViewer>
  101. ) => {
  102. const lastHighlightOnly = args.highlights.slice(-1)
  103. return <DocumentDiffViewer {...args} highlights={lastHighlightOnly} />
  104. }