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

@geoffcox/react-splitter

v2.1.2

Published

A splitter for React components that leverages CSS grid templates for simple and consistent resizing.

Downloads

11,472

Readme

@geoffcox/react-splitter

A resizable splitter for React that leverages CSS display:grid

Live Demo

Overview

See the ../Readme.md for features, version history, etc.

Installation

npm install --save @geoffcox/react-splitter

Usage

To create vertical or horizontal splits you only need the Split component.

Vertical Split

The default creates a left|right split down the middle, no minimum pane sizes, and renders the default splitter.

<Split>
  <div>This is the left pane.</div>
  <div>This is the right pane.<div>
</Split>

Horizontal Split

Add the horizontal attribute to split top/bottom.

<Split horizontal>
  <div>This is the top pane.</div>
  <div>This is the bottom pane.<div>
</Split>

Set the initial split size

Add the initialPrimarySize property to control where the initial split occurs.

<Split initialPrimarySize='30%'>
  <div>Primary pane</div>
  <div>Secondary pane<div>
</Split>

To support double-clicking to reset back to the initial size, add the resetOnDoubleClick property.

<Split initialPrimarySize='30%' resetOnDoubleClick>
  <div>Primary pane</div>
  <div>Secondary pane<div>
</Split>

Nest Splits

Just nest Split componets to create whatever layout you like. Here is an example of a common layout for a main, detail, and output view.

<Split initialPrimarySize='30%'>
  <div>This is the left pane.</div>
  <Split horizontal initialPrimarySize='60%'>
    <div>This is the right-top pane.</div>
    <div>This is the right-bottom pane.</div>
  </Split>
</Split>

Constrain minimum pane sizes

You can prevent either pane from becoming too small using the minPrimarySize and minSecondarySize properties. For vertical splits, primary is the left pane and secondary is the right pane. For horizontal splits, primary is the top pane and secondary is the bottom pane.

<Split minPrimarySize='250px' minSecondarySize='15%'>
  <div>This pane won't get smaller than 250 pixels.</div>
  <div>This pane won't get any smaller than 15% of the overall size of the split control./<div>
</Split>

Customize the splitter size

You can set the size of the hit area (where the user can click to start draggin the splitter) with the splitterSize property.

<Split splitterSize='10px'>
  <div>Primary pane</div>
  <div>Secondary pane<div>
</Split>

Customize the splitter colors

You can change the colors of the default splitter with the defaultSplitterColors property.

const colors = {
  color: 'red',
  hover: '#00FF00',
  drag: 'blue'
};

<Split defaultSplitterColors={colors}>
  <div>Primary pane</div>
  <div>Secondary pane<div>
</Split>

Custom render the splitter

You can render your own splitter by passing a callback to the renderSplitter property.

const renderSplitter = (props: RenderSplitterProps) => {
  return <div>Your splitter code goes here.</div>
};

<Split renderSplitter={renderSplitter}>
  <div>Primary pane</div>
  <div>Secondary pane<div>
</Split>

The callback receives the RenderSplitterProps to let you know the current size of the splitter, if the split is horizontal, and if the splitter is currently being dragged.

export type RenderSplitterProps = {
  pixelSize: number;
  horizontal: boolean;
  dragging: boolean;
};

Monitor changes

You can use event callbacks to monitor changes to the primary size and the measured sizes. The primary size is a CSS unit string (percentage or initial size). The measured sizes are pixels sizes.

const onSplitChanged = (primarySize: string) => {
  console.log(`The split is: ${primarySize}`);
};

const onMeasuredSizesChanged = (sizes: SplitMeasuredPixelSizes) => {
  console.log(`The primary pane is: ${sizes.primary}px`);
  console.log(`The splitter is: ${sizes.splitter}px`);
  console.log(`The secondary pane is: ${sizes.secondary}px`);
};

<Split onSplitChanged={onSplitChanged} onMeasuredSizesChanged={onMeasuredSizesChanged}>
  <div>Primary pane</div>
  <div>Secondary pane<div>
</Split>

Integrating into a web application

If you are using a style framework like Fluent, Material UI, or Bootstrap then your root div will likely have CSS styles applied that help this splitter work correctly. If you have no root stylesheet, you might have problems with vertical scrolling.

Here are some recommended CSS properties for your top-level divs if you are building a single-page application. In this case #app is the mounting point for React.Render. You can see this approach used in the demo application.

body {
  height: 100vh;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  overflow: hidden;
  padding: 0;
  margin: 0;
}

body,
div {
  box-sizing: border-box;
}

#app {
  position: relative;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  outline: none;
  overflow: hidden;
}