✨ Add UserMenu navigation component#13
Merged
Merged
Conversation
Introduce a ready-to-use user menu component for the navbar, plus minor
tweaks to the Menu component to keep items vertically aligned when their
heights differ.
UserMenu features:
- Circular avatar (3rem / 48px) rendered from a profile picture or
auto-derived colored initials when no image is provided
- Initials derived from the `name` parameter (first + last word, or
two first chars for single-word names), uppercase, multibyte-safe
- Background color picked deterministically from a curated palette via
CRC32 hash of `name`, so avatars stay stable across pages
- Right-aligned dropdown by default, with the user name as header
- Items support a `visible` flag to express conditional entries
(e.g. permission-gated links) without surrounding `{% if %}` blocks
- Auto-detection of active state on items, consistent with MenuItem
Menu adjustment:
- Add `align-items-center` to the rendered `<ul>` so menu items of
different heights (LocaleSwitcher, MenuItem, UserMenu avatar) stay
vertically centered on the same row
405c907 to
9b000fc
Compare
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.
Summary
Adds a new
Enabel:Ux:UserMenuTwig component that encapsulates the common pattern of a navbar user menu (circular avatar + right-aligned dropdown), avoiding the need to drop back into raw HTML inside aMenublock.Why
MenuItemsupports animagefor the dropdown toggle, but does not cover the full user-menu pattern that most Enabel apps need:Until now, projects had to hand-write the
<li class="nav-item dropdown">markup insideMenu'scontentblock, duplicating boilerplate and a11y attributes. This component centralizes that pattern.API
{{ component('Enabel:Ux:UserMenu', { name: app.user.displayName, {# required, drives aria-label, header, default initials/color #} image: app.user.profilePictureDataUri, {# optional, photo takes precedence over initials #} initials: app.user.initials, {# optional override of derived initials #} initialsColor: app.user.avatarColor, {# optional override of derived background #} items: [ {label: 'Profile'|trans, link: path('app_profile'), icon: 'bi:person-circle'}, {label: 'Admin'|trans, link: path('admin_dashboard'), icon: 'bi:gear-fill', visible: is_granted('ROLE_ADMIN')}, {divider: true}, {label: 'Logout'|trans, link: path('app_logout'), icon: 'bi:box-arrow-right'}, ], }) }}Initials derivation
Damien Lagae→DLJohn Ronald Reuel Tolkien→JT(first + last word only)Damien→DA(two first chars for single-word names)éric Dübois→ÉD(multibyte-safe, uppercase)Color derivation
Picked deterministically from a 10-color palette via CRC32 hash of
name, so avatars stay visually stable across pages and sessions without any DB column.visibleflag on itemsItems with
visible: falseare filtered out before rendering, which lets consumers express permission-gated entries inline without wrapping them in{% if %}blocks.Test plan
@Symfony+@Symfony:risky) — no violationsNotes
MenuItem/Menu/Navbar.docs/Navigation/userMenu.mdand linked fromdocs/index.md.<span>uses inline styles (width,height,background) because the color is dynamic per-user; happy to move the static parts to the Enabel Bootstrap Theme stylesheet in a follow-up if preferred.