@openeuropa/bcl-toasts 0.3732.202601071600

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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020-2021 Mark Otto
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@openeuropa/bcl-toasts",
3
+ "author": "European Commission",
4
+ "license": "EUPL-1.2",
5
+ "version": "0.3732.202601071600",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "description": "OE - BCL toast",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/openeuropa/bootstrap-component-library.git"
13
+ },
14
+ "bugs": {
15
+ "url": "https://github.com/openeuropa/bootstrap-component-library.git/issues"
16
+ },
17
+ "homepage": "https://github.com/openeuropa/bootstrap-component-library",
18
+ "keywords": [
19
+ "openeuropa",
20
+ "bootstrap-component-library",
21
+ "design-system",
22
+ "twig"
23
+ ],
24
+ "gitHead": "253e588bbc9fd4d20ced38c9384b70636725f2c6"
25
+ }
@@ -0,0 +1,132 @@
1
+ {% apply spaceless %}
2
+
3
+ {#
4
+ Parameters:
5
+ - with_wrapper (boolean) (default: false)
6
+ - wrapper_classes (string) (default: '')
7
+ - wrapper_aria_live (string) (default: '')
8
+ - with_container (boolean) (default: false)
9
+ - container_classes (string) (default: '')
10
+ - toasts (object[]) format: [
11
+ {
12
+ - body (string) (default: '')
13
+ - body_attributes (drupal attrs)
14
+ - header (string) (default: '')
15
+ - header_attributes (drupal attrs)
16
+ - button_attributes (drupal attrs)
17
+ - custom_content (string) (default: '')
18
+ - role (string) (default: 'alert')
19
+ - with_close (boolean) (default: true)
20
+ - autohide (boolean) (default: false)
21
+ - with_body_wrapper (boolean) (default: false)
22
+ - body_wrapper_classes (string) (default: '')
23
+ - attributes (drupal object) (default: undefined)
24
+ }
25
+ ]
26
+ - attributes (drupal attrs)
27
+ #}
28
+
29
+ {% set _with_wrapper = with_wrapper ?? false %}
30
+ {% set _wrapper_classes = wrapper_classes|default('') %}
31
+ {% set _wrapper_aria_live = wrapper_aria_live|default('') %}
32
+ {% set _with_container = with_container ?? false %}
33
+ {% set _toasts = toasts|default([]) %}
34
+
35
+ {% set _container_classes = 'toast-container' %}
36
+
37
+ {% if container_classes %}
38
+ {% set _container_classes = _container_classes ~ ' ' ~ container_classes %}
39
+ {% endif %}
40
+
41
+ {% if attributes is empty %}
42
+ {% set attributes = create_attribute() %}
43
+ {% endif %}
44
+
45
+ {# wrapper #}
46
+ {% if _with_wrapper %}
47
+ {% set attributes = attributes.setAttribute('aria-atomic', "true") %}
48
+ {% if _wrapper_aria_live %}
49
+ {% set attributes = attributes.setAttribute('aria-live', _wrapper_aria_live) %}
50
+ {% endif %}
51
+ {% if _wrapper_classes %}
52
+ {% set attributes = attributes.addClass(_wrapper_classes|split(' ')) %}
53
+ {% endif %}
54
+
55
+ <div {{ attributes }}>
56
+
57
+ {% endif %}
58
+ {# container #}
59
+ {% if _with_container %}
60
+ <div class="{{ _container_classes }}">
61
+ {% endif %}
62
+ {# toasts #}
63
+ {% if _toasts is not empty %}
64
+ {% for _toast in _toasts %}
65
+ {% set _classes = ['toast'] %}
66
+ {% set _body = _toast.body|default('') %}
67
+ {% set _role = _toast.role|default('') %}
68
+ {% set _with_close = _toast.with_close ?? true %}
69
+ {% set _aria_live = _toast.aria_live|default('') %}
70
+ {% set _autohide = _toast.autohide ?? true %}
71
+ {% set _with_body_wrapper = _toast.with_body_wrapper ?? false %}
72
+ {% set _body_wrapper_classes = _toast.body_wrapper_classes|default('') %}
73
+ {% set _toast_attributes = _toast.attributes ?: create_attribute() %}
74
+ {% set _body_attributes = _toast.body_attributes ?: create_attribute() %}
75
+ {% set _header_attributes = _toast.header_attributes ?: create_attribute() %}
76
+ {% set _button_attributes = _toast.button_attributes ?: create_attribute() %}
77
+ {% set _toast_attributes = _toast_attributes.addClass(_classes).setAttribute('aria-atomic', 'true') %}
78
+ {% if _aria_live is not empty %}
79
+ {% set _toast_attributes = _toast_attributes.setAttribute('aria-live', _aria_live) %}
80
+ {% endif %}
81
+ {% if _role is not empty %}
82
+ {% set _toast_attributes = _toast_attributes.setAttribute('role', _role) %}
83
+ {% endif %}
84
+ {% if not _autohide %}
85
+ {% set _toast_attributes = _toast_attributes.setAttribute('data-bs-autohide', 'false') %}
86
+ {% endif %}
87
+ <div
88
+ {{ _toast_attributes }}
89
+ >
90
+ {% if _with_close or
91
+ (_toast.header is defined and _toast.header is not empty)
92
+ %}
93
+ <div{{ _header_attributes.addClass(['toast-header']) }}>
94
+ {{- _toast.header|default('') -}}
95
+ {% if _with_close %}
96
+ {%- if not _button_attributes.hasAttribute('aria-label') %}
97
+ {%- set _button_attributes = _button_attributes.setAttribute('aria-label', 'Close') %}
98
+ {%- endif %}
99
+ {%- include '@oe-bcl/bcl-button/button.html.twig' with {
100
+ attributes: _button_attributes
101
+ .addClass(['btn-close'])
102
+ .setAttribute('data-bs-dismiss', 'toast'),
103
+ clean_class: true
104
+ } only -%}
105
+ {% endif -%}
106
+ </div>
107
+ {% endif %}
108
+ {% if _with_body_wrapper %}
109
+ <div
110
+ {% if _body_wrapper_classes %}
111
+ class="{{ _body_wrapper_classes }}"
112
+ {% endif %}
113
+ >
114
+ {% endif %}
115
+ <div{{ _body_attributes.addClass(['toast-body']) }}>
116
+ {{- _body -}}
117
+ </div>
118
+ {% if _with_body_wrapper %}
119
+ </div>
120
+ {% endif %}
121
+ {{- _toast.custom_content|default('') -}}
122
+ </div>
123
+ {% endfor %}
124
+ {% endif %}
125
+ {% if _with_container %}
126
+ </div>
127
+ {% endif %}
128
+ {% if _with_wrapper %}
129
+ </div>
130
+ {% endif %}
131
+
132
+ {% endapply %}