docs.tsx 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. import React from "react";
  2. import dynamic from "next/dynamic";
  3. import Head from "next/head";
  4. import { materialDark } from "react-syntax-highlighter/dist/cjs/styles/prism";
  5. import { Button } from "src/components/Button";
  6. import { Footer } from "src/components/Footer";
  7. import styled from "styled-components";
  8. const SyntaxHighlighter = dynamic(
  9. () => import("react-syntax-highlighter").then(c => c.PrismAsync),
  10. {
  11. ssr: false,
  12. }
  13. );
  14. const StyledFrame = styled.iframe`
  15. border: none;
  16. width: 80%;
  17. flex: 500px;
  18. margin: 3% auto;
  19. `;
  20. const StyledPage = styled.div`
  21. padding: 5%;
  22. `;
  23. const StyledContent = styled.section`
  24. margin-top: 20px;
  25. background: rgba(181, 116, 214, 0.23);
  26. padding: 16px;
  27. border-radius: 6px;
  28. `;
  29. const StyledDescription = styled.div``;
  30. const StyledContentBody = styled.div`
  31. display: flex;
  32. flex-direction: column;
  33. flex-wrap: wrap;
  34. gap: 15px;
  35. line-height: 1.8;
  36. ${StyledDescription} {
  37. flex: 1;
  38. }
  39. `;
  40. const StyledHighlight = styled.span<{ link?: boolean; alert?: boolean }>`
  41. text-align: left;
  42. white-space: nowrap;
  43. color: ${({ theme, link, alert }) =>
  44. alert ? theme.DANGER : link ? theme.BLURPLE : theme.TEXT_POSITIVE};
  45. background: ${({ theme }) => theme.BACKGROUND_TERTIARY};
  46. border-radius: 4px;
  47. font-weight: 500;
  48. padding: 4px;
  49. font-size: 14px;
  50. margin: ${({ alert }) => alert && "8px 0"};
  51. `;
  52. const Docs = () => {
  53. return (
  54. <>
  55. <Head>
  56. <title>Creating JSON Crack Embed | JSON Crack</title>
  57. <meta name="description" content="Embedding JSON Crack tutorial into your websites." />
  58. </Head>
  59. <StyledPage>
  60. <Button href="/" link status="SECONDARY">
  61. &lt; Go Back
  62. </Button>
  63. <h1>Documentation</h1>
  64. <iframe id="jsoncrackEmbed" src="//localhost:3000/widget" width="100%" height="100%"></iframe>
  65. <StyledContent>
  66. <h2># Fetching from URL</h2>
  67. <StyledContentBody>
  68. <StyledDescription>
  69. By adding <StyledHighlight>?json=https://catfact.ninja/fact</StyledHighlight> query at
  70. the end of iframe src you will be able to fetch from URL at widgets without additional
  71. scripts. This applies to editor page as well, the following link will fetch the url at
  72. the editor:{" "}
  73. <StyledHighlight
  74. as="a"
  75. href="https://jsoncrack.com/editor?json=https://catfact.ninja/fact"
  76. link
  77. >
  78. https://jsoncrack.com/editor?json=https://catfact.ninja/fact
  79. </StyledHighlight>
  80. </StyledDescription>
  81. <StyledFrame
  82. scrolling="no"
  83. title="Untitled"
  84. src="https://codepen.io/AykutSarac/embed/KKBpWVR?default-tab=html%2Cresult"
  85. loading="eager"
  86. >
  87. See the Pen <a href="https://codepen.io/AykutSarac/pen/KKBpWVR">Untitled</a> by Aykut
  88. Saraç (<a href="https://codepen.io/AykutSarac">@AykutSarac</a>) on{" "}
  89. <a href="https://codepen.io">CodePen</a>.
  90. </StyledFrame>
  91. </StyledContentBody>
  92. </StyledContent>
  93. <StyledContent>
  94. <h2># Embed Saved JSON</h2>
  95. <StyledContentBody>
  96. <StyledDescription>
  97. Just like fetching from URL above, you can embed saved public json by adding the json
  98. id to &quot;json&quot; query{" "}
  99. <StyledHighlight>?json=639b65c5a82efc29a24b2de2</StyledHighlight>
  100. </StyledDescription>
  101. <StyledFrame
  102. scrolling="no"
  103. title="Untitled"
  104. src="https://codepen.io/AykutSarac/embed/vYaORgM?default-tab=html%2Cresult"
  105. loading="lazy"
  106. >
  107. See the Pen <a href="https://codepen.io/AykutSarac/pen/vYaORgM">Untitled</a> by Aykut
  108. Saraç (<a href="https://codepen.io/AykutSarac">@AykutSarac</a>) on{" "}
  109. <a href="https://codepen.io">CodePen</a>.
  110. </StyledFrame>
  111. </StyledContentBody>
  112. </StyledContent>
  113. <StyledContent>
  114. <h2># Communicating with API</h2>
  115. <h3>◼︎ Post Message to Embed</h3>
  116. <StyledContentBody>
  117. <StyledDescription>
  118. Communicating with the embed is possible with{" "}
  119. <StyledHighlight
  120. as="a"
  121. href="https://developer.mozilla.org/en-US/docs/Web/API/MessagePort/postMessage"
  122. link
  123. >
  124. MessagePort
  125. </StyledHighlight>
  126. , you should pass an object consist of &quot;json&quot; and &quot;options&quot; key
  127. where json is a string and options is an object that may contain the following:
  128. <SyntaxHighlighter language="markdown" style={materialDark} showLineNumbers={true}>
  129. {`{\n\ttheme: "light" | "dark",\n\tdirection: "TOP" | "RIGHT" | "DOWN" | "LEFT"\n}`}
  130. </SyntaxHighlighter>
  131. </StyledDescription>
  132. <StyledFrame
  133. scrolling="no"
  134. title="Untitled"
  135. src="https://codepen.io/AykutSarac/embed/rNrVyWP?default-tab=html%2Cresult"
  136. loading="lazy"
  137. >
  138. See the Pen <a href="https://codepen.io/AykutSarac/pen/rNrVyWP">Untitled</a> by Aykut
  139. Saraç (<a href="https://codepen.io/AykutSarac">@AykutSarac</a>) on{" "}
  140. <a href="https://codepen.io">CodePen</a>.
  141. </StyledFrame>
  142. </StyledContentBody>
  143. </StyledContent>
  144. <StyledContent>
  145. <h3>◼︎ On Page Load</h3>
  146. <StyledContentBody>
  147. <StyledDescription>
  148. <StyledHighlight as="div" alert>
  149. ⚠️ <b>Important!</b> - iframe should be defined before the script tag
  150. </StyledHighlight>
  151. <StyledHighlight as="div" alert>
  152. ⚠️ <b>Note</b> - postMessage should be delayed using setTimeout
  153. </StyledHighlight>
  154. To display JSON on load event, you should post json into iframe using it&apos;s onload
  155. event like in the example. Make sure to use{" "}
  156. <StyledHighlight>setTimeout</StyledHighlight> when loading data and set a time around
  157. 500ms otherwise it won&apos;t work.
  158. </StyledDescription>
  159. <StyledFrame
  160. scrolling="no"
  161. title="Untitled"
  162. src="https://codepen.io/AykutSarac/embed/QWBbpqx?default-tab=html%2Cresult"
  163. loading="lazy"
  164. >
  165. See the Pen <a href="https://codepen.io/AykutSarac/pen/QWBbpqx">Untitled</a> by Aykut
  166. Saraç (<a href="https://codepen.io/AykutSarac">@AykutSarac</a>) on{" "}
  167. <a href="https://codepen.io">CodePen</a>.
  168. </StyledFrame>
  169. </StyledContentBody>
  170. </StyledContent>
  171. </StyledPage>
  172. <Footer />
  173. </>
  174. );
  175. };
  176. export default Docs;