@digigov/nextjs 0.6.7 → 0.6.8
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/CHANGELOG.md +6 -1
- package/esm/index.js +1 -1
- package/libs-ui/react-core/src/Base/index.d.ts +10 -10
- package/package.json +2 -2
- package/src/App.tsx +61 -0
- package/src/Document.tsx +73 -0
- package/src/Image.tsx +10 -0
- package/src/Link.tsx +33 -0
- package/src/hooks.ts +6 -0
- package/src/i18n.tsx +18 -0
- package/src/index.ts +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
# Change Log - @digigov/nextjs
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Mon, 16 Jan 2023 13:05:21 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 0.6.8
|
|
6
|
+
Mon, 16 Jan 2023 13:05:21 GMT
|
|
7
|
+
|
|
8
|
+
_Version update only_
|
|
4
9
|
|
|
5
10
|
## 0.6.7
|
|
6
11
|
Fri, 02 Dec 2022 11:20:56 GMT
|
package/esm/index.js
CHANGED
|
@@ -13,25 +13,25 @@ declare type PolymorphicRef<C extends React.ElementType> = React.ComponentPropsW
|
|
|
13
13
|
*/
|
|
14
14
|
export declare type BaseProps<C extends React.ElementType> = PolymorphicComponentPropWithRef<C, {
|
|
15
15
|
/** margin is optional. It has not a default value. */
|
|
16
|
-
margin?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
16
|
+
margin?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
|
|
17
17
|
/** marginTop is optional. It has not a default value. */
|
|
18
|
-
marginTop?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
18
|
+
marginTop?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
|
|
19
19
|
/** marginBottom is optional. It has not a default value. */
|
|
20
|
-
marginBottom?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
20
|
+
marginBottom?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
|
|
21
21
|
/** marginLeft is optional. It has not a default value. */
|
|
22
|
-
marginLeft?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
22
|
+
marginLeft?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
|
|
23
23
|
/** marginRight is optional. It has not a default value. */
|
|
24
|
-
marginRight?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
24
|
+
marginRight?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
|
|
25
25
|
/** padding is optional. It has not a default value. */
|
|
26
|
-
padding?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
26
|
+
padding?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
|
|
27
27
|
/** paddingTop is optional. It has not a default value. */
|
|
28
|
-
paddingTop?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
28
|
+
paddingTop?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
|
|
29
29
|
/** paddingBottom is optional. It has not a default value. */
|
|
30
|
-
paddingBottom?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
30
|
+
paddingBottom?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
|
|
31
31
|
/** paddingLeft is optional. It has not a default value. */
|
|
32
|
-
paddingLeft?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
32
|
+
paddingLeft?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
|
|
33
33
|
/** paddingRight is optional. It has not a default value. */
|
|
34
|
-
paddingRight?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
34
|
+
paddingRight?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
|
|
35
35
|
/** printHidden is optional. Default value is false. When true, the component is hidden at print. */
|
|
36
36
|
printHidden?: boolean;
|
|
37
37
|
}>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digigov/nextjs",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.8",
|
|
4
4
|
"description": "next specific utilities for @digigov apps",
|
|
5
5
|
"author": "GRNET Developers <devs@lists.grnet.gr>",
|
|
6
6
|
"license": "BSD-2-Clause",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"main": "dist/index.js"
|
|
11
11
|
},
|
|
12
12
|
"peerDependencies": {
|
|
13
|
-
"@digigov/ui": "0.
|
|
13
|
+
"@digigov/ui": "0.29.0",
|
|
14
14
|
"@material-ui/core": "4.11.3",
|
|
15
15
|
"@material-ui/icons": "4.11.2",
|
|
16
16
|
"clsx": "1.1.1",
|
package/src/App.tsx
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import App from 'next/app';
|
|
3
|
+
import Head from 'next/head';
|
|
4
|
+
import { LinkProvider } from '@digigov/ui/core/Link';
|
|
5
|
+
import NextLink from '@digigov/nextjs/Link';
|
|
6
|
+
import dynamic from 'next/dynamic';
|
|
7
|
+
import type { AppProps } from '@digigov/ui/app/App';
|
|
8
|
+
import { I18NProvider } from '@digigov/ui/app/i18n';
|
|
9
|
+
import { withTranslation, WithTranslation } from 'react-i18next';
|
|
10
|
+
import { i18n } from 'i18next';
|
|
11
|
+
|
|
12
|
+
const DigiGOVApp = dynamic(() => import('@digigov/ui/app/App'), {
|
|
13
|
+
ssr: false,
|
|
14
|
+
}) as React.FC<AppProps>;
|
|
15
|
+
export interface DigiGOVNextAppProps extends AppProps, WithTranslation {
|
|
16
|
+
children?: React.ReactNode;
|
|
17
|
+
t: (string) => string;
|
|
18
|
+
i18n: i18n;
|
|
19
|
+
}
|
|
20
|
+
class DigiGOVNextApp extends App<DigiGOVNextAppProps> {
|
|
21
|
+
componentDidMount(): void {
|
|
22
|
+
// Remove the server-side injected CSS.
|
|
23
|
+
const jssStyles = document.querySelector('#jss-server-side');
|
|
24
|
+
if (jssStyles && jssStyles.parentElement) {
|
|
25
|
+
jssStyles.parentElement.removeChild(jssStyles);
|
|
26
|
+
}
|
|
27
|
+
this.updateHtmlLang();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
componentDidUpdate(): void {
|
|
31
|
+
this.updateHtmlLang();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
updateHtmlLang(): void {
|
|
35
|
+
document.documentElement.lang = this.props.i18n.language;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
render(): React.ReactElement {
|
|
39
|
+
const { Component, pageProps, t, i18n } = this.props;
|
|
40
|
+
return (
|
|
41
|
+
<I18NProvider
|
|
42
|
+
t={(str) => (typeof str === 'string' ? t(str) : str)}
|
|
43
|
+
i18n={i18n}
|
|
44
|
+
>
|
|
45
|
+
<LinkProvider component={NextLink}>
|
|
46
|
+
<Head>
|
|
47
|
+
<meta
|
|
48
|
+
name="viewport"
|
|
49
|
+
content="minimum-scale=1, initial-scale=1, width=device-width"
|
|
50
|
+
/>
|
|
51
|
+
</Head>
|
|
52
|
+
<DigiGOVApp>
|
|
53
|
+
<Component {...pageProps} />
|
|
54
|
+
</DigiGOVApp>
|
|
55
|
+
</LinkProvider>
|
|
56
|
+
</I18NProvider>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const DigiGOVNextAppWithTranslation = withTranslation()(DigiGOVNextApp);
|
|
61
|
+
export default DigiGOVNextAppWithTranslation;
|
package/src/Document.tsx
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import Document, { Html, Head, Main, NextScript } from 'next/document';
|
|
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
|
+
export default class DigiGOVDocument extends Document {
|
|
20
|
+
render() {
|
|
21
|
+
return (
|
|
22
|
+
<Html>
|
|
23
|
+
<Head>
|
|
24
|
+
<script
|
|
25
|
+
type="text/javascript"
|
|
26
|
+
dangerouslySetInnerHTML={{
|
|
27
|
+
__html: `if (window.document.documentMode) alert('Internet Explorer is not supported. Please use a modern browser!');
|
|
28
|
+
`,
|
|
29
|
+
}}
|
|
30
|
+
></script>
|
|
31
|
+
{/* PWA primary color */}
|
|
32
|
+
<Fonts />
|
|
33
|
+
</Head>
|
|
34
|
+
<body>
|
|
35
|
+
<Main />
|
|
36
|
+
<NextScript />
|
|
37
|
+
</body>
|
|
38
|
+
</Html>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
DigiGOVDocument.getInitialProps = async (ctx) => {
|
|
44
|
+
// Resolution order
|
|
45
|
+
//
|
|
46
|
+
// On the server:
|
|
47
|
+
// 1. app.getInitialProps
|
|
48
|
+
// 2. page.getInitialProps
|
|
49
|
+
// 3. document.getInitialProps
|
|
50
|
+
// 4. app.render
|
|
51
|
+
// 5. page.render
|
|
52
|
+
// 6. document.render
|
|
53
|
+
//
|
|
54
|
+
// On the server with error:
|
|
55
|
+
// 1. document.getInitialProps
|
|
56
|
+
// 2. app.render
|
|
57
|
+
// 3. page.render
|
|
58
|
+
// 4. document.render
|
|
59
|
+
//
|
|
60
|
+
// On the client
|
|
61
|
+
// 1. app.getInitialProps
|
|
62
|
+
// 2. page.getInitialProps
|
|
63
|
+
// 3. app.render
|
|
64
|
+
// 4. page.render
|
|
65
|
+
|
|
66
|
+
// Render app and page and get the context of the page with collected side effects.
|
|
67
|
+
const initialProps = await Document.getInitialProps(ctx);
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
...initialProps,
|
|
71
|
+
// Styles fragment is rendered after the app and page rendering finish.
|
|
72
|
+
};
|
|
73
|
+
};
|
package/src/Image.tsx
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import NextImage, { ImageProps } from 'next/image';
|
|
3
|
+
import { useBasePath } from '@digigov/nextjs/hooks';
|
|
4
|
+
|
|
5
|
+
const Image: React.FC<ImageProps> = ({ src, ...rest }) => {
|
|
6
|
+
const basePathSrc = useBasePath(src);
|
|
7
|
+
return <NextImage src={basePathSrc} {...rest} />;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export default Image;
|
package/src/Link.tsx
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { LinkProps } from '@digigov/ui/core/Link';
|
|
3
|
+
import Link from 'next/link';
|
|
4
|
+
import LinkBase from '@digigov/react-core/LinkBase';
|
|
5
|
+
|
|
6
|
+
const NextLink: React.ForwardRefRenderFunction<HTMLAnchorElement, LinkProps> = (
|
|
7
|
+
props,
|
|
8
|
+
ref
|
|
9
|
+
) => {
|
|
10
|
+
const { href, ...other } = props;
|
|
11
|
+
const isExternalLink =
|
|
12
|
+
//check if url has a file extension
|
|
13
|
+
/^(?:[a-z]+:)?\/\/|.pdf|.docx?|.xlsx?/i.test(href || '') ||
|
|
14
|
+
// or if props has a target or rel
|
|
15
|
+
other.target === '_blank';
|
|
16
|
+
|
|
17
|
+
if (isExternalLink) {
|
|
18
|
+
return (
|
|
19
|
+
<LinkBase ref={ref} href={href || '#'} {...other}>
|
|
20
|
+
{props.children}
|
|
21
|
+
</LinkBase>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
return (
|
|
25
|
+
<Link href={href || '#'} {...other}>
|
|
26
|
+
<LinkBase ref={ref} {...other}>
|
|
27
|
+
{props.children}
|
|
28
|
+
</LinkBase>
|
|
29
|
+
</Link>
|
|
30
|
+
);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export default React.forwardRef(NextLink);
|
package/src/hooks.ts
ADDED
package/src/i18n.tsx
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import i18n, { Resource, TFunction } from 'i18next';
|
|
2
|
+
import { initReactI18next } from 'react-i18next';
|
|
3
|
+
|
|
4
|
+
export default function initI18n(
|
|
5
|
+
resources: Resource,
|
|
6
|
+
language = 'el'
|
|
7
|
+
): Promise<TFunction> {
|
|
8
|
+
return i18n
|
|
9
|
+
.use(initReactI18next) // passes i18n down to react-i18next
|
|
10
|
+
.init({
|
|
11
|
+
resources: resources,
|
|
12
|
+
lng: language,
|
|
13
|
+
keySeparator: '.', // we use keys in form messages.welcome
|
|
14
|
+
interpolation: {
|
|
15
|
+
escapeValue: false, // react already safes from xss
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
}
|
package/src/index.ts
ADDED
|
File without changes
|