Skip to content

Commit 4520997

Browse files
committed
release: 1.3.0
1 parent 6435ec3 commit 4520997

6 files changed

Lines changed: 63 additions & 15 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## 1.3.0 - 2025-02-05
8+
### Added
9+
- Added the ability to add a popover to the greeting area. This can be used to add a user account-specific menu or user details.
10+
11+
712
## 1.2.1 - 2025-02-03
813
### Added
914
- Styled the scrollbars that appear on `<admin-bar>` and `<admin-bar-button>` popover elements.

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,12 @@ Now your custom text will appear. If you would also like to add an avatar next t
116116

117117
### Admin Bar Slots
118118

119-
| Slot Name | Description |
120-
|------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
121-
| `default` | The `default` slot is where you would place `<admin-bar-button>` elements, but it can also be used for other elements. All children in the `default` slot will be laid out by CSS Flexbox and the contents will horizontally scroll when it gets too wide. |
122-
| `greeting` | This slot is meant to let the logged-in user verify they are logged in, but any HTML or text can appear in the `greeting` slot. |
123-
| `logout` | When `show-logout` is set, a default logout button will be rendered, using the `logout-href` and `logout-label` attributes. Adding elements into the `logout` slot will repace the default logout button, allowing you to use your own `<admin-bar-button>` in its place. |
119+
| Slot Name | Description |
120+
|--------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
121+
| `default` | The `default` slot is where you would place `<admin-bar-button>` elements, but it can also be used for other elements. All children in the `default` slot will be laid out by CSS Flexbox and the contents will horizontally scroll when it gets too wide. |
122+
| `greeting` | This slot is meant to let the logged-in user verify they are logged in, but any HTML or text can appear in the `greeting` slot. |
123+
| `greeting-popover` | Turns the `greeting` slot into a button and displays this slot content in a popover. |
124+
| `logout` | When `show-logout` is set, a default logout button will be rendered, using the `logout-href` and `logout-label` attributes. Adding elements into the `logout` slot will repace the default logout button, allowing you to use your own `<admin-bar-button>` in its place. |
124125

125126
## Customizing Add Admin Bar Buttons
126127

index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838
</head>
3939
<body>
4040
<admin-bar class="sticky" show-greeting show-environment show-logout avatar-alt="A Cat as an avatar" avatar-src="https://picsum.photos/150/150" greeting-text="Hi, Author">
41+
<nav slot="greeting-popover">
42+
<admin-bar-text multi-line label-content="ADMIN"><div style="margin-inline-end: 1em;"><strong style="display: block">Author Name</strong><em style="display: block">author-username</em></div></admin-bar-text>
43+
<admin-bar-button button-href="/" style="border-block-start: 1px solid color-mix(in srgb, var(--admin-bar-button-color-bg-hover), transparent 80%);">Profile</admin-bar-button>
44+
<admin-bar-button button-href="/">Edit Author</admin-bar-button>
45+
</nav>
4146
<admin-bar-button label-text="Label Text"><span slot="label-before"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="icon"><path fill-rule="evenodd" d="M2.5 3A1.5 1.5 0 001 4.5v4A1.5 1.5 0 002.5 10h6A1.5 1.5 0 0010 8.5v-4A1.5 1.5 0 008.5 3h-6zm11 2A1.5 1.5 0 0012 6.5v7a1.5 1.5 0 001.5 1.5h4a1.5 1.5 0 001.5-1.5v-7A1.5 1.5 0 0017.5 5h-4zm-10 7A1.5 1.5 0 002 13.5v2A1.5 1.5 0 003.5 17h6a1.5 1.5 0 001.5-1.5v-2A1.5 1.5 0 009.5 12h-6z" clip-rule="evenodd" /></svg></span></admin-bar-button>
4247
<admin-bar-button><span slot="label-before"><svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 228.93 228.72"><defs><style>.cls-1{fill:currentColor;}</style></defs><title>edit</title><path class="cls-1" d="M227.35,48.35a14.64,14.64,0,0,0-2.79-17L197.84,4.58a15.47,15.47,0,0,0-17.42-3.17l-5.95,4.74L14.29,166.33,0,228.72l62.39-14.29L222.57,54.26ZM32.59,210.92a30,30,0,0,0-14.84-14.58l5.53-24.15,14.14,6.91,13.06,13.06,6.86,13,0,0Z"/></svg></span>Label Slot</admin-bar-button>
4348
<admin-bar-button button-href="https://craftcms.com" label-text="Badge + Link"><span slot="label-before" style="--admin-bar-text-padding: 0"><admin-bar-text label-content="5"></admin-bar-text></span></admin-bar-button>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"test:open": "cypress open"
99
},
1010
"name": "admin-bar-component",
11-
"version": "1.2.1",
11+
"version": "1.3.0",
1212
"description": "A framework- and CMS-agnostic admin bar web component.",
1313
"type": "module",
1414
"main": "dist/admin-bar.js",

src/components/AdminBar.ts

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { css, html, LitElement, nothing } from 'lit'
22
import { classMap } from 'lit/directives/class-map.js'
3-
import { customElement, property } from 'lit/decorators.js'
3+
import { customElement, property, state } from 'lit/decorators.js'
44

55
import './AdminBarButton.ts'
66
import { glassStyles } from './css.ts'
@@ -75,6 +75,10 @@ export class AdminBar extends LitElement {
7575
padding: 0 clamp(6px, 2vw, 15px);
7676
white-space: nowrap;
7777
78+
&:has(+ [slot='popover']) {
79+
padding: 0;
80+
}
81+
7882
&:has(img) {
7983
display: grid;
8084
@@ -186,6 +190,28 @@ export class AdminBar extends LitElement {
186190
@property({ attribute: 'show-logout', type: Boolean })
187191
showLogout = false
188192

193+
/**
194+
* =========================================================================
195+
* STATE
196+
* =========================================================================
197+
*/
198+
/**
199+
* Tracks whether the `greeting-popover` slot has content.
200+
*/
201+
@state()
202+
private _hasGreetingPopoverSlot = false
203+
204+
/**
205+
* =========================================================================
206+
* SLOTS
207+
* =========================================================================
208+
*/
209+
handleGreetingPopoverSlotchange(e: any) {
210+
const childNodes = e.target.assignedNodes({ flatten: true })
211+
212+
this._hasGreetingPopoverSlot = childNodes.length > 0
213+
}
214+
189215
/**
190216
* ===========================================================================
191217
* LIFECYCLE
@@ -199,15 +225,29 @@ export class AdminBar extends LitElement {
199225
'admin-bar--logout': this.showLogout,
200226
}
201227

202-
const greetingContent = this.showGreeting
203-
? html`
228+
const greetingInnerContent = this.showGreeting
229+
? html`<div class="greeting">
204230
${this.avatarSrc
205231
? html`<img alt="${this.avatarAlt}" src="${this.avatarSrc}" width="25px" height="25px" />`
206232
: nothing}
207233
<span><slot name="greeting">${this.greetingText}</slot></span>
208-
`
234+
</div>`
209235
: nothing
210236

237+
const greetingContent = this._hasGreetingPopoverSlot
238+
? html`
239+
<admin-bar-button>
240+
${greetingInnerContent}
241+
<div slot="popover">
242+
<slot name="greeting-popover" @slotchange="${this.handleGreetingPopoverSlotchange}"></slot>
243+
</div>
244+
</admin-bar-button>
245+
`
246+
: html`${greetingInnerContent}<slot
247+
name="greeting-popover"
248+
@slotchange="${this.handleGreetingPopoverSlotchange}"
249+
></slot>`
250+
211251
const logoutContent = this.showLogout
212252
? html`<slot name="logout"
213253
><admin-bar-button
@@ -223,7 +263,7 @@ export class AdminBar extends LitElement {
223263
<div class="glass-surface"></div>
224264
<div class="glass-edge"></div>
225265
<div class="environment"></div>
226-
<div class="greeting">${greetingContent}</div>
266+
${greetingContent}
227267
<div class="buttons"><slot></slot></div>
228268
<div class="logout">${logoutContent}</div>
229269
</nav>

src/components/AdminBarButton.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export class AdminBarButton extends LitElement {
147147
* =========================================================================
148148
*/
149149
/**
150-
* List of guides being displayed, along with their related information.
150+
* Tracks whether the `popover` slot has content.
151151
*/
152152
@state()
153153
private _hasPopoverSlot = false
@@ -157,9 +157,6 @@ export class AdminBarButton extends LitElement {
157157
* SLOTS
158158
* =========================================================================
159159
*/
160-
// @queryAssignedNodes({ slot: 'popover' })
161-
// _popoverChildren!: Array<Node>
162-
163160
handlePopoverSlotchange(e: any) {
164161
const childNodes = e.target.assignedNodes({ flatten: true })
165162

0 commit comments

Comments
 (0)