Skip to content

Commit de7f903

Browse files
authored
chore: integrate feedback (#58)
* chore: centralize vars * fix: change link cursor * chore: reduce code footprint * chore: some doc * chore: typo
1 parent 553de90 commit de7f903

File tree

4 files changed

+55
-26
lines changed

4 files changed

+55
-26
lines changed

blocks/consent/README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Consent block provides a minimalistic, performant and non-intrusive cookie conse
1111
* When consent preferences are updated or read from the browser, a custom event is triggered. Martech loaders can listen to this events to decide what to load or not load, based on user preferences.
1212

1313
## Cookie Consent Flow
14-
![Cookie Consent flow (1)](https://github.com/adobe/aem-block-collection/assets/43381734/53583ee0-da46-4f1a-91f4-39411305bf47)
14+
![Cookie Consent flow](https://github.com/adobe/aem-block-collection/assets/43381734/53583ee0-da46-4f1a-91f4-39411305bf47)
1515

1616

1717
## Content of the banner
@@ -31,11 +31,11 @@ Metadata properties:
3131
*Samples*:
3232
* configuration:
3333

34-
![Screenshot 2024-02-16 at 16 31 43](https://github.com/adobe/aem-block-collection/assets/43381734/e8e52be7-1cf5-4820-8384-76ff228be061)
34+
![Consent configuration](https://github.com/adobe/aem-block-collection/assets/43381734/e8e52be7-1cf5-4820-8384-76ff228be061)
3535

3636
* banner displayed:
3737

38-
![Screenshot 2024-03-13 at 09 08 27](https://github.com/adobe/aem-block-collection/assets/43381734/7b70dfe8-1d79-432e-8e74-f09af016bab7)
38+
![Consent banner preview](https://github.com/adobe/aem-block-collection/assets/43381734/7b70dfe8-1d79-432e-8e74-f09af016bab7)
3939

4040

4141

@@ -57,16 +57,23 @@ The second and subsequent sections are considered to be cookie categories. And e
5757
*Samples*
5858
* configuration
5959

60-
![Screenshot 2024-02-16 at 17 00 58](https://github.com/adobe/aem-block-collection/assets/43381734/1fba9fcf-19a8-4f0d-9e3d-741e77befefb)
60+
![Multiple consent configuration samples](https://github.com/adobe/aem-block-collection/assets/43381734/1fba9fcf-19a8-4f0d-9e3d-741e77befefb)
6161

6262

6363
* dialog displayed
6464

65-
![Screenshot 2024-02-16 at 17 02 26](https://github.com/adobe/aem-block-collection/assets/43381734/72929596-0b25-450a-9332-72dea6d94204)
65+
![Consent dialog preview](https://github.com/adobe/aem-block-collection/assets/43381734/72929596-0b25-450a-9332-72dea6d94204)
6666

6767
## Update consent
6868
Sometimes users want to change their cookie preferences. For this purpose there is a function in the block `blocks/consent/consent.js` called `showConsentForUpdate(name)`.
6969
Where `name` is the name of the consent configuration document. This function is expected to be called when a user clicks on the "cookie preferences" or similar link.
7070

7171
* In case of *#1. Simple consent banner* this function will show the minimalistic non-intrusive banner
7272
* In case of *#2. Simple consent banner and categories details* this function would show the consent categories detail dialog.
73+
74+
## Block setup
75+
76+
Block needs to be loaded as quickly as possible and the logic to load the block or not highly depends on project needs. Here are the two elements you may want to patch in your project:
77+
78+
- in [scripts.js](../../scripts.js), you need to load the consent block in the lazy phase to load the consent banner
79+
- in [footer](../header/footer.js), you can "patch" the Cookie Preferences link to open the consent dialog using the `setupConsentPreferenceLink` function from the block.

blocks/consent/consent.css

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
.consent.banner {
1+
.consent {
22
--consent-banner-background-color: #202124;
33
--consent-banner-font-size-s: 12px;
44
--consent-banner-font-size-l: 14px;
55
--consent-banner-text-color: #eee;
66
--consent-banner-link-color: var(--background-color);
7+
--consent-dialog-background-color: var(--background-color);
8+
--consent-dialog-light-color: var(--light-color);
9+
--consent-dialog-dark-color: var(--dark-color);
10+
--consent-dialog-body-font-size: var(--body-font-size-s);
11+
--consent-dialog-heading-font-size: var(--heading-font-size-m);
12+
}
713

14+
.consent.banner {
815
font-size: var(--consent-banner-font-size-s);
916
color: var(--consent-banner-text-color);
1017
background-color: var(--consent-banner-background-color);
@@ -60,22 +67,23 @@
6067

6168
.consent.banner .more-info {
6269
color: var(--consent-banner-link-color);
70+
cursor: pointer;
6371
}
6472

6573
.consent dialog {
66-
font-size: var(--body-font-size-s);
74+
font-size: var(--consent-dialog-body-font-size);
6775
overscroll-behavior: none;
6876
padding: 30px;
6977
border: 1px solid #ccc;
70-
border-radius: var(--dialog-border-radius);
78+
border-radius: 16px;
7179
left: 20px;
7280
right: 20px;
7381
width: clamp(300px, 80%, 700px);
7482
}
7583

7684
/* stylelint-disable-next-line no-descending-specificity */
7785
.consent dialog .consent-button {
78-
font-size: var(--body-font-size-s);
86+
font-size: var(--consent-dialog-body-font-size);
7987
margin: 0;
8088
}
8189

@@ -86,7 +94,7 @@
8694
width: 20px;
8795
height: 100%;
8896
max-height: 54px;
89-
border-radius: 0 var(--dialog-border-radius) 0 0;
97+
border-radius: 0 16px 0 0;
9098
background-color: unset;
9199
text-overflow: clip;
92100
margin: 0;
@@ -100,7 +108,7 @@
100108
}
101109

102110
.consent dialog h2 {
103-
font-size: var(--heading-font-size-m);
111+
font-size: var(--consent-dialog-heading-font-size);
104112
}
105113

106114
.consent dialog .section {
@@ -199,7 +207,7 @@
199207

200208
/*** COPIED FROM ACCORDION ***/
201209
.consent .accordion details {
202-
border: 1px solid var(--dark-color);
210+
border: 1px solid var(--consent-dialog-dark-color);
203211
}
204212

205213
/* stylelint-disable-next-line no-descending-specificity */
@@ -218,12 +226,12 @@
218226
}
219227

220228
.consent .accordion details[open] summary {
221-
background-color: var(--light-color);
229+
background-color: var(--consent-dialog-light-color);
222230
}
223231

224232
.consent .accordion details summary:focus,
225233
.consent .accordion details summary:hover {
226-
background-color: var(--dark-color);
234+
background-color: var(--consent-dialog-dark-color);
227235
}
228236

229237
.consent .accordion details summary::-webkit-details-marker {
@@ -252,6 +260,6 @@
252260
}
253261

254262
.consent .accordion details[open] .accordion-item-body {
255-
border-top: 1px solid var(--dark-color);
256-
background-color: var(--background-color);
263+
border-top: 1px solid var(--consent-dialog-dark-color);
264+
background-color: var(--consent-dialog-background-color);
257265
}

blocks/consent/consent.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import {
22
sampleRUM,
33
loadCSS,
4+
getMetadata,
5+
fetchPlaceholders,
46
} from '../../scripts/aem.js';
57

68
const LOCAL_STORAGE_AEM_CONSENT = 'aem-consent';
@@ -72,7 +74,7 @@ export function init(consentName) {
7274
}
7375

7476
/**
75-
* shows the consent banner to update the preferences.
77+
* Shows the consent banner to update the preferences.
7678
* If config has category details, it will directly show the categoty details dialog.
7779
* Otherwise it will show the minimal banner.
7880
* @param {String} consentName name of the consent banner configuration file.
@@ -82,3 +84,19 @@ export function showConsentForUpdate(consentName) {
8284
loadCSS(`${window.hlx.codeBasePath}/blocks/consent/consent.css`);
8385
import('./consent-banner.js').then((ccdialog) => ccdialog.showConsentBannerForUpdate(consentName, manageConsentUpdate));
8486
}
87+
88+
/**
89+
* Updates the Cookie Preference link inside the provided element:
90+
* on click, the link will open the consent dialog
91+
* if the 'cookie-consent' metadata is set on the page.
92+
* @param {Element} el the DOM element in which the consent preference link is to be set up
93+
*/
94+
export function setupConsentPreferenceLink(el = document) {
95+
if (getMetadata('cookie-consent')) {
96+
const consentLinkText = fetchPlaceholders()['cookie-preferences-link'] || 'Cookie preferences';
97+
el.querySelector(`a[title="${consentLinkText}"]`).addEventListener('click', (e) => {
98+
showConsentForUpdate(getMetadata('cookie-consent'));
99+
e.preventDefault();
100+
});
101+
}
102+
}

blocks/footer/footer.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { getMetadata, fetchPlaceholders } from '../../scripts/aem.js';
1+
import { getMetadata } from '../../scripts/aem.js';
22
import { loadFragment } from '../fragment/fragment.js';
3-
import { showConsentForUpdate } from '../consent/consent.js';
3+
import { setupConsentPreferenceLink } from '../consent/consent.js';
4+
45
/**
56
* loads and decorates the footer
67
* @param {Element} block The footer block element
@@ -12,13 +13,8 @@ export default async function decorate(block) {
1213
// load footer fragment
1314
const footerPath = footerMeta.footer || '/footer';
1415
const fragment = await loadFragment(footerPath);
15-
if (getMetadata('cookie-consent')) {
16-
const consentLinkText = fetchPlaceholders()['cookie-preferences-link'] || 'Cookie preferences';
17-
fragment.querySelector(`a[title="${consentLinkText}"]`).addEventListener('click', (e) => {
18-
showConsentForUpdate(getMetadata('cookie-consent'));
19-
e.preventDefault();
20-
});
21-
}
16+
17+
setupConsentPreferenceLink(fragment);
2218

2319
// decorate footer DOM
2420
const footer = document.createElement('div');

0 commit comments

Comments
 (0)