_app.page.tsx 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import React, { ReactElement, ReactNode, useEffect } from 'react';
  2. import { NextPage } from 'next';
  3. import { appWithTranslation } from 'next-i18next';
  4. import { AppProps } from 'next/app';
  5. import { Lato } from 'next/font/google';
  6. import localFont from 'next/font/local';
  7. import { SWRConfig } from 'swr';
  8. import * as nextI18nConfig from '^/config/next-i18next.config';
  9. import { useI18nextHMR } from '~/services/i18next-hmr';
  10. import {
  11. useAppTitle, useConfidential, useGrowiVersion, useSiteUrl, useIsDefaultLogo, useForcedColorScheme,
  12. } from '~/stores/context';
  13. import { swrGlobalConfiguration } from '~/utils/swr-utils';
  14. import { CommonProps } from './utils/commons';
  15. import { registerTransformerForObjectId } from './utils/objectid-transformer';
  16. import '~/styles/prebuilt/vendor.css';
  17. import '~/styles/font-icons.scss';
  18. import '~/styles/style-app.scss';
  19. import '~/styles/prebuilt/apply-colors.css';
  20. const isDev = process.env.NODE_ENV === 'development';
  21. // define fonts
  22. const lato = Lato({
  23. weight: ['400', '700'],
  24. style: ['normal', 'italic'],
  25. subsets: ['latin'],
  26. display: 'swap',
  27. });
  28. const sourceHanCodeJP = localFont({ src: '../../resource/fonts/SourceHanCodeJP-Regular.woff2' });
  29. // eslint-disable-next-line @typescript-eslint/ban-types
  30. export type NextPageWithLayout<P = {}, IP = P> = NextPage<P, IP> & {
  31. getLayout?: (page: ReactElement) => ReactNode,
  32. }
  33. type GrowiAppProps = AppProps & {
  34. Component: NextPageWithLayout,
  35. };
  36. // register custom serializer
  37. registerTransformerForObjectId();
  38. function GrowiApp({ Component, pageProps }: GrowiAppProps): JSX.Element {
  39. useI18nextHMR(isDev);
  40. useEffect(() => {
  41. import('bootstrap/dist/js/bootstrap');
  42. }, []);
  43. const commonPageProps = pageProps as CommonProps;
  44. useAppTitle(commonPageProps.appTitle);
  45. useSiteUrl(commonPageProps.siteUrl);
  46. useConfidential(commonPageProps.confidential);
  47. useGrowiVersion(commonPageProps.growiVersion);
  48. useIsDefaultLogo(commonPageProps.isDefaultLogo);
  49. useForcedColorScheme(commonPageProps.forcedColorScheme);
  50. // Use the layout defined at the page level, if available
  51. const getLayout = Component.getLayout ?? (page => page);
  52. return (
  53. <>
  54. <style jsx global>{`
  55. :root {
  56. --font-family-sans-serif: ${lato.style.fontFamily} -apple-system, BlinkMacSystemFont, 'Hiragino Kaku Gothic ProN', Meiryo, sans-serif;
  57. --font-family-serif: Georgia, 'Times New Roman', Times, serif;
  58. --font-family-monospace: monospace, ${sourceHanCodeJP.style.fontFamily};
  59. }
  60. `}</style>
  61. <SWRConfig value={swrGlobalConfiguration}>
  62. {getLayout(<Component {...pageProps} />)}
  63. </SWRConfig>
  64. </>
  65. );
  66. }
  67. export default appWithTranslation(GrowiApp, nextI18nConfig);