react-artasys-ui 0.1.14 → 0.1.15
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/Dropdown/Items.d.ts +6 -0
- package/package.json +1 -1
- package/src/Dropdown/Dropdown.tsx +9 -14
- package/src/Dropdown/Items.tsx +28 -0
- package/src/Dropdown/style.module.css +17 -0
package/package.json
CHANGED
|
@@ -4,7 +4,9 @@ import {
|
|
|
4
4
|
useState,
|
|
5
5
|
FunctionComponentElement,
|
|
6
6
|
useEffect,
|
|
7
|
-
createContext
|
|
7
|
+
createContext,
|
|
8
|
+
Children,
|
|
9
|
+
type FocusEvent
|
|
8
10
|
} from "react";
|
|
9
11
|
import styles from "./style.module.css";
|
|
10
12
|
import Arrow from "../Components/Arrow";
|
|
@@ -12,6 +14,7 @@ import type {
|
|
|
12
14
|
IItem,
|
|
13
15
|
TChildrenAction
|
|
14
16
|
} from "./Item";
|
|
17
|
+
import Items from "./Items";
|
|
15
18
|
|
|
16
19
|
export const Context = createContext<TChildrenAction>({
|
|
17
20
|
close: () => {}
|
|
@@ -47,15 +50,11 @@ const Dropdown = ({children, className, items, direction = 'down', position = 'r
|
|
|
47
50
|
};
|
|
48
51
|
|
|
49
52
|
const handleClick = () => {
|
|
50
|
-
if (
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
if (hover) {
|
|
54
|
-
close();
|
|
55
|
-
}
|
|
53
|
+
if (hoverTimeout.current) return;
|
|
54
|
+
if (!split || hover) toggle();
|
|
56
55
|
};
|
|
57
56
|
|
|
58
|
-
const handleBlur = (e:
|
|
57
|
+
const handleBlur = (e: FocusEvent) => {
|
|
59
58
|
if (e.currentTarget.contains(e.relatedTarget)) return;
|
|
60
59
|
close();
|
|
61
60
|
};
|
|
@@ -93,15 +92,11 @@ const Dropdown = ({children, className, items, direction = 'down', position = 'r
|
|
|
93
92
|
}}>
|
|
94
93
|
<div {...props} className={classes.join(' ')} ref={containerRef} onMouseEnter={handleMouseEnter} onMouseLeave={handleMouseOut} tabIndex={1} onBlur={handleBlur}>
|
|
95
94
|
{(position === 'left' && !disabled) && <Arrow className={styles['arrow']} onClick={handleClickArrow}/>}
|
|
96
|
-
<div onClick={handleClick}>
|
|
95
|
+
<div onClick={handleClick} className={'ui-dropdown-block' + (isOpen ? ' ' + styles['hide'] : '')}>
|
|
97
96
|
{children}
|
|
98
97
|
</div>
|
|
99
98
|
{(position === 'right' && !disabled) && <Arrow className={styles['arrow']} onClick={handleClickArrow}/>}
|
|
100
|
-
{
|
|
101
|
-
(items && !disabled) && <ul className={styles['dropdown-list']}>
|
|
102
|
-
{items}
|
|
103
|
-
</ul>
|
|
104
|
-
}
|
|
99
|
+
<Items isOpen={isOpen} disabled={disabled} items={items}/>
|
|
105
100
|
</div>
|
|
106
101
|
</Context.Provider>);
|
|
107
102
|
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import styles from "./style.module.css";
|
|
2
|
+
import type { IDropdown } from "./Dropdown";
|
|
3
|
+
import { useEffect, useRef } from "react";
|
|
4
|
+
|
|
5
|
+
interface IItems extends Pick<IDropdown, 'items' | 'disabled'> {
|
|
6
|
+
isOpen: boolean;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const Items = ({items, isOpen, disabled}: IItems) => {
|
|
10
|
+
const listRef = useRef<HTMLUListElement>(null);
|
|
11
|
+
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (!listRef.current) return;
|
|
14
|
+
const screenWidth = window.innerWidth;
|
|
15
|
+
const element = listRef.current.getBoundingClientRect();
|
|
16
|
+
// console.log(element.left)
|
|
17
|
+
if (element.left <= 0) {
|
|
18
|
+
|
|
19
|
+
// listRef.current.style.transform = 'translateX(' + Math.abs(element.left) + 'px)';
|
|
20
|
+
}
|
|
21
|
+
},[isOpen]);
|
|
22
|
+
|
|
23
|
+
if (disabled) return null;
|
|
24
|
+
|
|
25
|
+
return(<ul className={styles['dropdown-list']} children={items} ref={listRef}/>);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export default Items;
|
|
@@ -9,6 +9,23 @@
|
|
|
9
9
|
cursor: pointer;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
.container > :global(.ui-dropdown-block) {
|
|
13
|
+
position: relative;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.container > :global(.ui-dropdown-block)::after {
|
|
17
|
+
content: "";
|
|
18
|
+
position: absolute;
|
|
19
|
+
left: 0;
|
|
20
|
+
top: 0;
|
|
21
|
+
width: 100%;
|
|
22
|
+
height: 100%;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.container > :global(.ui-dropdown-block).hide::after {
|
|
26
|
+
display: none;
|
|
27
|
+
}
|
|
28
|
+
|
|
12
29
|
.arrow {
|
|
13
30
|
padding: 5px;
|
|
14
31
|
}
|