@openeuropa/bcl-description-list 0.1.202408021145

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.
@@ -0,0 +1,52 @@
1
+ module.exports = {
2
+ variant: "horizontal",
3
+ items: [
4
+ {
5
+ term: [
6
+ {
7
+ label: "<p class='mb-0'>Only title label with <em>icon</em></p>",
8
+ icon: {
9
+ name: "geo-alt-fill",
10
+ size: "xs",
11
+ path: "/icons.svg",
12
+ },
13
+ },
14
+ ],
15
+ definition:
16
+ "Long Description text goes here.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin dignissim, quam at sollicitudin volutpat, ipsum arcu maximus massa, quis egestas diam tellus vitae nulla.",
17
+ },
18
+ {
19
+ term: [
20
+ {
21
+ label: "First title label",
22
+ color: "bg-success",
23
+ },
24
+ {
25
+ label: "Second title label",
26
+ icon: {
27
+ name: "geo-alt-fill",
28
+ size: "xs",
29
+ path: "/icons.svg",
30
+ },
31
+ },
32
+ ],
33
+ definition: "Description text goes here.",
34
+ },
35
+ {
36
+ term: "Only title <strong>label</strong>",
37
+ definition: [
38
+ {
39
+ label: "Description text goes here.",
40
+ },
41
+ {
42
+ label: "Description text goes here.",
43
+ icon: {
44
+ name: "geo-alt-fill",
45
+ size: "xs",
46
+ path: "/icons.svg",
47
+ },
48
+ },
49
+ ],
50
+ },
51
+ ],
52
+ };
package/data/data.js ADDED
@@ -0,0 +1,51 @@
1
+ module.exports = {
2
+ items: [
3
+ {
4
+ term: [
5
+ {
6
+ label: "<p class='mb-0'>Only title label with <em>icon</em></p>",
7
+ icon: {
8
+ name: "geo-alt-fill",
9
+ size: "xs",
10
+ path: "/icons.svg",
11
+ },
12
+ },
13
+ ],
14
+ definition:
15
+ "Long Description text goes here.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin dignissim, quam at sollicitudin volutpat, ipsum arcu maximus massa, quis egestas diam tellus vitae nulla.",
16
+ },
17
+ {
18
+ term: [
19
+ {
20
+ label: "First title label",
21
+ color: "bg-success",
22
+ },
23
+ {
24
+ label: "Second title label",
25
+ icon: {
26
+ name: "geo-alt-fill",
27
+ size: "xs",
28
+ path: "/icons.svg",
29
+ },
30
+ },
31
+ ],
32
+ definition: "Description text goes here.",
33
+ },
34
+ {
35
+ term: "Only title <strong>label</strong>",
36
+ definition: [
37
+ {
38
+ label: "Description text goes here.",
39
+ },
40
+ {
41
+ label: "Description text goes here.",
42
+ icon: {
43
+ name: "geo-alt-fill",
44
+ size: "xs",
45
+ path: "/icons.svg",
46
+ },
47
+ },
48
+ ],
49
+ },
50
+ ],
51
+ };
@@ -0,0 +1,44 @@
1
+ {% apply spaceless %}
2
+
3
+ {#
4
+ Parameters:
5
+ - button: (button object) (default: {})
6
+ - link: (link object) (default: {})
7
+ - icon: (icon object) (default: {})
8
+ - label: (string) (default: '')
9
+
10
+ BLOCKS:
11
+ - definition
12
+ #}
13
+
14
+ {% set _button = button|default({}) %}
15
+ {% set _link = link|default({}) %}
16
+ {% set _icon = icon|default({}) %}
17
+ {% set _label = label|default('') %}
18
+
19
+
20
+ <dd>
21
+ {%- block definition -%}
22
+ {%- if _button is not empty -%}
23
+ {% include '@oe-bcl/bcl-button/button.html.twig' with _button only %}
24
+ {%- elseif _link is not empty %}
25
+ {% include '@oe-bcl/bcl-link/link.html.twig' with _link only -%}
26
+ {%- else -%}
27
+ {%- if _icon is not empty -%}
28
+ {%- set _icon_classes = ["me-2", "align-self-center", "flex-shrink-0"] -%}
29
+ {% set _icon_attributes = _icon.attributes ?: create_attribute() %}
30
+ {% set _icon_attributes = _icon_attributes.addClass(_icon_classes) %}
31
+ {%- include '@oe-bcl/bcl-icon/icon.html.twig' with _icon|merge({
32
+ attributes: _icon_attributes,
33
+ }) only -%}
34
+ <div class="mb-0 d-inline-block">
35
+ {{- _label -}}
36
+ </div>
37
+ {%- else -%}
38
+ <div>{{- _label -}}</div>
39
+ {%- endif -%}
40
+ {%- endif -%}
41
+ {% endblock %}
42
+ </dd>
43
+
44
+ {% endapply %}
@@ -0,0 +1,33 @@
1
+ {% apply spaceless %}
2
+
3
+ {#
4
+ Parameters:
5
+ - icon: (icon object) (default: {})
6
+ - color: (string) (default: '')
7
+ - options: ['bg-primary', 'bg-secondary', 'bg-success', 'bg-warning', 'bg-info', 'bg-light', 'bg-dark', 'bg-lighter', 'bg-gray-200', 'bg-gray-400']
8
+ - label: (string) (default: '')
9
+ #}
10
+
11
+ {% set _icon = icon|default({}) %}
12
+ {% set _color = color|default('') %}
13
+ {% set _label = label|default('') %}
14
+
15
+ <dt>
16
+ <div class="d-flex">
17
+ {%- if _icon is not empty -%}
18
+ {% set _icon_classes = ["me-2", "align-self-center", "flex-shrink-0"] %}
19
+ {% set _icon_attributes = _icon.attributes ?: create_attribute() %}
20
+ {% set _icon_attributes = _icon_attributes.addClass(_icon_classes) %}
21
+ {% include '@oe-bcl/bcl-icon/icon.html.twig' with _icon|merge({
22
+ attributes: _icon_attributes,
23
+ }) only %}
24
+ {%- elseif _color is not empty -%}
25
+ <div class="align-self-center">
26
+ <span class="p-2 me-2 d-inline-block rounded-1 {{ _color }}"></span>
27
+ </div>
28
+ {%- endif -%}
29
+ <div>{{- _label -}}</div>
30
+ </div>
31
+ </dt>
32
+
33
+ {% endapply %}
@@ -0,0 +1,121 @@
1
+ {% apply spaceless %}
2
+
3
+ {#
4
+ Parameters:
5
+ - title: (string) (default: '')
6
+ - title_tag: (string) (default: 'h2')
7
+ - title_link: (link object) (default: {})
8
+ - title_attributes (drupal attrs)
9
+ - bordered (boolean) (default: false)
10
+ - col_classes (string) (default: 'col-3')
11
+ - items (array) (default: []): format: [
12
+ {
13
+ term (string or description list title [])
14
+ definition (string or description list details [])
15
+ },
16
+ ...
17
+ ]
18
+ - variant (string) (default: '')
19
+ - option: ['horizontal']
20
+ #}
21
+
22
+ {% set _title = title|default('') %}
23
+ {% set _title_tag = title_tag|default('h2') %}
24
+ {% set _title_link = title_link|default({}) %}
25
+ {% set _title_attributes = title_attributes ?: create_attribute() %}
26
+ {% set _bordered = bordered ?? false %}
27
+ {% set _col_classes = col_classes|default('col-md-3') %}
28
+ {% set _items = items|default([]) %}
29
+ {% set _variant = variant|default('') %}
30
+
31
+ {% if attributes is empty %}
32
+ {% set attributes = create_attribute() %}
33
+ {% endif %}
34
+
35
+ {% set _item_classes = ['mb-3'] %}
36
+
37
+ {% if _bordered %}
38
+ {% set _item_classes = ['border-bottom', 'pb-2-5', 'mb-2-5'] %}
39
+ {% endif %}
40
+
41
+ {% if _variant == 'horizontal' %}
42
+ {% set _item_classes = _item_classes|merge(['row']) %}
43
+ {% endif %}
44
+
45
+ {% if _title is not empty %}
46
+ {% include '@oe-bcl/bcl-heading/heading.html.twig' with {
47
+ title: _title,
48
+ title_tag: _title_tag,
49
+ title_link: _title_link,
50
+ attributes: _title_attributes,
51
+ } only %}
52
+ {% endif %}
53
+
54
+ {% set attributes = attributes.addClass(['bcl-description-list']) %}
55
+
56
+ {% if _variant != 'horizontal' %}
57
+ <dl
58
+ {{ attributes }}
59
+ >
60
+ {% else %}
61
+ <div
62
+ {{ attributes }}
63
+ >
64
+ {% endif %}
65
+ {% for _item in _items %}
66
+ {% if _variant == 'horizontal' %}
67
+ <dl
68
+ {{ create_attribute().addClass(_item_classes) }}
69
+ >
70
+ {% else %}
71
+ <div
72
+ {{ create_attribute().addClass(_item_classes) }}
73
+ >
74
+ {% endif %}
75
+ {% if _item.term is not empty %}
76
+ {% if _variant == 'horizontal' %}
77
+ <div class="{{ _col_classes }}">
78
+ {% endif %}
79
+ {% if _item.term is iterable %}
80
+ {% for _term in _item.term %}
81
+ {%- include '@oe-bcl/bcl-description-list/description-list-title.html.twig' with _term only -%}
82
+ {% endfor %}
83
+ {% else %}
84
+ {%- include '@oe-bcl/bcl-description-list/description-list-title.html.twig' with {
85
+ label: _item.term
86
+ } only -%}
87
+ {% endif %}
88
+ {% if _variant == 'horizontal' %}
89
+ </div>
90
+ {% endif %}
91
+ {% endif %}
92
+ {% if _item.definition is not empty %}
93
+ {% if _variant == 'horizontal' %}
94
+ <div class="col">
95
+ {% endif %}
96
+ {% if _item.definition is iterable %}
97
+ {% for _definition in _item.definition %}
98
+ {%- include '@oe-bcl/bcl-description-list/description-list-details.html.twig' with _definition only -%}
99
+ {% endfor %}
100
+ {% else %}
101
+ {%- include '@oe-bcl/bcl-description-list/description-list-details.html.twig' with {
102
+ label: _item.definition
103
+ } only -%}
104
+ {% endif %}
105
+ {% if _variant == 'horizontal' %}
106
+ </div>
107
+ {% endif %}
108
+ {% endif %}
109
+ {% if _variant == 'horizontal' %}
110
+ </dl>
111
+ {% else %}
112
+ </div>
113
+ {% endif %}
114
+ {% endfor %}
115
+ {% if _variant != 'horizontal' %}
116
+ </dl>
117
+ {% else %}
118
+ </div>
119
+ {% endif %}
120
+
121
+ {% endapply %}
@@ -0,0 +1,70 @@
1
+ import { withDesign } from "storybook-addon-designs";
2
+ import withCode from "@openeuropa/storybook-addon-code";
3
+ import { correctPaths, getTitleControls } from "@openeuropa/bcl-story-utils";
4
+
5
+ import demoData from "@openeuropa/bcl-description-list/data/data.js";
6
+ import demoDataHorizontal from "@openeuropa/bcl-description-list/data/data--horizontal";
7
+ import descriptionList from "@openeuropa/bcl-description-list/description-list.html.twig";
8
+
9
+ const getArgs = () => ({
10
+ title: "",
11
+ title_tag: "h2",
12
+ bordered: false,
13
+ col_classes: "col-md-3",
14
+ });
15
+
16
+ const getArgTypes = () => ({
17
+ ...getTitleControls(),
18
+ bordered: {
19
+ type: { name: "boolean" },
20
+ description: "Border between description items",
21
+ table: {
22
+ type: { summary: "boolean" },
23
+ defaultValue: { summary: "false" },
24
+ category: "Style",
25
+ },
26
+ },
27
+ col_classes: {
28
+ name: "col classes",
29
+ type: { name: "string" },
30
+ description: "Classes of the column in horizontal variant",
31
+ table: {
32
+ defaultValue: { summary: "col-md-3" },
33
+ type: { summary: "int" },
34
+ category: "Style",
35
+ },
36
+ },
37
+ });
38
+
39
+ const applyArgs = (data, args) => Object.assign(data, args);
40
+
41
+ export default {
42
+ title: "Paragraphs/Description List",
43
+ decorators: [withCode, withDesign],
44
+ parameters: {
45
+ badges: ["deprecated"],
46
+ viewport: {
47
+ defaultViewport: "tablet",
48
+ },
49
+ design: [
50
+ {
51
+ name: "Mockup",
52
+ type: "figma",
53
+ url: "https://www.figma.com/file/7aJedLkk8hiDoD3RcxTnQi/BCL-Starter-kit?node-id=5976%3A68483",
54
+ },
55
+ ],
56
+ },
57
+ };
58
+
59
+ export const Default = (args) =>
60
+ descriptionList(applyArgs(correctPaths(demoData), args));
61
+ Default.args = getArgs(demoData);
62
+ Default.argTypes = getArgTypes(demoData);
63
+ Default.argTypes.col_classes.table = { disable: true };
64
+
65
+ export const Horizontal = (args) =>
66
+ descriptionList(applyArgs(correctPaths(demoDataHorizontal), args));
67
+
68
+ Horizontal.storyName = "Horizontal";
69
+ Horizontal.args = getArgs(demoDataHorizontal);
70
+ Horizontal.argTypes = getArgTypes(demoDataHorizontal);
@@ -0,0 +1,165 @@
1
+ import {
2
+ renderTwigFileAsNode,
3
+ renderTwigFileAsHtml,
4
+ } from "@openeuropa/bcl-test-utils";
5
+ import { axe, toHaveNoViolations } from "jest-axe";
6
+ import drupalAttribute from "drupal-attribute";
7
+
8
+ import demoData from "@openeuropa/bcl-description-list/data/data";
9
+ import demoDataHorizontal from "@openeuropa/bcl-description-list/data/data--horizontal";
10
+
11
+ const template = "@oe-bcl/bcl-description-list/description-list.html.twig";
12
+
13
+ const render = (params) => renderTwigFileAsNode(template, params);
14
+
15
+ expect.extend(toHaveNoViolations);
16
+
17
+ describe("OE - Description List", () => {
18
+ test(`renders correctly`, () => {
19
+ expect.assertions(1);
20
+ return expect(render(demoData)).resolves.toMatchSnapshot();
21
+ });
22
+
23
+ test(`horizontal renders correctly`, () => {
24
+ expect.assertions(1);
25
+ return expect(render(demoDataHorizontal)).resolves.toMatchSnapshot();
26
+ });
27
+
28
+ test(`passes the accessibility tests`, async () => {
29
+ expect(
30
+ await axe(renderTwigFileAsHtml(template, demoData, true))
31
+ ).toHaveNoViolations();
32
+ });
33
+
34
+ test(`horizontal passes the accessibility tests`, async () => {
35
+ expect(
36
+ await axe(renderTwigFileAsHtml(template, demoDataHorizontal, true))
37
+ ).toHaveNoViolations();
38
+ });
39
+ });
40
+
41
+ describe("OE - Description List with title", () => {
42
+ test(`renders correctly`, () => {
43
+ expect.assertions(1);
44
+ return expect(
45
+ render({
46
+ ...demoData,
47
+ title: "Description list test title",
48
+ title_tag: "h6",
49
+ })
50
+ ).resolves.toMatchSnapshot();
51
+ });
52
+
53
+ test(`bordered renders correctly`, () => {
54
+ expect.assertions(1);
55
+ return expect(
56
+ render({
57
+ ...demoData,
58
+ title: "Description list test title",
59
+ title_tag: "h6",
60
+ bordered: true,
61
+ })
62
+ ).resolves.toMatchSnapshot();
63
+ });
64
+
65
+ test(`horizontal renders correctly`, () => {
66
+ expect.assertions(1);
67
+ return expect(
68
+ render({
69
+ ...demoDataHorizontal,
70
+ title: "Description list test title",
71
+ title_tag: "h6",
72
+ })
73
+ ).resolves.toMatchSnapshot();
74
+ });
75
+
76
+ test(`horizontal with different col size renders correctly`, () => {
77
+ expect.assertions(1);
78
+ return expect(
79
+ render({
80
+ ...demoDataHorizontal,
81
+ horizontal_size: "8-4",
82
+ title: "Description list test title",
83
+ title_tag: "h6",
84
+ })
85
+ ).resolves.toMatchSnapshot();
86
+ });
87
+
88
+ test(`horizontal and bordered renders correctly`, () => {
89
+ expect.assertions(1);
90
+ return expect(
91
+ render({
92
+ ...demoDataHorizontal,
93
+ bordered: true,
94
+ title: "Description list test title",
95
+ title_tag: "h6",
96
+ })
97
+ ).resolves.toMatchSnapshot();
98
+ });
99
+
100
+ test(`with inline icon renders correctly`, () => {
101
+ expect.assertions(1);
102
+ return expect(
103
+ render({
104
+ items: [
105
+ {
106
+ term: '<svg class="me-2 bi icon--fluid"><use xlink:href="/icons.svg#printer-fill"></use></svg>Only title <strong>label</strong> with inline icon',
107
+ definition:
108
+ '<svg class="me-2 bi icon--fluid"><use xlink:href="/icons.svg#printer-fill"></use></svg>Description text goes here.',
109
+ },
110
+ ],
111
+ })
112
+ ).resolves.toMatchSnapshot();
113
+ });
114
+
115
+ test(`with new classes on term icon renders correctly`, () => {
116
+ expect.assertions(1);
117
+ return expect(
118
+ render({
119
+ items: [
120
+ {
121
+ term: [
122
+ {
123
+ label:
124
+ "<p class='mb-0'>Only title label with <em>icon</em></p>",
125
+ icon: {
126
+ name: "geo-alt-fill",
127
+ size: "xs",
128
+ path: "/icons.svg",
129
+ attributes: new drupalAttribute().addClass("new-class"),
130
+ },
131
+ },
132
+ ],
133
+ definition:
134
+ "Long Description text goes here.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin dignissim, quam at sollicitudin volutpat, ipsum arcu maximus massa, quis egestas diam tellus vitae nulla.",
135
+ },
136
+ ],
137
+ })
138
+ ).resolves.toMatchSnapshot();
139
+ });
140
+
141
+ test(`with new classes on definition icon renders correctly`, () => {
142
+ expect.assertions(1);
143
+ return expect(
144
+ render({
145
+ items: [
146
+ {
147
+ term: "Term title",
148
+ definition: [
149
+ {
150
+ label:
151
+ "<p class='mb-0'>Only title label with <em>icon</em></p>",
152
+ icon: {
153
+ name: "geo-alt-fill",
154
+ size: "xs",
155
+ path: "/icons.svg",
156
+ attributes: new drupalAttribute().addClass("new-class"),
157
+ },
158
+ },
159
+ ],
160
+ },
161
+ ],
162
+ })
163
+ ).resolves.toMatchSnapshot();
164
+ });
165
+ });
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@openeuropa/bcl-description-list",
3
+ "author": "European Commission",
4
+ "license": "EUPL-1.2",
5
+ "version": "0.1.202408021145",
6
+ "description": "OE - BCL description-list",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "dependencies": {
11
+ "@openeuropa/bcl-heading": "^0.1.202408021145",
12
+ "@openeuropa/bcl-icon": "^0.1.202408021145"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/openeuropa/bootstrap-component-library.git"
17
+ },
18
+ "bugs": {
19
+ "url": "https://github.com/openeuropa/bootstrap-component-library.git/issues"
20
+ },
21
+ "homepage": "https://github.com/openeuropa/bootstrap-component-library",
22
+ "keywords": [
23
+ "openeuropa",
24
+ "bootstrap-component-library",
25
+ "design-system",
26
+ "twig"
27
+ ],
28
+ "gitHead": "7ee2013f7f64a70ddfa35228a9a65967dd71eec3"
29
+ }