UserMenu
DomainAvatar + name + role trigger. Dropdown with Profile, Settings, and Sign out items. Closes on outside click.
<%- include('modules/domain/common/user/UserMenu', {
name: user.name,
email: user.email,
role: user.role,
src: user.profilePicture,
profileHref: '/account/profile',
settingsHref: '/account/settings',
signOutHref: '/auth/logout',
signOutMethod: 'post'
}) %>
<%
var _id = locals.id || 'user-menu-' + Math.random().toString(36).substr(2, 9);
var _name = locals.name || (locals.user && locals.user.name) || 'User';
var _email = locals.email || (locals.user && locals.user.email) || '';
var _role = locals.role || (locals.user && locals.user.role) || '';
var _src = locals.src || (locals.user && locals.user.profilePicture) || null;
var _align = locals.align || 'right';
var _onlyAvatar = !!locals.onlyAvatar;
var _profileHref = locals.profileHref || '#';
var _settingsHref = locals.settingsHref || '#';
var _signOutHref = locals.signOutHref || '#';
// Build trigger as Button atom output (rendered via captureInclude).
// We do this via a string by inlining the same Button atom output we'd render.
// Because EJS includes can't be captured to a string easily without a helper,
// we manually compose the trigger using the exact Button atom shape (ghost / sm).
// This matches ``.
// Render Avatar via include into a captured chunk:
// we rely on the DropdownMenu atom accepting raw HTML strings for `trigger` and `header`.
%>
<%
// Capture the Avatar markup into a variable so we can embed it in the trigger string.
var _avatarHtml = '';
%>
<% _avatarHtml %><%
// We need a way to render Avatar to a string. EJS doesn't natively do this;
// emit the Avatar HTML inline by including with a flag to write to a buffer
// is not portable. Instead, use a div placeholder that we hydrate post-render.
%>
<%- include('../../../ui/DropdownMenu', {
id: _id,
align: _align,
trigger:
'',
header:
'' +
'' + _name + '
' +
(_email ? '' + _email + '
' : '') +
'',
items: [
{ type: 'item', label: 'Profile', icon: '', onClick: "window.location.href='" + _profileHref + "'" },
{ type: 'item', label: 'Settings', icon: '', onClick: "window.location.href='" + _settingsHref + "'" },
{ type: 'separator' },
{ type: 'item', label: 'Sign out', icon: '', danger: true, onClick: "window.location.href='" + _signOutHref + "'" }
]
}) %>
<%# Hidden Avatar — we mount it into the trigger slot via the script below. %>
<%- include('../../../ui/Avatar', { name: _name, src: _src, size: 'sm' }) %>