Skip to content

Commit 61178aa

Browse files
feat: migrate theme switcher to Stimulus controller
1 parent fa97197 commit 61178aa

5 files changed

Lines changed: 8 additions & 7 deletions

File tree

src/BootstrapAdminUi/assets/scripts/theme-switcher.js renamed to src/BootstrapAdminUi/assets/controllers/theme-switcher-controller.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
const toggleButton = document.querySelector('[data-theme-toggle]');
1+
import { Controller } from '@hotwired/stimulus';
22

3-
if (toggleButton) {
4-
toggleButton.addEventListener('click', () => {
3+
export default class extends Controller {
4+
toggle() {
55
const current = document.documentElement.getAttribute('data-bs-theme') || 'light';
66
const next = current === 'dark' ? 'light' : 'dark';
77
localStorage.setItem('sylius-theme', next);
88
document.documentElement.setAttribute('data-bs-theme', next);
9-
});
9+
}
1010
}

src/BootstrapAdminUi/assets/entrypoint.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,3 @@ import './scripts/check-all';
1414
import './scripts/menu-search';
1515

1616
import './scripts/bootstrap';
17-
import './scripts/theme-switcher';

src/BootstrapAdminUi/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"symfony/http-kernel": "^6.4 || ^7.4 || ^8.0",
1515
"symfony/http-client": "^6.4 || ^7.4 || ^8.0",
1616
"symfony/security-bundle": "^6.4 || ^7.4 || ^8.0",
17+
"symfony/stimulus-bundle": "^2.17",
1718
"symfony/ux-autocomplete": "^2.17",
1819
"symfony/ux-icons": "^2.20",
1920
"symfony/ux-live-component": "^2.17"

src/BootstrapAdminUi/templates/shared/crud/common/navbar/items/theme_switcher.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<div class="nav-item">
2-
<button class="btn btn-icon btn-ghost-secondary" data-theme-toggle aria-label="Toggle theme">
1+
<div class="nav-item" {{ stimulus_controller('theme-switcher') }}>
2+
<button class="btn btn-icon btn-ghost-secondary" {{ stimulus_action('theme-switcher', 'toggle') }} aria-label="Toggle theme">
33
{{ ux_icon('tabler:sun', {'class': 'icon', 'data-theme-switch': 'light'}) }}
44
{{ ux_icon('tabler:moon', {'class': 'icon', 'data-theme-switch': 'dark'}) }}
55
</button>

src/BootstrapAdminUi/tests/Functional/.application/config/bundles.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@
2626
BabDev\PagerfantaBundle\BabDevPagerfantaBundle::class => ['all' => true],
2727
Sylius\AdminUi\Symfony\SyliusAdminUiBundle::class => ['all' => true],
2828
Symfony\UX\Icons\UXIconsBundle::class => ['all' => true],
29+
Symfony\UX\StimulusBundle\StimulusBundle::class => ['all' => true],
2930
];

0 commit comments

Comments
 (0)