@micromag/consent 0.3.705 → 0.3.706

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.
@@ -1,5 +1,5 @@
1
1
  .micromag-consent-buttons-close-container{-webkit-appearance:none;-moz-appearance:none;appearance:none;background:transparent;border:0;color:inherit;cursor:pointer;display:inline-block;font-family:inherit;padding:0;position:relative}
2
- .micromag-consent-buttons-pill-container{-webkit-appearance:none;-moz-appearance:none;appearance:none;background:transparent;border:0;border:1px solid #fff;color:inherit;cursor:pointer;display:inline-block;font-family:inherit;padding:0;padding:6px 10px;position:relative}.micromag-consent-buttons-pill-container:active,.micromag-consent-buttons-pill-container:hover{background-color:#0b57d0;background-color:var(--color-primary,#0b57d0);color:#fff}
3
- .micromag-consent-fields-checkbox-container{display:-ms-flexbox;display:flex;-ms-flex-direction:row;flex-direction:row;-ms-flex-align:start;align-items:flex-start;line-height:1.2}.micromag-consent-fields-checkbox-container .micromag-consent-fields-checkbox-check{margin-right:6px}.micromag-consent-fields-checkbox-container .micromag-consent-fields-checkbox-input{accent-color:#0b57d0;accent-color:var(--color-primary,#0b57d0);cursor:pointer;display:block;height:1rem;margin:0 0 5px;width:1rem}.micromag-consent-fields-checkbox-container .micromag-consent-fields-checkbox-label{-ms-flex-positive:1;cursor:pointer;flex-grow:1;font-weight:800}.micromag-consent-fields-checkbox-container:active .micromag-consent-fields-checkbox-label,.micromag-consent-fields-checkbox-container:hover .micromag-consent-fields-checkbox-label{-webkit-text-decoration:underline;text-decoration:underline}
4
- .micromag-consent-forms-cookies-container{max-height:calc(100vh - 20px);overflow-y:scroll;padding:15px;position:relative}.micromag-consent-forms-cookies-container .micromag-consent-forms-cookies-description,.micromag-consent-forms-cookies-container .micromag-consent-forms-cookies-title{margin-bottom:1rem}.micromag-consent-forms-cookies-container .micromag-consent-forms-cookies-button{border-radius:10px;font-weight:700;margin:0 5px 5px 0}
2
+ .micromag-consent-buttons-pill-container{-webkit-appearance:none;-moz-appearance:none;appearance:none;background:transparent;border:0;border:1px solid #fff;color:inherit;cursor:pointer;display:inline-block;font-family:inherit;line-height:1.2;padding:0;padding:8px 12px;position:relative}.micromag-consent-buttons-pill-container:active,.micromag-consent-buttons-pill-container:hover{background-color:#0b57d0;background-color:var(--color-primary,#0b57d0);color:#fff}
3
+ .micromag-consent-fields-checkbox-container{display:-ms-flexbox;display:flex;-ms-flex-direction:row;flex-direction:row;-ms-flex-align:start;align-items:flex-start;line-height:1.2}.micromag-consent-fields-checkbox-container .micromag-consent-fields-checkbox-check{margin-right:6px}.micromag-consent-fields-checkbox-container .micromag-consent-fields-checkbox-input{accent-color:#0b57d0;accent-color:var(--color-primary,#0b57d0);cursor:pointer;display:block;height:1rem;margin:0 0 5px;width:1rem}.micromag-consent-fields-checkbox-container .micromag-consent-fields-checkbox-label{-ms-flex-positive:1;cursor:pointer;flex-grow:1;font-weight:700;line-height:1}.micromag-consent-fields-checkbox-container:active .micromag-consent-fields-checkbox-label,.micromag-consent-fields-checkbox-container:hover .micromag-consent-fields-checkbox-label{-webkit-text-decoration:underline;text-decoration:underline}
4
+ .micromag-consent-forms-cookies-container{max-height:calc(100vh - 20px);overflow-y:scroll;padding:15px;position:relative}.micromag-consent-forms-cookies-container .micromag-consent-forms-cookies-description,.micromag-consent-forms-cookies-container .micromag-consent-forms-cookies-label,.micromag-consent-forms-cookies-container .micromag-consent-forms-cookies-title{margin-bottom:1rem}.micromag-consent-forms-cookies-container .micromag-consent-forms-cookies-button{border-radius:10px;font-weight:700;margin:0 5px 5px 0}
5
5
  .micromag-consent-container{background-color:#000;background-color:var(--color-background,#000);border-radius:10px;color:#fff;color:var(--color-text,#fff);max-width:800px;position:relative}.micromag-consent-container .micromag-consent-close{color:#fff;color:var(--color-primary,#fff);cursor:pointer;font-size:1.5rem;position:absolute;right:15px;top:10px;z-index:10}
package/es/index.js CHANGED
@@ -1,17 +1,17 @@
1
1
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
2
  import classNames from 'classnames';
3
3
  import PropTypes from 'prop-types';
4
- import React, { useMemo, useState, useCallback, useRef, useInsertionEffect } from 'react';
4
+ import React, { useCallback, useRef, useInsertionEffect, useState } from 'react';
5
5
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
6
6
  import { faTimes } from '@fortawesome/free-solid-svg-icons/faTimes';
7
7
  import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
8
8
  import { Button } from '@micromag/core/components';
9
9
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
10
10
  import isString from 'lodash/isString';
11
- import { defineMessages, FormattedMessage } from 'react-intl';
12
- import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
11
+ import { FormattedMessage } from 'react-intl';
13
12
  import _objectSpread from '@babel/runtime/helpers/objectSpread2';
14
- import JSCookie from 'js-cookie';
13
+ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
14
+ import { useConsent } from '@micromag/core/contexts';
15
15
 
16
16
  var styles$4 = {"container":"micromag-consent-buttons-close-container"};
17
17
 
@@ -38,147 +38,8 @@ var CloseButton = function CloseButton(_ref) {
38
38
  CloseButton.propTypes = propTypes$5;
39
39
  CloseButton.defaultProps = defaultProps$5;
40
40
 
41
- var messages = defineMessages({
42
- functionality_title: {
43
- id: "consent.functionality_title",
44
- defaultMessage: [{
45
- "type": 0,
46
- "value": "Functionnal"
47
- }]
48
- },
49
- functionality_description: {
50
- id: "consent.functionality_description",
51
- defaultMessage: [{
52
- "type": 0,
53
- "value": "Cookies required for the site to function properly."
54
- }]
55
- },
56
- analytics_title: {
57
- id: "consent.analytics_title",
58
- defaultMessage: [{
59
- "type": 0,
60
- "value": "Analytics"
61
- }]
62
- },
63
- analytics_description: {
64
- id: "consent.analytics_description",
65
- defaultMessage: [{
66
- "type": 0,
67
- "value": "Cookies used to measure user behavior."
68
- }]
69
- },
70
- ad_storage_title: {
71
- id: "consent.ad_storage_title",
72
- defaultMessage: [{
73
- "type": 0,
74
- "value": "Ad Storage"
75
- }]
76
- },
77
- ad_storage_description: {
78
- id: "consent.ad_storage_description",
79
- defaultMessage: [{
80
- "type": 0,
81
- "value": "Cookies used for advertising purposes."
82
- }]
83
- },
84
- ad_personalization_title: {
85
- id: "consent.ad_personalization_title",
86
- defaultMessage: [{
87
- "type": 0,
88
- "value": "Ad Personalization"
89
- }]
90
- },
91
- ad_personalization_description: {
92
- id: "consent.ad_personalization_description",
93
- defaultMessage: [{
94
- "type": 0,
95
- "value": "Cookies used for ad targeting."
96
- }]
97
- },
98
- ad_user_data_title: {
99
- id: "consent.ad_user_data_title",
100
- defaultMessage: [{
101
- "type": 0,
102
- "value": "User Ad Data"
103
- }]
104
- },
105
- ad_user_data_description: {
106
- id: "consent.ad_user_data_description",
107
- defaultMessage: [{
108
- "type": 0,
109
- "value": "Cookies used for user-specific ad data."
110
- }]
111
- },
112
- personalization_storage_title: {
113
- id: "consent.personalization_storage_title",
114
- defaultMessage: [{
115
- "type": 0,
116
- "value": "Personalization Storage"
117
- }]
118
- },
119
- personalization_storage_description: {
120
- id: "consent.personalization_storage_description",
121
- defaultMessage: [{
122
- "type": 0,
123
- "value": "Cookies used for personalizing user experience."
124
- }]
125
- },
126
- security_storage_title: {
127
- id: "consent.security_storage_title",
128
- defaultMessage: [{
129
- "type": 0,
130
- "value": "Security Storage"
131
- }]
132
- },
133
- security_storage_description: {
134
- id: "consent.security_storage_description",
135
- defaultMessage: [{
136
- "type": 0,
137
- "value": "Cookies used for security purposes."
138
- }]
139
- }
140
- });
141
- var consent = [{
142
- id: 'functionality_storage',
143
- label: messages.functionality_title,
144
- description: messages.functionality_description,
145
- value: true,
146
- disabled: true
147
- }, {
148
- id: 'security_storage',
149
- label: messages.security_storage_title,
150
- description: messages.security_storage_description,
151
- value: true
152
- }, {
153
- id: 'personalization_storage',
154
- label: messages.personalization_storage_title,
155
- description: messages.personalization_storage_description,
156
- value: true
157
- }, {
158
- id: 'analytics_storage',
159
- label: messages.analytics_title,
160
- description: messages.analytics_description,
161
- value: true
162
- }, {
163
- id: 'ad_storage',
164
- label: messages.ad_storage_title,
165
- description: messages.ad_storage_description,
166
- value: true
167
- }, {
168
- id: 'ad_personalization',
169
- label: messages.ad_personalization_title,
170
- description: messages.ad_personalization_description,
171
- value: true
172
- }, {
173
- id: 'ad_user_data',
174
- label: messages.ad_user_data_title,
175
- description: messages.ad_user_data_description,
176
- value: true
177
- }];
178
- var useConsent = function useConsent(_ref) {
179
- var _ref$consent = _ref.consent,
180
- initialConsent = _ref$consent === void 0 ? null : _ref$consent,
181
- _ref$onSubmit = _ref.onSubmit,
41
+ var useConsentActions = function useConsentActions(_ref) {
42
+ var _ref$onSubmit = _ref.onSubmit,
182
43
  onSubmit = _ref$onSubmit === void 0 ? null : _ref$onSubmit,
183
44
  _ref$onChange = _ref.onChange,
184
45
  onChange = _ref$onChange === void 0 ? null : _ref$onChange,
@@ -186,33 +47,12 @@ var useConsent = function useConsent(_ref) {
186
47
  onClose = _ref$onClose === void 0 ? null : _ref$onClose,
187
48
  _ref$autoClose = _ref.autoClose,
188
49
  autoClose = _ref$autoClose === void 0 ? true : _ref$autoClose;
189
- var baseConsent = useMemo(function () {
190
- return (initialConsent || consent).map(function (item) {
191
- if (isString(item)) {
192
- return consent.find(function (it) {
193
- return it.id === item;
194
- }) || null;
195
- }
196
- return item || null;
197
- }).filter(function (it) {
198
- return it !== null;
199
- }).map(function (it) {
200
- return _objectSpread(_objectSpread({}, it), {}, {
201
- value:
202
- // eslint-disable-next-line no-nested-ternary
203
- JSCookie.get(it.id) === 'granted' ? true : JSCookie.get(it.id) === 'denied' ? false : it.value
204
- });
205
- });
206
- }, [initialConsent]);
207
- var _useState = useState(baseConsent),
208
- _useState2 = _slicedToArray(_useState, 2),
209
- choices = _useState2[0],
210
- setChoices = _useState2[1];
211
- var onSubmitForm = useCallback(function (values) {
212
- JSCookie.set('popup_cookies', false, {
213
- secure: true,
214
- expires: 182
215
- });
50
+ var _useConsent = useConsent(),
51
+ consent = _useConsent.consent,
52
+ setConsent = _useConsent.setConsent;
53
+ var onSubmitForm = useCallback(function () {
54
+ var values = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
55
+ setConsent(values);
216
56
  if (onSubmit !== null) {
217
57
  onSubmit(values || []);
218
58
  }
@@ -221,7 +61,7 @@ var useConsent = function useConsent(_ref) {
221
61
  }
222
62
  }, [onSubmit, onClose, autoClose]);
223
63
  var onClickChoice = useCallback(function (id, newValue) {
224
- var newChoices = (choices || []).reduce(function (acc, it) {
64
+ var newChoices = (consent || []).reduce(function (acc, it) {
225
65
  if (it.id === id) {
226
66
  return [].concat(_toConsumableArray(acc), [_objectSpread(_objectSpread({}, it), {}, {
227
67
  value: newValue
@@ -229,34 +69,32 @@ var useConsent = function useConsent(_ref) {
229
69
  }
230
70
  return [].concat(_toConsumableArray(acc), [it]);
231
71
  }, []);
232
- setChoices(newChoices);
72
+ setConsent(newChoices);
233
73
  if (onChange !== null) {
234
74
  onChange(newChoices || []);
235
75
  }
236
- }, [choices, setChoices]);
76
+ }, [consent, setConsent, onChange]);
237
77
  var onClickConfirm = useCallback(function () {
238
- onSubmitForm(choices);
239
- }, [choices, onSubmitForm]);
78
+ onSubmitForm(consent);
79
+ }, [consent, onSubmitForm]);
240
80
  var onClickAccept = useCallback(function () {
241
- var items = baseConsent.map(function (it) {
81
+ var items = (consent || []).map(function (it) {
242
82
  return _objectSpread(_objectSpread({}, it), {}, {
243
83
  value: !it.disabled ? true : it.value
244
84
  });
245
85
  });
246
- setChoices(items);
247
86
  onSubmitForm(items);
248
- }, [baseConsent, setChoices, onSubmitForm]);
87
+ }, [onSubmitForm]);
249
88
  var onClickDeny = useCallback(function () {
250
- var items = baseConsent.map(function (it) {
89
+ var items = (consent || []).map(function (it) {
251
90
  return _objectSpread(_objectSpread({}, it), {}, {
252
91
  value: !it.disabled ? false : it.value
253
92
  });
254
93
  });
255
- setChoices(items);
256
94
  onSubmitForm(items);
257
- }, [baseConsent, setChoices, onSubmitForm]);
95
+ }, [onSubmitForm]);
258
96
  return {
259
- choices: choices,
97
+ consent: consent,
260
98
  onClickChoice: onClickChoice,
261
99
  onClickConfirm: onClickConfirm,
262
100
  onClickAccept: onClickAccept,
@@ -449,11 +287,10 @@ var LinkPartial = function LinkPartial(_ref) {
449
287
  LinkPartial.propTypes = propTypes$2;
450
288
  LinkPartial.defaultProps = defaultProps$2;
451
289
 
452
- var styles$1 = {"container":"micromag-consent-forms-cookies-container","title":"micromag-consent-forms-cookies-title","description":"micromag-consent-forms-cookies-description","button":"micromag-consent-forms-cookies-button"};
290
+ var styles$1 = {"container":"micromag-consent-forms-cookies-container","title":"micromag-consent-forms-cookies-title","description":"micromag-consent-forms-cookies-description","label":"micromag-consent-forms-cookies-label","button":"micromag-consent-forms-cookies-button"};
453
291
 
454
- var _excluded = ["consent", "onChange", "onSubmit", "onClose", "onClickLink", "urls", "labels", "className"];
292
+ var _excluded = ["onChange", "onSubmit", "onClose", "onClickLink", "urls", "labels", "className"];
455
293
  var propTypes$1 = {
456
- consent: PropTypes.shape({}),
457
294
  urls: PropTypes.shape({
458
295
  privacy: PropTypes.string
459
296
  }),
@@ -469,7 +306,6 @@ var propTypes$1 = {
469
306
  className: PropTypes.string
470
307
  };
471
308
  var defaultProps$1 = {
472
- consent: null,
473
309
  urls: null,
474
310
  labels: null,
475
311
  onChange: null,
@@ -479,8 +315,7 @@ var defaultProps$1 = {
479
315
  className: null
480
316
  };
481
317
  var Cookies = function Cookies(_ref) {
482
- var consent = _ref.consent,
483
- onChange = _ref.onChange,
318
+ var onChange = _ref.onChange,
484
319
  onSubmit = _ref.onSubmit,
485
320
  onClose = _ref.onClose,
486
321
  onClickLink = _ref.onClickLink,
@@ -488,13 +323,12 @@ var Cookies = function Cookies(_ref) {
488
323
  labels = _ref.labels,
489
324
  className = _ref.className,
490
325
  props = _objectWithoutProperties(_ref, _excluded);
491
- var _useConsent = useConsent({
492
- consent: consent,
326
+ var _useConsent = useConsentActions({
493
327
  onChange: onChange,
494
328
  onSubmit: onSubmit,
495
329
  onClose: onClose
496
330
  }),
497
- choices = _useConsent.choices,
331
+ choices = _useConsent.consent,
498
332
  onClickChoice = _useConsent.onClickChoice,
499
333
  onClickConfirm = _useConsent.onClickConfirm,
500
334
  onClickAccept = _useConsent.onClickAccept,
@@ -550,7 +384,7 @@ var Cookies = function Cookies(_ref) {
550
384
  "type": 0,
551
385
  "value": "We use cookies to improve your experience on our site and for marketing purposes. By accepting, you consent to the use of these cookies."
552
386
  }]
553
- }))), showChoices ? choices.map(function (_ref5) {
387
+ }))), showChoices ? (choices || []).map(function (_ref5) {
554
388
  var _ref5$id = _ref5.id,
555
389
  id = _ref5$id === void 0 ? null : _ref5$id,
556
390
  _ref5$label = _ref5.label,
@@ -574,7 +408,7 @@ var Cookies = function Cookies(_ref) {
574
408
  return onClickChoice(id, !value);
575
409
  }
576
410
  })), /*#__PURE__*/React.createElement("p", {
577
- className: styles$1.itemDescription
411
+ className: styles$1.label
578
412
  }, isString(choiceDescription) ? choiceDescription : /*#__PURE__*/React.createElement(FormattedMessage, choiceDescription)));
579
413
  }) : null, privacyUrl !== null ? /*#__PURE__*/React.createElement("div", {
580
414
  className: styles$1.more
@@ -656,7 +490,6 @@ Cookies.defaultProps = defaultProps$1;
656
490
  var styles = {"container":"micromag-consent-container","close":"micromag-consent-close"};
657
491
 
658
492
  var propTypes = {
659
- consent: PropTypes.arrayOf(PropTypes.string),
660
493
  urls: PropTypes.shape({
661
494
  privacy: PropTypes.string,
662
495
  terms: PropTypes.string
@@ -675,7 +508,6 @@ var propTypes = {
675
508
  children: PropTypes.node
676
509
  };
677
510
  var defaultProps = {
678
- consent: ['functionality_storage', 'analytics_storage', 'ad_storage', 'ad_personalization', 'ad_user_data'],
679
511
  urls: null,
680
512
  labels: null,
681
513
  onChange: null,
@@ -686,8 +518,7 @@ var defaultProps = {
686
518
  children: null
687
519
  };
688
520
  function Consent(_ref) {
689
- var consent = _ref.consent,
690
- urls = _ref.urls,
521
+ var urls = _ref.urls,
691
522
  labels = _ref.labels,
692
523
  onChange = _ref.onChange,
693
524
  onSubmit = _ref.onSubmit,
@@ -704,7 +535,6 @@ function Consent(_ref) {
704
535
  "aria-label": "Close consent form"
705
536
  }) : null, children, /*#__PURE__*/React.createElement(Cookies, {
706
537
  className: styles.form,
707
- consent: consent,
708
538
  urls: urls,
709
539
  labels: labels,
710
540
  onChange: onChange,
@@ -715,4 +545,4 @@ function Consent(_ref) {
715
545
  Consent.propTypes = propTypes;
716
546
  Consent.defaultProps = defaultProps;
717
547
 
718
- export { Consent as default };
548
+ export { Consent as default, useConsentActions as useConsent };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micromag/consent",
3
- "version": "0.3.705",
3
+ "version": "0.3.706",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [
@@ -63,11 +63,10 @@
63
63
  "@fortawesome/fontawesome-svg-core": "^6.5.2",
64
64
  "@fortawesome/free-solid-svg-icons": "^6.5.2",
65
65
  "@fortawesome/react-fontawesome": "^0.2.0",
66
- "@micromag/core": "^0.3.703",
67
- "@micromag/data": "^0.3.703",
66
+ "@micromag/core": "^0.3.706",
67
+ "@micromag/data": "^0.3.706",
68
68
  "bootstrap": "^5.3.7",
69
69
  "classnames": "^2.2.6",
70
- "js-cookie": "^3.0.5",
71
70
  "lodash": "^4.17.21",
72
71
  "prop-types": "^15.7.2",
73
72
  "react-intl": "^6.6.4",
@@ -77,5 +76,5 @@
77
76
  "access": "public",
78
77
  "registry": "https://registry.npmjs.org/"
79
78
  },
80
- "gitHead": "e60264096c29617d1ffcd78a4af8d7c55e2df6d2"
79
+ "gitHead": "1797e88940f701824f9b047784d8f5a872b6a790"
81
80
  }