react-artasys-ui 0.1.8 → 0.1.9
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/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/lib/Select/Option.d.ts +1 -1
- package/lib/Select/Select.d.ts +2 -2
- package/package.json +2 -2
- package/src/Dropdown/Dropdown.tsx +9 -2
- package/src/Select/Option.tsx +4 -2
- package/src/Select/Select.tsx +8 -6
- package/src/Select/style.module.css +12 -5
- package/src/Spinner/style.module.css +4 -0
package/lib/Select/Option.d.ts
CHANGED
|
@@ -4,5 +4,5 @@ export interface IOption extends LiHTMLAttributes<HTMLLIElement> {
|
|
|
4
4
|
disabled?: boolean;
|
|
5
5
|
children?: string | React.ReactElement;
|
|
6
6
|
}
|
|
7
|
-
declare const Option: ({ children, value, disabled, onClick, ...props }: IOption) => JSX.Element;
|
|
7
|
+
declare const Option: ({ children, value, disabled, hidden, onClick, ...props }: IOption) => JSX.Element | null;
|
|
8
8
|
export default Option;
|
package/lib/Select/Select.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FunctionComponentElement } from "react";
|
|
1
|
+
import { FunctionComponentElement, ReactNode } from "react";
|
|
2
2
|
import { IElement } from "../Form/Element";
|
|
3
3
|
import type { IOptgroup } from "./Optgroup";
|
|
4
4
|
import type { IOption } from "./Option";
|
|
@@ -9,7 +9,7 @@ export declare const Context: import("react").Context<{
|
|
|
9
9
|
setSelected: (value: string) => void;
|
|
10
10
|
setTitle: (title: IOption['children']) => void;
|
|
11
11
|
}>;
|
|
12
|
-
export type TOptionElement = FunctionComponentElement<IOption> | FunctionComponentElement<IOption>[];
|
|
12
|
+
export type TOptionElement = FunctionComponentElement<IOption> | FunctionComponentElement<IOption>[] | ReactNode;
|
|
13
13
|
export interface ISelect extends Omit<IElement, 'children'> {
|
|
14
14
|
children?: TOptionElement | FunctionComponentElement<IOptgroup> | FunctionComponentElement<IOptgroup>[];
|
|
15
15
|
onChangeSelect?: (value: string) => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-artasys-ui",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"react-hook-form": "^7.47.0"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
|
-
|
|
49
|
+
"react": "^18.2.0",
|
|
50
50
|
"react-dom": "^18.2.0"
|
|
51
51
|
}
|
|
52
52
|
}
|
|
@@ -28,6 +28,7 @@ export interface IDropdown extends AllHTMLAttributes<HTMLDivElement> {
|
|
|
28
28
|
|
|
29
29
|
const Dropdown = ({children, className, items, direction = 'down', position = 'right', split = false, disabled, hover = false, ...props}: IDropdown) => {
|
|
30
30
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
31
|
+
const hoverTimeout = useRef<ReturnType<typeof setTimeout>>();
|
|
31
32
|
const [isOpen, setOpen] = useState(false);
|
|
32
33
|
|
|
33
34
|
const close = () => {
|
|
@@ -61,7 +62,13 @@ const Dropdown = ({children, className, items, direction = 'down', position = 'r
|
|
|
61
62
|
|
|
62
63
|
const handleMouseEnter = () => {
|
|
63
64
|
if (!hover || isOpen) return;
|
|
64
|
-
toggle
|
|
65
|
+
hoverTimeout.current = setTimeout(toggle, 50);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const handleMouseOut = () => {
|
|
69
|
+
if (hoverTimeout.current) {
|
|
70
|
+
clearTimeout(hoverTimeout.current);
|
|
71
|
+
}
|
|
65
72
|
};
|
|
66
73
|
|
|
67
74
|
useEffect(() => {
|
|
@@ -84,7 +91,7 @@ const Dropdown = ({children, className, items, direction = 'down', position = 'r
|
|
|
84
91
|
return(<Context.Provider value={{
|
|
85
92
|
close
|
|
86
93
|
}}>
|
|
87
|
-
<div {...props} className={classes.join(' ')} ref={containerRef} onMouseEnter={handleMouseEnter} tabIndex={1} onBlur={handleBlur}>
|
|
94
|
+
<div {...props} className={classes.join(' ')} ref={containerRef} onMouseEnter={handleMouseEnter} onMouseLeave={handleMouseOut} tabIndex={1} onBlur={handleBlur}>
|
|
88
95
|
{(position === 'left' && !disabled) && <Arrow className={styles['arrow']} onClick={handleClickArrow}/>}
|
|
89
96
|
<div onClick={handleClick}>
|
|
90
97
|
{children}
|
package/src/Select/Option.tsx
CHANGED
|
@@ -13,7 +13,7 @@ export interface IOption extends LiHTMLAttributes<HTMLLIElement> {
|
|
|
13
13
|
children?: string | React.ReactElement;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
const Option = ({children, value, disabled, onClick, ...props}: IOption) => {
|
|
16
|
+
const Option = ({children, value, disabled, hidden, onClick, ...props}: IOption) => {
|
|
17
17
|
const context = useContext(Context);
|
|
18
18
|
|
|
19
19
|
const handleClick = (e: MouseEvent<HTMLLIElement>) => {
|
|
@@ -33,12 +33,14 @@ const Option = ({children, value, disabled, onClick, ...props}: IOption) => {
|
|
|
33
33
|
context.emptyValue.current = true;
|
|
34
34
|
}
|
|
35
35
|
}, [context.selected]);
|
|
36
|
+
|
|
37
|
+
if (hidden) return(null);
|
|
36
38
|
|
|
37
39
|
const classes = ['ui-select-option'];
|
|
38
40
|
classes.push(styles['option']);
|
|
39
41
|
if (context.selected === value) classes.push(styles['active'], 'active');
|
|
40
42
|
if (disabled) classes.push(styles['disabled'], 'disabled');
|
|
41
|
-
|
|
43
|
+
|
|
42
44
|
return(<li {...props} onClick={handleClick} className={classes.join(' ')}>{children}</li>);
|
|
43
45
|
};
|
|
44
46
|
|
package/src/Select/Select.tsx
CHANGED
|
@@ -6,7 +6,8 @@ import {
|
|
|
6
6
|
useRef,
|
|
7
7
|
ChangeEvent,
|
|
8
8
|
useImperativeHandle,
|
|
9
|
-
FunctionComponentElement
|
|
9
|
+
FunctionComponentElement,
|
|
10
|
+
ReactNode
|
|
10
11
|
} from "react";
|
|
11
12
|
import Element,{
|
|
12
13
|
IElement
|
|
@@ -24,7 +25,7 @@ export const Context = createContext({
|
|
|
24
25
|
setTitle: (title: IOption['children']) => {},
|
|
25
26
|
});
|
|
26
27
|
|
|
27
|
-
export type TOptionElement = FunctionComponentElement<IOption> | FunctionComponentElement<IOption>[];
|
|
28
|
+
export type TOptionElement = FunctionComponentElement<IOption> | FunctionComponentElement<IOption>[] | ReactNode;
|
|
28
29
|
|
|
29
30
|
export interface ISelect extends Omit<IElement, 'children'> {
|
|
30
31
|
children?: TOptionElement | FunctionComponentElement<IOptgroup> | FunctionComponentElement<IOptgroup>[];
|
|
@@ -61,12 +62,13 @@ const Select = forwardRef<HTMLInputElement, ISelect>(({children, onChangeSelect,
|
|
|
61
62
|
inputRef.current!.dispatchEvent(event);
|
|
62
63
|
};
|
|
63
64
|
|
|
64
|
-
const setSelect = (
|
|
65
|
+
const setSelect = (val: string) => {
|
|
65
66
|
if (typeof onChangeSelect === 'function') {
|
|
66
|
-
onChangeSelect(
|
|
67
|
+
onChangeSelect(val);
|
|
68
|
+
}
|
|
69
|
+
if (typeof value === 'undefined') {
|
|
70
|
+
setSelected(val);
|
|
67
71
|
}
|
|
68
|
-
|
|
69
|
-
setSelected(value);
|
|
70
72
|
close();
|
|
71
73
|
};
|
|
72
74
|
|
|
@@ -35,25 +35,32 @@
|
|
|
35
35
|
position: absolute;
|
|
36
36
|
display: flex;
|
|
37
37
|
flex-direction: column;
|
|
38
|
-
width: 100%;
|
|
38
|
+
min-width: 100%;
|
|
39
39
|
max-height: 40vh;
|
|
40
|
-
|
|
40
|
+
max-height: 40dvh;
|
|
41
41
|
top: calc(100% - 1px);
|
|
42
|
-
|
|
42
|
+
right: -1px;
|
|
43
43
|
margin: 0;
|
|
44
44
|
padding: 0;
|
|
45
45
|
list-style-type: none;
|
|
46
46
|
background-color: #FFFFFF;
|
|
47
47
|
box-shadow: 0px 4px 5px 0px rgb(0 0 0 / 10%);
|
|
48
|
-
|
|
48
|
+
border: 1px solid #CCCCCC;
|
|
49
49
|
overflow: auto;
|
|
50
|
-
border-top: 0;
|
|
51
50
|
opacity: 0;
|
|
52
51
|
visibility: hidden;
|
|
53
52
|
transform: translateY(-10%);
|
|
54
53
|
transition: transform 0.3s ease-in-out, opacity 0.3s, visibility 0.3s;
|
|
55
54
|
}
|
|
56
55
|
|
|
56
|
+
.container.left > .select-list {
|
|
57
|
+
left: -1px;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.container.right > .select-list {
|
|
61
|
+
right: -1px;
|
|
62
|
+
}
|
|
63
|
+
|
|
57
64
|
.container.hidden > .select-list {
|
|
58
65
|
display: none;
|
|
59
66
|
}
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
.spinner {
|
|
4
4
|
--color-rgb: 94, 190, 214;
|
|
5
|
+
display: flex;
|
|
6
|
+
justify-content: center;
|
|
7
|
+
align-items: center;
|
|
5
8
|
width: 100%;
|
|
6
9
|
height: 100%;
|
|
7
10
|
max-width: 100px;
|
|
@@ -9,6 +12,7 @@
|
|
|
9
12
|
aspect-ratio: 1/1;
|
|
10
13
|
padding-left: calc(-0.5rem / 2);
|
|
11
14
|
padding-right: calc(-0.5rem / 2);
|
|
15
|
+
overflow: hidden;
|
|
12
16
|
}
|
|
13
17
|
|
|
14
18
|
.spinner::before {
|