@openeuropa/bcl-textarea 0.1.2 → 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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/textarea.html.twig +81 -50
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@openeuropa/bcl-textarea",
3
3
  "author": "European Commission",
4
4
  "license": "EUPL-1.2",
5
- "version": "0.1.2",
5
+ "version": "0.1.202408021145",
6
6
  "publishConfig": {
7
7
  "access": "public"
8
8
  },
@@ -21,5 +21,5 @@
21
21
  "design-system",
22
22
  "twig"
23
23
  ],
24
- "gitHead": "b242dcb5ed9578fcd212c98cf722eabc845d313b"
24
+ "gitHead": "7ee2013f7f64a70ddfa35228a9a65967dd71eec3"
25
25
  }
@@ -1,47 +1,56 @@
1
- {% spaceless %}
1
+ {% apply spaceless %}
2
2
 
3
3
  {#
4
4
  Parameters:
5
- - "id" (string) (default: '')
6
- - "label" (string) (default: '')
7
- - "disabled" (boolean) (default: false)
8
- - "invalid" (boolean) (default: false)
9
- - "required" (boolean) (default: false)
10
- - "readonly" (boolean) (default: false)
11
- - "rows" (int) (default: 4)
12
- - "helper_text" (string) (default: '')
13
- - "helper_text_id" (string) (default: '')
14
- - "hidden_label" (boolean) (default: false)
15
- - "floating" (boolean) (default: false)
16
- - "horizontal" (boolean) (default: false)
17
- - "horizontal_class" (string) (default: col-sm-10)
18
- - "size" (string) (default: '')
5
+ - id (string) (default: '')
6
+ - label (string) (default: '')
7
+ - required (boolean) (default: false)
8
+ - disabled (boolean) (default: false)
9
+ - readonly (boolean) (default: false)
10
+ - invalid (boolean) (default: false)
11
+ - valid (boolean) (default: false)
12
+ - invalid_feedback (string) (default: '')
13
+ - valid_feedback (string) (default: '')
14
+ - helper_text (string) (default: '')
15
+ - helper_text_id (string) (default: '')
16
+ - hidden_label (boolean) (default: false)
17
+ - text (string) (default: '')
18
+ - rows (int) (default: 4)
19
+ - floating (boolean) (default: false)
20
+ - horizontal (boolean) (default: false)
21
+ - horizontal_class (string) (default: col-sm-10)
22
+ - horizontal_label_class (string) (default: col-sm-2)
23
+ - attributes (drupal attrs)
19
24
  #}
20
25
 
21
26
  {% set _id = id|default('') %}
22
- {% set _size = size|default('') %}
23
27
  {% set _label = label|default('') %}
24
- {% set _required = required|default(false) %}
25
- {% set _disabled = disabled|default(false) %}
26
- {% set _readonly = readonly|default(false) %}
27
- {% set _invalid = invalid|default(false) %}
28
- {% set _floating = floating|default(false) %}
28
+ {% set _required = required ?? false %}
29
+ {% set _disabled = disabled ?? false %}
30
+ {% set _readonly = readonly ?? false %}
31
+ {% set _invalid = invalid ?? false %}
32
+ {% set _valid = valid ?? false %}
33
+ {% set _invalid_feedback = invalid_feedback|default('') %}
34
+ {% set _valid_feedback = valid_feedback|default('') %}
29
35
  {% set _helper_text = helper_text|default('') %}
30
36
  {% set _helper_text_id = helper_text_id|default('') %}
31
- {% set _hidden_label = hidden_label|default(false) %}
32
- {% set _horizontal = horizontal|default(false) %}
37
+ {% set _hidden_label = hidden_label ?? false %}
38
+ {% set _text = text|default('') %}
39
+ {% set _rows = rows|default('4') %}
40
+ {% set _floating = floating ?? false %}
41
+ {% set _horizontal = horizontal ?? false %}
33
42
  {% set _horizontal_class = horizontal_class|default('col-sm-10') %}
34
43
  {% set _horizontal_label_class = horizontal_label_class|default('col-sm-2') %}
44
+
35
45
  {% set _label_block = false %}
36
46
  {% set _label_class = 'form-label' %}
37
- {% set _class = 'form-control' %}
47
+ {% set _classes = ['form-control'] %}
38
48
 
39
- {% set _rows = rows|default('4') %}
40
- {% if _size is not empty %}
41
- {% set _class = _class ~ " form-control-" ~ size %}
42
- {% endif %}
43
49
  {% if _invalid is not empty %}
44
- {% set _class = _class ~ " is-invalid" %}
50
+ {% set _classes = _classes|merge(['is-invalid']) %}
51
+ {% endif %}
52
+ {% if _valid is not empty %}
53
+ {% set _classes = _classes|merge(['is-valid']) %}
45
54
  {% endif %}
46
55
  {% set _placeholder = placeholder|default('') %}
47
56
  {% if _horizontal %}
@@ -51,6 +60,36 @@
51
60
  {% set _label_class = _label_class ~ ' visually-hidden' %}
52
61
  {% endif %}
53
62
 
63
+ {% if attributes is empty %}
64
+ {% set attributes = create_attribute() %}
65
+ {% endif %}
66
+
67
+ {% set attributes = attributes.addClass(_classes).setAttribute('rows', _rows) %}
68
+
69
+ {% if _id %}
70
+ {% set attributes = attributes.setAttribute('id', _id) %}
71
+ {% endif %}
72
+
73
+ {% if _required %}
74
+ {% set attributes = attributes.setAttribute('required', true) %}
75
+ {% endif %}
76
+
77
+ {% if _disabled %}
78
+ {% set attributes = attributes.setAttribute('disabled', true) %}
79
+ {% endif %}
80
+
81
+ {% if _readonly %}
82
+ {% set attributes = attributes.setAttribute('readonly', true) %}
83
+ {% endif %}
84
+
85
+ {% if _placeholder is not empty %}
86
+ {% set attributes = attributes.setAttribute('placeholder', _placeholder) %}
87
+ {% endif %}
88
+
89
+ {% if _helper_text_id is not empty %}
90
+ {% set attributes = attributes.setAttribute('aria-describedby', _helper_text_id) %}
91
+ {% endif %}
92
+
54
93
  {% if _floating or _horizontal %}
55
94
  {% set _wrapper_class = _floating ? 'form-floating' : 'row' %}
56
95
  <div class="{{ _wrapper_class }}">
@@ -75,27 +114,9 @@
75
114
  <div class="{{ _horizontal_class }}">
76
115
  {% endif %}
77
116
  <textarea
78
- class="{{ _class }}"
79
- {% if _id %}
80
- id="{{ _id }}"
81
- {% endif %}
82
- {% if _required %}
83
- required
84
- {% endif %}
85
- {% if _disabled %}
86
- disabled
87
- {% endif %}
88
- {% if _readonly %}
89
- readonly
90
- {% endif %}
91
- rows="{{ _rows }}"
92
- {% if _placeholder is not empty %}
93
- placeholder="{{ _placeholder }}"
94
- {% endif %}
95
- {% if _helper_text_id is not empty %}
96
- aria-describedby="{{ _helper_text_id }}"
97
- {% endif %}
117
+ {{ attributes }}
98
118
  >
119
+ {{- _text -}}
99
120
  </textarea>
100
121
  {% if _horizontal and floating == false %}
101
122
  </div>
@@ -103,6 +124,16 @@
103
124
  {% if _label_block and _floating %}
104
125
  {{ _label_block|raw }}
105
126
  {% endif %}
127
+ {% if _invalid_feedback is not empty %}
128
+ <div class="invalid-feedback">
129
+ {{- _invalid_feedback -}}
130
+ </div>
131
+ {% endif %}
132
+ {% if _valid_feedback is not empty %}
133
+ <div class="valid-feedback">
134
+ {{- _valid_feedback -}}
135
+ </div>
136
+ {% endif %}
106
137
  {% if _helper_text is not empty %}
107
138
  <div
108
139
  class="form-text"
@@ -115,4 +146,4 @@
115
146
  {% if _floating or _horizontal %}
116
147
  </div>
117
148
  {% endif %}
118
- {% endspaceless %}
149
+ {% endapply %}