A TypeScript package for implementing smooth navbar animations with GSAP, featuring scroll-based show/hide behavior and customizable animation settings.
- β¨ Smooth GSAP-powered animations
- π Scroll-based navbar show/hide behavior
- βοΈ Configurable animation settings
- π― Attribute-based element selection
- π¦ ES Module-only package (no CommonJS support)
- π§ Modern TypeScript configuration with strict mode
- π§ͺ Testing setup with Vitest
- π¨ Formatting and linting with Biome
- ποΈ Build pipeline with TypeScript compiler
- π Source maps for debugging
- Node.js >= 22.0.0
npm install @refokus-agency/navigation- Add the
r-navbarattribute to your navbar element(s):
<nav r-navbar>
<!-- Your navbar content -->
</nav>- Initialize the navbar animation system:
import { initNavbarAnimation } from '@refokus-agency/navigation';
// Initialize with custom options
const success = initNavbarAnimation({
animationDuration: 0.3,
animationEasing: 'power2.inOut',
});
if (success) {
console.log('Navbar animation initialized');
}- Initial Animation: Navbar slides in smoothly on page load
- Scroll Down: Navbar hides when scrolling down past threshold (50px)
- Scroll Up: Navbar shows when scrolling up
- Multiple Navbars: Supports multiple navbar elements with the same attribute
pnpm build # Build types + ESM + browser bundle
pnpm build:clean # Clean and rebuild
pnpm build:watch # Watch modepnpm test # Run tests
pnpm test:watch # Watch mode
pnpm test:coverage # With coverage
pnpm test:ui # With UIpnpm check-types # Type checking
pnpm lint # Lint with Biome (--write)
pnpm format # Format with Biome (--write)src/
βββ index.ts # Main entry point
βββ nav-anim/
βββ index.ts # Navbar animation initialization
βββ config.ts # Configuration constants
βββ initial-animation.ts # Initial slide-in animation
βββ scroll-behaviour.ts # Scroll-based show/hide logic
βββ __tests__/
βββ index.test.ts # Initialization tests
βββ scroll-behaviour.test.ts # Scroll behavior tests
The package uses the following default configuration:
{
position: {
hidden: '-100%', // Y position when hidden
visible: '0%' // Y position when visible
},
scroll: {
threshold: 50 // Minimum scroll distance to trigger animation
},
selectors: {
navbar: '[r-navbar]' // Attribute selector for navbar elements
}
}This package uses automated semantic versioning and publishing through GitHub Actions. The release process is triggered automatically on pushes to the main branch (or manually via the Release workflow's workflow_dispatch) and publishes to the public npm registry (registry.npmjs.org) under the @refokus-agency scope.
The publishing workflow (.github/workflows/main-release.yml, named Release) calls the refokus-agency/platform reusable workflows (ci.yml then release.yml) and handles:
-
Automatic Triggering: Release checks run on push to the
mainbranch. -
Authentication: Publishing to npm uses OIDC Trusted Publishing β there is no
NPM_TOKENsecret. The caller grantspermissions: id-token: write, which lets npm mint a short-lived credential at publish time. For this to work, a Trusted Publisher must be configured for@refokus-agency/navigationon npmjs.com (Package settings β Trusted Publisher), pointing at this repository (refokus-agency/navigation) with the workflow filenamemain-release.yml. Note: even though the publish step runs inside therefokus-agency/platformreusable workflow (release.yml), npm authorizes the entry-point (caller) workflow β the one that triggers the run and holdsid-token: writeβ so enter exactlymain-release.yml(the file in this repo), notrelease.yml.
β οΈ WARNING: This repository uses automated semantic versioning and publishing. Do not publish manually withnpm publish. All releases are handled by GitHub Actions via semantic-release.To trigger a release, push to the
mainbranch or use the GitHub Actions workflow manually.Ensure your commits follow Conventional Commits to enable correct versioning and changelog generation. In order to do that, you MUST run
pnpm committo use the Commitizen wizard and stay compliant with our versioning standards.
The project uses semantic-release for automated version management based on conventional commits:
- Major version (
x.0.0): Breaking changes (commits withBREAKING CHANGE:or!:) - Minor version (
0.x.0): New features (commits withfeat:) - Patch version (
0.0.x): Bug fixes (commits withfix:)
Follow the Conventional Commits specification:
# Feature
feat: add new functionality
# Bug fix
fix: resolve issue with feature
# Breaking change
feat!: remove deprecated API
# or
feat: add new API
BREAKING CHANGE: old API has been removed
# Documentation
docs: update README
# Style changes
style: format code
# Refactoring
refactor: restructure code
# Performance
perf: improve performance
# Tests
test: add unit testsThe package is published to the public npm registry under the @refokus-agency scope, so consumers can npm install @refokus-agency/navigation with no auth or registry configuration. The release:
- Targets the public npm registry (
https://registry.npmjs.org) viapublishConfig - Publishes as a public scoped package (
access: public) - Authenticates with OIDC Trusted Publishing β no
NPM_TOKENsecret; the workflow requiresid-token: write - Keeps npm provenance disabled because the repository is currently private (provenance requires a public repo). When the repo is made public, pass
provenance: truefrom themain-release.ymlcaller to enable signed provenance
Peer dependency:
gsapis a peer dependency and is not bundled. Consumers must install it themselves (npm install gsap), or provide it globally as Webflow/CDN setups already do.
To trigger a release manually:
- Go to the GitHub repository
- Navigate to the Actions tab
- Select the Release workflow
- Click Run workflow
- Choose the branch (usually
main) - Click Run workflow
Before publishing, ensure:
- All tests pass (
pnpm test) - Code is properly formatted (
pnpm format) - Linting passes (
pnpm lint) - Type checking passes (
pnpm check-types) - Commit messages follow conventional commits format
Semantic-release automatically:
- Generates changelog based on commit messages
- Creates GitHub releases with release notes
- Tags releases in Git
- Updates package version in
package.json
Contributions are welcome! Please read our Contributing Guide and Code of Conduct before opening an issue or pull request.
To report a security vulnerability, please follow our Security Policy β do not open a public issue.
Release notes are published automatically on the GitHub Releases page.
Licensed under the Apache License 2.0. See also NOTICE.