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-hinter

v0.3.5

Published

React hinter component

Downloads

78

Readme

Version Version typescript

If you like the project, please give the project a GitHub 🌟

React component for showing information hints 🥸 🎨 Easy to customize 💨 Lightweight

Installation

npm install react-hinter

Usage

1 . Import the ReactHinter component and default styles for it. It's important to import default styles, hinter won't show without it.

import { ReactHinter } from "react-hinter";
import "react-hinter/dist/css/style.css";

2 . Select the elements that ReactHinter will point to. Specify the required data-attributes as in the example below. Mandatory data-attributes are data-rh-namespace - the namespace in which ReactHinter elements will be defined, data-rh-step - the counting order that ReactHinter will point to, data-text - the text that ReactHinter will draw.

return (
    <>
      <button
        data-rh-namespace="namespace"
        data-rh-step={1}
        data-rh-text="Text for hinter step 1"
      >
        Step 1
      </button>

      <button
        data-rh-namespace="namespace"
        data-rh-step={2}
        data-rh-text="Text for hinter step 2"
      >
        Step 2
      </button>
    </>
);

3 . Define a React Hinter component with required parameters. namespace - the same as data-namespace for elements, active - boolean state, onEnd - ReactHinter end events.

 <ReactHinter
    namespace="namespace"
    active={active}
    onEnd={() => setActive(false)}
/>

Full example

function App() {
    const [active, setActive] = useState(false);

    return (
        <>
            <button
                data-rh-namespace="namespace"
                data-rh-step={1}
                data-rh-text="Text for hinter step 1"
            >
                Step 1
            </button>

            <button
                data-rh-namespace="namespace"
                data-rh-step={2}
                data-rh-text="Text for hinter step 2"
            >
                Step 2
            </button>

            <ReactHinter
                namespace="namespace"
                active={active}
                onEnd={() => setActive(false)}
            />
        </>
    );
}

Customization

if you want to make your own unique content, ReactHinter accepts props content which takes exactly the same parameters for rendering as React Hinter.

import { ReactHinter, ReactHinterContentProps } from "react-hinter";
import "react-hinter/dist/css/style.css";

const MyAwesomeContent:FC<ReactHinterContentProps> = ({ prevStep, nextStep, finish, text }) => {
    return (
        <div>
            {text}
            <button onClick={nextStep}>Next step</button>
            <button onClick={prevStep}>Prev step</button>
            <button onClick={finish}>Finish</button>
        </div>
    )
}

const MainPage = () => {
    const [active, setActive] = useState(false);
    
    return (
        <>
            <button
                data-rh-namespace="scramble"
                data-rh-step={1}
                data-rh-text="Take 2 eggs and beat them!"
                data-rh-preferred-position="top"
            >
                Step 1: Take eggs
            </button>

            <button
                data-rh-namespace="scramble"
                data-rh-step={3}
                data-rh-text="Enjoy your meal :)"
            >
                Step 3: Enjoy
            </button>
            <button
                data-rh-namespace="scramble"
                data-rh-step={2}
                data-rh-text="Take a pen and heat it well!"
                data-rh-preferred-position="top"
            >
                Step 2: Take a pan
            </button>

            <ReactHinter
                namespace="scramble"
                active={active}
                content={MyAwesomeContent}
                onEnd={() => setActive(false)}
            />
        </>
    );
};

ReactHinter props

| Parameter | Type | Required | Default | About | |---------------|------------------------|----------|-----------|---------------------------------------------------------------------------------------------------| | active | boolean | true | false | Active state of ReactHinter | | namespace | string | true | – | Namespace in which ReactHinter will navigate | | onEnd | () => void | true | – | An event that fires when ReactHinter terminates. Here you should set the activity status to false | | content | FC<ReactHinterProps> | false | undefined | Your custom content component | | className | string | false | undefined | Your className |

ReactHinterContent props

| Parameter | Type | About | |-----------------|---------------------------------|---------------------------------------------------------------------------------------| | steps | number | Total number of steps passed in this namespace | | currentStep | number | Current active step | | text | string | data-rh-text that was passed to the element. Will subsequently display in ReactHinter | | elements | HTMLElement[] | All DOM namespace elements | | position | { left?: number; top?: number } | Current ReactHinter position | | nextStep | () => void | Function to go to next step | | prevStep | () => void | Function to go to previous step | | finish | () => void | function that terminates ReactHinter |

Additional HTMLAttributes

| Parameter | Type | Required for work | About | |--------------------------------|-----------------------|-------------------|--------------------------------------------------------------------------| | data-rh-namespace | string | true | Namespace in which ReactHinter will navigate | | data-rh-preferred-position | ReactHinterPlacesType | false | ReactHinter's preferred position relative to the element (top or bottom) | | data-rh-text | string | false | Text that will be displayed in ReactHinter | | data-rh-step | number | true | The order in which ReactHinter will be rendered relative to this element |

License

ISC