Simple dock component for Pret
Project description
React-Simple-Dock
A set of React components to create a dockable interface, allowing to arrange and resize tabs.
Installation of the javascript package
npm install react-simple-dock
Installation of the PRET python package
pip install pret-simple-dock
Demo
Usage
import React from "react";
import ReactDOM from "react-dom";
import { Layout, Panel } from "react-simple-dock";
import { DndProvider } from "react-dnd";
import { HTML5Backend } from "react-dnd-html5-backend";
const DEFAULT_CONFIG = {
kind: "row",
size: 100,
children: [
{
kind: "column",
size: 50,
children: [
{ kind: "leaf", tabs: ["Panel 1"], tabIndex: 0, size: 50 },
{ kind: "leaf", tabs: ["Panel 2"], tabIndex: 0, size: 50 },
],
},
{ kind: "leaf", tabs: ["Panel 3"], tabIndex: 0, size: 50 },
],
};
const App = () => (
<div style={{ background: "#bdbdbd", width: "100vw", height: "100vh" }}>
<Layout
/* optional initial layout config */
defaultConfig={DEFAULT_CONFIG}
>
<Panel key="Panel 1">
<p>Content 1</p>
</Panel>
<Panel key="Panel 2" header={<i>Italic title</i>}>
<p>Content 2</p>
</Panel>
<Panel key="Panel 3">
<p>Content 3</p>
</Panel>
</Layout>
</div>
);
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(<App />);
Dynamic tab placement
When children are added/removed dynamically, Layout now preserves user-arranged layout and applies place only
when a panel appears for the first time in the current layout.
<Layout
defaultConfig={{
kind: "row",
children: [
{ kind: "leaf", tabs: ["Panel 1", "@anchor-1"] },
{ kind: "leaf", tabs: ["Panel 2"] },
],
}}
>
<Panel key="Panel 1">...</Panel>
<Panel key="Panel 2">...</Panel>
{/* Insert into the same tab list */}
<Panel key="Panel 3" place={{ where: "after-tab", of: "Panel 1" }}>
...
</Panel>
{/* Insert as a sibling leaf around the target leaf */}
<Panel key="Panel 4" place={{ where: "right", of: "@anchor-1" }}>
...
</Panel>
</Layout>
wheresupports:before-tab,after-tab,first-tab,last-tab,left,right,top,bottom.ofreferences panel keys (or anchor tabs indefaultConfig, such as@anchor-1).- If
ofis missing, placement falls back to the first tab currently present in the layout. - Tabs prefixed with
@are treated as virtual anchors: preserved for placement, but never rendered as visible tabs or leaves.
Development
Installation
Clone the repository:
git clone https://github.com/percevalw/react-simple-dock.git
cd react-simple-dock
Install the dependencies:
yarn install
Make your changes and run the demo:
yarn start
Build the javascript library
To build the javascript library:
yarn build:lib
Build the PRET python package
Ensure pret is installed.
pip install pret
If you have changed the signature of the components, you will need to update the python stubs.
pret stub . SimpleDock pret_simple_dock/__init__.py
To build the python library and make it available in your environment:
pip install .
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pret_simple_dock-0.2.6-py3-none-any.whl.
File metadata
- Download URL: pret_simple_dock-0.2.6-py3-none-any.whl
- Upload date:
- Size: 80.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17d25f7c6719c2a696a03a0b92df186c6b326148d3e3e6528f401485ae84c47e
|
|
| MD5 |
5346715ebae916ef652ade37ed9dda83
|
|
| BLAKE2b-256 |
fddddfb89e487a88089e4ef59ec2638a589049761aa95261e80d951b5267f2ac
|