Common front-end components for Web using the Tesseract design system, written for React. https://make.modal.sh/tesseract/web/react/common
 
 
 
 

46 行
1.2 KiB

  1. import Document, { Html, Head, Main, NextScript, DocumentContext } from 'next/document'
  2. import { ServerStyleSheet } from 'styled-components'
  3. export default class MyDocument extends Document {
  4. static async getInitialProps(ctx: DocumentContext) {
  5. const sheet = new ServerStyleSheet()
  6. const originalRenderPage = ctx.renderPage
  7. try {
  8. ctx.renderPage = () =>
  9. originalRenderPage({
  10. enhanceApp: (App) => (props) =>
  11. sheet.collectStyles(<App {...props} />),
  12. })
  13. const initialProps = await Document.getInitialProps(ctx)
  14. return {
  15. ...initialProps,
  16. styles: (
  17. <>
  18. {initialProps.styles}
  19. <link rel="stylesheet" href="/global.css" />
  20. <link rel="stylesheet" title="Dark" href="/theme/dark.css" />
  21. <link rel="alternate stylesheet" title="Light" href="/theme/light.css" />
  22. {sheet.getStyleElement()}
  23. </>
  24. ),
  25. }
  26. } finally {
  27. sheet.seal()
  28. }
  29. }
  30. render() {
  31. return (
  32. <Html lang="en-PH">
  33. <Head />
  34. <body>
  35. <Main />
  36. <NextScript />
  37. </body>
  38. </Html>
  39. )
  40. }
  41. }