Restyle category tree to idiomatic Bootstrap list-group pattern (v0.1.8)
All checks were successful
Create Release Package / PHP Lint (push) Successful in 48s
Create Release Package / PHPUnit Tests (push) Successful in 56s
Create Release Package / Build Release (push) Successful in 1m4s

Switch from custom link classes to Bootstrap's native list-group-item-action
pattern. Replace bold primary-colored active background with subtle tertiary
background, left accent border, and semibold text.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-29 15:42:35 +02:00
parent 9860a184cd
commit 1e7f82615b
6 changed files with 56 additions and 50 deletions

View File

@@ -1,8 +1,8 @@
{#
# Single Category Tree Node (recursive)
#
# Renders one category with optional collapsible children.
# Included recursively by category-tree.html.twig.
# Renders one category as a list-group-item-action link with optional
# collapsible nested list for children. Included recursively.
#
# Expected context:
# node - Category node from wc_bootstrap_get_category_tree()
@@ -12,22 +12,24 @@
# @since 0.1.7
#}
<li class="list-group-item px-0 py-1 border-0">
{% set has_children = node.children is not empty %}
{% set is_open = node.is_active or node.is_ancestor %}
<div class="category-tree-item">
<div class="d-flex align-items-center">
<a href="{{ node.url }}"
class="category-tree-link d-block text-decoration-none py-1 px-2 rounded flex-grow-1{% if node.is_active %} active fw-semibold{% endif %}"
class="list-group-item list-group-item-action border-0 py-1 flex-grow-1{% if node.is_active %} active{% endif %}"
style="padding-left: {{ 0.5 + (level - 1) * 1 }}rem;"
{% if node.is_active %}aria-current="page"{% endif %}>
<span class="ps-{{ (level - 1) * 2 }}">
{{ node.name }}
</span>
<span class="badge bg-body-secondary text-body-secondary rounded-pill ms-1 small">{{ node.count }}</span>
{{ node.name }}
<small class="text-body-secondary ms-1">({{ node.count }})</small>
</a>
{% if node.children is not empty %}
<button class="btn btn-sm btn-link text-body-secondary p-0 ms-1 category-tree-toggle"
{% if has_children %}
<button class="btn btn-sm btn-link text-body-secondary p-0 px-2 category-tree-toggle"
type="button"
data-bs-toggle="collapse"
data-bs-target="#cat-{{ node.term_id }}"
aria-expanded="{{ node.is_active or node.is_ancestor ? 'true' : 'false' }}"
aria-expanded="{{ is_open ? 'true' : 'false' }}"
aria-controls="cat-{{ node.term_id }}"
aria-label="{{ __('Toggle subcategories', 'wc-bootstrap') }}">
<i class="bi bi-chevron-down small" aria-hidden="true"></i>
@@ -35,12 +37,11 @@
{% endif %}
</div>
{% if node.children is not empty %}
<ul class="list-group list-group-flush collapse{{ node.is_active or node.is_ancestor ? ' show' : '' }}"
id="cat-{{ node.term_id }}">
{% if has_children %}
<div class="collapse{{ is_open ? ' show' : '' }}" id="cat-{{ node.term_id }}">
{% for child in node.children %}
{% include 'global/category-tree-node.html.twig' with { node: child, level: level + 1 } only %}
{% endfor %}
</ul>
</div>
{% endif %}
</li>
</div>

View File

@@ -1,13 +1,13 @@
{#
# Product Category Tree (Bootstrap 5)
#
# Renders a hierarchical product category navigation with collapsible
# sub-levels, up to 3 levels deep. Uses Bootstrap 5 list-group and
# collapse components for responsive tree navigation.
# Renders a hierarchical product category navigation using Bootstrap
# list-group with nested sub-lists and action links.
#
# Expected context:
# categories - Hierarchical array from wc_bootstrap_get_category_tree()
# shop_url - URL to the main shop page
# categories - Hierarchical array from wc_bootstrap_get_category_tree()
# shop_url - URL to the main shop page
# current_cat - Term ID of the currently viewed category (0 = shop page)
#
# @package WcBootstrap
# @since 0.1.7
@@ -19,16 +19,14 @@
{{ __('Categories', 'wc-bootstrap') }}
</h3>
<ul class="list-group list-group-flush category-tree">
<li class="list-group-item px-0 py-1">
<a href="{{ shop_url }}"
class="category-tree-link d-block text-decoration-none py-1 px-2 rounded{% if current_cat == 0 %} active fw-semibold{% endif %}">
{{ __('All products', 'wc-bootstrap') }}
</a>
</li>
<div class="list-group list-group-flush category-tree">
<a href="{{ shop_url }}"
class="list-group-item list-group-item-action border-0 px-2 py-1{% if current_cat == 0 %} active{% endif %}">
{{ __('All products', 'wc-bootstrap') }}
</a>
{% for cat in categories %}
{% include 'global/category-tree-node.html.twig' with { node: cat, level: 1 } only %}
{% endfor %}
</ul>
</div>
</nav>
{% endif %}