Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dockview

Package Overview
Dependencies
Maintainers
1
Versions
149
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dockview

Zero dependency layout manager supporting tabs, grids and splitviews with ReactJS support

  • 0.0.0-experimental-fe3d0b23-20220427
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.6K
decreased by-0.04%
Maintainers
1
Weekly downloads
 
Created
Source

dockview

Zero dependency layout manager supporting tabs, grids and splitviews with ReactJS support


npm version CI Build Coverage Quality Gate Status Bundle Phobia

A zero dependency layout manager based on the layering of splitview with support for ReactJS components, written in TypeScript.

Want to inspect the latest deployment? Go to https://unpkg.com/browse/dockview@latest/

Features

  • Simple splitviews, nested splitviews (i.e. gridviews) supporting full layout managment with dockable and tabular views
  • Extensive API support at the component level and view level
  • Themable and customizable
  • Serialization / deserialization support
  • Tabular docking and Drag and Drop support
  • Documentation and examples

Table of contents

This project was inspired by many popular IDE editors. Some parts of the core resizable panelling are inspired by code found in the VSCode codebase, splitview and gridview.

Quick start

Dockview has a peer dependency on react >= 16.8.0 and react-dom >= 16.8.0. You can install dockview from npm.

npm install --save dockview

Within your project you must import or reference the stylesheet at dockview/dist/styles/dockview.css. For example:

@import '~dockview/dist/styles/dockview.css';

You should also attach a dockview theme to an element containing your components. For example:

<body classname="dockview-theme-dark"></body>

Demonstrated below is a high level example of a DockviewReact component. You can follow a similar pattern for GridviewReact, SplitviewReact and PaneviewReact components too, see examples for more.

import {
    DockviewReact,
    DockviewReadyEvent,
    PanelCollection,
    IDockviewPanelProps,
    IDockviewPanelHeaderProps,
} from 'dockview';

const components: PanelCollection<IDockviewPanelProps> = {
    default: (props: IDockviewPanelProps<{ someProps: string }>) => {
        return <div>{props.params.someProps}</div>;
    },
};

const headers: PanelCollection<IDockviewPanelHeaderProps> = {
    customTab: (props: IDockviewPanelHeaderProps) => {
        return (
            <div>
                <span>{props.api.title}</span>
                <span onClick={() => props.api.close()}>{'[x]'}</span>
            </div>
        );
    },
};

const Component = () => {
    const onReady = (event: DockviewReadyEvent) => {
        event.api.addPanel({
            id: 'panel1',
            component: 'default',
            params: {
                someProps: 'Hello',
            },
        });
        event.api.addPanel({
            id: 'panel2',
            component: 'default',
            params: {
                someProps: 'World',
            },
            position: { referencePanel: 'panel1', direction: 'below' },
        });
    };

    return (
        <DockviewReact
            components={components}
            tabComponents={headers}
            onReady={onReady}
        />
    );
};

Specifically for DockviewReact there exists higher-order components to encapsulate both the tab and contents into one logical component for the user making state sharing between the two simple, which is an optional feature.

const components: PanelCollection<IDockviewPanelProps> = {
    default: (props: IDockviewPanelProps<{ someProps: string }>) => {
        return <div>{props.params.someProps}</div>;
    },
    fancy: (props: IDockviewPanelProps) => {
        const close = () => props.api.close();
        return (
            <DockviewComponents.Panel>
                <DockviewComponents.Tab>
                    <div>
                        <span>{props.api.title}</span>
                        <span onClick={close}>{'Close'}</span>
                    </div>
                </DockviewComponents.Tab>
                <DockviewComponents.Content>
                    <div>{'Hello world'}</div>
                </DockviewComponents.Content>
            </DockviewComponents.Panel>
        );
    },
};

Sandbox examples

Serializated layouts

All view components support the methods toJSON(), fromJSON(...) and onDidLayoutChange().

See example here.

Drag and drop

Both DockviewReact and PaneviewReact support drag and drop functionality out of the box.

  • DockviewReact allows tabs to be repositioned using drag and drop.
  • PaneviewReact allows the repositioning of views using drag and drop on the header section.

You can use the utility methods getPaneData and getPanelData to manually extract the data transfer metadata associated with an active drag and drop event for either of the above components.

import {
    getPaneData,
    getPanelData,
    PanelTransfer,
    PaneTransfer,
} from 'dockview';

const panelData: PanelTransfer | undefined = getPanelData();

if (panelData) {
    // DockviewReact: data transfer metadata associated with the active drag and drop event
    const { viewId, groupId, panelId } = panelData; // deconstructed object
}

const paneData: PaneTransfer | undefined = getPaneData();

if (paneData) {
    // PaneviewReact: data transfer metadata associated with the active drag and drop event
    const { viewId, paneId } = paneData; // deconstructed object
}

You can also intercept custom drag and drop events allowing dockview components to interact with and react to external drag events. PaneviewReact supports the method onDidDrop and DockviewReact supports the methods onDidDrop and showDndOverlay.

Theming

The theme can be customized using the below set of CSS properties. You can find the built in themes here which could be used as an example to extend upon or build your own theme.

CSS PropertyDescription
General
--dv-active-sash-colorThe background color a dividing sash during an interaction
--dv-separator-borderThe color of the seperator between panels
Paneview
--dv-paneview-header-border-color-
--dv-paneview-active-outline-colorThe primary accent color, used for example to highlight the active panel in Paneviews
Dockview -> Dragging
--dv-drag-over-background-colorThe overlay color applied to a group when a moving tab is dragged over
Dockview -> Tabs container
--dv-tabs-and-actions-container-font-size-
--dv-tabs-and-actions-container-heightDefault tab height
--dv-tabs-and-actions-container-background-color-
--dv-tabs-container-scrollbar-color-
--dv-group-view-background-color-
Dockview -> Tabs(see dockviewComponent.scss)
--dv-activegroup-visiblepanel-tab-background-colorThe background color of the tab for the visible panel in the active group
--dv-activegroup-hiddenpanel-tab-background-colorThe background color of the tab for the hidden panel/s in the active group
--dv-inactivegroup-visiblepanel-tab-background-colorThe background color of the tab for the visible panel in groups other than the active group
--dv-inactivegroup-hiddenpanel-tab-background-colorThe background color of the tab for the hidden panel/s in groups other than the active group
--dv-activegroup-visiblepanel-tab-colorThe color of the tab for the visible panel in the active group
--dv-activegroup-hiddenpanel-tab-colorThe color of the tab for the hidden panel/s in the active group
--dv-inactivegroup-visiblepanel-tab-colorThe color of the tab for the visible panel in groups other than the active group
--dv-inactivegroup-hiddenpanel-tab-colorThe color of the tab for the hidden panel/s in groups other than the active group
--dv-tab-divider-color-
--dv-tab-close-iconDefault tab close icon

Performance

Consider using React.lazy(...) to defer the importing of your panels until they are required. This has the potential to reduce the initial import cost when your application starts.

FAQ

Q: Can I use this library without React?

A: In theory, yes. The library is written in plain-old JS and the parts written in ReactJS are merely wrappers around the plain-old JS components. Currently everything is published as one package though so maybe that's something to change in the future.

Q: Can I use this library with AngularJS/Vue.js or any other arbitrarily named JavaScript library/framework?

A: Yes but with some extra work. Dockview is written in plain-old JS so you can either interact directly with the plain-old JS components or create a wrapper using your prefered library/framework. The React wrapper may give some ideas on how this wrapper implementation could be done for other libraries/frameworks. Maybe that's something to change in the future.

Keywords

FAQs

Package last updated on 27 Apr 2022

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc