From 96277c5decddf5bf34d17c899d00e3968bbaf2de Mon Sep 17 00:00:00 2001 From: smastrom Date: Sun, 14 Jan 2024 12:13:53 +0100 Subject: [PATCH] x --- .../src/useFixedHeader.ts | 35 +++------- playground/assets/global.css | 6 +- playground/components/Header.vue | 65 +++++++++---------- playground/components/WithContainer.vue | 13 ++-- 4 files changed, 50 insertions(+), 69 deletions(-) diff --git a/packages/vue-use-fixed-header/src/useFixedHeader.ts b/packages/vue-use-fixed-header/src/useFixedHeader.ts index dfaaf12..4207ec0 100644 --- a/packages/vue-use-fixed-header/src/useFixedHeader.ts +++ b/packages/vue-use-fixed-header/src/useFixedHeader.ts @@ -32,10 +32,6 @@ export function useFixedHeader( const { enterStyles, leaveStyles } = TRANSITION_STYLES - const root = () => (options.root || options.root === null ? unref(options.root) : null) - const transitionOpacity = () => - options.transitionOpacity === undefined ? false : unref(options.transitionOpacity) - const isReduced = useReducedMotion() // State @@ -57,17 +53,17 @@ export function useFixedHeader( // Utils function getRoot() { - const _root = root() + const _root = unref(options.root) if (_root != null) return _root return document.documentElement } - function getScrollTop() { - const root = getRoot() - if (!root) return 0 + const getScrollTop = () => getRoot().scrollTop - return root.scrollTop + function getScrollRoot() { + const root = getRoot() + return root === document.documentElement ? document : root } function isFixed() { @@ -104,8 +100,7 @@ export function useFixedHeader( toggleListeners() }) - const root = getRoot() - if (root) internal.resizeObserver.observe(root) + internal.resizeObserver.observe(getRoot()) } function onVisible() { @@ -115,7 +110,7 @@ export function useFixedHeader( setStyles({ ...enterStyles, - ...(transitionOpacity() ? { opacity: 1 } : {}), + ...(unref(options.transitionOpacity) ? { opacity: 1 } : {}), visibility: '' as CSS['visibility'], }) @@ -125,7 +120,7 @@ export function useFixedHeader( function onHidden() { if (state.value === State.LEAVE) return - setStyles({ ...leaveStyles, ...(transitionOpacity() ? { opacity: 0 } : {}) }) + setStyles({ ...leaveStyles, ...(unref(options.transitionOpacity) ? { opacity: 0 } : {}) }) setState(State.LEAVE) @@ -198,22 +193,12 @@ export function useFixedHeader( const onScroll = createScrollHandler() function addScrollListener() { - const root = getRoot() - if (!root) return - - const scrollRoot = root === document.documentElement ? document : root - - scrollRoot.addEventListener('scroll', onScroll, { passive: true }) + getScrollRoot().addEventListener('scroll', onScroll, { passive: true }) internal.isListeningScroll = true } function removeScrollListener() { - const root = getRoot() - if (!root) return - - const scrollRoot = root === document.documentElement ? document : root - - scrollRoot.removeEventListener('scroll', onScroll) + getScrollRoot().removeEventListener('scroll', onScroll) internal.isListeningScroll = false } diff --git a/playground/assets/global.css b/playground/assets/global.css index 8a24938..a62d4f4 100644 --- a/playground/assets/global.css +++ b/playground/assets/global.css @@ -1,7 +1,7 @@ :root { font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; line-height: 1.5; - background-image: var(--Gradient); + background: var(--AccentBrightColor); -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-rendering: optimizeLegibility; @@ -11,7 +11,9 @@ --AccentColor: #00976b; --TextColor: #494949; --WhiteColor: #fff; - --Gradient: linear-gradient(to top, #00ff8d 0%, #00c68c 100%); + --AccentBrightColor: #2fe292; + --AccentLightColor: #d5ece2; + --AccentDarkColor: #076046; } :root { diff --git a/playground/components/Header.vue b/playground/components/Header.vue index 33c6b56..ca9d010 100644 --- a/playground/components/Header.vue +++ b/playground/components/Header.vue @@ -5,6 +5,8 @@ import { useFixedHeader } from 'vue-use-fixed-header' const headerRef = ref(null) const { styles } = useFixedHeader(headerRef) + +const linkProps = { target: '_blank', class: 'Nav_List_Link' }