Skip to content

Commit 814bc9b

Browse files
authored
feat(components): automatically detect touchscreen in ResizeLayout (#5)
1 parent debca00 commit 814bc9b

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pistonite/celera",
3-
"version": "0.1.4",
3+
"version": "0.1.5",
44
"type": "module",
55
"private": true,
66
"description": "In-house UI framework",

src/components/resize_layout.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { makeStyles, mergeClasses } from "@fluentui/react-components";
22
import { Children, useRef, useState, type PropsWithChildren } from "react";
33

4+
import { isMobile } from "#pref";
5+
46
/**
57
* React component. A flex-box layout of 2 children, with a draggable divider between them.
68
*
@@ -28,7 +30,10 @@ export interface ResizeLayoutOwnProps {
2830
/** Use the natural size instead of valuePercent */
2931
naturalSize?: boolean;
3032

31-
/** Optimize for touch screen */
33+
/**
34+
* Force enable styles for touch screen. Note that by default it is enabled
35+
* if the device is mobile
36+
*/
3237
touch?: boolean;
3338
}
3439

@@ -88,8 +93,8 @@ export const ResizeLayout: React.FC<PropsWithChildren<ResizeLayoutProps>> = (inP
8893
naturalSize,
8994
minWidth,
9095
minHeight,
91-
touch,
9296
children,
97+
touch: propTouch,
9398
...props
9499
} = inProps;
95100
const [firstChild, secondChild] = Children.toArray(children);
@@ -100,6 +105,8 @@ export const ResizeLayout: React.FC<PropsWithChildren<ResizeLayoutProps>> = (inP
100105
// [startX, startY, startWidth, startHeight]
101106
const [resizing, setResizing] = useState<number[] | undefined>(undefined);
102107

108+
const touch = propTouch || isMobile();
109+
103110
const startResize = (e: React.MouseEvent | React.TouchEvent) => {
104111
if (disabled || !firstRef.current) {
105112
return;

0 commit comments

Comments
 (0)