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-drag-and-dock

v0.2.1

Published

Create free-floating panels that "dock" into designated docks. Panel docking does not cause its children to remount.

Downloads

49

Readme

React Drag and Dock

Create free-floating panels that "dock" into designated docks. Panel docking does not cause its children to remount.

Contents

Demos

Dock area

Custom layout

Install

npm i react-drag-and-dock

How It Works

When a Panel docked, the position of the Dock is determined using Element.getBoundingClientRect(). Then the Panel height, width, and position are changed. All positions are relative to document.body.

To the user, the Panel appears to be inside the Dock. In reality, the Panel is actually on top of the Dock.

Examples

Dock area

Dock areas are a simple, opinionated way to create a layout with docks.

import React, { Component } from 'react';
import DragAndDock from 'react-drag-and-dock';

const App = () => {
  render() {
    return (
      <div
        style={{
          background: 'lightblue',
          display: 'flex',
          flexDirection: 'column',
          height: '100vh',
        }}
      >
        <DragAndDock.Area>
          <DragAndDock.Area.Center>
            <div style={{ height: '100%', width: '100%' }}>hello</div>
          </DragAndDock.Area.Center>

          <DragAndDock.Area.Dock location="left" width={300} />
          <DragAndDock.Area.Dock location="right" width={300} />

          <DragAndDock.Area.Panel title="Panel 1" initialDockUid="left">
            <div>I am panel 1</div>
          </DragAndDock.Area.Panel>

          <DragAndDock.Area.Panel title="Panel 2" defaultPosition={{ x: 400, y: 100 }}>
            <div>I am panel 2</div>
          </DragAndDock.Area.Panel>
        </DragAndDock.Area>
      </div>
    );
  }
}

export default Example;

Two docks and one panel

import React from 'react';
import DragAndDock from 'react-drag-and-dock';

const App = () => {
    return (
        <div style={{ display: 'grid', gridTemplateColumns: '3fr 4fr 2fr', height: '80vh' }}>
            <DragAndDock.Provider>
                <DragAndDock.Dock>
                    <div style={{ background: '#D0E4FB', height: '100%' }}>I am a dock</div>
                </DragAndDock.Dock>

                <div />

                <DragAndDock.Dock>
                    <div style={{ background: '#D0E4FB', height: '100%' }}>I am a dock</div>
                </DragAndDock.Dock>

                <DragAndDock.Panel title="Panel">
                    <div>Drag me into a dock.</div>
                </DragAndDock.Panel>
            </DragAndDock.Provider>
        </div>
    );
};

Start docked in dock

Give the Dock an id, and then set initialDockUid on the Panel to the same value.

import React from 'react';
import DragAndDock from 'react-drag-and-dock';

const App = () => {
    return (
        <div>
            <DragAndDock.Provider>
                <DragAndDock.Dock uid="dock-1">
                    <div style={{ background: '#ddd', height: '80vh', width: '50vw' }}>
                        I am a dock
                    </div>
                </DragAndDock.Dock>

                <DragAndDock.Panel initialDockUid="dock-1" title="Panel">
                    <div>yo</div>
                </DragAndDock.Panel>
            </DragAndDock.Provider>
        </div>
    );
};

API

<DragAndDock.Area>

  • Used to create a simple, opinionated dock layout.
  • Demo

<DragAndDock.Area.Center>

  • Required.
  • Center content.
  • Not dockable.

<DragAndDock.Area.Dock>

  • Dockable area.

<DragAndDock.Area.Dock>

  • See <DragAndDock.Panel>.

<DragAndDock.Provider>

  • Docks and Panels must be decendents of the Provider.
  • But they don't need to be direct descendents.

<DragAndDock.Panel>

  • Draggable, free-floating Panel.

<DragAndDock.Dock>

  • Panels "dock" into Docks.

Development

  1. Run npm start to watch the src files and launch the sandbox server at http://localhost:3010.
  2. Change source code in src folder.
  3. Change sandbox code in sandbox/src folder.
    • Don't edit the files in sandbox/src/DragAndDock. The src folder is copied into in on change.