1.2.5 ā€¢ Published 2 years ago

react-better-splitviews v1.2.5

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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>
  );
};
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>
  );
};
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

1.2.5

2 years ago

1.2.4

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago