Skip to content

Commit

Permalink
Core - Add transitionOpacity prop
Browse files Browse the repository at this point in the history
  • Loading branch information
smastrom committed Nov 14, 2023
1 parent 5bc0194 commit 0a1fb02
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import type { UseFixedHeaderOptions } from './types'

export const TRANSITION_STYLES = {
enterStyles: {
transition: `transform 0.4s cubic-bezier(0.16, 1, 0.3, 1) 0s`,
transition: `transform 0.4s cubic-bezier(0.16, 1, 0.3, 1) 0s, opacity 0.4s cubic-bezier(0.16, 1, 0.3, 1) 0s`,
transform: 'translateY(0px)',
},
leaveStyles: {
transition: `transform 0.5s cubic-bezier(0.16, 1, 0.3, 1) 0s`,
transition: `transform 0.5s cubic-bezier(0.16, 1, 0.3, 1) 0s, opacity 0.4s cubic-bezier(0.16, 1, 0.3, 1) 0s`,
transform: 'translateY(-101%)',
},
}
Expand Down
9 changes: 7 additions & 2 deletions src/useFixedHeader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,14 @@ export function useFixedHeader(
if (isInstant) {
setStyles({
transform: leaveStyles.transform,
...(config.transitionOpacity ? { opacity: 0 } : {}),
visibility: 'hidden',
})
} else {
setStyles({ transform: enterStyles.transform })
setStyles({
transform: enterStyles.transform,
...(config.transitionOpacity ? { opacity: 1 } : {}),
})
}

internals.isMount = false
Expand Down Expand Up @@ -125,6 +129,7 @@ export function useFixedHeader(

setStyles({
...enterStyles,
...(config.transitionOpacity ? { opacity: 1 } : {}),
visibility: '' as CSS['visibility'],
})

Expand All @@ -134,7 +139,7 @@ export function useFixedHeader(
function onHidden() {
if (state.value === State.LEAVE) return

setStyles(leaveStyles)
setStyles({ ...leaveStyles, ...(config.transitionOpacity ? { opacity: 0 } : {}) })

setState(State.LEAVE)

Expand Down

0 comments on commit 0a1fb02

Please sign in to comment.