Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IonButtons with end slot #84

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/useIonicHeaderParallax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export function useIonHeaderParallax({
// ion-buttons
const barButtons = header.querySelector('ion-buttons') as HTMLElement

const endBarButtons = header.querySelector('ion-buttons[slot="end"]') as HTMLElement

// ion-content
const ionContent = parentElement.querySelector('ion-content')
if (!ionContent) throw new Error('Parallax requires an <ion-content> element on the page to work.')
Expand All @@ -79,6 +81,10 @@ export function useIonHeaderParallax({
imageOverlay.appendChild(barButtons)
}

if (endBarButtons) {
imageOverlay.appendChild(endBarButtons)
}

/*** initStyles ***/
// still in init use JS DOM
setTicking(false)
Expand Down Expand Up @@ -112,6 +118,9 @@ export function useIonHeaderParallax({
imageOverlay.style.pointerEvents = 'none'
imageOverlay.style.backgroundSize = 'cover'
imageOverlay.style.backgroundPosition = 'center'
imageOverlay.style.display = 'flex'
imageOverlay.style.justifyContent = 'space-between'
imageOverlay.style.alignItems = 'flex-start'

// .toolbar-background
toolbarBackground.style.backgroundColor = originalToolbarBgColor
Expand All @@ -124,7 +133,13 @@ export function useIonHeaderParallax({
htmlBtn.style.color = titleColor
})
}

if (endBarButtons) {
endBarButtons.style.pointerEvents = 'all'
Array.from(endBarButtons.children).forEach((btn) => {
const htmlBtn = btn as HTMLElement
htmlBtn.style.color = titleColor
})
}
// .scroll-content
if (scrollContent) {
scrollContent.style.paddingTop = `${imageOverlay.clientHeight - toolbar.clientHeight}px`
Expand Down Expand Up @@ -158,6 +173,8 @@ export function useIonHeaderParallax({
if (barButtons && showBarButtons) {
if (targetHeight > headerMinHeight) {
imageOverlay.append(barButtons)
imageOverlay.append(endBarButtons)

Array.from(barButtons.children).forEach((btn) => {
const htmlBtn = btn as HTMLElement
if (htmlBtn) {
Expand All @@ -167,6 +184,8 @@ export function useIonHeaderParallax({
})
} else {
toolbar.append(barButtons)
toolbar.append(endBarButtons)

Array.from(barButtons.children).forEach((btn) => {
const htmlBtn = btn as HTMLElement
if (htmlBtn) {
Expand Down