Design system.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

188 lines
5.2 KiB

  1. import {NextPage} from 'next';
  2. import * as React from 'react';
  3. import * as BlobReact from '@tesseract-design/web-blob-react';
  4. import {DefaultLayout} from '@/components/DefaultLayout';
  5. import {Section, Subsection} from '@/components/Section';
  6. import {addDataUrl} from '@/utils/blob';
  7. const BlobPage: NextPage = () => {
  8. const [imageFile, setImageFile] = React.useState<Partial<File>>();
  9. React.useEffect(() => {
  10. fetch('/image.png').then((response) => {
  11. response.blob().then(async (blob) => {
  12. const imageFile = new File([blob], 'image.png', {
  13. type: 'image/png',
  14. });
  15. const theFile = await addDataUrl(imageFile);
  16. setImageFile(theFile);
  17. });
  18. });
  19. }, []);
  20. const [videoFile, setVideoFile] = React.useState<File>();
  21. React.useEffect(() => {
  22. fetch('/video.mp4').then((response) => {
  23. response.blob().then((blob) => {
  24. setVideoFile(new File([blob], 'video.mp4', {
  25. type: 'video/mp4',
  26. }));
  27. });
  28. });
  29. }, []);
  30. const [audioFile, setAudioFile] = React.useState<File>();
  31. React.useEffect(() => {
  32. fetch('/audio.wav').then((response) => {
  33. response.blob().then((blob) => {
  34. setAudioFile(new File([blob], 'audio.wav', {
  35. type: 'audio/wav',
  36. }));
  37. });
  38. });
  39. }, []);
  40. const [binaryFile, setBinaryFile] = React.useState<File>();
  41. React.useEffect(() => {
  42. fetch('/binary.bin').then((response) => {
  43. response.blob().then((blob) => {
  44. setBinaryFile(new File([blob], 'binary.bin', {
  45. type: 'application/octet-stream',
  46. }));
  47. });
  48. });
  49. }, []);
  50. const [plaintextFile, setPlaintextFile] = React.useState<File>();
  51. React.useEffect(() => {
  52. fetch('/plaintext.txt').then((response) => {
  53. response.blob().then((blob) => {
  54. setPlaintextFile(new File([blob], 'plaintext.txt', {
  55. type: 'text/plain',
  56. }));
  57. });
  58. });
  59. }, []);
  60. const [codeFile, setCodeFile] = React.useState<File>();
  61. React.useEffect(() => {
  62. fetch('/code.py').then((response) => {
  63. response.blob().then((blob) => {
  64. setCodeFile(new File([blob], 'code.py', {
  65. type: 'text/x-python',
  66. }));
  67. });
  68. });
  69. }, []);
  70. return (
  71. <DefaultLayout title="Blob">
  72. <Section title="ImageFilePreview">
  73. <Subsection title="Single File">
  74. <BlobReact.ImageFilePreview
  75. enhanced
  76. file={
  77. imageFile
  78. ?? {
  79. name: 'image.png',
  80. type: 'image/png',
  81. url: '/image.png',
  82. } as Partial<File>
  83. }
  84. className="sm:h-64"
  85. />
  86. </Subsection>
  87. </Section>
  88. <Section title="VideoFilePreview">
  89. <Subsection title="Single File">
  90. <BlobReact.VideoFilePreview
  91. file={
  92. videoFile
  93. ?? {
  94. name: 'video.mp4',
  95. type: 'video/mp4',
  96. url: '/video.mp4',
  97. } as Partial<File>
  98. }
  99. className="sm:h-64"
  100. enhanced
  101. />
  102. </Subsection>
  103. </Section>
  104. <Section title="AudioFilePreview">
  105. <Subsection title="Single File">
  106. <BlobReact.AudioFilePreview
  107. file={
  108. audioFile
  109. ?? {
  110. name: 'audio.wav',
  111. type: 'audio/wav',
  112. url: '/audio.wav',
  113. } as Partial<File>
  114. }
  115. className="sm:h-64"
  116. enhanced
  117. />
  118. </Subsection>
  119. </Section>
  120. <Section title="BinaryFilePreview">
  121. <Subsection title="Single File">
  122. <BlobReact.BinaryFilePreview
  123. file={
  124. binaryFile
  125. ?? {
  126. name: 'binary.bin',
  127. type: 'application/octet-stream',
  128. url: '/binary.bin',
  129. } as Partial<File>
  130. }
  131. className="sm:h-64"
  132. />
  133. </Subsection>
  134. </Section>
  135. <Section title="TextFilePreview">
  136. <Subsection title="Single File (Plaintext)">
  137. <BlobReact.TextFilePreview
  138. file={
  139. plaintextFile
  140. ?? {
  141. name: 'plaintext.txt',
  142. type: 'text/plain',
  143. url: '/plaintext.txt',
  144. } as Partial<File>
  145. }
  146. className="sm:h-64"
  147. />
  148. </Subsection>
  149. <Subsection title="Single File (Code)">
  150. <BlobReact.TextFilePreview
  151. file={
  152. codeFile
  153. ?? {
  154. name: 'code.py',
  155. type: 'text/x-python',
  156. url: '/code.py',
  157. } as Partial<File>
  158. }
  159. className="sm:h-64"
  160. />
  161. </Subsection>
  162. </Section>
  163. <Section title="FileSelectBox">
  164. <Subsection title="Single File">
  165. <BlobReact.FileSelectBox
  166. border
  167. enhanced
  168. label="Primary Image"
  169. hint="Select any files here"
  170. block
  171. className="sm:h-96"
  172. onChange={(e) => console.log(e.currentTarget.files)}
  173. />
  174. </Subsection>
  175. </Section>
  176. </DefaultLayout>
  177. )
  178. }
  179. export default BlobPage;