Skip to content

Commit b6e08c2

Browse files
committed
release 1.0.0
1 parent b5d0efd commit b6e08c2

File tree

14 files changed

+698
-720
lines changed

14 files changed

+698
-720
lines changed

README.md

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Vue Use Fixed Header
44

5-
Turn your boring fixed header into a smart one with one line of code.
5+
Turn your boring fixed header into a smart one with three lines of code.
66

77
<br />
88

@@ -12,13 +12,12 @@ Turn your boring fixed header into a smart one with one line of code.
1212

1313
## Features
1414

15-
- **Dead simple** - Call a function and you're done whether you're SSR'ing or not
16-
- **Lightweight** - Just over 1kb without any dependency
17-
- **Enjoyable** - When scrolling down, the header is hidden, when scrolling up, the header is shown.
18-
- **Powerful** - Uses acceleration delta for both hiding and showing instead of fixed thresholds
19-
- **User-centric** - Behaves as your users expect on page load, scroll restoration, hovering, dropdown navigation, top reached and reduced motion.
15+
- **Dead simple** - Write three lines of code and you're done.
16+
- **Enjoyable defaults** - When scrolling down, the header is hidden, when scrolling up, the header is shown.
17+
- **Powerful** - Uses acceleration delta (scroll speed) for both hiding and showing instead of fixed thresholds.
18+
- **Intuitive** - Behaves as expected on page load, scroll restoration, hovering, dropdown navigation, top-reached and reduced motion.
2019
- **Smart** - Functionalities are automatically enabled/disabled if your header turns from fixed/sticky to something else or it is hidden at different viewports
21-
- **Flexible** - Works with any scrolling container and with your own transition styles
20+
- **Flexible** - Works with any scrolling container and with your own styles
2221

2322
<br />
2423

@@ -28,11 +27,21 @@ Turn your boring fixed header into a smart one with one line of code.
2827
pnpm add vue-use-fixed-header
2928
```
3029

30+
Or:
31+
32+
```bash
33+
yarn add vue-use-fixed-header
34+
```
35+
36+
```bash
37+
npm i vue-use-fixed-header
38+
```
39+
3140
<br />
3241

3342
## Usage
3443

35-
Pass your header's template ref to `useFixedHeader`. Then style it as you normally would. That's it.
44+
Pass your header's template ref to `useFixedHeader`. Then apply the returned reactive styles. That's it.
3645

3746
```vue
3847
<script setup>
@@ -41,11 +50,11 @@ import { useFixedHeader } from 'vue-use-fixed-header'
4150
4251
const headerRef = ref(null)
4352
44-
useFixedHeader(headerRef)
53+
const { styles } = useFixedHeader(headerRef)
4554
</script>
4655
4756
<template>
48-
<header class="Header" ref="headerRef">
57+
<header class="Header" ref="headerRef" :style="styles">
4958
<!-- Your content -->
5059
</header>
5160
</template>
@@ -59,35 +68,33 @@ useFixedHeader(headerRef)
5968
</style>
6069
```
6170

62-
As long as your header position is set to fixed/sticky, it will behave as described in the [features](#features) section.
63-
64-
> :warning: There's only **one rule** to respect: Do not apply any _transition-related_ property since they're handled internally. See [below](#customization) how to customize them.
71+
All you have to do is to set `position: fixed` (or `sticky`) to your header. `useFixedHeader` will take care of the rest.
6572

6673
<br />
6774

6875
## Automatic behavior toggling
6976

7077
On resize, `useFixedHeader` checks your header's `position` and `display` properties to determine whether its functionalities should be enabled or not.
7178

72-
_Disabled_ means that the header will behave as you're not using the composable at all: no event listeners are attached and no additional styles are applied.
79+
_Disabled_ means that no event listeners are attached and the returned styles match an empty object `{}`.
7380

7481
### Different viewports
7582

76-
If at different viewports your header position is not fixed/sticky (or it is hidden), functionalities are automatically toggled when needed.
77-
78-
So feel free to have code like this:
83+
Hence feel free to have code like this:
7984

8085
```css
8186
.Header {
8287
position: fixed;
8388
}
8489

90+
/* Will be disabled */
8591
@media (max-width: 768px) {
8692
.Header {
8793
position: relative;
8894
}
8995
}
9096

97+
/* Same */
9198
@media (max-width: 375px) {
9299
.Header {
93100
display: none;
@@ -132,28 +139,41 @@ useFixedHeader(headerRef, {
132139
## Customization
133140

134141
```ts
135-
useFixedHeader(headerRef, {
142+
const { styles, isEnter, isLeave } = useFixedHeader(headerRef, {
136143
/**
144+
*
137145
* Use `null` if content is scrolled by the window,
138146
* otherwise pass a custom scrolling container template ref */
139147
root: null,
140148
/**
149+
*
141150
* ref or computed to watch for automatic behavior toggling */
142151
watch: () => null,
143152
/**
144-
* Minimum acceleration delta required to show the header */
153+
*
154+
* Minimum acceleration delta required to show the header.
155+
* An higher value means that the user has to scroll faster. */
145156
enterDelta: 0.5,
146157
/**
158+
*
147159
* Minimum acceleration delta required to hide the header */
148160
leaveDelta: 0.15,
149161
/**
150-
* Custom enter transition styles */
162+
*
163+
* Whether to toggle `visibility: hidden` on leave.
164+
* Set this to `false` if you want to keep the header
165+
* visible. */
166+
toggleVisibility: true,
167+
/**
168+
*
169+
* Custom styles applied when scrolling up */
151170
enterStyles: {
152171
transition: `transform 0.3s ease-out`,
153172
transform: 'translateY(0px)',
154173
},
155174
/**
156-
* Custom leave transition styles */
175+
*
176+
* Custom styles applied when scrolling down */
157177
leaveStyles: {
158178
transition: `transform 0.5s ease-out`,
159179
transform: 'translateY(-100%)',

demo/Header.vue

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
<script setup lang="ts">
2-
import { ref } from 'vue'
2+
import { ref, watchEffect } from 'vue'
33
import { useFixedHeader } from '../src'
44
55
const headerRef = ref<HTMLElement | null>(null)
66
7-
useFixedHeader(headerRef)
7+
const { styles, isEnter, isLeave } = useFixedHeader(headerRef, {
8+
toggleVisibility: true,
9+
})
10+
11+
watchEffect(() => {
12+
console.table([
13+
{
14+
isEnter: isEnter.value,
15+
isLeave: isLeave.value,
16+
},
17+
])
18+
})
819
</script>
920

1021
<template>
1122
<div>
12-
<header class="Header" ref="headerRef">
23+
<header class="Header" ref="headerRef" :style="styles">
1324
<div class="Nav">
1425
<h2 class="Global_Logo">Vufh</h2>
1526
<ul class="Nav_List">
@@ -167,3 +178,4 @@ useFixedHeader(headerRef)
167178
}
168179
}
169180
</style>
181+
../src/useFixedHeader

demo/WithContainer.vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import Header from './Header.vue'
77
const containerRef = ref<HTMLElement | null>(null)
88
const headerRef = ref<HTMLElement | null>(null)
99
10-
useFixedHeader(headerRef, {
10+
const { styles } = useFixedHeader(headerRef, {
1111
root: containerRef,
1212
})
1313
</script>
1414

1515
<template>
1616
<div class="Scroll_Container" ref="containerRef">
1717
<div class="Container">
18-
<header class="Header_Wrapper" ref="headerRef">
18+
<header class="Header_Wrapper" ref="headerRef" :style="styles">
1919
<div class="Header_Container">
2020
<h2 class="Global_Logo">Vufh</h2>
2121

@@ -80,7 +80,9 @@ useFixedHeader(headerRef, {
8080
line-height: 1;
8181
padding: 0.65rem 1rem;
8282
text-decoration: none;
83-
transition: color 200ms ease-in-out, background-color 200ms ease-in-out;
83+
transition:
84+
color 200ms ease-in-out,
85+
background-color 200ms ease-in-out;
8486
}
8587
8688
@media (hover: hover) {
@@ -103,3 +105,4 @@ useFixedHeader(headerRef, {
103105
text-align: center;
104106
}
105107
</style>
108+
../src/useFixedHeader

package.json

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "vue-use-fixed-header",
3-
"description": "Turn your boring fixed header into a smart one.",
3+
"description": "Turn your boring fixed header into a smart one with three lines of code.",
44
"private": false,
5-
"version": "0.9.8",
5+
"version": "1.0.0",
66
"type": "module",
77
"keywords": [
88
"vue",
@@ -31,7 +31,7 @@
3131
"exports": {
3232
".": {
3333
"import": "./dist/index.js",
34-
"require": "./dist/index.cjs"
34+
"types": "./dist/index.d.ts"
3535
}
3636
},
3737
"main": "dist/index.cjs",
@@ -42,9 +42,9 @@
4242
],
4343
"scripts": {
4444
"dev": "vite",
45-
"build": "rimraf dist && vue-tsc && vite build",
45+
"build": "rm -rf dist && vue-tsc && vite build",
4646
"postbuild": "pnpm pack",
47-
"build:demo": "rimraf dist && vue-tsc && vite build --mode demo",
47+
"build:demo": "rm -rf dist && vue-tsc && vite build --mode demo",
4848
"preview": "vite preview --mode demo",
4949
"test": "pnpm run test:chrome && pnpm run test:firefox && pnpm run test:container:chrome && pnpm run test:container:firefox",
5050
"test:chrome": "cypress run --component --browser chrome",
@@ -58,16 +58,14 @@
5858
},
5959
"devDependencies": {
6060
"@rollup/plugin-terser": "^0.4.3",
61-
"@types/node": "^20.4.5",
61+
"@types/node": "^20.5.0",
6262
"@vitejs/plugin-vue": "^4.2.3",
63-
"@vue/compiler-dom": "^3.3.4",
64-
"cypress": "^12.17.2",
65-
"cypress-real-events": "^1.9.1",
63+
"cypress": "^12.17.4",
64+
"cypress-real-events": "^1.10.0",
6665
"playwright-webkit": "~1.34.3",
67-
"rimraf": "^5.0.1",
6866
"typescript": "^5.1.6",
69-
"vite": "^4.4.7",
70-
"vite-plugin-dts": "^3.3.1",
67+
"vite": "^4.4.9",
68+
"vite-plugin-dts": "^3.5.2",
7169
"vue": "^3.3.4",
7270
"vue-tsc": "^1.8.8"
7371
}

0 commit comments

Comments
 (0)