diff --git a/src/jinja/dialog.html.jinja b/src/jinja/dialog.html.jinja index 6af62d5..0400054 100644 --- a/src/jinja/dialog.html.jinja +++ b/src/jinja/dialog.html.jinja @@ -8,103 +8,87 @@ @param footer {string} [optional] - HTML content for the dialog footer. @param main_attrs {object} [optional] - Additional HTML attributes for the main container div. @param trigger_attrs {object} [optional] - Additional HTML attributes for the trigger button. - @param content_attrs {object} [optional] - Additional HTML attributes for the dialog content article. - @param content_header_attrs {object} [optional] - Additional HTML attributes for the dialog header. - @param content_body_attrs {object} [optional] - Additional HTML attributes for the dialog body section. - @param content_footer_attrs {object} [optional] - Additional HTML attributes for the dialog footer. - @param open {boolean} [optional] [default=False] - Whether the dialog should be open initially. - @param close_button {boolean} [optional] [default=True] - Whether to include a close button. - @param close_on_overlay_click {boolean} [optional] [default=True] - Whether clicking the overlay closes the dialog. + @param dialog_attrs {object} [optional] - Additional HTML attributes for the dialog content article. + @param header_attrs {object} [optional] - Additional HTML attributes for the dialog header. + @param body_attrs {object} [optional] - Additional HTML attributes for the dialog body section. + @param footer_attrs {object} [optional] - Additional HTML attributes for the dialog footer. + @param open {boolean} [optional] [default=false] - Whether the dialog should be open initially. + @param close_button {boolean} [optional] [default=true] - Whether to include a close button. + @param close_on_overlay_click {boolean} [optional] [default=true] - Whether clicking the overlay closes the dialog. #} {% macro dialog( - id, + id=None, trigger=None, title=None, description=None, footer=None, - main_attrs={}, + dialog_attrs={}, trigger_attrs={}, - content_attrs={}, - content_header_attrs={}, - content_body_attrs={}, - content_footer_attrs={}, - open=False, - close_button=True, - close_on_overlay_click=True + header_attrs={}, + body_attrs={}, + footer_attrs={}, + open=false, + close_button=true, + close_on_overlay_click=true ) %} -
- {% if trigger %} - - {% endif %} - -
+ + + {% endif %} + + {% endmacro %} \ No newline at end of file diff --git a/src/jinja/dropdown-menu.html.jinja b/src/jinja/dropdown-menu.html.jinja index e1dcf34..ab4a2dd 100644 --- a/src/jinja/dropdown-menu.html.jinja +++ b/src/jinja/dropdown-menu.html.jinja @@ -3,61 +3,62 @@ @param id {string} [optional] - Unique identifier for the dropdown component. @param trigger {string} [optional] - HTML content for the button that triggers the dropdown. - @param menu {array} [optional] - Array of menu items for the dropdown. + @param items {array} [optional] - Array of menu items for the dropdown. @param main_attrs {object} [optional] - Additional HTML attributes for the main container div. @param trigger_attrs {object} [optional] - Additional HTML attributes for the trigger button. - @param content_attrs {object} [optional] - Additional HTML attributes for the dropdown content div. + @param popover_attrs {object} [optional] - Additional HTML attributes for the dropdown content div. #} {% macro dropdown_menu( + trigger, id=None, - trigger=None, - menu=None, + items=None, main_attrs={}, trigger_attrs={}, - content_attrs={} + popover_attrs={}, + menu_attrs={} ) %} +{% set id = id or ("dropdown-menu-" + (range(100000, 999999) | random | string)) %} +
- {% if trigger %} - {% endif %}
{% endmacro %} @@ -69,7 +70,7 @@ @param parent_id_prefix {string} [optional] - Prefix for generating element IDs. #} {% macro render_dropdown_items(items, parent_id_prefix="items") %} - {% for item in items.items() %} + {% for item in items %} {% set item_id = parent_id_prefix ~ "-" ~ loop.index %} {% if item.type == "group" %} @@ -77,11 +78,13 @@
-
{{ item.label }}
+ {{ render_dropdown_items(item.items, item_id) if item.items }}
{% elif item.type == "separator" %} @@ -89,24 +92,29 @@ {% elif item.type == "item" or not item.type %} {% if item.url %} {{ item.label | safe }} {% else %} - + {% endif %} {% endif %} {% endfor %} diff --git a/src/jinja/popover.html.jinja b/src/jinja/popover.html.jinja index 23448ef..e3bc22c 100644 --- a/src/jinja/popover.html.jinja +++ b/src/jinja/popover.html.jinja @@ -5,51 +5,43 @@ @param trigger {string} [optional] - HTML content for the element that triggers the popover. @param main_attrs {object} [optional] - Additional HTML attributes for the main container div. @param trigger_attrs {object} [optional] - Additional HTML attributes for the trigger element. - @param content_attrs {object} [optional] - Additional HTML attributes for the popover content div. + @param popover_attrs {object} [optional] - Additional HTML attributes for the popover content div. #} {% macro popover( + trigger, id=None, - trigger=None, main_attrs={}, trigger_attrs={}, - content_attrs={} + popover_attrs={} ) %} +{% set id = id or ("popover-" + (range(100000, 999999) | random | string)) %} +
- {% if trigger %} - {% endif %}
-{% endmacro %} +{% endmacro %} \ No newline at end of file diff --git a/src/jinja/select.html.jinja b/src/jinja/select.html.jinja index 90f0dd5..8ca5bb8 100644 --- a/src/jinja/select.html.jinja +++ b/src/jinja/select.html.jinja @@ -6,7 +6,7 @@ @param name {string} [optional] - The name attribute for the hidden input storing the selected value. @param main_attrs {object} [optional] - Additional HTML attributes for the main container div. @param trigger_attrs {object} [optional] - Additional HTML attributes for the trigger button. - @param content_attrs {object} [optional] - Additional HTML attributes for the popover content div. + @param popover_attrs {object} [optional] - Additional HTML attributes for the popover content div. @param listbox_attrs {object} [optional] - Additional HTML attributes for the listbox div. @param input_attrs {object} [optional] - Additional HTML attributes for the hidden input. @param search_placeholder {string} [optional] [default="Search entries..."] - Placeholder text for the search input (combobox only). @@ -17,49 +17,55 @@ selected=None, name=None, items=None, + main_attrs={}, trigger_attrs={}, popover_attrs={}, listbox_attrs={}, + input_attrs={}, search_placeholder="Search entries...", is_combobox=false ) %} {% set id = id or ("select-" + (range(100000, 999999) | random | string)) %} -{% set first_option = [] %} -{% set selected_option = [] %} +{% set first_option = namespace(item=None) %} +{% set selected_option = namespace(item=None) %} -{% for item in items.items() %} +{% for item in items %} {% if item.type == "group" %} - {% for sub_item in item.items.items() %} - {% if not first_option[0] %} - {% set first_option = (first_option.push(sub_item), first_option) %} + {% for sub_item in item.items %} + {% if not first_option.item %} + {% set first_option.item = sub_item %} {% endif %} - {% if selected and sub_item.value == selected and not selected_option[0] %} - {% set selected_option = (selected_option.push(sub_item), selected_option) %} + {% if selected and sub_item.value == selected and not selected_option.item %} + {% set selected_option.item = sub_item %} {% endif %} {% endfor %} {% else %} - {% if not first_option[0] %} - {% set first_option = (first_option.push(item), first_option) %} + {% if not first_option.item %} + {% set first_option.item = item %} {% endif %} - {% if selected and item.value == selected and not selected_option[0] %} - {% set selected_option = (selected_option.push(item), selected_option) %} + {% if selected and item.value == selected and not selected_option.item %} + {% set selected_option.item = item %} {% endif %} {% endif %} {% endfor %} -{% set default_option = selected_option[0] or first_option[0] or None %} +{% set default_option = selected_option.item or first_option.item or None %} -
+
{% elif item.type == "separator" %} @@ -152,9 +160,11 @@ role="option" data-value="{{ item.value }}" {% if selected == item.value %}aria-selected="true"{% endif %} - {% for key, value in item.attrs %} - {{ key }}="{{ value }}" - {% endfor %} + {% if item.attrs %} + {% for key, value in item.attrs.items() %} + {{ key }}="{{ value }}" + {% endfor %} + {% endif %} > {{ item.label | safe }}
diff --git a/src/jinja/sidebar.html.jinja b/src/jinja/sidebar.html.jinja index f6f12bd..16bd1b0 100644 --- a/src/jinja/sidebar.html.jinja +++ b/src/jinja/sidebar.html.jinja @@ -2,17 +2,21 @@ Renders a sidebar component. @param id {string} [optional] - Unique identifier for the sidebar component. - @param label {string} [optional] [default="Sidebar navigation"] - Label for the sidebar navigation. - @param open {boolean} [optional] [default=True] - Whether the sidebar is open. + @param label {string} [optional] - Label for the sidebar navigation. + @param open {boolean} [optional] - Whether the sidebar is open. @param side {string} [optional] - Side of the sidebar to display. @param header {string} [optional] - Header content for the sidebar. @param footer {string} [optional] - Footer content for the sidebar. @param menu {array} [optional] - Array of menu items for the sidebar. + @param main_attrs {object} [optional] - Additional HTML attributes for the main container div. + @param header_attrs {object} [optional] - Additional HTML attributes for the header div. + @param content_attrs {object} [optional] - Additional HTML attributes for the content div. + @param footer_attrs {object} [optional] - Additional HTML attributes for the footer div. #} {% macro sidebar( id=None, label="Sidebar navigation", - open=True, + open=true, side=None, header=None, footer=None, @@ -20,21 +24,17 @@ main_attrs={}, header_attrs={}, content_attrs={}, - footer_attrs={}, - content_wrapper_attrs=None + footer_attrs={} ) %} - + {% endmacro %} {# @@ -81,7 +81,7 @@ @param parent_id_prefix {string} [optional] - Prefix for generating element IDs. #} {% macro render_sidebar_content(items, parent_id_prefix="content") %} - {% for item in items.items() %} + {% for item in items %} {% set item_id = parent_id_prefix ~ "-" ~ loop.index %} {% if item.type == "group" %} @@ -89,15 +89,17 @@
{% if item.label %}

{{ item.label }}

{% endif %}
{% elif item.type == "separator" %} @@ -107,16 +109,18 @@ @@ -125,9 +129,11 @@ {% if item.icon %}{{ item.icon | safe }}{% endif %} {{ item.label }} diff --git a/src/jinja/tabs.html.jinja b/src/jinja/tabs.html.jinja index 4b1537e..a16c44f 100644 --- a/src/jinja/tabs.html.jinja +++ b/src/jinja/tabs.html.jinja @@ -14,17 +14,17 @@ @param default_tab_index {number} [optional] [default=1] - The 1-based index of the tab to be active initially. #} {% macro tabs( - id, + id=None, tabsets=[], - main_attrs=None, - tablist_attrs=None, + main_attrs={}, + tablist_attrs={}, default_tab_index=1 ) %} +{% set id = id or ("tabs-" + (range(100000, 999999) | random | string)) %}
- {% for tabset in tabsets.items() %} + {% for tabset in tabsets %} {% endfor %} - {% for tabset in tabsets.items() %} + {% for tabset in tabsets %} {% if tabset.panel %}
{{ tabset.panel | safe }}
diff --git a/src/jinja/toast.html.jinja b/src/jinja/toast.html.jinja index ad09f65..ccfa2ba 100644 --- a/src/jinja/toast.html.jinja +++ b/src/jinja/toast.html.jinja @@ -5,21 +5,19 @@ @param id {string} [optional] [default="toaster"] - Unique identifier for the toaster container. @param toasts {array} [optional] - An array of toast objects to render initially. See the toast() macro for more details. @param main_attrs {object} [optional] - Additional HTML attributes for the main toaster container div. - @param is_fragment {boolean} [optional] [default=False] - If True, renders only the toast elements with hx-swap-oob="beforeend", suitable for htmx responses. Skips script and template inclusion. + @param is_fragment {boolean} [optional] [default=false] - If true, renders only the toast elements with hx-swap-oob="beforeend", suitable for htmx responses. Skips script and template inclusion. #} {% macro toaster( id="toaster", toasts=[], - main_attrs={}, - is_fragment=False + attrs={} ) %}
{% for item in toasts %} {{ toast( @@ -31,79 +29,6 @@ ) }} {% endfor %}
- -{% if not is_fragment %} - -{% endif %} {% endmacro %} {# @@ -134,65 +59,51 @@ aria-atomic="true" aria-hidden="false" {% if category %}data-category="{{ category }}"{% endif %} - x-data="toast({ - category: '{{ category }}', - duration: {{ duration or 'null' }} - })" - x-bind="$toastBindings" >
- + {% endif %} + {% if cancel %} + + {% endif %} + + {% endif %}
-{% endmacro %} - -{% set toast_icons = { - 'success': '', - 'error': '', - 'info': '', - 'warning': '' -} %} \ No newline at end of file +{% endmacro %} \ No newline at end of file diff --git a/src/nunjucks/dropdown-menu.njk b/src/nunjucks/dropdown-menu.njk index 205f558..5d608b7 100644 --- a/src/nunjucks/dropdown-menu.njk +++ b/src/nunjucks/dropdown-menu.njk @@ -3,14 +3,14 @@ @param id {string} [optional] - Unique identifier for the dropdown component. @param trigger {string} [optional] - HTML content for the button that triggers the dropdown. - @param menu {array} [optional] - Array of menu items for the dropdown. + @param items {array} [optional] - Array of menu items for the dropdown. @param main_attrs {object} [optional] - Additional HTML attributes for the main container div. @param trigger_attrs {object} [optional] - Additional HTML attributes for the trigger button. @param popover_attrs {object} [optional] - Additional HTML attributes for the dropdown content div. #} {% macro dropdown_menu( - id=None, trigger, + id=None, items=None, main_attrs={}, trigger_attrs={}, @@ -78,9 +78,11 @@
{{ render_dropdown_items(item.items, item_id) if item.items }} @@ -93,9 +95,11 @@ id="{{ item_id }}" role="menuitem" href="{{ item.url }}" - {% for key, value in item.attrs %} - {% if key != "url" %} {{ key }}="{{ value }}" {% endif %} - {% endfor %} + {% if item.attrs %} + {% for key, value in item.attrs %} + {% if key != "url" %} {{ key }}="{{ value }}" {% endif %} + {% endfor %} + {% endif %} > {{ item.label | safe }} @@ -103,9 +107,11 @@ diff --git a/src/nunjucks/popover.njk b/src/nunjucks/popover.njk index 239d2ce..78f2070 100644 --- a/src/nunjucks/popover.njk +++ b/src/nunjucks/popover.njk @@ -8,8 +8,8 @@ @param popover_attrs {object} [optional] - Additional HTML attributes for the popover content div. #} {% macro popover( - id=None, trigger, + id=None, main_attrs={}, trigger_attrs={}, popover_attrs={} diff --git a/src/nunjucks/select.njk b/src/nunjucks/select.njk index a4e027b..60ba1d1 100644 --- a/src/nunjucks/select.njk +++ b/src/nunjucks/select.njk @@ -145,9 +145,11 @@
{{ render_select_items(item.items, selected, item_id) if item.items }} @@ -160,9 +162,11 @@ role="option" data-value="{{ item.value }}" {% if selected == item.value %}aria-selected="true"{% endif %} - {% for key, value in item.attrs %} - {{ key }}="{{ value }}" - {% endfor %} + {% if item.attrs %} + {% for key, value in item.attrs %} + {{ key }}="{{ value }}" + {% endfor %} + {% endif %} > {{ item.label | safe }}
diff --git a/src/nunjucks/sidebar.njk b/src/nunjucks/sidebar.njk index aa9127c..22404bb 100644 --- a/src/nunjucks/sidebar.njk +++ b/src/nunjucks/sidebar.njk @@ -7,7 +7,11 @@ @param side {string} [optional] - Side of the sidebar to display. @param header {string} [optional] - Header content for the sidebar. @param footer {string} [optional] - Footer content for the sidebar. - @param menu {array} [optional] - Array of menu items for the sidebar. + @param items {array} [optional] - Array of menu items for the sidebar. + @param main_attrs {object} [optional] - Additional HTML attributes for the main container div. + @param header_attrs {object} [optional] - Additional HTML attributes for the header element. + @param content_attrs {object} [optional] - Additional HTML attributes for the content section. + @param footer_attrs {object} [optional] - Additional HTML attributes for the footer element. #} {% macro sidebar( id=None, @@ -20,8 +24,7 @@ main_attrs={}, header_attrs={}, content_attrs={}, - footer_attrs={}, - content_wrapper_attrs=None + footer_attrs={} ) %}
diff --git a/src/nunjucks/toast.njk b/src/nunjucks/toast.njk index fc7d665..674ce31 100644 --- a/src/nunjucks/toast.njk +++ b/src/nunjucks/toast.njk @@ -10,7 +10,7 @@ {% macro toaster( id="toaster", toasts=[], - attrs=None + attrs={} ) %}
{% if category in ["error", "success", "info", "warning"] %} {% if category == "success" %} - {% lucide "circle-check" %} + {% elif category == "error" %} - {% lucide "circle-x" %} + {% elif category == "info" %} - {% lucide "info" %} + {% elif category == "warning" %} - {% lucide "triangle-alert" %} + {% endif %} {% endif %}