basecoat-cli 0.3.9 → 0.3.10-beta.1
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/dist/assets/jinja/carousel.html.jinja +111 -0
- package/dist/assets/jinja/select.html.jinja +48 -20
- package/dist/assets/js/all.js +159 -25
- package/dist/assets/js/all.min.js +1 -1
- package/dist/assets/js/carousel.js +192 -0
- package/dist/assets/js/carousel.min.js +1 -0
- package/dist/assets/js/select.js +159 -25
- package/dist/assets/js/select.min.js +1 -1
- package/dist/assets/nunjucks/carousel.njk +111 -0
- package/dist/assets/nunjucks/select.njk +48 -20
- package/package.json +1 -1
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
Renders a select or combobox component.
|
|
3
3
|
|
|
4
4
|
@param id {string} [optional] - Unique identifier for the select component.
|
|
5
|
-
@param selected {string} [optional] - The initially selected value.
|
|
5
|
+
@param selected {string|array} [optional] - The initially selected value(s).
|
|
6
6
|
@param name {string} [optional] - The name attribute for the hidden input storing the selected value.
|
|
7
|
+
@param multiple {boolean} [optional] [default=false] - Enables multiple selection mode.
|
|
8
|
+
@param placeholder {string} [optional] - Placeholder text shown when no options are selected (multiple mode only).
|
|
7
9
|
@param main_attrs {object} [optional] - Additional HTML attributes for the main container div.
|
|
8
10
|
@param trigger_attrs {object} [optional] - Additional HTML attributes for the trigger button.
|
|
9
11
|
@param popover_attrs {object} [optional] - Additional HTML attributes for the popover content div.
|
|
@@ -17,6 +19,8 @@
|
|
|
17
19
|
selected=None,
|
|
18
20
|
name=None,
|
|
19
21
|
items=None,
|
|
22
|
+
multiple=false,
|
|
23
|
+
placeholder=None,
|
|
20
24
|
main_attrs={},
|
|
21
25
|
trigger_attrs={},
|
|
22
26
|
popover_attrs={},
|
|
@@ -27,8 +31,9 @@
|
|
|
27
31
|
) %}
|
|
28
32
|
{% set id = id or ("select-" + (range(100000, 999999) | random | string)) %}
|
|
29
33
|
|
|
34
|
+
{% set selectedArray = ((selected if (selected is iterable and selected is not string) else [selected]) if selected else []) %}
|
|
30
35
|
{% set first_option = [] %}
|
|
31
|
-
{% set
|
|
36
|
+
{% set selected_options = [] %}
|
|
32
37
|
|
|
33
38
|
{% if items %}
|
|
34
39
|
{% for item in items %}
|
|
@@ -37,33 +42,41 @@
|
|
|
37
42
|
{% if not first_option[0] %}
|
|
38
43
|
{% set first_option = (first_option.push(sub_item), first_option) %}
|
|
39
44
|
{% endif %}
|
|
40
|
-
{% if
|
|
41
|
-
{% set
|
|
45
|
+
{% if sub_item.value in selectedArray %}
|
|
46
|
+
{% set selected_options = (selected_options.push(sub_item), selected_options) %}
|
|
42
47
|
{% endif %}
|
|
43
48
|
{% endfor %}
|
|
44
49
|
{% else %}
|
|
45
50
|
{% if not first_option[0] %}
|
|
46
51
|
{% set first_option = (first_option.push(item), first_option) %}
|
|
47
52
|
{% endif %}
|
|
48
|
-
{% if
|
|
49
|
-
{% set
|
|
53
|
+
{% if item.value in selectedArray %}
|
|
54
|
+
{% set selected_options = (selected_options.push(item), selected_options) %}
|
|
50
55
|
{% endif %}
|
|
51
56
|
{% endif %}
|
|
52
57
|
{% endfor %}
|
|
53
58
|
{% endif %}
|
|
54
59
|
|
|
55
|
-
{% set default_option =
|
|
60
|
+
{% set default_option = (selected_options[0] if selected_options[0] else (first_option[0] if first_option[0] else None)) %}
|
|
61
|
+
{% set labels = [] %}
|
|
62
|
+
{% if multiple and selected_options %}
|
|
63
|
+
{% for opt in selected_options %}
|
|
64
|
+
{% set labels = (labels.push(opt.label), labels) %}
|
|
65
|
+
{% endfor %}
|
|
66
|
+
{% endif %}
|
|
67
|
+
{% set default_label = (labels | join(', ') if (multiple and selected_options) else ((placeholder or '') if (multiple and not selected_options) else (default_option.label if default_option else ''))) %}
|
|
56
68
|
|
|
57
69
|
<div
|
|
58
70
|
id="{{ id }}"
|
|
59
71
|
class="select {{ main_attrs.class }}"
|
|
72
|
+
{% if multiple and placeholder %}data-placeholder="{{ placeholder }}"{% endif %}
|
|
60
73
|
{% for key, value in main_attrs %}
|
|
61
74
|
{% if key != 'class' %}{{ key }}="{{ value }}"{% endif %}
|
|
62
75
|
{% endfor %}
|
|
63
76
|
>
|
|
64
77
|
<button
|
|
65
78
|
type="button"
|
|
66
|
-
class="btn-outline
|
|
79
|
+
class="btn-outline {{ trigger_attrs.class }}"
|
|
67
80
|
id="{{ id }}-trigger"
|
|
68
81
|
aria-haspopup="listbox"
|
|
69
82
|
aria-expanded="false"
|
|
@@ -72,7 +85,7 @@
|
|
|
72
85
|
{% if key != 'class' %}{{ key }}="{{ value }}"{% endif %}
|
|
73
86
|
{% endfor %}
|
|
74
87
|
>
|
|
75
|
-
<span class="truncate">{{
|
|
88
|
+
<span class="truncate">{{ default_label }}</span>
|
|
76
89
|
{% if is_combobox %}
|
|
77
90
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-chevrons-up-down-icon lucide-chevrons-up-down text-muted-foreground opacity-50 shrink-0"><path d="m7 15 5 5 5-5"/><path d="m7 9 5-5 5 5"/></svg>
|
|
78
91
|
{% else %}
|
|
@@ -110,25 +123,40 @@
|
|
|
110
123
|
id="{{ id }}-listbox"
|
|
111
124
|
aria-orientation="vertical"
|
|
112
125
|
aria-labelledby="{{ id }}-trigger"
|
|
126
|
+
{% if multiple %}aria-multiselectable="true"{% endif %}
|
|
113
127
|
{% for key, value in listbox_attrs %}
|
|
114
128
|
{{ key }}="{{ value }}"
|
|
115
129
|
{% endfor %}
|
|
116
130
|
>
|
|
117
131
|
{% if items and items.length > 0 %}
|
|
118
|
-
{{ render_select_items(items,
|
|
132
|
+
{{ render_select_items(items, selectedArray, id ~ "-items" if id else "items") }}
|
|
119
133
|
{% else %}
|
|
120
134
|
{{ caller() if caller }}
|
|
121
135
|
{% endif %}
|
|
122
136
|
</div>
|
|
123
137
|
</div>
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
138
|
+
{% if multiple and selectedArray %}
|
|
139
|
+
{% for val in selectedArray %}
|
|
140
|
+
<input
|
|
141
|
+
type="hidden"
|
|
142
|
+
name="{{ name or id ~ '-value' }}"
|
|
143
|
+
value="{{ val }}"
|
|
144
|
+
{% if loop.index0 > 0 %}id="{{ id }}-value-{{ loop.index0 }}"{% endif %}
|
|
145
|
+
{% for key, value in input_attrs %}
|
|
146
|
+
{% if key != 'name' and key != 'value' %}{{ key }}="{{ value }}"{% endif %}
|
|
147
|
+
{% endfor %}
|
|
148
|
+
>
|
|
130
149
|
{% endfor %}
|
|
131
|
-
|
|
150
|
+
{% else %}
|
|
151
|
+
<input
|
|
152
|
+
type="hidden"
|
|
153
|
+
name="{{ name or id ~ '-value' }}"
|
|
154
|
+
value="{{ (default_option.value if default_option) or '' }}"
|
|
155
|
+
{% for key, value in input_attrs %}
|
|
156
|
+
{% if key != 'name' and key != 'value' %}{{ key }}="{{ value }}"{% endif %}
|
|
157
|
+
{% endfor %}
|
|
158
|
+
>
|
|
159
|
+
{% endif %}
|
|
132
160
|
</div>
|
|
133
161
|
{% endmacro %}
|
|
134
162
|
|
|
@@ -138,7 +166,7 @@
|
|
|
138
166
|
@param items {array} - The array of items to render.
|
|
139
167
|
@param parent_id_prefix {string} [optional] - The prefix for the item id.
|
|
140
168
|
#}
|
|
141
|
-
{% macro render_select_items(items,
|
|
169
|
+
{% macro render_select_items(items, selectedArray, parent_id_prefix="items") %}
|
|
142
170
|
{% for item in items %}
|
|
143
171
|
{% set item_id = parent_id_prefix ~ "-" ~ loop.index %}
|
|
144
172
|
{% if item.type == "group" %}
|
|
@@ -153,7 +181,7 @@
|
|
|
153
181
|
{% endif %}
|
|
154
182
|
>
|
|
155
183
|
<div role="heading" id="{{ group_label_id }}">{{ item.label }}</div>
|
|
156
|
-
{{ render_select_items(item.items,
|
|
184
|
+
{{ render_select_items(item.items, selectedArray, item_id) if item.items }}
|
|
157
185
|
</div>
|
|
158
186
|
{% elif item.type == "separator" %}
|
|
159
187
|
<hr role="separator" />
|
|
@@ -162,7 +190,7 @@
|
|
|
162
190
|
id="{{ item_id }}"
|
|
163
191
|
role="option"
|
|
164
192
|
data-value="{{ item.value }}"
|
|
165
|
-
{% if
|
|
193
|
+
{% if item.value in selectedArray %}aria-selected="true"{% endif %}
|
|
166
194
|
{% if item.attrs %}
|
|
167
195
|
{% for key, value in item.attrs %}
|
|
168
196
|
{{ key }}="{{ value }}"
|