npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@caspeco/navigation-core

v3.10.0

Published

[![NPM Version](https://img.shields.io/npm/v/%40caspeco%2Fnavigation-core?logo=npm&label=%40caspeco%2Fnavigation-core)](https://www.npmjs.com/package/@caspeco/navigation-core)

Readme

@caspeco/navigation-core

NPM Version

This package installs the TypeScript type definitions for the <caspeco-navigation-menu> Web Component as well as some utility functions.

Additional Resources

Installation

Install the package from npm.

npm i @caspeco/navigation-core

Usage

Correctly typed props

To make sure you are passing the correct props, you can use the NavigationMenuProps type:

import type { NavigationMenuProps } from "@caspeco/navigation-core";

export const NavigationMenu = () => {
	const navProps: NavigationMenuProps = {
		currentLocation: window.location.href,
		itemGroup: "Staff",
		// etc ...
	};

	return <caspeco-navigation-menu {...navProps}></caspeco-navigation-menu>;
};

Listening to events

The navigation has some Custom Events that you may want to listen to. Navigation events are always dispatched on the body element, and will bubble.

import type { MobileMenuClosedEventName } from "@caspeco/navigation-core";

useEffect(() => {
	const eventName: MobileMenuClosedEventName = "mobile-menu-closed";

	function handleMobileMenuClosed() {
		doSomething();
	}

	window.addEventListener(eventName, handleMobileMenuClosed);

	return () => {
		window.removeEventListener(eventName, handleMobileMenuClosed);
	};
}, []);

Context

The context contains information about the company (or system!) that the user has selected in the context selector.

Reading context

To read the RMS context correctly, you can use the getRmsContext() function:

import { getRmsContext } from "@caspeco/navigation-core";

function getContextId(): string {
	const { companyId, systemName } = getRmsContext();
	return companyId ?? systemName;
}

Setting context

If you need to, you can also setRmsContext(), but the use case for this should be rare. Make sure that you trigger a page navigation (either reload the page or redirect the user) after setting the context.

Preventing context changes

By default, when a user changes their context in the context selector, their selection is saved in browser storage and they are redirected to the overview page. In some cases you may want to send them somewhere else (e.g. Cloud App wants to send people to /cloud/home), in which case you can intercept and cancel the context-selected Custom Event:

import { setRmsContext, type RmsContext, type ContextSelectedEventName } from "@caspeco/navigation-core";

useEffect(() => {
	const eventName: ContextSelectedEventName = "context-selected";

	function handleContextChanged(event: Event) {
		if (!(event instanceof CustomEvent)) {
			return;
		}

		// Cancel default behavior
		event.preventDefault();

		// Set the context
		const newContext = event.detail as RmsContext;
		setRmsContext(newContext);

		// Redirect somewhere other than the Overview page
		window.location.href = "rms.caspeco.se/cloud/home";
	}

	window.addEventListener(eventName, handleContextChanged);

	return () => {
		window.removeEventListener(eventName, handleContextChanged);
	};
}, []);

Installing <caspeco-navigation-menu>

Option 1: Use the NPM package (experimental)

Available in >=3.8.0-alpha.0

Get URL and ID and inject manually

import { getNavigationScriptData } from "@caspeco/navigation-core";

const { src, id } = getNavigationScriptData({ environment: "stage" });
const script = document.createElement("script");
script.id = id;
script.src = src;
script.type = "module";
document.head.appendChild(script);

Get HTMLScriptElement and inject manually

Will skip injection if it already exists in the DOM.

import { getNavigationHTMLScriptElement } from "@caspeco/navigation-core";

const { scriptElement, data } = getNavigationHTMLScriptElement({ environment: "stage" });
document.head.appendChild(scriptElement);

Inject automatically

Will skip injection if it already exists in the DOM.

import { injectHTMLNavigationElement } from "@caspeco/navigation-core";

injectHTMLNavigationElement({ environment: "stage" });

Option 2: Use the CDN url directly (not using npm package)

Add it manually by importing the deployed script from our CDN urls, e.g.:

<script type="module" src="https://webcomponents.caspeco.net/v3/index.js"></script>
  • Development: https://webcomponents.dev.caspeco.net/v{MAJOR_VERSION}/index.js
  • Stage: https://webcomponents.stage.caspeco.net/v{MAJOR_VERSION}/index.js
  • Production: https://webcomponents.caspeco.net/v{MAJOR_VERSION}/index.js

Side effects

Mobile navigation

On small devices (< 768px) the navigation is turned into a mobile navigation bar at the bottom of the screen. When this happens, the mobile-nav class is added to the root html document.

You may need to update your application to respond to this change, for example to change the height of your application from 100% to calc(100% - var(--mobile-navigation-height)). The --mobile-navigation-height is automatically added on your root html document when the navigation is installed.

This is an example of what had to be done on the Overview page:

main {
    height: 100%;
    /* ... */
}

+ .mobile-nav main {
+     height: calc(100% - var(--mobile-navigation-height));
+ }

Favicons

The navigation will overwrite your existing favicons with the correctly branded favicons as soon as it loads.

dev favicon stage favicon prod favicon

document.title

As of 2025-04-08 the navigation does not change your document.title, but soon it will modify it automatically depending on the page's name in the navigation.