0.1.14 • Published 8 months ago

@ainias42/react-windows v0.1.14

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

React-Windows

With this library you can add different Windows to your project. These windows can be minimized, maximized or even opened in a browser popup to display them on a different screen.

Also tabs are supported! You can drag a tab anywhere to create a new window or drag it to another window to add it there instead.

How to install

The usual. Just run

npm install @ainias42/react-windows

and you are good to go!

How to use

You only really need two components. The first one is

<Window id = {"unique-window-id"}
title = {"myWindowTitle"} > {...} < /Window>

and the second one is

<WindowList / >

With <Window> you create new window data. The component itself does not render anything but will add the data and children you give it to a store in the background. Then <WindowList> displays the different windows. With this concept you can add windows in different parts of your application, but they will always be on the same z-layer and therefore can better interact with each other.

The settings (which windows are displayed as tabs inside one container ect) is saved locally. From the window itself, only the id and the corresponding container is saved. If a window in future is not present, aka not in the React-DOM, then it will not be loaded or displayed. If it is added at a later point, it will be in the same container as before. This allows conditional window display.

Props

<Window>

Proptyperequireddefaultexplanation
idstringxThe unique id inside the store for the window (can be the same as a containerId. See below)
titlestringxThe Title of the window
defaultContainerIdstringundefinedWhen two windows have the same containerId, they will be displayed as tabs inside the same windowContainer. Keep in mind, the user can with drag and drop change the container. The user configuration will always be more important than the defaultContainerId.
fillHeightbooleanfalseIf the content should fill all of the available window-space. This breaks the resize-to-content-function in the height.
defaultWidthnumberundefinedsets an initial width
storeIdstring'default'the name of the store to use. Normally you don't need this. If you want windows which should not interact with each other, use different stores for them.
buttonsWindowButtonData[] or (state: ContainerState, defaultButtons: WindowButtonData[]) => WindowButtonData[][]Title Buttons to display at the right of a window container. See below for a definition of WindowButtonData and ContainerState

<WindowList>

Proptyperequireddefaultexplanation
storeIdstring'default'the name of the store to use. Normally you don't need this. If you want windows which should not interact with each other, use different stores for them.

WindowButtonData

{
    key: string;
    icon: IconSource;
    title ? : string;
    containerState ? : ContainerState;
    hideWhenMaximized ? : boolean;
    hideWhenMinimized ? : boolean;
    onClick: (mouseEvent, onClickData) => void;
    onClickData: any
}

Containerstate

enum ContainerState {
    NORMAL,
    MINIMIZED,
    MAXIMIZED,
    POPUP,
}

FAQ

My component is not working correctly when the window is opened inside a popup!

Did you use the window-object inside your component? Thats not directly possible as this library uses React-Portals to render the component inside the popup (or the window). Therefore the window-object always returns the window of the main browser-window.

But there is a solution! You just have to use useWindow() from react-bootstrap-mobile. This hook gives you undefined on the server, but a window-object on the client. Either the new popup-window or the normal browser window.

0.1.13

8 months ago

0.1.14

8 months ago

0.1.12

2 years ago

0.1.10

2 years ago

0.1.11

2 years ago

0.1.9

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago