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-layer-handles

v0.0.5

Published

![Example GIF](/sample.gif)

Downloads

10

Readme

react-layer-handles [WIP]

Example GIF

Overview

react-layer-handles is a simple utility that allows you to add handles to your React components. It is meant to provide just the basic functionality of showing handles and to be extended with the userLayerHandles hook to provide more features.

Install

yarn add react-layer-handles

Usage

import { LayerHandlesProvider, useLayerHandles } from "react-layer-handles";
export const App = () => {
  return (
    <LayerHandlesProvider
      // default props show here
      dataAttribute="data-layer-id"
      handleOffsetX={8}
      handleOffsetY={8}
      handleWidth={8}
      handleHeight={8}
      handleBorderRadius={12}
    >
      <div className="App">
        <Text layerId="01234" />
      </div>
    </LayerHandlesProvider>
  );
};
// just to show the component can have layer handles
// attached no matter where it is positioned.
const TEXT_LAYER_STYLE = {
  position: "absolute",
  top: 222,
  left: 222,
  background: "rgba(0,0,0,0.1)"
};

const Text = props => {
  // subscribe to the store.
  const layers = useLayerHandles();
  const isSelected = layers.isSelected(props.layerId);

  // toggle layerHandles on when this component is clicked.
  const onClick = () => {
    if (!isSelected) {
      layers.setSelectedLayerId(props.layerId);
    }
  };

  // react-layer-handles uses the data-layer-id attribute by default.
  // be sure to give this attribute to your elements or it will not work.
  return (
    <p onClick={onClick} data-layer-id={props.layerId} style={TEXT_LAYER_STYLE}>
      Foo bar baz.
    </p>
  );
};

Props

LayerHandlesProvider Props

dataAttribute

Type: string Required: false
Default: 'data-layer-id'

Used to select elements from the DOM to create handles around.

handleOffset

Type: number Required: false
Default: 8

Pushes the handles away from the content they are related to. For example, with the default value of 8, the top left handle will be 8px above and 8px left of the top/left coordinates of the content it is attached to. The bottom right handle will be pushed to the right 8px and down 8px from the bottom right corner of the content it is attached to.

cornerHandleWidth

Type: number Required: false
Default: 8

Controls the width of the topLeft, topRight, bottomRight, and bottomLeft corner handles.

cornerHandleHeight

Type: number Required: false
Default: 8

Controls the height of the topLeft, topRight, bottomRight, and bottomLeft corner handles.

borderHandleThickness

Type: number Required: false
Default: 1

Controls the thickness of the top, right, bottom, and left handles.


Values

useLayerHandles (hook)

The useLayerHandles hook gives you access to the main store that powers react-layer-handles. The following descriptions are what values/methods you can access when using this hook.

selectedLayerId

Type: string

The id of the currently selected layer. If there is no selected layer, undefined.

setSelectedLayerId

Type: function(id: string): undefined

A method to set the currently selected layer id. Returns nothing.

isSelected

Type: function(id: string): boolean

A method to check if a specific id is currently selected. Returns a boolean, true or false.

layerBounds

Type: Object

The currently selected element's getBoundingRectClient values with some additional values as helpers. (top, left, right, bottom, height, width, etc.)

topHandleRef

Type: ref

A React ref for the top handle. Can be used to add event listeners, etc.

rightHandleRef

Type: ref

A React ref for the right handle. Can be used to add event listeners, etc.

bottomHandleRef

Type: ref

A React ref for the bottom handle. Can be used to add event listeners, etc.

leftHandleRef

Type: ref

A React ref for the left handle. Can be used to add event listeners, etc.

topRightHandleRef

Type: ref

A React ref for the top right handle. Can be used to add event listeners, etc.

topLeftHandleRef

Type: ref

A React ref for the top left handle. Can be used to add event listeners, etc.

bottomRightHandleRef

Type: ref

A React ref for the bottom right handle. Can be used to add event listeners, etc.

bottomLeftHandleRef

Type: ref

A React ref for the bottom left handle. Can be used to add event listeners, etc.

Styling

Each handle has a shared className, _reactLayerHandle that can be used to style the handles yourself. In addition to this shared className, the following classNames are given to the corresponding handles and can also be manipulated with global CSS or JS.

_topLeftReactLayerHandle
_topRightReactLayerHandle
_bottomRightReactLayerHandle
_bottomLeftReactLayerHandle
_topReactLayerHandle
_rightReactLayerHandle
_bottomReactLayerHandle
_leftReactLayerHandle