Socket
Socket
Sign inDemoInstall

react-better-splitviews

Package Overview
Dependencies
8
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-better-splitviews

A great react component with a simple API that mimics the way SplitViews operate in visual studio code.


Version published
Weekly downloads
3
decreased by-40%
Maintainers
1
Install size
1.60 MB
Created
Weekly downloads
 

Readme

Source

Handle Split Views like it's 2022

Live demo

Nowadays, split views are everywhere, and yet it looked like there wasn't a great one, with an easy-to-use API, for React -- so we made one. We've fetched great inspiration from the Visual Studio Code split views. They're discrete, and they feel great.

🐥 Tiny ~4.7kb

🐼 Written in TypeScript

🦁 Use standard CSS properties to customize the SplitView and it's views

🦄 A simple, easy-to-use API, and a beautiful SplitView! No redundancy! All hail the unicorns!

TypeScript-lovers notice: All type declarations are included in the package. No need to install @types.

Installation

npm i react-better-splitviews
// OR
yarn add react-better-splitviews

and

import { SplitView } from "react-better-splitviews";

Examples

There are 2 orientations you can use for your SplitView: rows or columns.

1. Rows (default)

import { SplitView } from "react-better-splitviews";

const CustomComponent = () => {
  return (
    <SplitView style={{ height: "500px" }}>
      <div>First View</div>
      <div>Second View</div>
      <div>Third View</div>
    </SplitView>
  );
};
With constraints
import { SplitView } from "react-better-splitviews";

const CustomComponent = () => {
  return (
    <SplitView style={{ height: "500px" }}>
      {/* Width will start at 10 pixels */}
      <div style={{ width: "10px" }}>First View</div>

      {/*
        Width will start at 50% of the SplitView's 
        It can't be shrunk under 110 pixels
      */}
      <div style={{ width: "50%", minWidth: 110 }}>Second View</div>

      {/* 
        Width will take all remaining space 
        It can't be shrunk under 100 pixels
        It can't be stretched above 300 pixels
      */}
      <div style={{ minWidth: 100, maxWidth: 300 }}>Third View</div>
    </SplitView>
  );
};

2. Columns

import { SplitView } from "react-better-splitviews";

const CustomComponent = () => {
  return (
    <SplitView style={{ height: "500px" }} direction="column">
      <div>First View</div>
      <div>Second View</div>
      <div>Third View</div>
    </SplitView>
  );
};
With constraints
import { SplitView } from "react-better-splitviews";

const CustomComponent = () => {
  return (
    <SplitView style={{ height: "500px" }} direction="column">
      {/* Height will start at 10 pixels */}
      <div style={{ height: "10px" }}>First View</div>

      {/*
        Height will start at 50% of the SplitView's 
        It can't be shrunk under 110 pixels
      */}
      <div style={{ height: "50%", minHeight: 110 }}>Second View</div>

      {/* 
        Height will take all remaining space 
        It can't be shrunk under 100 pixels
        It can't be stretched above 300 pixels
      */}
      <div style={{ minHeight: 100, maxHeight: 300 }}>Third View</div>
    </SplitView>
  );
};

3. Combine them

Support for various combinations of Splitviews is supported. For example, this looks a bit like the Visual Studio Code layout.

import { SplitView } from "react-better-splitviews";

const CustomComponent = () => {
  return (
    <SplitView id="container">
      <SplitView id="side-bar" style={{ width: "25%" }} direction="column">
        <Workspace style={{ minHeight: 24 }} />
        <Outline style={{ minHeight: 24 }} />
        <TimeLine style={{ minHeight: 24 }} />
      </SplitView>
      <SplitView
        id="editors_panel"
        style={{ minWidth: 100 }}
        direction="column"
      >
        <SplitView id="editors" style={{ minWidth: 100 }} direction="row">
          <Editor style={{ width: 250 }} />
          <Editor style={{ minWidth: 100 }} />
          <Editor style={{ minWidth: 100 }} />
        </SplitView>
        <Panel style={{ height: "25%" }} />
      </SplitView>
    </SplitView>
  );
};

Please let us know if you need more examples.

Contributing

While we are confident this library will work for most use cases, it is still young. We welcome any feedback, recommendations and pull requests to make it even better!

API

SplitViewProperties

PropTypeDescriptionDefault
styleCSSPropertiesObject with CSS Properties to be applied to the SplitView{ height: "100%", width: "100%" }
directionDirectionSpecifies the direction of the splitview. Much like Flexboxes, it can be row or column."row"
handleOptionsHandleOptionsSpecified the looks and feel of the Handle.see HandleOptions
onGrabHandleFunctionGets called when a handle is grabbed by the user.undefined (is not called)
onDragHandleFunctionGets called when a handle is moved by the user.undefined (is not called)
onReleaseHandleFunctionGets called when a handle is released by the user.undefined (is not called)

HandleOptions

PropTypeDescriptionDefault
focusedColorstringWhen the handle is focused (hovered, selected), this is the color it will display. Any CSS colors work here."#0D6EFD"
focusedSizenumberWhen the handle is focused (hovered, selected), this is the size (in pixels) it will have.5
defaultColorstringThis is the default color it will display. Any CSS colors work here."lightgray"
defaultSizenumberThis is the default size (in pixels) it will have.1

License

MIT

Sharing is caring ❤️

Show us some love and STAR ⭐ the project if you find it useful

Send us pictures of what you did the Better SplitViews library; we can't wait to see what the community will do with it! Cheers

Keywords

FAQs

Last updated on 26 Jun 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc