docs.tsx 6.7 KB

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