react-artasys-ui 0.1.5 → 0.1.6

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.
@@ -10,5 +10,5 @@ export interface IElement<T = any> extends Omit<AllHTMLAttributes<T>, 'children'
10
10
  afterElement?: React.ReactElement;
11
11
  hiddenContainer?: boolean;
12
12
  }
13
- declare const Element: ({ children, beforeElement, afterElement, error, placeholder, disabled, styleContainer, classNameContainer, hiddenContainer, ...props }: IElement) => JSX.Element;
13
+ declare const Element: ({ children, beforeElement, afterElement, error, placeholder, styleContainer, classNameContainer, hiddenContainer, ...props }: IElement) => JSX.Element;
14
14
  export default Element;
@@ -3,7 +3,9 @@ import { IElement } from "../Form/Element";
3
3
  import type { IOption } from "./Option";
4
4
  export declare const Context: import("react").Context<{
5
5
  selected: string;
6
+ emptyValue: import("react").MutableRefObject<boolean>;
6
7
  setSelect: (value: string) => void;
8
+ setSelected: (value: string) => void;
7
9
  setTitle: (title: string) => void;
8
10
  }>;
9
11
  export interface ISelect extends Omit<IElement, 'children' | 'onChange'> {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-artasys-ui",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -19,7 +19,7 @@ export interface IElement<T = any> extends Omit<AllHTMLAttributes<T>, 'children'
19
19
  hiddenContainer?: boolean;
20
20
  }
21
21
 
22
- const Element = ({children, beforeElement, afterElement, error, placeholder, disabled, styleContainer, classNameContainer, hiddenContainer, ...props}: IElement) => {
22
+ const Element = ({children, beforeElement, afterElement, error, placeholder, styleContainer, classNameContainer, hiddenContainer, ...props}: IElement) => {
23
23
  const [currentError, setCurrentError] = useState('');
24
24
 
25
25
  useEffect(() => {
@@ -30,7 +30,7 @@ const Element = ({children, beforeElement, afterElement, error, placeholder, dis
30
30
 
31
31
  classes.push(styles['container']);
32
32
  if (currentError) classes.push(styles['error']);
33
- if (disabled) classes.push(styles['disabled']);
33
+ if (props.disabled) classes.push(styles['disabled']);
34
34
  if (hiddenContainer) classes.push(styles['hidden']);
35
35
  if (classNameContainer) classes.push(classNameContainer);
36
36
 
@@ -27,6 +27,7 @@ const Input = forwardRef<HTMLInputElement, IInput>(({onChange, onInput, onChange
27
27
  };
28
28
 
29
29
  const handleInput = (e: ChangeEvent<HTMLInputElement>) => {
30
+ if (props.disabled) return;
30
31
  if (typeof onInput === 'function') {
31
32
  onInput(e);
32
33
  }
@@ -24,8 +24,12 @@ const Option = ({children, value, onClick, ...props}: IOption) => {
24
24
  };
25
25
 
26
26
  useEffect(() => {
27
- if (value === context.selected && children) {
27
+ if (children && (value === context.selected || !context.emptyValue.current)) {
28
28
  context.setTitle(children?.toString());
29
+ if (!context.emptyValue.current && value) {
30
+ context.setSelected(value);
31
+ }
32
+ context.emptyValue.current = true;
29
33
  }
30
34
  }, [context.selected]);
31
35
 
@@ -13,8 +13,10 @@ import styles from "./style.module.css";
13
13
 
14
14
  export const Context = createContext({
15
15
  selected: '',
16
+ emptyValue: {current:{}} as React.MutableRefObject<boolean>,
16
17
  setSelect: (value: string) => {},
17
- setTitle: (title: string) => {}
18
+ setSelected: (value: string) => {},
19
+ setTitle: (title: string) => {},
18
20
  });
19
21
 
20
22
  export interface ISelect extends Omit<IElement, 'children' | 'onChange'> {
@@ -24,19 +26,19 @@ export interface ISelect extends Omit<IElement, 'children' | 'onChange'> {
24
26
 
25
27
  const Select = forwardRef<HTMLInputElement, ISelect>(({children, onChange, value, ...props}, ref) => {
26
28
  const containerRef = useRef<HTMLDivElement>(null);
29
+ const emptyValue = useRef(false);
27
30
 
31
+ const [isOpen, setOpen] = useState(false);
28
32
  const [selected, setSelected] = useState('');
29
33
  const [title, setTitle] = useState<string>();
30
34
 
31
35
  const open = () => {
32
- const element = containerRef.current;
33
- element?.classList.add(styles['opened']);
34
- element?.focus();
36
+ if (props.disabled) return;
37
+ setOpen(true);
35
38
  };
36
39
 
37
40
  const close = () => {
38
- const element = containerRef.current;
39
- element?.classList.remove(styles['opened']);
41
+ setOpen(false);
40
42
  };
41
43
 
42
44
  const setSelect = (value: string) => {
@@ -51,15 +53,40 @@ const Select = forwardRef<HTMLInputElement, ISelect>(({children, onChange, value
51
53
  if (typeof value === 'undefined') return;
52
54
  setSelected(String(value));
53
55
  }, [value]);
56
+
57
+ useEffect(() => {
58
+ const element = containerRef.current;
59
+ const classList = element!.classList;
60
+ if (isOpen) {
61
+ classList.remove(styles['hidden']);
62
+ requestAnimationFrame(() => {
63
+ classList.add(styles['opened']);
64
+ element?.focus();
65
+ });
66
+ }else{
67
+ if (classList.contains(styles['opened'])) {
68
+ element!.ontransitionend = () => {
69
+ classList.add(styles['hidden']);
70
+ element!.ontransitionend = null;
71
+ };
72
+ }
73
+ classList.remove(styles['opened']);
74
+ }
75
+ }, [isOpen]);
76
+
77
+ const classes = [''];
78
+ classes.push(styles['container'], styles['hidden']);
54
79
 
55
- return(<Element {...props} styleContainer={{zIndex: 1}}>
80
+ return(<Element {...props} classNameContainer={styles['container-element']}>
56
81
  { (props) => <Context.Provider value={{
57
82
  selected,
83
+ emptyValue: emptyValue,
58
84
  setSelect,
85
+ setSelected,
59
86
  setTitle
60
87
  }}>
61
88
  <input {...props} type="hidden" value={selected} ref={ref}/>
62
- <div className={styles['container']} ref={containerRef} tabIndex={1} onBlur={close}>
89
+ <div className={classes.join(' ')} ref={containerRef} tabIndex={1} onBlur={close}>
63
90
  <div className={styles['select']} onClick={open}>
64
91
  <span className={styles['title']}>{title}</span>
65
92
  </div>
@@ -1,5 +1,9 @@
1
1
  /* Select */
2
2
 
3
+ .container-element {
4
+ z-index: 1;
5
+ }
6
+
3
7
  .container {
4
8
  position: relative;
5
9
  display: flex;
@@ -13,7 +17,8 @@
13
17
  display: flex;
14
18
  flex-direction: row;
15
19
  align-items: center;
16
- min-height: 20px;
20
+ min-height: 45px;
21
+ box-sizing: border-box;
17
22
  padding: 10px;
18
23
  }
19
24
 
@@ -28,6 +33,10 @@
28
33
  transition: rotate 0.3s;
29
34
  }
30
35
 
36
+ .container-element:has(input[type="hidden"]:disabled) .select::after {
37
+ border-top-color: #CCCCCC;
38
+ }
39
+
31
40
  .container.opened > .select::after {
32
41
  rotate: 180deg;
33
42
  }
@@ -37,6 +46,8 @@
37
46
  display: flex;
38
47
  flex-direction: column;
39
48
  width: 100%;
49
+ max-height: 40vh;
50
+ max-height: 40dvh;
40
51
  top: calc(100% - 1px);
41
52
  left: -1px;
42
53
  margin: 0;
@@ -44,8 +55,8 @@
44
55
  list-style-type: none;
45
56
  background-color: #FFFFFF;
46
57
  box-shadow: 0px 4px 5px 0px rgb(0 0 0 / 10%);
47
- box-shadow: 0px 4px 5px 0px rgb(0 0 0 / 10%);
48
58
  border: 1px solid #CCCCCC;
59
+ overflow: auto;
49
60
  border-top: 0;
50
61
  opacity: 0;
51
62
  visibility: hidden;
@@ -53,6 +64,10 @@
53
64
  transition: transform 0.3s ease-in-out, opacity 0.3s, visibility 0.3s;
54
65
  }
55
66
 
67
+ .container.hidden > .select-list {
68
+ display: none;
69
+ }
70
+
56
71
  .container.opened > .select-list {
57
72
  opacity: 1;
58
73
  transform: translateY(0);