@react-xp/aeiou 0.1.0-beta.9 → 1.0.0-beta.0
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 +7 -7
- package/dist/cjs/components/a/a.web.js +7 -7
- package/dist/cjs/components/d/d.native.js +8 -8
- package/dist/cjs/components/d/d.web.js +10 -7
- package/dist/cjs/components/e/e.native.js +7 -14
- package/dist/cjs/components/e/e.web.js +7 -9
- package/dist/cjs/components/i/i.native.js +9 -5
- package/dist/cjs/components/i/i.web.js +9 -5
- package/dist/cjs/components/l/l.web.js +7 -9
- package/dist/cjs/components/o/o.native.js +4 -4
- package/dist/cjs/components/o/o.web.js +7 -4
- package/dist/cjs/components/p/p.native.js +4 -4
- package/dist/cjs/components/p/p.web.js +7 -4
- package/dist/cjs/components/s/s.native.js +4 -4
- package/dist/cjs/components/t/t.native.js +7 -8
- package/dist/cjs/components/t/t.web.js +7 -8
- package/dist/cjs/components/u/errorBoundary.js +27 -0
- package/dist/cjs/components/u/provider.native.js +3 -2
- package/dist/cjs/components/u/provider.web.js +3 -2
- package/dist/cjs/hooks/index.js +0 -3
- package/dist/cjs/hooks/index.native.js +2 -2
- package/dist/cjs/hooks/index.web.js +2 -2
- package/dist/cjs/hooks/useInteractiveHandlers/useInteractiveHandlers.native.js +43 -0
- package/dist/cjs/hooks/useInteractiveHandlers/useInteractiveHandlers.web.js +45 -0
- package/dist/cjs/hooks/useInteractiveState/useInteractiveState.native.js +53 -15
- package/dist/cjs/hooks/useInteractiveState/useInteractiveState.web.js +51 -39
- package/dist/cjs/hooks/useOnChange.js +1 -1
- package/dist/cjs/hooks/useStyles/useStyles.helpers.js +35 -0
- package/dist/cjs/hooks/useStyles/useStyles.native.js +42 -0
- package/dist/cjs/hooks/useStyles/useStyles.web.js +71 -0
- package/dist/esm/components/a/a.native.js +7 -7
- package/dist/esm/components/a/a.web.js +7 -7
- package/dist/esm/components/d/d.native.js +6 -6
- package/dist/esm/components/d/d.web.js +8 -5
- package/dist/esm/components/e/e.native.js +6 -13
- package/dist/esm/components/e/e.web.js +6 -8
- package/dist/esm/components/i/i.native.js +7 -3
- package/dist/esm/components/i/i.web.js +7 -3
- package/dist/esm/components/l/l.web.js +6 -8
- package/dist/esm/components/o/o.native.js +3 -3
- package/dist/esm/components/o/o.web.js +6 -3
- package/dist/esm/components/p/p.native.js +3 -3
- package/dist/esm/components/p/p.web.js +6 -3
- package/dist/esm/components/s/s.native.js +3 -3
- package/dist/esm/components/t/t.native.js +6 -7
- package/dist/esm/components/t/t.web.js +6 -7
- package/dist/esm/components/u/errorBoundary.js +23 -0
- package/dist/esm/components/u/provider.native.js +3 -2
- package/dist/esm/components/u/provider.web.js +3 -2
- package/dist/esm/hooks/index.js +0 -3
- package/dist/esm/hooks/index.native.js +2 -2
- package/dist/esm/hooks/index.web.js +2 -2
- package/dist/esm/hooks/useInteractiveHandlers/useInteractiveHandlers.native.js +40 -0
- package/dist/esm/hooks/useInteractiveHandlers/useInteractiveHandlers.web.js +42 -0
- package/dist/esm/hooks/useInteractiveState/useInteractiveState.native.js +54 -16
- package/dist/esm/hooks/useInteractiveState/useInteractiveState.web.js +51 -39
- package/dist/esm/hooks/useOnChange.js +1 -1
- package/dist/esm/hooks/useStyles/useStyles.helpers.js +29 -0
- package/dist/esm/hooks/useStyles/useStyles.native.js +38 -0
- package/dist/esm/hooks/useStyles/useStyles.web.js +66 -0
- package/dist/native/cjs/components/a/a.native.js +7 -7
- package/dist/native/cjs/components/a/a.web.js +7 -7
- package/dist/native/cjs/components/d/d.native.js +8 -8
- package/dist/native/cjs/components/d/d.web.js +10 -7
- package/dist/native/cjs/components/e/e.native.js +7 -14
- package/dist/native/cjs/components/e/e.web.js +7 -9
- package/dist/native/cjs/components/i/i.native.js +9 -5
- package/dist/native/cjs/components/i/i.web.js +9 -5
- package/dist/native/cjs/components/l/l.web.js +7 -9
- package/dist/native/cjs/components/o/o.native.js +4 -4
- package/dist/native/cjs/components/o/o.web.js +7 -4
- package/dist/native/cjs/components/p/p.native.js +4 -4
- package/dist/native/cjs/components/p/p.web.js +7 -4
- package/dist/native/cjs/components/s/s.native.js +4 -4
- package/dist/native/cjs/components/t/t.native.js +7 -8
- package/dist/native/cjs/components/t/t.web.js +7 -8
- package/dist/native/cjs/components/u/errorBoundary.js +27 -0
- package/dist/native/cjs/components/u/provider.native.js +3 -2
- package/dist/native/cjs/components/u/provider.web.js +3 -2
- package/dist/native/cjs/hooks/index.js +0 -3
- package/dist/native/cjs/hooks/index.native.js +2 -2
- package/dist/native/cjs/hooks/index.web.js +2 -2
- package/dist/native/cjs/hooks/useInteractiveHandlers/useInteractiveHandlers.native.js +43 -0
- package/dist/native/cjs/hooks/useInteractiveHandlers/useInteractiveHandlers.web.js +45 -0
- package/dist/native/cjs/hooks/useInteractiveState/useInteractiveState.native.js +53 -15
- package/dist/native/cjs/hooks/useInteractiveState/useInteractiveState.web.js +51 -39
- package/dist/native/cjs/hooks/useOnChange.js +1 -1
- package/dist/native/cjs/hooks/useStyles/useStyles.helpers.js +35 -0
- package/dist/native/cjs/hooks/useStyles/useStyles.native.js +42 -0
- package/dist/native/cjs/hooks/useStyles/useStyles.web.js +71 -0
- package/dist/native/esm/components/a/a.native.js +7 -7
- package/dist/native/esm/components/a/a.web.js +7 -7
- package/dist/native/esm/components/d/d.native.js +6 -6
- package/dist/native/esm/components/d/d.web.js +8 -5
- package/dist/native/esm/components/e/e.native.js +6 -13
- package/dist/native/esm/components/e/e.web.js +6 -8
- package/dist/native/esm/components/i/i.native.js +7 -3
- package/dist/native/esm/components/i/i.web.js +7 -3
- package/dist/native/esm/components/l/l.web.js +6 -8
- package/dist/native/esm/components/o/o.native.js +3 -3
- package/dist/native/esm/components/o/o.web.js +6 -3
- package/dist/native/esm/components/p/p.native.js +3 -3
- package/dist/native/esm/components/p/p.web.js +6 -3
- package/dist/native/esm/components/s/s.native.js +3 -3
- package/dist/native/esm/components/t/t.native.js +6 -7
- package/dist/native/esm/components/t/t.web.js +6 -7
- package/dist/native/esm/components/u/errorBoundary.js +23 -0
- package/dist/native/esm/components/u/provider.native.js +3 -2
- package/dist/native/esm/components/u/provider.web.js +3 -2
- package/dist/native/esm/hooks/index.js +0 -3
- package/dist/native/esm/hooks/index.native.js +2 -2
- package/dist/native/esm/hooks/index.web.js +2 -2
- package/dist/native/esm/hooks/useInteractiveHandlers/useInteractiveHandlers.native.js +40 -0
- package/dist/native/esm/hooks/useInteractiveHandlers/useInteractiveHandlers.web.js +42 -0
- package/dist/native/esm/hooks/useInteractiveState/useInteractiveState.native.js +54 -16
- package/dist/native/esm/hooks/useInteractiveState/useInteractiveState.web.js +51 -39
- package/dist/native/esm/hooks/useOnChange.js +1 -1
- package/dist/native/esm/hooks/useStyles/useStyles.helpers.js +29 -0
- package/dist/native/esm/hooks/useStyles/useStyles.native.js +38 -0
- package/dist/native/esm/hooks/useStyles/useStyles.web.js +66 -0
- 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/d/d.native.d.ts +1 -1
- package/dist/types/components/d/d.native.d.ts.map +1 -1
- package/dist/types/components/d/d.web.d.ts +1 -1
- package/dist/types/components/d/d.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/i.native.d.ts +1 -1
- package/dist/types/components/i/i.native.d.ts.map +1 -1
- package/dist/types/components/i/i.web.d.ts +1 -1
- package/dist/types/components/i/i.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/o/o.native.d.ts +1 -1
- package/dist/types/components/o/o.native.d.ts.map +1 -1
- package/dist/types/components/o/o.web.d.ts +1 -1
- package/dist/types/components/o/o.web.d.ts.map +1 -1
- package/dist/types/components/p/p.native.d.ts +1 -1
- package/dist/types/components/p/p.native.d.ts.map +1 -1
- package/dist/types/components/p/p.web.d.ts +1 -1
- package/dist/types/components/p/p.web.d.ts.map +1 -1
- package/dist/types/components/s/s.native.d.ts +1 -1
- package/dist/types/components/s/s.native.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/components/u/errorBoundary.d.ts +18 -0
- package/dist/types/components/u/errorBoundary.d.ts.map +1 -0
- package/dist/types/components/u/provider.native.d.ts +1 -1
- package/dist/types/components/u/provider.native.d.ts.map +1 -1
- package/dist/types/components/u/provider.web.d.ts +1 -1
- package/dist/types/components/u/provider.web.d.ts.map +1 -1
- package/dist/types/components/u/types.d.ts +5 -0
- package/dist/types/components/u/types.d.ts.map +1 -1
- package/dist/types/hooks/index.d.ts +0 -3
- package/dist/types/hooks/index.d.ts.map +1 -1
- package/dist/types/hooks/index.native.d.ts +2 -2
- package/dist/types/hooks/index.native.d.ts.map +1 -1
- package/dist/types/hooks/index.web.d.ts +2 -2
- package/dist/types/hooks/index.web.d.ts.map +1 -1
- package/dist/types/hooks/useInteractiveHandlers/useInteractiveHandlers.native.d.ts +11 -0
- package/dist/types/hooks/useInteractiveHandlers/useInteractiveHandlers.native.d.ts.map +1 -0
- package/dist/types/hooks/useInteractiveHandlers/useInteractiveHandlers.web.d.ts +12 -0
- package/dist/types/hooks/useInteractiveHandlers/useInteractiveHandlers.web.d.ts.map +1 -0
- package/dist/types/hooks/useInteractiveState/useInteractiveState.native.d.ts +12 -6
- package/dist/types/hooks/useInteractiveState/useInteractiveState.native.d.ts.map +1 -1
- package/dist/types/hooks/useInteractiveState/useInteractiveState.web.d.ts +13 -12
- package/dist/types/hooks/useInteractiveState/useInteractiveState.web.d.ts.map +1 -1
- package/dist/types/hooks/useOnChange.d.ts +3 -3
- package/dist/types/hooks/useOnChange.d.ts.map +1 -1
- package/dist/types/hooks/useStyles/useStyles.helpers.d.ts +171 -0
- package/dist/types/hooks/useStyles/useStyles.helpers.d.ts.map +1 -0
- package/dist/types/hooks/useStyles/useStyles.native.d.ts +15 -0
- package/dist/types/hooks/useStyles/useStyles.native.d.ts.map +1 -0
- package/dist/types/hooks/useStyles/useStyles.types.d.ts +6 -0
- package/dist/types/hooks/useStyles/useStyles.types.d.ts.map +1 -0
- package/dist/types/hooks/useStyles/useStyles.web.d.ts +11 -0
- package/dist/types/hooks/useStyles/useStyles.web.d.ts.map +1 -0
- package/dist/types/types/base.d.ts +44 -11
- package/dist/types/types/base.d.ts.map +1 -1
- package/package.json +1 -1
- 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/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/useInteractiveState/useInteractiveState.types.js +0 -2
- 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/useInteractiveState/useInteractiveState.types.js +0 -1
- 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/useInteractiveState/useInteractiveState.types.d.ts +0 -18
- package/dist/types/hooks/useInteractiveState/useInteractiveState.types.d.ts.map +0 -1
- package/dist/types/hooks/useOnHoverOrPress.d.ts +0 -12
- package/dist/types/hooks/useOnHoverOrPress.d.ts.map +0 -1
- /package/dist/cjs/hooks/{useAction/types.js → useStyles/useStyles.types.js} +0 -0
- /package/dist/esm/hooks/{useAction/types.js → useStyles/useStyles.types.js} +0 -0
- /package/dist/{cjs/hooks/useInteractiveState/useInteractiveState.types.js → native/cjs/hooks/useStyles/useStyles.types.js} +0 -0
- /package/dist/{esm/hooks/useInteractiveState/useInteractiveState.types.js → native/esm/hooks/useStyles/useStyles.types.js} +0 -0
|
@@ -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
|
-
|
|
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
|
-
|
|
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,6 @@
|
|
|
1
|
-
export * from './useAction/useAction.native';
|
|
2
1
|
export * from './useCn';
|
|
2
|
+
export * from './useInteractiveHandlers/useInteractiveHandlers.native';
|
|
3
3
|
export * from './useInteractiveState/useInteractiveState.native';
|
|
4
4
|
export * from './useOnChange';
|
|
5
|
-
export * from './useOnHoverOrPress';
|
|
6
5
|
export * from './useProps';
|
|
6
|
+
export * from './useStyles/useStyles.native';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from './useAction/useAction.web';
|
|
2
1
|
export * from './useCn';
|
|
2
|
+
export * from './useInteractiveHandlers/useInteractiveHandlers.web';
|
|
3
3
|
export * from './useInteractiveState/useInteractiveState.web';
|
|
4
4
|
export * from './useOnChange';
|
|
5
|
-
export * from './useOnHoverOrPress';
|
|
6
5
|
export * from './useProps';
|
|
6
|
+
export * from './useStyles/useStyles.web';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useRef } from 'react';
|
|
2
|
+
export function useInteractiveHandlers({ disabled, onBlur, onClick, onFocus, onPress, onIn, onOut, } = {}) {
|
|
3
|
+
const offOn = useRef('off');
|
|
4
|
+
const eventHandlers = {
|
|
5
|
+
onBlur: (e) => {
|
|
6
|
+
if (disabled) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
onBlur?.(e);
|
|
10
|
+
},
|
|
11
|
+
onFocus: (e) => {
|
|
12
|
+
if (disabled) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
onFocus?.(e);
|
|
16
|
+
},
|
|
17
|
+
onPress: (e) => {
|
|
18
|
+
if (disabled) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if ((onIn || onOut) && offOn.current === 'off') {
|
|
22
|
+
offOn.current = 'on';
|
|
23
|
+
onIn?.(e);
|
|
24
|
+
}
|
|
25
|
+
if ((onIn || onOut) && offOn.current === 'on') {
|
|
26
|
+
offOn.current = 'off';
|
|
27
|
+
onOut?.(e);
|
|
28
|
+
}
|
|
29
|
+
if (onPress) {
|
|
30
|
+
onPress?.(e);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
onClick?.(e);
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
return {
|
|
37
|
+
disabled,
|
|
38
|
+
eventHandlers,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export function useInteractiveHandlers({ disabled, onBlur, onClick, onFocus, onPress, onIn, onOut, } = {}) {
|
|
2
|
+
const eventHandlers = {
|
|
3
|
+
onBlur: (e) => {
|
|
4
|
+
if (disabled) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
onBlur?.(e);
|
|
8
|
+
},
|
|
9
|
+
onClick: (e) => {
|
|
10
|
+
if (disabled) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (onClick) {
|
|
14
|
+
onClick?.(e);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
onPress?.(e);
|
|
18
|
+
},
|
|
19
|
+
onFocus: (e) => {
|
|
20
|
+
if (disabled) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
onFocus?.(e);
|
|
24
|
+
},
|
|
25
|
+
onMouseEnter: (e) => {
|
|
26
|
+
if (disabled) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
onIn?.(e);
|
|
30
|
+
},
|
|
31
|
+
onMouseLeave: (e) => {
|
|
32
|
+
if (disabled) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
onOut?.(e);
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
return {
|
|
39
|
+
disabled,
|
|
40
|
+
eventHandlers,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -1,28 +1,66 @@
|
|
|
1
|
-
import { useState } from 'react';
|
|
2
|
-
export function useInteractiveState(
|
|
3
|
-
const
|
|
4
|
-
const [
|
|
5
|
-
const state = disabled
|
|
6
|
-
? 'disabled'
|
|
7
|
-
: pressed
|
|
8
|
-
? 'pressed'
|
|
9
|
-
: 'idle';
|
|
1
|
+
import { useRef, useState } from 'react';
|
|
2
|
+
export function useInteractiveState({ disabled, onBlur, onClick, onFocus, onPress, onIn, onOut, } = {}) {
|
|
3
|
+
const offOn = useRef('off');
|
|
4
|
+
const [interactiveState, setInteractiveState] = useState('idle');
|
|
10
5
|
const dataAttrs = {
|
|
11
|
-
'data-state':
|
|
12
|
-
'data-pressed': pressed ? 'true' : 'false',
|
|
6
|
+
'data-state': interactiveState,
|
|
13
7
|
'data-disabled': disabled ? 'true' : 'false',
|
|
8
|
+
'data-focused': interactiveState === 'focused' ? 'true' : 'false',
|
|
9
|
+
'data-hovered': interactiveState === 'hovered' ? 'true' : 'false',
|
|
10
|
+
'data-pressed': interactiveState === 'pressed' ? 'true' : 'false',
|
|
14
11
|
};
|
|
15
12
|
const eventHandlers = {
|
|
13
|
+
onBlur: (e) => {
|
|
14
|
+
if (disabled) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
onBlur?.(e);
|
|
18
|
+
setInteractiveState('idle');
|
|
19
|
+
},
|
|
20
|
+
onFocus: (e) => {
|
|
21
|
+
if (disabled) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
onFocus?.(e);
|
|
25
|
+
setInteractiveState('focused');
|
|
26
|
+
},
|
|
27
|
+
onPress: (e) => {
|
|
28
|
+
if (disabled) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if ((onIn || onOut) && offOn.current === 'off') {
|
|
32
|
+
offOn.current = 'on';
|
|
33
|
+
onIn?.(e);
|
|
34
|
+
}
|
|
35
|
+
if ((onIn || onOut) && offOn.current === 'on') {
|
|
36
|
+
offOn.current = 'off';
|
|
37
|
+
onOut?.(e);
|
|
38
|
+
}
|
|
39
|
+
if (onPress) {
|
|
40
|
+
onPress?.(e);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
onClick?.(e);
|
|
44
|
+
},
|
|
16
45
|
onPressIn: (e) => {
|
|
17
|
-
if (disabled)
|
|
46
|
+
if (disabled) {
|
|
18
47
|
return;
|
|
19
|
-
|
|
48
|
+
}
|
|
49
|
+
onIn?.(e);
|
|
50
|
+
setInteractiveState('pressed');
|
|
20
51
|
},
|
|
21
52
|
onPressOut: (e) => {
|
|
22
|
-
if (disabled)
|
|
53
|
+
if (disabled) {
|
|
23
54
|
return;
|
|
24
|
-
|
|
55
|
+
}
|
|
56
|
+
onOut?.(e);
|
|
57
|
+
setInteractiveState('idle');
|
|
25
58
|
},
|
|
26
59
|
};
|
|
27
|
-
return {
|
|
60
|
+
return {
|
|
61
|
+
dataAttrs,
|
|
62
|
+
disabled,
|
|
63
|
+
eventHandlers,
|
|
64
|
+
interactiveState,
|
|
65
|
+
};
|
|
28
66
|
}
|
|
@@ -1,59 +1,71 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
|
-
export function useInteractiveState(
|
|
3
|
-
const
|
|
4
|
-
const [hovered, setHovered] = useState(false);
|
|
5
|
-
const [pressed, setPressed] = useState(false);
|
|
6
|
-
const [focused, setFocused] = useState(false);
|
|
7
|
-
const state = disabled
|
|
8
|
-
? 'disabled'
|
|
9
|
-
: pressed
|
|
10
|
-
? 'pressed'
|
|
11
|
-
: hovered
|
|
12
|
-
? 'hovered'
|
|
13
|
-
: focused
|
|
14
|
-
? 'focused'
|
|
15
|
-
: 'idle';
|
|
2
|
+
export function useInteractiveState({ disabled, onBlur, onClick, onFocus, onPress, onIn, onOut, } = {}) {
|
|
3
|
+
const [interactiveState, setInteractiveState] = useState('idle');
|
|
16
4
|
const dataAttrs = {
|
|
17
|
-
'data-state':
|
|
18
|
-
'data-hovered': hovered ? 'true' : 'false',
|
|
19
|
-
'data-pressed': pressed ? 'true' : 'false',
|
|
20
|
-
'data-focused': focused ? 'true' : 'false',
|
|
5
|
+
'data-state': interactiveState,
|
|
21
6
|
'data-disabled': disabled ? 'true' : 'false',
|
|
7
|
+
'data-focused': interactiveState === 'focused' ? 'true' : 'false',
|
|
8
|
+
'data-hovered': interactiveState === 'hovered' ? 'true' : 'false',
|
|
9
|
+
'data-pressed': interactiveState === 'pressed' ? 'true' : 'false',
|
|
22
10
|
};
|
|
23
11
|
const eventHandlers = {
|
|
24
|
-
|
|
25
|
-
if (disabled)
|
|
12
|
+
onBlur: (e) => {
|
|
13
|
+
if (disabled) {
|
|
26
14
|
return;
|
|
27
|
-
|
|
15
|
+
}
|
|
16
|
+
onBlur?.(e);
|
|
17
|
+
setInteractiveState('idle');
|
|
28
18
|
},
|
|
29
|
-
|
|
30
|
-
if (disabled)
|
|
19
|
+
onClick: (e) => {
|
|
20
|
+
if (disabled) {
|
|
31
21
|
return;
|
|
32
|
-
|
|
33
|
-
|
|
22
|
+
}
|
|
23
|
+
if (onClick) {
|
|
24
|
+
onClick?.(e);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
onPress?.(e);
|
|
28
|
+
},
|
|
29
|
+
onFocus: (e) => {
|
|
30
|
+
if (disabled) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
onFocus?.(e);
|
|
34
|
+
setInteractiveState('focused');
|
|
34
35
|
},
|
|
35
36
|
onMouseDown: (e) => {
|
|
36
|
-
if (disabled
|
|
37
|
+
if (disabled) {
|
|
37
38
|
return;
|
|
38
|
-
|
|
39
|
+
}
|
|
40
|
+
setInteractiveState('pressed');
|
|
39
41
|
},
|
|
40
|
-
|
|
41
|
-
if (disabled)
|
|
42
|
+
onMouseEnter: (e) => {
|
|
43
|
+
if (disabled) {
|
|
42
44
|
return;
|
|
43
|
-
|
|
45
|
+
}
|
|
46
|
+
onIn?.(e);
|
|
47
|
+
setInteractiveState('hovered');
|
|
44
48
|
},
|
|
45
|
-
|
|
46
|
-
if (disabled)
|
|
49
|
+
onMouseLeave: (e) => {
|
|
50
|
+
if (disabled) {
|
|
47
51
|
return;
|
|
48
|
-
|
|
52
|
+
}
|
|
53
|
+
console.log('[DEBUG] onMouseLeave', typeof onOut, e);
|
|
54
|
+
onOut?.(e);
|
|
55
|
+
setInteractiveState('idle');
|
|
49
56
|
},
|
|
50
|
-
|
|
51
|
-
if (disabled)
|
|
57
|
+
onMouseUp: (e) => {
|
|
58
|
+
if (disabled) {
|
|
52
59
|
return;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
60
|
+
}
|
|
61
|
+
console.log('[DEBUG] onMouseUp', e);
|
|
62
|
+
setInteractiveState('idle');
|
|
56
63
|
},
|
|
57
64
|
};
|
|
58
|
-
return {
|
|
65
|
+
return {
|
|
66
|
+
dataAttrs,
|
|
67
|
+
disabled,
|
|
68
|
+
eventHandlers,
|
|
69
|
+
interactiveState,
|
|
70
|
+
};
|
|
59
71
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export const extractStyles = (style) => {
|
|
2
|
+
const base = { ...style };
|
|
3
|
+
const disabled = style.$disabled || {};
|
|
4
|
+
const focused = style.$focused || {};
|
|
5
|
+
const hovered = style.$hovered || {};
|
|
6
|
+
const pressed = style.$pressed || {};
|
|
7
|
+
base.$disabled = undefined;
|
|
8
|
+
base.$focused = undefined;
|
|
9
|
+
base.$hovered = undefined;
|
|
10
|
+
base.$pressed = undefined;
|
|
11
|
+
return {
|
|
12
|
+
styleBase: base,
|
|
13
|
+
styleDisabled: disabled,
|
|
14
|
+
styleFocused: focused,
|
|
15
|
+
styleHovered: hovered,
|
|
16
|
+
stylePressed: pressed,
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export const toKebab = (s) => s.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
|
|
20
|
+
export const toCssDecls = (style) => {
|
|
21
|
+
if (!style) {
|
|
22
|
+
return '';
|
|
23
|
+
}
|
|
24
|
+
// TODO: adiconar os px ou outra medida quando necessario e faça sentido
|
|
25
|
+
return Object.entries(style)
|
|
26
|
+
.filter(([, v]) => v !== undefined && v !== null)
|
|
27
|
+
.map(([k, v]) => `${toKebab(k)}:${typeof v === 'number' ? `${v}` : v};`)
|
|
28
|
+
.join('');
|
|
29
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { extractStyles } from './useStyles.helpers';
|
|
2
|
+
const getStyles = ({ disabled, style, }) => {
|
|
3
|
+
if (!style) {
|
|
4
|
+
return {};
|
|
5
|
+
}
|
|
6
|
+
const { styleBase, styleDisabled, styleFocused, styleHovered, stylePressed } = extractStyles(style);
|
|
7
|
+
const composedStyle = { ...styleBase };
|
|
8
|
+
if (disabled) {
|
|
9
|
+
Object.assign(composedStyle, styleDisabled || {});
|
|
10
|
+
}
|
|
11
|
+
return { style: composedStyle };
|
|
12
|
+
};
|
|
13
|
+
const getStylesWithInteraction = ({ disabled, style }) => (options) => {
|
|
14
|
+
if (!style) {
|
|
15
|
+
return {};
|
|
16
|
+
}
|
|
17
|
+
const { styleBase, styleDisabled, styleFocused, styleHovered, stylePressed, } = extractStyles(style);
|
|
18
|
+
const composedStyle = { ...styleBase };
|
|
19
|
+
if (disabled) {
|
|
20
|
+
Object.assign(composedStyle, styleDisabled || {});
|
|
21
|
+
}
|
|
22
|
+
if (options?.focused) {
|
|
23
|
+
Object.assign(composedStyle, styleFocused || {});
|
|
24
|
+
}
|
|
25
|
+
if (options?.hovered) {
|
|
26
|
+
Object.assign(composedStyle, styleHovered || {});
|
|
27
|
+
}
|
|
28
|
+
if (options?.pressed) {
|
|
29
|
+
Object.assign(composedStyle, stylePressed || {});
|
|
30
|
+
}
|
|
31
|
+
return { style: composedStyle };
|
|
32
|
+
};
|
|
33
|
+
export const useStyles = () => {
|
|
34
|
+
return {
|
|
35
|
+
getStyles,
|
|
36
|
+
getStylesWithInteraction,
|
|
37
|
+
};
|
|
38
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { useId } from 'react';
|
|
2
|
+
import { extractStyles, toCssDecls } from './useStyles.helpers';
|
|
3
|
+
const injected = new Set();
|
|
4
|
+
const injectOnce = (id, cssText) => {
|
|
5
|
+
if (typeof document === 'undefined')
|
|
6
|
+
return;
|
|
7
|
+
if (injected.has(id))
|
|
8
|
+
return;
|
|
9
|
+
const style = document.createElement('style');
|
|
10
|
+
style.setAttribute('data-interactive', id);
|
|
11
|
+
style.textContent = cssText;
|
|
12
|
+
document.head.appendChild(style);
|
|
13
|
+
injected.add(id);
|
|
14
|
+
};
|
|
15
|
+
export const createInteractiveClass = ({ disabled, id, style, }) => {
|
|
16
|
+
const className = `ix-${id}`;
|
|
17
|
+
const { styleBase, styleDisabled, styleFocused, styleHovered, stylePressed } = extractStyles(style);
|
|
18
|
+
const hoveredClass = styleHovered
|
|
19
|
+
? `.${className}:hover{${toCssDecls(styleHovered)}}`
|
|
20
|
+
: '';
|
|
21
|
+
const activeClass = stylePressed
|
|
22
|
+
? `.${className}:active{${toCssDecls(stylePressed)}}`
|
|
23
|
+
: '';
|
|
24
|
+
// focus-visible com fallback para browsers sem suporte
|
|
25
|
+
const focusVisibleClass = styleFocused
|
|
26
|
+
? `
|
|
27
|
+
.${className}:focus-visible{${toCssDecls(styleFocused)}}
|
|
28
|
+
@supports not selector(:focus-visible){
|
|
29
|
+
.${className}:focus{${toCssDecls(styleFocused)}}
|
|
30
|
+
}
|
|
31
|
+
`
|
|
32
|
+
: '';
|
|
33
|
+
const disabledClass = disabled
|
|
34
|
+
? `
|
|
35
|
+
.${className}[data-disabled="true"]{${toCssDecls(styleDisabled)}}
|
|
36
|
+
.${className}[data-disabled="true"]:hover{${toCssDecls(styleDisabled)}}
|
|
37
|
+
.${className}[data-disabled="true"]:active{${toCssDecls(styleDisabled)}}
|
|
38
|
+
`
|
|
39
|
+
: '';
|
|
40
|
+
const baseClass = `.${className}{${toCssDecls(styleBase)}}`;
|
|
41
|
+
injectOnce(id, `${baseClass}${hoveredClass}${activeClass}${focusVisibleClass}${disabledClass}`);
|
|
42
|
+
return className;
|
|
43
|
+
};
|
|
44
|
+
const getStyles = ({ id }) => ({ disabled, style }) => {
|
|
45
|
+
if (!style) {
|
|
46
|
+
return {};
|
|
47
|
+
}
|
|
48
|
+
const className = createInteractiveClass({ disabled, id, style });
|
|
49
|
+
return {
|
|
50
|
+
className,
|
|
51
|
+
...(disabled ? { 'aria-disabled': 'true', 'data-disabled': 'true' } : {}),
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
export const useStyles = () => {
|
|
55
|
+
const id = useId();
|
|
56
|
+
// TODO: cleanup on unmount
|
|
57
|
+
// useEffect(() => {
|
|
58
|
+
// return () => {
|
|
59
|
+
// document.querySelector(`style[data-interactive="${id}"]`)?.remove();
|
|
60
|
+
// injected.delete(id);
|
|
61
|
+
// };
|
|
62
|
+
// }, [id]);
|
|
63
|
+
return {
|
|
64
|
+
getStyles: getStyles({ id }),
|
|
65
|
+
};
|
|
66
|
+
};
|