@slotjs/hooks 0.0.1 → 0.0.3
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/README.md +13 -63
- package/dist/types/index.d.ts +21 -0
- package/package.json +18 -4
- /package/dist/{index.es.js → index.js} +0 -0
- /package/dist/{index.umd.js → index.umd.cjs} +0 -0
package/README.md
CHANGED
|
@@ -1,69 +1,19 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @slotjs/hooks
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Currently, two official plugins are available:
|
|
6
|
-
|
|
7
|
-
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) for Fast Refresh
|
|
8
|
-
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
|
|
9
|
-
|
|
10
|
-
## Expanding the ESLint configuration
|
|
11
|
-
|
|
12
|
-
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
|
|
13
|
-
|
|
14
|
-
```js
|
|
15
|
-
export default tseslint.config([
|
|
16
|
-
globalIgnores(['dist']),
|
|
17
|
-
{
|
|
18
|
-
files: ['**/*.{ts,tsx}'],
|
|
19
|
-
extends: [
|
|
20
|
-
// Other configs...
|
|
21
|
-
|
|
22
|
-
// Remove tseslint.configs.recommended and replace with this
|
|
23
|
-
...tseslint.configs.recommendedTypeChecked,
|
|
24
|
-
// Alternatively, use this for stricter rules
|
|
25
|
-
...tseslint.configs.strictTypeChecked,
|
|
26
|
-
// Optionally, add this for stylistic rules
|
|
27
|
-
...tseslint.configs.stylisticTypeChecked,
|
|
28
|
-
|
|
29
|
-
// Other configs...
|
|
30
|
-
],
|
|
31
|
-
languageOptions: {
|
|
32
|
-
parserOptions: {
|
|
33
|
-
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
|
34
|
-
tsconfigRootDir: import.meta.dirname,
|
|
35
|
-
},
|
|
36
|
-
// other options...
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
])
|
|
3
|
+
```bash
|
|
4
|
+
npm i @slotjs/hooks
|
|
40
5
|
```
|
|
41
6
|
|
|
42
|
-
|
|
7
|
+
```tsx
|
|
8
|
+
import { useResponsive } from "@slotjs/hooks";
|
|
43
9
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
import reactX from 'eslint-plugin-react-x'
|
|
47
|
-
import reactDom from 'eslint-plugin-react-dom'
|
|
10
|
+
const Index: React.FC = () => {
|
|
11
|
+
const isReady = useResponsive();
|
|
48
12
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
// Enable lint rules for React
|
|
56
|
-
reactX.configs['recommended-typescript'],
|
|
57
|
-
// Enable lint rules for React DOM
|
|
58
|
-
reactDom.configs.recommended,
|
|
59
|
-
],
|
|
60
|
-
languageOptions: {
|
|
61
|
-
parserOptions: {
|
|
62
|
-
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
|
63
|
-
tsconfigRootDir: import.meta.dirname,
|
|
64
|
-
},
|
|
65
|
-
// other options...
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
])
|
|
13
|
+
return isReady ? (
|
|
14
|
+
<ContentContainer>content</ContentContainer>
|
|
15
|
+
) : (
|
|
16
|
+
<FullScreenWrapper>loading</FullScreenWrapper>
|
|
17
|
+
);
|
|
18
|
+
};
|
|
69
19
|
```
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A React hook to set the root font size based on the viewport width.
|
|
3
|
+
* It scales the font size up to a maximum of 2x the base font size.
|
|
4
|
+
* This is useful for responsive designs where the font size needs to adapt to different screen sizes.
|
|
5
|
+
* It listens for window resize events to adjust the font size dynamically.
|
|
6
|
+
*
|
|
7
|
+
* @param baseWidth
|
|
8
|
+
* @param baseFontSize
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const isReady = useResponsive(1920, 16);
|
|
12
|
+
* ```
|
|
13
|
+
* // This will set the root font size based on a base width of 1920px
|
|
14
|
+
* // and a base font size of 16px.
|
|
15
|
+
* // The hook returns true once the font size has been set, allowing components to render correctly
|
|
16
|
+
* // with the appropriate font size.
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
export declare function useResponsive(baseWidth?: number, baseFontSize?: number): boolean;
|
|
20
|
+
|
|
21
|
+
export { }
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slotjs/hooks",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.3",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"description": "
|
|
6
|
+
"description": "@slotjs/hooks for react",
|
|
7
7
|
"homepage": "https://github.com/slotjs/hooks.git#readme",
|
|
8
8
|
"bugs": {
|
|
9
9
|
"url": "https://github.com/slotjs/hooks.git/issues"
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"author": "iamwjun",
|
|
17
17
|
"scripts": {
|
|
18
18
|
"dev": "vite",
|
|
19
|
+
"types": "tsc -p tsconfig.build.json",
|
|
19
20
|
"build": "tsc -b && vite build",
|
|
20
21
|
"lint": "eslint .",
|
|
21
22
|
"preview": "vite preview",
|
|
@@ -30,6 +31,7 @@
|
|
|
30
31
|
"@eslint/js": "^9.32.0",
|
|
31
32
|
"@testing-library/jest-dom": "^6.6.4",
|
|
32
33
|
"@testing-library/react": "^16.3.0",
|
|
34
|
+
"@types/node": "^24.3.0",
|
|
33
35
|
"@types/react": "^19.1.9",
|
|
34
36
|
"@types/react-dom": "^19.1.7",
|
|
35
37
|
"@vitejs/plugin-react": "^4.7.0",
|
|
@@ -41,9 +43,21 @@
|
|
|
41
43
|
"typescript": "~5.8.3",
|
|
42
44
|
"typescript-eslint": "^8.39.0",
|
|
43
45
|
"vite": "^7.1.0",
|
|
46
|
+
"vite-plugin-dts": "^4.5.4",
|
|
44
47
|
"vitest": "^3.2.4"
|
|
45
48
|
},
|
|
46
49
|
"files": [
|
|
47
|
-
"dist"
|
|
48
|
-
|
|
50
|
+
"dist",
|
|
51
|
+
"README.md"
|
|
52
|
+
],
|
|
53
|
+
"main": "dist/index.umd.js",
|
|
54
|
+
"module": "dist/index.es.js",
|
|
55
|
+
"types": "dist/types/index.d.ts",
|
|
56
|
+
"exports": {
|
|
57
|
+
".": {
|
|
58
|
+
"import": "./dist/index.es.js",
|
|
59
|
+
"require": "./dist/index.umd.js",
|
|
60
|
+
"types": "./dist/types/index.d.ts"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
49
63
|
}
|
|
File without changes
|
|
File without changes
|