@aiszlab/relax 1.2.27 → 1.2.28-beta.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.
@@ -1,9 +1,15 @@
1
- type UsedFocus = [
2
- boolean,
3
- {
4
- onFocus: () => void;
5
- onBlur: () => void;
6
- }
7
- ];
8
- export declare const useFoucs: () => UsedFocus;
1
+ import { type DOMAttributes } from 'react';
2
+ /**
3
+ * @description
4
+ * hooks for focus
5
+ */
6
+ type UseFoucsBy<T> = Pick<DOMAttributes<T>, 'onFocus' | 'onBlur'> & {
7
+ onFocusChange?: (isFocused: boolean) => void;
8
+ };
9
+ /**
10
+ * @description
11
+ * dom attributes
12
+ */
13
+ type UsedFocus<T> = [boolean, Required<Pick<DOMAttributes<T>, 'onFocus' | 'onBlur'>>];
14
+ export declare const useFoucs: <T = Element>(useBy: UseFoucsBy<T>) => UsedFocus<T>;
9
15
  export {};
@@ -0,0 +1,16 @@
1
+ import { useCallback } from 'react';
2
+ import { useBoolean } from './use-boolean.mjs';
3
+ import { chain } from '../utils/chain.mjs';
4
+
5
+ const useFoucs = (useBy) => {
6
+ const [isFocused, { turnOn, turnOff }] = useBoolean(false);
7
+ const onFocus = useCallback(() => {
8
+ chain(useBy.onFocus, turnOn, () => { var _a; return (_a = useBy.onFocusChange) === null || _a === void 0 ? void 0 : _a.call(useBy, true); })();
9
+ }, [useBy.onFocus, useBy.onFocusChange]);
10
+ const onBlur = useCallback(() => {
11
+ chain(useBy.onBlur, turnOff, () => { var _a; return (_a = useBy.onFocusChange) === null || _a === void 0 ? void 0 : _a.call(useBy, false); })();
12
+ }, [useBy.onBlur, useBy.onFocusChange]);
13
+ return [isFocused, { onFocus, onBlur }];
14
+ };
15
+
16
+ export { useFoucs };
package/dist/index.d.ts CHANGED
@@ -20,6 +20,7 @@ export { useEvent } from './hooks/use-event';
20
20
  export { useUpdateEffect } from './hooks/use-update-effect';
21
21
  export { useCounter } from './hooks/use-counter';
22
22
  export { useHover } from './hooks/use-hover';
23
+ export { useFoucs } from './hooks/use-focus';
23
24
  /**
24
25
  * @description
25
26
  * is
package/dist/index.mjs CHANGED
@@ -16,6 +16,7 @@ export { useEvent } from './hooks/use-event.mjs';
16
16
  export { useUpdateEffect } from './hooks/use-update-effect.mjs';
17
17
  export { useCounter } from './hooks/use-counter.mjs';
18
18
  export { useHover } from './hooks/use-hover.mjs';
19
+ export { useFoucs } from './hooks/use-focus.mjs';
19
20
  export { isRefable } from './is/is-refable.mjs';
20
21
  export { isUndefined } from './is/is-undefined.mjs';
21
22
  export { isStateGetter } from './is/is-state-getter.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiszlab/relax",
3
- "version": "1.2.27",
3
+ "version": "1.2.28-beta.1",
4
4
  "description": "react utils collection",
5
5
  "type": "module",
6
6
  "exports": {