@adamjanicki/ui 1.2.0 → 1.2.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/hooks/index.d.ts +1 -0
- package/hooks/index.js +1 -0
- package/hooks/useScrollLock.d.ts +1 -1
- package/hooks/useScrollLock.js +1 -1
- package/hooks/useWindowResize.d.ts +7 -0
- package/hooks/useWindowResize.js +13 -0
- package/package.json +1 -1
- package/tmp +0 -95
package/hooks/index.d.ts
CHANGED
|
@@ -3,3 +3,4 @@ export { default as useMediaQuery } from "./useMediaQuery";
|
|
|
3
3
|
export { default as useWatchScroll } from "./useWatchScroll";
|
|
4
4
|
export { default as useFocusTrap } from "./useFocusTrap";
|
|
5
5
|
export { default as useScrollToHash } from "./useScrollToHash";
|
|
6
|
+
export { default as useWindowResize } from "./useWindowResize";
|
package/hooks/index.js
CHANGED
|
@@ -3,3 +3,4 @@ export { default as useMediaQuery } from "./useMediaQuery";
|
|
|
3
3
|
export { default as useWatchScroll } from "./useWatchScroll";
|
|
4
4
|
export { default as useFocusTrap } from "./useFocusTrap";
|
|
5
5
|
export { default as useScrollToHash } from "./useScrollToHash";
|
|
6
|
+
export { default as useWindowResize } from "./useWindowResize";
|
package/hooks/useScrollLock.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ type ScrollLock = {
|
|
|
9
9
|
unlock: () => void;
|
|
10
10
|
};
|
|
11
11
|
/**
|
|
12
|
-
* Hook to lock and unlock the scroll position
|
|
12
|
+
* Hook to lock and unlock the scroll position.
|
|
13
13
|
* @returns Object with lock and unlock functions to lock and unlock the scroll position
|
|
14
14
|
*/
|
|
15
15
|
declare const useScrollLock: () => ScrollLock;
|
package/hooks/useScrollLock.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useCallback } from "react";
|
|
2
2
|
/**
|
|
3
|
-
* Hook to lock and unlock the scroll position
|
|
3
|
+
* Hook to lock and unlock the scroll position.
|
|
4
4
|
* @returns Object with lock and unlock functions to lock and unlock the scroll position
|
|
5
5
|
*/
|
|
6
6
|
var useScrollLock = function () {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* A hook that listens for window resize events.
|
|
4
|
+
*
|
|
5
|
+
* @param callback the callback function fired when the window is resized.
|
|
6
|
+
*/
|
|
7
|
+
var useWindowResize = function (callback) {
|
|
8
|
+
useEffect(function () {
|
|
9
|
+
window.addEventListener("resize", callback);
|
|
10
|
+
return function () { return window.removeEventListener("resize", callback); };
|
|
11
|
+
}, [callback]);
|
|
12
|
+
};
|
|
13
|
+
export default useWindowResize;
|
package/package.json
CHANGED
package/tmp
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import React, { forwardRef } from "react";
|
|
2
|
-
import { classNames } from "../../utils/util";
|
|
3
|
-
import { CornerType } from "../../utils/types";
|
|
4
|
-
|
|
5
|
-
type Props = Omit<
|
|
6
|
-
React.DetailedHTMLProps<
|
|
7
|
-
React.SelectHTMLAttributes<HTMLSelectElement>,
|
|
8
|
-
HTMLSelectElement
|
|
9
|
-
>,
|
|
10
|
-
"aria-label"
|
|
11
|
-
> & {
|
|
12
|
-
/**
|
|
13
|
-
* Array of options to display in the select
|
|
14
|
-
*/
|
|
15
|
-
options: string[];
|
|
16
|
-
/**
|
|
17
|
-
* Mapper function to get the value of the option
|
|
18
|
-
*
|
|
19
|
-
* @param option the option to get the value of
|
|
20
|
-
* @returns the value of the option
|
|
21
|
-
*/
|
|
22
|
-
getOptionValue?: (option: string) => string;
|
|
23
|
-
/**
|
|
24
|
-
* Mapper function to get the label of the option
|
|
25
|
-
*
|
|
26
|
-
* @param option the option to get the label of
|
|
27
|
-
* @returns the label of the option
|
|
28
|
-
*/
|
|
29
|
-
getOptionLabel?: (option: string) => string;
|
|
30
|
-
/**
|
|
31
|
-
* [Optional] The corner style of the select element.
|
|
32
|
-
* @default "rounded"
|
|
33
|
-
*/
|
|
34
|
-
corners?: CornerType;
|
|
35
|
-
/**
|
|
36
|
-
* Name of the select for accessibility purposes
|
|
37
|
-
*/
|
|
38
|
-
"aria-label": string;
|
|
39
|
-
/**
|
|
40
|
-
* [Optional] The styles to apply to the select element
|
|
41
|
-
*/
|
|
42
|
-
innerStyle?: React.CSSProperties;
|
|
43
|
-
/**
|
|
44
|
-
* [Optional] The class name to apply to the select element
|
|
45
|
-
*/
|
|
46
|
-
innerClassName?: string;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const identity = (x: string) => x;
|
|
50
|
-
|
|
51
|
-
const Select = (
|
|
52
|
-
{
|
|
53
|
-
className,
|
|
54
|
-
options,
|
|
55
|
-
getOptionValue = identity,
|
|
56
|
-
getOptionLabel = identity,
|
|
57
|
-
corners = "rounded",
|
|
58
|
-
style,
|
|
59
|
-
innerStyle,
|
|
60
|
-
innerClassName,
|
|
61
|
-
...props
|
|
62
|
-
}: Props,
|
|
63
|
-
ref: React.Ref<HTMLSelectElement>
|
|
64
|
-
) => (
|
|
65
|
-
<div className={classNames("ajui-select-container", className)} style={style}>
|
|
66
|
-
<select
|
|
67
|
-
{...props}
|
|
68
|
-
ref={ref}
|
|
69
|
-
className={classNames(
|
|
70
|
-
`ajui-select-base corners--${corners}`,
|
|
71
|
-
innerClassName
|
|
72
|
-
)}
|
|
73
|
-
style={innerStyle}
|
|
74
|
-
>
|
|
75
|
-
{options.map((option, index) => (
|
|
76
|
-
<option key={index} value={getOptionValue(option)}>
|
|
77
|
-
{getOptionLabel(option)}
|
|
78
|
-
</option>
|
|
79
|
-
))}
|
|
80
|
-
</select>
|
|
81
|
-
<svg
|
|
82
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
83
|
-
viewBox="0 0 64 64"
|
|
84
|
-
className="ajui-select-triangle"
|
|
85
|
-
aria-hidden="true"
|
|
86
|
-
>
|
|
87
|
-
<path
|
|
88
|
-
fill="currentColor"
|
|
89
|
-
d="M 29.175781 50.824219 C 30.738281 52.386719 33.273438 52.386719 34.835938 50.824219 L 58.835938 26.824219 C 60.398438 25.261719 60.398438 22.726562 58.835938 21.164062 C 57.273438 19.601562 54.738281 19.601562 53.175781 21.164062 L 32 42.335938 L 10.824219 21.175781 C 9.261719 19.613281 6.726562 19.613281 5.164062 21.175781 C 3.601562 22.738281 3.601562 25.273438 5.164062 26.835938 L 29.164062 50.835938 Z M 29.175781 50.824219"
|
|
90
|
-
/>
|
|
91
|
-
</svg>
|
|
92
|
-
</div>
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
export default forwardRef(Select);
|