@xwadex/fesd-next 0.3.6 → 0.3.7

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,17 @@
1
+ import { DragResizePropsTypes, ResizeTypes } from "../../hooks";
2
+ import { AsPropsTypes } from "../../types";
3
+ type PropsTypes<T extends React.ElementType = "div"> = AsPropsTypes<T, {
4
+ as?: React.ElementType;
5
+ children: React.ReactNode;
6
+ defaultWidth?: number;
7
+ defaultHeight?: number;
8
+ resizeClass?: string;
9
+ containerClass?: string;
10
+ dragClass?: string;
11
+ resizeStore?: boolean;
12
+ resizeStoreKey?: string;
13
+ resizeStoreValue?: ResizeTypes;
14
+ } & DragResizePropsTypes>;
15
+ declare const DragResizeBase: <T extends React.ElementType = "div">(props: PropsTypes<T>) => import("react/jsx-runtime").JSX.Element;
16
+ declare const DragResize: React.MemoExoticComponent<typeof DragResizeBase>;
17
+ export default DragResize;
@@ -0,0 +1,74 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { memo, useCallback, useMemo, useState } from "react";
4
+ import { useDragResize, useCookies } from "../../hooks";
5
+ import { DragResizeContext } from "./dragResizeContext";
6
+ import { mergeClassName } from "../../utils";
7
+ import styles from "./dragResize.module.scss";
8
+ const DragResizeBase = (props) => {
9
+ const { as, children, defaultWidth, defaultHeight, resizeClass, containerClass, dragClass, resizeStore = true, resizeStoreKey, resizeStoreValue, active = true, direction = "width", minWidth = 500, maxWidth = 950, onInit, onResizeStart, onResizing, onResizeEnd, ...othersProps } = props;
10
+ const RootComponent = as || "div";
11
+ const [isActive, setActive] = useState(active);
12
+ const { setCookies, deleteCookies } = useCookies();
13
+ const resizeCSS = useMemo(() => mergeClassName(styles.root, resizeClass ? resizeClass : ""), [resizeClass]);
14
+ const dragCSS = useMemo(() => mergeClassName(styles.drag, dragClass ? dragClass : "", !isActive ? styles.off : ""), [isActive, dragClass]);
15
+ const containerCSS = useMemo(() => mergeClassName(styles.container, containerClass ? containerClass : ""), [containerClass]);
16
+ const isCookieStore = useMemo(() => resizeStore
17
+ && resizeStoreKey
18
+ && resizeStoreKey !== ""
19
+ ? true : false, [resizeStore, resizeStoreKey]);
20
+ const resizeDefauleStyles = useMemo(() => {
21
+ if (!isCookieStore || !resizeStoreValue)
22
+ return {
23
+ width: minWidth + "px",
24
+ // height: minHeight + "px"
25
+ };
26
+ const { width, height } = resizeStoreValue;
27
+ return {
28
+ width: width ? width + "px" : "inherit",
29
+ height: height ? height + "px" : "inherit",
30
+ };
31
+ }, [isCookieStore, resizeStoreValue]);
32
+ const onResizeEndHandler = useCallback((size) => {
33
+ onResizeEnd?.(size);
34
+ if (!isCookieStore)
35
+ return;
36
+ setCookies(resizeStoreKey, JSON.stringify(size));
37
+ }, [isCookieStore, onResizeEnd, resizeStore]);
38
+ //Hooks
39
+ const { dragRef, resizeRef } = useDragResize({
40
+ active: isActive,
41
+ direction,
42
+ minWidth,
43
+ maxWidth,
44
+ onInit,
45
+ onResizeStart,
46
+ onResizing,
47
+ onResizeEnd: onResizeEndHandler,
48
+ });
49
+ //Context Functions
50
+ const setResizeActive = useCallback((active) => setActive(active), [setActive]);
51
+ const clearResizeStore = useCallback(() => resizeStoreKey
52
+ ? deleteCookies(resizeStoreKey)
53
+ : console.error("resizeStoreKey is not undefined"), [resizeStoreKey]);
54
+ const defaultResizeSize = useCallback(() => {
55
+ if (!resizeRef.current)
56
+ return;
57
+ resizeRef.current.style.width = minWidth + "px";
58
+ // resizeRef.current.style.height = minHeight + "px"
59
+ clearResizeStore();
60
+ }, [resizeRef.current, clearResizeStore]);
61
+ const contextValue = useMemo(() => ({
62
+ setResizeActive,
63
+ clearResizeStore,
64
+ defaultResizeSize
65
+ }), [
66
+ setResizeActive,
67
+ clearResizeStore,
68
+ defaultResizeSize
69
+ ]);
70
+ return (_jsx(DragResizeContext, { value: contextValue, children: _jsxs(RootComponent, { ...othersProps, ref: resizeRef, className: resizeCSS, style: resizeDefauleStyles, children: [_jsx("div", { className: containerCSS, children: children }), _jsx("div", { ref: dragRef, className: dragCSS })] }) }));
71
+ };
72
+ const DragResize = memo(DragResizeBase);
73
+ DragResize.displayName = "DragResize";
74
+ export default DragResize;
@@ -0,0 +1,39 @@
1
+ .root {
2
+ width: inherit;
3
+ height: inherit;
4
+ display: flex;
5
+ flex-direction: row;
6
+ }
7
+
8
+ .container {
9
+ width: inherit;
10
+ height: inherit;
11
+ }
12
+
13
+ .drag {
14
+ width: 0;
15
+ height: inherit;
16
+ position: relative;
17
+ z-index: 2;
18
+
19
+ &::before {
20
+ content: "";
21
+ width: 0;
22
+ height: inherit;
23
+ border-left: 2px solid rgb(0, 0, 0);
24
+ position: absolute;
25
+ inset: 0 0 0 -1px;
26
+ z-index: 1;
27
+ opacity: 0;
28
+ transition: 0.5s ease-in-out;
29
+ }
30
+
31
+ &:not(.off) {
32
+ &:hover {
33
+ cursor: ew-resize;
34
+ &::before {
35
+ opacity: 1;
36
+ }
37
+ }
38
+ }
39
+ }
@@ -0,0 +1,10 @@
1
+ import React from "react";
2
+ export interface DragResizeContextType {
3
+ setResizeActive: (active: boolean) => void;
4
+ clearResizeStore: () => void;
5
+ defaultResizeSize: () => void;
6
+ }
7
+ export declare const DragResizeContext: React.Context<DragResizeContextType | undefined> & {
8
+ displayName: string;
9
+ };
10
+ export declare const useDragResizeContext: () => DragResizeContextType;
@@ -0,0 +1,9 @@
1
+ "use client";
2
+ import { use, createContext, } from "react";
3
+ export const DragResizeContext = Object.assign(createContext(undefined), { displayName: "DragResizeContext" });
4
+ export const useDragResizeContext = () => {
5
+ const context = use(DragResizeContext);
6
+ if (context)
7
+ return context;
8
+ throw new Error("DragResizeContext is not defined!!");
9
+ };
@@ -0,0 +1,2 @@
1
+ export { default as DragResize } from "./dragResize";
2
+ export * from "./dragResizeContext";
@@ -0,0 +1,2 @@
1
+ export { default as DragResize } from "./dragResize";
2
+ export * from "./dragResizeContext";
@@ -0,0 +1,19 @@
1
+ import type { Sortable, Store } from "react-sortablejs";
2
+ import type { AsPropsTypes } from "../../types";
3
+ type PropsTypes<T extends React.ElementType = "div"> = AsPropsTypes<T, {
4
+ as?: string;
5
+ children: React.ReactNode;
6
+ datasets: any[];
7
+ rootClass?: string;
8
+ sorterClass?: string;
9
+ handlerClass?: string;
10
+ style?: React.CSSProperties;
11
+ disabled?: boolean;
12
+ animation?: number;
13
+ onChange?: (newState: any[], sortable: Sortable | null, store: Store) => void;
14
+ onStart?: ((evt: Sortable.SortableEvent, sortable: Sortable | null, store: Store) => void) | undefined;
15
+ onEnd?: ((evt: Sortable.SortableEvent, sortable: Sortable | null, store: Store) => void) | undefined;
16
+ }>;
17
+ declare const DragSortableBase: <T extends React.ElementType = "div">(props: PropsTypes<T>) => import("react/jsx-runtime").JSX.Element;
18
+ declare const DragSortable: React.MemoExoticComponent<typeof DragSortableBase>;
19
+ export default DragSortable;
@@ -0,0 +1,11 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { memo } from "react";
4
+ import { ReactSortable } from "react-sortablejs";
5
+ const DragSortableBase = (props) => {
6
+ const { as, children, datasets = [], rootClass, sorterClass, handlerClass, style, animation = 150, disabled = false, onChange, onStart, onEnd, ...othersProps } = props;
7
+ return (_jsx(ReactSortable, { ...othersProps, tag: as, disabled: disabled, className: rootClass, ghostClass: sorterClass, handle: "." + handlerClass, fallbackClass: "sortable-fallback", list: datasets, setList: onChange, animation: animation, style: style, onStart: onStart, onEnd: onEnd, children: children }));
8
+ };
9
+ const DragSortable = memo(DragSortableBase);
10
+ DragSortable.displayName = "DragSortable";
11
+ export default DragSortable;
@@ -0,0 +1,7 @@
1
+ .dragging {
2
+ > * {
3
+ &:hover {
4
+ background-color: transparent !important;
5
+ }
6
+ }
7
+ }
@@ -0,0 +1 @@
1
+ export { default as DragSortable } from "./dragSortable";
@@ -0,0 +1 @@
1
+ export { default as DragSortable } from "./dragSortable";
@@ -1,2 +1,4 @@
1
1
  export * from "./myComponents";
2
2
  export * from "./accordions";
3
+ export * from "./dragResize";
4
+ export * from "./dragSortable";
@@ -1,2 +1,4 @@
1
1
  export * from "./myComponents";
2
2
  export * from "./accordions";
3
+ export * from "./dragResize";
4
+ export * from "./dragSortable";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xwadex/fesd-next",
3
- "version": "0.3.6",
3
+ "version": "0.3.7",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -38,6 +38,7 @@
38
38
  "react": ">=18",
39
39
  "react-dom": ">=18",
40
40
  "next": ">=15.3.3",
41
- "tua-body-scroll-lock": ">=1.5.3"
41
+ "tua-body-scroll-lock": ">=1.5.3",
42
+ "react-sortablejs": ">=6.1.4"
42
43
  }
43
44
  }