@codeleap/hooks 4.3.0 → 4.3.2
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/package.json +8 -8
- package/package.json.bak +1 -1
- package/src/index.ts +1 -0
- package/src/useIsClient.ts +17 -0
- package/src/useModal.ts +17 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codeleap/hooks",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.2",
|
|
4
4
|
"main": "src/index.ts",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
|
@@ -9,19 +9,19 @@
|
|
|
9
9
|
"directory": "packages/hooks"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
|
-
"@codeleap/config": "4.3.
|
|
13
|
-
"@codeleap/types": "4.3.
|
|
14
|
-
"@codeleap/utils": "4.3.
|
|
15
|
-
"@codeleap/logger": "4.3.
|
|
12
|
+
"@codeleap/config": "4.3.2",
|
|
13
|
+
"@codeleap/types": "4.3.2",
|
|
14
|
+
"@codeleap/utils": "4.3.2",
|
|
15
|
+
"@codeleap/logger": "4.3.2",
|
|
16
16
|
"ts-node-dev": "1.1.8"
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
19
|
"build": "echo 'No build needed'"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
|
-
"@codeleap/types": "4.3.
|
|
23
|
-
"@codeleap/utils": "4.3.
|
|
24
|
-
"@codeleap/logger": "4.3.
|
|
22
|
+
"@codeleap/types": "4.3.2",
|
|
23
|
+
"@codeleap/utils": "4.3.2",
|
|
24
|
+
"@codeleap/logger": "4.3.2",
|
|
25
25
|
"axios": "^1.7.9",
|
|
26
26
|
"typescript": "5.0.4",
|
|
27
27
|
"react": "18.1.0",
|
package/package.json.bak
CHANGED
package/src/index.ts
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Hook to check if the code is running on the client-side.
|
|
5
|
+
* @return `isClient: true` after the component is mounted in the browser.
|
|
6
|
+
*/
|
|
7
|
+
export function useIsClient() {
|
|
8
|
+
const [isClient, setIsClient] = useState(false)
|
|
9
|
+
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
setIsClient(true)
|
|
12
|
+
}, [])
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
isClient
|
|
16
|
+
}
|
|
17
|
+
}
|
package/src/useModal.ts
CHANGED
|
@@ -1,10 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TypeGuards } from '@codeleap/types'
|
|
2
|
+
import { useState } from 'react'
|
|
2
3
|
|
|
3
4
|
export function useModal(startsOpen = false) {
|
|
4
|
-
const [visible,
|
|
5
|
+
const [visible, setVisible] = useState(startsOpen)
|
|
6
|
+
|
|
7
|
+
function open() {
|
|
8
|
+
setVisible(true)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function close() {
|
|
12
|
+
setVisible(false)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function toggle(forceVisible?: boolean) {
|
|
16
|
+
setVisible(prev => TypeGuards.isBoolean(forceVisible) ? forceVisible : !prev)
|
|
17
|
+
}
|
|
5
18
|
|
|
6
19
|
return {
|
|
7
20
|
visible,
|
|
8
21
|
toggle,
|
|
22
|
+
open,
|
|
23
|
+
close,
|
|
9
24
|
}
|
|
10
25
|
}
|