@digigov/nextjs 1.1.3 → 1.1.5-07ee8440
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/App/index.js +41 -48
- package/App.d.ts +4 -7
- package/App.js.map +7 -0
- package/Document/index.js +22 -63
- package/Document.d.ts +2 -3
- package/Document.js.map +7 -0
- package/Image/index.js +11 -14
- package/Image.js.map +7 -0
- package/Link/index.js +28 -36
- package/Link.d.ts +1 -1
- package/Link.js.map +7 -0
- package/cjs/App/index.js +69 -57
- package/cjs/App.js.map +7 -0
- package/cjs/Document/index.js +50 -70
- package/cjs/Document.js.map +7 -0
- package/cjs/Image/index.js +39 -20
- package/cjs/Image.js.map +7 -0
- package/cjs/Link/index.js +56 -45
- package/cjs/Link.js.map +7 -0
- package/cjs/hooks/index.js +29 -8
- package/cjs/hooks.js.map +7 -0
- package/cjs/i18n/index.js +41 -16
- package/cjs/i18n.js.map +7 -0
- package/cjs/index.js +1 -1
- package/cjs/index.js.map +7 -0
- package/hooks/index.js +8 -4
- package/hooks.js.map +7 -0
- package/i18n/index.js +13 -10
- package/i18n.js.map +7 -0
- package/index.js +2 -1
- package/index.js.map +7 -0
- package/package.json +6 -8
- package/src/App.tsx +16 -4
- package/src/Document.tsx +0 -16
- package/src/Image.tsx +4 -2
- package/src/Link.tsx +6 -3
package/src/App.tsx
CHANGED
|
@@ -2,6 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { i18n, TFunction } from 'i18next';
|
|
3
3
|
import App from 'next/app';
|
|
4
4
|
import Head from 'next/head';
|
|
5
|
+
import { NextRouter, useRouter } from 'next/router';
|
|
5
6
|
import { withTranslation, WithTranslation } from 'react-i18next';
|
|
6
7
|
import NextLink from '@digigov/nextjs/Link';
|
|
7
8
|
import DigiGOVApp, { StaticApp } from '@digigov/ui/app/App';
|
|
@@ -14,10 +15,16 @@ export interface DigiGOVNextAppProps extends AppProps, WithTranslation {
|
|
|
14
15
|
t: TFunction;
|
|
15
16
|
i18n: i18n;
|
|
16
17
|
ssr: boolean;
|
|
18
|
+
router: NextRouter;
|
|
17
19
|
}
|
|
18
|
-
class
|
|
20
|
+
class DigiGOVNextAppClass extends App<DigiGOVNextAppProps> {
|
|
19
21
|
render(): React.ReactElement {
|
|
20
|
-
const { Component, pageProps, t, i18n, ssr = false } = this.props;
|
|
22
|
+
const { Component, pageProps, t, i18n, ssr = false, router } = this.props;
|
|
23
|
+
const { locale } = router;
|
|
24
|
+
|
|
25
|
+
if (locale && i18n.language != locale) {
|
|
26
|
+
i18n.changeLanguage(locale);
|
|
27
|
+
}
|
|
21
28
|
return (
|
|
22
29
|
<I18NProvider
|
|
23
30
|
t={(str) => (typeof str === 'string' ? t(str) : str)}
|
|
@@ -44,5 +51,10 @@ class DigiGOVNextApp extends App<DigiGOVNextAppProps> {
|
|
|
44
51
|
);
|
|
45
52
|
}
|
|
46
53
|
}
|
|
47
|
-
|
|
48
|
-
|
|
54
|
+
|
|
55
|
+
const DigiGOVNextAppWithTranslation = withTranslation()(DigiGOVNextAppClass);
|
|
56
|
+
const DigiGOVNextApp = (props) => {
|
|
57
|
+
const router = useRouter();
|
|
58
|
+
return <DigiGOVNextAppWithTranslation {...props} router={router} />;
|
|
59
|
+
};
|
|
60
|
+
export default DigiGOVNextApp;
|
package/src/Document.tsx
CHANGED
|
@@ -2,20 +2,6 @@
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import Document, { Html, Head, Main, NextScript } from 'next/document';
|
|
4
4
|
|
|
5
|
-
export function Fonts() {
|
|
6
|
-
return (
|
|
7
|
-
<>
|
|
8
|
-
<link
|
|
9
|
-
rel="stylesheet"
|
|
10
|
-
href="https://fonts.googleapis.com/icon?family=Material+Icons"
|
|
11
|
-
/>
|
|
12
|
-
<link
|
|
13
|
-
rel="stylesheet"
|
|
14
|
-
href="https://fonts.googleapis.com/css?family=Roboto:300,400,500"
|
|
15
|
-
/>
|
|
16
|
-
</>
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
5
|
export default class DigiGOVDocument extends Document {
|
|
20
6
|
render() {
|
|
21
7
|
return (
|
|
@@ -28,8 +14,6 @@ export default class DigiGOVDocument extends Document {
|
|
|
28
14
|
`,
|
|
29
15
|
}}
|
|
30
16
|
></script>
|
|
31
|
-
{/* PWA primary color */}
|
|
32
|
-
<Fonts />
|
|
33
17
|
</Head>
|
|
34
18
|
<body>
|
|
35
19
|
<Main />
|
package/src/Image.tsx
CHANGED
|
@@ -3,8 +3,10 @@ import NextImage, { ImageProps } from 'next/image';
|
|
|
3
3
|
import { useBasePath } from '@digigov/nextjs/hooks';
|
|
4
4
|
|
|
5
5
|
const Image: React.FC<ImageProps> = ({ src, ...rest }) => {
|
|
6
|
-
const basePathSrc = useBasePath(src);
|
|
7
|
-
return
|
|
6
|
+
const basePathSrc = useBasePath(typeof src === 'string' ? src : '');
|
|
7
|
+
return (
|
|
8
|
+
<NextImage src={typeof src === 'string' ? basePathSrc : src} {...rest} />
|
|
9
|
+
);
|
|
8
10
|
};
|
|
9
11
|
|
|
10
12
|
export default Image;
|
package/src/Link.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useEffect } from 'react';
|
|
2
2
|
import Link from 'next/link';
|
|
3
3
|
import { useRouter } from 'next/router';
|
|
4
|
-
import LinkBase from '@digigov/
|
|
4
|
+
import { LinkBase } from '@digigov/ui/navigation/Link';
|
|
5
5
|
import { LinkProps } from '@digigov/ui/navigation/Link';
|
|
6
6
|
|
|
7
7
|
const NextLink: React.ForwardRefRenderFunction<HTMLAnchorElement, LinkProps> = (
|
|
@@ -9,11 +9,13 @@ const NextLink: React.ForwardRefRenderFunction<HTMLAnchorElement, LinkProps> = (
|
|
|
9
9
|
ref
|
|
10
10
|
) => {
|
|
11
11
|
const { href, ...other } = props;
|
|
12
|
+
|
|
12
13
|
const isExternalLink =
|
|
13
|
-
//check if url has a file extension
|
|
14
|
-
/^(?:[a-z]+:)
|
|
14
|
+
//check if url has a file extension or starts with mailto
|
|
15
|
+
/^(?:[a-z]+:)?\/\/|\.pdf|\.docx?|\.xlsx?|^mailto:/i.test(href || '') ||
|
|
15
16
|
// or if props has a target or rel
|
|
16
17
|
other.target === '_blank';
|
|
18
|
+
|
|
17
19
|
const router = useRouter();
|
|
18
20
|
|
|
19
21
|
useEffect(() => {
|
|
@@ -40,6 +42,7 @@ const NextLink: React.ForwardRefRenderFunction<HTMLAnchorElement, LinkProps> = (
|
|
|
40
42
|
</LinkBase>
|
|
41
43
|
);
|
|
42
44
|
}
|
|
45
|
+
|
|
43
46
|
return (
|
|
44
47
|
<Link href={href || '#'} {...other}>
|
|
45
48
|
<LinkBase ref={ref} {...other}>
|