@digigov/nextjs 1.0.0-rc → 1.0.0-rc.2

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/Link.js CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
 
5
+ var _typeof = require("@babel/runtime/helpers/typeof");
6
+
5
7
  Object.defineProperty(exports, "__esModule", {
6
8
  value: true
7
9
  });
@@ -11,7 +13,9 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
11
13
 
12
14
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
13
15
 
14
- var _react = _interopRequireDefault(require("react"));
16
+ var _react = _interopRequireWildcard(require("react"));
17
+
18
+ var _router = require("next/router");
15
19
 
16
20
  var _link = _interopRequireDefault(require("next/link"));
17
21
 
@@ -19,12 +23,37 @@ var _LinkBase = _interopRequireDefault(require("@digigov/react-core/LinkBase"));
19
23
 
20
24
  var _excluded = ["href"];
21
25
 
26
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
27
+
28
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
29
+
22
30
  var NextLink = function NextLink(props, ref) {
23
31
  var href = props.href,
24
32
  other = (0, _objectWithoutProperties2["default"])(props, _excluded);
25
33
  var isExternalLink = //check if url has a file extension
26
34
  /^(?:[a-z]+:)?\/\/|.pdf|.docx?|.xlsx?/i.test(href || '') || // or if props has a target or rel
27
35
  other.target === '_blank';
36
+ var router = (0, _router.useRouter)();
37
+ (0, _react.useEffect)(function () {
38
+ var path = router.asPath;
39
+
40
+ if (path && path.includes('#')) {
41
+ setTimeout(function () {
42
+ var id = path.replace("#", "");
43
+ var el = window.document.getElementById(id);
44
+ var r = el === null || el === void 0 ? void 0 : el.getBoundingClientRect();
45
+
46
+ if (r) {
47
+ var _window$top;
48
+
49
+ (_window$top = window.top) === null || _window$top === void 0 ? void 0 : _window$top.scroll({
50
+ top: scrollY + r.top,
51
+ behavior: "smooth"
52
+ });
53
+ }
54
+ }, 600);
55
+ }
56
+ }, [router.asPath]);
28
57
 
29
58
  if (isExternalLink) {
30
59
  return /*#__PURE__*/_react["default"].createElement(_LinkBase["default"], (0, _extends2["default"])({
package/es/Link.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
3
  var _excluded = ["href"];
4
- import React from 'react';
4
+ import React, { useEffect } from 'react';
5
+ import { useRouter } from 'next/router';
5
6
  import Link from 'next/link';
6
7
  import LinkBase from '@digigov/react-core/LinkBase';
7
8
 
@@ -12,6 +13,27 @@ var NextLink = function NextLink(props, ref) {
12
13
  var isExternalLink = //check if url has a file extension
13
14
  /^(?:[a-z]+:)?\/\/|.pdf|.docx?|.xlsx?/i.test(href || '') || // or if props has a target or rel
14
15
  other.target === '_blank';
16
+ var router = useRouter();
17
+ useEffect(function () {
18
+ var path = router.asPath;
19
+
20
+ if (path && path.includes('#')) {
21
+ setTimeout(function () {
22
+ var id = path.replace("#", "");
23
+ var el = window.document.getElementById(id);
24
+ var r = el === null || el === void 0 ? void 0 : el.getBoundingClientRect();
25
+
26
+ if (r) {
27
+ var _window$top;
28
+
29
+ (_window$top = window.top) === null || _window$top === void 0 ? void 0 : _window$top.scroll({
30
+ top: scrollY + r.top,
31
+ behavior: "smooth"
32
+ });
33
+ }
34
+ }, 600);
35
+ }
36
+ }, [router.asPath]);
15
37
 
16
38
  if (isExternalLink) {
17
39
  return /*#__PURE__*/React.createElement(LinkBase, _extends({
package/esm/Link.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
3
  var _excluded = ["href"];
4
- import React from 'react';
4
+ import React, { useEffect } from 'react';
5
+ import { useRouter } from 'next/router';
5
6
  import Link from 'next/link';
6
7
  import LinkBase from '@digigov/react-core/LinkBase';
7
8
 
@@ -12,6 +13,27 @@ var NextLink = function NextLink(props, ref) {
12
13
  var isExternalLink = //check if url has a file extension
13
14
  /^(?:[a-z]+:)?\/\/|.pdf|.docx?|.xlsx?/i.test(href || '') || // or if props has a target or rel
14
15
  other.target === '_blank';
16
+ var router = useRouter();
17
+ useEffect(function () {
18
+ var path = router.asPath;
19
+
20
+ if (path && path.includes('#')) {
21
+ setTimeout(function () {
22
+ var id = path.replace("#", "");
23
+ var el = window.document.getElementById(id);
24
+ var r = el === null || el === void 0 ? void 0 : el.getBoundingClientRect();
25
+
26
+ if (r) {
27
+ var _window$top;
28
+
29
+ (_window$top = window.top) === null || _window$top === void 0 ? void 0 : _window$top.scroll({
30
+ top: scrollY + r.top,
31
+ behavior: "smooth"
32
+ });
33
+ }
34
+ }, 600);
35
+ }
36
+ }, [router.asPath]);
15
37
 
16
38
  if (isExternalLink) {
17
39
  return /*#__PURE__*/React.createElement(LinkBase, _extends({
package/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Digigov v1.0.0-rc
1
+ /** @license Digigov v1.0.0-rc.2
2
2
  *
3
3
  * This source code is licensed under the BSD-2-Clause license found in the
4
4
  * LICENSE file in the root directory of this source tree.
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
2
  import LinkBase, { LinkBaseProps } from '@digigov/react-core/LinkBase';
3
3
  export interface LinkComponentContextProps {
4
4
  component: React.ElementType<LinkProps>;
@@ -35,6 +35,8 @@ export declare type BaseProps<C extends React.ElementType> = PolymorphicComponen
35
35
  printHidden?: boolean;
36
36
  /** printVisible is optional. When block, the component is displayed as block. When inline, the component is displayed as inline.*/
37
37
  printVisible?: 'block' | 'inline';
38
+ /** Components will be hidden at all screen sizes. */
39
+ hidden?: boolean;
38
40
  /** Components will be hidden from 'xs' screen size and up. */
39
41
  xsUpHidden?: boolean;
40
42
  /** Components will be hidden from 'sm' screen size and up. */
@@ -2,9 +2,11 @@ import React from 'react';
2
2
  import { BaseProps } from '@digigov/react-core/Base';
3
3
  export interface LinkBaseProps extends BaseProps<'a'> {
4
4
  /**
5
- * underline is optional. The default value is 'true'.
6
- * Make it 'false' only if the context tells the user that the text is a link, even without the underline.
7
- */
5
+ * underline is optional. The default value is 'true'.
6
+ * Make it 'false' only if the context tells the user that the text is a link, even without the underline.
7
+ * @value true
8
+ * @value false
9
+ */
8
10
  underline?: boolean;
9
11
  }
10
12
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digigov/nextjs",
3
- "version": "1.0.0-rc",
3
+ "version": "1.0.0-rc.2",
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": "1.0.0-rc",
13
+ "@digigov/ui": "1.0.0-rc.2",
14
14
  "@material-ui/core": "4.11.3",
15
15
  "@material-ui/icons": "4.11.2",
16
16
  "clsx": "1.1.1",
package/src/Link.tsx CHANGED
@@ -1,5 +1,6 @@
1
- import React from 'react';
1
+ import React, { useEffect } from 'react';
2
2
  import { LinkProps } from '@digigov/ui/navigation/Link';
3
+ import { useRouter } from 'next/router';
3
4
  import Link from 'next/link';
4
5
  import LinkBase from '@digigov/react-core/LinkBase';
5
6
 
@@ -13,6 +14,24 @@ const NextLink: React.ForwardRefRenderFunction<HTMLAnchorElement, LinkProps> = (
13
14
  /^(?:[a-z]+:)?\/\/|.pdf|.docx?|.xlsx?/i.test(href || '') ||
14
15
  // or if props has a target or rel
15
16
  other.target === '_blank';
17
+ const router = useRouter();
18
+
19
+ useEffect(() => {
20
+ const path = router.asPath;
21
+ if (path && path.includes('#')) {
22
+ setTimeout(() => {
23
+ const id = path.replace("#", "")
24
+ const el = window.document.getElementById(id)
25
+ const r = el?.getBoundingClientRect()
26
+ if (r) {
27
+ window.top?.scroll({
28
+ top: scrollY + r.top,
29
+ behavior: "smooth",
30
+ })
31
+ }
32
+ }, 600)
33
+ }
34
+ }, [router.asPath]);
16
35
 
17
36
  if (isExternalLink) {
18
37
  return (