@synerise/ds-panels-resizer 0.0.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.
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Synerise
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,43 @@
1
+ ---
2
+ id: panels-resizer
3
+ title: PanelResizer
4
+ ---
5
+
6
+ The `PanelsResizer` component allows you to create a layout with resizable left and right panels, separated by a draggable resizer.
7
+
8
+ Users can adjust the width of the panels by dragging the resizer, providing a flexible and customizable interface.
9
+
10
+ ## Installation
11
+ ```
12
+ npm i @synerise/ds-panels-resizer
13
+ or
14
+ yarn add @synerise/ds-panels-resizer
15
+ ```
16
+
17
+ ## Usage
18
+ ```
19
+ import { PanelsResizer } from '@synerise/ds-panels-resizer';
20
+
21
+ const App = () => (
22
+ <div style={{ width: '100%', height: '680px' }}>
23
+ <PanelsResizer
24
+ leftPanel={<div>Left Panel Content</div>}
25
+ rightPanel={<div>Right Panel Content</div>}
26
+ />
27
+ </div>
28
+ );
29
+
30
+ ```
31
+
32
+ ## Demo
33
+
34
+ <iframe src="/storybook-static/iframe.html?id=components-panels-resizer--default"></iframe>
35
+
36
+ ## API
37
+
38
+ | Property | Description | Type | Default |
39
+ | --- | --- | --- | --- |
40
+ | leftPanel | The content to display in the left panel. | React.ReactNode | --- |
41
+ | rightPanel | The content to display in the right panel. | React.ReactNode | --- |
42
+ | initial | Initial widths of the panels. Can specify leftPanel or rightPanel width in pixels. | { leftPanel: number } \| { rightPanel: number } | --- |
43
+ | scrollable | Whether the panels should be scrollable when their content overflows. | boolean | false |
@@ -0,0 +1 @@
1
+ export declare const PanelsResizerContainer: import("styled-components").StyledComponent<"div", any, {}, never>;
@@ -0,0 +1,5 @@
1
+ import styled from 'styled-components';
2
+ export var PanelsResizerContainer = styled.div.withConfig({
3
+ displayName: "PanelResizerstyles__PanelsResizerContainer",
4
+ componentId: "d1bdei-0"
5
+ })(["display:flex;flex:1;height:-webkit-fill-available;"]);
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import type { ReactNode } from 'react';
3
+ import type { InitialVectorOptions } from './utils';
4
+ type PanelsResizerProps = {
5
+ leftPanel: ReactNode;
6
+ rightPanel: ReactNode;
7
+ initial?: InitialVectorOptions;
8
+ scrollable?: boolean;
9
+ };
10
+ export declare const PanelsResizer: ({ leftPanel, rightPanel, initial, scrollable }: PanelsResizerProps) => React.JSX.Element;
11
+ export {};
@@ -0,0 +1,65 @@
1
+ import React, { useCallback, useState, useRef, useEffect } from 'react';
2
+ import { Resizer } from './Resizer';
3
+ import { calculateLeftPanelWidth, calculateRightPanelWidth, getInitialVector } from './utils';
4
+ import * as S from './PanelResizer.styles';
5
+ export var PanelsResizer = function PanelsResizer(_ref) {
6
+ var leftPanel = _ref.leftPanel,
7
+ rightPanel = _ref.rightPanel,
8
+ initial = _ref.initial,
9
+ scrollable = _ref.scrollable;
10
+ var containerRef = useRef(null);
11
+ var _useState = useState(false),
12
+ isResizing = _useState[0],
13
+ setIsResizing = _useState[1];
14
+ var _useState2 = useState(0),
15
+ vector = _useState2[0],
16
+ setVector = _useState2[1];
17
+ var startClientXRef = useRef(0);
18
+ useEffect(function () {
19
+ if (containerRef.current) {
20
+ var containerWidth = containerRef.current.offsetWidth;
21
+ var initialVector = getInitialVector(initial, containerWidth);
22
+ setVector(initialVector);
23
+ }
24
+ }, [initial]);
25
+ var handleMouseMove = useCallback(function (event) {
26
+ if (!isResizing) return;
27
+ var deltaX = event.clientX - startClientXRef.current;
28
+ setVector(function (prevVector) {
29
+ return prevVector !== null ? prevVector + deltaX : deltaX;
30
+ });
31
+ startClientXRef.current = event.clientX;
32
+ }, [isResizing]);
33
+ var handleMouseUpOrLeave = useCallback(function () {
34
+ if (!isResizing) return;
35
+ setIsResizing(false);
36
+ }, [isResizing]);
37
+ var handleMouseDownOnResizer = useCallback(function (event) {
38
+ setIsResizing(true);
39
+ startClientXRef.current = event.clientX;
40
+ }, []);
41
+ return /*#__PURE__*/React.createElement(S.PanelsResizerContainer, {
42
+ ref: containerRef,
43
+ "data-testid": "panels-resizer-container",
44
+ onMouseUp: handleMouseUpOrLeave,
45
+ onMouseMove: handleMouseMove,
46
+ onMouseLeave: handleMouseUpOrLeave
47
+ }, /*#__PURE__*/React.createElement("div", {
48
+ "data-testid": "left-panel-wrapper",
49
+ style: {
50
+ width: calculateLeftPanelWidth(vector),
51
+ pointerEvents: isResizing ? 'none' : 'auto',
52
+ overflow: scrollable ? 'auto' : 'hidden'
53
+ }
54
+ }, leftPanel), /*#__PURE__*/React.createElement(Resizer, {
55
+ onMouseDown: handleMouseDownOnResizer
56
+ }), /*#__PURE__*/React.createElement("div", {
57
+ "data-testid": "right-panel-wrapper",
58
+ style: {
59
+ width: calculateRightPanelWidth(vector),
60
+ pointerEvents: isResizing ? 'none' : 'auto',
61
+ zIndex: 4,
62
+ overflow: scrollable ? 'auto' : 'hidden'
63
+ }
64
+ }, rightPanel));
65
+ };
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ import type { MouseEvent } from 'react';
3
+ type ResizerProps = {
4
+ onMouseDown: (event: MouseEvent<HTMLDivElement>) => void;
5
+ };
6
+ export declare const Resizer: ({ onMouseDown }: ResizerProps) => React.JSX.Element;
7
+ export {};
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ import { DragHandleM } from '@synerise/ds-icon';
3
+ import { Handler, HandlerIcon } from './Resizer.styles';
4
+ var HANDLER_WIDTH = 16;
5
+ export var Resizer = function Resizer(_ref) {
6
+ var onMouseDown = _ref.onMouseDown;
7
+ return /*#__PURE__*/React.createElement(Handler, {
8
+ "data-testid": "resizer-handler",
9
+ onMouseDown: onMouseDown,
10
+ width: HANDLER_WIDTH
11
+ }, /*#__PURE__*/React.createElement(HandlerIcon, {
12
+ component: /*#__PURE__*/React.createElement(DragHandleM, null),
13
+ size: HANDLER_WIDTH
14
+ }));
15
+ };
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ export declare const Handler: import("styled-components").StyledComponent<"div", any, {
3
+ width: number;
4
+ }, never>;
5
+ export declare const HandlerIcon: import("styled-components").StyledComponent<({ name, component, className, ...rest }: import("@synerise/ds-icon").IconProps) => import("react").JSX.Element, any, {}, never>;
@@ -0,0 +1,20 @@
1
+ import styled from 'styled-components';
2
+ import Icon from '@synerise/ds-icon';
3
+ export var Handler = styled.div.withConfig({
4
+ displayName: "Resizerstyles__Handler",
5
+ componentId: "s3ii80-0"
6
+ })(["display:flex;align-items:center;width:", "px;flex-grow:1;z-index:5;background-color:", ";&:hover{cursor:ew-resize;background-color:", ";}"], function (props) {
7
+ return props.width;
8
+ }, function (props) {
9
+ return props.theme.palette['grey-200'];
10
+ }, function (props) {
11
+ return props.theme.palette['blue-100'];
12
+ });
13
+ export var HandlerIcon = styled(Icon).withConfig({
14
+ displayName: "Resizerstyles__HandlerIcon",
15
+ componentId: "s3ii80-1"
16
+ })(["svg{fill:", ";}&:hover{color:", ";}"], function (props) {
17
+ return props.theme.palette['grey-600'];
18
+ }, function (props) {
19
+ return props.theme.palette['blue-600'];
20
+ });
@@ -0,0 +1 @@
1
+ export * from './Resizer';
@@ -0,0 +1 @@
1
+ export * from './Resizer';
@@ -0,0 +1 @@
1
+ export { PanelsResizer } from './PanelsResizer';
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export { PanelsResizer } from './PanelsResizer';
@@ -0,0 +1 @@
1
+ import '@testing-library/jest-dom/extend-expect';
@@ -0,0 +1,8 @@
1
+ export type InitialVectorOptions = {
2
+ leftPanel: number;
3
+ } | {
4
+ rightPanel: number;
5
+ };
6
+ export declare const getInitialVector: (options: InitialVectorOptions | undefined, containerWidth: number) => number;
7
+ export declare const calculateLeftPanelWidth: (vector: number) => string;
8
+ export declare const calculateRightPanelWidth: (vector: number) => string;
@@ -0,0 +1,18 @@
1
+ export var getInitialVector = function getInitialVector(options, containerWidth) {
2
+ if (!options) return 0;
3
+ var half = containerWidth / 2;
4
+ if ('leftPanel' in options) {
5
+ return options.leftPanel - half;
6
+ }
7
+ if ('rightPanel' in options) {
8
+ return half - options.rightPanel;
9
+ }
10
+ return 0;
11
+ };
12
+ var HALF_WIDTH = '50%';
13
+ export var calculateLeftPanelWidth = function calculateLeftPanelWidth(vector) {
14
+ return "calc(" + HALF_WIDTH + " + " + vector + "px)";
15
+ };
16
+ export var calculateRightPanelWidth = function calculateRightPanelWidth(vector) {
17
+ return "calc(" + HALF_WIDTH + " - " + vector + "px)";
18
+ };
@@ -0,0 +1 @@
1
+ export * from './calculatePanelsWidth';
@@ -0,0 +1 @@
1
+ export * from './calculatePanelsWidth';
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@synerise/ds-panels-resizer",
3
+ "version": "0.0.1",
4
+ "description": "PanelResizer UI Component for the Synerise Design System",
5
+ "license": "ISC",
6
+ "repository": "Synerise/synerise-design",
7
+ "main": "dist/index.js",
8
+ "files": [
9
+ "/dist",
10
+ "CHANGELOG.md",
11
+ "README.md",
12
+ "package.json",
13
+ "LICENSE.md"
14
+ ],
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "scripts": {
19
+ "build": "npm run build:js && npm run build:css && npm run defs",
20
+ "build:css": "node ../../../scripts/style/less.js",
21
+ "build:js": "babel --delete-dir-on-start --root-mode upward src --out-dir dist --extensions '.js,.ts,.tsx'",
22
+ "build:watch": "npm run build:js -- --watch",
23
+ "defs": "tsc --declaration --outDir dist/ --emitDeclarationOnly",
24
+ "pack:ci": "npm pack --pack-destination ../../portal/storybook-static/static",
25
+ "prepublish": "npm run build",
26
+ "test": "jest",
27
+ "test:watch": "npm run test -- --watchAll",
28
+ "types": "tsc --noEmit",
29
+ "upgrade:ds": "ncu -f \"@synerise/ds-*\" -u"
30
+ },
31
+ "sideEffects": [
32
+ "dist/style/*",
33
+ "*.less"
34
+ ],
35
+ "types": "dist/index.d.ts",
36
+ "dependencies": {
37
+ "@synerise/ds-icon": "^0.68.0"
38
+ },
39
+ "peerDependencies": {
40
+ "@synerise/ds-core": "*",
41
+ "react": ">=16.9.0 <= 17.0.2",
42
+ "styled-components": "5.0.1"
43
+ },
44
+ "gitHead": "cc884c487bf337d59ff357e1232dda3156d4396e"
45
+ }