@purr-core/hooks.focus-with-callback 0.0.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.
@@ -0,0 +1,14 @@
1
+ import { FocusEvent, FocusEventHandler } from 'react';
2
+
3
+ export interface IFocusWithCallback {
4
+ onFocus: FocusEventHandler<HTMLElement> | undefined;
5
+ onBlur: FocusEventHandler<HTMLElement> | undefined;
6
+ focused?: boolean;
7
+ disabled?: boolean;
8
+ }
9
+ declare const useFocusWithCallback: ({ onFocus, onBlur, focused, disabled, }: IFocusWithCallback) => {
10
+ captureOnFocus: (e: FocusEvent<HTMLElement, Element>) => void;
11
+ captureOnBlur: (e: FocusEvent<HTMLElement, Element>) => void;
12
+ isFocused: boolean;
13
+ };
14
+ export default useFocusWithCallback;
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";const a=require("react"),p=({onFocus:t,onBlur:e,focused:u=!1,disabled:s=!1})=>{const[f,r]=a.useState(u),i=a.useCallback(c=>{s||(t==null||t(c),r(!0))},[s,t]),k=a.useCallback(c=>{s||(e==null||e(c),r(!1))},[s,e]);return{captureOnFocus:i,captureOnBlur:k,isFocused:f}};module.exports=p;
@@ -0,0 +1 @@
1
+ export { default } from './_hook';
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
1
+ import { useState as k, useCallback as c } from "react";
2
+ const C = ({
3
+ onFocus: t,
4
+ onBlur: e,
5
+ focused: f = !1,
6
+ disabled: a = !1
7
+ }) => {
8
+ const [u, r] = k(f), p = c((s) => {
9
+ a || (t == null || t(s), r(!0));
10
+ }, [a, t]), i = c((s) => {
11
+ a || (e == null || e(s), r(!1));
12
+ }, [a, e]);
13
+ return {
14
+ captureOnFocus: p,
15
+ captureOnBlur: i,
16
+ isFocused: u
17
+ };
18
+ };
19
+ export {
20
+ C as default
21
+ };
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@purr-core/hooks.focus-with-callback",
3
+ "version": "0.0.0",
4
+ "type": "module",
5
+ "main": "dist/index.cjs",
6
+ "module": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ },
14
+ "require": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.cjs"
17
+ }
18
+ }
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "peerDependencies": {
24
+ "typescript": "*",
25
+ "react": "*"
26
+ },
27
+ "author": "@DinhThienPhuc",
28
+ "license": "ISC",
29
+ "description": "",
30
+ "sideEffects": false,
31
+ "scripts": {
32
+ "dev": "vite build --watch",
33
+ "build": "tsc && vite build",
34
+ "lint": "eslint . --ext ts,tsx --max-warnings 0"
35
+ }
36
+ }