@openeuropa/bcl-subscription 0.20.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/data/data.js ADDED
@@ -0,0 +1,30 @@
1
+ const drupalAttribute = require("drupal-attribute");
2
+
3
+ module.exports = {
4
+ service_buttons: [
5
+ {
6
+ label: "Print",
7
+ variant: "primary",
8
+ outline: true,
9
+ icon_position: "before",
10
+ icon: {
11
+ name: "printer-fill",
12
+ path: "/icons.svg",
13
+ },
14
+ attributes: new drupalAttribute().addClass("me-3"),
15
+ },
16
+ {
17
+ label: "Subscribe",
18
+ variant: "primary",
19
+ outline: true,
20
+ icon_position: "before",
21
+ icon: {
22
+ name: "envelope-fill",
23
+ path: "/icons.svg",
24
+ },
25
+ attributes: new drupalAttribute()
26
+ .setAttribute("data-bs-toggle", "modal")
27
+ .setAttribute("data-bs-target", "#subscribeModal"),
28
+ },
29
+ ],
30
+ };
@@ -0,0 +1,98 @@
1
+ const drupalAttribute = require("drupal-attribute");
2
+
3
+ module.exports = {
4
+ id: "subscribeModal",
5
+ header:
6
+ '<h5 class="modal-title">Subscribe</h5><button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>',
7
+ footer:
8
+ '<div class="text-align-end">' +
9
+ '<button class="btn btn-light" data-bs-dismiss="modal">Close</button>' +
10
+ '<button class="btn btn-primary form-submit ms-4">Subscribe now</button>' +
11
+ "</div>",
12
+ form: {
13
+ attributes: new drupalAttribute()
14
+ .addClass("needs-validation")
15
+ .setAttribute("novalidate", true)
16
+ .setAttribute("onsubmit", "return false;"),
17
+ items: [
18
+ [
19
+ {
20
+ legend_classes: "h6 fw-normal mb-0",
21
+ type: "fieldset",
22
+ legend:
23
+ "<p>Please enter your information & preference to receive the wished information in your mailbox. Your email will not be shared with anyone.</p>",
24
+ },
25
+ ],
26
+ [
27
+ {
28
+ classes: "mb-3",
29
+ input_type: "email",
30
+ required: true,
31
+ label: "E-mail",
32
+ invalid_feedback: "Please enter a valid e-mail address",
33
+ placeholder: "Type in your e-mail address",
34
+ },
35
+ ],
36
+ [
37
+ {
38
+ classes: "mb-3",
39
+ type: "select",
40
+ label: "Languages",
41
+ required: true,
42
+ invalid_feedback: "Please select a language",
43
+ id: "language-select",
44
+ options: [
45
+ {
46
+ label: "Please select a language",
47
+ selected: true,
48
+ disabled: true,
49
+ value: "",
50
+ hidden: true,
51
+ },
52
+ { value: 1, label: "a select option" },
53
+ { value: 2, label: "another select option" },
54
+ { value: 3, label: "another option" },
55
+ { value: 4, label: "last option" },
56
+ ],
57
+ },
58
+ ],
59
+ [
60
+ {
61
+ input_type: "checkbox",
62
+ classes: "mb-3",
63
+ required: true,
64
+ label:
65
+ "By checking this box, I confirm that I want to register for this service, and I agree with the <a href='/example.html'>privacy statement</a>",
66
+ id: "exampleInputCheck1",
67
+ invalid_feedback: "Please check the required checkbox.",
68
+ },
69
+ ],
70
+ ],
71
+ },
72
+ success_alert: {
73
+ message:
74
+ "Your subscription has been successfully registered. You can now close this dialog.",
75
+ heading: "Thank you!",
76
+ icon_path: "/icons.svg",
77
+ variant: "success",
78
+ attributes: new drupalAttribute().addClass([
79
+ "success-alert",
80
+ "d-none",
81
+ "mb-0",
82
+ ]),
83
+ dismissible: false,
84
+ },
85
+ error_alert: {
86
+ message:
87
+ "There was an error!<hr class='d-none d-md-block' /><p class='d-none d-md-block mb-0'>Please verify your e-mail address and agree with the privacy statement.</p>",
88
+ heading: "Sorry!",
89
+ icon_path: "/icons.svg",
90
+ variant: "danger",
91
+ dismissible: false,
92
+ attributes: new drupalAttribute().addClass([
93
+ "error-alert",
94
+ "d-none",
95
+ "mb-0",
96
+ ]),
97
+ },
98
+ };
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@openeuropa/bcl-subscription",
3
+ "author": "European Commission",
4
+ "license": "EUPL-1.2",
5
+ "version": "0.20.0",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "description": "OE - BCL subscription",
10
+ "dependencies": {
11
+ "@openeuropa/bcl-subscription": "^0.20.0"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/openeuropa/bootstrap-component-library.git"
16
+ },
17
+ "bugs": {
18
+ "url": "https://github.com/openeuropa/bootstrap-component-library.git/issues"
19
+ },
20
+ "homepage": "https://github.com/openeuropa/bootstrap-component-library",
21
+ "keywords": [
22
+ "openeuropa",
23
+ "bootstrap-component-library",
24
+ "design-system",
25
+ "twig"
26
+ ],
27
+ "gitHead": "ea13560489a089d0c198f781e75951a9160d2554"
28
+ }
@@ -0,0 +1,24 @@
1
+ {# Parameters:
2
+ - form: (form object) (default: {})
3
+ - success_alert: (alert object) (default: {})
4
+ - error_alert: (button Object) (default: {})
5
+
6
+ Blocks:
7
+ - body
8
+ - messages
9
+ #}
10
+
11
+ {% set _form = form|default({}) %}
12
+ {% set _success_alert = success_alert|default({}) %}
13
+ {% set _error_alert = error_alert|default({}) %}
14
+
15
+ {% extends "@oe-bcl/bcl-modal/modal.html.twig" %}
16
+
17
+ {% block body %}
18
+ {% include '@oe-bcl/bcl-form/form.html.twig' with _form only %}
19
+ {% endblock %}
20
+
21
+ {% block messages %}
22
+ {% include '@oe-bcl/bcl-alert/alert.html.twig' with _success_alert only %}
23
+ {% include '@oe-bcl/bcl-alert/alert.html.twig' with _error_alert only %}
24
+ {% endblock %}
@@ -0,0 +1,10 @@
1
+ {% extends '@oe-bcl/bcl-base-templates/content-type.html.twig' %}
2
+
3
+ {% block sidebar %}
4
+ {% include '@oe-bcl/bcl-inpage-navigation/inpage-navigation.html.twig' with sidebar only %}
5
+ {% endblock %}
6
+
7
+ {% block content_bottom %}
8
+ {% include '@oe-bcl/bcl-subscription-block/subscription-block.html.twig' with subscription only %}
9
+ {% include '@oe-bcl/bcl-subscription/subscription-modal.html.twig' with modal only %}
10
+ {% endblock %}
@@ -0,0 +1,153 @@
1
+ import { withDesign } from "storybook-addon-designs";
2
+ import { screen, userEvent } from "@storybook/testing-library";
3
+ import isChromatic from "chromatic/isChromatic";
4
+ import { correctPaths, initScrollspy } from "@openeuropa/bcl-story-utils";
5
+ import header from "@openeuropa/bcl-data-header/data--simple";
6
+ import footer from "@openeuropa/bcl-data-footer/data";
7
+ import content from "@openeuropa/bcl-news/data/data_content.js";
8
+ import banner from "@openeuropa/bcl-content-banner/data/data.js";
9
+ import subscriptionPage from "@openeuropa/bcl-subscription/subscription.html.twig";
10
+ import subscriptionPageData from "@openeuropa/bcl-subscription/data/data.js";
11
+ import modalData from "@openeuropa/bcl-subscription/data/data_modal.js";
12
+ import blockData from "@openeuropa/bcl-subscription-block/data/data.js";
13
+ import sidebar from "@openeuropa/bcl-inpage-navigation/data--simple";
14
+ import drupalAttribute from "drupal-attribute";
15
+
16
+ if (isChromatic()) {
17
+ banner.image.classes = banner.image.classes
18
+ ? `${banner.image.classes} chromatic-ignore`
19
+ : "chromatic-ignore";
20
+ }
21
+
22
+ const demoData = {
23
+ content_type: "subscription",
24
+ page_title: "Subscription",
25
+ header: header,
26
+ footer: {
27
+ ...footer,
28
+ attributes: new drupalAttribute().addClass("mt-4"),
29
+ },
30
+ with_banner: true,
31
+ with_header: true,
32
+ with_footer: true,
33
+ sidebar: sidebar,
34
+ subscription: blockData,
35
+ modal: modalData,
36
+ banner: {
37
+ ...banner,
38
+ ...subscriptionPageData,
39
+ },
40
+ content: content,
41
+ };
42
+
43
+ const clientValidation = (story) => {
44
+ const demo = story();
45
+ return `<script>
46
+ var backdrop = document.getElementsByClassName('modal-backdrop')[0];
47
+ if (typeof(backdrop) != 'undefined' && backdrop != null) {
48
+ backdrop.remove();
49
+ document.body.removeAttribute("style")
50
+ }
51
+
52
+ var submit = document.querySelector('.form-submit');
53
+ var successAlert = document.querySelector('.success-alert');
54
+ var errorAlert = document.querySelector('.error-alert');
55
+ var form = document.querySelector('.needs-validation');
56
+
57
+ submit.addEventListener('click', function () {
58
+ successAlert.classList.add("d-none")
59
+ errorAlert.classList.add("d-none")
60
+ if (!form.checkValidity()) {
61
+ event.preventDefault()
62
+ event.stopPropagation()
63
+ errorAlert.classList.remove("d-none")
64
+ } else {
65
+ successAlert.classList.remove("d-none")
66
+ form.closest('.modal-body').remove();
67
+ submit.classList.add('d-none')
68
+ }
69
+
70
+ form.classList.add('was-validated')
71
+ });
72
+ </script>${demo}`;
73
+ };
74
+
75
+ const openModal = (story) => {
76
+ const demo = story();
77
+ return `
78
+ ${demo}
79
+ <script>
80
+ var backdrop = document.getElementsByClassName('modal-backdrop')[0];
81
+ if (typeof(backdrop) != 'undefined' && backdrop != null) {
82
+ backdrop.remove()
83
+ }
84
+ var subscribeModal = new bootstrap.Modal(document.getElementById('subscribeModal'))
85
+ subscribeModal.show()
86
+ </script>
87
+ `;
88
+ };
89
+
90
+ const successState = (story) => {
91
+ const demo = story();
92
+ return `
93
+ ${demo}
94
+ <script>
95
+ var submit = document.querySelector('.form-submit');
96
+ var successAlert = document.querySelector('.success-alert');
97
+ var form = document.querySelector('.needs-validation');
98
+
99
+ successAlert.classList.remove("d-none")
100
+ form.closest('.modal-body').remove();
101
+ submit.classList.add('d-none')
102
+ </script>
103
+ `;
104
+ };
105
+
106
+ const errorState = (story) => {
107
+ const demo = story();
108
+ return `
109
+ ${demo}
110
+ <script>
111
+ var errorAlert = document.querySelector('.error-alert');
112
+ var form = document.querySelector('.needs-validation');
113
+
114
+ errorAlert.classList.remove("d-none")
115
+ form.classList.add('was-validated')
116
+ </script>
117
+ `;
118
+ };
119
+
120
+ export default {
121
+ title: "Features/Subscription",
122
+ decorators: [withDesign, initScrollspy],
123
+ parameters: {
124
+ layout: "fullscreen",
125
+ controls: { disable: true },
126
+ badges: ["stable"],
127
+ design: [
128
+ {
129
+ name: "Mockup",
130
+ type: "figma",
131
+ url: "https://www.figma.com/file/NQlGvTiTXZYN8TwY2Ur5EI/BCL-Features?node-id=5859%3A239083",
132
+ },
133
+ ],
134
+ },
135
+ };
136
+
137
+ export const Default = () => subscriptionPage(correctPaths(demoData));
138
+ Default.decorators = [clientValidation];
139
+
140
+ if (isChromatic()) {
141
+ Default.play = async () => {
142
+ const button = screen.getAllByText("Subscribe", {
143
+ selector: "button",
144
+ });
145
+ await userEvent.click(button[0]);
146
+ };
147
+ }
148
+
149
+ export const Success = () => subscriptionPage(correctPaths(demoData));
150
+ Success.decorators = [openModal, successState];
151
+
152
+ export const Error = () => subscriptionPage(correctPaths(demoData));
153
+ Error.decorators = [openModal, errorState];
@@ -0,0 +1,43 @@
1
+ import { renderTwigFileAsNode } from "@openeuropa/bcl-test-utils";
2
+ import header from "@openeuropa/bcl-data-header/data--simple";
3
+ import footer from "@openeuropa/bcl-data-footer/data";
4
+ import content from "@openeuropa/bcl-news/data/data_content.js";
5
+ import banner from "@openeuropa/bcl-content-banner/data/data.js";
6
+ import subscriptionPageData from "@openeuropa/bcl-subscription/data/data.js";
7
+ import modalData from "@openeuropa/bcl-subscription/data/data_modal.js";
8
+ import blockData from "@openeuropa/bcl-subscription-block/data/data.js";
9
+ import sidebar from "@openeuropa/bcl-inpage-navigation/data--simple";
10
+ import drupalAttribute from "drupal-attribute";
11
+
12
+ const demoData = {
13
+ content_type: "subscription",
14
+ page_title: "Subscription",
15
+ header: header,
16
+ footer: {
17
+ ...footer,
18
+ attributes: new drupalAttribute().addClass("mt-4"),
19
+ },
20
+ with_banner: true,
21
+ with_header: true,
22
+ with_footer: true,
23
+ sidebar: sidebar,
24
+ subscription: blockData,
25
+ modal: modalData,
26
+ banner: {
27
+ ...banner,
28
+ ...subscriptionPageData,
29
+ },
30
+ content: content,
31
+ };
32
+
33
+ const template = "@oe-bcl/bcl-subscription/subscription.html.twig";
34
+
35
+ const render = (params) => renderTwigFileAsNode(template, params, true);
36
+
37
+ describe("OE - Subscription", () => {
38
+ test("renders correctly", () => {
39
+ expect.assertions(1);
40
+
41
+ return expect(render(demoData)).resolves.toMatchSnapshot();
42
+ });
43
+ });