You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The useVirtualCursor hook creates a virtual cursor that can be moved freely within the viewport with arrow key presses, and trigger click events on elements like buttons and links with 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.
3
+
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.
4
4
5
5
## Installation
6
6
7
7
Install the package via npm or yarn:
8
8
9
9
```bash
10
-
npm install @hyperlaunch/react-use-virtual-cursor
10
+
npm install @hyperlaunch/use-virtual-cursor
11
11
# or
12
-
pnpm add @hyperlaunch/react-use-virtual-cursor
12
+
pnpm add @hyperlaunch/use-virtual-cursor
13
13
# or
14
-
bun add @hyperlaunch/react-use-virtual-cursor
14
+
bun add @hyperlaunch/use-virtual-cursor
15
15
```
16
16
17
17
## Usage
@@ -27,35 +27,34 @@ To use the `useVirtualCursor` hook, add it to your React component by attaching
27
27
-**cursorRef** (`React.RefObject<HTMLDivElement>`): A ref to be attached to the cursor element, allowing the hook to manage its position based on keyboard interactions.
28
28
-**position** (`{ x: number, y: number }`): The current x and y coordinates of the cursor, useful for positioning the cursor element in an absolute layout.
29
29
-**canInteract** (`boolean`): Indicates whether the cursor is currently over an interactive element like links or buttons, enabling dynamic styling changes.
30
+
-**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.
30
31
31
32
The cursor will be positioned in the center of the screen, initially.
32
33
33
34
### Example
34
35
35
-
Here’s an example of how to use `useVirtualCursor` in a component:
36
+
Here’s an example of how to use `useVirtualCursor` in a component with [Tailwind CSS](https://tailwindcss.com/) for styles:
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.
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.
4
+
5
+
## Installation
6
+
7
+
Install the package via npm or yarn:
8
+
9
+
```bash
10
+
npm install @hyperlaunch/use-virtual-cursor
11
+
# or
12
+
pnpm add @hyperlaunch/use-virtual-cursor
13
+
# or
14
+
bun add @hyperlaunch/use-virtual-cursor
15
+
```
16
+
17
+
## Usage
18
+
19
+
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.
20
+
21
+
### Arguments
22
+
23
+
-**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.
24
+
25
+
### Returns
26
+
27
+
-**cursorRef** (`React.RefObject<HTMLDivElement>`): A ref to be attached to the cursor element, allowing the hook to manage its position based on keyboard interactions.
28
+
-**position** (`{ x: number, y: number }`): The current x and y coordinates of the cursor, useful for positioning the cursor element in an absolute layout.
29
+
-**canInteract** (`boolean`): Indicates whether the cursor is currently over an interactive element like links or buttons, enabling dynamic styling changes.
30
+
-**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.
31
+
32
+
The cursor will be positioned in the center of the screen, initially.
33
+
34
+
### Example
35
+
36
+
Here’s an example of how to use `useVirtualCursor` in a component with [Tailwind CSS](https://tailwindcss.com/) for styles:
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.
0 commit comments