@gfazioli/mantine-window
A Mantine extension component that renders interactive JSON trees with syntax highlighting, collapsible nodes, copy-to-clipboard, and configurable expansion depth.
Installation
After installation import package styles at the root of your application:
You can import styles within a layer @layer mantine-window by importing @gfazioli/mantine-window/styles.layer.css file.
Usage
The Window component allows you to create draggable and resizable windows within your application. It provides a familiar desktop-like experience for users. You can customize the appearance and behavior of the windows using various props. Also, you can choose whether the window should be rendered within a portal or relative to its parent container using the withinPortal prop.
Note:
Usually, you would want to use the
Windowcomponent within a portal to avoid layout issues. However, if you want the window to be constrained within a specific container, you can set thewithinPortalprop tofalseand the container should haveposition: relativestyle.For example, in the demos below, the
Windowcomponent is rendered relative to its parent container which hasposition: relativestyle.
Hello, World! Hello, Mantiners! Say Hello to the Window component
Controlled
You can control the open and close state of the Window component using the opened and onClose props. This allows you to manage the visibility of the window programmatically.
Within Portal vs Container
The withinPortal prop controls how the window is positioned. When withinPortal={true} (default), the window uses fixed positioning relative to the viewport. When withinPortal={false}, it uses absolute positioning relative to its parent container.
Fixed positioning (withinPortal=true):
- Window stays in place when scrolling
- Positioned relative to the browser viewport
- Best for modals and overlays
Absolute positioning (withinPortal=false):
- Window is constrained within parent container
- Parent must have
position: relative - Best for embedded UI components
Container with position: relative
Custom Position
You can set the initial position of the window using the defaultPosition prop. This is useful when you want the window to appear at a specific location on the screen.
Custom Position
Custom Size
Set custom initial dimensions for the window using the defaultSize prop. This allows you to control the width and height of the window when it first appears.
Custom Size
Min/Max Size Constraints
Control the minimum and maximum dimensions during resize operations using minWidth, minHeight, maxWidth, and maxHeight props. This prevents the window from becoming too small or too large.
Constrained Resize
Drag Boundaries
Restrict the draggable area of the window using the dragBounds prop. This ensures the window stays within specific boundaries and cannot be dragged outside the defined area.
Bounded Dragging
Persistence
Enable state persistence to save the window's position and size in localStorage by setting persistState={true} (default is true). When enabled, the window will remember its position and size across page refreshes. Set persistState={false} to disable this behavior and always start at the default position and size.
With Persistence
Callbacks
Use onPositionChange and onSizeChange callbacks to respond to window movements and resize operations. These callbacks receive the current position or size as arguments.
With Callbacks
Centered Window
Create a centered, fixed window that cannot be moved or resized by combining defaultPosition, defaultSize, resizable="none", and draggable="none" props.
Centered Window
Multiple Windows
You can render multiple windows in the same container. Each window maintains its own z-index and can be brought to the front by clicking on it. Use unique id props to ensure proper state persistence.
Window 1
Window 2
Disable Collapsing
Prevent the window from being collapsed by setting collapsable={false}. This removes the collapse functionality, including the double-click handler on the header.
No Collapsable
Styles API
Window supports Styles API, you can add styles to any inner element of the component with classNames prop. Follow Styles API documentation to learn more.
You can customize the appearance of the Window component using the Styles API. This allows you to modify styles for various parts of the component, such as keys, values, brackets, and more.
Styles API
Component Styles API
Hover over selectors to highlight corresponding elements