basecoat-css 1.0.0-beta.6 → 1.0.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.
Files changed (62) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +82 -35
  3. package/dist/base/base.css +3 -45
  4. package/dist/basecoat-base.cdn.css +226 -22
  5. package/dist/basecoat-base.cdn.min.css +1 -1
  6. package/dist/basecoat-compat.cdn.css +16 -20
  7. package/dist/basecoat-compat.cdn.min.css +1 -1
  8. package/dist/basecoat-components.css +2 -0
  9. package/dist/basecoat-luma.cdn.css +375 -91
  10. package/dist/basecoat-luma.cdn.min.css +1 -1
  11. package/dist/basecoat-lyra.cdn.css +358 -96
  12. package/dist/basecoat-lyra.cdn.min.css +1 -1
  13. package/dist/basecoat-maia.cdn.css +364 -84
  14. package/dist/basecoat-maia.cdn.min.css +1 -1
  15. package/dist/basecoat-mira.cdn.css +366 -94
  16. package/dist/basecoat-mira.cdn.min.css +1 -1
  17. package/dist/basecoat-nova.cdn.css +369 -96
  18. package/dist/basecoat-nova.cdn.min.css +1 -1
  19. package/dist/basecoat-rhea.cdn.css +376 -91
  20. package/dist/basecoat-rhea.cdn.min.css +1 -1
  21. package/dist/basecoat-sera.cdn.css +342 -71
  22. package/dist/basecoat-sera.cdn.min.css +1 -1
  23. package/dist/basecoat-vega.cdn.css +366 -92
  24. package/dist/basecoat-vega.cdn.min.css +1 -1
  25. package/dist/basecoat.cdn.css +366 -92
  26. package/dist/basecoat.cdn.min.css +1 -1
  27. package/dist/compat/legacy.css +19 -1
  28. package/dist/components/drawer.css +89 -0
  29. package/dist/components/input-group.css +1 -1
  30. package/dist/components/scrollbar.css +46 -0
  31. package/dist/components/select.css +16 -16
  32. package/dist/js/all.js +85 -0
  33. package/dist/js/all.min.js +1 -1
  34. package/dist/js/drawer.js +84 -0
  35. package/dist/js/drawer.min.js +1 -0
  36. package/dist/styles/luma.css +47 -14
  37. package/dist/styles/lyra.css +64 -14
  38. package/dist/styles/maia.css +47 -14
  39. package/dist/styles/mira.css +48 -15
  40. package/dist/styles/nova.css +64 -14
  41. package/dist/styles/rhea.css +47 -14
  42. package/dist/styles/sera.css +66 -16
  43. package/dist/styles/vega.css +64 -14
  44. package/package.json +28 -6
  45. package/templates/jinja/combobox.html.jinja +147 -0
  46. package/templates/jinja/command.html.jinja +210 -0
  47. package/templates/jinja/dialog.html.jinja +97 -0
  48. package/templates/jinja/dropdown-menu.html.jinja +130 -0
  49. package/templates/jinja/popover.html.jinja +51 -0
  50. package/templates/jinja/select.html.jinja +191 -0
  51. package/templates/jinja/sidebar.html.jinja +149 -0
  52. package/templates/jinja/tabs.html.jinja +82 -0
  53. package/templates/jinja/toast.html.jinja +139 -0
  54. package/templates/nunjucks/combobox.njk +157 -0
  55. package/templates/nunjucks/command.njk +203 -0
  56. package/templates/nunjucks/dialog.njk +92 -0
  57. package/templates/nunjucks/dropdown-menu.njk +125 -0
  58. package/templates/nunjucks/popover.njk +48 -0
  59. package/templates/nunjucks/select.njk +184 -0
  60. package/templates/nunjucks/sidebar.njk +144 -0
  61. package/templates/nunjucks/tabs.njk +39 -0
  62. package/templates/nunjucks/toast.njk +137 -0
@@ -0,0 +1,191 @@
1
+ {#
2
+ Renders a select component.
3
+
4
+ @param id {string} [optional] - Unique identifier for the select component.
5
+ @param selected {string|array} [optional] - The initially selected value(s).
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 option is selected.
9
+ @param close_on_select {boolean} [optional] [default=false] - Closes the popover when selecting an option in multiple mode.
10
+ @param format {string} [optional] [default="value"] - Hidden input serialization format: "value" or "object".
11
+ @param main_attrs {object} [optional] - Additional HTML attributes for the main container div.
12
+ @param trigger_attrs {object} [optional] - Additional HTML attributes for the trigger button.
13
+ @param popover_attrs {object} [optional] - Additional HTML attributes for the popover content div.
14
+ @param listbox_attrs {object} [optional] - Additional HTML attributes for the listbox div.
15
+ @param input_attrs {object} [optional] - Additional HTML attributes for the hidden input.
16
+ #}
17
+ {% macro select(
18
+ id=None,
19
+ selected=None,
20
+ name=None,
21
+ items=[],
22
+ multiple=false,
23
+ placeholder=None,
24
+ close_on_select=false,
25
+ format="value",
26
+ main_attrs={},
27
+ trigger_attrs={},
28
+ popover_attrs={},
29
+ listbox_attrs={},
30
+ input_attrs={}
31
+ ) %}
32
+ {% set id = id or ("select-" + (range(100000, 999999) | random | string)) %}
33
+ {% set main_attrs = main_attrs or {} %}
34
+ {% set trigger_attrs = trigger_attrs or {} %}
35
+ {% set popover_attrs = popover_attrs or {} %}
36
+ {% set listbox_attrs = listbox_attrs or {} %}
37
+ {% set input_attrs = input_attrs or {} %}
38
+
39
+ {% if selected is defined and selected is not none and selected is iterable and selected is not string %}
40
+ {% set selectedArray = selected %}
41
+ {% elif selected is defined and selected is not none %}
42
+ {% set selectedArray = [selected] %}
43
+ {% else %}
44
+ {% set selectedArray = [] %}
45
+ {% endif %}
46
+ {% set first_option = namespace(item=None) %}
47
+ {% set selected_options = namespace(items=[]) %}
48
+
49
+ {% if items %}
50
+ {% for item in items %}
51
+ {% set item_type = item.type | default("item") %}
52
+ {% if item_type == "group" %}
53
+ {% for sub_item in item.get('items', []) %}
54
+ {% if not first_option.item %}
55
+ {% set first_option.item = sub_item %}
56
+ {% endif %}
57
+ {% if sub_item.value in selectedArray %}
58
+ {% set selected_options.items = selected_options.items + [sub_item] %}
59
+ {% endif %}
60
+ {% endfor %}
61
+ {% else %}
62
+ {% if not first_option.item %}
63
+ {% set first_option.item = item %}
64
+ {% endif %}
65
+ {% if item.value in selectedArray %}
66
+ {% set selected_options.items = selected_options.items + [item] %}
67
+ {% endif %}
68
+ {% endif %}
69
+ {% endfor %}
70
+ {% endif %}
71
+
72
+ {% set default_option = (selected_options.items[0] if selected_options.items else (none if placeholder else first_option.item)) %}
73
+ {% set labels = [] %}
74
+ {% if multiple and selected_options.items %}
75
+ {% for opt in selected_options.items %}
76
+ {% set labels = labels + [opt.label] %}
77
+ {% endfor %}
78
+ {% endif %}
79
+ {% set default_label = (', '.join(labels) if (multiple and selected_options.items) else ((placeholder or '') if (placeholder and not selected_options.items) else (default_option.label if default_option else ''))) %}
80
+ {% set selected_payload = namespace(items=[]) %}
81
+ {% if multiple and selected_options.items %}
82
+ {% for opt in selected_options.items %}
83
+ {% set selected_payload.items = selected_payload.items + [{'value': opt.value, 'label': opt.label}] %}
84
+ {% endfor %}
85
+ {% elif default_option %}
86
+ {% set selected_payload.items = [{'value': default_option.value, 'label': default_option.label}] %}
87
+ {% endif %}
88
+
89
+ <div
90
+ id="{{ id }}"
91
+ class="select {{ main_attrs.class | default('') }}"
92
+ {% if format == "object" %}data-format="object"{% endif %}
93
+ {% if placeholder %}data-placeholder="{{ placeholder }}"{% endif %}
94
+ {% if multiple and close_on_select %}data-close-on-select="true"{% endif %}
95
+ {% for key, value in main_attrs.items() %}
96
+ {% if key != 'class' %}{{ key }}="{{ value }}"{% endif %}
97
+ {% endfor %}
98
+ >
99
+ <button
100
+ type="button"
101
+ class="{{ trigger_attrs.class | default('') }}"
102
+ id="{{ id }}-trigger"
103
+ aria-haspopup="listbox"
104
+ aria-expanded="false"
105
+ aria-controls="{{ id }}-listbox"
106
+ {% for key, value in trigger_attrs.items() %}
107
+ {% if key != 'class' %}{{ key }}="{{ value }}"{% endif %}
108
+ {% endfor %}
109
+ >
110
+ <span class="truncate">{{ default_label }}</span>
111
+ <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-chevron-down-icon lucide-chevron-down text-muted-foreground opacity-50 shrink-0"><path d="m6 9 6 6 6-6"/></svg>
112
+ </button>
113
+ <div
114
+ id="{{ id }}-popover"
115
+ data-popover
116
+ aria-hidden="true"
117
+ {% for key, value in popover_attrs.items() %}
118
+ {{ key }}="{{ value }}"
119
+ {% endfor %}
120
+ >
121
+ <div
122
+ role="listbox"
123
+ id="{{ id }}-listbox"
124
+ aria-orientation="vertical"
125
+ aria-labelledby="{{ id }}-trigger"
126
+ {% if multiple %}aria-multiselectable="true"{% endif %}
127
+ {% for key, value in listbox_attrs.items() %}
128
+ {{ key }}="{{ value }}"
129
+ {% endfor %}
130
+ >
131
+ {% if items %}
132
+ {{ render_select_items(items, selectedArray, id ~ "-items" if id else "items") }}
133
+ {% else %}
134
+ {{ caller() if caller is defined }}
135
+ {% endif %}
136
+ </div>
137
+ </div>
138
+ <input
139
+ type="hidden"
140
+ name="{{ name or id ~ '-value' }}"
141
+ value="{% if format == 'object' %}{{ (selected_payload.items if multiple else (selected_payload.items[0] if selected_payload.items else none)) | tojson }}{% elif multiple %}{{ selectedArray | tojson }}{% else %}{{ (default_option.value if default_option) or '' }}{% endif %}"
142
+ {% for key, value in input_attrs.items() %}
143
+ {% if key != 'name' and key != 'value' %}{{ key }}="{{ value }}"{% endif %}
144
+ {% endfor %}
145
+ >
146
+ </div>
147
+ {% endmacro %}
148
+
149
+ {#
150
+ Renders a list of items for the select component.
151
+
152
+ @param items {array} - The array of items to render.
153
+ @param parent_id_prefix {string} [optional] - The prefix for the item id.
154
+ #}
155
+ {% macro render_select_items(items, selectedArray, parent_id_prefix="items") %}
156
+ {% for item in items %}
157
+ {% set item_id = parent_id_prefix ~ "-" ~ loop.index %}
158
+ {% set item_type = item.type | default("item") %}
159
+ {% if item_type == "group" %}
160
+ {% set group_label_id = item.id | default("group-label-" + item_id) %}
161
+ <div
162
+ role="group"
163
+ aria-labelledby="{{ group_label_id }}"
164
+ {% if item.attrs is defined and item.attrs %}
165
+ {% for key, value in item.attrs.items() %}
166
+ {{ key }}="{{ value }}"
167
+ {% endfor %}
168
+ {% endif %}
169
+ >
170
+ <div role="heading" id="{{ group_label_id }}">{{ item.label | default('') }}</div>
171
+ {{ render_select_items(item.get('items', []), selectedArray, item_id) if item.get('items') }}
172
+ </div>
173
+ {% elif item_type == "separator" %}
174
+ <hr role="separator" />
175
+ {% elif item_type == "item" %}
176
+ <div
177
+ id="{{ item_id }}"
178
+ role="option"
179
+ {% if item.value is defined and item.value is not none %}data-value="{{ item.value }}"{% endif %}
180
+ {% if item.value is defined and item.value in selectedArray %}aria-selected="true"{% endif %}
181
+ {% if item.attrs is defined and item.attrs %}
182
+ {% for key, value in item.attrs.items() %}
183
+ {{ key }}="{{ value }}"
184
+ {% endfor %}
185
+ {% endif %}
186
+ >
187
+ {{ item.label | default(item.value | default('')) | safe }}
188
+ </div>
189
+ {% endif %}
190
+ {% endfor %}
191
+ {% endmacro %}
@@ -0,0 +1,149 @@
1
+ {#
2
+ Renders a sidebar component.
3
+
4
+ @param id {string} [optional] - Unique identifier for the sidebar component.
5
+ @param label {string} [optional] - Label for the sidebar navigation.
6
+ @param open {boolean} [optional] - Whether the sidebar is open.
7
+ @param side {string} [optional] - Side of the sidebar to display.
8
+ @param header {string} [optional] - Header content for the sidebar.
9
+ @param footer {string} [optional] - Footer content for the sidebar.
10
+ @param menu {array} [optional] - Array of menu items for the sidebar.
11
+ @param main_attrs {object} [optional] - Additional HTML attributes for the main container div.
12
+ @param header_attrs {object} [optional] - Additional HTML attributes for the header div.
13
+ @param content_attrs {object} [optional] - Additional HTML attributes for the content div.
14
+ @param footer_attrs {object} [optional] - Additional HTML attributes for the footer div.
15
+ #}
16
+ {% macro sidebar(
17
+ id=None,
18
+ label="Sidebar navigation",
19
+ open=true,
20
+ side=None,
21
+ header=None,
22
+ footer=None,
23
+ menu=None,
24
+ main_attrs={},
25
+ header_attrs={},
26
+ content_attrs={},
27
+ footer_attrs={}
28
+ ) %}
29
+ {% set main_attrs = main_attrs or {} %}
30
+ {% set header_attrs = header_attrs or {} %}
31
+ {% set content_attrs = content_attrs or {} %}
32
+ {% set footer_attrs = footer_attrs or {} %}
33
+ <aside
34
+ {% if id %}id="{{ id }}"{% endif %}
35
+ class="sidebar {{ main_attrs.class | default('') }}"
36
+ data-side="{{ side if side else "left" }}"
37
+ aria-hidden="{{ "true" if not open else "false" }}"
38
+ {{ "inert" if not open }}
39
+ {% for key, value in main_attrs.items() %}
40
+ {% if key != "class" %}{{ key }}="{{ value }}"{% endif %}
41
+ {% endfor %}
42
+ >
43
+ <nav
44
+ aria-label="{{ label }}"
45
+ >
46
+ {% if header %}
47
+ <header
48
+ {% for key, value in header_attrs.items() %}
49
+ {{ key }}="{{ value }}"
50
+ {% endfor %}
51
+ >
52
+ {{ header | safe }}
53
+ </header>
54
+ {% endif %}
55
+
56
+ <section
57
+ {% for key, value in content_attrs.items() %}
58
+ {{ key }}="{{ value }}"
59
+ {% endfor %}
60
+ >
61
+ {% if menu %}
62
+ {{ render_sidebar_content(menu, id ~ "-content" if id else "content") }}
63
+ {% else %}
64
+ {{ caller() if caller is defined }}
65
+ {% endif %}
66
+ </section>
67
+
68
+ {% if footer %}
69
+ <footer
70
+ {% for key, value in footer_attrs.items() %}
71
+ {{ key }}="{{ value }}"
72
+ {% endfor %}
73
+ >
74
+ {{ footer | safe }}
75
+ </footer>
76
+ {% endif %}
77
+ </nav>
78
+ </aside>
79
+ {% endmacro %}
80
+
81
+ {#
82
+ Renders sidebar content recursively (groups, items, submenus, separators).
83
+
84
+ @param items {array} - The array of items to render.
85
+ @param parent_id_prefix {string} [optional] - Prefix for generating element IDs.
86
+ #}
87
+ {% macro render_sidebar_content(items, parent_id_prefix="content") %}
88
+ {% for item in items %}
89
+ {% set item_id = parent_id_prefix ~ "-" ~ loop.index %}
90
+
91
+ {% set item_type = item.type | default("item") %}
92
+ {% if item_type == "group" %}
93
+ {% set group_label_id = item.id | default("group-label-" + item_id) %}
94
+ <div
95
+ role="group"
96
+ {% if item.label is defined and item.label %}aria-labelledby="{{ group_label_id }}"{% endif %}
97
+ {% if item.attrs is defined and item.attrs %}
98
+ {% for key, value in item.attrs.items() %}
99
+ {{ key }}="{{ value }}"
100
+ {% endfor %}
101
+ {% endif %}
102
+ >
103
+ {% if item.label is defined and item.label %}
104
+ <h3 id="{{ group_label_id }}">{{ item.label }}</h3>
105
+ {% endif %}
106
+ <ul>
107
+ {{ render_sidebar_content(item.get("items", []), item_id) if item.get("items") }}
108
+ </ul>
109
+ </div>
110
+ {% elif item_type == "separator" %}
111
+ <hr role="separator"/>
112
+ {% elif item_type == "submenu" %}
113
+ <li>
114
+ <details
115
+ id="submenu-{{ item_id }}"
116
+ {{ "open" if item.open is defined and item.open }}
117
+ {% if item.attrs is defined and item.attrs %}
118
+ {% for key, value in item.attrs.items() %}
119
+ {% if key != "open" %}{{ key }}="{{ value }}"{% endif %}
120
+ {% endfor %}
121
+ {% endif %}
122
+ >
123
+ <summary aria-controls="submenu-{{ item_id }}-content">
124
+ {% if item.icon is defined and item.icon %}{{ item.icon | safe }}{% endif %}
125
+ <span>{{ item.label | default('') | safe }}</span>
126
+ </summary>
127
+ <ul id="submenu-{{ item_id }}-content">
128
+ {{ render_sidebar_content(item.get("items", []), item_id) if item.get("items") }}
129
+ </ul>
130
+ </details>
131
+ </li>
132
+ {% elif item_type == "item" %}
133
+ <li>
134
+ <a
135
+ href="{{ item.url | default('#') }}"
136
+ {% if item.current is defined and item.current %}aria-current="page"{% endif %}
137
+ {% if item.attrs is defined and item.attrs %}
138
+ {% for key, value in item.attrs.items() %}
139
+ {% if key != "href" and key != "aria-current" %}{{ key }}="{{ value }}"{% endif %}
140
+ {% endfor %}
141
+ {% endif %}
142
+ >
143
+ {% if item.icon is defined and item.icon %}{{ item.icon | safe }}{% endif %}
144
+ <span>{{ item.label | default('') | safe }}</span>
145
+ </a>
146
+ </li>
147
+ {% endif %}
148
+ {% endfor %}
149
+ {% endmacro %}
@@ -0,0 +1,82 @@
1
+ {#
2
+ Renders a tabs component.
3
+
4
+ @param id {string} - Unique identifier for the tabs component.
5
+ @param tabsets {array} - An array of objects, each representing a tab and its panel.
6
+ Each object should have:
7
+ - tab {string}: HTML content for the tab button.
8
+ - panel {string} [optional]: HTML content for the tab panel.
9
+ - tab_attrs {object} [optional]: Additional HTML attributes for the tab button.
10
+ - panel_attrs {object} [optional]: Additional HTML attributes for the tab panel div.
11
+ @param main_attrs {object} [optional] - Additional HTML attributes for the main container div.
12
+ @param tablist_attrs {object} [optional] - Additional HTML attributes for the tablist nav element.
13
+ Set aria-orientation="vertical" for vertical tabs or data-variant="line" for line tabs.
14
+ @param default_tab_index {number} [optional] [default=1] - The 1-based index of the tab to be active initially.
15
+ #}
16
+ {% macro tabs(
17
+ id=None,
18
+ tabsets=[],
19
+ main_attrs={},
20
+ tablist_attrs={},
21
+ default_tab_index=1
22
+ )
23
+ %}
24
+ {% set id = id or ("tabs-" + (range(100000, 999999) | random | string)) %}
25
+ {% set main_attrs = main_attrs or {} %}
26
+ {% set tablist_attrs = tablist_attrs or {} %}
27
+ {% set orientation = tablist_attrs.get('aria-orientation', 'horizontal') %}
28
+ <div
29
+ class="tabs {{ main_attrs.class | default('') }}"
30
+ id="{{ id }}"
31
+ {% for key, value in main_attrs.items() %}
32
+ {% if key != 'class' %}{{ key }}="{{ value }}"{% endif %}
33
+ {% endfor %}
34
+ >
35
+ <nav
36
+ role="tablist"
37
+ aria-orientation="{{ orientation }}"
38
+ {% for key, value in tablist_attrs.items() %}
39
+ {% if key != 'aria-orientation' %}{{ key }}="{{ value }}"{% endif %}
40
+ {% endfor %}
41
+ >
42
+ {% for tabset in tabsets %}
43
+ {% set tab_attrs = tabset.tab_attrs | default({}) %}
44
+ <button
45
+ type="button"
46
+ role="tab"
47
+ id="{{ id }}-tab-{{ loop.index }}"
48
+ aria-controls="{{ id }}-panel-{{ loop.index }}"
49
+ aria-selected="{{ 'true' if loop.index == default_tab_index else 'false' }}"
50
+ tabindex="{{ '0' if loop.index == default_tab_index and not (tab_attrs.disabled | default(false)) and (tab_attrs['aria-disabled'] | default('false')) != 'true' else '-1' }}"
51
+ {% if tab_attrs %}
52
+ {% for key, value in tab_attrs.items() %}
53
+ {{ key }}="{{ value }}"
54
+ {% endfor %}
55
+ {% endif %}
56
+ >
57
+ {{ tabset.tab | safe }}
58
+ </button>
59
+ {% endfor %}
60
+ </nav>
61
+
62
+ {% for tabset in tabsets %}
63
+ {% if tabset.panel is defined and tabset.panel %}
64
+ <div
65
+ role="tabpanel"
66
+ id="{{ id }}-panel-{{ loop.index }}"
67
+ aria-labelledby="{{ id }}-tab-{{ loop.index }}"
68
+ tabindex="-1"
69
+ aria-selected="{{ 'true' if loop.index == default_tab_index else 'false' }}"
70
+ {% if loop.index != default_tab_index %}hidden{% endif %}
71
+ {% if tabset.panel_attrs is defined and tabset.panel_attrs %}
72
+ {% for key, value in tabset.panel_attrs.items() %}
73
+ {{ key }}="{{ value }}"
74
+ {% endfor %}
75
+ {% endif %}
76
+ >
77
+ {{ tabset.panel | safe }}
78
+ </div>
79
+ {% endif %}
80
+ {% endfor %}
81
+ </div>
82
+ {% endmacro %}
@@ -0,0 +1,139 @@
1
+ {#
2
+ Renders a toaster container and individual toast messages.
3
+ Can render the initial container or be used with htmx OOB swaps to add toasts dynamically.
4
+
5
+ @param id {string} [optional] [default="toaster"] - Unique identifier for the toaster container.
6
+ @param toasts {array} [optional] - An array of toast objects to render initially. See the <code>toast()</code> macro for more details.
7
+ @param attrs {object} [optional] - Additional HTML attributes for the main toaster container div.
8
+
9
+ Supports caller() for custom toast markup.
10
+ #}
11
+ {% macro toaster(
12
+ id="toaster",
13
+ toasts=[],
14
+ attrs={}
15
+ ) %}
16
+ {% set attrs = attrs or {} %}
17
+ <div
18
+ id="{{ id }}"
19
+ class="toaster {{ attrs.class | default('') }}"
20
+ {% for key, value in attrs.items() %}
21
+ {% if key != 'class' %}{{ key }}="{{ value }}"{% endif %}
22
+ {% endfor %}
23
+ >
24
+ {% for item in toasts %}
25
+ {{ toast(
26
+ category=item.category | default("success"),
27
+ title=item.title | default(""),
28
+ description=item.description | default(""),
29
+ action=item.action | default(None),
30
+ cancel=item.cancel | default(None),
31
+ duration=item.duration | default(None),
32
+ icon=item.icon | default(None),
33
+ attrs=item.attrs | default({})
34
+ ) }}
35
+ {% endfor %}
36
+ {{ caller() if caller is defined }}
37
+ </div>
38
+ {% endmacro %}
39
+
40
+ {#
41
+ Renders a single toast message.
42
+
43
+ @param category {string} [optional] [default="success"] - Type of toast ('success', 'error', 'info', 'warning'). Determines icon and ARIA role.
44
+ @param title {string} [optional] - The main title text of the toast.
45
+ @param description {string} [optional] - The secondary description text.
46
+ @param duration {number} [optional] - Timeout in milliseconds. Use -1 to keep the toast open.
47
+ @param icon {string} [optional] - Custom icon HTML. Defaults to the category icon.
48
+ @param action {object} [optional] - Defines an action button.
49
+ - label {string}: Button text.
50
+ - onclick {string}: JavaScript code to execute on click.
51
+ - href {string}: URL for an anchor link button.
52
+ @param cancel {object} [optional] - Defines a cancel/dismiss button (similar structure to action).
53
+ - label {string}: Button text.
54
+ - onclick {string}: JavaScript code to execute on click.
55
+ - href {string}: URL for an anchor link button.
56
+ @param attrs {object} [optional] - Additional HTML attributes for the toast div.
57
+ #}
58
+ {% macro toast(
59
+ category="success",
60
+ title="",
61
+ description="",
62
+ action=None,
63
+ cancel=None,
64
+ duration=None,
65
+ icon=None,
66
+ attrs={}
67
+ ) %}
68
+ {% set attrs = attrs or {} %}
69
+ {% set action_href = action.href if action and action.href is defined and action.href else (action.url if action and action.url is defined and action.url else None) %}
70
+ {% set cancel_href = cancel.href if cancel and cancel.href is defined and cancel.href else (cancel.url if cancel and cancel.url is defined and cancel.url else None) %}
71
+ <div
72
+ class="toast {{ attrs.class | default('') }}"
73
+ role="{{ 'alert' if category == 'error' else 'status' }}"
74
+ aria-atomic="true"
75
+ aria-hidden="false"
76
+ {% if category %}data-category="{{ category }}"{% endif %}
77
+ {% if duration is not none %}data-duration="{{ duration }}"{% endif %}
78
+ {% for key, value in attrs.items() %}
79
+ {% if key != 'class' %}{{ key }}="{{ value }}"{% endif %}
80
+ {% endfor %}
81
+ >
82
+ <div class="toast-content">
83
+ {% if icon %}
84
+ {{ icon | safe }}
85
+ {% elif category in ["error", "success", "info", "warning"] %}
86
+ {% if category == "success" %}
87
+ <svg aria-hidden="true" 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"><circle cx="12" cy="12" r="10"/><path d="m9 12 2 2 4-4"/></svg>
88
+ {% elif category == "error" %}
89
+ <svg aria-hidden="true" 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"><circle cx="12" cy="12" r="10"/><path d="m15 9-6 6"/><path d="m9 9 6 6"/></svg>
90
+ {% elif category == "info" %}
91
+ <svg aria-hidden="true" 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"><circle cx="12" cy="12" r="10"/><path d="M12 16v-4"/><path d="M12 8h.01"/></svg>
92
+ {% elif category == "warning" %}
93
+ <svg aria-hidden="true" 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"><path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3"/><path d="M12 9v4"/><path d="M12 17h.01"/></svg>
94
+ {% endif %}
95
+ {% endif %}
96
+ <section>
97
+ {% if title %}<h2>{{ title }}</h2>{% endif %}
98
+ {% if description %}<p>{{ description }}</p>{% endif %}
99
+ </section>
100
+ {% if action or cancel %}
101
+ <footer>
102
+ {% if action %}
103
+ {% if action_href %}
104
+ <a
105
+ href="{{ action_href }}"
106
+ class="btn" data-size="sm"
107
+ data-toast-action
108
+ >{{ action.label | default('') }}</a>
109
+ {% else %}
110
+ <button
111
+ type="button"
112
+ class="btn"
113
+ data-size="sm"
114
+ data-toast-action
115
+ {% if action.onclick is defined and action.onclick %}onclick="{{ action.onclick }}"{% endif %}
116
+ >{{ action.label | default('') }}</button>
117
+ {% endif %}
118
+ {% endif %}
119
+ {% if cancel %}
120
+ {% if cancel_href %}
121
+ <a
122
+ href="{{ cancel_href }}"
123
+ class="btn" data-variant="outline" data-size="sm"
124
+ data-toast-cancel
125
+ >{{ cancel.label | default('') }}</a>
126
+ {% else %}
127
+ <button
128
+ type="button"
129
+ class="btn" data-variant="outline" data-size="sm"
130
+ data-toast-cancel
131
+ {% if cancel.onclick is defined and cancel.onclick %}onclick="{{ cancel.onclick }}"{% endif %}
132
+ >{{ cancel.label | default('') }}</button>
133
+ {% endif %}
134
+ {% endif %}
135
+ </footer>
136
+ {% endif %}
137
+ </div>
138
+ </div>
139
+ {% endmacro %}