@digigov/nextjs 1.1.3 → 1.1.5-061795a7
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 +25 -38
- 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 +53 -47
- 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 +17 -19
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,31 +1,28 @@
|
|
|
1
1
|
import React, { useEffect } from 'react';
|
|
2
|
-
import
|
|
2
|
+
import NextRouterLink from 'next/link';
|
|
3
3
|
import { useRouter } from 'next/router';
|
|
4
|
-
import
|
|
5
|
-
import { LinkProps } from '@digigov/ui/navigation/Link';
|
|
4
|
+
import { Link, LinkProps } from '@digigov/ui/navigation/Link';
|
|
6
5
|
|
|
7
6
|
const NextLink: React.ForwardRefRenderFunction<HTMLAnchorElement, LinkProps> = (
|
|
8
7
|
props,
|
|
9
8
|
ref
|
|
10
9
|
) => {
|
|
11
|
-
const { href, ...other } = props;
|
|
10
|
+
const { href, as, ...other } = props;
|
|
12
11
|
const isExternalLink =
|
|
13
|
-
|
|
14
|
-
/^(?:[a-z]+:)?\/\/|.pdf|.docx?|.xlsx?/i.test(href || '') ||
|
|
15
|
-
// or if props has a target or rel
|
|
12
|
+
/^(?:[a-z]+:)?\/\/|\.pdf|\.docx?|\.xlsx?|^mailto:/i.test(href || '') ||
|
|
16
13
|
other.target === '_blank';
|
|
14
|
+
|
|
17
15
|
const router = useRouter();
|
|
18
16
|
|
|
19
17
|
useEffect(() => {
|
|
20
18
|
const path = router.asPath;
|
|
21
|
-
if (path
|
|
19
|
+
if (path.includes('#')) {
|
|
22
20
|
setTimeout(() => {
|
|
23
21
|
const id = path.replace('#', '');
|
|
24
|
-
const el =
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
top: scrollY + r.top,
|
|
22
|
+
const el = document.getElementById(id);
|
|
23
|
+
if (el) {
|
|
24
|
+
window.scroll({
|
|
25
|
+
top: scrollY + el.getBoundingClientRect().top,
|
|
29
26
|
behavior: 'smooth',
|
|
30
27
|
});
|
|
31
28
|
}
|
|
@@ -35,17 +32,18 @@ const NextLink: React.ForwardRefRenderFunction<HTMLAnchorElement, LinkProps> = (
|
|
|
35
32
|
|
|
36
33
|
if (isExternalLink) {
|
|
37
34
|
return (
|
|
38
|
-
<
|
|
35
|
+
<Link ref={ref} href={href || '#'} {...other}>
|
|
39
36
|
{props.children}
|
|
40
|
-
</
|
|
37
|
+
</Link>
|
|
41
38
|
);
|
|
42
39
|
}
|
|
40
|
+
|
|
43
41
|
return (
|
|
44
|
-
<
|
|
45
|
-
<
|
|
42
|
+
<NextRouterLink href={href || '#'} as={undefined} {...other}>
|
|
43
|
+
<Link ref={ref} {...other} as={as}>
|
|
46
44
|
{props.children}
|
|
47
|
-
</
|
|
48
|
-
</
|
|
45
|
+
</Link>
|
|
46
|
+
</NextRouterLink>
|
|
49
47
|
);
|
|
50
48
|
};
|
|
51
49
|
|