Repository navigation
Shadcn admin UI - #408
Merged
Merged
Shadcn admin UI#408
Conversation
…r the recipes update command
…lapsible components
…wnMenu components
… trigger to its panel
…ucture with keyboard
Create shadcn admin ui based on bootstrap admin ui. ## Screenshots ### Login  ### Dashboard  ### Grid  ### Form  ## Color themes Interchangeable color themes, enabled in the bundle configuration (plain CSS, no Tailwind rebuild needed): ```yaml sylius_shadcn_admin_ui: themes: [zinc, blue] ``` Base colors: `stone`, `zinc`, `slate`. Accents: `blue`, `green`, `orange`, `rose`, `violet`. ### No theme (neutral)  ### `[zinc, blue]`  ### `[stone, orange]`  ### `[slate, violet]`  ### `[green]`  ### `[rose]` 
Member
Author
|
@rem42 @camilleislasse |
Member
Author
https://ux.symfony.com/toolkit#kits |
Port of the BootstrapAdminUi auto mode (#407): the switcher opens a Light / Dark / Auto menu, Auto follows prefers-color-scheme live and across tabs, and is the default (no stored sylius-theme key).
| Q | A |-----------------|----- | Branch? | shadcn-admin-ui | Bug fix? | no | New feature? | yes | BC breaks? | no | Related tickets | port of #407 | License | MIT The BootstrapAdminUi theme switcher got an auto mode in #407, but the ShadcnAdminUi one still only toggles between light and dark: once clicked, the OS preference is ignored for good. The button now opens a shadcn `DropdownMenu` with three radio items: - **Light** and **Dark** force the theme, as before. - **Auto** follows `prefers-color-scheme`, live when the OS switches and across open tabs. - The button shows the icon of the selected mode (sun, moon or monitor), and the selected item is checked. Same storage as Bootstrap: Auto is the default and removes the `sylius-theme` key, so admins who never picked a theme see no change and those who did keep their choice. The inline script sets `data-theme-mode` on `<html>` before the stylesheet, so there is no flash and the right icon shows before Stimulus connects. The `toggle` action is kept for overridden templates. Labels reuse the `sylius.ui.theme_*` keys added to UiTranslations in #407. `lucide:monitor` was added to the test app's locked icons. | Light | Dark | |-------|------| | <img width="400" alt="Theme switcher with Light selected" src="https://github.com/user-attachments/assets/e82a8b88-a590-40db-b821-fb4083dbf8d9" /> | <img width="400" alt="Theme switcher with Dark selected" src="https://github.com/user-attachments/assets/a4f02952-8d46-41ad-93cc-8369f0506618" /> | | Auto (OS light) | Auto (OS dark) | |-----------------|----------------| | <img width="400" alt="Theme switcher with Auto selected and a light OS" src="https://github.com/user-attachments/assets/2375d95d-7d64-4894-a3e2-5dea9a81d8b8" /> | <img width="400" alt="Theme switcher with Auto selected and a dark OS" src="https://github.com/user-attachments/assets/65db64bb-d558-4459-9a98-5b8c34abbba4" /> |
## Problem
`confirmation_modal` only renders a Cancel button. To confirm anything
that isn't the CSRF form of `delete_modal` (a Live action, a Stimulus
action, a form of the page), the whole `footer` block has to be
overridden: the Cancel button is copied, the confirm button rebuilt with
the right classes, and the dialog has to be closed by hand.
```twig
<twig:sylius_shadcn_admin_ui:confirmation_modal title="Archive this book?">
<twig:block name="trigger">…</twig:block>
<twig:block name="footer">
<button type="button" class="{{ cancel_class }}" data-action="shadcn--alert-dialog#close">{{ 'sylius.ui.cancel'|trans }}</button>
<button type="button" class="{{ confirm_class }}" data-action="shadcn--alert-dialog#close live#action" data-live-action-param="archive">Archive</button>
</twig:block>
</twig:sylius_shadcn_admin_ui:confirmation_modal>
```
`button_class()` isn't visible inside the `<twig:…>` blocks either, so
the classes must be computed before the component.
## Solution
Three optional props. Without `confirm_label`, the footer is unchanged.
| Prop | Default | |
|---|---|---|
| `confirm_label` | `null` | Adds a confirm button next to Cancel |
| `confirm_variant` | `'default'` | Button variant; `destructive` uses
the same solid style as `delete_modal` |
| `confirm_attributes` | `{}` | Attributes of the button. Its
`data-action` runs after `shadcn--alert-dialog#close`, `type` defaults
to `button` |
Live action:
```twig
<twig:sylius_shadcn_admin_ui:confirmation_modal
title="Archive this book?"
confirm_label="Archive"
confirm_variant="destructive"
:confirm_attributes="{'data-action': 'live#action', 'data-live-action-param': 'archive'}"
>
<twig:block name="trigger">
<button type="button" {{ trigger_attributes }}>Archive</button>
</twig:block>
</twig:sylius_shadcn_admin_ui:confirmation_modal>
```
Form of the page:
```twig
<twig:sylius_shadcn_admin_ui:confirmation_modal
confirm_label="Publish"
:confirm_attributes="{type: 'submit', form: 'publish-form'}"
>…</twig:sylius_shadcn_admin_ui:confirmation_modal>
```
The confirm button carries `data-test-confirm-button`, like the one of
`delete_modal`.
## Tests
`ConfirmationModalComponentTest`: default footer, Live action,
destructive variant, form submit. The ShadcnAdminUi suite passes (74
tests) after `importmap:install` and `tailwind:build`, as in the CI.
Implementation suggested from this comment: #403 (review) - "Admin panel" in sidebar.php goes through |trans but isn't a key, so it's never translated. Maybe a sylius.ui.admin_panel key in UiTranslations? -> rem42@7f61b93 - Row "…" menu with the keyboard: focus stays on the trigger, arrows do nothing, and with 2+ actions the second Tab closes the menu. I guess because grid actions aren't DropdownMenu:Item. -> rem42@76686f3 - dropdown.default() only reads text, icon and class from button, the other Bootstrap options (disabled, icon_only, size...) are ignored. Not used anywhere in the repo though. -> rem42@119865c - No JS test for the custom Stimulus controllers. Bootstrap has one for its copy-to-clipboard controller (yarn test in CI), the shadcn copy controller could get the same. -> rem42@bfffaae
Member
Author
|
Thx @rem42 and @camilleislasse for your great work 👏 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The main PR with the work from @rem42 @camilleislasse and myself.
Sub tasks: