@gfazioli/mantine-window 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,114 @@
1
+ import React from 'react';
2
+ import { Factory, StylesApiProps, type BoxProps, type MantineColor, type MantineRadius, type MantineShadow } from '@mantine/core';
3
+ export type WindowStylesNames = 'root' | 'container' | 'content' | 'header' | 'title' | 'closeButton' | 'collapseButton' | 'windowToolsButton' | 'resizeHandleTopLeft' | 'resizeHandleTop' | 'resizeHandleTopRight' | 'resizeHandleRight' | 'resizeHandleBottomRight' | 'resizeHandleBottom' | 'resizeHandleBottomLeft' | 'resizeHandleLeft';
4
+ export type WindowCssVariables = {
5
+ root: '--window-background' | '--window-radius';
6
+ container: never;
7
+ content: never;
8
+ header: never;
9
+ title: never;
10
+ closeButton: never;
11
+ collapseButton: never;
12
+ windowToolsButton: never;
13
+ resizeHandleTopLeft: never;
14
+ resizeHandleTop: never;
15
+ resizeHandleTopRight: never;
16
+ resizeHandleRight: never;
17
+ resizeHandleBottomRight: never;
18
+ resizeHandleBottom: never;
19
+ resizeHandleBottomLeft: never;
20
+ resizeHandleLeft: never;
21
+ };
22
+ export type ResizableMode = 'none' | 'vertical' | 'horizontal' | 'both';
23
+ export type DraggableMode = 'none' | 'window' | 'header' | 'both';
24
+ export interface WindowBounds {
25
+ /** Minimum x coordinate (left boundary) */
26
+ minX?: number;
27
+ /** Maximum x coordinate (right boundary) */
28
+ maxX?: number;
29
+ /** Minimum y coordinate (top boundary) */
30
+ minY?: number;
31
+ /** Maximum y coordinate (bottom boundary) */
32
+ maxY?: number;
33
+ }
34
+ export interface WindowSize {
35
+ /** Width in pixels */
36
+ width: number;
37
+ /** Height in pixels */
38
+ height: number;
39
+ }
40
+ export interface WindowPosition {
41
+ /** X coordinate in pixels */
42
+ x: number;
43
+ /** Y coordinate in pixels */
44
+ y: number;
45
+ }
46
+ export interface WindowBaseProps {
47
+ /** Whether the window is opened for controlled usage */
48
+ opened?: boolean;
49
+ /** Color of the window */
50
+ color?: MantineColor;
51
+ /** Unique id of the window. Used to store window position and size. If not provided, the title is used */
52
+ id?: string;
53
+ /** Title of the window. Used as a fallback id if no id is provided */
54
+ title?: string;
55
+ /** Radius of the window */
56
+ radius?: MantineRadius | number;
57
+ /** Whether the window has a border */
58
+ withBorder?: boolean;
59
+ /** Shadow of the window */
60
+ shadow?: MantineShadow;
61
+ /** Resizable mode of the window */
62
+ resizable?: ResizableMode;
63
+ /** Draggable mode of the window */
64
+ draggable?: DraggableMode;
65
+ /** Whether the window is initially collapsed */
66
+ collapsed?: boolean;
67
+ /** Whether the window has a collapse button */
68
+ withCollapseButton?: boolean;
69
+ /** Whether the window is collapsable */
70
+ collapsable?: boolean;
71
+ /** Whether the window has a close button */
72
+ withCloseButton?: boolean;
73
+ /** Called when the window is closed */
74
+ onClose?: () => void;
75
+ /** Initial position of the window. If not provided, defaults to { x: 20, y: 100 } */
76
+ defaultPosition?: WindowPosition;
77
+ /** Initial size of the window. If not provided, defaults to { width: 400, height: 400 } */
78
+ defaultSize?: WindowSize;
79
+ /** Minimum width in pixels during resize. Default: 250 */
80
+ minWidth?: number;
81
+ /** Minimum height in pixels during resize. Default: 100 */
82
+ minHeight?: number;
83
+ /** Maximum width in pixels during resize. If not provided, no maximum limit */
84
+ maxWidth?: number;
85
+ /** Maximum height in pixels during resize. If not provided, no maximum limit */
86
+ maxHeight?: number;
87
+ /** Boundaries for dragging the window. If not provided, window can be dragged anywhere within viewport */
88
+ dragBounds?: WindowBounds;
89
+ /** Whether to persist position and size in localStorage. You have to set the `id` or `title` prop for persistence to work. Default: false */
90
+ persistState?: boolean;
91
+ /** If true, window is positioned relative to the viewport. If false, positioned relative to parent container. Default: true */
92
+ withinPortal?: boolean;
93
+ /** Called when the window is moved */
94
+ onPositionChange?: (position: WindowPosition) => void;
95
+ /** Called when the window is resized */
96
+ onSizeChange?: (size: WindowSize) => void;
97
+ /** Window content */
98
+ children?: React.ReactNode;
99
+ }
100
+ export interface WindowProps extends BoxProps, WindowBaseProps, StylesApiProps<WindowFactory> {
101
+ }
102
+ export type WindowFactory = Factory<{
103
+ props: WindowProps;
104
+ ref: HTMLDivElement;
105
+ stylesNames: WindowStylesNames;
106
+ vars: WindowCssVariables;
107
+ }>;
108
+ export declare const defaultProps: Partial<WindowProps>;
109
+ export declare const Window: import("@mantine/core").MantineComponent<{
110
+ props: WindowProps;
111
+ ref: HTMLDivElement;
112
+ stylesNames: WindowStylesNames;
113
+ vars: WindowCssVariables;
114
+ }>;
@@ -0,0 +1,22 @@
1
+ import type { WindowBaseProps, WindowPosition, WindowSize } from '../Window';
2
+ export declare function useMantineWindow(props: WindowBaseProps): {
3
+ readonly isCollapsed: boolean;
4
+ readonly setIsCollapsed: import("react").Dispatch<import("react").SetStateAction<boolean>>;
5
+ readonly isVisible: boolean;
6
+ readonly setIsVisible: import("react").Dispatch<import("react").SetStateAction<boolean>>;
7
+ readonly zIndex: number;
8
+ readonly position: WindowPosition;
9
+ readonly size: WindowSize;
10
+ readonly windowRef: import("react").RefObject<HTMLDivElement>;
11
+ readonly handleMouseDownDrag: (e: React.MouseEvent) => void;
12
+ readonly handleMouseDownResizeTopLeft: (e: React.MouseEvent) => void;
13
+ readonly handleMouseDownResizeTop: (e: React.MouseEvent) => void;
14
+ readonly handleMouseDownResizeTopRight: (e: React.MouseEvent) => void;
15
+ readonly handleMouseDownResizeRight: (e: React.MouseEvent) => void;
16
+ readonly handleMouseDownResizeBottomRight: (e: React.MouseEvent) => void;
17
+ readonly handleMouseDownResizeBottom: (e: React.MouseEvent) => void;
18
+ readonly handleMouseDownResizeBottomLeft: (e: React.MouseEvent) => void;
19
+ readonly handleMouseDownResizeLeft: (e: React.MouseEvent) => void;
20
+ readonly handleClose: () => void;
21
+ readonly bringToFront: () => void;
22
+ };
@@ -0,0 +1,2 @@
1
+ export { Window } from './Window';
2
+ export type { DraggableMode, ResizableMode, WindowBaseProps, WindowBounds, WindowCssVariables, WindowFactory, WindowPosition, WindowProps, WindowSize, WindowStylesNames, } from './Window';
@@ -0,0 +1,2 @@
1
+ export { Window } from './Window';
2
+ export type { DraggableMode, ResizableMode, WindowBaseProps, WindowBounds, WindowCssVariables, WindowFactory, WindowPosition, WindowProps, WindowSize, WindowStylesNames, } from './Window';
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@gfazioli/mantine-window",
3
+ "version": "0.5.1",
4
+ "description": "A Mantine extension component that renders draggable, resizable floating windows with persistent state, customizable boundaries, collapsible content, and flexible control over position, size, and interaction modes.",
5
+ "homepage": "https://gfazioli.github.io/mantine-window/",
6
+ "packageManager": "yarn@4.0.1",
7
+ "license": "MIT",
8
+ "author": "Giovambattista Fazioli <giovambattista.fazioli@gmail.com>",
9
+ "keywords": [
10
+ "extension",
11
+ "window",
12
+ "mantine",
13
+ "react",
14
+ "react-component",
15
+ "typescript"
16
+ ],
17
+ "main": "./dist/cjs/index.cjs",
18
+ "module": "./dist/esm/index.mjs",
19
+ "types": "./dist/types/index.d.ts",
20
+ "exports": {
21
+ ".": {
22
+ "import": {
23
+ "types": "./dist/types/index.d.mts",
24
+ "default": "./dist/esm/index.mjs"
25
+ },
26
+ "require": {
27
+ "types": "./dist/types/index.d.ts",
28
+ "default": "./dist/cjs/index.cjs"
29
+ }
30
+ },
31
+ "./styles.css": "./dist/styles.css",
32
+ "./styles.layer.css": "./dist/styles.layer.css"
33
+ },
34
+ "repository": "https://github.com/gfazioli/mantine-window.git",
35
+ "peerDependencies": {
36
+ "@mantine/core": ">=7.0.0",
37
+ "@mantine/hooks": ">=7.0.0",
38
+ "@tabler/icons-react": "^3.34.0",
39
+ "react": "^18.x || ^19.x",
40
+ "react-dom": "^18.x || ^19.x"
41
+ },
42
+ "bugs": "https://github.com/gfazioli/mantine-window/issues"
43
+ }