@zuzjs/ui 0.8.9 → 0.9.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/dist/cjs/comps/Box/index.js +5 -16
- package/dist/cjs/comps/Form/index.js +7 -2
- package/dist/cjs/comps/Password/index.js +1 -1
- package/dist/cjs/comps/ProgressBar/index.js +0 -1
- package/dist/cjs/comps/Segmented/index.d.ts +2 -2
- package/dist/cjs/comps/Segmented/index.js +21 -7
- package/dist/cjs/comps/Segmented/types.d.ts +3 -0
- package/dist/cjs/comps/Table/index.d.ts +2 -2
- package/dist/cjs/comps/Table/index.js +27 -6
- package/dist/cjs/comps/Table/types.d.ts +5 -1
- package/dist/cjs/funs/css.js +0 -7
- package/dist/cjs/hooks/index.d.ts +1 -0
- package/dist/cjs/hooks/index.js +1 -0
- package/dist/cjs/hooks/useBase.d.ts +2 -2
- package/dist/cjs/hooks/useBase.js +37 -20
- package/dist/cjs/hooks/useScrollPhysics.d.ts +22 -0
- package/dist/cjs/hooks/useScrollPhysics.js +69 -0
- package/dist/cjs/types/enums.d.ts +2 -1
- package/dist/cjs/types/enums.js +1 -0
- package/dist/cjs/types/index.d.ts +1 -0
- package/dist/cjs/types/interfaces.d.ts +9 -0
- package/dist/css/styles.css +1 -1
- package/dist/esm/comps/Box/index.js +5 -16
- package/dist/esm/comps/Form/index.js +7 -2
- package/dist/esm/comps/Password/index.js +1 -1
- package/dist/esm/comps/ProgressBar/index.js +0 -1
- package/dist/esm/comps/Segmented/index.d.ts +2 -2
- package/dist/esm/comps/Segmented/index.js +21 -7
- package/dist/esm/comps/Segmented/types.d.ts +3 -0
- package/dist/esm/comps/Table/index.d.ts +2 -2
- package/dist/esm/comps/Table/index.js +27 -6
- package/dist/esm/comps/Table/types.d.ts +5 -1
- package/dist/esm/funs/css.js +0 -7
- package/dist/esm/hooks/index.d.ts +1 -0
- package/dist/esm/hooks/index.js +1 -0
- package/dist/esm/hooks/useBase.d.ts +2 -2
- package/dist/esm/hooks/useBase.js +37 -20
- package/dist/esm/hooks/useScrollPhysics.d.ts +22 -0
- package/dist/esm/hooks/useScrollPhysics.js +69 -0
- package/dist/esm/types/enums.d.ts +2 -1
- package/dist/esm/types/enums.js +1 -0
- package/dist/esm/types/index.d.ts +1 -0
- package/dist/esm/types/interfaces.d.ts +9 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
package/dist/esm/funs/css.js
CHANGED
|
@@ -899,12 +899,6 @@ export const buildWithStyles = (source) => {
|
|
|
899
899
|
for (const _prop in source) {
|
|
900
900
|
let prop = _prop;
|
|
901
901
|
if (prop in cssWithKeys) {
|
|
902
|
-
// console.log(
|
|
903
|
-
// prop,
|
|
904
|
-
// cssTransformKeys.includes(cssWithKeys[prop].toString()),
|
|
905
|
-
// cssFilterKeys.includes(cssWithKeys[prop].toString()),
|
|
906
|
-
// cssWithKeys[prop]
|
|
907
|
-
// )
|
|
908
902
|
if (cssTransformKeys.includes(cssWithKeys[prop].toString())) {
|
|
909
903
|
_transform.push(`${cssWithKeys[prop]}(${source[prop]}${_css.makeUnit(prop, source[prop])})`);
|
|
910
904
|
}
|
|
@@ -931,7 +925,6 @@ export const buildWithStyles = (source) => {
|
|
|
931
925
|
if (_filter.length > 0) {
|
|
932
926
|
_.filter = _filter.join(` `);
|
|
933
927
|
}
|
|
934
|
-
// console.log(_, _transform)
|
|
935
928
|
}
|
|
936
929
|
return _;
|
|
937
930
|
};
|
|
@@ -22,6 +22,7 @@ export { default as useImage } from './useImage';
|
|
|
22
22
|
export { default as useImageCropper } from './useImageCropper';
|
|
23
23
|
export { default as useIntersectionObserver } from './useIntersectionObserver';
|
|
24
24
|
export { default as useScrollbar } from './useScrollbar';
|
|
25
|
+
export { default as useScrollPhysics } from './useScrollPhysics';
|
|
25
26
|
export { default as useSheet } from './useSheet';
|
|
26
27
|
export { default as useShortcuts } from './useShortcuts';
|
|
27
28
|
export { default as useNetworkStatus } from './useNetworkStatus';
|
package/dist/esm/hooks/index.js
CHANGED
|
@@ -23,6 +23,7 @@ export { default as useImage } from './useImage';
|
|
|
23
23
|
export { default as useImageCropper } from './useImageCropper';
|
|
24
24
|
export { default as useIntersectionObserver } from './useIntersectionObserver';
|
|
25
25
|
export { default as useScrollbar } from './useScrollbar';
|
|
26
|
+
export { default as useScrollPhysics } from './useScrollPhysics';
|
|
26
27
|
export { default as useSheet } from './useSheet';
|
|
27
28
|
export { default as useShortcuts } from './useShortcuts';
|
|
28
29
|
export { default as useNetworkStatus } from './useNetworkStatus';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ComponentPropsWithRef, CSSProperties, JSX } from "react";
|
|
1
|
+
import { ComponentPropsWithRef, CSSProperties, JSX, RefObject } from "react";
|
|
2
2
|
import { Props } from "../types";
|
|
3
|
-
declare const useBase: <T extends keyof JSX.IntrinsicElements>(props: Props<T>) => {
|
|
3
|
+
declare const useBase: <T extends keyof JSX.IntrinsicElements>(props: Props<T>, ref?: RefObject<HTMLElement>) => {
|
|
4
4
|
style: CSSProperties;
|
|
5
5
|
className: string;
|
|
6
6
|
rest: ComponentPropsWithRef<T>;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { animateCSSVar } from "@zuzjs/core";
|
|
2
|
+
import { useEffect, useRef } from "react";
|
|
1
3
|
import { cleanProps, css } from "../funs";
|
|
2
4
|
import { buildWithStyles, getAnimationCurve, getAnimationTransition } from "../funs/css";
|
|
3
5
|
import { cssFilterKeys, cssProps, cssTransformKeys, cssWithKeys } from "../funs/stylesheet";
|
|
@@ -28,13 +30,15 @@ const buildSkeletonStyle = (s) => {
|
|
|
28
30
|
}
|
|
29
31
|
return style;
|
|
30
32
|
};
|
|
31
|
-
const useBase = (props) => {
|
|
32
|
-
const { as, fx, animate, transition: autoTransition, skeleton, className, shimmer, propsToRemove, draggable, dragOptions, ...rest } = props || {};
|
|
33
|
+
const useBase = (props, ref) => {
|
|
34
|
+
const { as, fx, animate, timeline, transition: autoTransition, skeleton, className, shimmer, propsToRemove, draggable, dragOptions, ...rest } = props || {};
|
|
35
|
+
const currentScroll = useRef({ x: 0, y: 0 });
|
|
36
|
+
const lastTime = useRef(performance.now());
|
|
33
37
|
let cx = [];
|
|
34
38
|
if (as) {
|
|
35
39
|
cx = css().Build(`string` == typeof as ? as : as.join(` `)).cx;
|
|
36
40
|
}
|
|
37
|
-
const { transition, from, to, exit, when, duration, delay, curve } = autoTransition ? {
|
|
41
|
+
const { transition, from, to, exit, when, duration, delay, curve, scroll } = autoTransition ? {
|
|
38
42
|
transition: autoTransition,
|
|
39
43
|
duration: 0.3
|
|
40
44
|
} : fx || animate || {};
|
|
@@ -48,23 +52,6 @@ const useBase = (props) => {
|
|
|
48
52
|
else {
|
|
49
53
|
_style = transition ? getAnimationTransition(transition, false, true) : from || {};
|
|
50
54
|
}
|
|
51
|
-
// Track previous value of 'when'
|
|
52
|
-
// const prevWhenRef = useRef<boolean | undefined>(when);
|
|
53
|
-
// if (undefined === when) {
|
|
54
|
-
// _style = transition ? getAnimationTransition(transition, true) : { ...from, ...to };
|
|
55
|
-
// } else if (true === when) {
|
|
56
|
-
// _style = transition ? getAnimationTransition(transition, false) : { ...(to || {}) };
|
|
57
|
-
// } else {
|
|
58
|
-
// // Check if exit style should be applied
|
|
59
|
-
// const wasTrue = prevWhenRef.current === true;
|
|
60
|
-
// if (wasTrue && exit) {
|
|
61
|
-
// _style = { ...(exit || {}) };
|
|
62
|
-
// } else {
|
|
63
|
-
// _style = transition ? getAnimationTransition(transition, false, true) : from || {};
|
|
64
|
-
// }
|
|
65
|
-
// }
|
|
66
|
-
// // Update previous value for next render
|
|
67
|
-
// prevWhenRef.current = when;
|
|
68
55
|
const _transition = {};
|
|
69
56
|
if (transition || (from && to)) {
|
|
70
57
|
// { transition: `all ${duration || `0.2`}s ${getAnimationCurve(curve)} ${delay || 0}s` }
|
|
@@ -111,6 +98,36 @@ const useBase = (props) => {
|
|
|
111
98
|
};
|
|
112
99
|
}
|
|
113
100
|
}
|
|
101
|
+
const handleScroll = () => {
|
|
102
|
+
if (fx && fx.scroll && typeof window !== 'undefined') {
|
|
103
|
+
const now = performance.now();
|
|
104
|
+
const dt = (now - lastTime.current) / 1000;
|
|
105
|
+
lastTime.current = now;
|
|
106
|
+
const { lerpFactor, x, y, multiplier, xMultiplier, yMultiplier } = fx.scroll;
|
|
107
|
+
const delta = window.scrollY - currentScroll.current.y;
|
|
108
|
+
const velocity = delta / dt;
|
|
109
|
+
currentScroll.current.y += delta * (lerpFactor || .1);
|
|
110
|
+
if (ref?.current) {
|
|
111
|
+
const translateX = x ? currentScroll.current.x * x * (multiplier || xMultiplier || .25) : 0;
|
|
112
|
+
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
|
+
animateCSSVar(ref, "--scroll-y", translateY);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
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)`}`;
|
|
124
|
+
}
|
|
125
|
+
window.addEventListener('scroll', handleScroll, { passive: true });
|
|
126
|
+
return () => {
|
|
127
|
+
window.removeEventListener('scroll', handleScroll);
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
}, [ref]);
|
|
114
131
|
return {
|
|
115
132
|
style: {
|
|
116
133
|
...buildWithStyles(_style),
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
type ScrollPhysicsOptions = {
|
|
3
|
+
lerpFactor?: number;
|
|
4
|
+
x?: number;
|
|
5
|
+
y?: number;
|
|
6
|
+
xMultiplier?: number;
|
|
7
|
+
yMultiplier?: number;
|
|
8
|
+
scale?: {
|
|
9
|
+
min: number;
|
|
10
|
+
max: number;
|
|
11
|
+
factor: number;
|
|
12
|
+
};
|
|
13
|
+
rotate?: {
|
|
14
|
+
direction?: 1 | -1;
|
|
15
|
+
multiplier?: number;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
declare const useScrollPhysics: (ref: RefObject<HTMLElement>, options: ScrollPhysicsOptions) => {
|
|
19
|
+
position: RefObject<number>;
|
|
20
|
+
velocity: RefObject<number>;
|
|
21
|
+
};
|
|
22
|
+
export default useScrollPhysics;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { clamp } from '@zuzjs/core';
|
|
2
|
+
import { useEffect, useRef } from 'react';
|
|
3
|
+
const useScrollPhysics = (ref, options) => {
|
|
4
|
+
const { lerpFactor = 0.1, x, y, xMultiplier = 0.25, yMultiplier = 0.25, scale, rotate, } = options;
|
|
5
|
+
const position = useRef(0);
|
|
6
|
+
const velocity = useRef(0);
|
|
7
|
+
const current = useRef(0);
|
|
8
|
+
const target = useRef(0);
|
|
9
|
+
const lastTime = useRef(performance.now());
|
|
10
|
+
const raf = useRef(null);
|
|
11
|
+
const isRunning = useRef(false);
|
|
12
|
+
const smoothedVelocity = useRef(0);
|
|
13
|
+
const threshold = 0.2; // minimum delta to trigger animation
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (typeof window === 'undefined')
|
|
16
|
+
return;
|
|
17
|
+
const tick = () => {
|
|
18
|
+
const now = performance.now();
|
|
19
|
+
const dt = (now - lastTime.current) / 1000;
|
|
20
|
+
lastTime.current = now;
|
|
21
|
+
const delta = target.current - current.current;
|
|
22
|
+
const v = delta / dt;
|
|
23
|
+
// Update position & velocity
|
|
24
|
+
current.current += delta * lerpFactor;
|
|
25
|
+
position.current = current.current;
|
|
26
|
+
velocity.current = v;
|
|
27
|
+
smoothedVelocity.current += (v - smoothedVelocity.current) * lerpFactor;
|
|
28
|
+
// Apply transform
|
|
29
|
+
if (ref.current) {
|
|
30
|
+
const translateX = x ? position.current * x * xMultiplier : 0;
|
|
31
|
+
const translateY = y ? position.current * y * yMultiplier : 0;
|
|
32
|
+
const scaleValue = scale
|
|
33
|
+
? clamp(scale.max - Math.abs(smoothedVelocity.current) * scale.factor, scale.min, scale.max) : 1;
|
|
34
|
+
const rotateValue = rotate
|
|
35
|
+
? velocity.current * (rotate.multiplier ?? 1) * (rotate.direction ?? 1)
|
|
36
|
+
: 0;
|
|
37
|
+
ref.current.style.transform = `
|
|
38
|
+
translate3d(${translateX}px, ${translateY}px, 0)
|
|
39
|
+
scale(${scaleValue})
|
|
40
|
+
rotate(${rotateValue}deg)
|
|
41
|
+
`.trim();
|
|
42
|
+
}
|
|
43
|
+
// If still moving, continue animating
|
|
44
|
+
if (Math.abs(delta) > threshold || Math.abs(v) > threshold) {
|
|
45
|
+
raf.current = requestAnimationFrame(tick);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
isRunning.current = false;
|
|
49
|
+
raf.current = null;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const handleScroll = () => {
|
|
53
|
+
target.current = window.scrollY;
|
|
54
|
+
if (!isRunning.current) {
|
|
55
|
+
lastTime.current = performance.now();
|
|
56
|
+
raf.current = requestAnimationFrame(tick);
|
|
57
|
+
isRunning.current = true;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
window.addEventListener('scroll', handleScroll, { passive: true });
|
|
61
|
+
return () => {
|
|
62
|
+
window.removeEventListener('scroll', handleScroll);
|
|
63
|
+
if (raf.current)
|
|
64
|
+
cancelAnimationFrame(raf.current);
|
|
65
|
+
};
|
|
66
|
+
}, [lerpFactor, x, y, xMultiplier, yMultiplier, scale, rotate]);
|
|
67
|
+
return { position, velocity };
|
|
68
|
+
};
|
|
69
|
+
export default useScrollPhysics;
|
package/dist/esm/types/enums.js
CHANGED
|
@@ -24,6 +24,7 @@ export var FORMVALIDATION;
|
|
|
24
24
|
FORMVALIDATION["Password"] = "PASSWORD";
|
|
25
25
|
FORMVALIDATION["MatchField"] = "MATCHFIELD";
|
|
26
26
|
FORMVALIDATION["Pattern"] = "*";
|
|
27
|
+
FORMVALIDATION["GreaterThan"] = "GREATER_THAN";
|
|
27
28
|
})(FORMVALIDATION || (FORMVALIDATION = {}));
|
|
28
29
|
export var SHEET;
|
|
29
30
|
(function (SHEET) {
|
|
@@ -48,6 +48,7 @@ export interface ZuzProps {
|
|
|
48
48
|
animate?: animationProps;
|
|
49
49
|
/** Animation configuration using {@link animationProps} */
|
|
50
50
|
fx?: animationProps;
|
|
51
|
+
timeline?: animationProps[];
|
|
51
52
|
transition?: TRANSITIONS;
|
|
52
53
|
/** Skeleton placeholder configuration using {@link Skeleton} */
|
|
53
54
|
skeleton?: Skeleton;
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { dynamicObject } from ".";
|
|
2
2
|
import { SKELETON, TRANSITION_CURVES, TRANSITIONS } from "./enums";
|
|
3
|
+
export interface scrollEffectProps {
|
|
4
|
+
lerpFactor?: number;
|
|
5
|
+
x?: number;
|
|
6
|
+
y?: number;
|
|
7
|
+
multiplier?: number;
|
|
8
|
+
xMultiplier?: number;
|
|
9
|
+
yMultiplier?: number;
|
|
10
|
+
}
|
|
3
11
|
/**
|
|
4
12
|
* `animationProps` defines the properties to control animation effects
|
|
5
13
|
* applied to elements. Supports transitions with timing configurations.
|
|
@@ -26,6 +34,7 @@ export interface animationProps {
|
|
|
26
34
|
delay?: number;
|
|
27
35
|
/** Easing curve applied to the animation, as a string or {@link TRANSITION_CURVES} */
|
|
28
36
|
curve?: string | TRANSITION_CURVES;
|
|
37
|
+
scroll?: scrollEffectProps;
|
|
29
38
|
}
|
|
30
39
|
/**
|
|
31
40
|
* `Skeleton` defines properties for a skeleton loader, used to indicate
|