From 865c825dd2cd8d108916c9202f1d264a31f09f27 Mon Sep 17 00:00:00 2001 From: camilleislasse Date: Sat, 14 Nov 2026 09:17:00 +0100 Subject: [PATCH 01/27] fix(demo): clear the whole cache when switching the admin UI or theme --- bin/switch-admin-theme | 1 + bin/switch-admin-ui | 1 + 2 files changed, 2 insertions(+) diff --git a/bin/switch-admin-theme b/bin/switch-admin-theme index 349abeda..eb553909 100755 --- a/bin/switch-admin-theme +++ b/bin/switch-admin-theme @@ -98,6 +98,7 @@ if [[ ${#themes[@]} -gt 0 ]]; then printf ' themes: [%s]\n' "${list%, }" >> "$config" fi +rm -rf var/cache/* php bin/console cache:clear --quiet # PHP-FPM only revalidates the cached PHP files every 2 seconds (opcache.revalidate_freq): wait for the new container. diff --git a/bin/switch-admin-ui b/bin/switch-admin-ui index 2da4658f..3fe1ee78 100755 --- a/bin/switch-admin-ui +++ b/bin/switch-admin-ui @@ -49,6 +49,7 @@ grep -rlE "@Sylius${OldNs}AdminUi|sylius_${old_prefix}_admin_ui:" app templates # The shadcn theme fully replaces the Tom Select stylesheet. perl -pi -e "s#(\"tom-select/dist/css/tom-select.default.css\": )(true|false)#\${1}${tom_select}#" assets/controllers.json +rm -rf var/cache/* php bin/console cache:clear --quiet # PHP-FPM only revalidates the cached PHP files every 2 seconds (opcache.revalidate_freq): wait for the new container. From 1231aa6efa0600145071e4cc4ac77a8f225cbb73 Mon Sep 17 00:00:00 2001 From: camilleislasse Date: Sat, 14 Nov 2026 09:17:00 +0100 Subject: [PATCH 02/27] fix(demo): read the dashboard chart colors from the shadcn tokens --- assets/scripts/statistics_chart.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/assets/scripts/statistics_chart.js b/assets/scripts/statistics_chart.js index ee71acfe..f3ee1950 100644 --- a/assets/scripts/statistics_chart.js +++ b/assets/scripts/statistics_chart.js @@ -10,8 +10,9 @@ function renderChart() { } const styles = getComputedStyle(document.documentElement); - const labelColor = styles.getPropertyValue('--tblr-body-color').trim(); - const primaryColor = styles.getPropertyValue('--tblr-primary').trim(); + const cssVar = (...names) => names.map((name) => styles.getPropertyValue(name).trim()).find(Boolean); + const labelColor = cssVar('--tblr-body-color', '--foreground'); + const primaryColor = cssVar('--tblr-primary', '--primary'); const options = { colors: [primaryColor], @@ -121,7 +122,7 @@ if (element) { const themeObserver = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { - if (mutation.attributeName === 'data-bs-theme') { + if (mutation.attributeName === 'data-bs-theme' || mutation.attributeName === 'data-theme') { chart.destroy(); renderChart(); } From 0efca11ba47528f8ffff68e963e4d0d2ed05d799 Mon Sep 17 00:00:00 2001 From: camilleislasse Date: Sat, 14 Nov 2026 09:17:00 +0100 Subject: [PATCH 03/27] fix(demo): port the dashboard, export button and book page to shadcn --- bin/switch-admin-ui | 11 ++++ .../book/show/content/page_body.html.twig | 32 +++++++++++ .../shadcn/component/new_speakers.html.twig | 31 +++++++++++ .../shadcn/component/new_talks.html.twig | 38 +++++++++++++ .../shadcn/component/statistics.html.twig | 9 +++ .../index/content/last_updates.html.twig | 3 + .../index/content/statistics_chart.html.twig | 55 +++++++++++++++++++ .../index/content/statistics_grid.html.twig | 3 + .../statistics_grid/conferences.html.twig | 13 +++++ .../statistics_grid/speakers.html.twig | 13 +++++ .../content/statistics_grid/talks.html.twig | 13 +++++ .../shared/grid/action/export.html.twig | 11 ++++ 12 files changed, 232 insertions(+) create mode 100644 templates/shadcn/book/show/content/page_body.html.twig create mode 100644 templates/shadcn/component/new_speakers.html.twig create mode 100644 templates/shadcn/component/new_talks.html.twig create mode 100644 templates/shadcn/component/statistics.html.twig create mode 100644 templates/shadcn/dashboard/index/content/last_updates.html.twig create mode 100644 templates/shadcn/dashboard/index/content/statistics_chart.html.twig create mode 100644 templates/shadcn/dashboard/index/content/statistics_grid.html.twig create mode 100644 templates/shadcn/dashboard/index/content/statistics_grid/conferences.html.twig create mode 100644 templates/shadcn/dashboard/index/content/statistics_grid/speakers.html.twig create mode 100644 templates/shadcn/dashboard/index/content/statistics_grid/talks.html.twig create mode 100644 templates/shadcn/shared/grid/action/export.html.twig diff --git a/bin/switch-admin-ui b/bin/switch-admin-ui index 3fe1ee78..28959841 100755 --- a/bin/switch-admin-ui +++ b/bin/switch-admin-ui @@ -42,8 +42,19 @@ imports: - { resource: '../../src/${Ns}AdminUi/config/app.php' } EOF +if [[ "$to" == shadcn ]]; then + cat > config/packages/app_shadcn_templates.yaml </dev/null \ + | { grep -v '^templates/shadcn/' || true; } \ | xargs -r perl -pi -e "s/\@Sylius${OldNs}AdminUi/\@Sylius${Ns}AdminUi/g; s/sylius_${old_prefix}_admin_ui:/sylius_${prefix}_admin_ui:/g" # The shadcn theme fully replaces the Tom Select stylesheet. diff --git a/templates/shadcn/book/show/content/page_body.html.twig b/templates/shadcn/book/show/content/page_body.html.twig new file mode 100644 index 00000000..0b7e6e50 --- /dev/null +++ b/templates/shadcn/book/show/content/page_body.html.twig @@ -0,0 +1,32 @@ +{% set book = hookable_metadata.context.resource %} + + + +
+
+
{{ 'app.ui.title'|trans }}
+
+ + {{ book.title }} + +
+
+
+
{{ 'app.ui.author'|trans }}
+
+ + {{ book.authorName }} + +
+
+
+
{{ 'app.ui.category'|trans }}
+
+ + {{ book.category.value }} + +
+
+
+
+
diff --git a/templates/shadcn/component/new_speakers.html.twig b/templates/shadcn/component/new_speakers.html.twig new file mode 100644 index 00000000..3b941b78 --- /dev/null +++ b/templates/shadcn/component/new_speakers.html.twig @@ -0,0 +1,31 @@ + + + {{ 'app.ui.new_speakers'|trans }} + + + {{ 'app.ui.show_all'|trans }} + + + + + + + {% for speaker in new_speakers|default([]) %} + + + + {% if speaker.avatar %} + + {% endif %} + {{ speaker.firstName|first }}{{ speaker.lastName|first }} + + + + {{ speaker.fullName }} + {{ speaker.companyName }} + + + {% endfor %} + + + diff --git a/templates/shadcn/component/new_talks.html.twig b/templates/shadcn/component/new_talks.html.twig new file mode 100644 index 00000000..fd250841 --- /dev/null +++ b/templates/shadcn/component/new_talks.html.twig @@ -0,0 +1,38 @@ + + + {{ 'app.ui.new_talks'|trans }} + + + {{ 'app.ui.show_all'|trans }} + + + + + + + {% for talk in new_talks|default([]) %} + {% set first_speaker = talk.speakers.first %} + + {% if first_speaker %} + + + {% if first_speaker.avatar %} + + {% endif %} + {{ first_speaker.firstName|first }}{{ first_speaker.lastName|first }} + + + {% endif %} + + {{ talk.title }} + + {%- for speaker in talk.speakers -%} + {% if not loop.first %}, {% endif %}{{ speaker.fullName }} + {%- endfor -%} + + + + {% endfor %} + + + diff --git a/templates/shadcn/component/statistics.html.twig b/templates/shadcn/component/statistics.html.twig new file mode 100644 index 00000000..f0ce0101 --- /dev/null +++ b/templates/shadcn/component/statistics.html.twig @@ -0,0 +1,9 @@ +
+ {% hook 'statistics' with { + statistics_data: statistics, + period, + } %} +
diff --git a/templates/shadcn/dashboard/index/content/last_updates.html.twig b/templates/shadcn/dashboard/index/content/last_updates.html.twig new file mode 100644 index 00000000..e5fa2175 --- /dev/null +++ b/templates/shadcn/dashboard/index/content/last_updates.html.twig @@ -0,0 +1,3 @@ +
+ {% hook 'latest_updates' %} +
diff --git a/templates/shadcn/dashboard/index/content/statistics_chart.html.twig b/templates/shadcn/dashboard/index/content/statistics_chart.html.twig new file mode 100644 index 00000000..c1b8492c --- /dev/null +++ b/templates/shadcn/dashboard/index/content/statistics_chart.html.twig @@ -0,0 +1,55 @@ +{% set statistics_data = hookable_metadata.context.statistics_data %} +{% set period = hookable_metadata.context.period %} + + + + {{ 'app.ui.talks'|trans }} + +
+ {% for range in [ + {period: '2 weeks', interval: 'day', label: 'app.ui.statistics.2weeks'}, + {period: 'month', interval: 'day', label: 'app.ui.statistics.month'}, + {period: 'year', interval: 'month', label: 'app.ui.statistics.year', test: 'year-split-into-months'}, + ] %} + + {{ range.label|trans }} + + {% endfor %} +
+
+ + + + + + +
+
+
+ +
+
+
diff --git a/templates/shadcn/dashboard/index/content/statistics_grid.html.twig b/templates/shadcn/dashboard/index/content/statistics_grid.html.twig new file mode 100644 index 00000000..3fc7ac48 --- /dev/null +++ b/templates/shadcn/dashboard/index/content/statistics_grid.html.twig @@ -0,0 +1,3 @@ +
+ {% hook 'statistics_grid' %} +
diff --git a/templates/shadcn/dashboard/index/content/statistics_grid/conferences.html.twig b/templates/shadcn/dashboard/index/content/statistics_grid/conferences.html.twig new file mode 100644 index 00000000..62841e7a --- /dev/null +++ b/templates/shadcn/dashboard/index/content/statistics_grid/conferences.html.twig @@ -0,0 +1,13 @@ +{% set statistics_data = hookable_metadata.context.statistics_data %} + + + + {{ 'app.ui.conferences'|trans }} + + {{ statistics_data.business_activity_summary.totalConferences }} + + + + + + diff --git a/templates/shadcn/dashboard/index/content/statistics_grid/speakers.html.twig b/templates/shadcn/dashboard/index/content/statistics_grid/speakers.html.twig new file mode 100644 index 00000000..8b2e9834 --- /dev/null +++ b/templates/shadcn/dashboard/index/content/statistics_grid/speakers.html.twig @@ -0,0 +1,13 @@ +{% set statistics_data = hookable_metadata.context.statistics_data %} + + + + {{ 'app.ui.speakers'|trans }} + + {{ statistics_data.business_activity_summary.totalSpeakers }} + + + + + + diff --git a/templates/shadcn/dashboard/index/content/statistics_grid/talks.html.twig b/templates/shadcn/dashboard/index/content/statistics_grid/talks.html.twig new file mode 100644 index 00000000..7227a847 --- /dev/null +++ b/templates/shadcn/dashboard/index/content/statistics_grid/talks.html.twig @@ -0,0 +1,13 @@ +{% set statistics_data = hookable_metadata.context.statistics_data %} + + + + {{ 'app.ui.talks'|trans }} + + {{ statistics_data.business_activity_summary.totalTalks }} + + + + + + diff --git a/templates/shadcn/shared/grid/action/export.html.twig b/templates/shadcn/shared/grid/action/export.html.twig new file mode 100644 index 00000000..a83ad846 --- /dev/null +++ b/templates/shadcn/shared/grid/action/export.html.twig @@ -0,0 +1,11 @@ +{% set path = options.link.url|default(path(options.link.route|default(grid.requestConfiguration.getRouteName('export')), options.link.parameters|default([]))) %} + +{% set message = action.label %} +{% if message is empty %} + {% set message = 'app.ui.export' %} +{% endif %} + + + + {{ message|trans }} + From 9cdb835614e394f174294c75db1c609c1c96c493 Mon Sep 17 00:00:00 2001 From: camilleislasse Date: Sat, 14 Nov 2026 09:17:00 +0100 Subject: [PATCH 04/27] fix(shadcn-admin-ui): escape the copy button classes only once --- .../components/copy_to_clipboard.html.twig | 2 +- .../CopyToClipboardComponentTest.php | 63 +++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 src/ShadcnAdminUi/tests/Functional/CopyToClipboardComponentTest.php diff --git a/src/ShadcnAdminUi/templates/shared/components/copy_to_clipboard.html.twig b/src/ShadcnAdminUi/templates/shared/components/copy_to_clipboard.html.twig index 34d4c7e3..99dcc9c0 100644 --- a/src/ShadcnAdminUi/templates/shared/components/copy_to_clipboard.html.twig +++ b/src/ShadcnAdminUi/templates/shared/components/copy_to_clipboard.html.twig @@ -15,11 +15,11 @@ errorLabel: error_label|trans, }) }}> - + + + + {{ ux_icon('lucide:x', {'aria-hidden': 'true'}) }} + + + {% endfor %} {% endfor %} From bdc120cdad78f167aba75bc734e98b57c2a29399 Mon Sep 17 00:00:00 2001 From: camilleislasse Date: Sat, 14 Nov 2026 10:05:32 +0100 Subject: [PATCH 09/27] docs(shadcn-admin-ui): list every template copying the kit classes --- docs/shadcn-admin-ui/components.md | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/docs/shadcn-admin-ui/components.md b/docs/shadcn-admin-ui/components.md index 85e2278e..b0fd78c1 100644 --- a/docs/shadcn-admin-ui/components.md +++ b/docs/shadcn-admin-ui/components.md @@ -192,10 +192,27 @@ Update this table when you add or drop a local change. {% hint style="warning" %} Classes copied outside the components must be synced **by hand**: -- `shared/helper/ui.html.twig` -- `shared/form_theme.html.twig` -- `shared/crud/common/sidebar/menu/menu.html.twig` -- `shared/pagerfanta.html.twig` +- `shared/helper/ui.html.twig`: `Button` +- `shared/form_theme.html.twig`: `Field`, `Input`, `Checkbox`, `Switch`, `NativeSelect`, `Alert` +- `shared/crud/common/sidebar/menu/menu.html.twig`: `Sidebar`, `Collapsible` +- `shared/pagerfanta.html.twig`: `Pagination`, `Button` +- `shared/components/badge.html.twig`: `Badge` +- `shared/components/confirmation_modal.html.twig`: `AlertDialog`, `Dialog/Footer` +- `shared/crud/common/content/form_error_alert.html.twig`: `Alert` +- `security/login/page/content/form/error.html.twig`: `Alert` +- `shared/crud/common/sidebar/search.html.twig`: `Input` +- `shared/crud/index/content/grid/data_table.html.twig`: `Card`, `Table` +- `shared/crud/index/content/grid/filters.html.twig`: `Card` +- `shared/crud/index/content/grid/no_results.html.twig`: `Empty` +- `shared/crud/index/content/grid/no_results/image.html.twig`: `Empty/Media` +- `shared/helper/_checkbox.html.twig`: `Checkbox` +- `shared/helper/accordion.html.twig`: `Card` +- `shared/helper/avatar.html.twig`: `Avatar` +- `shared/helper/breadcrumbs.html.twig`: `Breadcrumb` +- `shared/helper/dropdown.html.twig`: `DropdownMenu` +- `shared/helper/header.html.twig`: `Empty/Media` +- `shared/helper/sorting.html.twig`: `Table/Head` +- `shared/helper/table.html.twig`: `Table` {% endhint %} ### 4. Check From 3f131580113b593f056f7cacb9e89e6f03c75464 Mon Sep 17 00:00:00 2001 From: camilleislasse Date: Sat, 14 Nov 2026 10:08:06 +0100 Subject: [PATCH 10/27] refactor(shadcn-admin-ui): render the form error alert with the Alert component --- docs/shadcn-admin-ui/components.md | 1 - .../crud/common/content/form_error_alert.html.twig | 12 ++++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/docs/shadcn-admin-ui/components.md b/docs/shadcn-admin-ui/components.md index b0fd78c1..258d14cd 100644 --- a/docs/shadcn-admin-ui/components.md +++ b/docs/shadcn-admin-ui/components.md @@ -198,7 +198,6 @@ Classes copied outside the components must be synced **by hand**: - `shared/pagerfanta.html.twig`: `Pagination`, `Button` - `shared/components/badge.html.twig`: `Badge` - `shared/components/confirmation_modal.html.twig`: `AlertDialog`, `Dialog/Footer` -- `shared/crud/common/content/form_error_alert.html.twig`: `Alert` - `security/login/page/content/form/error.html.twig`: `Alert` - `shared/crud/common/sidebar/search.html.twig`: `Input` - `shared/crud/index/content/grid/data_table.html.twig`: `Card`, `Table` diff --git a/src/ShadcnAdminUi/templates/shared/crud/common/content/form_error_alert.html.twig b/src/ShadcnAdminUi/templates/shared/crud/common/content/form_error_alert.html.twig index 8a0a3379..0c28ec37 100644 --- a/src/ShadcnAdminUi/templates/shared/crud/common/content/form_error_alert.html.twig +++ b/src/ShadcnAdminUi/templates/shared/crud/common/content/form_error_alert.html.twig @@ -1,9 +1,13 @@ {% set form = hookable_metadata.context.form|default(null) %} {% if form is not null and form.vars.submitted and form.vars.valid == false %} - + {{ 'sylius.ui.error'|trans }} + {{ 'sylius.ui.this_form_contains_errors'|trans }} + {% endif %} From 36474c4fd0b974e00d17780c48e97944cde49e9e Mon Sep 17 00:00:00 2001 From: camilleislasse Date: Sat, 14 Nov 2026 10:17:46 +0100 Subject: [PATCH 11/27] refactor(shadcn-admin-ui): render the login error with the Alert component --- docs/shadcn-admin-ui/components.md | 1 - .../security/login/page/content/form/error.html.twig | 10 +++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/docs/shadcn-admin-ui/components.md b/docs/shadcn-admin-ui/components.md index 258d14cd..1cf602f2 100644 --- a/docs/shadcn-admin-ui/components.md +++ b/docs/shadcn-admin-ui/components.md @@ -198,7 +198,6 @@ Classes copied outside the components must be synced **by hand**: - `shared/pagerfanta.html.twig`: `Pagination`, `Button` - `shared/components/badge.html.twig`: `Badge` - `shared/components/confirmation_modal.html.twig`: `AlertDialog`, `Dialog/Footer` -- `security/login/page/content/form/error.html.twig`: `Alert` - `shared/crud/common/sidebar/search.html.twig`: `Input` - `shared/crud/index/content/grid/data_table.html.twig`: `Card`, `Table` - `shared/crud/index/content/grid/filters.html.twig`: `Card` diff --git a/src/ShadcnAdminUi/templates/security/login/page/content/form/error.html.twig b/src/ShadcnAdminUi/templates/security/login/page/content/form/error.html.twig index 9bcdd854..cdc79616 100644 --- a/src/ShadcnAdminUi/templates/security/login/page/content/form/error.html.twig +++ b/src/ShadcnAdminUi/templates/security/login/page/content/form/error.html.twig @@ -1,8 +1,12 @@ {% set last_error = hookable_metadata.context.last_error|default(null) %} {% if last_error is not null %} - + {{ last_error.messageKey|trans(last_error.messageData, 'security') }} + {% endif %} From f7066afb35ba78335e94c76a792a4cc95986db12 Mon Sep 17 00:00:00 2001 From: camilleislasse Date: Sat, 14 Nov 2026 10:30:36 +0100 Subject: [PATCH 12/27] refactor(shadcn-admin-ui): render the breadcrumbs with the Breadcrumb components --- docs/shadcn-admin-ui/components.md | 1 - .../shared/helper/breadcrumbs.html.twig | 22 ++++----- .../tests/Functional/BreadcrumbsMacroTest.php | 46 +++++++++++++++++++ 3 files changed, 57 insertions(+), 12 deletions(-) create mode 100644 src/ShadcnAdminUi/tests/Functional/BreadcrumbsMacroTest.php diff --git a/docs/shadcn-admin-ui/components.md b/docs/shadcn-admin-ui/components.md index 1cf602f2..37fb6be8 100644 --- a/docs/shadcn-admin-ui/components.md +++ b/docs/shadcn-admin-ui/components.md @@ -206,7 +206,6 @@ Classes copied outside the components must be synced **by hand**: - `shared/helper/_checkbox.html.twig`: `Checkbox` - `shared/helper/accordion.html.twig`: `Card` - `shared/helper/avatar.html.twig`: `Avatar` -- `shared/helper/breadcrumbs.html.twig`: `Breadcrumb` - `shared/helper/dropdown.html.twig`: `DropdownMenu` - `shared/helper/header.html.twig`: `Empty/Media` - `shared/helper/sorting.html.twig`: `Table/Head` diff --git a/src/ShadcnAdminUi/templates/shared/helper/breadcrumbs.html.twig b/src/ShadcnAdminUi/templates/shared/helper/breadcrumbs.html.twig index 657a6304..a9fba743 100644 --- a/src/ShadcnAdminUi/templates/shared/helper/breadcrumbs.html.twig +++ b/src/ShadcnAdminUi/templates/shared/helper/breadcrumbs.html.twig @@ -1,22 +1,22 @@ {# Same signature as the BootstrapAdminUi macro: items = [{name, url?, active?}, ...] #} {% macro breadcrumbs(items) %} {% set items = items|filter(item => item is not empty) %} - + + {% endmacro %} diff --git a/src/ShadcnAdminUi/tests/Functional/BreadcrumbsMacroTest.php b/src/ShadcnAdminUi/tests/Functional/BreadcrumbsMacroTest.php new file mode 100644 index 00000000..d6be6ec0 --- /dev/null +++ b/src/ShadcnAdminUi/tests/Functional/BreadcrumbsMacroTest.php @@ -0,0 +1,46 @@ +crawl(<<<'TWIG' + {% from '@SyliusShadcnAdminUi/shared/helper/breadcrumbs.html.twig' import breadcrumbs %} + {{ breadcrumbs([{name: 'Dashboard', url: '/admin'}, null, {name: 'Speakers', url: '/admin/speakers'}, {name: 'Julien', active: true}, {name: 'Edit'}]) }} + TWIG); + + self::assertSame(4, $crawler->filter('[data-slot="breadcrumb-item"]')->count()); + self::assertSame(3, $crawler->filter('[data-slot="breadcrumb-separator"]')->count()); + self::assertSame(['/admin', '/admin/speakers'], $crawler->filter('a[data-slot="breadcrumb-link"]')->each(static fn ($link): string => (string) $link->attr('href'))); + self::assertSame('Julien', trim($crawler->filter('[data-slot="breadcrumb-item"]')->eq(2)->text())); + self::assertSame(['Edit'], $crawler->filter('[aria-current="page"]')->each(static fn ($page): string => trim($page->text()))); + } + + public function testAnActiveItemIsNotALink(): void + { + $crawler = $this->crawl(<<<'TWIG' + {% from '@SyliusShadcnAdminUi/shared/helper/breadcrumbs.html.twig' import breadcrumbs %} + {{ breadcrumbs([{name: 'Dashboard', url: '/admin'}, {name: 'Books', url: '/admin/books', active: true}]) }} + TWIG); + + self::assertSame(1, $crawler->filter('a[data-slot="breadcrumb-link"]')->count()); + self::assertSame('Books', trim($crawler->filter('[data-slot="breadcrumb-page"][aria-current="page"]')->text())); + } +} From 3abb848e083567e99b84bcf375c9503e88051213 Mon Sep 17 00:00:00 2001 From: camilleislasse Date: Sat, 14 Nov 2026 10:35:22 +0100 Subject: [PATCH 13/27] refactor(shadcn-admin-ui): render the avatars with the Avatar components --- docs/shadcn-admin-ui/components.md | 3 +- .../templates/shared/helper/avatar.html.twig | 16 ++--- .../tests/Functional/AvatarMacroTest.php | 70 +++++++++++++++++++ 3 files changed, 79 insertions(+), 10 deletions(-) create mode 100644 src/ShadcnAdminUi/tests/Functional/AvatarMacroTest.php diff --git a/docs/shadcn-admin-ui/components.md b/docs/shadcn-admin-ui/components.md index 37fb6be8..72b25f84 100644 --- a/docs/shadcn-admin-ui/components.md +++ b/docs/shadcn-admin-ui/components.md @@ -67,7 +67,7 @@ Same macro APIs as `@SyliusBootstrapAdminUi`: only the namespace changes. | `table.html.twig` | `headers`, `row` | | `pagination.html.twig` | `simple(paginator, options)`, `results_count(paginator)` | | `accordion.html.twig` | `accordion(items, open, auto_close, flush)` | -| `avatar.html.twig` | `default(img, class, initials)`, `small(img, class, initials)` | +| `avatar.html.twig` | `default(img, class, initials, size)`, `small(img, class, initials)` | | `palette.html.twig` | [`tone(color, kind)`](theming.md#the-tone-macro) | The button macros accept an extra `variant` param: `default`, `secondary`, `outline`, `ghost`, `destructive`, `link`. @@ -205,7 +205,6 @@ Classes copied outside the components must be synced **by hand**: - `shared/crud/index/content/grid/no_results/image.html.twig`: `Empty/Media` - `shared/helper/_checkbox.html.twig`: `Checkbox` - `shared/helper/accordion.html.twig`: `Card` -- `shared/helper/avatar.html.twig`: `Avatar` - `shared/helper/dropdown.html.twig`: `DropdownMenu` - `shared/helper/header.html.twig`: `Empty/Media` - `shared/helper/sorting.html.twig`: `Table/Head` diff --git a/src/ShadcnAdminUi/templates/shared/helper/avatar.html.twig b/src/ShadcnAdminUi/templates/shared/helper/avatar.html.twig index 741ff087..ccb3e4bb 100644 --- a/src/ShadcnAdminUi/templates/shared/helper/avatar.html.twig +++ b/src/ShadcnAdminUi/templates/shared/helper/avatar.html.twig @@ -1,15 +1,15 @@ -{% macro default(img, class, initials) %} - +{% macro default(img, class, initials, size = 'default') %} + {% if img %} - + {% else %} - - {% if initials %}{{ initials }}{% else %}{{ ux_icon('lucide:user', {class: 'size-4'}) }}{% endif %} - + + {% if initials %}{{ initials }}{% else %}{{ ux_icon('lucide:user', {class: 'size-4', 'aria-hidden': 'true'}) }}{% endif %} + {% endif %} - + {% endmacro %} {% macro small(img, class, initials) %} - {{ _self.default(img, 'size-6 ' ~ class, initials) }} + {{ _self.default(img, class, initials, 'sm') }} {% endmacro %} diff --git a/src/ShadcnAdminUi/tests/Functional/AvatarMacroTest.php b/src/ShadcnAdminUi/tests/Functional/AvatarMacroTest.php new file mode 100644 index 00000000..b7ea4d4b --- /dev/null +++ b/src/ShadcnAdminUi/tests/Functional/AvatarMacroTest.php @@ -0,0 +1,70 @@ +crawl(<<<'TWIG' + {% import '@SyliusShadcnAdminUi/shared/helper/avatar.html.twig' as avatar %} + {{ avatar.default('/avatar.jpg', 'my-avatar', 'jd') }} + TWIG); + + $root = $crawler->filter('[data-slot="avatar"]'); + self::assertSame('default', $root->attr('data-size')); + self::assertStringContainsString('my-avatar', (string) $root->attr('class')); + $image = $crawler->filter('img[data-slot="avatar-image"]'); + self::assertSame('/avatar.jpg', $image->attr('src')); + self::assertNotContains('hidden', explode(' ', (string) $image->attr('class'))); + self::assertCount(0, $crawler->filter('[data-slot="avatar-fallback"]')); + } + + public function testItRendersTheInitialsWithoutImage(): void + { + $crawler = $this->crawl(<<<'TWIG' + {% import '@SyliusShadcnAdminUi/shared/helper/avatar.html.twig' as avatar %} + {{ avatar.default(null, '', 'jd') }} + TWIG); + + self::assertCount(0, $crawler->filter('img')); + self::assertSame('jd', trim($crawler->filter('[data-slot="avatar-fallback"]')->text())); + } + + public function testItRendersAnIconWithoutImageNorInitials(): void + { + $crawler = $this->crawl(<<<'TWIG' + {% import '@SyliusShadcnAdminUi/shared/helper/avatar.html.twig' as avatar %} + {{ avatar.default(null, '') }} + TWIG); + + self::assertCount(0, $crawler->filter('img')); + self::assertCount(1, $crawler->filter('[data-slot="avatar-fallback"] svg')); + } + + public function testSmallRendersTheSmallSize(): void + { + $crawler = $this->crawl(<<<'TWIG' + {% import '@SyliusShadcnAdminUi/shared/helper/avatar.html.twig' as avatar %} + {{ avatar.small(null, '', 'JD') }} + TWIG); + + self::assertSame('sm', $crawler->filter('[data-slot="avatar"]')->attr('data-size')); + self::assertSame('JD', trim($crawler->filter('[data-slot="avatar-fallback"]')->text())); + } +} From a802ddc6fedd1c2f84385f401b8194bd0236a313 Mon Sep 17 00:00:00 2001 From: camilleislasse Date: Sat, 14 Nov 2026 10:39:37 +0100 Subject: [PATCH 14/27] refactor(shadcn-admin-ui): render the menu search with the Sidebar:Input component --- docs/shadcn-admin-ui/components.md | 1 - .../templates/shared/crud/common/sidebar/search.html.twig | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/shadcn-admin-ui/components.md b/docs/shadcn-admin-ui/components.md index 72b25f84..0440de3c 100644 --- a/docs/shadcn-admin-ui/components.md +++ b/docs/shadcn-admin-ui/components.md @@ -198,7 +198,6 @@ Classes copied outside the components must be synced **by hand**: - `shared/pagerfanta.html.twig`: `Pagination`, `Button` - `shared/components/badge.html.twig`: `Badge` - `shared/components/confirmation_modal.html.twig`: `AlertDialog`, `Dialog/Footer` -- `shared/crud/common/sidebar/search.html.twig`: `Input` - `shared/crud/index/content/grid/data_table.html.twig`: `Card`, `Table` - `shared/crud/index/content/grid/filters.html.twig`: `Card` - `shared/crud/index/content/grid/no_results.html.twig`: `Empty` diff --git a/src/ShadcnAdminUi/templates/shared/crud/common/sidebar/search.html.twig b/src/ShadcnAdminUi/templates/shared/crud/common/sidebar/search.html.twig index 2f488f08..87efaedc 100644 --- a/src/ShadcnAdminUi/templates/shared/crud/common/sidebar/search.html.twig +++ b/src/ShadcnAdminUi/templates/shared/crud/common/sidebar/search.html.twig @@ -1,13 +1,13 @@
{{ ux_icon('lucide:search', {class: 'pointer-events-none absolute start-4 top-1/2 mt-1 size-4 -translate-y-1/2 text-muted-foreground', 'aria-hidden': 'true'}) }} - + />
From 0eb19f71129108eb879685d9b47f9a9f64d02e5f Mon Sep 17 00:00:00 2001 From: camilleislasse Date: Sat, 14 Nov 2026 10:49:31 +0100 Subject: [PATCH 15/27] refactor(shadcn-admin-ui): render the grid table with the Card and Table components --- docs/shadcn-admin-ui/components.md | 1 - .../index/content/grid/data_table.html.twig | 39 ++++++++++--------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/docs/shadcn-admin-ui/components.md b/docs/shadcn-admin-ui/components.md index 0440de3c..ee7b54b3 100644 --- a/docs/shadcn-admin-ui/components.md +++ b/docs/shadcn-admin-ui/components.md @@ -198,7 +198,6 @@ Classes copied outside the components must be synced **by hand**: - `shared/pagerfanta.html.twig`: `Pagination`, `Button` - `shared/components/badge.html.twig`: `Badge` - `shared/components/confirmation_modal.html.twig`: `AlertDialog`, `Dialog/Footer` -- `shared/crud/index/content/grid/data_table.html.twig`: `Card`, `Table` - `shared/crud/index/content/grid/filters.html.twig`: `Card` - `shared/crud/index/content/grid/no_results.html.twig`: `Empty` - `shared/crud/index/content/grid/no_results/image.html.twig`: `Empty/Media` diff --git a/src/ShadcnAdminUi/templates/shared/crud/index/content/grid/data_table.html.twig b/src/ShadcnAdminUi/templates/shared/crud/index/content/grid/data_table.html.twig index e5673e26..02296368 100644 --- a/src/ShadcnAdminUi/templates/shared/crud/index/content/grid/data_table.html.twig +++ b/src/ShadcnAdminUi/templates/shared/crud/index/content/grid/data_table.html.twig @@ -1,13 +1,20 @@ -{% import '@SyliusShadcnAdminUi/shared/helper/table.html.twig' as table %} -{% import '@SyliusShadcnAdminUi/shared/helper/pagination.html.twig' as pagination %} - {% set resources = resources|default(hookable_metadata.context.resources|default(null)) %} {% set data = resources.data|default([]) %} {% set definition = resources.definition|default(null) %} {% set has_bulk_actions = definition.actionGroups.bulk is defined and definition.getEnabledActions('bulk')|length > 0 %} {% if data|length > 0 %} -
+ + {% import '@SyliusShadcnAdminUi/shared/helper/table.html.twig' as table %} + {% import '@SyliusShadcnAdminUi/shared/helper/pagination.html.twig' as pagination %} + + {% set headers %}{{ table.headers(resources, definition, app.request.attributes) }}{% endset %} + {% set rows %} + {% for row in data %} + {{ table.row(resources, definition, row) }} + {% endfor %} + {% endset %} +
{% if has_bulk_actions %}
@@ -21,20 +28,14 @@
-
- - - - {{ table.headers(resources, resources.definition, app.request.attributes) }} - - - - {% for row in resources.data %} - {{ table.row(resources, resources.definition, row) }} - {% endfor %} - -
-
+ + + {{ headers }} + + + {{ rows }} + +
@@ -44,5 +45,5 @@ {{ pagination.simple(data) }}
-
+ {% endif %} From 39d91523f53afc8364ca83eb2623ba5dc98c7e19 Mon Sep 17 00:00:00 2001 From: camilleislasse Date: Sat, 14 Nov 2026 10:58:54 +0100 Subject: [PATCH 16/27] refactor(shadcn-admin-ui): render the filter buttons with the Button component --- docs/shadcn-admin-ui/components.md | 2 +- .../shared/crud/index/content/grid/filters.html.twig | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/docs/shadcn-admin-ui/components.md b/docs/shadcn-admin-ui/components.md index ee7b54b3..97cf3ed2 100644 --- a/docs/shadcn-admin-ui/components.md +++ b/docs/shadcn-admin-ui/components.md @@ -198,7 +198,7 @@ Classes copied outside the components must be synced **by hand**: - `shared/pagerfanta.html.twig`: `Pagination`, `Button` - `shared/components/badge.html.twig`: `Badge` - `shared/components/confirmation_modal.html.twig`: `AlertDialog`, `Dialog/Footer` -- `shared/crud/index/content/grid/filters.html.twig`: `Card` +- `shared/crud/index/content/grid/filters.html.twig`: `Card`, `Collapsible` - `shared/crud/index/content/grid/no_results.html.twig`: `Empty` - `shared/crud/index/content/grid/no_results/image.html.twig`: `Empty/Media` - `shared/helper/_checkbox.html.twig`: `Checkbox` diff --git a/src/ShadcnAdminUi/templates/shared/crud/index/content/grid/filters.html.twig b/src/ShadcnAdminUi/templates/shared/crud/index/content/grid/filters.html.twig index 96d50fc5..6e7cd11e 100644 --- a/src/ShadcnAdminUi/templates/shared/crud/index/content/grid/filters.html.twig +++ b/src/ShadcnAdminUi/templates/shared/crud/index/content/grid/filters.html.twig @@ -5,8 +5,6 @@ # Inner hooks: "filters#trigger" (inside the trigger, after its title) and "filters#summary" (between the trigger # and the form, visible when the panel is collapsed). #} -{% from '@SyliusShadcnAdminUi/shared/helper/ui.html.twig' import button_class %} - {% set resources = resources|default(hookable_metadata.context.resources|default(null)) %} {% set path = path(app.request.attributes.get('_route'), app.request.attributes.all('_route_params')) %} {% set criteria = app.request.query.all('criteria') %} @@ -53,14 +51,14 @@ {% endfor %}
- - + + {{ ux_icon('lucide:rotate-ccw', {'data-icon': 'inline-start', 'aria-hidden': 'true'}) }} {{ 'sylius.ui.reset'|trans }} - +
From fc15e862be88043f80ae33b1b158af1b26b2608f Mon Sep 17 00:00:00 2001 From: camilleislasse Date: Sat, 14 Nov 2026 11:06:25 +0100 Subject: [PATCH 17/27] refactor(shadcn-admin-ui): render the accordion with the Card and Collapsible components --- docs/shadcn-admin-ui/components.md | 1 - .../templates/shared/helper/accordion.html.twig | 14 +++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/docs/shadcn-admin-ui/components.md b/docs/shadcn-admin-ui/components.md index 97cf3ed2..5168ac77 100644 --- a/docs/shadcn-admin-ui/components.md +++ b/docs/shadcn-admin-ui/components.md @@ -202,7 +202,6 @@ Classes copied outside the components must be synced **by hand**: - `shared/crud/index/content/grid/no_results.html.twig`: `Empty` - `shared/crud/index/content/grid/no_results/image.html.twig`: `Empty/Media` - `shared/helper/_checkbox.html.twig`: `Checkbox` -- `shared/helper/accordion.html.twig`: `Card` - `shared/helper/dropdown.html.twig`: `DropdownMenu` - `shared/helper/header.html.twig`: `Empty/Media` - `shared/helper/sorting.html.twig`: `Table/Head` diff --git a/src/ShadcnAdminUi/templates/shared/helper/accordion.html.twig b/src/ShadcnAdminUi/templates/shared/helper/accordion.html.twig index ed1cea2f..3adb7b21 100644 --- a/src/ShadcnAdminUi/templates/shared/helper/accordion.html.twig +++ b/src/ShadcnAdminUi/templates/shared/helper/accordion.html.twig @@ -1,18 +1,18 @@ -{# Same signature as the BootstrapAdminUi macro, based on the shadcn Collapsible controller. #} +{# Same signature as the BootstrapAdminUi macro, based on the shadcn Collapsible component. #} {% macro accordion(items, open = false, auto_close = null, flush = false) %} -
+ {% for item in items %} {% set item = {open: open, icon: null}|merge(item) %} -
+ -
+ {{ item.content|default('Content') }} -
-
+ + {% endfor %} -
+ {% endmacro %} From 3e01398f99961fc1eb2b0a6acb74c2ac24715adc Mon Sep 17 00:00:00 2001 From: camilleislasse Date: Sat, 14 Nov 2026 11:17:21 +0100 Subject: [PATCH 18/27] refactor(shadcn-admin-ui): render the dropdown macros with the DropdownMenu components --- docs/shadcn-admin-ui/components.md | 1 - .../shared/helper/dropdown.html.twig | 74 ++++--------- .../tests/Functional/DropdownMacroTest.php | 101 ++++++++++++++++++ 3 files changed, 124 insertions(+), 52 deletions(-) create mode 100644 src/ShadcnAdminUi/tests/Functional/DropdownMacroTest.php diff --git a/docs/shadcn-admin-ui/components.md b/docs/shadcn-admin-ui/components.md index 5168ac77..d2002cf9 100644 --- a/docs/shadcn-admin-ui/components.md +++ b/docs/shadcn-admin-ui/components.md @@ -202,7 +202,6 @@ Classes copied outside the components must be synced **by hand**: - `shared/crud/index/content/grid/no_results.html.twig`: `Empty` - `shared/crud/index/content/grid/no_results/image.html.twig`: `Empty/Media` - `shared/helper/_checkbox.html.twig`: `Checkbox` -- `shared/helper/dropdown.html.twig`: `DropdownMenu` - `shared/helper/header.html.twig`: `Empty/Media` - `shared/helper/sorting.html.twig`: `Table/Head` - `shared/helper/table.html.twig`: `Table` diff --git a/src/ShadcnAdminUi/templates/shared/helper/dropdown.html.twig b/src/ShadcnAdminUi/templates/shared/helper/dropdown.html.twig index fbb663bf..a7a762fe 100644 --- a/src/ShadcnAdminUi/templates/shared/helper/dropdown.html.twig +++ b/src/ShadcnAdminUi/templates/shared/helper/dropdown.html.twig @@ -1,10 +1,8 @@ {# # Same signature as the BootstrapAdminUi macros (default / list), rendered with the shadcn - # DropdownMenu controller. params.id makes the generated ids stable (random otherwise). + # DropdownMenu components. params.id makes the generated ids stable (random otherwise). #} {% macro default(params) %} - {% from '@SyliusShadcnAdminUi/shared/helper/ui.html.twig' import button_class %} - {% set params = { id: 'dropdown-' ~ random(), button: {}, @@ -13,57 +11,30 @@ customTrigger: null, direction: 'down', }|merge(params) %} - {% set trigger_id = 'dropdown-menu-' ~ params.id ~ '-trigger' %} - {% set content_id = 'dropdown-menu-' ~ params.id ~ '-content' %} - {% set align_class = params.direction == 'down-end' ? 'end-0 ltr:origin-top-right rtl:origin-top-left' : 'start-0 ltr:origin-top-left rtl:origin-top-right' %} -
- {% set trigger_attributes %} - id="{{ trigger_id }}" data-slot="dropdown-menu-trigger" data-shadcn--dropdown-menu-target="trigger" aria-haspopup="menu" aria-controls="{{ content_id }}" aria-expanded="false" data-state="closed" data-action="click->shadcn--dropdown-menu#toggle keydown->shadcn--dropdown-menu#onTriggerKeydown" - {% endset %} - {% if params.customTrigger %} -
{{ params.customTrigger }}
- {% else %} - {% set button = {text: 'Menu', icon: null, class: null}|merge(params.button) %} - - {% endif %} - -
+ + {% endmacro %} {# content is printed raw: escape user data before passing it. #} {% macro item(attributes = {}, content = '', variant = 'default') %} - {% from '@SyliusShadcnAdminUi/shared/helper/ui.html.twig' import html_attributes %} - {% set tag = attributes.href is defined ? 'a' : 'button' %} - <{{ tag }} - role="menuitem" - tabindex="-1" - data-slot="dropdown-menu-item" - data-variant="{{ variant }}" - data-shadcn--dropdown-menu-target="item" - data-close-on-select="true" - data-action="click->shadcn--dropdown-menu#closeFromItem" - {% if tag == 'button' %}type="button"{% endif %} - class="relative flex w-full cursor-default items-center gap-1.5 rounded-md px-1.5 py-1 text-sm outline-hidden transition-colors select-none hover:bg-accent hover:text-accent-foreground focus:bg-accent focus:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*=size-])]:size-4 {{ variant == 'destructive' ? 'text-destructive hover:bg-destructive/10 hover:text-destructive focus:bg-destructive/10 focus:text-destructive' : '' }}" - {{- html_attributes(attributes) }} - >{{ content|raw }} + {% set href = attributes.href|default(null) %} + {{ content|raw }} {% endmacro %} {% macro list(params, items) %} @@ -71,12 +42,13 @@ {% for item in items %} {% set item = {type: null, class: null, icon: null}|merge(item) %} {% if item.type == 'header' %} -
{{ item.title|trans }}
+ {{ item.title|trans }} {% elseif item.type == 'divider' %} - + {% else %} + {% set title = item.title|trans %} {% set icon = item.icon ? ux_icon(item.icon, {'aria-hidden': 'true'}) : '' %} - {{ _self.item({href: item.url, class: item.class}, icon ~ (item.title|trans|e)) }} + {{ _self.item({href: item.url|default(null), class: item.class}|merge(sylius_test_form_attribute('user-dropdown-item', title).attr|default({})), icon ~ (title|e)) }} {% endif %} {% endfor %} {% endset %} diff --git a/src/ShadcnAdminUi/tests/Functional/DropdownMacroTest.php b/src/ShadcnAdminUi/tests/Functional/DropdownMacroTest.php new file mode 100644 index 00000000..d728869b --- /dev/null +++ b/src/ShadcnAdminUi/tests/Functional/DropdownMacroTest.php @@ -0,0 +1,101 @@ +crawl(<<<'TWIG' + {% import '@SyliusShadcnAdminUi/shared/helper/dropdown.html.twig' as dropdown %} + {{ dropdown.list({id: 'user', button: {text: 'Menu'}}, [ + {type: 'header', title: 'Account'}, + {title: 'Profile', url: '/profile', class: 'my-item'}, + {type: 'divider'}, + {title: 'Logout', url: '/logout'}, + ]) }} + TWIG); + + self::assertSame('dropdown-menu-user-content', $crawler->filter('#dropdown-menu-user-trigger')->attr('aria-controls')); + self::assertSame('Account', trim($crawler->filter('[data-slot="dropdown-menu-label"]')->text())); + self::assertCount(1, $crawler->filter('[data-slot="dropdown-menu-separator"]')); + + $profile = $crawler->filter('a[role="menuitem"][href="/profile"]'); + self::assertStringContainsString('my-item', (string) $profile->attr('class')); + self::assertSame('Profile', $profile->attr('data-test-user-dropdown-item')); + self::assertCount(2, $crawler->filter('[data-test-user-dropdown-item]')); + } + + public function testTheButtonTriggerOpensTheMenuAndKeepsItsClass(): void + { + $crawler = $this->crawl(<<<'TWIG' + {% import '@SyliusShadcnAdminUi/shared/helper/dropdown.html.twig' as dropdown %} + {{ dropdown.default({id: 'limit', button: {text: 'Show 10', class: 'h-7'}, content: ''}) }} + TWIG); + + $trigger = $crawler->filter('button#dropdown-menu-limit-trigger'); + self::assertSame('trigger', $trigger->attr('data-shadcn--dropdown-menu-target')); + self::assertStringContainsString('shadcn--dropdown-menu#toggle', (string) $trigger->attr('data-action')); + $classes = explode(' ', (string) $trigger->attr('class')); + self::assertContains('h-7', $classes); + self::assertNotContains('h-8', $classes); + } + + public function testAListItemWithoutUrlIsAButton(): void + { + $crawler = $this->crawl(<<<'TWIG' + {% import '@SyliusShadcnAdminUi/shared/helper/dropdown.html.twig' as dropdown %} + {{ dropdown.list({id: 'list'}, [{title: 'Refresh'}]) }} + TWIG); + + self::assertCount(0, $crawler->filter('a[role="menuitem"]')); + self::assertNull($crawler->filter('button[role="menuitem"]')->attr('href')); + } + + public function testItemRendersALinkOnlyWithAnHref(): void + { + $crawler = $this->crawl(<<<'TWIG' + {% import '@SyliusShadcnAdminUi/shared/helper/dropdown.html.twig' as dropdown %} + {{ dropdown.item({href: '/books'}, 'Books') }} + {{ dropdown.item({href: ''}, 'Empty') }} + {{ dropdown.item({href: null}, 'Null') }} + TWIG); + + self::assertSame(['/books'], $crawler->filter('a[role="menuitem"]')->each(static fn ($link): string => (string) $link->attr('href'))); + self::assertCount(2, $crawler->filter('button[role="menuitem"]')); + self::assertCount(0, $crawler->filter('button[href]')); + } + + public function testItemRendersAButtonWithItsVariant(): void + { + $crawler = $this->crawl(<<<'TWIG' + {% import '@SyliusShadcnAdminUi/shared/helper/dropdown.html.twig' as dropdown %} + {{ dropdown.default({id: 'row', customTrigger: 'More', content: dropdown.item({}, 'Delete', 'destructive'), direction: 'down-end'}) }} + TWIG); + + self::assertSame('end', $crawler->filter('[data-slot="dropdown-menu-content"]')->attr('data-align')); + $trigger = $crawler->filter('#dropdown-menu-row-trigger'); + self::assertSame('button', $trigger->attr('role')); + self::assertSame('dropdown-menu-row-content', $trigger->attr('aria-controls')); + self::assertSame('trigger', $trigger->attr('data-shadcn--dropdown-menu-target')); + self::assertStringContainsString('shadcn--dropdown-menu#toggle', (string) $trigger->attr('data-action')); + $item = $crawler->filter('button[role="menuitem"]'); + self::assertSame('destructive', $item->attr('data-variant')); + self::assertSame('Delete', trim($item->text())); + } +} From 48061066eaa87a9696f5398d272b08a50e3c21b6 Mon Sep 17 00:00:00 2001 From: camilleislasse Date: Sat, 14 Nov 2026 11:37:03 +0100 Subject: [PATCH 19/27] fix(shadcn-admin-ui): color the apply_transition actions with the palette --- docs/shadcn-admin-ui/grids.md | 8 ++++++++ .../shared/grid/action/apply_transition.html.twig | 11 ++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/docs/shadcn-admin-ui/grids.md b/docs/shadcn-admin-ui/grids.md index 4351ab66..48e631f0 100644 --- a/docs/shadcn-admin-ui/grids.md +++ b/docs/shadcn-admin-ui/grids.md @@ -10,6 +10,14 @@ Sylius grids are rendered as a shadcn data table with: - filters `string`, `boolean`, `date`, `enum`, `entity`, `exists`, `select`; - a card layout below the `md` breakpoint. +The `class` option of an `apply_transition` action colors its (single-color) icon with a +[palette](theming.md#the-tone-macro) color: `success`, `danger`, `warning`, `info`, `green`, `red`… The `outline-` and +`ghost-` prefixes of BootstrapAdminUi are ignored, and an unknown color renders as `secondary`. + +```php +ApplyTransitionAction::create(name: 'accept', route: 'app_admin_application_accept', options: ['class' => 'success']); +``` + ## Column options Cells are `whitespace-nowrap`: the table scrolls horizontally when needed. A field's `vars` option accepts: diff --git a/src/ShadcnAdminUi/templates/shared/grid/action/apply_transition.html.twig b/src/ShadcnAdminUi/templates/shared/grid/action/apply_transition.html.twig index df4a0381..2bddb9d0 100644 --- a/src/ShadcnAdminUi/templates/shared/grid/action/apply_transition.html.twig +++ b/src/ShadcnAdminUi/templates/shared/grid/action/apply_transition.html.twig @@ -1,4 +1,4 @@ -{% from '@SyliusShadcnAdminUi/shared/helper/ui.html.twig' import button_class %} +{% from '@SyliusShadcnAdminUi/shared/helper/palette.html.twig' import tone %} {% if workflow_can(data, action.name) %} {% if options.link.url is defined %} @@ -8,14 +8,15 @@ {% endif %} {% set message = action.label|default('sylius.ui.apply_transition') %} - {% set variants = {danger: 'destructive', red: 'destructive', primary: 'default', green: 'secondary', success: 'secondary'} %} + {% set color = options.class|default('')|replace({'outline-': '', 'ghost-': ''}) %} + {% set icon_attributes = {'aria-hidden': 'true'}|merge(color ? {class: tone(color, 'text')|trim} : {}) %}
- +
{% endif %} From 986ec2d22f2428dfcdccd797476ce1f4c084fb51 Mon Sep 17 00:00:00 2001 From: camilleislasse Date: Sat, 14 Nov 2026 12:35:09 +0100 Subject: [PATCH 20/27] fix(shadcn-admin-ui): keep a single accordion item open and link each trigger to its panel --- docs/shadcn-admin-ui/components.md | 3 +- .../controllers/admin/accordion_controller.js | 18 +++++ .../shared/helper/accordion.html.twig | 33 +++++--- .../tests/Functional/AccordionMacroTest.php | 77 +++++++++++++++++++ 4 files changed, 121 insertions(+), 10 deletions(-) create mode 100644 src/ShadcnAdminUi/assets/controllers/admin/accordion_controller.js create mode 100644 src/ShadcnAdminUi/tests/Functional/AccordionMacroTest.php diff --git a/docs/shadcn-admin-ui/components.md b/docs/shadcn-admin-ui/components.md index d2002cf9..8b0d0d72 100644 --- a/docs/shadcn-admin-ui/components.md +++ b/docs/shadcn-admin-ui/components.md @@ -66,7 +66,7 @@ Same macro APIs as `@SyliusBootstrapAdminUi`: only the namespace changes. | `dropdown.html.twig` | `default(params)`, `list(params, items)`, `item(attributes, content, variant)` | | `table.html.twig` | `headers`, `row` | | `pagination.html.twig` | `simple(paginator, options)`, `results_count(paginator)` | -| `accordion.html.twig` | `accordion(items, open, auto_close, flush)` | +| `accordion.html.twig` | `accordion(items, open, auto_close, flush)`: `auto_close: false` keeps several items open, no `flag` item option | | `avatar.html.twig` | `default(img, class, initials, size)`, `small(img, class, initials)` | | `palette.html.twig` | [`tone(color, kind)`](theming.md#the-tone-macro) | @@ -121,6 +121,7 @@ Registered automatically by the bundle. | Identifier | Role | |---------------------------------------------|------------------------------------------------------------------| | `admin--tabs` | Accessible tabs ([see above](#tabs)) | +| `admin--accordion` | Keeps a single item of the `accordion()` macro open | | `admin--grid-selection` | Row selection, "select all", bulk action forms | | `admin--copy-to-clipboard` | Copy buttons | | `admin--dismissible` | Closable flash messages and alerts | diff --git a/src/ShadcnAdminUi/assets/controllers/admin/accordion_controller.js b/src/ShadcnAdminUi/assets/controllers/admin/accordion_controller.js new file mode 100644 index 00000000..30b17d4b --- /dev/null +++ b/src/ShadcnAdminUi/assets/controllers/admin/accordion_controller.js @@ -0,0 +1,18 @@ +import { Controller } from '@hotwired/stimulus'; + +/** Keeps a single item open in an accordion of shadcn Collapsible items: opening one closes the others. */ +export default class extends Controller { + closeOthers(event) { + const item = event.currentTarget.closest('[data-controller~="shadcn--collapsible"]'); + + if (item?.parentElement !== this.element || item.getAttribute('data-shadcn--collapsible-open-value') !== 'true') { + return; + } + + for (const other of this.element.querySelectorAll(':scope > [data-controller~="shadcn--collapsible"]')) { + if (other !== item) { + other.setAttribute('data-shadcn--collapsible-open-value', 'false'); + } + } + } +} diff --git a/src/ShadcnAdminUi/templates/shared/helper/accordion.html.twig b/src/ShadcnAdminUi/templates/shared/helper/accordion.html.twig index 3adb7b21..fdd046bf 100644 --- a/src/ShadcnAdminUi/templates/shared/helper/accordion.html.twig +++ b/src/ShadcnAdminUi/templates/shared/helper/accordion.html.twig @@ -1,15 +1,30 @@ -{# Same signature as the BootstrapAdminUi macro, based on the shadcn Collapsible component. #} +{# Same signature as the BootstrapAdminUi macro, based on the shadcn Collapsible component. The "flag" item option is not supported. #} {% macro accordion(items, open = false, auto_close = null, flush = false) %} - + {% set accordion_id = 'accordion-' ~ random() %} + {% set auto_close = auto_close is not same as(false) %} + + {% for item in items %} {% set item = {open: open, icon: null}|merge(item) %} - - - + {% set content_id = item.id|default(accordion_id ~ '-' ~ loop.index) %} + + +

+ +

+
+ {{ item.content|default('Content') }}
diff --git a/src/ShadcnAdminUi/tests/Functional/AccordionMacroTest.php b/src/ShadcnAdminUi/tests/Functional/AccordionMacroTest.php new file mode 100644 index 00000000..d46e0971 --- /dev/null +++ b/src/ShadcnAdminUi/tests/Functional/AccordionMacroTest.php @@ -0,0 +1,77 @@ +crawl(<<<'TWIG' + {% import '@SyliusShadcnAdminUi/shared/helper/accordion.html.twig' as accordion %} + {{ accordion.accordion([ + {title: 'First 1', content: 'A'}, + {title: 'Second', content: 'B', open: true, id: 'second'}, + ]) }} + TWIG); + + $triggers = $crawler->filter('button[data-shadcn--collapsible-target="trigger"]'); + self::assertSame(['false', 'true'], $triggers->each(static fn ($trigger): string => (string) $trigger->attr('aria-expanded'))); + self::assertStringContainsString('First 1', $triggers->eq(0)->text()); + + self::assertSame('second', $triggers->eq(1)->attr('aria-controls')); + self::assertSame('collapsible-content', $crawler->filter('#second')->attr('data-slot')); + self::assertSame('collapsible-content', $crawler->filter('#' . $triggers->eq(0)->attr('aria-controls'))->attr('data-slot')); + self::assertCount(2, $crawler->filter('h2 > button[data-shadcn--collapsible-target="trigger"]')); + } + + public function testItWiresTheSingleOpenControllerByDefault(): void + { + $crawler = $this->crawl(<<<'TWIG' + {% import '@SyliusShadcnAdminUi/shared/helper/accordion.html.twig' as accordion %} + {{ accordion.accordion([{title: 'A', content: 'A'}]) }} + TWIG); + + $card = $crawler->filter('[data-slot="card"]'); + self::assertSame('admin--accordion', $card->attr('data-controller')); + self::assertSame('click->shadcn--collapsible#toggle admin--accordion#closeOthers', $crawler->filter('button[data-shadcn--collapsible-target="trigger"]')->attr('data-action')); + } + + public function testEachChevronFollowsItsOwnTrigger(): void + { + $crawler = $this->crawl(<<<'TWIG' + {% import '@SyliusShadcnAdminUi/shared/helper/accordion.html.twig' as accordion %} + {{ accordion.accordion([{title: 'Outer', open: true, content: accordion.accordion([{title: 'Inner', content: 'A'}])}]) }} + TWIG); + + $triggers = $crawler->filter('button.group\/trigger'); + self::assertSame(['open', 'closed'], $triggers->each(static fn ($trigger): string => (string) $trigger->attr('data-state'))); + self::assertCount(0, $crawler->filter('.group\/collapsible')); + $triggers->each(static fn ($trigger) => self::assertStringContainsString('group-data-[state=open]/trigger:rotate-180', (string) $trigger->filter('svg')->last()->attr('class'))); + } + + public function testAutoCloseFalseAllowsSeveralOpenItems(): void + { + $crawler = $this->crawl(<<<'TWIG' + {% import '@SyliusShadcnAdminUi/shared/helper/accordion.html.twig' as accordion %} + {{ accordion.accordion([{title: 'A', content: 'A'}, {title: 'B', content: 'B'}], true, false) }} + TWIG); + + self::assertNull($crawler->filter('[data-slot="card"]')->attr('data-controller')); + self::assertCount(2, $crawler->filter('button[aria-expanded="true"]')); + } +} From b726a02852f5a36ef20bc3beb40806f0e61dd253 Mon Sep 17 00:00:00 2001 From: camilleislasse Date: Sat, 14 Nov 2026 12:48:07 +0100 Subject: [PATCH 21/27] docs(shadcn-admin-ui): explain how to replace the Bootstrap JavaScript when migrating --- docs/shadcn-admin-ui/migration.md | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/docs/shadcn-admin-ui/migration.md b/docs/shadcn-admin-ui/migration.md index c18162ce..1eb8d69d 100644 --- a/docs/shadcn-admin-ui/migration.md +++ b/docs/shadcn-admin-ui/migration.md @@ -28,13 +28,26 @@ is a search and replace. 4. **Rewrite Bootstrap classes** of your custom templates with Tailwind utilities. -5. **Icons**: nothing to do. `tabler:*` names keep working through UX Icons; the theme itself uses `lucide:*`. +5. **Replace the Bootstrap JavaScript**: it is not loaded, so the `data-bs-*` attributes of your templates stop + working, without any error. + + | BootstrapAdminUi | Shadcn Admin UI | + |--------------------------------|---------------------------------------------------------------------| + | `data-bs-toggle="modal"` | `` or `` | + | `data-bs-toggle="tab"` | The `admin--tabs` controller (see [Tabs](components.md#tabs)) | + | `data-bs-toggle="dropdown"` | `` or the `dropdown` macros | + | `data-bs-toggle="tooltip"` | ``, or a `title` attribute | + | `data-bs-toggle="collapse"` | `` or the `accordion` macro | + | `data-bs-dismiss="modal"` | ``, or `dialog_close_attrs` of `` on a button | + | `data-bs-dismiss="alert"` | `data-controller="admin--dismissible"` on the alert and `data-action="admin--dismissible#close"` on its close button | + +6. **Icons**: nothing to do. `tabler:*` names keep working through UX Icons; the theme itself uses `lucide:*`. {% hint style="info" %} Find what is left to migrate: ```bash -grep -rn "SyliusBootstrapAdminUi\|sylius_bootstrap_admin_ui" templates config +grep -rn "SyliusBootstrapAdminUi\|sylius_bootstrap_admin_ui\|data-bs-" templates config ``` {% endhint %} From e343a2d5cf482b70da3110dd23306d9639601507 Mon Sep 17 00:00:00 2001 From: camilleislasse Date: Sat, 14 Nov 2026 13:02:53 +0100 Subject: [PATCH 22/27] test(shadcn-admin-ui): port the copy components tests of BootstrapAdminUi --- .../packages/copy_components_hooks.yaml | 12 ++ .../CopyToClipboardComponentTest.php | 162 +++++++++++++++++- .../Functional/CopyableComponentTest.php | 129 ++++++++++++++ .../tests/Functional/RendersTwigTrait.php | 14 +- 4 files changed, 305 insertions(+), 12 deletions(-) create mode 100644 src/ShadcnAdminUi/tests/Functional/.application/config/packages/copy_components_hooks.yaml create mode 100644 src/ShadcnAdminUi/tests/Functional/CopyableComponentTest.php diff --git a/src/ShadcnAdminUi/tests/Functional/.application/config/packages/copy_components_hooks.yaml b/src/ShadcnAdminUi/tests/Functional/.application/config/packages/copy_components_hooks.yaml new file mode 100644 index 00000000..346950f2 --- /dev/null +++ b/src/ShadcnAdminUi/tests/Functional/.application/config/packages/copy_components_hooks.yaml @@ -0,0 +1,12 @@ +sylius_twig_hooks: + hooks: + 'app.copy_to_clipboard': + copy: + component: 'sylius_shadcn_admin_ui:copy_to_clipboard' + props: + value: '@=_context.value' + 'app.copyable': + copy: + component: 'sylius_shadcn_admin_ui:copyable' + props: + value: '@=_context.value' diff --git a/src/ShadcnAdminUi/tests/Functional/CopyToClipboardComponentTest.php b/src/ShadcnAdminUi/tests/Functional/CopyToClipboardComponentTest.php index bfe41c8f..c7028bde 100644 --- a/src/ShadcnAdminUi/tests/Functional/CopyToClipboardComponentTest.php +++ b/src/ShadcnAdminUi/tests/Functional/CopyToClipboardComponentTest.php @@ -13,12 +13,49 @@ namespace Tests\Sylius\ShadcnAdminUi\Functional; +use PHPUnit\Framework\Attributes\DataProvider; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; +use Symfony\Component\DomCrawler\Crawler; +use Symfony\Contracts\Translation\TranslatorInterface; final class CopyToClipboardComponentTest extends KernelTestCase { use RendersTwigTrait; + private const CONTROLLER = '[data-controller~="admin--copy-to-clipboard"]'; + + public function testItRendersWithTheDefaultConfiguration(): void + { + $crawler = $this->crawl(''); + + $controller = $crawler->filter(self::CONTROLLER); + self::assertCount(1, $controller); + self::assertSame('customer@example.com', $controller->attr('data-admin--copy-to-clipboard-value-value')); + self::assertSame($this->trans('sylius.ui.copied_to_clipboard'), $controller->attr('data-admin--copy-to-clipboard-copied-label-value')); + self::assertSame($this->trans('sylius.ui.unable_to_copy_to_clipboard'), $controller->attr('data-admin--copy-to-clipboard-error-label-value')); + + $button = $controller->filter('button[data-test-copy-to-clipboard]'); + self::assertCount(1, $button); + self::assertSame('button', $button->attr('type')); + self::assertSame('admin--copy-to-clipboard#copy', $button->attr('data-action')); + self::assertSame($this->trans('sylius.ui.copy_to_clipboard'), $button->attr('aria-label')); + self::assertSame($this->trans('sylius.ui.copy_to_clipboard'), $button->attr('title')); + self::assertSame('button', $button->attr('data-admin--copy-to-clipboard-target')); + self::assertNull($button->attr('data-bs-toggle')); + } + + public function testItSafelyRendersAValueContainingSpecialCharacters(): void + { + $value = 'customer+"' %} + + TWIG); + + self::assertCount(0, $crawler->filter('script')); + self::assertSame('', trim($crawler->filter(self::CONTAINER)->text())); + } + + public function testItRendersThroughTwigHooks(): void + { + $crawler = $this->crawl("{% hook 'app.copyable' with { value: 'ABC-123' } %}"); + + self::assertSame('ABC-123', trim($crawler->filter(self::CONTAINER)->text())); + self::assertCount(1, $crawler->filter('button')); + self::assertCount(0, $crawler->filter('[hookableMetadata]')); + } + + public function testItDisablesCopyingAnAbsentValueButPreservesCustomContent(): void + { + $crawler = $this->crawl(<<<'TWIG' + + Not available + + TWIG); + + self::assertSame('Not available', trim($crawler->filter(self::CONTAINER)->text())); + self::assertCount(1, $crawler->filter('button[disabled]')); + } +} diff --git a/src/ShadcnAdminUi/tests/Functional/RendersTwigTrait.php b/src/ShadcnAdminUi/tests/Functional/RendersTwigTrait.php index 2f85c5c5..94b56eb4 100644 --- a/src/ShadcnAdminUi/tests/Functional/RendersTwigTrait.php +++ b/src/ShadcnAdminUi/tests/Functional/RendersTwigTrait.php @@ -18,16 +18,22 @@ trait RendersTwigTrait { - private function render(string $template): string + /** + * @param array $context + */ + private function render(string $template, array $context = []): string { /** @var Environment $twig */ $twig = self::getContainer()->get('twig'); - return $twig->createTemplate($template)->render(); + return $twig->createTemplate($template)->render($context); } - private function crawl(string $template): Crawler + /** + * @param array $context + */ + private function crawl(string $template, array $context = []): Crawler { - return new Crawler($this->render($template)); + return new Crawler($this->render($template, $context)); } } From 3d21623b7d37c92847a54fac478cac1a9d0898c9 Mon Sep 17 00:00:00 2001 From: camilleislasse Date: Sat, 14 Nov 2026 13:29:47 +0100 Subject: [PATCH 23/27] docs(shadcn-admin-ui): use a neutral example for the branding configuration --- docs/shadcn-admin-ui/configuration.md | 10 +++++----- .../shared/crud/common/sidebar/logo/image.html.twig | 8 -------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/docs/shadcn-admin-ui/configuration.md b/docs/shadcn-admin-ui/configuration.md index e7e683c3..65ea3182 100644 --- a/docs/shadcn-admin-ui/configuration.md +++ b/docs/shadcn-admin-ui/configuration.md @@ -25,15 +25,15 @@ sylius_twig_hooks: 'sylius_admin.common.component.sidebar.logo': image: configuration: - name: 'Camalo' - subtitle: 'WMS' - icon: 'lucide:warehouse' # or image: 'images/logo.svg' + name: 'Acme' + subtitle: 'Back office' + icon: 'lucide:store' # or image: 'images/logo.svg' 'sylius_admin.security.login.page.logo': image: - configuration: { name: 'Camalo', icon: 'lucide:warehouse' } + configuration: { name: 'Acme', icon: 'lucide:store' } 'sylius_admin.base#base_title': default: - configuration: { title: 'Camalo' } + configuration: { title: 'Acme' } ``` {% endcode %} diff --git a/src/ShadcnAdminUi/templates/shared/crud/common/sidebar/logo/image.html.twig b/src/ShadcnAdminUi/templates/shared/crud/common/sidebar/logo/image.html.twig index ba82e930..cf1d9b71 100644 --- a/src/ShadcnAdminUi/templates/shared/crud/common/sidebar/logo/image.html.twig +++ b/src/ShadcnAdminUi/templates/shared/crud/common/sidebar/logo/image.html.twig @@ -1,11 +1,3 @@ -{# - # Configure it from your app: - # sylius_twig_hooks: - # hooks: - # 'sylius_admin.common.component.sidebar.logo': - # image: - # configuration: { name: 'Camalo', subtitle: 'WMS', icon: 'lucide:warehouse' } # or image: 'images/logo.svg' - #} {% set configuration = hookable_metadata.configuration %}
{% if configuration.image|default(null) %} From c8e6ec085a4c3721eed22767c50162e57bed5e4a Mon Sep 17 00:00:00 2001 From: camilleislasse Date: Sat, 14 Nov 2026 13:35:33 +0100 Subject: [PATCH 24/27] fix(shadcn-admin-ui): open the custom trigger dropdown with Enter and Space --- .../templates/shared/helper/dropdown.html.twig | 2 +- .../tests/Functional/DropdownMacroTest.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/ShadcnAdminUi/templates/shared/helper/dropdown.html.twig b/src/ShadcnAdminUi/templates/shared/helper/dropdown.html.twig index a7a762fe..a23fe1f5 100644 --- a/src/ShadcnAdminUi/templates/shared/helper/dropdown.html.twig +++ b/src/ShadcnAdminUi/templates/shared/helper/dropdown.html.twig @@ -15,7 +15,7 @@ {% if params.customTrigger %} -
{{ params.customTrigger }}
+
shadcn--dropdown-menu#toggle keydown.space->shadcn--dropdown-menu#onTriggerKeydown:prevent keyup.space->shadcn--dropdown-menu#toggle'|html_attr_type('sst')}) }}>{{ params.customTrigger }}
{% else %} {% set button = {text: 'Menu', icon: null, class: null}|merge(params.button) %} diff --git a/src/ShadcnAdminUi/tests/Functional/DropdownMacroTest.php b/src/ShadcnAdminUi/tests/Functional/DropdownMacroTest.php index d728869b..4beb5925 100644 --- a/src/ShadcnAdminUi/tests/Functional/DropdownMacroTest.php +++ b/src/ShadcnAdminUi/tests/Functional/DropdownMacroTest.php @@ -98,4 +98,18 @@ public function testItemRendersAButtonWithItsVariant(): void self::assertSame('destructive', $item->attr('data-variant')); self::assertSame('Delete', trim($item->text())); } + + public function testTheCustomTriggerOpensTheMenuWithEnterAndSpace(): void + { + $crawler = $this->crawl(<<<'TWIG' + {% import '@SyliusShadcnAdminUi/shared/helper/dropdown.html.twig' as dropdown %} + {{ dropdown.default({id: 'row', customTrigger: 'More'}) }} + TWIG); + + $actions = explode(' ', (string) $crawler->filter('#dropdown-menu-row-trigger')->attr('data-action')); + self::assertContains('click->shadcn--dropdown-menu#toggle', $actions); + self::assertContains('keydown.enter->shadcn--dropdown-menu#toggle', $actions); + self::assertContains('keydown.space->shadcn--dropdown-menu#onTriggerKeydown:prevent', $actions); + self::assertContains('keyup.space->shadcn--dropdown-menu#toggle', $actions); + } } From 2b5adc1665e0ebbb559b0c8a6e9ad6f83a11356b Mon Sep 17 00:00:00 2001 From: camilleislasse Date: Sat, 14 Nov 2026 14:12:05 +0100 Subject: [PATCH 25/27] chore(shadcn-admin-ui): sync Sidebar/GroupLabel with UX Toolkit 3.7.1 --- .../components/shadcn/Sidebar/GroupLabel.html.twig | 11 ++++++++--- .../shared/crud/common/sidebar/menu/menu.html.twig | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/ShadcnAdminUi/templates/components/shadcn/Sidebar/GroupLabel.html.twig b/src/ShadcnAdminUi/templates/components/shadcn/Sidebar/GroupLabel.html.twig index 94781bfd..f6c1c6fd 100644 --- a/src/ShadcnAdminUi/templates/components/shadcn/Sidebar/GroupLabel.html.twig +++ b/src/ShadcnAdminUi/templates/components/shadcn/Sidebar/GroupLabel.html.twig @@ -1,9 +1,14 @@ -
svg]:size-4 [&>svg]:shrink-0'|tailwind_classes, }) }} > {##- The group label text. -#} {%- block content %}{% endblock -%} -
+ diff --git a/src/ShadcnAdminUi/templates/shared/crud/common/sidebar/menu/menu.html.twig b/src/ShadcnAdminUi/templates/shared/crud/common/sidebar/menu/menu.html.twig index 9aff2b3c..30fd309b 100644 --- a/src/ShadcnAdminUi/templates/shared/crud/common/sidebar/menu/menu.html.twig +++ b/src/ShadcnAdminUi/templates/shared/crud/common/sidebar/menu/menu.html.twig @@ -19,7 +19,7 @@ {% if item.getExtra('section', false) %} {% if group_open %}
{% endif %}
-
+
{{ block('label') }}
    From 61bc5ebb7ede5dbc42518fde71309b3c14c19b45 Mon Sep 17 00:00:00 2001 From: camilleislasse Date: Mon, 16 Nov 2026 12:44:33 +0100 Subject: [PATCH 26/27] fix(shadcn-admin-ui): make html_attr_type('sst') mergeable under Symfony UX 2 --- .../Twig/Extension/SpaceSeparatedTokens.php | 68 +++++++++++++++++++ .../Extension/UxTwoCompatibilityExtension.php | 4 +- .../tests/Functional/HtmlAttrTokensTest.php | 39 +++++++++++ .../Extension/SpaceSeparatedTokensTest.php | 55 +++++++++++++++ 4 files changed, 164 insertions(+), 2 deletions(-) create mode 100644 src/ShadcnAdminUi/src/Twig/Extension/SpaceSeparatedTokens.php create mode 100644 src/ShadcnAdminUi/tests/Functional/HtmlAttrTokensTest.php create mode 100644 src/ShadcnAdminUi/tests/Unit/Twig/Extension/SpaceSeparatedTokensTest.php diff --git a/src/ShadcnAdminUi/src/Twig/Extension/SpaceSeparatedTokens.php b/src/ShadcnAdminUi/src/Twig/Extension/SpaceSeparatedTokens.php new file mode 100644 index 00000000..4d312f83 --- /dev/null +++ b/src/ShadcnAdminUi/src/Twig/Extension/SpaceSeparatedTokens.php @@ -0,0 +1,68 @@ + */ + private readonly array $tokens; + + /** + * @param iterable|string $value + */ + public function __construct(iterable|string $value) + { + $this->tokens = self::tokens($value); + } + + public function mergeInto(mixed $previous): mixed + { + return new self([...self::tokens($previous), ...$this->tokens]); + } + + public function appendFrom(mixed $newValue): mixed + { + return new self([...$this->tokens, ...self::tokens($newValue)]); + } + + public function getValue(): ?string + { + return [] === $this->tokens ? null : implode(' ', $this->tokens); + } + + public function __toString(): string + { + return $this->getValue() ?? ''; + } + + /** + * @return list + */ + private static function tokens(mixed $value): array + { + if ($value instanceof self) { + return $value->tokens; + } + + $tokens = is_iterable($value) ? [...$value] : [$value]; + + return array_values(array_map('strval', array_filter($tokens, static fn (mixed $token): bool => null !== $token && false !== $token))); + } +} diff --git a/src/ShadcnAdminUi/src/Twig/Extension/UxTwoCompatibilityExtension.php b/src/ShadcnAdminUi/src/Twig/Extension/UxTwoCompatibilityExtension.php index 5dd86be9..9630c5e0 100644 --- a/src/ShadcnAdminUi/src/Twig/Extension/UxTwoCompatibilityExtension.php +++ b/src/ShadcnAdminUi/src/Twig/Extension/UxTwoCompatibilityExtension.php @@ -108,7 +108,7 @@ public function classes(string|iterable|null $classes = null): mixed /** * ComponentAttributes::defaults() casts values to strings to concatenate them under Symfony UX 2, - * which SeparatedTokenList does not support: space-separated lists stay plain strings. + * which SeparatedTokenList does not support: space-separated lists use a stringable equivalent. */ public function attributeType(mixed $value, string $type = 'sst'): mixed { @@ -116,7 +116,7 @@ public function attributeType(mixed $value, string $type = 'sst'): mixed return HtmlExtension::htmlAttrType($value, $type); } - return is_iterable($value) ? implode(' ', [...$value]) : $value; + return new SpaceSeparatedTokens(is_iterable($value) ? $value : [$value]); } /** diff --git a/src/ShadcnAdminUi/tests/Functional/HtmlAttrTokensTest.php b/src/ShadcnAdminUi/tests/Functional/HtmlAttrTokensTest.php new file mode 100644 index 00000000..58e2bc0c --- /dev/null +++ b/src/ShadcnAdminUi/tests/Functional/HtmlAttrTokensTest.php @@ -0,0 +1,39 @@ +render(<<<'TWIG' + {{ html_attr({'data-action': 'click->a#b'|html_attr_type('sst')}, {'data-action': 'keydown->c#d'|html_attr_type('sst')}) }} + TWIG); + + self::assertSame('data-action="click->a#b keydown->c#d"', trim($html)); + } + + public function testHtmlAttrOmitsAnAttributeWhoseListIsFalse(): void + { + $html = $this->render(<<<'TWIG' + {{ html_attr({'data-action': false|html_attr_type('sst'), 'data-x': 'y'}) }} + TWIG); + + self::assertSame('data-x="y"', trim($html)); + } +} diff --git a/src/ShadcnAdminUi/tests/Unit/Twig/Extension/SpaceSeparatedTokensTest.php b/src/ShadcnAdminUi/tests/Unit/Twig/Extension/SpaceSeparatedTokensTest.php new file mode 100644 index 00000000..c4c45caa --- /dev/null +++ b/src/ShadcnAdminUi/tests/Unit/Twig/Extension/SpaceSeparatedTokensTest.php @@ -0,0 +1,55 @@ +getValue()); + self::assertSame('a#b c#d', (string) $tokens); + } + + public function testItMergesIntoAPreviousList(): void + { + $merged = (new SpaceSeparatedTokens('b'))->mergeInto(new SpaceSeparatedTokens('a')); + + self::assertSame('a b', $merged->getValue()); + } + + public function testItAppendsFromANewList(): void + { + $appended = (new SpaceSeparatedTokens('a'))->appendFrom(['b', 'c']); + + self::assertSame('a b c', $appended->getValue()); + } + + public function testItIgnoresNullAndFalseTokens(): void + { + self::assertSame('a b', (new SpaceSeparatedTokens(['a', null, false, 'b']))->getValue()); + } + + public function testAnEmptyListHasNoValue(): void + { + $tokens = new SpaceSeparatedTokens([null]); + + self::assertNull($tokens->getValue()); + self::assertSame('', (string) $tokens); + } +} From db13b594bb78cb0d9ac713b8e4472013870738be Mon Sep 17 00:00:00 2001 From: camilleislasse Date: Mon, 16 Nov 2026 12:44:33 +0100 Subject: [PATCH 27/27] fix(shadcn-admin-ui): do not render an empty href on dropdown buttons --- src/ShadcnAdminUi/templates/shared/helper/dropdown.html.twig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ShadcnAdminUi/templates/shared/helper/dropdown.html.twig b/src/ShadcnAdminUi/templates/shared/helper/dropdown.html.twig index a23fe1f5..e758d4c8 100644 --- a/src/ShadcnAdminUi/templates/shared/helper/dropdown.html.twig +++ b/src/ShadcnAdminUi/templates/shared/helper/dropdown.html.twig @@ -33,8 +33,8 @@ {# content is printed raw: escape user data before passing it. #} {% macro item(attributes = {}, content = '', variant = 'default') %} - {% set href = attributes.href|default(null) %} - {{ content|raw }} + {% set attributes = attributes|filter((value, key) => 'href' != key or value) %} + {{ content|raw }} {% endmacro %} {% macro list(params, items) %}