@react-xp/aeiou 0.1.0-beta.12 → 0.1.0-beta.13
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/components/a/a.native.js +4 -6
- package/dist/cjs/components/a/a.web.js +4 -6
- package/dist/cjs/components/e/e.native.js +3 -12
- package/dist/cjs/components/e/e.web.js +3 -7
- package/dist/cjs/components/l/l.web.js +3 -7
- package/dist/cjs/components/t/t.native.js +3 -6
- package/dist/cjs/components/t/t.web.js +3 -6
- package/dist/cjs/hooks/index.js +0 -2
- package/dist/cjs/hooks/index.native.js +0 -2
- package/dist/cjs/hooks/index.web.js +0 -2
- package/dist/cjs/hooks/useInteractiveState/useInteractiveState.native.js +65 -5
- package/dist/cjs/hooks/useInteractiveState/useInteractiveState.web.js +62 -21
- package/dist/esm/components/a/a.native.js +5 -7
- package/dist/esm/components/a/a.web.js +5 -7
- package/dist/esm/components/e/e.native.js +4 -13
- package/dist/esm/components/e/e.web.js +4 -8
- package/dist/esm/components/l/l.web.js +4 -8
- package/dist/esm/components/t/t.native.js +4 -7
- package/dist/esm/components/t/t.web.js +4 -7
- package/dist/esm/hooks/index.js +0 -2
- package/dist/esm/hooks/index.native.js +0 -2
- package/dist/esm/hooks/index.web.js +0 -2
- package/dist/esm/hooks/useInteractiveState/useInteractiveState.native.js +66 -6
- package/dist/esm/hooks/useInteractiveState/useInteractiveState.web.js +62 -21
- package/dist/native/cjs/components/a/a.native.js +4 -6
- package/dist/native/cjs/components/a/a.web.js +4 -6
- package/dist/native/cjs/components/e/e.native.js +3 -12
- package/dist/native/cjs/components/e/e.web.js +3 -7
- package/dist/native/cjs/components/l/l.web.js +3 -7
- package/dist/native/cjs/components/t/t.native.js +3 -6
- package/dist/native/cjs/components/t/t.web.js +3 -6
- package/dist/native/cjs/hooks/index.js +0 -2
- package/dist/native/cjs/hooks/index.native.js +0 -2
- package/dist/native/cjs/hooks/index.web.js +0 -2
- package/dist/native/cjs/hooks/useInteractiveState/useInteractiveState.native.js +65 -5
- package/dist/native/cjs/hooks/useInteractiveState/useInteractiveState.web.js +62 -21
- package/dist/native/esm/components/a/a.native.js +5 -7
- package/dist/native/esm/components/a/a.web.js +5 -7
- package/dist/native/esm/components/e/e.native.js +4 -13
- package/dist/native/esm/components/e/e.web.js +4 -8
- package/dist/native/esm/components/l/l.web.js +4 -8
- package/dist/native/esm/components/t/t.native.js +4 -7
- package/dist/native/esm/components/t/t.web.js +4 -7
- package/dist/native/esm/hooks/index.js +0 -2
- package/dist/native/esm/hooks/index.native.js +0 -2
- package/dist/native/esm/hooks/index.web.js +0 -2
- package/dist/native/esm/hooks/useInteractiveState/useInteractiveState.native.js +66 -6
- package/dist/native/esm/hooks/useInteractiveState/useInteractiveState.web.js +62 -21
- package/dist/native/tsconfig.native.cjs.tsbuildinfo +1 -1
- package/dist/native/tsconfig.native.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/components/a/a.native.d.ts +1 -1
- package/dist/types/components/a/a.native.d.ts.map +1 -1
- package/dist/types/components/a/a.web.d.ts +1 -1
- package/dist/types/components/a/a.web.d.ts.map +1 -1
- package/dist/types/components/e/e.native.d.ts +1 -1
- package/dist/types/components/e/e.native.d.ts.map +1 -1
- package/dist/types/components/e/e.web.d.ts +1 -1
- package/dist/types/components/e/e.web.d.ts.map +1 -1
- package/dist/types/components/i/useIUtils.d.ts +2 -2
- package/dist/types/components/l/l.web.d.ts +1 -1
- package/dist/types/components/l/l.web.d.ts.map +1 -1
- package/dist/types/components/t/t.native.d.ts +1 -1
- package/dist/types/components/t/t.native.d.ts.map +1 -1
- package/dist/types/components/t/t.web.d.ts +1 -1
- package/dist/types/components/t/t.web.d.ts.map +1 -1
- package/dist/types/hooks/index.d.ts +0 -2
- package/dist/types/hooks/index.d.ts.map +1 -1
- package/dist/types/hooks/index.native.d.ts +0 -2
- package/dist/types/hooks/index.native.d.ts.map +1 -1
- package/dist/types/hooks/index.web.d.ts +0 -2
- package/dist/types/hooks/index.web.d.ts.map +1 -1
- package/dist/types/hooks/useInteractiveState/useInteractiveState.native.d.ts +13 -5
- package/dist/types/hooks/useInteractiveState/useInteractiveState.native.d.ts.map +1 -1
- package/dist/types/hooks/useInteractiveState/useInteractiveState.types.d.ts +2 -2
- package/dist/types/hooks/useInteractiveState/useInteractiveState.types.d.ts.map +1 -1
- package/dist/types/hooks/useInteractiveState/useInteractiveState.web.d.ts +10 -7
- package/dist/types/hooks/useInteractiveState/useInteractiveState.web.d.ts.map +1 -1
- package/dist/types/types/base.d.ts +14 -4
- package/dist/types/types/base.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/cjs/hooks/useAction/types.js +0 -2
- package/dist/cjs/hooks/useAction/useAction.native.js +0 -18
- package/dist/cjs/hooks/useAction/useAction.web.js +0 -21
- package/dist/cjs/hooks/useOnHoverOrPress.js +0 -21
- package/dist/esm/hooks/useAction/types.js +0 -1
- package/dist/esm/hooks/useAction/useAction.native.js +0 -14
- package/dist/esm/hooks/useAction/useAction.web.js +0 -17
- package/dist/esm/hooks/useOnHoverOrPress.js +0 -17
- package/dist/native/cjs/hooks/useAction/types.js +0 -2
- package/dist/native/cjs/hooks/useAction/useAction.native.js +0 -18
- package/dist/native/cjs/hooks/useAction/useAction.web.js +0 -21
- package/dist/native/cjs/hooks/useOnHoverOrPress.js +0 -21
- package/dist/native/esm/hooks/useAction/types.js +0 -1
- package/dist/native/esm/hooks/useAction/useAction.native.js +0 -14
- package/dist/native/esm/hooks/useAction/useAction.web.js +0 -17
- package/dist/native/esm/hooks/useOnHoverOrPress.js +0 -17
- package/dist/types/hooks/useAction/types.d.ts +0 -7
- package/dist/types/hooks/useAction/types.d.ts.map +0 -1
- package/dist/types/hooks/useAction/useAction.native.d.ts +0 -5
- package/dist/types/hooks/useAction/useAction.native.d.ts.map +0 -1
- package/dist/types/hooks/useAction/useAction.web.d.ts +0 -5
- package/dist/types/hooks/useAction/useAction.web.d.ts.map +0 -1
- package/dist/types/hooks/useOnHoverOrPress.d.ts +0 -12
- package/dist/types/hooks/useOnHoverOrPress.d.ts.map +0 -1
|
@@ -6,12 +6,10 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
6
6
|
const react_native_1 = require("react-native");
|
|
7
7
|
const index_native_1 = require("../../hooks/index.native");
|
|
8
8
|
const index_native_2 = require("../e/index.native");
|
|
9
|
-
function A({ className, children,
|
|
9
|
+
function A({ accessibilityLabel, accessibilityRole, accessibilityState, className, children, loading, disabled, ref, style, ...rest }) {
|
|
10
10
|
const cn = (0, index_native_1.useCn)();
|
|
11
|
-
const {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
});
|
|
15
|
-
return ((0, jsx_runtime_1.jsx)(react_native_1.Pressable, { ref: ref, onPress: onAction, disabled: disabled, children: (0, jsx_runtime_1.jsx)(index_native_2.E, { className: cn(disabled && 'opacity-60', className), style: style, ...rest, children: children }) }));
|
|
11
|
+
const { eventHandlers } = (0, index_native_1.useInteractiveState)({ ...rest, disabled });
|
|
12
|
+
const isDisabled = Boolean(disabled || loading);
|
|
13
|
+
return ((0, jsx_runtime_1.jsx)(react_native_1.Pressable, { ref: ref, disabled: isDisabled, accessibilityLabel: accessibilityLabel, accessibilityRole: accessibilityRole, accessibilityState: accessibilityState, ...eventHandlers, children: (0, jsx_runtime_1.jsx)(index_native_2.E, { className: cn(disabled && 'opacity-60', className), style: style, ...rest, children: children }) }));
|
|
16
14
|
}
|
|
17
15
|
exports.Action = A;
|
|
@@ -4,12 +4,10 @@ exports.Action = void 0;
|
|
|
4
4
|
exports.A = A;
|
|
5
5
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
6
|
const index_web_1 = require("../../hooks/index.web");
|
|
7
|
-
function A({ className, children,
|
|
7
|
+
function A({ className, children, disabled, loading, ref, style, testID, accessibilityLabel, ...rest }) {
|
|
8
8
|
const cn = (0, index_web_1.useCn)();
|
|
9
|
-
const {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
});
|
|
13
|
-
return ((0, jsx_runtime_1.jsx)("button", { ref: ref, type: "button", disabled: disabled, className: cn('cursor-pointer', disabled && 'opacity-60', className), onClick: onAction, style: style, ...rest, children: children }));
|
|
9
|
+
const { eventHandlers } = (0, index_web_1.useInteractiveState)({ ...rest, disabled });
|
|
10
|
+
const isDisabled = Boolean(disabled || loading);
|
|
11
|
+
return ((0, jsx_runtime_1.jsx)("button", { ref: ref, type: "button", disabled: disabled, className: cn('cursor-pointer', disabled && 'opacity-60', className), style: style, "aria-disabled": isDisabled || undefined, "aria-busy": loading || undefined, "aria-label": accessibilityLabel, "data-testid": testID, ...rest, ...eventHandlers, children: children }));
|
|
14
12
|
}
|
|
15
13
|
exports.Action = A;
|
|
@@ -6,18 +6,9 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
6
6
|
const react_native_1 = require("react-native");
|
|
7
7
|
const index_native_1 = require("../../hooks/index.native");
|
|
8
8
|
const index_native_2 = require("../t/index.native");
|
|
9
|
-
function E({ className, children,
|
|
9
|
+
function E({ className, children, ref, style, ...rest }) {
|
|
10
10
|
const cn = (0, index_native_1.useCn)();
|
|
11
|
-
const {
|
|
12
|
-
|
|
13
|
-
onPress,
|
|
14
|
-
});
|
|
15
|
-
const { onPress: onHoverOrPress } = (0, index_native_1.useOnHoverOrPress)({ onIn, onOut });
|
|
16
|
-
const handleOnPress = () => {
|
|
17
|
-
onAction();
|
|
18
|
-
onHoverOrPress();
|
|
19
|
-
return false;
|
|
20
|
-
};
|
|
21
|
-
return ((0, jsx_runtime_1.jsx)(react_native_1.View, { ref: ref, className: cn(className), onStartShouldSetResponder: handleOnPress, style: style, ...rest, children: typeof children === 'string' ? (0, jsx_runtime_1.jsx)(index_native_2.T, { children: children }) : children }));
|
|
11
|
+
const { eventHandlers } = (0, index_native_1.useInteractiveState)(rest);
|
|
12
|
+
return ((0, jsx_runtime_1.jsx)(react_native_1.View, { ref: ref, className: cn(className), style: style, ...rest, ...eventHandlers, children: typeof children === 'string' ? (0, jsx_runtime_1.jsx)(index_native_2.T, { children: children }) : children }));
|
|
22
13
|
}
|
|
23
14
|
exports.Element = E;
|
|
@@ -4,13 +4,9 @@ exports.Element = void 0;
|
|
|
4
4
|
exports.E = E;
|
|
5
5
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
6
|
const index_web_1 = require("../../hooks/index.web");
|
|
7
|
-
function E({ className, children,
|
|
7
|
+
function E({ className, children, ref, style, ...rest }) {
|
|
8
8
|
const cn = (0, index_web_1.useCn)();
|
|
9
|
-
const {
|
|
10
|
-
|
|
11
|
-
onPress,
|
|
12
|
-
});
|
|
13
|
-
const { onMouseEnter, onMouseLeave } = (0, index_web_1.useOnHoverOrPress)({ onIn, onOut });
|
|
14
|
-
return ((0, jsx_runtime_1.jsx)("div", { ref: ref, className: cn(className), onClick: onAction, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, style: style, ...rest, children: children }));
|
|
9
|
+
const { eventHandlers } = (0, index_web_1.useInteractiveState)(rest);
|
|
10
|
+
return ((0, jsx_runtime_1.jsx)("div", { ref: ref, className: cn(className), style: style, ...rest, ...eventHandlers, children: children }));
|
|
15
11
|
}
|
|
16
12
|
exports.Element = E;
|
|
@@ -3,15 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Link = void 0;
|
|
4
4
|
exports.L = L;
|
|
5
5
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
-
const index_native_1 = require("../../hooks/index.native");
|
|
7
6
|
const index_web_1 = require("../../hooks/index.web");
|
|
8
|
-
function L({ className, children, to, href,
|
|
7
|
+
function L({ className, children, to, href, preventDefault, ref, style, ...rest }) {
|
|
9
8
|
const cn = (0, index_web_1.useCn)();
|
|
10
|
-
const {
|
|
11
|
-
onClick,
|
|
12
|
-
onPress,
|
|
13
|
-
});
|
|
9
|
+
const { eventHandlers } = (0, index_web_1.useInteractiveState)(rest);
|
|
14
10
|
const resolvedHref = href ?? to ?? '#';
|
|
15
|
-
return ((0, jsx_runtime_1.jsx)("a", { ref: ref, href: resolvedHref, className: cn('cursor-pointer', className),
|
|
11
|
+
return ((0, jsx_runtime_1.jsx)("a", { ref: ref, href: resolvedHref, className: cn('cursor-pointer', className), style: style, ...rest, ...eventHandlers, children: children }));
|
|
16
12
|
}
|
|
17
13
|
exports.Link = L;
|
|
@@ -5,12 +5,9 @@ exports.T = T;
|
|
|
5
5
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
6
|
const react_native_1 = require("react-native");
|
|
7
7
|
const index_native_1 = require("../../hooks/index.native");
|
|
8
|
-
function T({ className, children,
|
|
8
|
+
function T({ className, children, ref, ...rest }) {
|
|
9
9
|
const cn = (0, index_native_1.useCn)();
|
|
10
|
-
const {
|
|
11
|
-
|
|
12
|
-
onPress,
|
|
13
|
-
});
|
|
14
|
-
return ((0, jsx_runtime_1.jsx)(react_native_1.Text, { ref: ref, className: cn('leading-relaxed', className), onPress: onAction, ...rest, children: children }));
|
|
10
|
+
const { eventHandlers } = (0, index_native_1.useInteractiveState)(rest);
|
|
11
|
+
return ((0, jsx_runtime_1.jsx)(react_native_1.Text, { ref: ref, className: cn('leading-relaxed', className), ...rest, ...eventHandlers, children: children }));
|
|
15
12
|
}
|
|
16
13
|
exports.Text = T;
|
|
@@ -4,13 +4,10 @@ exports.Text = void 0;
|
|
|
4
4
|
exports.T = T;
|
|
5
5
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
6
|
const index_web_1 = require("../../hooks/index.web");
|
|
7
|
-
function T({ className, children, as = 'span',
|
|
7
|
+
function T({ className, children, as = 'span', ref, ...rest }) {
|
|
8
8
|
const cn = (0, index_web_1.useCn)();
|
|
9
|
-
const {
|
|
10
|
-
onClick,
|
|
11
|
-
onPress,
|
|
12
|
-
});
|
|
9
|
+
const { eventHandlers } = (0, index_web_1.useInteractiveState)(rest);
|
|
13
10
|
const Comp = as;
|
|
14
|
-
return ((0, jsx_runtime_1.jsx)(Comp, { ref: ref, className: cn('leading-relaxed', className),
|
|
11
|
+
return ((0, jsx_runtime_1.jsx)(Comp, { ref: ref, className: cn('leading-relaxed', className), ...rest, ...eventHandlers, children: children }));
|
|
15
12
|
}
|
|
16
13
|
exports.Text = T;
|
package/dist/cjs/hooks/index.js
CHANGED
|
@@ -14,9 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./useAction/useAction.web"), exports);
|
|
18
17
|
__exportStar(require("./useCn"), exports);
|
|
19
18
|
__exportStar(require("./useInteractiveState/useInteractiveState.web"), exports);
|
|
20
19
|
__exportStar(require("./useOnChange"), exports);
|
|
21
|
-
__exportStar(require("./useOnHoverOrPress"), exports);
|
|
22
20
|
__exportStar(require("./useProps"), exports);
|
|
@@ -14,9 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./useAction/useAction.native"), exports);
|
|
18
17
|
__exportStar(require("./useCn"), exports);
|
|
19
18
|
__exportStar(require("./useInteractiveState/useInteractiveState.native"), exports);
|
|
20
19
|
__exportStar(require("./useOnChange"), exports);
|
|
21
|
-
__exportStar(require("./useOnHoverOrPress"), exports);
|
|
22
20
|
__exportStar(require("./useProps"), exports);
|
|
@@ -14,9 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./useAction/useAction.web"), exports);
|
|
18
17
|
__exportStar(require("./useCn"), exports);
|
|
19
18
|
__exportStar(require("./useInteractiveState/useInteractiveState.web"), exports);
|
|
20
19
|
__exportStar(require("./useOnChange"), exports);
|
|
21
|
-
__exportStar(require("./useOnHoverOrPress"), exports);
|
|
22
20
|
__exportStar(require("./useProps"), exports);
|
|
@@ -3,29 +3,89 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useInteractiveState = useInteractiveState;
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
function useInteractiveState(options = {}) {
|
|
6
|
-
const { disabled } = options;
|
|
6
|
+
const { disabled, onBlur, onClick, onFocus, onPress, onIn, onOut } = options;
|
|
7
|
+
const [hovered, setHovered] = (0, react_1.useState)(false);
|
|
7
8
|
const [pressed, setPressed] = (0, react_1.useState)(false);
|
|
9
|
+
const [focused, setFocused] = (0, react_1.useState)(false);
|
|
10
|
+
const offOn = (0, react_1.useRef)('off');
|
|
8
11
|
const state = disabled
|
|
9
12
|
? 'disabled'
|
|
10
13
|
: pressed
|
|
11
14
|
? 'pressed'
|
|
12
|
-
:
|
|
15
|
+
: hovered
|
|
16
|
+
? 'hovered'
|
|
17
|
+
: focused
|
|
18
|
+
? 'focused'
|
|
19
|
+
: 'idle';
|
|
13
20
|
const dataAttrs = {
|
|
14
21
|
'data-state': state,
|
|
15
|
-
'data-pressed': pressed ? 'true' : 'false',
|
|
16
22
|
'data-disabled': disabled ? 'true' : 'false',
|
|
23
|
+
'data-focused': focused ? 'true' : 'false',
|
|
24
|
+
'data-hovered': hovered ? 'true' : 'false',
|
|
25
|
+
'data-pressed': pressed ? 'true' : 'false',
|
|
17
26
|
};
|
|
18
27
|
const eventHandlers = {
|
|
28
|
+
onBlur: (e) => {
|
|
29
|
+
if (disabled) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
onBlur?.(e);
|
|
33
|
+
setFocused(false);
|
|
34
|
+
setPressed(false);
|
|
35
|
+
},
|
|
36
|
+
onFocus: (e) => {
|
|
37
|
+
if (disabled) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
onFocus?.(e);
|
|
41
|
+
setFocused(true);
|
|
42
|
+
},
|
|
43
|
+
onIn: (e) => {
|
|
44
|
+
if (disabled) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
console.log('[DEBUG] onIn', typeof onIn, e);
|
|
48
|
+
onIn?.(e);
|
|
49
|
+
},
|
|
50
|
+
onPress: (e) => {
|
|
51
|
+
if (disabled) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if ((onIn || onOut) && offOn.current === 'off') {
|
|
55
|
+
offOn.current = 'on';
|
|
56
|
+
onIn?.(e);
|
|
57
|
+
}
|
|
58
|
+
if ((onIn || onOut) && offOn.current === 'on') {
|
|
59
|
+
offOn.current = 'off';
|
|
60
|
+
onOut?.(e);
|
|
61
|
+
}
|
|
62
|
+
if (onPress) {
|
|
63
|
+
onPress?.(e);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
onClick?.(e);
|
|
67
|
+
},
|
|
19
68
|
onPressIn: (e) => {
|
|
20
|
-
if (disabled)
|
|
69
|
+
if (disabled) {
|
|
21
70
|
return;
|
|
71
|
+
}
|
|
72
|
+
onIn?.(e);
|
|
22
73
|
setPressed(true);
|
|
23
74
|
},
|
|
24
75
|
onPressOut: (e) => {
|
|
25
|
-
if (disabled)
|
|
76
|
+
if (disabled) {
|
|
26
77
|
return;
|
|
78
|
+
}
|
|
79
|
+
onOut?.(e);
|
|
27
80
|
setPressed(false);
|
|
28
81
|
},
|
|
82
|
+
onOut: (e) => {
|
|
83
|
+
if (disabled) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
console.log('[DEBUG] onOut', typeof onOut, e);
|
|
87
|
+
onOut?.(e);
|
|
88
|
+
},
|
|
29
89
|
};
|
|
30
90
|
return { state, dataAttrs, eventHandlers };
|
|
31
91
|
}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useInteractiveState = useInteractiveState;
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
function useInteractiveState(options = {}) {
|
|
6
|
-
const { disabled } = options;
|
|
6
|
+
const { disabled, onBlur, onClick, onPress, onFocus, onIn, onOut } = options;
|
|
7
7
|
const [hovered, setHovered] = (0, react_1.useState)(false);
|
|
8
8
|
const [pressed, setPressed] = (0, react_1.useState)(false);
|
|
9
9
|
const [focused, setFocused] = (0, react_1.useState)(false);
|
|
@@ -18,44 +18,85 @@ function useInteractiveState(options = {}) {
|
|
|
18
18
|
: 'idle';
|
|
19
19
|
const dataAttrs = {
|
|
20
20
|
'data-state': state,
|
|
21
|
+
'data-disabled': disabled ? 'true' : 'false',
|
|
22
|
+
'data-focused': focused ? 'true' : 'false',
|
|
21
23
|
'data-hovered': hovered ? 'true' : 'false',
|
|
22
24
|
'data-pressed': pressed ? 'true' : 'false',
|
|
23
|
-
'data-focused': focused ? 'true' : 'false',
|
|
24
|
-
'data-disabled': disabled ? 'true' : 'false',
|
|
25
25
|
};
|
|
26
26
|
const eventHandlers = {
|
|
27
|
-
|
|
28
|
-
if (disabled)
|
|
27
|
+
onBlur: (e) => {
|
|
28
|
+
if (disabled) {
|
|
29
29
|
return;
|
|
30
|
-
|
|
30
|
+
}
|
|
31
|
+
console.log('[DEBUG] onBlur', typeof onBlur, e);
|
|
32
|
+
onBlur?.(e);
|
|
33
|
+
setFocused(false);
|
|
34
|
+
setPressed(false);
|
|
35
|
+
setHovered(false);
|
|
31
36
|
},
|
|
32
|
-
|
|
33
|
-
if (disabled)
|
|
37
|
+
onClick: (e) => {
|
|
38
|
+
if (disabled) {
|
|
34
39
|
return;
|
|
35
|
-
|
|
36
|
-
|
|
40
|
+
}
|
|
41
|
+
console.log('[DEBUG] onClick', typeof onClick, e);
|
|
42
|
+
if (onClick) {
|
|
43
|
+
onClick?.(e);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
onPress?.(e);
|
|
47
|
+
},
|
|
48
|
+
onFocus: (e) => {
|
|
49
|
+
if (disabled) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
console.log('[DEBUG] onFocus', typeof onFocus, e);
|
|
53
|
+
onFocus?.(e);
|
|
54
|
+
setFocused(true);
|
|
55
|
+
},
|
|
56
|
+
onIn: (e) => {
|
|
57
|
+
if (disabled) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
console.log('[DEBUG] onIn', typeof onIn, e);
|
|
61
|
+
onIn?.(e);
|
|
37
62
|
},
|
|
38
63
|
onMouseDown: (e) => {
|
|
39
|
-
if (disabled || e.button !== 0)
|
|
64
|
+
if (disabled || e.button !== 0) {
|
|
40
65
|
return;
|
|
66
|
+
}
|
|
67
|
+
console.log('[DEBUG] onMouseDown', e);
|
|
41
68
|
setPressed(true);
|
|
42
69
|
},
|
|
43
|
-
|
|
44
|
-
if (disabled)
|
|
70
|
+
onMouseEnter: (e) => {
|
|
71
|
+
if (disabled) {
|
|
45
72
|
return;
|
|
46
|
-
|
|
73
|
+
}
|
|
74
|
+
console.log('[DEBUG] onMouseEnter', typeof onIn, e);
|
|
75
|
+
onIn?.(e);
|
|
76
|
+
setHovered(true);
|
|
47
77
|
},
|
|
48
|
-
|
|
49
|
-
if (disabled)
|
|
78
|
+
onMouseLeave: (e) => {
|
|
79
|
+
if (disabled) {
|
|
50
80
|
return;
|
|
51
|
-
|
|
81
|
+
}
|
|
82
|
+
console.log('[DEBUG] onMouseLeave', typeof onOut, e);
|
|
83
|
+
onOut?.(e);
|
|
84
|
+
setHovered(false);
|
|
85
|
+
setPressed(false);
|
|
52
86
|
},
|
|
53
|
-
|
|
54
|
-
if (disabled)
|
|
87
|
+
onMouseUp: (e) => {
|
|
88
|
+
if (disabled) {
|
|
55
89
|
return;
|
|
56
|
-
|
|
90
|
+
}
|
|
91
|
+
console.log('[DEBUG] onMouseUp', e);
|
|
57
92
|
setPressed(false);
|
|
58
|
-
|
|
93
|
+
},
|
|
94
|
+
onOut: (e) => {
|
|
95
|
+
if (disabled) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
console.log('[DEBUG] onOut', typeof onOut, e);
|
|
99
|
+
onOut?.(e);
|
|
59
100
|
},
|
|
60
101
|
};
|
|
61
102
|
return { state, dataAttrs, eventHandlers };
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Pressable } from 'react-native';
|
|
3
|
-
import {
|
|
3
|
+
import { useCn, useInteractiveState } from '../../hooks/index.native';
|
|
4
4
|
import { E } from '../e/index.native';
|
|
5
|
-
export function A({ className, children,
|
|
5
|
+
export function A({ accessibilityLabel, accessibilityRole, accessibilityState, className, children, loading, disabled, ref, style, ...rest }) {
|
|
6
6
|
const cn = useCn();
|
|
7
|
-
const {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
});
|
|
11
|
-
return (_jsx(Pressable, { ref: ref, onPress: onAction, disabled: disabled, children: _jsx(E, { className: cn(disabled && 'opacity-60', className), style: style, ...rest, children: children }) }));
|
|
7
|
+
const { eventHandlers } = useInteractiveState({ ...rest, disabled });
|
|
8
|
+
const isDisabled = Boolean(disabled || loading);
|
|
9
|
+
return (_jsx(Pressable, { ref: ref, disabled: isDisabled, accessibilityLabel: accessibilityLabel, accessibilityRole: accessibilityRole, accessibilityState: accessibilityState, ...eventHandlers, children: _jsx(E, { className: cn(disabled && 'opacity-60', className), style: style, ...rest, children: children }) }));
|
|
12
10
|
}
|
|
13
11
|
export const Action = A;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
export function A({ className, children,
|
|
2
|
+
import { useCn, useInteractiveState } from '../../hooks/index.web';
|
|
3
|
+
export function A({ className, children, disabled, loading, ref, style, testID, accessibilityLabel, ...rest }) {
|
|
4
4
|
const cn = useCn();
|
|
5
|
-
const {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
});
|
|
9
|
-
return (_jsx("button", { ref: ref, type: "button", disabled: disabled, className: cn('cursor-pointer', disabled && 'opacity-60', className), onClick: onAction, style: style, ...rest, children: children }));
|
|
5
|
+
const { eventHandlers } = useInteractiveState({ ...rest, disabled });
|
|
6
|
+
const isDisabled = Boolean(disabled || loading);
|
|
7
|
+
return (_jsx("button", { ref: ref, type: "button", disabled: disabled, className: cn('cursor-pointer', disabled && 'opacity-60', className), style: style, "aria-disabled": isDisabled || undefined, "aria-busy": loading || undefined, "aria-label": accessibilityLabel, "data-testid": testID, ...rest, ...eventHandlers, children: children }));
|
|
10
8
|
}
|
|
11
9
|
export const Action = A;
|
|
@@ -1,19 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { View } from 'react-native';
|
|
3
|
-
import {
|
|
3
|
+
import { useCn, useInteractiveState } from '../../hooks/index.native';
|
|
4
4
|
import { T } from '../t/index.native';
|
|
5
|
-
export function E({ className, children,
|
|
5
|
+
export function E({ className, children, ref, style, ...rest }) {
|
|
6
6
|
const cn = useCn();
|
|
7
|
-
const {
|
|
8
|
-
|
|
9
|
-
onPress,
|
|
10
|
-
});
|
|
11
|
-
const { onPress: onHoverOrPress } = useOnHoverOrPress({ onIn, onOut });
|
|
12
|
-
const handleOnPress = () => {
|
|
13
|
-
onAction();
|
|
14
|
-
onHoverOrPress();
|
|
15
|
-
return false;
|
|
16
|
-
};
|
|
17
|
-
return (_jsx(View, { ref: ref, className: cn(className), onStartShouldSetResponder: handleOnPress, style: style, ...rest, children: typeof children === 'string' ? _jsx(T, { children: children }) : children }));
|
|
7
|
+
const { eventHandlers } = useInteractiveState(rest);
|
|
8
|
+
return (_jsx(View, { ref: ref, className: cn(className), style: style, ...rest, ...eventHandlers, children: typeof children === 'string' ? _jsx(T, { children: children }) : children }));
|
|
18
9
|
}
|
|
19
10
|
export const Element = E;
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
export function E({ className, children,
|
|
2
|
+
import { useCn, useInteractiveState } from '../../hooks/index.web';
|
|
3
|
+
export function E({ className, children, ref, style, ...rest }) {
|
|
4
4
|
const cn = useCn();
|
|
5
|
-
const {
|
|
6
|
-
|
|
7
|
-
onPress,
|
|
8
|
-
});
|
|
9
|
-
const { onMouseEnter, onMouseLeave } = useOnHoverOrPress({ onIn, onOut });
|
|
10
|
-
return (_jsx("div", { ref: ref, className: cn(className), onClick: onAction, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, style: style, ...rest, children: children }));
|
|
5
|
+
const { eventHandlers } = useInteractiveState(rest);
|
|
6
|
+
return (_jsx("div", { ref: ref, className: cn(className), style: style, ...rest, ...eventHandlers, children: children }));
|
|
11
7
|
}
|
|
12
8
|
export const Element = E;
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
export function L({ className, children, to, href, onClick, onPress, preventDefault, ref, style, ...rest }) {
|
|
2
|
+
import { useCn, useInteractiveState } from '../../hooks/index.web';
|
|
3
|
+
export function L({ className, children, to, href, preventDefault, ref, style, ...rest }) {
|
|
5
4
|
const cn = useCn();
|
|
6
|
-
const {
|
|
7
|
-
onClick,
|
|
8
|
-
onPress,
|
|
9
|
-
});
|
|
5
|
+
const { eventHandlers } = useInteractiveState(rest);
|
|
10
6
|
const resolvedHref = href ?? to ?? '#';
|
|
11
|
-
return (_jsx("a", { ref: ref, href: resolvedHref, className: cn('cursor-pointer', className),
|
|
7
|
+
return (_jsx("a", { ref: ref, href: resolvedHref, className: cn('cursor-pointer', className), style: style, ...rest, ...eventHandlers, children: children }));
|
|
12
8
|
}
|
|
13
9
|
export const Link = L;
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Text as RNText } from 'react-native';
|
|
3
|
-
import {
|
|
4
|
-
export function T({ className, children,
|
|
3
|
+
import { useCn, useInteractiveState } from '../../hooks/index.native';
|
|
4
|
+
export function T({ className, children, ref, ...rest }) {
|
|
5
5
|
const cn = useCn();
|
|
6
|
-
const {
|
|
7
|
-
|
|
8
|
-
onPress,
|
|
9
|
-
});
|
|
10
|
-
return (_jsx(RNText, { ref: ref, className: cn('leading-relaxed', className), onPress: onAction, ...rest, children: children }));
|
|
6
|
+
const { eventHandlers } = useInteractiveState(rest);
|
|
7
|
+
return (_jsx(RNText, { ref: ref, className: cn('leading-relaxed', className), ...rest, ...eventHandlers, children: children }));
|
|
11
8
|
}
|
|
12
9
|
export const Text = T;
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
export function T({ className, children, as = 'span',
|
|
2
|
+
import { useCn, useInteractiveState } from '../../hooks/index.web';
|
|
3
|
+
export function T({ className, children, as = 'span', ref, ...rest }) {
|
|
4
4
|
const cn = useCn();
|
|
5
|
-
const {
|
|
6
|
-
onClick,
|
|
7
|
-
onPress,
|
|
8
|
-
});
|
|
5
|
+
const { eventHandlers } = useInteractiveState(rest);
|
|
9
6
|
const Comp = as;
|
|
10
|
-
return (_jsx(Comp, { ref: ref, className: cn('leading-relaxed', className),
|
|
7
|
+
return (_jsx(Comp, { ref: ref, className: cn('leading-relaxed', className), ...rest, ...eventHandlers, children: children }));
|
|
11
8
|
}
|
|
12
9
|
export const Text = T;
|
package/dist/esm/hooks/index.js
CHANGED
|
@@ -1,28 +1,88 @@
|
|
|
1
|
-
import { useState } from 'react';
|
|
1
|
+
import { useRef, useState } from 'react';
|
|
2
2
|
export function useInteractiveState(options = {}) {
|
|
3
|
-
const { disabled } = options;
|
|
3
|
+
const { disabled, onBlur, onClick, onFocus, onPress, onIn, onOut } = options;
|
|
4
|
+
const [hovered, setHovered] = useState(false);
|
|
4
5
|
const [pressed, setPressed] = useState(false);
|
|
6
|
+
const [focused, setFocused] = useState(false);
|
|
7
|
+
const offOn = useRef('off');
|
|
5
8
|
const state = disabled
|
|
6
9
|
? 'disabled'
|
|
7
10
|
: pressed
|
|
8
11
|
? 'pressed'
|
|
9
|
-
:
|
|
12
|
+
: hovered
|
|
13
|
+
? 'hovered'
|
|
14
|
+
: focused
|
|
15
|
+
? 'focused'
|
|
16
|
+
: 'idle';
|
|
10
17
|
const dataAttrs = {
|
|
11
18
|
'data-state': state,
|
|
12
|
-
'data-pressed': pressed ? 'true' : 'false',
|
|
13
19
|
'data-disabled': disabled ? 'true' : 'false',
|
|
20
|
+
'data-focused': focused ? 'true' : 'false',
|
|
21
|
+
'data-hovered': hovered ? 'true' : 'false',
|
|
22
|
+
'data-pressed': pressed ? 'true' : 'false',
|
|
14
23
|
};
|
|
15
24
|
const eventHandlers = {
|
|
25
|
+
onBlur: (e) => {
|
|
26
|
+
if (disabled) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
onBlur?.(e);
|
|
30
|
+
setFocused(false);
|
|
31
|
+
setPressed(false);
|
|
32
|
+
},
|
|
33
|
+
onFocus: (e) => {
|
|
34
|
+
if (disabled) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
onFocus?.(e);
|
|
38
|
+
setFocused(true);
|
|
39
|
+
},
|
|
40
|
+
onIn: (e) => {
|
|
41
|
+
if (disabled) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
console.log('[DEBUG] onIn', typeof onIn, e);
|
|
45
|
+
onIn?.(e);
|
|
46
|
+
},
|
|
47
|
+
onPress: (e) => {
|
|
48
|
+
if (disabled) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if ((onIn || onOut) && offOn.current === 'off') {
|
|
52
|
+
offOn.current = 'on';
|
|
53
|
+
onIn?.(e);
|
|
54
|
+
}
|
|
55
|
+
if ((onIn || onOut) && offOn.current === 'on') {
|
|
56
|
+
offOn.current = 'off';
|
|
57
|
+
onOut?.(e);
|
|
58
|
+
}
|
|
59
|
+
if (onPress) {
|
|
60
|
+
onPress?.(e);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
onClick?.(e);
|
|
64
|
+
},
|
|
16
65
|
onPressIn: (e) => {
|
|
17
|
-
if (disabled)
|
|
66
|
+
if (disabled) {
|
|
18
67
|
return;
|
|
68
|
+
}
|
|
69
|
+
onIn?.(e);
|
|
19
70
|
setPressed(true);
|
|
20
71
|
},
|
|
21
72
|
onPressOut: (e) => {
|
|
22
|
-
if (disabled)
|
|
73
|
+
if (disabled) {
|
|
23
74
|
return;
|
|
75
|
+
}
|
|
76
|
+
onOut?.(e);
|
|
24
77
|
setPressed(false);
|
|
25
78
|
},
|
|
79
|
+
onOut: (e) => {
|
|
80
|
+
if (disabled) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
console.log('[DEBUG] onOut', typeof onOut, e);
|
|
84
|
+
onOut?.(e);
|
|
85
|
+
},
|
|
26
86
|
};
|
|
27
87
|
return { state, dataAttrs, eventHandlers };
|
|
28
88
|
}
|