@digigov/ui 0.26.2 → 0.26.4

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.
Files changed (84) hide show
  1. package/CHANGELOG.md +18 -1
  2. package/admin/AutoComplete/index.d.ts +3 -3
  3. package/admin/AutoComplete/index.js +16 -6
  4. package/admin/CopyToClipboard/__stories__/Default.js +3 -3
  5. package/admin/CopyToClipboard/__stories__/MultipleCopies.js +3 -3
  6. package/admin/CopyToClipboard/index.d.ts +3 -2
  7. package/admin/CopyToClipboard/index.js +6 -4
  8. package/app/Footer/Footer.stories.d.ts +1 -0
  9. package/app/Footer/Footer.stories.js +14 -0
  10. package/app/Footer/__stories__/FooterWithLogo.js +1 -1
  11. package/app/Footer/__stories__/FooterWithSecondaryNavigation.js +1 -1
  12. package/app/Footer/__stories__/YearCopyright.d.ts +2 -0
  13. package/app/Footer/__stories__/YearCopyright.js +44 -0
  14. package/app/QrCodeViewer/QRCode.stories.d.ts +8 -0
  15. package/app/QrCodeViewer/QRCode.stories.js +46 -0
  16. package/app/QrCodeViewer/__stories__/Custom.d.ts +2 -0
  17. package/app/QrCodeViewer/__stories__/Custom.js +37 -0
  18. package/app/QrCodeViewer/__stories__/Default.d.ts +2 -0
  19. package/app/QrCodeViewer/__stories__/Default.js +24 -0
  20. package/app/QrCodeViewer/index.d.ts +8 -0
  21. package/app/QrCodeViewer/index.js +248 -0
  22. package/app/QrCodeViewer/index.mdx +21 -0
  23. package/app/QrCodeViewer/qrcodegen.d.ts +100 -0
  24. package/app/QrCodeViewer/qrcodegen.js +1086 -0
  25. package/app/QrCodeViewer/types.d.ts +29 -0
  26. package/app/QrCodeViewer/types.js +5 -0
  27. package/app/QrCodeViewer/utils.d.ts +11 -0
  28. package/app/QrCodeViewer/utils.js +108 -0
  29. package/app/index.d.ts +1 -0
  30. package/app/index.js +13 -0
  31. package/core/FileUpload/index.d.ts +1 -0
  32. package/core/FileUpload/index.js +14 -0
  33. package/es/admin/AutoComplete/index.js +16 -6
  34. package/es/admin/CopyToClipboard/__stories__/Default.js +2 -2
  35. package/es/admin/CopyToClipboard/__stories__/MultipleCopies.js +3 -3
  36. package/es/admin/CopyToClipboard/index.js +6 -4
  37. package/es/app/Footer/Footer.stories.js +2 -1
  38. package/es/app/Footer/__stories__/FooterWithLogo.js +1 -1
  39. package/es/app/Footer/__stories__/FooterWithSecondaryNavigation.js +1 -1
  40. package/es/app/Footer/__stories__/YearCopyright.js +22 -0
  41. package/es/app/QrCodeViewer/QRCode.stories.js +8 -0
  42. package/es/app/QrCodeViewer/__stories__/Custom.js +22 -0
  43. package/es/app/QrCodeViewer/__stories__/Default.js +11 -0
  44. package/es/app/QrCodeViewer/index.js +224 -0
  45. package/es/app/QrCodeViewer/index.mdx +21 -0
  46. package/es/app/QrCodeViewer/qrcodegen.js +1085 -0
  47. package/es/app/QrCodeViewer/types.js +1 -0
  48. package/es/app/QrCodeViewer/utils.js +95 -0
  49. package/es/app/index.js +1 -0
  50. package/es/core/FileUpload/index.js +1 -0
  51. package/es/govgr/Footer/Copyright.js +7 -10
  52. package/es/layouts/Grid/__stories__/Default.js +19 -18
  53. package/es/layouts/Grid/__stories__/Inline.js +19 -18
  54. package/es/registry.js +8 -0
  55. package/esm/admin/AutoComplete/index.js +16 -6
  56. package/esm/admin/CopyToClipboard/__stories__/Default.js +2 -2
  57. package/esm/admin/CopyToClipboard/__stories__/MultipleCopies.js +3 -3
  58. package/esm/admin/CopyToClipboard/index.js +6 -4
  59. package/esm/app/Footer/Footer.stories.js +2 -1
  60. package/esm/app/Footer/__stories__/FooterWithLogo.js +1 -1
  61. package/esm/app/Footer/__stories__/FooterWithSecondaryNavigation.js +1 -1
  62. package/esm/app/Footer/__stories__/YearCopyright.js +22 -0
  63. package/esm/app/QrCodeViewer/QRCode.stories.js +8 -0
  64. package/esm/app/QrCodeViewer/__stories__/Custom.js +22 -0
  65. package/esm/app/QrCodeViewer/__stories__/Default.js +11 -0
  66. package/esm/app/QrCodeViewer/index.js +224 -0
  67. package/esm/app/QrCodeViewer/index.mdx +21 -0
  68. package/esm/app/QrCodeViewer/qrcodegen.js +1085 -0
  69. package/esm/app/QrCodeViewer/types.js +1 -0
  70. package/esm/app/QrCodeViewer/utils.js +95 -0
  71. package/esm/app/index.js +1 -0
  72. package/esm/core/FileUpload/index.js +1 -0
  73. package/esm/govgr/Footer/Copyright.js +7 -10
  74. package/esm/index.js +1 -1
  75. package/esm/layouts/Grid/__stories__/Default.js +19 -18
  76. package/esm/layouts/Grid/__stories__/Inline.js +19 -18
  77. package/esm/registry.js +8 -0
  78. package/govgr/Footer/Copyright.d.ts +1 -0
  79. package/govgr/Footer/Copyright.js +9 -8
  80. package/layouts/Grid/__stories__/Default.js +20 -18
  81. package/layouts/Grid/__stories__/Inline.js +20 -18
  82. package/package.json +3 -3
  83. package/registry.d.ts +4 -0
  84. package/registry.js +12 -0
@@ -0,0 +1,29 @@
1
+ import type { CSSProperties } from 'react';
2
+ import qrcodegen from '@digigov/ui/app/QrCodeViewer/qrcodegen';
3
+ export declare type QRProps = {
4
+ value: string;
5
+ size?: number;
6
+ level?: string;
7
+ bgColor?: string;
8
+ fgColor?: string;
9
+ style?: CSSProperties;
10
+ includeMargin?: boolean;
11
+ imageSettings?: ImageSettings;
12
+ };
13
+ export declare type QRPropsCanvas = QRProps & React.CanvasHTMLAttributes<HTMLCanvasElement>;
14
+ export declare type QRPropsSVG = QRProps & React.SVGProps<SVGSVGElement>;
15
+ export declare type Modules = ReturnType<qrcodegen.QrCode['getModules']>;
16
+ export declare type Excavation = {
17
+ x: number;
18
+ y: number;
19
+ w: number;
20
+ h: number;
21
+ };
22
+ export declare type ImageSettings = {
23
+ src: string;
24
+ height: number;
25
+ width: number;
26
+ excavate: boolean;
27
+ x?: number;
28
+ y?: number;
29
+ };
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1,11 @@
1
+ import { Modules, Excavation, ImageSettings } from '@digigov/ui/app/QrCodeViewer/types';
2
+ export declare const MARGIN_SIZE = 4;
3
+ export declare function generatePath(modules: Modules, margin?: number): string;
4
+ export declare function excavateModules(modules: Modules, excavation: Excavation): Modules;
5
+ export declare function getImageSettings(cells: Modules, size: number, includeMargin: boolean, imageSettings?: ImageSettings): null | {
6
+ x: number;
7
+ y: number;
8
+ h: number;
9
+ w: number;
10
+ excavation: Excavation | null;
11
+ };
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.MARGIN_SIZE = void 0;
7
+ exports.excavateModules = excavateModules;
8
+ exports.generatePath = generatePath;
9
+ exports.getImageSettings = getImageSettings;
10
+ var DEFAULT_IMG_SCALE = 0.1;
11
+ var MARGIN_SIZE = 4;
12
+ exports.MARGIN_SIZE = MARGIN_SIZE;
13
+
14
+ function generatePath(modules) {
15
+ var margin = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
16
+ var ops = [];
17
+ modules.forEach(function (row, y) {
18
+ var start = null;
19
+ row.forEach(function (cell, x) {
20
+ if (!cell && start !== null) {
21
+ // M0 0h7v1H0z injects the space with the move and drops the comma,
22
+ // saving a char per operation
23
+ ops.push("M".concat(start + margin, " ").concat(y + margin, "h").concat(x - start, "v1H").concat(start + margin, "z"));
24
+ start = null;
25
+ return;
26
+ } // end of row, clean up or skip
27
+
28
+
29
+ if (x === row.length - 1) {
30
+ if (!cell) {
31
+ // We would have closed the op above already so this can only mean
32
+ // 2+ light modules in a row.
33
+ return;
34
+ }
35
+
36
+ if (start === null) {
37
+ // Just a single dark module.
38
+ ops.push("M".concat(x + margin, ",").concat(y + margin, " h1v1H").concat(x + margin, "z"));
39
+ } else {
40
+ // Otherwise finish the current line.
41
+ ops.push("M".concat(start + margin, ",").concat(y + margin, " h").concat(x + 1 - start, "v1H").concat(start + margin, "z"));
42
+ }
43
+
44
+ return;
45
+ }
46
+
47
+ if (cell && start === null) {
48
+ start = x;
49
+ }
50
+ });
51
+ });
52
+ return ops.join('');
53
+ } // We could just do this in generatePath, except that we want to support
54
+ // non-Path2D canvas, so we need to keep it an explicit step.
55
+
56
+
57
+ function excavateModules(modules, excavation) {
58
+ return modules.slice().map(function (row, y) {
59
+ if (y < excavation.y || y >= excavation.y + excavation.h) {
60
+ return row;
61
+ }
62
+
63
+ return row.map(function (cell, x) {
64
+ if (x < excavation.x || x >= excavation.x + excavation.w) {
65
+ return cell;
66
+ }
67
+
68
+ return false;
69
+ });
70
+ });
71
+ }
72
+
73
+ function getImageSettings(cells, size, includeMargin, imageSettings) {
74
+ if (imageSettings == null) {
75
+ return null;
76
+ }
77
+
78
+ var margin = includeMargin ? MARGIN_SIZE : 0;
79
+ var numCells = cells.length + margin * 2;
80
+ var defaultSize = Math.floor(size * DEFAULT_IMG_SCALE);
81
+ var scale = numCells / size;
82
+ var w = (imageSettings.width || defaultSize) * scale;
83
+ var h = (imageSettings.height || defaultSize) * scale;
84
+ var x = imageSettings.x == null ? cells.length / 2 - w / 2 : imageSettings.x * scale;
85
+ var y = imageSettings.y == null ? cells.length / 2 - h / 2 : imageSettings.y * scale;
86
+ var excavation;
87
+
88
+ if (imageSettings.excavate) {
89
+ var floorX = Math.floor(x);
90
+ var floorY = Math.floor(y);
91
+ var ceilW = Math.ceil(w + x - floorX);
92
+ var ceilH = Math.ceil(h + y - floorY);
93
+ excavation = {
94
+ x: floorX,
95
+ y: floorY,
96
+ w: ceilW,
97
+ h: ceilH
98
+ };
99
+ }
100
+
101
+ return {
102
+ x: x,
103
+ y: y,
104
+ h: h,
105
+ w: w,
106
+ excavation: excavation
107
+ };
108
+ }
package/app/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from '@digigov/ui/app/App';
2
2
  export * from '@digigov/ui/app/PageTitle';
3
3
  export * from '@digigov/ui/app/QrCodeScanner';
4
+ export * from '@digigov/ui/app/QrCodeViewer';
4
5
  export * from '@digigov/ui/app/Header';
5
6
  export * from '@digigov/ui/app/i18n';
6
7
  export * from '@digigov/ui/app/I18nText';
package/app/index.js CHANGED
@@ -43,6 +43,19 @@ Object.keys(_QrCodeScanner).forEach(function (key) {
43
43
  });
44
44
  });
45
45
 
46
+ var _QrCodeViewer = require("@digigov/ui/app/QrCodeViewer");
47
+
48
+ Object.keys(_QrCodeViewer).forEach(function (key) {
49
+ if (key === "default" || key === "__esModule") return;
50
+ if (key in exports && exports[key] === _QrCodeViewer[key]) return;
51
+ Object.defineProperty(exports, key, {
52
+ enumerable: true,
53
+ get: function get() {
54
+ return _QrCodeViewer[key];
55
+ }
56
+ });
57
+ });
58
+
46
59
  var _Header = require("@digigov/ui/app/Header");
47
60
 
48
61
  Object.keys(_Header).forEach(function (key) {
@@ -1,3 +1,4 @@
1
1
  export * from '@digigov/react-core/FileUpload';
2
2
  import FileUpload from '@digigov/react-core/FileUpload';
3
+ export * from '@digigov/react-core/FileUploadContainer';
3
4
  export default FileUpload;
@@ -22,6 +22,20 @@ Object.keys(_FileUpload).forEach(function (key) {
22
22
  });
23
23
  });
24
24
 
25
+ var _FileUploadContainer = require("@digigov/react-core/FileUploadContainer");
26
+
27
+ Object.keys(_FileUploadContainer).forEach(function (key) {
28
+ if (key === "default" || key === "__esModule") return;
29
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
30
+ if (key in exports && exports[key] === _FileUploadContainer[key]) return;
31
+ Object.defineProperty(exports, key, {
32
+ enumerable: true,
33
+ get: function get() {
34
+ return _FileUploadContainer[key];
35
+ }
36
+ });
37
+ });
38
+
25
39
  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); }
26
40
 
27
41
  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; }
@@ -572,16 +572,26 @@ var AutoComplete = /*#__PURE__*/function (_Component) {
572
572
  role: "listbox"
573
573
  }, options.map(function (option, index) {
574
574
  var showFocused = focused === -1 ? selected === index : focused === index;
575
- var iosPosinsetHtml = isIosDevice() ? "<span id=".concat(id, "__option-suffix--").concat(index, " style=\"border:0;clip:rect(0 0 0 0);height:1px;") + 'marginBottom:-1px;marginRight:-1px;overflow:hidden;padding:0;position:absolute;' + 'whiteSpace:nowrap;width:1px">' + " ".concat(index + 1, " of ").concat(options.length, "</span>") : '';
575
+ var iosPosinsetHtml = isIosDevice() ? /*#__PURE__*/React.createElement("span", {
576
+ id: "".concat(id, "__option-suffix--").concat(index),
577
+ style: {
578
+ border: '0',
579
+ clip: 'rect(0 0 0 0)',
580
+ height: '1px',
581
+ marginBottom: '-1px',
582
+ marginRight: '-1px',
583
+ overflow: 'hidden',
584
+ padding: '0',
585
+ position: 'absolute',
586
+ whiteSpace: 'nowrap',
587
+ width: '1px'
588
+ }
589
+ }, index + 1, " \u03B1\u03C0\u03CC ", options.length) : '';
576
590
  return /*#__PURE__*/React.createElement(AutoCompleteResultListItem, {
577
591
  isFocused: showFocused,
578
592
  isHovered: hovered,
579
593
  index: index,
580
594
  "aria-selected": focused === index ? 'true' : 'false',
581
- dangerouslySetInnerHTML: {
582
- __html: _this7.templateSuggestion(option) + iosPosinsetHtml
583
- },
584
- id: "".concat(id, "__option--").concat(index),
585
595
  key: index,
586
596
  onBlur: function onBlur(event) {
587
597
  return _this7.handleOptionBlur(event, index);
@@ -600,7 +610,7 @@ var AutoComplete = /*#__PURE__*/function (_Component) {
600
610
  tabIndex: -1,
601
611
  "aria-posinset": index + 1,
602
612
  "aria-setsize": options.length
603
- });
613
+ }, _this7.templateSuggestion(option), " ", iosPosinsetHtml);
604
614
  }), showNoOptionsFound && /*#__PURE__*/React.createElement(AutoCompleteNoResult, null, tNoResults === null || tNoResults === void 0 ? void 0 : tNoResults())), /*#__PURE__*/React.createElement(AutoCompleteAssistiveHint, {
605
615
  id: assistiveHintID
606
616
  }, tAssistiveHint === null || tAssistiveHint === void 0 ? void 0 : tAssistiveHint()));
@@ -1,10 +1,10 @@
1
1
  import React from 'react';
2
- import { CopyToClipboard } from '@digigov/ui/admin';
2
+ import { CopyToClipboard } from '@digigov/ui/admin/CopyToClipboard';
3
3
  import { Button } from '@digigov/ui';
4
4
 
5
5
  var _ref = /*#__PURE__*/React.createElement(CopyToClipboard, {
6
6
  text: "copied-text",
7
- variant: "tooltipLeft",
7
+ variant: "tooltip-left",
8
8
  message: "text successfuly copied!",
9
9
  id: "copy-to-clipboard"
10
10
  }, /*#__PURE__*/React.createElement(Button, {
@@ -59,7 +59,7 @@ var _ref3 = /*#__PURE__*/React.createElement(Title, {
59
59
 
60
60
  var _ref4 = /*#__PURE__*/React.createElement(ButtonGroup, null, /*#__PURE__*/React.createElement(CopyToClipboard, {
61
61
  text: "AAABBBFFFLLL",
62
- variant: "tooltipLeft",
62
+ variant: "tooltip-left",
63
63
  message: "text successfuly copied!"
64
64
  }, /*#__PURE__*/React.createElement(Button, null, "\u0391\u03C0\u03AC\u03BD\u03C4\u03B7\u03C3\u03B7")), /*#__PURE__*/React.createElement(Button, {
65
65
  color: "secondary"
@@ -83,7 +83,7 @@ var _ref6 = /*#__PURE__*/React.createElement(Grid, {
83
83
  xs: 12
84
84
  }, /*#__PURE__*/React.createElement(CopyToClipboard, {
85
85
  text: "AAABBBFFFLLL",
86
- variant: "tooltipLeft",
86
+ variant: "tooltip-left",
87
87
  message: "text successfuly copied!"
88
88
  }, /*#__PURE__*/React.createElement(Button, {
89
89
  color: "secondary"
@@ -108,7 +108,7 @@ export var MultipleCopies = function MultipleCopies() {
108
108
  }, /*#__PURE__*/React.createElement(SummaryListItemKey, null, field.name), /*#__PURE__*/React.createElement(SummaryListItemValue, null, field.value), /*#__PURE__*/React.createElement(SummaryListItemAction, null, /*#__PURE__*/React.createElement(ButtonGroup, null, field.actions && field.actions.map(function (action, subIndex) {
109
109
  return /*#__PURE__*/React.createElement(CopyToClipboard, {
110
110
  text: "MMMNNNKKKO",
111
- variant: "tooltipRight",
111
+ variant: "tooltip-right",
112
112
  key: subIndex
113
113
  }, /*#__PURE__*/React.createElement(Button, {
114
114
  key: subIndex,
@@ -7,8 +7,10 @@ import { useTranslation } from '@digigov/ui/app';
7
7
  export var CopyToClipboard = /*#__PURE__*/React.forwardRef(function CopyToClipboard(_ref, ref) {
8
8
  var text = _ref.text,
9
9
  _ref$variant = _ref.variant,
10
- variant = _ref$variant === void 0 ? 'tooltipRight' : _ref$variant,
10
+ variant = _ref$variant === void 0 ? 'tooltip-right' : _ref$variant,
11
11
  message = _ref.message,
12
+ _ref$timeout = _ref.timeout,
13
+ timeout = _ref$timeout === void 0 ? 3000 : _ref$timeout,
12
14
  children = _ref.children;
13
15
 
14
16
  var _useState = useState(false),
@@ -20,11 +22,11 @@ export var CopyToClipboard = /*#__PURE__*/React.forwardRef(function CopyToClipbo
20
22
  t = _useTranslation.t;
21
23
 
22
24
  useEffect(function () {
23
- var timeout = setTimeout(function () {
25
+ var timeoutInstance = setTimeout(function () {
24
26
  if (enabled) setEnabled(false);
25
- }, 3000);
27
+ }, timeout);
26
28
  return function () {
27
- return clearTimeout(timeout);
29
+ return clearTimeout(timeoutInstance);
28
30
  };
29
31
  }, [enabled]);
30
32
 
@@ -9,4 +9,5 @@ export * from './__stories__/FooterWithLogo';
9
9
  export * from './__stories__/FooterWithLink';
10
10
  export * from './__stories__/DefaultCopyright';
11
11
  export * from './__stories__/FooterWithSecondaryNavigation';
12
- export * from './__stories__/FooterAllInclusive';
12
+ export * from './__stories__/FooterAllInclusive';
13
+ export * from './__stories__/YearCopyright';
@@ -11,7 +11,7 @@ var _ref = /*#__PURE__*/React.createElement(Footer, null, /*#__PURE__*/React.cre
11
11
  src: logo1
12
12
  }), /*#__PURE__*/React.createElement(FooterImage, {
13
13
  src: logo2
14
- })), /*#__PURE__*/React.createElement(Copyright, null, "\xA9 Copyright 2021 - \u03A5\u03BB\u03BF\u03C0\u03BF\u03AF\u03B7\u03C3\u03B7 \u03B1\u03C0\u03CC \u03C4\u03BF", ' ', /*#__PURE__*/React.createElement(Link, {
14
+ })), /*#__PURE__*/React.createElement(Copyright, null, "\u03A5\u03BB\u03BF\u03C0\u03BF\u03AF\u03B7\u03C3\u03B7 \u03B1\u03C0\u03CC \u03C4\u03BF", ' ', /*#__PURE__*/React.createElement(Link, {
15
15
  href: "https://grnet.gr/",
16
16
  target: "_blank"
17
17
  }, ' ', "\u0395\u0394\u03A5\u03A4\u0395", ' ', /*#__PURE__*/React.createElement(VisuallyHidden, null, "(\u03B1\u03BD\u03BF\u03AF\u03B3\u03B5\u03B9 \u03C3\u03B5 \u03BA\u03B1\u03B9\u03BD\u03BF\u03CD\u03C1\u03B9\u03B1 \u03BA\u03B1\u03C1\u03C4\u03AD\u03BB\u03B1)")), ' ', "\u03B3\u03B9\u03B1 \u03C4\u03BF", ' ', /*#__PURE__*/React.createElement(Link, {
@@ -18,7 +18,7 @@ var _ref = /*#__PURE__*/React.createElement(Footer, null, /*#__PURE__*/React.cre
18
18
  size: "m"
19
19
  }), /*#__PURE__*/React.createElement(FooterMeta, null, /*#__PURE__*/React.createElement(FooterMetaItem, {
20
20
  grow: true
21
- }, /*#__PURE__*/React.createElement(FooterContent, null, /*#__PURE__*/React.createElement(Copyright, null, "\xA9 Copyright 2021 - \u03A5\u03BB\u03BF\u03C0\u03BF\u03AF\u03B7\u03C3\u03B7 \u03B1\u03C0\u03CC \u03C4\u03BF", ' ', /*#__PURE__*/React.createElement(Link, {
21
+ }, /*#__PURE__*/React.createElement(FooterContent, null, /*#__PURE__*/React.createElement(Copyright, null, "\u03A5\u03BB\u03BF\u03C0\u03BF\u03AF\u03B7\u03C3\u03B7 \u03B1\u03C0\u03CC \u03C4\u03BF", ' ', /*#__PURE__*/React.createElement(Link, {
22
22
  href: "https://grnet.gr/",
23
23
  target: "_blank"
24
24
  }, ' ', "\u0395\u0394\u03A5\u03A4\u0395", ' ', /*#__PURE__*/React.createElement(VisuallyHidden, null, "(\u03B1\u03BD\u03BF\u03AF\u03B3\u03B5\u03B9 \u03C3\u03B5 \u03BA\u03B1\u03B9\u03BD\u03BF\u03CD\u03C1\u03B9\u03B1 \u03BA\u03B1\u03C1\u03C4\u03AD\u03BB\u03B1)")), ' ', "\u03B3\u03B9\u03B1 \u03C4\u03BF", ' ', /*#__PURE__*/React.createElement(Link, {
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ import Copyright, { getCopyright } from '@digigov/ui/govgr/Footer/Copyright';
3
+ import HellenicRepublicLogo from '@digigov/ui/govgr/Footer/HellenicRepublicLogo';
4
+ import Footer from '@digigov/ui/govgr/Footer';
5
+ import { FooterMeta, FooterMetaItem, FooterContent, FooterInlineList, FooterInlineListItem, FooterLink, VisuallyHidden } from '@digigov/react-core';
6
+
7
+ var _ref = /*#__PURE__*/React.createElement(VisuallyHidden, null, "\u03A0\u03B5\u03C1\u03B9\u03C3\u03C3\u03CC\u03C4\u03B5\u03C1\u03B5\u03C2 \u03B5\u03C0\u03B9\u03BB\u03BF\u03B3\u03AD\u03C2");
8
+
9
+ var _ref2 = /*#__PURE__*/React.createElement(FooterInlineList, null, /*#__PURE__*/React.createElement(FooterInlineListItem, null, /*#__PURE__*/React.createElement(FooterLink, {
10
+ href: "#"
11
+ }, " \u0391\u03BA\u03CC\u03BC\u03B1 \u03BC\u03B9\u03B1 \u03B5\u03C0\u03B9\u03BB\u03BF\u03B3\u03AE")), /*#__PURE__*/React.createElement(FooterInlineListItem, null, /*#__PURE__*/React.createElement(FooterLink, null, " \u0391\u03BA\u03CC\u03BC\u03B1 \u03BC\u03B9\u03B1")));
12
+
13
+ var _ref3 = /*#__PURE__*/React.createElement(FooterMetaItem, null, /*#__PURE__*/React.createElement(HellenicRepublicLogo, null));
14
+
15
+ export var YearCopyright = function YearCopyright() {
16
+ return /*#__PURE__*/React.createElement(Footer, null, /*#__PURE__*/React.createElement(FooterMeta, null, /*#__PURE__*/React.createElement(FooterMetaItem, {
17
+ grow: true
18
+ }, /*#__PURE__*/React.createElement(FooterContent, null, _ref, _ref2, /*#__PURE__*/React.createElement(Copyright, {
19
+ copyright: getCopyright()
20
+ }))), _ref3));
21
+ };
22
+ export default YearCopyright;
@@ -0,0 +1,8 @@
1
+ /* eslint-disable digigov/no-relative-imports */
2
+ import QrCodeViewer from '@digigov/ui/app/QrCodeViewer';
3
+ export default {
4
+ title: 'Digigov UI/app/QrCodeViewer',
5
+ component: QrCodeViewer
6
+ };
7
+ export * from './__stories__/Default';
8
+ export * from './__stories__/Custom';
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ import QrCodeViewer from '@digigov/ui/app/QrCodeViewer';
3
+ import logo from '@digigov/ui/govgr/images/greek-government-base64';
4
+ export var Custom = function Custom() {
5
+ return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(QrCodeViewer, {
6
+ value: "https://www.gov.gr/",
7
+ size: 126,
8
+ bgColor: '#ededed',
9
+ fgColor: '#003375',
10
+ level: 'H',
11
+ includeMargin: false,
12
+ imageSettings: {
13
+ src: "".concat(logo),
14
+ x: undefined,
15
+ y: undefined,
16
+ height: 35,
17
+ width: 50,
18
+ excavate: true
19
+ }
20
+ }));
21
+ };
22
+ export default Custom;
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import QrCodeViewer from '@digigov/ui/app/QrCodeViewer';
3
+
4
+ var _ref = /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(QrCodeViewer, {
5
+ value: "https://www.gov.gr/"
6
+ }));
7
+
8
+ export var Default = function Default() {
9
+ return _ref;
10
+ };
11
+ export default Default;
@@ -0,0 +1,224 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
4
+ var _excluded = ["value", "size", "level", "bgColor", "fgColor", "includeMargin", "style", "imageSettings"],
5
+ _excluded2 = ["value", "size", "level", "bgColor", "fgColor", "includeMargin", "imageSettings"],
6
+ _excluded3 = ["renderAs"];
7
+ import React, { useRef, useEffect, useState } from 'react';
8
+ import qrcodegen from '@digigov/ui/app/QrCodeViewer/qrcodegen';
9
+ import { generatePath, excavateModules, getImageSettings, MARGIN_SIZE } from '@digigov/ui/app/QrCodeViewer/utils';
10
+ var DEFAULT_SIZE = 128;
11
+ var DEFAULT_LEVEL = 'L';
12
+ var DEFAULT_BGCOLOR = '#FFFFFF';
13
+ var DEFAULT_FGCOLOR = '#000000';
14
+ var DEFAULT_INCLUDEMARGIN = false;
15
+
16
+ var SUPPORTS_PATH2D = function () {
17
+ try {
18
+ new Path2D().addPath(new Path2D());
19
+ } catch (e) {
20
+ return false;
21
+ }
22
+
23
+ return true;
24
+ }();
25
+
26
+ var ERROR_LEVEL_MAP = {
27
+ L: qrcodegen.QrCode.Ecc.LOW,
28
+ M: qrcodegen.QrCode.Ecc.MEDIUM,
29
+ Q: qrcodegen.QrCode.Ecc.QUARTILE,
30
+ H: qrcodegen.QrCode.Ecc.HIGH
31
+ };
32
+
33
+ function QrCodeViewerCanvas(props) {
34
+ var value = props.value,
35
+ _props$size = props.size,
36
+ size = _props$size === void 0 ? DEFAULT_SIZE : _props$size,
37
+ _props$level = props.level,
38
+ level = _props$level === void 0 ? DEFAULT_LEVEL : _props$level,
39
+ _props$bgColor = props.bgColor,
40
+ bgColor = _props$bgColor === void 0 ? DEFAULT_BGCOLOR : _props$bgColor,
41
+ _props$fgColor = props.fgColor,
42
+ fgColor = _props$fgColor === void 0 ? DEFAULT_FGCOLOR : _props$fgColor,
43
+ _props$includeMargin = props.includeMargin,
44
+ includeMargin = _props$includeMargin === void 0 ? DEFAULT_INCLUDEMARGIN : _props$includeMargin,
45
+ style = props.style,
46
+ imageSettings = props.imageSettings,
47
+ otherProps = _objectWithoutProperties(props, _excluded);
48
+
49
+ var imgSrc = imageSettings === null || imageSettings === void 0 ? void 0 : imageSettings.src;
50
+
51
+ var _canvas = useRef(null);
52
+
53
+ var _image = useRef(null); // We're just using this state to trigger rerenders when images load. We
54
+ // Don't actually read the value anywhere. A smarter use of useEffect would
55
+ // depend on this value.
56
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
57
+
58
+
59
+ var _useState = useState(false),
60
+ _useState2 = _slicedToArray(_useState, 2),
61
+ isImgLoaded = _useState2[0],
62
+ setIsImageLoaded = _useState2[1];
63
+
64
+ useEffect(function () {
65
+ // Always update the canvas. It's cheap enough and we want to be correct
66
+ // with the current state.
67
+ if (_canvas.current !== null) {
68
+ var canvas = _canvas.current;
69
+ var ctx = canvas.getContext('2d');
70
+
71
+ if (!ctx) {
72
+ return;
73
+ }
74
+
75
+ var cells = qrcodegen.QrCode.encodeText(value, ERROR_LEVEL_MAP[level]).getModules();
76
+ var margin = includeMargin ? MARGIN_SIZE : 0;
77
+ var numCells = cells.length + margin * 2;
78
+ var calculatedImageSettings = getImageSettings(cells, size, includeMargin, imageSettings);
79
+ var image = _image.current;
80
+ var haveImageToRender = calculatedImageSettings != null && image !== null && image.complete && image.naturalHeight !== 0 && image.naturalWidth !== 0;
81
+
82
+ if (haveImageToRender && calculatedImageSettings) {
83
+ if (calculatedImageSettings.excavation != null) {
84
+ cells = excavateModules(cells, calculatedImageSettings.excavation);
85
+ }
86
+ } // We're going to scale this so that the number of drawable units
87
+ // matches the number of cells. This avoids rounding issues, but does
88
+ // result in some potentially unwanted single pixel issues between
89
+ // blocks, only in environments that don't support Path2D.
90
+
91
+
92
+ var pixelRatio = window.devicePixelRatio || 1;
93
+ canvas.height = canvas.width = size * pixelRatio;
94
+ var scale = size / numCells * pixelRatio;
95
+ ctx.scale(scale, scale); // Draw solid background, only paint dark modules.
96
+
97
+ ctx.fillStyle = bgColor;
98
+ ctx.fillRect(0, 0, numCells, numCells);
99
+ ctx.fillStyle = fgColor;
100
+
101
+ if (SUPPORTS_PATH2D) {
102
+ // $FlowFixMe: Path2D c'tor doesn't support args yet.
103
+ ctx.fill(new Path2D(generatePath(cells, margin)));
104
+ } else {
105
+ cells.forEach(function (row, rdx) {
106
+ row.forEach(function (cell, cdx) {
107
+ if (cell) {
108
+ ctx.fillRect(cdx + margin, rdx + margin, 1, 1);
109
+ }
110
+ });
111
+ });
112
+ }
113
+
114
+ if (haveImageToRender && calculatedImageSettings) {
115
+ if (image instanceof HTMLImageElement) {
116
+ ctx.drawImage(image, calculatedImageSettings.x + margin, calculatedImageSettings.y + margin, calculatedImageSettings.w, calculatedImageSettings.h);
117
+ }
118
+ }
119
+ }
120
+ }); // Ensure we mark image loaded as false here so we trigger updating the
121
+ // canvas in our other effect.
122
+
123
+ useEffect(function () {
124
+ setIsImageLoaded(false);
125
+ }, [imgSrc, isImgLoaded]);
126
+
127
+ var canvasStyle = _extends({
128
+ height: size,
129
+ width: size
130
+ }, style);
131
+
132
+ var img;
133
+
134
+ if (imgSrc != null) {
135
+ img = /*#__PURE__*/React.createElement("img", {
136
+ src: imgSrc,
137
+ key: imgSrc,
138
+ style: {
139
+ display: 'none'
140
+ },
141
+ onLoad: function onLoad() {
142
+ setIsImageLoaded(true);
143
+ },
144
+ ref: _image
145
+ });
146
+ }
147
+
148
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("canvas", _extends({
149
+ style: canvasStyle,
150
+ height: size,
151
+ width: size,
152
+ ref: _canvas
153
+ }, otherProps)), img);
154
+ }
155
+
156
+ function QrCodeViewerSVG(props) {
157
+ var value = props.value,
158
+ _props$size2 = props.size,
159
+ size = _props$size2 === void 0 ? DEFAULT_SIZE : _props$size2,
160
+ _props$level2 = props.level,
161
+ level = _props$level2 === void 0 ? DEFAULT_LEVEL : _props$level2,
162
+ _props$bgColor2 = props.bgColor,
163
+ bgColor = _props$bgColor2 === void 0 ? DEFAULT_BGCOLOR : _props$bgColor2,
164
+ _props$fgColor2 = props.fgColor,
165
+ fgColor = _props$fgColor2 === void 0 ? DEFAULT_FGCOLOR : _props$fgColor2,
166
+ _props$includeMargin2 = props.includeMargin,
167
+ includeMargin = _props$includeMargin2 === void 0 ? DEFAULT_INCLUDEMARGIN : _props$includeMargin2,
168
+ imageSettings = props.imageSettings,
169
+ otherProps = _objectWithoutProperties(props, _excluded2);
170
+
171
+ var cells = qrcodegen.QrCode.encodeText(value, ERROR_LEVEL_MAP[level]).getModules();
172
+ var margin = includeMargin ? MARGIN_SIZE : 0;
173
+ var numCells = cells.length + margin * 2;
174
+ var calculatedImageSettings = getImageSettings(cells, size, includeMargin, imageSettings);
175
+ var image;
176
+
177
+ if (imageSettings != null && calculatedImageSettings != null) {
178
+ if (calculatedImageSettings.excavation != null) {
179
+ cells = excavateModules(cells, calculatedImageSettings.excavation);
180
+ }
181
+
182
+ image = /*#__PURE__*/React.createElement("image", {
183
+ xlinkHref: imageSettings.src,
184
+ height: calculatedImageSettings.h,
185
+ width: calculatedImageSettings.w,
186
+ x: calculatedImageSettings.x + margin,
187
+ y: calculatedImageSettings.y + margin,
188
+ preserveAspectRatio: "none"
189
+ });
190
+ } // Drawing strategy: instead of a rect per module, we're going to create a
191
+ // single path for the dark modules and layer that on top of a light rect,
192
+ // for a total of 2 DOM nodes. We pay a bit more in string concat but that's
193
+ // way faster than DOM ops.
194
+ // For level 1, 441 nodes -> 2
195
+ // For level 40, 31329 -> 2
196
+
197
+
198
+ var fgPath = generatePath(cells, margin);
199
+ return /*#__PURE__*/React.createElement("svg", _extends({
200
+ height: size,
201
+ width: size,
202
+ viewBox: "0 0 ".concat(numCells, " ").concat(numCells)
203
+ }, otherProps), /*#__PURE__*/React.createElement("path", {
204
+ fill: bgColor,
205
+ d: "M0,0 h".concat(numCells, "v").concat(numCells, "H0z"),
206
+ shapeRendering: "crispEdges"
207
+ }), /*#__PURE__*/React.createElement("path", {
208
+ fill: fgColor,
209
+ d: fgPath,
210
+ shapeRendering: "crispEdges"
211
+ }), image);
212
+ }
213
+
214
+ export var QrCodeViewer = function QrCodeViewer(props) {
215
+ var renderAs = props.renderAs,
216
+ otherProps = _objectWithoutProperties(props, _excluded3);
217
+
218
+ if (renderAs === 'svg') {
219
+ return /*#__PURE__*/React.createElement(QrCodeViewerSVG, otherProps);
220
+ }
221
+
222
+ return /*#__PURE__*/React.createElement(QrCodeViewerCanvas, otherProps);
223
+ };
224
+ export default QrCodeViewer;