@zuzjs/ui 0.9.3 → 0.9.5

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.
Files changed (40) hide show
  1. package/dist/cjs/comps/Crumb/index.d.ts +1 -1
  2. package/dist/cjs/comps/Drawer/index.js +4 -0
  3. package/dist/cjs/comps/Form/index.js +4 -1
  4. package/dist/cjs/comps/Form/types.d.ts +1 -0
  5. package/dist/cjs/comps/Group/index.d.ts +6 -0
  6. package/dist/cjs/comps/Group/index.js +21 -0
  7. package/dist/cjs/comps/Image/index.js +5 -3
  8. package/dist/cjs/comps/List/index.d.ts +1 -1
  9. package/dist/cjs/comps/ScrollView/index.js +1 -2
  10. package/dist/cjs/comps/Text/index.js +0 -2
  11. package/dist/cjs/comps/index.d.ts +1 -0
  12. package/dist/cjs/comps/index.js +2 -0
  13. package/dist/cjs/funs/index.d.ts +1 -1
  14. package/dist/cjs/funs/index.js +4 -3
  15. package/dist/cjs/hooks/useBase.js +52 -11
  16. package/dist/cjs/hooks/useScrollbar.d.ts +1 -1
  17. package/dist/cjs/hooks/useScrollbar.js +12 -5
  18. package/dist/cjs/types/interfaces.d.ts +3 -2
  19. package/dist/css/styles.css +1 -1
  20. package/dist/esm/comps/Crumb/index.d.ts +1 -1
  21. package/dist/esm/comps/Drawer/index.js +4 -0
  22. package/dist/esm/comps/Form/index.js +4 -1
  23. package/dist/esm/comps/Form/types.d.ts +1 -0
  24. package/dist/esm/comps/Group/index.d.ts +6 -0
  25. package/dist/esm/comps/Group/index.js +21 -0
  26. package/dist/esm/comps/Image/index.js +5 -3
  27. package/dist/esm/comps/List/index.d.ts +1 -1
  28. package/dist/esm/comps/ScrollView/index.js +1 -2
  29. package/dist/esm/comps/Text/index.js +0 -2
  30. package/dist/esm/comps/index.d.ts +1 -0
  31. package/dist/esm/comps/index.js +2 -0
  32. package/dist/esm/funs/index.d.ts +1 -1
  33. package/dist/esm/funs/index.js +4 -3
  34. package/dist/esm/hooks/useBase.js +52 -11
  35. package/dist/esm/hooks/useScrollbar.d.ts +1 -1
  36. package/dist/esm/hooks/useScrollbar.js +12 -5
  37. package/dist/esm/types/interfaces.d.ts +3 -2
  38. package/dist/tsconfig.esm.tsbuildinfo +1 -1
  39. package/dist/tsconfig.tsbuildinfo +1 -1
  40. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  declare const Crumb: import("react").ForwardRefExoticComponent<import("..").BoxProps & {
2
2
  items: import("./types").CrumbItem[];
3
3
  maxItems?: number;
4
- } & import("react").RefAttributes<HTMLUListElement | HTMLOListElement>>;
4
+ } & import("react").RefAttributes<HTMLOListElement | HTMLUListElement>>;
5
5
  export default Crumb;
@@ -41,10 +41,14 @@ const Drawer = forwardRef((props, ref) => {
41
41
  open(child) {
42
42
  if (child)
43
43
  setContent(child);
44
+ if (!window.document.body.classList.contains(`--no-scroll`))
45
+ window.document.body.classList.add(`--no-scroll`);
44
46
  setVisible(true);
45
47
  },
46
48
  close() {
47
49
  onClose?.();
50
+ if (window.document.body.classList.contains(`--no-scroll`))
51
+ window.document.body.classList.remove(`--no-scroll`);
48
52
  setVisible(false);
49
53
  }
50
54
  }));
@@ -267,7 +267,7 @@ const Form = forwardRef((props, ref) => {
267
267
  });
268
268
  }
269
269
  }, [innerRef.current]);
270
- const buildChildren = useMemo(() => addPropsToChildren(children, child => child.props.type == `submit`, { ref: submit }), [children]);
270
+ const buildChildren = useMemo(() => addPropsToChildren(children, child => child.props.type == `submit`, index => ({ ref: submit })), [children]);
271
271
  useImperativeHandle(ref, () => ({
272
272
  setLoading(mod) {
273
273
  if (mod) {
@@ -296,6 +296,9 @@ const Form = forwardRef((props, ref) => {
296
296
  },
297
297
  init() {
298
298
  _init();
299
+ },
300
+ submit() {
301
+ _onSubmit();
299
302
  }
300
303
  }));
301
304
  useEffect(_init, []);
@@ -40,4 +40,5 @@ export interface FormHandler {
40
40
  hideError: () => void;
41
41
  /** Resets the form to its initial state */
42
42
  init: () => void;
43
+ submit: () => void;
43
44
  }
@@ -0,0 +1,6 @@
1
+ import { BoxProps } from "../Box";
2
+ declare const Group: import("react").ForwardRefExoticComponent<BoxProps & {
3
+ fxDelay?: number;
4
+ fxStep?: number;
5
+ } & import("react").RefAttributes<HTMLDivElement>>;
6
+ export default Group;
@@ -0,0 +1,21 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { forwardRef, useMemo } from "react";
3
+ import { useDelayed } from "../..";
4
+ import { addPropsToChildren } from "../../funs";
5
+ import Box from "../Box";
6
+ const Group = forwardRef((props, ref) => {
7
+ const { children, fx, fxDelay, fxStep, ...rest } = props;
8
+ const when = useDelayed();
9
+ const Children = useMemo(() => {
10
+ if (!fx)
11
+ return children;
12
+ return addPropsToChildren(children, child => !(`fx` in (child.props ?? {})), index => ({ fx: {
13
+ ...fx,
14
+ delay: (fxDelay || 0) + index * (fxStep || .1), // how to increment per index ?
15
+ when
16
+ } }));
17
+ }, [children, when, fx]);
18
+ return _jsx(Box, { className: `--group`, ref: ref, ...rest, children: Children });
19
+ });
20
+ Group.displayName = `Zuz.Group`;
21
+ export default Group;
@@ -1,11 +1,13 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { forwardRef } from 'react';
2
+ import { forwardRef, useMemo, useRef } from 'react';
3
3
  import { useBase } from '../../hooks';
4
4
  const Image = forwardRef((props, ref) => {
5
- const { style, className, rest } = useBase(props);
5
+ const innerRef = useRef(null);
6
+ const targetRef = useMemo(() => ref && typeof ref !== "function" && ref.current ? ref : innerRef, [ref]);
7
+ const { style, className, rest } = useBase(props, targetRef);
6
8
  if (!rest.src || rest.src == ``)
7
9
  return null;
8
- return _jsx("img", { ref: ref, style: style, className: `${className} flex`, ...rest });
10
+ return _jsx("img", { ref: targetRef, style: style, className: `${className} flex`, ...rest });
9
11
  });
10
12
  Image.displayName = `Zuz.Image`;
11
13
  export default Image;
@@ -6,5 +6,5 @@ declare const List: import("react").ForwardRefExoticComponent<import("../..").Zu
6
6
  direction?: "cols" | "rows";
7
7
  seperator?: import("react").ReactNode;
8
8
  ol?: boolean;
9
- } & import("react").RefAttributes<HTMLUListElement | HTMLOListElement>>;
9
+ } & import("react").RefAttributes<HTMLOListElement | HTMLUListElement>>;
10
10
  export default List;
@@ -4,9 +4,8 @@ import { useBase, useScrollbar } from "../../hooks";
4
4
  import Box from "../Box";
5
5
  const ScrollView = forwardRef((props, ref) => {
6
6
  const { speed, style: _style, ...pops } = props;
7
- const { rootRef, containerRef, thumbY, thumbX, onScrollY, onScrollX } = useScrollbar();
7
+ const { rootRef, containerRef, thumbY, thumbX, onScrollY, onScrollX } = useScrollbar(speed || 1);
8
8
  const { style, className, rest } = useBase(pops);
9
- // useEffect(() => { }, [])
10
9
  return _jsxs(Box, { ref: rootRef, className: className.trim(), as: `--scrollview rel`, children: [_jsx(Box, { as: `--scroll-content`, ref: containerRef, style: _style || {}, children: rest.children }), _jsx(Box, { as: `--scroll-track --track-y --abs`, children: _jsx(Box, { as: `--scroll-thumb --abs`, ref: thumbY, onMouseDown: onScrollY }) }), _jsx(Box, { as: `--scroll-track --track-x --abs`, children: _jsx(Box, { as: `--scroll-thumb --abs`, ref: thumbX, onMouseDown: onScrollX }) })] });
11
10
  });
12
11
  ScrollView.displayName = `Zuz.ScrollView`;
@@ -5,8 +5,6 @@ import Span from '../Span';
5
5
  const Text = forwardRef((props, ref) => {
6
6
  const { h, html, children, lines, ...pops } = props;
7
7
  const { style, className, rest } = useBase(pops);
8
- // const textRef = useTruncateText(lines || 2)
9
- // const mergedRef = useMergedRefs(ref, textRef)
10
8
  const Tag = `h${props.h || 1}`;
11
9
  return _jsx(Tag, { ref: ref, style: style, className: className, ...rest, children: html ? _jsx(Span, { dangerouslySetInnerHTML: { __html: html } }) : children });
12
10
  });
@@ -36,6 +36,7 @@ export * from './Fab/types';
36
36
  export { default as Filters, type FilterProps } from './Filters';
37
37
  export { default as Form } from './Form';
38
38
  export * from './Form/types';
39
+ export { default as Group } from './Group';
39
40
  export { default as Icon, type IconProps } from './Icon';
40
41
  export { default as Image, type ImageProps } from './Image';
41
42
  export { default as Input, type InputProps } from './Input';
@@ -36,6 +36,8 @@ export * from './Fab/types';
36
36
  export { default as Filters } from './Filters';
37
37
  export { default as Form } from './Form';
38
38
  export * from './Form/types';
39
+ export { default as Group } from './Group';
40
+ // export * from './Form/types';
39
41
  export { default as Icon } from './Icon';
40
42
  export { default as Image } from './Image';
41
43
  export { default as Input } from './Input';
@@ -63,7 +63,7 @@ export declare const bindKey: (key: KeyCode, fun: () => void, element?: HTMLElem
63
63
  export declare const camelCase: (str: string, ucf?: boolean) => string;
64
64
  export declare const camelCaseToDash: (str: string) => string;
65
65
  export declare const pluralize: (word: string, count: number) => string;
66
- export declare const addPropsToChildren: (children: ReactNode, conditions: (child: ReactElement<any>) => boolean, newProps: object) => ReactNode;
66
+ export declare const addPropsToChildren: (children: ReactNode, conditions: (child: ReactElement<any>) => boolean, getProps: (index: number, element: ReactElement<any>) => object) => ReactNode;
67
67
  export declare const getPositionAroundElement: (x: number, y: number, distance: number, childCount: number) => {
68
68
  x: number;
69
69
  y: number;
@@ -395,16 +395,17 @@ export const camelCase = (str, ucf = false) => {
395
395
  };
396
396
  export const camelCaseToDash = (str) => str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
397
397
  export const pluralize = (word, count) => `${word}${count !== 1 ? 's' : ''}`;
398
- export const addPropsToChildren = (children, conditions, newProps) => {
398
+ export const addPropsToChildren = (children, conditions, getProps) => {
399
+ let i = 0;
399
400
  return Children.map(children, (child) => {
400
401
  if (isValidElement(child)) {
401
402
  const element = child;
402
403
  const newChild = conditions(element)
403
- ? cloneElement(element, { ...newProps })
404
+ ? cloneElement(element, getProps(i++, element))
404
405
  : element;
405
406
  if (element.props.children) {
406
407
  return cloneElement(newChild, {
407
- children: addPropsToChildren(element.props.children, conditions, newProps)
408
+ children: addPropsToChildren(element.props.children, conditions, getProps)
408
409
  });
409
410
  }
410
411
  return newChild;
@@ -57,6 +57,7 @@ const useBase = (props, ref) => {
57
57
  // { transition: `all ${duration || `0.2`}s ${getAnimationCurve(curve)} ${delay || 0}s` }
58
58
  const _curve = getAnimationCurve(curve);
59
59
  const _transitionList = [];
60
+ const _willChangeList = [];
60
61
  Object.keys(_style).forEach(ck => {
61
62
  let prop = ck;
62
63
  let _subTrans = ck;
@@ -68,11 +69,15 @@ const useBase = (props, ref) => {
68
69
  else if (cssTransformKeys.includes(prop)) {
69
70
  _subTrans = `transform`;
70
71
  }
72
+ // will-change: ${_subTrans};
71
73
  const _newTransition = `${_subTrans} ${duration || `0.2`}s ${_curve} ${delay || 0}s`;
74
+ if (!_willChangeList.includes(_subTrans))
75
+ _willChangeList.push(_subTrans);
72
76
  if (!_transitionList.includes(_newTransition))
73
77
  _transitionList.push(_newTransition);
74
78
  });
75
79
  _transition.transition = _transitionList.join(`, `);
80
+ _transition.willChange = _willChangeList.join(`, `);
76
81
  }
77
82
  // // console.log(_style, _transition)
78
83
  const is = typeof window !== "undefined";
@@ -98,7 +103,7 @@ const useBase = (props, ref) => {
98
103
  };
99
104
  }
100
105
  }
101
- const handleScroll = () => {
106
+ const handleScrollParallax = () => {
102
107
  if (fx && fx.scroll && typeof window !== 'undefined') {
103
108
  const now = performance.now();
104
109
  const dt = (now - lastTime.current) / 1000;
@@ -110,22 +115,58 @@ const useBase = (props, ref) => {
110
115
  if (ref?.current) {
111
116
  const translateX = x ? currentScroll.current.x * x * (multiplier || xMultiplier || .25) : 0;
112
117
  const translateY = y ? currentScroll.current.y * y * (multiplier || yMultiplier || .25) : 0;
113
- // ref.current.style.setProperty(`--scroll-y`, `${translateY}px`)
114
- // transform = `translate3d(${translateX}px, ${translateY}px, 0)`.trim()
115
118
  animateCSSVar(ref, "--scroll-y", translateY);
119
+ animateCSSVar(ref, "--scroll-x", translateX);
116
120
  }
117
121
  }
118
122
  };
123
+ const handleMouseParallax = (e) => {
124
+ if (!fx || !fx.mouse || typeof window === 'undefined')
125
+ return;
126
+ const now = performance.now();
127
+ const dt = (now - lastTime.current) / 1000;
128
+ lastTime.current = now;
129
+ const { lerpFactor, x, y, multiplier, xMultiplier, yMultiplier } = fx.mouse;
130
+ // Normalize mouse position to center (0) range (-1 to 1)
131
+ const vw = window.innerWidth;
132
+ const vh = window.innerHeight;
133
+ const nx = (e.clientX - vw / 2) / (vw / 2); // -1 to 1
134
+ const ny = (e.clientY - vh / 2) / (vh / 2); // -1 to 1
135
+ const dx = nx - currentScroll.current.x;
136
+ const dy = ny - currentScroll.current.y;
137
+ currentScroll.current.x += dx * (lerpFactor || 0.1);
138
+ currentScroll.current.y += dy * (lerpFactor || 0.1);
139
+ if (ref?.current) {
140
+ const translateX = x ? currentScroll.current.x * (multiplier || xMultiplier || 20) : 0;
141
+ const translateY = y ? currentScroll.current.y * (multiplier || yMultiplier || 20) : 0;
142
+ animateCSSVar(ref, '--mouse-x', translateX);
143
+ animateCSSVar(ref, '--mouse-y', translateY);
144
+ }
145
+ };
119
146
  useEffect(() => {
120
- if (fx && fx.scroll && typeof window !== 'undefined') {
121
- if (ref) {
122
- ref.current.style.transform = `translate3d(0px, var(--scroll-y), 0)`;
123
- ref.current.style.transition = `transform 0.1s ${fx.curve ? getAnimationCurve(fx.curve) : `var(--spring)`}`;
147
+ if (typeof window !== 'undefined') {
148
+ if (fx && fx.scroll) {
149
+ if (ref) {
150
+ ref.current.style.willChange = `transform`;
151
+ ref.current.style.transform = `translate3d(0px, var(--scroll-y), 0)`;
152
+ ref.current.style.transition = `transform 0.1s ${fx.curve ? getAnimationCurve(fx.curve) : `var(--spring)`}`;
153
+ }
154
+ window.addEventListener('scroll', handleScrollParallax, { passive: true });
155
+ return () => {
156
+ window.removeEventListener('scroll', handleScrollParallax);
157
+ };
158
+ }
159
+ if (fx && fx.mouse) {
160
+ if (ref) {
161
+ ref.current.style.willChange = `transform`;
162
+ ref.current.style.transform = `translate3d(0px, var(--mouse-y), 0)`;
163
+ ref.current.style.transition = `transform 0.1s ${fx.curve ? getAnimationCurve(fx.curve) : `var(--spring)`}`;
164
+ }
165
+ window.document.addEventListener('mousemove', handleMouseParallax, { passive: true });
166
+ return () => {
167
+ window.removeEventListener('mousemove', handleMouseParallax);
168
+ };
124
169
  }
125
- window.addEventListener('scroll', handleScroll, { passive: true });
126
- return () => {
127
- window.removeEventListener('scroll', handleScroll);
128
- };
129
170
  }
130
171
  }, [ref]);
131
172
  return {
@@ -1,7 +1,7 @@
1
1
  export interface ScrollBreakpoint {
2
2
  [key: number]: () => void;
3
3
  }
4
- declare const useScrollbar: (breakpoints?: ScrollBreakpoint) => {
4
+ declare const useScrollbar: (speed: number, breakpoints?: ScrollBreakpoint) => {
5
5
  rootRef: import("react").RefObject<HTMLDivElement | null>;
6
6
  containerRef: import("react").RefObject<HTMLDivElement | null>;
7
7
  thumbY: import("react").RefObject<HTMLDivElement | null>;
@@ -1,11 +1,12 @@
1
1
  "use client";
2
- import { useCallback, useEffect, useRef } from "react";
2
+ import { useCallback, useEffect, useMemo, useRef } from "react";
3
3
  import { useMutationObserver } from "..";
4
- const useScrollbar = (breakpoints = {}) => {
4
+ const useScrollbar = (speed, breakpoints = {}) => {
5
5
  const rootRef = useRef(null);
6
6
  const containerRef = useRef(null);
7
7
  const thumbY = useRef(null);
8
8
  const thumbX = useRef(null);
9
+ const SCROLL_SPEED = useMemo(() => speed ?? 1, [speed]); // default to 1x multiplier
9
10
  const isDraggingY = useRef(false);
10
11
  const isDraggingX = useRef(false);
11
12
  const dragStartX = useRef(0);
@@ -52,7 +53,13 @@ const useScrollbar = (breakpoints = {}) => {
52
53
  });
53
54
  };
54
55
  const handleScroll = useCallback(() => {
55
- if (!containerRef.current)
56
+ if (!containerRef.current
57
+ // ||
58
+ // (
59
+ // typeof window !== `undefined` &&
60
+ // window.document.body.classList.contains(`--no-scroll`)
61
+ // )
62
+ )
56
63
  return;
57
64
  const { scrollTop, scrollHeight, clientHeight, scrollLeft, scrollWidth, clientWidth } = containerRef.current;
58
65
  const scrollPercentY = (scrollTop / (scrollHeight - clientHeight)) * 100;
@@ -122,13 +129,13 @@ const useScrollbar = (breakpoints = {}) => {
122
129
  const maxScrollY = scrollHeight - clientHeight;
123
130
  let newScrollTop = scrollTop + e.deltaY;
124
131
  newScrollTop = Math.max(0, Math.min(newScrollTop, maxScrollY));
125
- containerRef.current.scrollTop = newScrollTop;
132
+ containerRef.current.scrollTop = newScrollTop * SCROLL_SPEED;
126
133
  }
127
134
  if (Math.abs(e.deltaX) > Math.abs(e.deltaY)) {
128
135
  const maxScrollX = scrollWidth - clientWidth;
129
136
  let newScrollLeft = scrollLeft + e.deltaX;
130
137
  newScrollLeft = Math.max(0, Math.min(newScrollLeft, maxScrollX));
131
- containerRef.current.scrollLeft = newScrollLeft;
138
+ containerRef.current.scrollLeft = newScrollLeft * SCROLL_SPEED;
132
139
  }
133
140
  const scrollPercentY = (containerRef.current.scrollTop / (containerRef.current.scrollHeight - clientHeight)) * 100;
134
141
  const scrollPercentX = (containerRef.current.scrollLeft / (containerRef.current.scrollWidth - clientWidth)) * 100;
@@ -1,6 +1,6 @@
1
1
  import { dynamicObject } from ".";
2
2
  import { SKELETON, TRANSITION_CURVES, TRANSITIONS } from "./enums";
3
- export interface scrollEffectProps {
3
+ export interface parallaxEffectProps {
4
4
  lerpFactor?: number;
5
5
  x?: number;
6
6
  y?: number;
@@ -34,7 +34,8 @@ export interface animationProps {
34
34
  delay?: number;
35
35
  /** Easing curve applied to the animation, as a string or {@link TRANSITION_CURVES} */
36
36
  curve?: string | TRANSITION_CURVES;
37
- scroll?: scrollEffectProps;
37
+ scroll?: parallaxEffectProps;
38
+ mouse?: parallaxEffectProps;
38
39
  }
39
40
  /**
40
41
  * `Skeleton` defines properties for a skeleton loader, used to indicate