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

@highlight-ui/utils-hooks

v3.5.1

Published

A collections of React hooks that are used by UI-components in Personio

Downloads

7,013

Readme

@highlight-ui/utils-hooks

Installation

yarn add @highlight-ui/utils-hooks

Hooks


useAutoPositioner

This component is deprecated

A wrapper for the usePopper from the react-popper library.

Usage

Accepts a Popper.js options object as an argument and returns the styles and attributes values from the usePopper hook. For convenience, the hook also returns setReferenceElement and setPopperElement functions.

import { useAutoPositioner } from '@highlight-ui/utils-hooks';

const MyComponent = () => {
  const { setReferenceElement, setPopperElement, styles, attributes } =
    useAutoPositioner();

  return (
    <div ref={setReferenceElement}>
      <div
        ref={setPopperElement}
        style={{ ...styles.popper }}
        {...attributes.popper}
      ></div>
    </div>
  );
};

useAutoPosition

Calculating position of "floating" elements like tooltips, popovers, dropdowns, menus, and more.

Usage

Accepts a config as an argument and returns the styles, triggerRef and floatRef functions.

type Options = {
  // Position of the element to the trigger element. Default: bottom-start
  placement: Placement;
  // Automatic position based on the space around the trigger. This overrides flip and placement options. Default: Disabled
  auto: AutoConfig | null | false;
  // Flip position if there is not enough space on the placement area: Default: Enabled
  flip: FlipConfig | null | false;
  // Offset from the trigger element: Default: Enabled
  offset: OffsetConfig | null | false;
};
import { useAutoPosition } from '@highlight-ui/utils-hooks';

const MyComponent = () => {
  const { triggerRef, floatRef, styles } = useAutoPosition();

  return (
    <>
      <div ref={triggerRef}>Trigger</div>
      <div ref={floatRef} style={{ ...styles }}>
        Floating tooltip
      </div>
    </>
  );
};

useAutoIntegration

Wrap above useAutoPosition with interaction controls. Based on the config updated open property

Usage

Accepts a config as an argument and returns the styles, open, getTriggerProps, getFloatProps, triggerRef and floatRef functions.

type Options = AutoPositionOptions & {
  // Auto open on hover. Default: Enabled
  hover?: HoverConfig;
  // Auto open on click.  Default: Disabled
  click?: EnableConfig;
  // Auto open on focus.  Default: Enabled
  focus?: EnableConfig;
  // Set role to automatically add a11y params to floater. Default: Disabled
  role?: RoleConfig;
  // Auto close.  Default: Enabled
  dimish?: EnableConfig;
};
import { useAutoInteractions } from '@highlight-ui/utils-hooks';

const MyComponent = () => {
  const { triggerRef, floatRef, styles, open, getTriggerProps, getFloatProps } =
    useAutoInteractions();

  return (
    <>
      <div
        ref={triggerRef}
        // Functions like onClick, onHover, ... are at risk of being overriden
        // to prevent that we add then into the getTriggerProps that will join
        // the props/callbacks if it needs/uses it
        {...getTriggerProps({
          onClick: () => {
            console.log('clicked');
          },
        })}
      >
        Trigger
      </div>
      {open && (
        <div
          ref={floatRef}
          style={{ ...styles }}
          // Functions like onClick, onHover, ... are at risk of being overriden
          // to prevent that we add then into the getTriggerProps that will join
          // the props/callbacks if it needs/uses it
          {...getFloatProps({
            onClick: () => {
              console.log('clicked');
            },
          })}
        >
          Floating tooltip
        </div>
      )}
    </>
  );
};

useForkRef

Allows multiple ref objects/callbacks to be combined so that they can be passed as a single callback ref.

Usage

import React from 'react';
import { useForkRef } from '@highlight-ui/utils-hooks';

const MyComponent = () => {
  const firstRef = React.useRef();
  const secondRef = React.useRef();
  const finalRef = React.useRef([firstRef, secondRef]);

  return <div ref={finalRef}></div>;
};

useClickOutside

Allows attaching a click-outside listener to a target element.

Usage

import { useClickOutside } from '@highlight-ui/utils-hooks';

const MyComponent = () => {
  const onClickOutside = () => {
    console.log('clicked outside');
  };
  const setElement = useClickOutside(onClickOutside);

  return (
    <div>
      <span>Outer Div</span>
      <div ref={setElement}>
        <span>Inner Div</span>
      </div>
    </div>
  );
};

useScrollObserver

Allows attaching a scroll listener to a target element.

Usage

import { useScrollObserver } from '@highlight-ui/utils-hooks';

const MyComponent = () => {
  const onScroll = () => {
    console.log('scrolled');
  };
  const { setElement } = useScrollObserver(onScroll);

  return (
    <div>
      <span>Outer Div</span>
      <div ref={setElement}>
        <span>Inner Div</span>
      </div>
    </div>
  );
};