Skip to content

silen-z/fiveway

Repository files navigation

fiveway

fiveway is a TypeScript library for rich web applications that need to support keyboard navigation and require precise control over what is focused. It comes with a set of default behaviors and allows for extensive customization.

Features

  • 🧱 Composable — designed with components, local reasoning and composition in mind
  • 🔌 Extensible — fully customize behavior via advanced middleware-like handler system
  • 🌈 Framework agnostic — use it in your favorite framework - React, SolidJS and more to come

Getting started

Install the React version of the library:

npm install @fiveway/react

Create a navigation tree and provide it to the application:

import { createNavigationTree, NavigationProvider, useActionHandler } from "@fiveway/react";

const navtree = createNavigationTree();

function App() {
	// register keyboard listeners (by default on window)
	useActionHandler(navtree);

	return <NavigationProvider tree={navtree}>{/* rest of your app */}</NavigationProvider>;
}

ReactDOM.createRoot(rootElement).render(<App />);

Now your components can become navigation nodes:

import { useNavigationNode, horizontalHandler } from "@fiveway/react";

const items = [
	{ id: "1", label: "One" },
	{ id: "2", label: "Two" },
	{ id: "3", label: "Three" },
];

function List() {
	const nav = useNavigationNode({ id: "list", handler: horizontalHandler });

	return (
		<nav.Context>
			<ul>
				{items.map((item, i) => (
					<Item key={item.id} item={item} order={i} />
				))}
			</ul>
		</nav.Context>
	);
}

function Item(props) {
	const nav = useNavigationNode({ id: props.item.id, order: props.order });

	return <li className={nav.isFocused() && "focused"}>{props.item.label}</li>;
}

Checkout the full guide at: https://fiveway.io/getting-started

Packages

  • @fiveway/core — Core library: navigation tree, nodes, handlers, actions, and DOM utilities
  • @fiveway/react — React integration (NavigationProvider, useNavigationNode, useActionHandler)
  • @fiveway/solid — SolidJS integration (NavigationProvider, useNavigationNode, useActionHandler)
  • @fiveway/inspector — Inspector UI for inspecting and debugging the navigation tree in the browser

About

5-way navigation for React and SolidJS

Resources

Stars

Watchers

Forks

Contributors

Languages