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-tour-callout

v1.0.5

Published

A simple library to create UI callouts designed for building custom tour components

Downloads

153

Readme

react-tour-callout

A simple library to create UI callouts designed for building custom tour components

This component provides a simple way to build a callout targeted at any UI element on the page.

It's worth noting up front that this library is not designed to replace the popular (and powerful) react-joyride library. The goal of this library is to provide a more primitive (and less opinionated) way to build a single callout against any UI element.

In my experience, react-joyride is primarily optimized for building a single linear tour on a page. However, in many cases, tour callouts are displayed more progressively over multiple pages and often only when certain features are interacted with. This makes building these "one-off" tour callouts more challenging since you either need to manage the tour cycle manually or even use multiple tour instances. Advanced UI customization can also be a challenge beyond the built-in properties and often requires custom CSS to target built-in styles.

In contrast, this library handles the positioning of the callout but leaves it up to the developer to manage the tour lifecycle and layout/styling within the callout.

Features

  • ✅ Anchor the callout to any element on the page via a ref or CSS selector. The Popper library is used to accomplish this.
  • ✅ Optionally render a "speech bubble" arrow that based on its position relative to the anchored element. The color/positioning of this arrow can be customized as well.
  • ✅ Optionally render a semi-transparent backdrop behind the callout.
  • ✅ Highlight multiple elements above the backdrop (not just the anchor element). Custom styles can also be applied to highlighted elements.
  • ✅ Allow highlighted elements to be interactive or read only to the user.

Installation

npm install --save react-tour-callout

Using the demo

  1. Checkout this repository

  2. Run the below command to start the server on port 3010.

npm run example

Edit react-tour-callout

Docs

Props

| Prop | Type | Default | Definition | |------------------|---------------------------------------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | open | boolean | REQUIRED | Whether to open the callout popover | | height | number | REQUIRED | Height of the popover in px | | width | number | REQUIRED | Width of the popover in px | | showBackdrop | boolean | true | Whether to show the backdrop when the popover is open | | backdropProps | BackdropProps | None | Additional props to pass onto the backdrop component | | placement | PopoverPlacement | center | REQUIRED | See the Popper docs for available options | | zIndex | number | 1500 | The z-index value to apply to the popover | | popoverMargin | number | None | Add a margin to the popover container (y-axis for right/left placement, x-axis for top/bottom placement) | | popoverAnchor | HTMLElement | string | null | null | The element to anchor the popover to. Can specify either the element ref or a selector that resolves to the element. If null is provided, the popover is centered on the page. | | anchorOffset | [number, number] | None | Adjust the position of the popover relative to the anchor in the format [skidding, distance]. See the Popper docs for more information. | | raiseAnchor | boolean | true | Whether to increase the z-index of the target element to "raise" it above the backdrop | | enterTransition | boolean | true | Whether to enable a "zoom in" animation when opening the popover | | showArrow | boolean | true | Whether to show a speech bubble like arrow pointing at the anchor element | | arrowOffset | number | None | Offset in px to adjust arrow position by on its primary axis | | arrowColor | string | #000 | Color of the arrow icon using CSS color syntax | | highlightTargets | (HTMLElement | string)[] | None | Array of elements (selector or ref) to raise above the backdrop. This can be used to "highlight" multiple elements on the page for a single tour step. | | highlightStyles | CSSProperties | None | Additional CSS styles to apply to highlighted elements | | children | React.ReactNode | REQUIRED | The body of the callout popover |

Example

This is just a simple contrived example showing anchoring the popover to a button.

export const App = () => {
    const [open, setOpen] = React.useState(false);

    return (
        <div>
            <button
                className="open-button"
                onClick={() => setOpen(true)}
            >
                Open popover
            </button>
            <CalloutPopover
                placement="bottom"
                open={open}
                height={180}
                width={350}
                showBackdrop={true}
                backdropProps={{
                    onClick: () => setOpen(false),
                    onEsc: () => setOpen(false),
                }}
                popoverAnchor=".open-button"
            >
                <h1>Popover content here...</h1>
                <button
                    onClick={() => setOpen(false)}
                >
                    Close popover
                </button>
            </CalloutPopover>
        </div>
    )
};

Note

Feel free to submit issues/PR's and I will do my best to respond. I'm sure there are plenty of improvements that can be made :-)

License

This project is licensed under the terms of the MIT license.