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

react-directional

v0.0.13

Published

Simple directional joystick for react

Downloads

29

Readme

react-directional

This is a simple directional controller, using an SVG, for react.

You can see a demo here.

Really, this component can be thought of "use an SVG to manage a bunch of buttons", and the fact that it's a little nintendo-style directional-controller is just because that is what I first wanted to use it for.

usage

npm i react-directional

Now, you can use it in your code:

import React from 'react'
import Directional from 'react-directional'

export default () => {
  const onDirection = (direction, pressed) => {
    console.log(direction, pressed)
  }
  return <Directional onDirection={onDirection} />
}

There are a few ways to customize the output.

If you make an inline SVG with the correct classes on some buttons, it will work:

import React from 'react'
import Directional from 'react-directional'

export default () => {
  const onDirection = (direction, pressed) => {
    console.log(direction, pressed)
  }
  return(
    <Directional onDirection={onDirection} classes={{ up: 'up', down: 'down', left: 'left', right: 'right' }}>
      <svg version='1.1' viewBox='0 0 26.458 26.458' xmlns='http://www.w3.org/2000/svg'>
        <g transform='translate(0 -270.54)' strokeWidth='5.2'>
          <path className='up' d='m15.725 277.71-2.3934-1.163-2.3149 1.3123 0.3665-2.6356-1.9634-1.7961 2.6199-0.46589 1.1015-2.4223 1.2527 2.3477 2.6441 0.29901-1.8457 1.9168z' />
          <path className='down' d='m25.145 287.28-2.3934-1.163-2.3149 1.3123 0.3665-2.6356-1.9634-1.7961 2.6199-0.46589 1.1015-2.4223 1.2527 2.3477 2.6441 0.29902-1.8457 1.9168z' />
          <path className='left' d='m15.725 296.85-2.3934-1.163-2.3149 1.3123 0.3665-2.6356-1.9634-1.7961 2.6199-0.46588 1.1015-2.4223 1.2527 2.3477 2.6441 0.29901-1.8457 1.9168z' />
          <path className='right' d='m6.3051 287.28-2.3934-1.163-2.3149 1.3123 0.3665-2.6356-1.9634-1.7961 2.6199-0.46589 1.1015-2.4223 1.2527 2.3477 2.6441 0.29902-1.8457 1.9168z' />
        </g>
      </svg>
    </Directional>
  )
}

In this case, the buttons are elements that have the classes in the classes prop.

You can also use standard SVG css-styling, as I did in the demo

I highly recommend using svgr to reactize the SVG, as it makes it much easier to manage & edit the look, but be aware that it adds prefixes to classes, which is my default classes are like this:

{
  up: 'look_svg__up',
  down: 'look_svg__down',
  left: 'look_svg__left',
  right: 'look_svg__right'
}