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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@hyperlaunch/use-virtual-cursor

v0.1.0

Published

The `useVirtualCursor` hook creates a virtual cursor that can be moved freely within the viewport via arrow key presses, and trigger click events on elements like buttons and links via the enter key. It's designed for environments such as touch screen kio

Downloads

13

Readme

@hyperlaunch/use-virtual-cursor

The useVirtualCursor hook creates a virtual cursor that can be moved freely within the viewport via arrow key presses, and trigger click events on elements like buttons and links via the enter key. It's designed for environments such as touch screen kiosks, allowing D-pad navigation to enhance accessibility without requiring additional UI modifications.

Installation

Install the package via npm or yarn:

npm install @hyperlaunch/use-virtual-cursor
# or
pnpm add @hyperlaunch/use-virtual-cursor
# or
bun add @hyperlaunch/use-virtual-cursor

Usage

To use the useVirtualCursor hook, add it to your React component by attaching the cursorRef to the element you want to control, and using position to update the elements position. Configure the movement speed through the moveMultiplier, which scales the cursor's movement relative to its width for each key press.

Arguments

  • moveMultiplier (number): Adjusts the scale of movement of the cursor. The movement distance per arrow key press is calculated as a fraction of the cursor's width, allowing for adjustable responsiveness.

Returns

  • cursorRef (React.RefObject<HTMLDivElement>): A ref to be attached to the cursor element, allowing the hook to manage its position based on keyboard interactions.
  • position ({ x: number, y: number }): The current x and y coordinates of the cursor, useful for positioning the cursor element in an absolute layout.
  • canInteract (boolean): Indicates whether the cursor is currently over an interactive element like links or buttons, enabling dynamic styling changes.
  • suggestedStyles (React.CSSProperties): Position related styles to control the onscreen position of the cursor element (ie. top, left, z-index). These are suggested, so can be overridden if required.

The cursor will be positioned in the center of the screen, initially.

Example

Here’s an example of how to use useVirtualCursor in a component with Tailwind CSS for styles:

import useVirtualCursor from "@hyperlaunch/use-virtual-cursor";

function Cursor() {
	const { cursorRef, canInteract, suggestedStyles } = useVirtualCursor({
		moveMultiplier: 0.8,
	});

	const classNames = `
    pointer-events-none fixed h-8 w-8 rounded-full transition-transform duration-200
    ${
			canInteract
				? "bg-gray-500 border-2 border-white ring-1 ring-gray-400 shadow-lg origin-center scale-75"
				: "bg-gray-900/40"
		}
  `;

	return <div style={suggestedStyles} ref={cursorRef} className={classNames} />;
}

This component sets up a custom cursor that responds to keyboard inputs. It applies contextual class names if the cursor is over interactive elements, demonstrating how useVirtualCursor can be applied to enhance accessibility and interactivity in your React applications.