@dvrd/dvr-controls 1.0.5 → 1.0.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.
Files changed (177) hide show
  1. package/package.json +1 -1
  2. package/src/js/button/button.tsx +0 -102
  3. package/src/js/button/buttonController.tsx +0 -179
  4. package/src/js/button/closeButton.tsx +0 -29
  5. package/src/js/button/dvrdButton.tsx +0 -128
  6. package/src/js/button/outlinedButton.tsx +0 -105
  7. package/src/js/button/simpleButton.tsx +0 -163
  8. package/src/js/button/style/button.scss +0 -95
  9. package/src/js/button/style/closeButton.scss +0 -15
  10. package/src/js/button/style/dvrdButton.scss +0 -30
  11. package/src/js/button/style/outlinedButton.scss +0 -84
  12. package/src/js/button/style/simpleButton.scss +0 -80
  13. package/src/js/carousel/DVRCarousel.tsx +0 -163
  14. package/src/js/carousel/DVRCarouselController.tsx +0 -95
  15. package/src/js/carousel/style/DVRCarousel.scss +0 -38
  16. package/src/js/checkbox/checkbox.tsx +0 -147
  17. package/src/js/checkbox/checkboxController.tsx +0 -131
  18. package/src/js/checkbox/style/checkbox.scss +0 -109
  19. package/src/js/colorPicker/colorPicker.tsx +0 -118
  20. package/src/js/colorPicker/style/colorPicker.scss +0 -20
  21. package/src/js/date/dvrdDatePicker.tsx +0 -357
  22. package/src/js/date/style/dvrdDatePicker.scss +0 -307
  23. package/src/js/dialog/dialog.tsx +0 -207
  24. package/src/js/dialog/dialogController.tsx +0 -70
  25. package/src/js/dialog/inlineDialog.tsx +0 -127
  26. package/src/js/dialog/style/dialog.scss +0 -61
  27. package/src/js/events/withEvents.tsx +0 -40
  28. package/src/js/head/DVRHead.tsx +0 -49
  29. package/src/js/header/DVRHeader.tsx +0 -413
  30. package/src/js/header/style/header.scss +0 -206
  31. package/src/js/icon/awesomeIcon.tsx +0 -46
  32. package/src/js/image/imageUpload.tsx +0 -69
  33. package/src/js/image/style/imageUpload.scss +0 -11
  34. package/src/js/info/info.tsx +0 -136
  35. package/src/js/info/style/info.scss +0 -39
  36. package/src/js/input/animated/animatedTextField.tsx +0 -159
  37. package/src/js/input/date/dateField.tsx +0 -360
  38. package/src/js/input/date/dateFieldController.tsx +0 -245
  39. package/src/js/input/date/datePicker/datePicker.tsx +0 -186
  40. package/src/js/input/date/datePicker/style/datePicker.scss +0 -102
  41. package/src/js/input/date/input/dateInput.tsx +0 -213
  42. package/src/js/input/date/style/dateField.scss +0 -40
  43. package/src/js/input/date/timePicker/style/timePicker.scss +0 -95
  44. package/src/js/input/date/timePicker/timePicker.tsx +0 -143
  45. package/src/js/input/editor/DVREditor.tsx +0 -21
  46. package/src/js/input/number/numberInput.tsx +0 -157
  47. package/src/js/input/password/passwordInput.tsx +0 -140
  48. package/src/js/input/password/passwordRules.tsx +0 -48
  49. package/src/js/input/password/style/passwordInput.scss +0 -39
  50. package/src/js/input/password/style/passwordRules.scss +0 -41
  51. package/src/js/input/simple/style/simpleInput.scss +0 -98
  52. package/src/js/input/simple/v2/simpleInputV2.tsx +0 -178
  53. package/src/js/input/style/input.scss +0 -138
  54. package/src/js/input/v2/inputController_v2.tsx +0 -250
  55. package/src/js/input/v2/input_v2.tsx +0 -7
  56. package/src/js/label/label.tsx +0 -196
  57. package/src/js/label/style/label.scss +0 -4
  58. package/src/js/link/link.tsx +0 -38
  59. package/src/js/link/style/link.scss +0 -30
  60. package/src/js/loader/loader.tsx +0 -79
  61. package/src/js/loader/loaderController.tsx +0 -61
  62. package/src/js/loader/style/loader.scss +0 -53
  63. package/src/js/media/media.tsx +0 -72
  64. package/src/js/navigator/navigator.tsx +0 -51
  65. package/src/js/optionsList/dvrdOptionsList.tsx +0 -112
  66. package/src/js/optionsList/style/dvrdOptionsList.scss +0 -84
  67. package/src/js/optionsMenu/optionsMenu.tsx +0 -187
  68. package/src/js/optionsMenu/style/optionsMenu.scss +0 -70
  69. package/src/js/pdf/element/pdfElement.tsx +0 -315
  70. package/src/js/pdf/element/style/pdfElement.scss +0 -111
  71. package/src/js/pdf/history/pdfHistory.ts +0 -57
  72. package/src/js/pdf/image/pdfImage.tsx +0 -175
  73. package/src/js/pdf/image/style/pdfImage.scss +0 -34
  74. package/src/js/pdf/invoiceTable/pdfInvoiceTable.tsx +0 -176
  75. package/src/js/pdf/invoiceTable/style/pdfInvoiceTable.scss +0 -32
  76. package/src/js/pdf/pdfTemplateCreator.tsx +0 -278
  77. package/src/js/pdf/settings/buttons/iconButton.tsx +0 -49
  78. package/src/js/pdf/settings/buttons/style/iconButton.scss +0 -50
  79. package/src/js/pdf/settings/image/pdfImageSettings.tsx +0 -82
  80. package/src/js/pdf/settings/image/style/pdfImageSettings.scss +0 -9
  81. package/src/js/pdf/settings/invoiceTable/pdfInvoiceTableSettings.tsx +0 -141
  82. package/src/js/pdf/settings/invoiceTable/style/pdfInvoiceTableSettings.scss +0 -38
  83. package/src/js/pdf/settings/pdfElementSettings.tsx +0 -86
  84. package/src/js/pdf/settings/style/pdfElementSettings.scss +0 -56
  85. package/src/js/pdf/settings/text/pdfTextSettings.tsx +0 -202
  86. package/src/js/pdf/settings/text/style/pdfTextSettings.scss +0 -94
  87. package/src/js/pdf/style/pdfTemplateCreator.scss +0 -118
  88. package/src/js/pdf/text/pdfText.tsx +0 -267
  89. package/src/js/pdf/text/style/pdfText.scss +0 -22
  90. package/src/js/popup/style/withBackground.scss +0 -29
  91. package/src/js/popup/withBackground.tsx +0 -102
  92. package/src/js/select/async/asyncSelect.tsx +0 -46
  93. package/src/js/select/async/style/asyncSelect.scss +0 -23
  94. package/src/js/select/dvrdSelect.tsx +0 -185
  95. package/src/js/select/dvrdSelectController.tsx +0 -81
  96. package/src/js/select/select.tsx +0 -310
  97. package/src/js/select/selectController.tsx +0 -341
  98. package/src/js/select/style/dvrdSelect.scss +0 -140
  99. package/src/js/select/style/select.scss +0 -199
  100. package/src/js/sidebarMenu/sidebarMenu.tsx +0 -165
  101. package/src/js/sidebarMenu/style/sidebarMenu.scss +0 -161
  102. package/src/js/slider/DVRSlider.tsx +0 -107
  103. package/src/js/slider/style/DVRSlider.scss +0 -88
  104. package/src/js/snackbar/snackbar.tsx +0 -72
  105. package/src/js/snackbar/snackbarController.tsx +0 -104
  106. package/src/js/snackbar/style/snackbar.scss +0 -46
  107. package/src/js/switch/dvrdSwitch.tsx +0 -53
  108. package/src/js/switch/style/dvrdSwitch.scss +0 -47
  109. package/src/js/switch/style/switch.scss +0 -84
  110. package/src/js/switch/switch.tsx +0 -115
  111. package/src/js/switch/switchController.tsx +0 -97
  112. package/src/js/textField/dvrdInput.tsx +0 -217
  113. package/src/js/textField/dvrdInputController.tsx +0 -97
  114. package/src/js/textField/dvrdNumberInput.tsx +0 -141
  115. package/src/js/textField/dvrdPasswordInput.tsx +0 -40
  116. package/src/js/textField/style/dvrdInput.scss +0 -114
  117. package/src/js/textField/style/dvrdPassword.scss +0 -15
  118. package/src/js/topButton/style/topButton.scss +0 -54
  119. package/src/js/topButton/topButton.tsx +0 -135
  120. package/src/js/util/analyticsUtil.ts +0 -41
  121. package/src/js/util/colorUtil.ts +0 -230
  122. package/src/js/util/componentUtil.tsx +0 -59
  123. package/src/js/util/constants.ts +0 -12
  124. package/src/js/util/controlContext.tsx +0 -46
  125. package/src/js/util/controlUtil.ts +0 -107
  126. package/src/js/util/cookieUtil.ts +0 -17
  127. package/src/js/util/eventUtil.ts +0 -65
  128. package/src/js/util/googleUtil.ts +0 -88
  129. package/src/js/util/interfaces.ts +0 -179
  130. package/src/js/util/jwtUtil.ts +0 -72
  131. package/src/js/util/miscUtil.ts +0 -170
  132. package/src/js/util/momentUtil.ts +0 -45
  133. package/src/js/util/pdfUtil.ts +0 -124
  134. package/src/js/util/requestUtil.ts +0 -146
  135. package/src/js/util/responsiveUtil.ts +0 -37
  136. package/src/js/util/validationUtil.ts +0 -13
  137. package/src/res/img/lock-handle.png +0 -0
  138. package/src/res/img/lock-handle.webp +0 -0
  139. package/src/res/img/lock.png +0 -0
  140. package/src/res/img/lock.webp +0 -0
  141. package/src/style/common-icons-variables.scss +0 -140
  142. package/src/style/common-icons.scss +0 -714
  143. package/src/style/common-variables.scss +0 -243
  144. package/src/style/display-breakpoints.scss +0 -141
  145. package/src/style/fonts/common-icons.eot +0 -0
  146. package/src/style/fonts/common-icons.svg +0 -150
  147. package/src/style/fonts/common-icons.ttf +0 -0
  148. package/src/style/fonts/common-icons.woff +0 -0
  149. package/src/style/fonts/common-icons.woff2 +0 -0
  150. package/src/style/fonts/fontAwesome/css/all.css +0 -7003
  151. package/src/style/fonts/fontAwesome/css/all.min.css +0 -6
  152. package/src/style/fonts/fontAwesome/css/brands.css +0 -1423
  153. package/src/style/fonts/fontAwesome/css/brands.min.css +0 -6
  154. package/src/style/fonts/fontAwesome/css/fontawesome.css +0 -5519
  155. package/src/style/fonts/fontAwesome/css/fontawesome.min.css +0 -6
  156. package/src/style/fonts/fontAwesome/css/regular.css +0 -19
  157. package/src/style/fonts/fontAwesome/css/regular.min.css +0 -6
  158. package/src/style/fonts/fontAwesome/css/solid.css +0 -19
  159. package/src/style/fonts/fontAwesome/css/solid.min.css +0 -6
  160. package/src/style/fonts/fontAwesome/css/svg-with-js.css +0 -634
  161. package/src/style/fonts/fontAwesome/css/svg-with-js.min.css +0 -6
  162. package/src/style/fonts/fontAwesome/css/v4-font-face.css +0 -26
  163. package/src/style/fonts/fontAwesome/css/v4-font-face.min.css +0 -6
  164. package/src/style/fonts/fontAwesome/css/v4-shims.css +0 -2146
  165. package/src/style/fonts/fontAwesome/css/v4-shims.min.css +0 -6
  166. package/src/style/fonts/fontAwesome/css/v5-font-face.css +0 -22
  167. package/src/style/fonts/fontAwesome/css/v5-font-face.min.css +0 -6
  168. package/src/style/fonts/fontAwesome/webfonts/fa-brands-400.ttf +0 -0
  169. package/src/style/fonts/fontAwesome/webfonts/fa-brands-400.woff2 +0 -0
  170. package/src/style/fonts/fontAwesome/webfonts/fa-regular-400.ttf +0 -0
  171. package/src/style/fonts/fontAwesome/webfonts/fa-regular-400.woff2 +0 -0
  172. package/src/style/fonts/fontAwesome/webfonts/fa-solid-900.ttf +0 -0
  173. package/src/style/fonts/fontAwesome/webfonts/fa-solid-900.woff2 +0 -0
  174. package/src/style/fonts/fontAwesome/webfonts/fa-v4compatibility.ttf +0 -0
  175. package/src/style/fonts/fontAwesome/webfonts/fa-v4compatibility.woff2 +0 -0
  176. package/src/style/variables.scss +0 -11
  177. package/tsconfig.json +0 -15
@@ -1,230 +0,0 @@
1
- /*
2
- * Copyright (c) 2021. Dave van Rijn Development
3
- */
4
-
5
- import {ColorSet} from "./interfaces";
6
- import {isNotNull} from "./controlUtil";
7
-
8
- interface ColorShape {
9
- [index: string]: string,
10
- }
11
-
12
- const colorConstants: ColorShape = {
13
- orange: "color-orange",
14
- white: "#ffffff",
15
- black: '#000000',
16
- gray: 'gray',
17
- "color-blue-1": "#009fe3",
18
- "color-blue-handels": "#005fa0",
19
- "color-blue-knab": "#003b5a",
20
- "color-blue-trio": "#00006b",
21
- "color-blue-text": "#2A435F",
22
- "color-gray-2": "#808080",
23
- "color-gray-3": "#9a9a9a",
24
- "color-gray-4": "#cccccc",
25
- "color-gray-5": "#434b50",
26
- "color-gray-6": "#F2F2F2",
27
- "color-gray-7": "#e4e4e4",
28
- "color-gray-header": "#3a4044",
29
- "color-green-1": "#18A155",
30
- "color-green-abn": "#00857a",
31
- "color-green-whatsapp": "#29A71A",
32
- "color-orange": "#f39320",
33
- "color-orange-asn": "#f0533d",
34
- "color-purple-sns": "#562772",
35
- "color-red-moneyou": "#d40d47",
36
- "color-red-regio": "#ca031a",
37
- };
38
-
39
- export const constants: ColorShape = {
40
- ...colorConstants,
41
- };
42
-
43
- export const OrangeSet: ColorSet = {
44
- base: '#ffc47d',
45
- contrast: '#ab5d00',
46
- // contrast: '#ffc47d'
47
- };
48
-
49
- export const OrangeSet2: ColorSet = {
50
- base: '#F9ECD1',
51
- contrast: '#ab5d00'
52
- };
53
-
54
- export const GreenSet: ColorSet = {
55
- base: '#D9F6D9',
56
- contrast: '#669966',
57
- };
58
-
59
- export const YellowSet: ColorSet = {
60
- base: '',
61
- contrast: '',
62
- };
63
-
64
- export const BlueSet: ColorSet = {
65
- base: '#b0e7ff',
66
- contrast: '#007bb0',
67
- };
68
-
69
- export const RedSet: ColorSet = {
70
- base: '',
71
- contrast: '',
72
- };
73
-
74
- export const findDarkestColor = (...colors: string[]): string => {
75
- let darkest = 9999, darkestColor: string = '';
76
- for (const color of colors) {
77
- const hsp: number | undefined = getHsp(color);
78
- if (hsp !== undefined && hsp < darkest) {
79
- darkest = hsp;
80
- darkestColor = color;
81
- }
82
- }
83
- return darkestColor;
84
- };
85
-
86
- const getHsp = (color: string): number | undefined => {
87
- let r: number | undefined, g: number | undefined, b: number | undefined, hsp: number | undefined;
88
- if (color.match(/^rgb/)) {
89
- const colorMatch = color.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)$/);
90
- if (colorMatch) {
91
- r = parseInt(colorMatch[1]);
92
- g = parseInt(colorMatch[2]);
93
- b = parseInt(colorMatch[3]);
94
- }
95
- } else {
96
- // @ts-ignore
97
- let colorNum: number = +("0x" + color.slice(1).replace(color.length < 5 && /./g, '$&$&'));
98
- r = colorNum >> 16;
99
- g = colorNum >> 8 & 255;
100
- b = colorNum & 255;
101
- }
102
- if (r !== undefined && g !== undefined && b !== undefined)
103
- return Math.sqrt(
104
- 0.299 * (r * r) +
105
- 0.587 * (g * g) +
106
- 0.114 * (b * b)
107
- );
108
- }
109
-
110
- export const hexToRgb = (hex: string): { r: number | null, g: number | null, b: number | null } => {
111
- const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
112
- return result ? {
113
- r: parseInt(result[1], 16),
114
- g: parseInt(result[2], 16),
115
- b: parseInt(result[3], 16)
116
- } : {r: null, g: null, b: null};
117
- };
118
-
119
- export const getRandomColor = (): string => {
120
- const letters = '0123456789ABCDEF';
121
- let color = '#';
122
- for (let i = 0; i < 6; i++)
123
- color += letters[Math.floor(Math.random() * letters.length)];
124
- return color;
125
- };
126
-
127
- //@ts-ignore-start
128
- export const editColor = (p, c0, c1?, l?): string => {
129
- c0 = convertColor(c0);
130
- let r, g, b, P, f, t, h, i = parseInt, m = Math.round, a = typeof (c1) == "string";
131
- if (p < -1 || p > 1 || (c0[0] !== 'r' && c0[0] !== '#') || (c1 && !a)) return c0;
132
- // @ts-ignore
133
- if (!window.pSBCr) window.pSBCr = (d) => {
134
- let n = d.length, x = {};
135
- if (n > 9) {
136
- [r, g, b, a] = d = d.split(","), n = d.length;
137
- if (n < 3 || n > 4) return null;
138
- // @ts-ignore
139
- x.r = i(r[3] === "a" ? r.slice(5) : r.slice(4)), x.g = i(g), x.b = i(b), x.a = a ? parseFloat(a) : -1
140
- } else {
141
- if (n === 8 || n === 6 || n < 4) return null;
142
- if (n < 6) d = "#" + d[1] + d[1] + d[2] + d[2] + d[3] + d[3] + (n > 4 ? d[4] + d[4] : "");
143
- d = i(d.slice(1), 16);
144
- // @ts-ignore
145
- if (n === 9 || n === 5) x.r = d >> 24 & 255, x.g = d >> 16 & 255, x.b = d >> 8 & 255, x.a =
146
- m((d & 255) / 0.255) / 1000;
147
- // @ts-ignore
148
- else x.r = d >> 16, x.g = d >> 8 & 255, x.b = d & 255, x.a = -1
149
- }
150
- return x
151
- };
152
- // @ts-ignore
153
- h = c0.length > 9, h = a ? c1.length > 9 ? true : c1 === "c" ? !h : false : h, f = pSBCr(c0), P = p < 0, t =
154
- // @ts-ignore
155
- c1 && c1 !== "c" ? pSBCr(c1) : P ? {
156
- r: 0,
157
- g: 0,
158
- b: 0,
159
- a: -1
160
- } : {r: 255, g: 255, b: 255, a: -1}, p = P ? p * -1 : p, P = 1 - p;
161
- if (!f || !t) return c0;
162
- if (l) r = m(P * f.r + p * t.r), g = m(P * f.g + p * t.g), b = m(P * f.b + p * t.b);
163
- else r = m((P * f.r ** 2 + p * t.r ** 2) ** 0.5), g = m((P * f.g ** 2 + p * t.g ** 2) ** 0.5), b =
164
- m((P * f.b ** 2 + p * t.b ** 2) ** 0.5);
165
- // @ts-ignore
166
- a = f.a, t = t.a, f = a >= 0 || t >= 0, a = f ? a < 0 ? t : t < 0 ? a : a * P + t * p : 0;
167
- // @ts-ignore
168
- if (h) return "rgb" + (f ? "a(" : "(") + r + "," + g + "," + b + (f ? "," + m(a * 1000) / 1000 : "") + ")";
169
- // @ts-ignore
170
- else return "#" + (4294967296 + r * 16777216 + g * 65536 + b * 256 + (f ? m(a * 255) : 0)).toString(16)
171
- .slice(1, f ? undefined : -2)
172
- };
173
-
174
- export const darkenColor = (color: string, percentage: number) => editColor(percentage / -100, color);
175
- export const lightenColor = (color: string, percentage: number) => editColor(percentage / 100, color);
176
-
177
- export const colorIsHex = (colorName: string): boolean => /^#[A-Za-z\d]{6,7}$/.test(colorName);
178
-
179
- export const colorIsWhite = (color: string): boolean => color === 'white' || /#fff(fff)?/.test(color);
180
-
181
- export const convertColor = (colorName: string) => {
182
- if (colorIsHex(colorName)) return colorName;
183
- else if (colorConstants.hasOwnProperty(colorName)) {
184
- if (colorIsHex(colorConstants[colorName])) return colorConstants[colorName];
185
-
186
- const converted = colorConstants[colorName];
187
- if (isNotNull(converted)) return colorConstants[converted];
188
- }
189
- return colorName;
190
- };
191
-
192
- export enum Colors {
193
- BLUE = '#0000ff',
194
- FACEBOOK = '#4267B2',
195
- BLUE1 = '#3687bc',
196
- BLUE2 = '#008dca',
197
- BLUE3 = '#009fe3',
198
- BLUE3_HOVER = '#31c1ff',
199
- BLUE4 = '#779bbc',
200
- BLUE5 = '#DEEAF6',
201
- GRAY1 = '#333',
202
- GRAY2 = '#3a4044', // HEADER
203
- GRAY3 = '#434b50',
204
- GRAY = '#808080',
205
- GRAY_DVR_LOGO = '#b4b7b999',
206
- GRAY4 = '#9a9a9a',
207
- GRAY5_HOVER = '#b2b2b2',
208
- GRAY6 = '#ccc',
209
- GRAY5 = '#d8d8d8', // HEADER TEXT
210
- GRAY7 = '#e4e4e4',
211
- GRAY8 = '#f8f8f8',
212
- GRAY9 = '#F2F2F2',
213
- ORANGE1 = '#b05a20',
214
- ORANGE2_HOVER = '#f39320cc',
215
- ORANGE2 = '#f39320',
216
- YELLOW1 = '#fff000',
217
- GREEN1 = '#18A155',
218
- WHATSAPP = '#29A71A',
219
- GREEN2 = '#94FB82',
220
- GREEN3 = '#eafeea',
221
- GREEN4 = '#E2EFDA',
222
- GREEN5 = '#edf1f2',
223
- PINK1_HOVER = '#fbe1d599',
224
- PINK1 = '#fbe1d5',
225
- RED_HOVER = '#cc0000',
226
- RED1 = '#ca031a',
227
- RED = '#ff0000',
228
- RED2 = '#ff7e78',
229
- RED3 = '#FDD4CC',
230
- }
@@ -1,59 +0,0 @@
1
- /*
2
- * Copyright (c) 2021. Dave van Rijn Development
3
- */
4
-
5
- import React from "react";
6
- import {debug} from "./miscUtil";
7
- import {getScreenHeight, getScreenWidth} from "./responsiveUtil";
8
- import {generateUUID} from "./controlUtil";
9
-
10
- export const generateComponentId = (id?: string | null, lettersOnly: boolean = true): string => {
11
- if (id !== null && id !== undefined) return id;
12
- const generated = generateUUID();
13
- let compId = generated.substring(0, generated.indexOf('-', generated.indexOf('-') + 1));
14
- if (lettersOnly)
15
- compId = compId.split('').map((char: string) => Number.isNaN(char) ? char : String.fromCharCode(97 + Number(char))).join('');
16
- return compId;
17
- };
18
-
19
- export const navigate = (url: string, stripQuery: boolean = true, move: boolean | string = true,
20
- customScroller?: (id?: boolean | string) => void) => {
21
- let navigator = document.getElementById('appNavigator');
22
- if (navigator) {
23
- navigator.dataset.url = url;
24
- if (stripQuery) navigator.dataset.strip = '1';
25
- navigator.click();
26
-
27
- if (customScroller) {
28
- directTimeout(() => {
29
- customScroller(move);
30
- });
31
- } else if (typeof move === 'string') {
32
- directTimeout(() => {
33
- const element = document.getElementById(move);
34
- if (element) element.scrollIntoView({block: "start", behavior: "smooth"});
35
- });
36
- } else if (move) directTimeout(() => {
37
- window.scrollTo(0, 0)
38
- });
39
- } else debug('Navigator not found');
40
- };
41
-
42
- export const elementIsInView = (element: HTMLElement): boolean => {
43
- const box = element.getBoundingClientRect();
44
- return box.top >= 0 && box.left >= 0 && box.bottom <= getScreenHeight() && box.right <= getScreenWidth();
45
- };
46
-
47
- export const directTimeout = (handler: Function) => {
48
- window.setTimeout(handler, 0);
49
- };
50
-
51
- export const getElementTop = (element: string | HTMLElement | null): number => {
52
- if (typeof element === 'string') element = document.getElementById(element);
53
- if (element) {
54
- const box = element.getBoundingClientRect(),
55
- scrollTop = window.pageYOffset || document.documentElement.scrollTop;
56
- return box.top + scrollTop;
57
- }
58
- return 0;
59
- };
@@ -1,12 +0,0 @@
1
- /*
2
- * Copyright (c) 2021. Dave van Rijn Development
3
- */
4
-
5
- /*
6
- ================================================
7
- KEY CODES
8
- ================================================
9
- */
10
- export const ESCAPE_CODE = 'Escape', ESCAPE_IE_CODE = 'Esc', ENTER_CODE = 'Enter', BACKSPACE_CODE = 'Backspace';
11
-
12
-
@@ -1,46 +0,0 @@
1
- /*
2
- * Copyright (c) 2021. Dave van Rijn Development
3
- */
4
-
5
- import React, {Context, PropsWithChildren, useEffect} from 'react';
6
- import {ControlVariant} from "./interfaces";
7
- import {defer} from 'lodash';
8
-
9
- // noinspection JSUnusedGlobalSymbols
10
- export interface ThemeContextShape {
11
- baseColor: string,
12
- contrastColor: string,
13
- onChange: Function,
14
- }
15
-
16
- export interface ProviderProps {
17
- theme: ThemeShape;
18
- }
19
-
20
- export interface ThemeShape {
21
- baseColor: string,
22
- contrastColor: string,
23
- controlVariant?: ControlVariant;
24
- borderColor?: string;
25
- onChange?: (theme?: ThemeShape) => void;
26
- }
27
-
28
- export const ControlContext: Context<ThemeShape> = React.createContext<ThemeShape>(
29
- {baseColor: 'black', contrastColor: 'white', controlVariant: ControlVariant.STANDARD});
30
-
31
- export default function ThemeContextProvider(props: PropsWithChildren<ProviderProps>) {
32
- const {theme, children} = props;
33
- useEffect(() => {
34
- defer(() => {
35
- const root = document.documentElement;
36
- root.style.setProperty('--base-color', theme.baseColor);
37
- root.style.setProperty('--contrast-color', theme.contrastColor);
38
- });
39
- }, [theme]);
40
-
41
- return (
42
- <ControlContext.Provider value={theme}>
43
- {children}
44
- </ControlContext.Provider>
45
- )
46
- }
@@ -1,107 +0,0 @@
1
- /*
2
- * Copyright (c) 2021. Dave van Rijn Development
3
- */
4
-
5
- import React from 'react';
6
- import {v4} from 'uuid';
7
- import {ENTER_CODE, ESCAPE_CODE, ESCAPE_IE_CODE} from "./constants";
8
- import {Breakpoint} from "./interfaces";
9
-
10
- export const generateUUID = (): string => {
11
- // Crypto is not supported by some browsers, so we use another method if crypto is not supported.
12
- if (window.crypto)
13
- // @ts-ignore
14
- return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, (c: any) =>
15
- (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
16
- );
17
- return v4();
18
- };
19
-
20
- export const isNotNull = (obj: any): boolean => {
21
- if (obj === undefined || obj === null)
22
- return false;
23
- return !(obj.hasOwnProperty('length') && obj.length === 0);
24
- };
25
-
26
- export const isNull = (obj: any): boolean => !isNotNull(obj);
27
-
28
- export const hasHover = (element: HTMLElement | null): boolean => {
29
- if(!element) return false;
30
- if (isNotNull(element) && element.parentElement !== null) {
31
- return element.parentElement.querySelector(':hover') === element;
32
- }
33
- return false;
34
- };
35
-
36
- export const pxToRem = (pxValue: number) => {
37
- let fontSize: number = getFontSize();
38
- return pxValue / fontSize;
39
- };
40
-
41
- export const remToPx = (remValue: number) => {
42
- let htmlElement = document.getElementsByTagName('html')[0];
43
- let fontSize: number | string = window.getComputedStyle(htmlElement, null).getPropertyValue('font-size');
44
- fontSize = parseInt(fontSize.slice(0, fontSize.length - 2), 10);
45
- return remValue * fontSize;
46
- };
47
-
48
- const getFontSize = (): number => {
49
- let fontSize: number | string = getComputedProperty('font-size');
50
- fontSize = parseInt(fontSize.slice(0, fontSize.length - 2), 10);
51
- return fontSize;
52
- };
53
-
54
- export const getComputedProperty = (propertyName: string, element?: Element): string => {
55
- const htmlElement = element || document.getElementsByTagName('html')[0];
56
- return window.getComputedStyle(htmlElement, null).getPropertyValue(propertyName);
57
- };
58
-
59
- export const stringStartsWith = (string: string, value: string): boolean => {
60
- value = value.trim().toLowerCase();
61
- const valueLength = value.length;
62
- return string.toLowerCase().slice(0, valueLength) === value;
63
- };
64
-
65
- export const stringContains = (string: string, value: string): boolean =>
66
- string.toLowerCase().includes(value.toLowerCase());
67
-
68
- export const voidFunction = () => null;
69
-
70
- export const escapePressed = (evt: React.KeyboardEvent | KeyboardEvent) => {
71
- return ((evt.key && (evt.key === ESCAPE_IE_CODE || evt.key === ESCAPE_CODE))) || evt.keyCode === 27 || evt.which ===
72
- 27;
73
- };
74
-
75
- export const enterPressed = (evt: React.KeyboardEvent | KeyboardEvent) => {
76
- return ((evt.key && evt.key === ENTER_CODE) || evt.keyCode === 13 || evt.which === 13);
77
- };
78
-
79
- let canvas: HTMLCanvasElement | null = null;
80
- export const calculateTextWidth = (text: string, fontSize?: number, fontFamily?: string): number => {
81
- canvas = canvas || document.createElement('canvas');
82
- const context = canvas.getContext('2d');
83
- if (fontSize === undefined) fontSize = getFontSize();
84
- if (fontFamily === undefined || !fontFamily.length) fontFamily = getComputedProperty('font-family');
85
-
86
- let width = 0;
87
- if (context) {
88
- context.font = `${fontSize}px ${fontFamily}`;
89
- width = context.measureText(text).width;
90
- }
91
- return Math.ceil(width);
92
- };
93
-
94
- export const pad = (num: string | number): string => ('0' + num).slice(-2);
95
-
96
- export const stopPropagation = (evt: Event | React.SyntheticEvent) => {
97
- evt.stopPropagation();
98
- };
99
-
100
- export const assert = (condition: boolean, errMsg?: string | null) => {
101
- const message = errMsg || 'Undocumented assertion error';
102
- if (!condition) {
103
- if (typeof Error !== 'undefined')
104
- throw new Error(message);
105
- else throw message;
106
- }
107
- };
@@ -1,17 +0,0 @@
1
- /*
2
- * Copyright (c) 2021. Dave van Rijn Development
3
- */
4
-
5
- import Cookies, {CookieAttributes} from "js-cookie";
6
-
7
- export const setCookie = (key: string, value: string, args?: CookieAttributes) => {
8
- Cookies.set(key, value, {...args})
9
- }
10
-
11
- export const removeCookie = (key: string, args?: CookieAttributes) => {
12
- Cookies.remove(key, args);
13
- };
14
-
15
- export const getCookie = (key: string): string | undefined => {
16
- return Cookies.get(key);
17
- }
@@ -1,65 +0,0 @@
1
- /*
2
- * Copyright (c) 2021. Dave van Rijn Development
3
- */
4
-
5
- import React from 'react';
6
- import {DialogActions} from "../dialog/dialogController";
7
- import {DialogConfig, Snack} from "./interfaces";
8
-
9
- interface ListenerShape {
10
- component: string,
11
- eventName: string,
12
- eventHandler: Function,
13
- }
14
-
15
- const listeners: ListenerShape[] = [];
16
-
17
- export const addCustomEventListener = (componentName: string, eventName: string, eventHandler: Function): boolean => {
18
- if (listenerExists(componentName, eventName)) return false;
19
- listeners.push({component: componentName, eventName, eventHandler});
20
- return true;
21
- };
22
-
23
- export const removeCustomEventListener = (componentName: string, eventName: string): boolean => {
24
- let foundListeners = false;
25
- for (let i = listeners.length - 1; i >= 0; i--) {
26
- const listener = listeners[i];
27
- if (listener.component === componentName && listener.eventName === eventName) {
28
- listeners.splice(i, 1);
29
- foundListeners = true;
30
- }
31
- }
32
- return foundListeners;
33
- };
34
-
35
- export const dispatchCustomEvent = (eventName: string, data?: any | null) => {
36
- let listenerFound = false;
37
- for (const listener of listeners) {
38
- if (listener.eventName === eventName) {
39
- listenerFound = true;
40
- listener.eventHandler(data);
41
- }
42
- }
43
- };
44
-
45
- const listenerExists = (componentName: string, eventName: string) => {
46
- for (let i = 0; i < listeners.length; i++) {
47
- const listener = listeners[i];
48
- if (listener.component === componentName && listener.eventName === eventName) return true;
49
- }
50
- return false;
51
- };
52
-
53
- //==========================
54
- // Events
55
- //==========================
56
-
57
- export const showDialog = (message: string | React.ReactElement, title: string = 'Bericht van het systeem',
58
- actions?: DialogActions | null,
59
- persistent?: boolean, transparent?: boolean) => {
60
- dispatchCustomEvent('onOpenDialog', {message, title, actions, transparent, persistent});
61
- };
62
-
63
- export const showSnackbar = (text: string | React.ReactElement, config?: DialogConfig) => {
64
- dispatchCustomEvent('onShowSnackbar', {text, config});
65
- };
@@ -1,88 +0,0 @@
1
- /*
2
- * Copyright (c) 2021. Dave van Rijn Development
3
- */
4
-
5
- /**
6
- * Loads Google SDK.
7
- * @see https://developers.google.com/api-client-library/javascript/reference/referencedocs#gapiclientloadname--------version--------callback
8
- * @see https://developers.google.com/api-client-library/javascript/reference/referencedocs#gapiauth2initparams
9
- * @see https://developers.google.com/api-client-library/javascript/reference/referencedocs#gapiauth2getauthinstance
10
- */
11
- export const loadSocial = (appId: string): Promise<void> => new Promise((resolve, reject) => {
12
- const firstJS = document.getElementsByTagName('script')[0];
13
- const js = document.createElement('script');
14
-
15
- js.src = '//apis.google.com/js/platform.js';
16
- js.id = 'gapi-client';
17
- js.onload = () => {
18
- window.gapi.load('auth2', () => {
19
- if (!window.gapi.auth2.getAuthInstance()) {
20
- window.gapi.auth2.init({
21
- client_id: appId,
22
- fetchBasicProfile: true,
23
- scope: null
24
- }).then(() => resolve(), (err: any) => reject({
25
- provider: 'google',
26
- type: 'load',
27
- description: 'Failed to load SDK',
28
- error: err
29
- }));
30
- } else resolve();
31
- });
32
- };
33
-
34
- if (!firstJS?.parentNode) document.appendChild(js);
35
- else firstJS.parentNode.appendChild(js);
36
- });
37
-
38
- /**
39
- * Checks if user is logged in to app through Google.
40
- * Requires SDK to be loaded first.
41
- * @see https://developers.google.com/api-client-library/javascript/reference/referencedocs#gapiauth2getauthinstance
42
- * @see https://developers.google.com/api-client-library/javascript/reference/referencedocs#googleauthissignedinget
43
- * @see https://developers.google.com/api-client-library/javascript/reference/referencedocs#googleauthcurrentuserget
44
- */
45
- export const checkLogin = () => new Promise((resolve, reject) => {
46
- const GoogleAuth = window.gapi.auth2.getAuthInstance();
47
-
48
- if (!GoogleAuth.isSignedIn.get()) {
49
- return reject({
50
- provider: 'google',
51
- type: 'check_login',
52
- description: 'Not authenticated',
53
- error: null
54
- });
55
- }
56
-
57
- return resolve(GoogleAuth.currentUser.get());
58
- });
59
-
60
- /**
61
- * Trigger Google login process.
62
- * Requires SDK to be loaded first.
63
- * @see https://developers.google.com/api-client-library/javascript/reference/referencedocs#gapiauth2getauthinstance
64
- * @see https://developers.google.com/api-client-library/javascript/reference/referencedocs#googleauthsignin
65
- */
66
- export const login = () => new Promise((resolve, reject) => {
67
- const GoogleAuth = window.gapi.auth2.getAuthInstance();
68
-
69
- GoogleAuth.signIn().then(
70
- () => checkLogin().then(resolve, reject),
71
- (err: any) => reject({
72
- provider: 'google',
73
- type: 'auth',
74
- description: 'Authentication failed',
75
- error: err
76
- })
77
- );
78
- });
79
-
80
- /**
81
- * Trigger Google logout.
82
- * Requires SDK to be loaded first.
83
- * @see https://developers.google.com/api-client-library/javascript/reference/referencedocs#googleauthsignout
84
- */
85
- export const googleLogout = () => new Promise((resolve, reject) => {
86
- const GoogleAuth = window.gapi.auth2.getAuthInstance();
87
- GoogleAuth.signOut().then(resolve, reject);
88
- })