1.0.5 • Published 2 months ago

react-tour-callout v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

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

PropTypeDefaultDefinition
openbooleanREQUIREDWhether to open the callout popover
heightnumberREQUIREDHeight of the popover in px
widthnumberREQUIREDWidth of the popover in px
showBackdropbooleantrueWhether to show the backdrop when the popover is open
backdropPropsBackdropPropsNoneAdditional props to pass onto the backdrop component
placementPopoverPlacement | centerREQUIREDSee the Popper docs for available options
zIndexnumber1500The z-index value to apply to the popover
popoverMarginnumberNoneAdd a margin to the popover container (y-axis for right/left placement, x-axis for top/bottom placement)
popoverAnchorHTMLElement | string | nullnullThe 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]NoneAdjust the position of the popover relative to the anchor in the format skidding, distance. See the Popper docs for more information.
raiseAnchorbooleantrueWhether to increase the z-index of the target element to "raise" it above the backdrop
enterTransitionbooleantrueWhether to enable a "zoom in" animation when opening the popover
showArrowbooleantrueWhether to show a speech bubble like arrow pointing at the anchor element
arrowOffsetnumberNoneOffset in px to adjust arrow position by on its primary axis
arrowColorstring#000Color of the arrow icon using CSS color syntax
highlightTargets(HTMLElement | string)[]NoneArray 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.
highlightStylesCSSPropertiesNoneAdditional CSS styles to apply to highlighted elements
childrenReact.ReactNodeREQUIREDThe 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.