@react-xp/aeiou 0.1.0-beta.11 → 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.
Files changed (126) hide show
  1. package/dist/cjs/components/a/a.native.js +4 -6
  2. package/dist/cjs/components/a/a.web.js +4 -6
  3. package/dist/cjs/components/e/e.native.js +3 -12
  4. package/dist/cjs/components/e/e.web.js +3 -7
  5. package/dist/cjs/components/l/l.web.js +3 -7
  6. package/dist/cjs/components/t/t.native.js +3 -6
  7. package/dist/cjs/components/t/t.web.js +3 -6
  8. package/dist/cjs/components/u/errorBoundary.js +27 -0
  9. package/dist/cjs/components/u/provider.native.js +3 -2
  10. package/dist/cjs/components/u/provider.web.js +3 -2
  11. package/dist/cjs/hooks/index.js +0 -2
  12. package/dist/cjs/hooks/index.native.js +0 -2
  13. package/dist/cjs/hooks/index.web.js +0 -2
  14. package/dist/cjs/hooks/useInteractiveState/useInteractiveState.native.js +65 -5
  15. package/dist/cjs/hooks/useInteractiveState/useInteractiveState.web.js +62 -21
  16. package/dist/esm/components/a/a.native.js +5 -7
  17. package/dist/esm/components/a/a.web.js +5 -7
  18. package/dist/esm/components/e/e.native.js +4 -13
  19. package/dist/esm/components/e/e.web.js +4 -8
  20. package/dist/esm/components/l/l.web.js +4 -8
  21. package/dist/esm/components/t/t.native.js +4 -7
  22. package/dist/esm/components/t/t.web.js +4 -7
  23. package/dist/esm/components/u/errorBoundary.js +23 -0
  24. package/dist/esm/components/u/provider.native.js +3 -2
  25. package/dist/esm/components/u/provider.web.js +3 -2
  26. package/dist/esm/hooks/index.js +0 -2
  27. package/dist/esm/hooks/index.native.js +0 -2
  28. package/dist/esm/hooks/index.web.js +0 -2
  29. package/dist/esm/hooks/useInteractiveState/useInteractiveState.native.js +66 -6
  30. package/dist/esm/hooks/useInteractiveState/useInteractiveState.web.js +62 -21
  31. package/dist/native/cjs/components/a/a.native.js +4 -6
  32. package/dist/native/cjs/components/a/a.web.js +4 -6
  33. package/dist/native/cjs/components/e/e.native.js +3 -12
  34. package/dist/native/cjs/components/e/e.web.js +3 -7
  35. package/dist/native/cjs/components/l/l.web.js +3 -7
  36. package/dist/native/cjs/components/t/t.native.js +3 -6
  37. package/dist/native/cjs/components/t/t.web.js +3 -6
  38. package/dist/native/cjs/components/u/errorBoundary.js +27 -0
  39. package/dist/native/cjs/components/u/provider.native.js +3 -2
  40. package/dist/native/cjs/components/u/provider.web.js +3 -2
  41. package/dist/native/cjs/hooks/index.js +0 -2
  42. package/dist/native/cjs/hooks/index.native.js +0 -2
  43. package/dist/native/cjs/hooks/index.web.js +0 -2
  44. package/dist/native/cjs/hooks/useInteractiveState/useInteractiveState.native.js +65 -5
  45. package/dist/native/cjs/hooks/useInteractiveState/useInteractiveState.web.js +62 -21
  46. package/dist/native/esm/components/a/a.native.js +5 -7
  47. package/dist/native/esm/components/a/a.web.js +5 -7
  48. package/dist/native/esm/components/e/e.native.js +4 -13
  49. package/dist/native/esm/components/e/e.web.js +4 -8
  50. package/dist/native/esm/components/l/l.web.js +4 -8
  51. package/dist/native/esm/components/t/t.native.js +4 -7
  52. package/dist/native/esm/components/t/t.web.js +4 -7
  53. package/dist/native/esm/components/u/errorBoundary.js +23 -0
  54. package/dist/native/esm/components/u/provider.native.js +3 -2
  55. package/dist/native/esm/components/u/provider.web.js +3 -2
  56. package/dist/native/esm/hooks/index.js +0 -2
  57. package/dist/native/esm/hooks/index.native.js +0 -2
  58. package/dist/native/esm/hooks/index.web.js +0 -2
  59. package/dist/native/esm/hooks/useInteractiveState/useInteractiveState.native.js +66 -6
  60. package/dist/native/esm/hooks/useInteractiveState/useInteractiveState.web.js +62 -21
  61. package/dist/native/tsconfig.native.cjs.tsbuildinfo +1 -1
  62. package/dist/native/tsconfig.native.esm.tsbuildinfo +1 -1
  63. package/dist/tsconfig.cjs.tsbuildinfo +1 -1
  64. package/dist/tsconfig.esm.tsbuildinfo +1 -1
  65. package/dist/types/components/a/a.native.d.ts +1 -1
  66. package/dist/types/components/a/a.native.d.ts.map +1 -1
  67. package/dist/types/components/a/a.web.d.ts +1 -1
  68. package/dist/types/components/a/a.web.d.ts.map +1 -1
  69. package/dist/types/components/e/e.native.d.ts +1 -1
  70. package/dist/types/components/e/e.native.d.ts.map +1 -1
  71. package/dist/types/components/e/e.web.d.ts +1 -1
  72. package/dist/types/components/e/e.web.d.ts.map +1 -1
  73. package/dist/types/components/i/useIUtils.d.ts +2 -2
  74. package/dist/types/components/l/l.web.d.ts +1 -1
  75. package/dist/types/components/l/l.web.d.ts.map +1 -1
  76. package/dist/types/components/t/t.native.d.ts +1 -1
  77. package/dist/types/components/t/t.native.d.ts.map +1 -1
  78. package/dist/types/components/t/t.web.d.ts +1 -1
  79. package/dist/types/components/t/t.web.d.ts.map +1 -1
  80. package/dist/types/components/u/errorBoundary.d.ts +18 -0
  81. package/dist/types/components/u/errorBoundary.d.ts.map +1 -0
  82. package/dist/types/components/u/provider.native.d.ts +1 -1
  83. package/dist/types/components/u/provider.native.d.ts.map +1 -1
  84. package/dist/types/components/u/provider.web.d.ts +1 -1
  85. package/dist/types/components/u/provider.web.d.ts.map +1 -1
  86. package/dist/types/components/u/types.d.ts +5 -0
  87. package/dist/types/components/u/types.d.ts.map +1 -1
  88. package/dist/types/hooks/index.d.ts +0 -2
  89. package/dist/types/hooks/index.d.ts.map +1 -1
  90. package/dist/types/hooks/index.native.d.ts +0 -2
  91. package/dist/types/hooks/index.native.d.ts.map +1 -1
  92. package/dist/types/hooks/index.web.d.ts +0 -2
  93. package/dist/types/hooks/index.web.d.ts.map +1 -1
  94. package/dist/types/hooks/useInteractiveState/useInteractiveState.native.d.ts +13 -5
  95. package/dist/types/hooks/useInteractiveState/useInteractiveState.native.d.ts.map +1 -1
  96. package/dist/types/hooks/useInteractiveState/useInteractiveState.types.d.ts +2 -2
  97. package/dist/types/hooks/useInteractiveState/useInteractiveState.types.d.ts.map +1 -1
  98. package/dist/types/hooks/useInteractiveState/useInteractiveState.web.d.ts +10 -7
  99. package/dist/types/hooks/useInteractiveState/useInteractiveState.web.d.ts.map +1 -1
  100. package/dist/types/types/base.d.ts +14 -4
  101. package/dist/types/types/base.d.ts.map +1 -1
  102. package/package.json +1 -1
  103. package/dist/cjs/hooks/useAction/types.js +0 -2
  104. package/dist/cjs/hooks/useAction/useAction.native.js +0 -18
  105. package/dist/cjs/hooks/useAction/useAction.web.js +0 -21
  106. package/dist/cjs/hooks/useOnHoverOrPress.js +0 -21
  107. package/dist/esm/hooks/useAction/types.js +0 -1
  108. package/dist/esm/hooks/useAction/useAction.native.js +0 -14
  109. package/dist/esm/hooks/useAction/useAction.web.js +0 -17
  110. package/dist/esm/hooks/useOnHoverOrPress.js +0 -17
  111. package/dist/native/cjs/hooks/useAction/types.js +0 -2
  112. package/dist/native/cjs/hooks/useAction/useAction.native.js +0 -18
  113. package/dist/native/cjs/hooks/useAction/useAction.web.js +0 -21
  114. package/dist/native/cjs/hooks/useOnHoverOrPress.js +0 -21
  115. package/dist/native/esm/hooks/useAction/types.js +0 -1
  116. package/dist/native/esm/hooks/useAction/useAction.native.js +0 -14
  117. package/dist/native/esm/hooks/useAction/useAction.web.js +0 -17
  118. package/dist/native/esm/hooks/useOnHoverOrPress.js +0 -17
  119. package/dist/types/hooks/useAction/types.d.ts +0 -7
  120. package/dist/types/hooks/useAction/types.d.ts.map +0 -1
  121. package/dist/types/hooks/useAction/useAction.native.d.ts +0 -5
  122. package/dist/types/hooks/useAction/useAction.native.d.ts.map +0 -1
  123. package/dist/types/hooks/useAction/useAction.web.d.ts +0 -5
  124. package/dist/types/hooks/useAction/useAction.web.d.ts.map +0 -1
  125. package/dist/types/hooks/useOnHoverOrPress.d.ts +0 -12
  126. package/dist/types/hooks/useOnHoverOrPress.d.ts.map +0 -1
@@ -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
- onMouseEnter: () => {
28
- if (disabled)
27
+ onBlur: (e) => {
28
+ if (disabled) {
29
29
  return;
30
- setHovered(true);
30
+ }
31
+ console.log('[DEBUG] onBlur', typeof onBlur, e);
32
+ onBlur?.(e);
33
+ setFocused(false);
34
+ setPressed(false);
35
+ setHovered(false);
31
36
  },
32
- onMouseLeave: () => {
33
- if (disabled)
37
+ onClick: (e) => {
38
+ if (disabled) {
34
39
  return;
35
- setHovered(false);
36
- setPressed(false);
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
- onMouseUp: () => {
44
- if (disabled)
70
+ onMouseEnter: (e) => {
71
+ if (disabled) {
45
72
  return;
46
- setPressed(false);
73
+ }
74
+ console.log('[DEBUG] onMouseEnter', typeof onIn, e);
75
+ onIn?.(e);
76
+ setHovered(true);
47
77
  },
48
- onFocus: () => {
49
- if (disabled)
78
+ onMouseLeave: (e) => {
79
+ if (disabled) {
50
80
  return;
51
- setFocused(true);
81
+ }
82
+ console.log('[DEBUG] onMouseLeave', typeof onOut, e);
83
+ onOut?.(e);
84
+ setHovered(false);
85
+ setPressed(false);
52
86
  },
53
- onBlur: () => {
54
- if (disabled)
87
+ onMouseUp: (e) => {
88
+ if (disabled) {
55
89
  return;
56
- setFocused(false);
90
+ }
91
+ console.log('[DEBUG] onMouseUp', e);
57
92
  setPressed(false);
58
- setHovered(false);
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 "nativewind/jsx-runtime";
2
2
  import { Pressable } from 'react-native';
3
- import { useAction, useCn } from '../../hooks/index.native';
3
+ import { useCn, useInteractiveState } from '../../hooks/index.native';
4
4
  import { E } from '../e/index.native';
5
- export function A({ className, children, onPress, onClick, disabled, ref, style, ...rest }) {
5
+ export function A({ accessibilityLabel, accessibilityRole, accessibilityState, className, children, loading, disabled, ref, style, ...rest }) {
6
6
  const cn = useCn();
7
- const { onAction } = useAction({
8
- onClick,
9
- onPress,
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 "nativewind/jsx-runtime";
2
- import { useAction, useCn } from '../../hooks/index.web';
3
- export function A({ className, children, onPress, onClick, disabled, ref, style, ...rest }) {
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 { onAction } = useAction({
6
- onClick,
7
- onPress,
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 "nativewind/jsx-runtime";
2
2
  import { View } from 'react-native';
3
- import { useAction, useCn, useOnHoverOrPress } from '../../hooks/index.native';
3
+ import { useCn, useInteractiveState } from '../../hooks/index.native';
4
4
  import { T } from '../t/index.native';
5
- export function E({ className, children, onIn, onOut, onClick, onPress, ref, style, ...rest }) {
5
+ export function E({ className, children, ref, style, ...rest }) {
6
6
  const cn = useCn();
7
- const { onAction } = useAction({
8
- onClick,
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 "nativewind/jsx-runtime";
2
- import { useAction, useCn, useOnHoverOrPress } from '../../hooks/index.web';
3
- export function E({ className, children, onIn, onOut, onPress, onClick, ref, style, ...rest }) {
2
+ import { useCn, useInteractiveState } from '../../hooks/index.web';
3
+ export function E({ className, children, ref, style, ...rest }) {
4
4
  const cn = useCn();
5
- const { onAction } = useAction({
6
- onClick,
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 "nativewind/jsx-runtime";
2
- import { useAction } from '../../hooks/index.native';
3
- import { useCn } from '../../hooks/index.web';
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 { onAction } = useAction({
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), onClick: onAction, style: style, ...rest, children: children }));
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 "nativewind/jsx-runtime";
2
2
  import { Text as RNText } from 'react-native';
3
- import { useAction, useCn } from '../../hooks/index.native';
4
- export function T({ className, children, onClick, onPress, ref, ...rest }) {
3
+ import { useCn, useInteractiveState } from '../../hooks/index.native';
4
+ export function T({ className, children, ref, ...rest }) {
5
5
  const cn = useCn();
6
- const { onAction } = useAction({
7
- onClick,
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 "nativewind/jsx-runtime";
2
- import { useAction, useCn } from '../../hooks/index.web';
3
- export function T({ className, children, as = 'span', onClick, onPress, ref, ...rest }) {
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 { onAction } = useAction({
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), onClick: onAction, ...rest, children: children }));
7
+ return (_jsx(Comp, { ref: ref, className: cn('leading-relaxed', className), ...rest, ...eventHandlers, children: children }));
11
8
  }
12
9
  export const Text = T;
@@ -0,0 +1,23 @@
1
+ import { jsx as _jsx } from "nativewind/jsx-runtime";
2
+ import { Component } from 'react';
3
+ export class ErrorBoundary extends Component {
4
+ constructor(props) {
5
+ super(props);
6
+ this.state = { hasError: false };
7
+ }
8
+ static getDerivedStateFromError() {
9
+ return { hasError: true };
10
+ }
11
+ componentDidCatch(error, errorInfo) {
12
+ this.props.onError?.callback?.(error, errorInfo);
13
+ }
14
+ render() {
15
+ if (this.state.hasError) {
16
+ if (this.props.onError?.render) {
17
+ return this.props.onError.render;
18
+ }
19
+ return _jsx("h1", { children: "Ocorreu um erro. Por favor, tente novamente mais tarde." });
20
+ }
21
+ return this.props.children;
22
+ }
23
+ }
@@ -2,7 +2,8 @@ import { jsx as _jsx } from "nativewind/jsx-runtime";
2
2
  import { useMemo, useState } from 'react';
3
3
  import { Appearance } from 'react-native';
4
4
  import { UniverseContext } from './context';
5
- export function U({ children, config }) {
5
+ import { ErrorBoundary } from './errorBoundary';
6
+ export function U({ children, config, onError }) {
6
7
  const systemColorScheme = Appearance.getColorScheme() ?? 'light';
7
8
  const [colorScheme, setColorScheme] = useState(config?.colorScheme ?? 'system');
8
9
  const [locale, setLocale] = useState(config?.locale ?? 'en-US');
@@ -14,6 +15,6 @@ export function U({ children, config }) {
14
15
  setColorScheme,
15
16
  setLocale,
16
17
  }), [colorScheme, locale, systemColorScheme]);
17
- return (_jsx(UniverseContext.Provider, { value: value, children: children }));
18
+ return (_jsx(ErrorBoundary, { onError: onError, children: _jsx(UniverseContext.Provider, { value: value, children: children }) }));
18
19
  }
19
20
  export const Universe = U;
@@ -1,7 +1,8 @@
1
1
  import { jsx as _jsx } from "nativewind/jsx-runtime";
2
2
  import { useMemo, useState } from 'react';
3
3
  import { UniverseContext } from './context';
4
- export function U({ children, config }) {
4
+ import { ErrorBoundary } from './errorBoundary';
5
+ export function U({ children, config, onError }) {
5
6
  const [colorScheme, setColorScheme] = useState(config?.colorScheme ?? 'system');
6
7
  const [locale, setLocale] = useState(config?.locale ?? 'en-US');
7
8
  const value = useMemo(() => ({
@@ -11,6 +12,6 @@ export function U({ children, config }) {
11
12
  setColorScheme,
12
13
  setLocale,
13
14
  }), [colorScheme, locale]);
14
- return (_jsx(UniverseContext.Provider, { value: value, children: children }));
15
+ return (_jsx(ErrorBoundary, { onError: onError, children: _jsx(UniverseContext.Provider, { value: value, children: children }) }));
15
16
  }
16
17
  export const Universe = U;
@@ -1,6 +1,4 @@
1
- export * from './useAction/useAction.web';
2
1
  export * from './useCn';
3
2
  export * from './useInteractiveState/useInteractiveState.web';
4
3
  export * from './useOnChange';
5
- export * from './useOnHoverOrPress';
6
4
  export * from './useProps';
@@ -1,6 +1,4 @@
1
- export * from './useAction/useAction.native';
2
1
  export * from './useCn';
3
2
  export * from './useInteractiveState/useInteractiveState.native';
4
3
  export * from './useOnChange';
5
- export * from './useOnHoverOrPress';
6
4
  export * from './useProps';
@@ -1,6 +1,4 @@
1
- export * from './useAction/useAction.web';
2
1
  export * from './useCn';
3
2
  export * from './useInteractiveState/useInteractiveState.web';
4
3
  export * from './useOnChange';
5
- export * from './useOnHoverOrPress';
6
4
  export * from './useProps';
@@ -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
- : 'idle';
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
  }
@@ -1,6 +1,6 @@
1
1
  import { useState } from 'react';
2
2
  export function useInteractiveState(options = {}) {
3
- const { disabled } = options;
3
+ const { disabled, onBlur, onClick, onPress, onFocus, onIn, onOut } = options;
4
4
  const [hovered, setHovered] = useState(false);
5
5
  const [pressed, setPressed] = useState(false);
6
6
  const [focused, setFocused] = useState(false);
@@ -15,44 +15,85 @@ export function useInteractiveState(options = {}) {
15
15
  : 'idle';
16
16
  const dataAttrs = {
17
17
  'data-state': state,
18
+ 'data-disabled': disabled ? 'true' : 'false',
19
+ 'data-focused': focused ? 'true' : 'false',
18
20
  'data-hovered': hovered ? 'true' : 'false',
19
21
  'data-pressed': pressed ? 'true' : 'false',
20
- 'data-focused': focused ? 'true' : 'false',
21
- 'data-disabled': disabled ? 'true' : 'false',
22
22
  };
23
23
  const eventHandlers = {
24
- onMouseEnter: () => {
25
- if (disabled)
24
+ onBlur: (e) => {
25
+ if (disabled) {
26
26
  return;
27
- setHovered(true);
27
+ }
28
+ console.log('[DEBUG] onBlur', typeof onBlur, e);
29
+ onBlur?.(e);
30
+ setFocused(false);
31
+ setPressed(false);
32
+ setHovered(false);
28
33
  },
29
- onMouseLeave: () => {
30
- if (disabled)
34
+ onClick: (e) => {
35
+ if (disabled) {
31
36
  return;
32
- setHovered(false);
33
- setPressed(false);
37
+ }
38
+ console.log('[DEBUG] onClick', typeof onClick, e);
39
+ if (onClick) {
40
+ onClick?.(e);
41
+ return;
42
+ }
43
+ onPress?.(e);
44
+ },
45
+ onFocus: (e) => {
46
+ if (disabled) {
47
+ return;
48
+ }
49
+ console.log('[DEBUG] onFocus', typeof onFocus, e);
50
+ onFocus?.(e);
51
+ setFocused(true);
52
+ },
53
+ onIn: (e) => {
54
+ if (disabled) {
55
+ return;
56
+ }
57
+ console.log('[DEBUG] onIn', typeof onIn, e);
58
+ onIn?.(e);
34
59
  },
35
60
  onMouseDown: (e) => {
36
- if (disabled || e.button !== 0)
61
+ if (disabled || e.button !== 0) {
37
62
  return;
63
+ }
64
+ console.log('[DEBUG] onMouseDown', e);
38
65
  setPressed(true);
39
66
  },
40
- onMouseUp: () => {
41
- if (disabled)
67
+ onMouseEnter: (e) => {
68
+ if (disabled) {
42
69
  return;
43
- setPressed(false);
70
+ }
71
+ console.log('[DEBUG] onMouseEnter', typeof onIn, e);
72
+ onIn?.(e);
73
+ setHovered(true);
44
74
  },
45
- onFocus: () => {
46
- if (disabled)
75
+ onMouseLeave: (e) => {
76
+ if (disabled) {
47
77
  return;
48
- setFocused(true);
78
+ }
79
+ console.log('[DEBUG] onMouseLeave', typeof onOut, e);
80
+ onOut?.(e);
81
+ setHovered(false);
82
+ setPressed(false);
49
83
  },
50
- onBlur: () => {
51
- if (disabled)
84
+ onMouseUp: (e) => {
85
+ if (disabled) {
52
86
  return;
53
- setFocused(false);
87
+ }
88
+ console.log('[DEBUG] onMouseUp', e);
54
89
  setPressed(false);
55
- setHovered(false);
90
+ },
91
+ onOut: (e) => {
92
+ if (disabled) {
93
+ return;
94
+ }
95
+ console.log('[DEBUG] onOut', typeof onOut, e);
96
+ onOut?.(e);
56
97
  },
57
98
  };
58
99
  return { state, dataAttrs, eventHandlers };