@movalib/movalib-commons 1.36.0 → 1.37.0
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/devIndex.tsx +14 -12
- package/dist/devIndex.js +1 -1
- package/dist/src/QRCode.d.ts +1 -0
- package/dist/src/QRCode.js +105 -46
- package/package.json +2 -1
- package/src/QRCode.tsx +116 -86
package/devIndex.tsx
CHANGED
|
@@ -79,7 +79,7 @@ const App = () => {
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
const handleScheduleChange = (schedule: DaySchedule[]) => {
|
|
82
|
-
|
|
82
|
+
|
|
83
83
|
if(schedule){
|
|
84
84
|
// On contrôle l'absence d'erreur dans le tableau de schedule
|
|
85
85
|
const hasErrors = schedule.some(day => day.intervals.some(interval => interval.error !== null));
|
|
@@ -88,9 +88,9 @@ const App = () => {
|
|
|
88
88
|
// On crée un objet Schedule sur la base du DaySchedule reçu de ScheduleFields
|
|
89
89
|
let newSchedule = new Array<Schedule>();
|
|
90
90
|
|
|
91
|
-
schedule.forEach(s => {
|
|
91
|
+
schedule.forEach(s => {
|
|
92
92
|
newSchedule.push(new Schedule(
|
|
93
|
-
s.day,
|
|
93
|
+
s.day,
|
|
94
94
|
s.intervals.map(({ startTime, endTime, countryCode }) => ({ startTime, endTime, countryCode })),
|
|
95
95
|
true
|
|
96
96
|
));
|
|
@@ -117,17 +117,17 @@ const App = () => {
|
|
|
117
117
|
} } form={{
|
|
118
118
|
gender: undefined
|
|
119
119
|
}} />
|
|
120
|
-
|
|
120
|
+
|
|
121
121
|
<Container style={flexCenter} sx={{ width: '400px', mt: 2}}>
|
|
122
122
|
<VehiclePlateField onValidVehiclePlate={function (vehiclePlate: string): void {
|
|
123
123
|
alert('plaque valide');
|
|
124
124
|
} } />
|
|
125
125
|
</Container>
|
|
126
|
-
|
|
127
126
|
|
|
128
|
-
|
|
127
|
+
|
|
128
|
+
<MovaLogin
|
|
129
129
|
darkMode={false}
|
|
130
|
-
movaAppType={MovaAppType.INDIVIDUAL}
|
|
130
|
+
movaAppType={MovaAppType.INDIVIDUAL}
|
|
131
131
|
version="0.1.3"
|
|
132
132
|
onSubmit={function (form: MovaLoginForm): void {
|
|
133
133
|
alert('Form Submitted !');
|
|
@@ -135,7 +135,7 @@ const App = () => {
|
|
|
135
135
|
throw new Error('Function not implemented.');
|
|
136
136
|
} } />
|
|
137
137
|
|
|
138
|
-
<MovaSignUp
|
|
138
|
+
<MovaSignUp
|
|
139
139
|
headerText={<><Alert severity='success' icon={<></>} style={flexCenter} sx={{width:'100%', textTransform: 'none', textAlign: 'center'}}>
|
|
140
140
|
<b>NOUVEAU COMPTE UTILISATEUR</b></Alert></>}
|
|
141
141
|
darkMode={false}
|
|
@@ -145,17 +145,19 @@ const App = () => {
|
|
|
145
145
|
|
|
146
146
|
<GaragePLV url={getQRCodeData()} />
|
|
147
147
|
|
|
148
|
-
<
|
|
148
|
+
<div id='qr-code-container'>
|
|
149
|
+
<QRCode data={getQRCodeData()} size={400} showDownload showCTAWhenDownloaded />
|
|
150
|
+
</div>
|
|
149
151
|
|
|
150
152
|
<div style={{ marginTop: '40px' }} />
|
|
151
153
|
|
|
152
154
|
<div style={flexCenter}>
|
|
153
|
-
<ScheduleFields
|
|
155
|
+
<ScheduleFields
|
|
154
156
|
//schedules={undefined}
|
|
155
157
|
schedules={garage?.schedules}
|
|
156
158
|
size="small"
|
|
157
|
-
timePickerStep={15}
|
|
158
|
-
onChange={handleScheduleChange}
|
|
159
|
+
timePickerStep={15}
|
|
160
|
+
onChange={handleScheduleChange}
|
|
159
161
|
/>
|
|
160
162
|
</div>
|
|
161
163
|
|
package/dist/devIndex.js
CHANGED
|
@@ -136,7 +136,7 @@ var App = function () {
|
|
|
136
136
|
throw new Error('Function not implemented.');
|
|
137
137
|
} }), (0, jsx_runtime_1.jsx)(MovaSignUp_1.default, { headerText: (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(material_1.Alert, __assign({ severity: 'success', icon: (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {}), style: Tools_1.flexCenter, sx: { width: '100%', textTransform: 'none', textAlign: 'center' } }, { children: (0, jsx_runtime_1.jsx)("b", { children: "NOUVEAU COMPTE UTILISATEUR" }) })) }), darkMode: false, movaAppType: Enums_1.MovaAppType.INDIVIDUAL, onSubmit: function (form) {
|
|
138
138
|
alert('Form Submitted !');
|
|
139
|
-
} }), (0, jsx_runtime_1.jsx)(GaragePLV_1.default, { url: getQRCodeData() }), (0, jsx_runtime_1.jsx)(QRCode_1.default, { data: getQRCodeData(), showDownload: true,
|
|
139
|
+
} }), (0, jsx_runtime_1.jsx)(GaragePLV_1.default, { url: getQRCodeData() }), (0, jsx_runtime_1.jsx)("div", __assign({ id: 'qr-code-container' }, { children: (0, jsx_runtime_1.jsx)(QRCode_1.default, { data: getQRCodeData(), size: 400, showDownload: true, showCTAWhenDownloaded: true }) })), (0, jsx_runtime_1.jsx)("div", { style: { marginTop: '40px' } }), (0, jsx_runtime_1.jsx)("div", __assign({ style: Tools_1.flexCenter }, { children: (0, jsx_runtime_1.jsx)(ScheduleFields_1.default
|
|
140
140
|
//schedules={undefined}
|
|
141
141
|
, {
|
|
142
142
|
//schedules={undefined}
|
package/dist/src/QRCode.d.ts
CHANGED
package/dist/src/QRCode.js
CHANGED
|
@@ -10,6 +10,42 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
};
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
13
49
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
50
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
51
|
};
|
|
@@ -20,14 +56,15 @@ var leaf_yellow_small_png_1 = __importDefault(require("./assets/images/leaf_yell
|
|
|
20
56
|
var material_1 = require("@mui/material");
|
|
21
57
|
var qr_code_styling_1 = __importDefault(require("qr-code-styling"));
|
|
22
58
|
require("./QRCode.css");
|
|
59
|
+
var html2canvas_1 = __importDefault(require("html2canvas"));
|
|
23
60
|
var QRCode = function (_a) {
|
|
24
|
-
var _b = _a.size, size = _b === void 0 ? 300 : _b, data = _a.data, _c = _a.showDownload, showDownload = _c === void 0 ? false : _c;
|
|
61
|
+
var _b = _a.size, size = _b === void 0 ? 300 : _b, data = _a.data, _c = _a.showDownload, showDownload = _c === void 0 ? false : _c, _d = _a.showCTAWhenDownloaded, showCTAWhenDownloaded = _d === void 0 ? false : _d;
|
|
25
62
|
var theme = (0, material_1.useTheme)();
|
|
26
63
|
// Le contenu du QR Code est transmis en props, sinon redirection vers le site vitrine
|
|
27
64
|
var defaultData = 'https://movalib.com';
|
|
28
|
-
var
|
|
29
|
-
width: size
|
|
30
|
-
height: size
|
|
65
|
+
var options = (0, react_1.useMemo)(function () { return ({
|
|
66
|
+
width: size,
|
|
67
|
+
height: size,
|
|
31
68
|
type: 'canvas',
|
|
32
69
|
data: data !== null && data !== void 0 ? data : defaultData,
|
|
33
70
|
image: leaf_yellow_small_png_1.default,
|
|
@@ -43,70 +80,92 @@ var QRCode = function (_a) {
|
|
|
43
80
|
margin: 15
|
|
44
81
|
},
|
|
45
82
|
dotsOptions: {
|
|
46
|
-
//color: 'black',
|
|
47
83
|
color: (0, material_1.darken)(theme.palette.primary.main, 0.4),
|
|
48
|
-
|
|
49
|
-
// type: 'linear', // 'radial'
|
|
50
|
-
// rotation: 0,
|
|
51
|
-
// colorStops: [{ offset: 0, color: theme.palette.primary.main }, { offset: 1, color: theme.palette.secondary.main }]
|
|
52
|
-
// },
|
|
53
|
-
type: 'square' // "dots" | "rounded" | "classy" | "classy-rounded" | "square" | "extra-rounded";
|
|
84
|
+
type: 'square'
|
|
54
85
|
},
|
|
55
86
|
backgroundOptions: {
|
|
56
87
|
color: 'white',
|
|
57
|
-
// gradient: {
|
|
58
|
-
// type: 'linear', // 'radial'
|
|
59
|
-
// rotation: 0,
|
|
60
|
-
// colorStops: [{ offset: 0, color: '#ededff' }, { offset: 1, color: '#e6e7ff' }]
|
|
61
|
-
// },
|
|
62
88
|
},
|
|
63
89
|
cornersSquareOptions: {
|
|
64
|
-
//color: '#de007dff',
|
|
65
90
|
color: (0, material_1.darken)(theme.palette.secondary.main, 0.2),
|
|
66
91
|
type: 'square',
|
|
67
|
-
// gradient: {
|
|
68
|
-
// type: 'linear', // 'radial'
|
|
69
|
-
// rotation: 180,
|
|
70
|
-
// colorStops: [{ offset: 0, color: '#25456e' }, { offset: 1, color: '#4267b2' }]
|
|
71
|
-
// },
|
|
72
92
|
},
|
|
73
93
|
cornersDotOptions: {
|
|
74
|
-
//color: '#de007dff',
|
|
75
94
|
color: (0, material_1.darken)(theme.palette.secondary.main, 0.2),
|
|
76
95
|
type: 'square',
|
|
77
|
-
// gradient: {
|
|
78
|
-
// type: 'linear', // 'radial'
|
|
79
|
-
// rotation: 180,
|
|
80
|
-
// colorStops: [{ offset: 0, color: '#00266e' }, { offset: 1, color: '#4060b3' }]
|
|
81
|
-
// },
|
|
82
96
|
}
|
|
83
|
-
}),
|
|
84
|
-
|
|
85
|
-
var _e = (0, react_1.useState)("png"), fileExt = _e[0], setFileExt = _e[1];
|
|
86
|
-
var qrCode = (0, react_1.useState)(new qr_code_styling_1.default(options))[0];
|
|
97
|
+
}); }, [size, data]);
|
|
98
|
+
var qrCode = (0, react_1.useMemo)(function () { return new qr_code_styling_1.default(options); }, [options]);
|
|
87
99
|
var ref = (0, react_1.useRef)(null);
|
|
88
100
|
(0, react_1.useEffect)(function () {
|
|
89
101
|
if (ref.current) {
|
|
90
102
|
qrCode.append(ref.current);
|
|
91
103
|
}
|
|
92
104
|
}, [qrCode, ref]);
|
|
93
|
-
(0,
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
105
|
+
var onDownloadClick = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
106
|
+
return __generator(this, function (_a) {
|
|
107
|
+
if (!qrCode)
|
|
108
|
+
return [2 /*return*/];
|
|
109
|
+
if (!showCTAWhenDownloaded) {
|
|
110
|
+
qrCode.download({
|
|
111
|
+
extension: "png",
|
|
112
|
+
name: "movalib-qr-code"
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
downloadQrCodeWithCTA();
|
|
117
|
+
}
|
|
118
|
+
return [2 /*return*/];
|
|
119
|
+
});
|
|
120
|
+
}); };
|
|
121
|
+
var downloadQrCodeWithCTA = function () {
|
|
122
|
+
// Check if we have everything we need
|
|
123
|
+
var qrCodeContainer = document.querySelector('#qr-code-container');
|
|
124
|
+
var qrCodeDiv = qrCodeContainer === null || qrCodeContainer === void 0 ? void 0 : qrCodeContainer.querySelector('.qr-code');
|
|
125
|
+
var qrCodeCanva = qrCodeDiv === null || qrCodeDiv === void 0 ? void 0 : qrCodeDiv.querySelector('canvas');
|
|
126
|
+
// If we don't have the QR Code, we can't download it
|
|
127
|
+
if (!qrCodeContainer || !qrCodeDiv || !qrCodeCanva) {
|
|
103
128
|
return;
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
129
|
+
}
|
|
130
|
+
var tmpRendered = document.createElement('div');
|
|
131
|
+
tmpRendered.style.width = 'fit-content';
|
|
132
|
+
tmpRendered.style.display = 'flex';
|
|
133
|
+
tmpRendered.style.justifyContent = 'center';
|
|
134
|
+
tmpRendered.style.flexDirection = 'column';
|
|
135
|
+
tmpRendered.style.alignItems = 'center';
|
|
136
|
+
tmpRendered.style.gap = '8px';
|
|
137
|
+
tmpRendered.style.background = 'transparent';
|
|
138
|
+
var catchPhrase = document.createElement('span');
|
|
139
|
+
catchPhrase.innerText = 'PRENEZ RENDEZ-VOUS EN LIGNE !';
|
|
140
|
+
catchPhrase.style.color = (0, material_1.darken)(theme.palette.primary.main, 0.4);
|
|
141
|
+
catchPhrase.style.fontWeight = '900';
|
|
142
|
+
catchPhrase.style.padding = '8px';
|
|
143
|
+
catchPhrase.style.fontFamily = 'Caveat';
|
|
144
|
+
catchPhrase.style.fontSize = '2em';
|
|
145
|
+
var scanThis = document.createElement('span');
|
|
146
|
+
scanThis.innerText = 'SCANNEZ CE QR CODE';
|
|
147
|
+
scanThis.style.color = (0, material_1.darken)(theme.palette.primary.main, 0.4);
|
|
148
|
+
scanThis.style.fontWeight = '900';
|
|
149
|
+
scanThis.style.marginBottom = '8px';
|
|
150
|
+
scanThis.style.fontSize = '1.5em';
|
|
151
|
+
tmpRendered.append(catchPhrase);
|
|
152
|
+
tmpRendered.append(qrCodeCanva);
|
|
153
|
+
tmpRendered.append(scanThis);
|
|
154
|
+
// add it to the document to be able to download it
|
|
155
|
+
document.body.append(tmpRendered);
|
|
156
|
+
// create the canva of the tmpRendered div and download it
|
|
157
|
+
(0, html2canvas_1.default)(tmpRendered).then(function (canvas) {
|
|
158
|
+
var a = document.createElement("a");
|
|
159
|
+
a.download = "movalib-qr-code.png";
|
|
160
|
+
a.href = canvas.toDataURL("image/png");
|
|
161
|
+
a.click();
|
|
107
162
|
});
|
|
163
|
+
// remove the tmpRendered div
|
|
164
|
+
tmpRendered.remove();
|
|
165
|
+
// re-append the QR Code to the initial container
|
|
166
|
+
qrCode.append(ref.current);
|
|
108
167
|
};
|
|
109
|
-
return ((0, jsx_runtime_1.jsxs)(
|
|
168
|
+
return ((0, jsx_runtime_1.jsxs)("div", __assign({ style: {
|
|
110
169
|
display: 'flex',
|
|
111
170
|
flexDirection: 'column',
|
|
112
171
|
alignItems: 'center'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@movalib/movalib-commons",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.37.0",
|
|
4
4
|
"description": "Bibliothèque d'objets communs à l'ensemble des projets React de Movalib",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"date-fns": "^2.29.3",
|
|
29
29
|
"date-fns-tz": "^2.0.0",
|
|
30
30
|
"file-loader": "^6.2.0",
|
|
31
|
+
"html2canvas": "^1.4.1",
|
|
31
32
|
"js-cookie": "^3.0.5",
|
|
32
33
|
"qr-code-styling": "^1.4.4",
|
|
33
34
|
"react": "^18.2.0",
|
package/src/QRCode.tsx
CHANGED
|
@@ -1,45 +1,40 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type FC, useRef, useEffect, useMemo } from 'react';
|
|
2
2
|
import QRCodeImage from "./assets/images/leaf_yellow_small.png";
|
|
3
3
|
import { Box, Button, darken, useTheme } from '@mui/material';
|
|
4
|
-
import QRCodeStyling, {
|
|
5
|
-
DrawType,
|
|
6
|
-
TypeNumber,
|
|
7
|
-
Mode,
|
|
8
|
-
ErrorCorrectionLevel,
|
|
9
|
-
DotType,
|
|
10
|
-
CornerSquareType,
|
|
11
|
-
CornerDotType,
|
|
12
|
-
Extension,
|
|
13
|
-
Options
|
|
14
|
-
} from "qr-code-styling";
|
|
4
|
+
import QRCodeStyling, { Options } from "qr-code-styling";
|
|
15
5
|
import './QRCode.css';
|
|
16
|
-
import
|
|
17
|
-
|
|
6
|
+
import html2canvas from "html2canvas";
|
|
18
7
|
|
|
19
8
|
interface QRCodeProps {
|
|
20
|
-
size?: number
|
|
21
|
-
data?:string
|
|
22
|
-
showDownload?:boolean
|
|
9
|
+
size?: number;
|
|
10
|
+
data?:string;
|
|
11
|
+
showDownload?: boolean;
|
|
12
|
+
showCTAWhenDownloaded?: boolean;
|
|
23
13
|
}
|
|
24
|
-
|
|
25
|
-
const QRCode: FC<QRCodeProps> = ({
|
|
14
|
+
|
|
15
|
+
const QRCode: FC<QRCodeProps> = ({
|
|
16
|
+
size = 300,
|
|
17
|
+
data,
|
|
18
|
+
showDownload= false,
|
|
19
|
+
showCTAWhenDownloaded= false,
|
|
20
|
+
}) => {
|
|
26
21
|
|
|
27
22
|
const theme = useTheme();
|
|
28
|
-
|
|
23
|
+
|
|
29
24
|
// Le contenu du QR Code est transmis en props, sinon redirection vers le site vitrine
|
|
30
|
-
const defaultData
|
|
25
|
+
const defaultData = 'https://movalib.com';
|
|
31
26
|
|
|
32
|
-
const
|
|
33
|
-
width: size
|
|
34
|
-
height: size
|
|
35
|
-
type: 'canvas'
|
|
27
|
+
const options: Options = useMemo(() => ({
|
|
28
|
+
width: size,
|
|
29
|
+
height: size,
|
|
30
|
+
type: 'canvas',
|
|
36
31
|
data: data ?? defaultData,
|
|
37
32
|
image: QRCodeImage,
|
|
38
33
|
margin: 10,
|
|
39
34
|
qrOptions: {
|
|
40
|
-
typeNumber: 0
|
|
41
|
-
mode: 'Byte'
|
|
42
|
-
errorCorrectionLevel: 'Q'
|
|
35
|
+
typeNumber: 0,
|
|
36
|
+
mode: 'Byte',
|
|
37
|
+
errorCorrectionLevel: 'Q'
|
|
43
38
|
},
|
|
44
39
|
imageOptions: {
|
|
45
40
|
hideBackgroundDots: true,
|
|
@@ -47,48 +42,23 @@ const QRCode: FC<QRCodeProps> = ({ size = 300, data, showDownload=false }) => {
|
|
|
47
42
|
margin: 15
|
|
48
43
|
},
|
|
49
44
|
dotsOptions: {
|
|
50
|
-
//color: 'black',
|
|
51
45
|
color: darken(theme.palette.primary.main, 0.4),
|
|
52
|
-
|
|
53
|
-
// type: 'linear', // 'radial'
|
|
54
|
-
// rotation: 0,
|
|
55
|
-
// colorStops: [{ offset: 0, color: theme.palette.primary.main }, { offset: 1, color: theme.palette.secondary.main }]
|
|
56
|
-
// },
|
|
57
|
-
type: 'square' as DotType // "dots" | "rounded" | "classy" | "classy-rounded" | "square" | "extra-rounded";
|
|
46
|
+
type: 'square'
|
|
58
47
|
},
|
|
59
48
|
backgroundOptions: {
|
|
60
49
|
color: 'white',
|
|
61
|
-
// gradient: {
|
|
62
|
-
// type: 'linear', // 'radial'
|
|
63
|
-
// rotation: 0,
|
|
64
|
-
// colorStops: [{ offset: 0, color: '#ededff' }, { offset: 1, color: '#e6e7ff' }]
|
|
65
|
-
// },
|
|
66
50
|
},
|
|
67
51
|
cornersSquareOptions: {
|
|
68
|
-
//color: '#de007dff',
|
|
69
52
|
color: darken(theme.palette.secondary.main, 0.2),
|
|
70
|
-
type: 'square'
|
|
71
|
-
// gradient: {
|
|
72
|
-
// type: 'linear', // 'radial'
|
|
73
|
-
// rotation: 180,
|
|
74
|
-
// colorStops: [{ offset: 0, color: '#25456e' }, { offset: 1, color: '#4267b2' }]
|
|
75
|
-
// },
|
|
53
|
+
type: 'square',
|
|
76
54
|
},
|
|
77
55
|
cornersDotOptions: {
|
|
78
|
-
//color: '#de007dff',
|
|
79
56
|
color: darken(theme.palette.secondary.main, 0.2),
|
|
80
|
-
type: 'square'
|
|
81
|
-
// gradient: {
|
|
82
|
-
// type: 'linear', // 'radial'
|
|
83
|
-
// rotation: 180,
|
|
84
|
-
// colorStops: [{ offset: 0, color: '#00266e' }, { offset: 1, color: '#4060b3' }]
|
|
85
|
-
// },
|
|
57
|
+
type: 'square',
|
|
86
58
|
}
|
|
87
|
-
});
|
|
59
|
+
}), [size, data]);
|
|
88
60
|
|
|
89
|
-
|
|
90
|
-
const [fileExt, setFileExt] = useState<Extension>("png");
|
|
91
|
-
const [qrCode] = useState<QRCodeStyling>(new QRCodeStyling(options));
|
|
61
|
+
const qrCode = useMemo(() => new QRCodeStyling(options), [options]);
|
|
92
62
|
const ref = useRef<HTMLDivElement>(null);
|
|
93
63
|
|
|
94
64
|
useEffect(() => {
|
|
@@ -97,45 +67,105 @@ const QRCode: FC<QRCodeProps> = ({ size = 300, data, showDownload=false }) => {
|
|
|
97
67
|
}
|
|
98
68
|
}, [qrCode, ref]);
|
|
99
69
|
|
|
100
|
-
|
|
70
|
+
const onDownloadClick = async () => {
|
|
101
71
|
if (!qrCode) return;
|
|
102
|
-
qrCode.update(options);
|
|
103
|
-
}, [qrCode, options]);
|
|
104
72
|
|
|
73
|
+
if(!showCTAWhenDownloaded) {
|
|
74
|
+
qrCode.download({
|
|
75
|
+
extension: "png",
|
|
76
|
+
name:"movalib-qr-code"
|
|
77
|
+
});
|
|
78
|
+
} else {
|
|
79
|
+
downloadQrCodeWithCTA();
|
|
80
|
+
}
|
|
81
|
+
};
|
|
105
82
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
83
|
+
const downloadQrCodeWithCTA = () => {
|
|
84
|
+
// Check if we have everything we need
|
|
85
|
+
const qrCodeContainer = document.querySelector<HTMLElement>('#qr-code-container');
|
|
86
|
+
const qrCodeDiv = qrCodeContainer?.querySelector<HTMLElement>('.qr-code');
|
|
87
|
+
const qrCodeCanva = qrCodeDiv?.querySelector('canvas');
|
|
109
88
|
|
|
110
|
-
|
|
111
|
-
if (!
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
89
|
+
// If we don't have the QR Code, we can't download it
|
|
90
|
+
if (!qrCodeContainer || !qrCodeDiv || !qrCodeCanva) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const tmpRendered = document.createElement('div');
|
|
95
|
+
|
|
96
|
+
tmpRendered.style.width = 'fit-content';
|
|
97
|
+
tmpRendered.style.display = 'flex';
|
|
98
|
+
tmpRendered.style.justifyContent = 'center';
|
|
99
|
+
tmpRendered.style.flexDirection = 'column';
|
|
100
|
+
tmpRendered.style.alignItems = 'center';
|
|
101
|
+
tmpRendered.style.gap = '8px';
|
|
102
|
+
tmpRendered.style.background= 'transparent';
|
|
103
|
+
|
|
104
|
+
const catchPhrase = document.createElement('span');
|
|
105
|
+
catchPhrase.innerText = 'PRENEZ RENDEZ-VOUS EN LIGNE !';
|
|
106
|
+
catchPhrase.style.color = darken(theme.palette.primary.main, 0.4);
|
|
107
|
+
catchPhrase.style.fontWeight = '900';
|
|
108
|
+
catchPhrase.style.padding = '8px';
|
|
109
|
+
catchPhrase.style.fontFamily= 'Caveat';
|
|
110
|
+
catchPhrase.style.fontSize= '2em';
|
|
111
|
+
|
|
112
|
+
const scanThis = document.createElement('span');
|
|
113
|
+
|
|
114
|
+
scanThis.innerText = 'SCANNEZ CE QR CODE';
|
|
115
|
+
scanThis.style.color = darken(theme.palette.primary.main, 0.4);
|
|
116
|
+
scanThis.style.fontWeight = '900';
|
|
117
|
+
scanThis.style.marginBottom = '8px';
|
|
118
|
+
scanThis.style.fontSize= '1.5em';
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
tmpRendered.append(catchPhrase);
|
|
122
|
+
tmpRendered.append(qrCodeCanva);
|
|
123
|
+
tmpRendered.append(scanThis);
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
// add it to the document to be able to download it
|
|
127
|
+
document.body.append(tmpRendered);
|
|
128
|
+
|
|
129
|
+
// create the canva of the tmpRendered div and download it
|
|
130
|
+
html2canvas(tmpRendered).then(canvas => {
|
|
131
|
+
let a = document.createElement("a");
|
|
132
|
+
a.download = "movalib-qr-code.png";
|
|
133
|
+
a.href = canvas.toDataURL("image/png");
|
|
134
|
+
a.click();
|
|
115
135
|
});
|
|
116
|
-
|
|
136
|
+
|
|
137
|
+
// remove the tmpRendered div
|
|
138
|
+
tmpRendered.remove();
|
|
139
|
+
|
|
140
|
+
// re-append the QR Code to the initial container
|
|
141
|
+
qrCode.append(ref.current!);
|
|
142
|
+
}
|
|
117
143
|
|
|
118
144
|
return (
|
|
119
|
-
<
|
|
145
|
+
<div
|
|
146
|
+
style={{
|
|
120
147
|
display: 'flex',
|
|
121
148
|
flexDirection: 'column',
|
|
122
|
-
alignItems: 'center'
|
|
123
|
-
|
|
149
|
+
alignItems: 'center'
|
|
150
|
+
}}
|
|
151
|
+
>
|
|
152
|
+
<div
|
|
153
|
+
ref={ref}
|
|
154
|
+
style={{height: `${size}px`, width: `${size}px`, maxWidth: `${size}px !important`}}
|
|
124
155
|
className='qr-code'
|
|
125
156
|
/>
|
|
126
|
-
{
|
|
127
|
-
|
|
128
|
-
<
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
</Box>
|
|
157
|
+
{showDownload &&
|
|
158
|
+
<Box sx={{ display:'flex', justifyContent:'center'}}>
|
|
159
|
+
<Button
|
|
160
|
+
variant='outlined'
|
|
161
|
+
onClick={onDownloadClick}
|
|
162
|
+
sx={{ color: darken(theme.palette.primary.main, 0.2)}}
|
|
163
|
+
>
|
|
164
|
+
Télécharger
|
|
165
|
+
</Button>
|
|
166
|
+
</Box>
|
|
167
|
+
}
|
|
168
|
+
</div>
|
|
139
169
|
);
|
|
140
170
|
}
|
|
141
171
|
|