react-artasys-ui 0.1.20 → 0.1.22

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.
Files changed (132) hide show
  1. package/dist/index.js +2 -2
  2. package/dist/index.js.map +1 -1
  3. package/lib/Button/Button.d.ts +12 -10
  4. package/lib/Button/index.d.ts +3 -2
  5. package/lib/Checkbox/Checkbox.d.ts +7 -7
  6. package/lib/Components/Arrow/Arrow.d.ts +6 -6
  7. package/lib/Dropdown/Dropdown.d.ts +18 -16
  8. package/lib/Dropdown/Item.d.ts +11 -11
  9. package/lib/Dropdown/Items.d.ts +6 -6
  10. package/lib/File/File.d.ts +18 -17
  11. package/lib/FileInput/FileInput.d.ts +13 -0
  12. package/lib/FileInput/index.d.ts +3 -0
  13. package/lib/Form/Element/Element.d.ts +16 -15
  14. package/lib/Form/Form.d.ts +10 -11
  15. package/lib/Input/Input.d.ts +11 -8
  16. package/lib/Loading/Loading.d.ts +6 -0
  17. package/lib/Loading/index.d.ts +3 -0
  18. package/lib/Progress/Progress.d.ts +7 -7
  19. package/lib/Provider/Provider.d.ts +7 -0
  20. package/lib/Provider/ProviderContext.d.ts +1 -0
  21. package/lib/Provider/index.d.ts +2 -0
  22. package/lib/Select/Optgroup.d.ts +7 -8
  23. package/lib/Select/Option.d.ts +8 -8
  24. package/lib/Select/Select.d.ts +18 -18
  25. package/lib/Spinner/Spinner.d.ts +8 -7
  26. package/lib/Spinner/index.d.ts +3 -3
  27. package/lib/TextArea/TextArea.d.ts +10 -7
  28. package/lib/UploadImages/Image.d.ts +16 -16
  29. package/lib/UploadImages/UploadImages.d.ts +9 -9
  30. package/lib/index.d.ts +19 -16
  31. package/lib/src/Button/Button.d.ts +12 -0
  32. package/lib/src/Button/index.d.ts +3 -0
  33. package/lib/src/Checkbox/Checkbox.d.ts +7 -0
  34. package/{src/Checkbox/index.tsx → lib/src/Checkbox/index.d.ts} +2 -2
  35. package/lib/src/Components/Arrow/Arrow.d.ts +6 -0
  36. package/{src/Components/Arrow/index.tsx → lib/src/Components/Arrow/index.d.ts} +2 -3
  37. package/lib/src/Dropdown/Dropdown.d.ts +18 -0
  38. package/lib/src/Dropdown/Item.d.ts +11 -0
  39. package/lib/src/Dropdown/Items.d.ts +6 -0
  40. package/lib/src/Dropdown/index.d.ts +9 -0
  41. package/lib/src/File/File.d.ts +18 -0
  42. package/lib/src/File/index.d.ts +3 -0
  43. package/lib/src/FileInput/FileInput.d.ts +14 -0
  44. package/lib/src/FileInput/index.d.ts +3 -0
  45. package/lib/src/Form/Element/Element.d.ts +16 -0
  46. package/lib/src/Form/Element/index.d.ts +3 -0
  47. package/lib/src/Form/Form.d.ts +10 -0
  48. package/{src/Form/index.tsx → lib/src/Form/index.d.ts} +5 -8
  49. package/{src/Form/types.ts → lib/src/Form/types.d.ts} +11 -17
  50. package/lib/src/Form/useForm.d.ts +17 -0
  51. package/lib/src/Input/Input.d.ts +11 -0
  52. package/{src/Input/index.tsx → lib/src/Input/index.d.ts} +2 -3
  53. package/lib/src/Loading/Loading.d.ts +6 -0
  54. package/lib/src/Loading/index.d.ts +3 -0
  55. package/lib/src/Progress/Progress.d.ts +7 -0
  56. package/{src/Progress/index.tsx → lib/src/Progress/index.d.ts} +2 -3
  57. package/lib/src/Provider/Provider.d.ts +7 -0
  58. package/lib/src/Provider/ProviderContext.d.ts +1 -0
  59. package/lib/src/Provider/index.d.ts +2 -0
  60. package/lib/src/Select/Optgroup.d.ts +7 -0
  61. package/lib/src/Select/Option.d.ts +8 -0
  62. package/lib/src/Select/Select.d.ts +18 -0
  63. package/lib/src/Select/index.d.ts +11 -0
  64. package/lib/src/Spinner/Spinner.d.ts +8 -0
  65. package/lib/src/Spinner/index.d.ts +3 -0
  66. package/lib/src/TextArea/TextArea.d.ts +9 -0
  67. package/{src/TextArea/index.tsx → lib/src/TextArea/index.d.ts} +2 -3
  68. package/lib/src/UploadImages/Image.d.ts +16 -0
  69. package/lib/src/UploadImages/UploadImages.d.ts +9 -0
  70. package/lib/src/UploadImages/index.d.ts +5 -0
  71. package/lib/src/index.d.ts +19 -0
  72. package/lib/src/ui-types.d.ts +3 -0
  73. package/lib/stories/Button.stories.d.ts +6 -0
  74. package/lib/stories/Checkbox.stories.d.ts +6 -0
  75. package/lib/stories/Dropdown/Dropdown.stories.d.ts +6 -0
  76. package/lib/stories/Dropdown/Item.stories.d.ts +6 -0
  77. package/lib/stories/Dropdown/Items.stories.d.ts +6 -0
  78. package/lib/stories/File.stories.d.ts +6 -0
  79. package/lib/stories/FileInput.stories.d.ts +9 -0
  80. package/lib/stories/Form/Element/Element.stories.d.ts +6 -0
  81. package/lib/stories/Form/Form.stories.d.ts +6 -0
  82. package/lib/stories/Input.stories.d.ts +6 -0
  83. package/lib/stories/Loading.stories.d.ts +6 -0
  84. package/lib/stories/Progress.stories.d.ts +6 -0
  85. package/lib/stories/Select/Select.stories.d.ts +6 -0
  86. package/lib/stories/Spinner.stories.d.ts +6 -0
  87. package/lib/stories/TextArea.stories.d.ts +6 -0
  88. package/lib/ui-types.d.ts +3 -0
  89. package/package.json +26 -5
  90. package/__tests__/static.test.js +0 -0
  91. package/babel.config.json +0 -3
  92. package/src/Button/Button.tsx +0 -29
  93. package/src/Button/index.tsx +0 -3
  94. package/src/Button/style.module.css +0 -45
  95. package/src/Checkbox/Checkbox.tsx +0 -22
  96. package/src/Checkbox/style.module.css +0 -74
  97. package/src/Components/Arrow/Arrow.tsx +0 -18
  98. package/src/Components/Arrow/style.module.css +0 -40
  99. package/src/Dropdown/Dropdown.tsx +0 -113
  100. package/src/Dropdown/Item.tsx +0 -42
  101. package/src/Dropdown/Items.tsx +0 -38
  102. package/src/Dropdown/index.tsx +0 -28
  103. package/src/Dropdown/style.module.css +0 -89
  104. package/src/File/File.tsx +0 -85
  105. package/src/File/index.tsx +0 -9
  106. package/src/Form/Element/Element.tsx +0 -54
  107. package/src/Form/Element/index.tsx +0 -7
  108. package/src/Form/Element/style.module.css +0 -119
  109. package/src/Form/Form.tsx +0 -40
  110. package/src/Form/style.module.css +0 -30
  111. package/src/Form/useForm.tsx +0 -76
  112. package/src/Input/Input.tsx +0 -49
  113. package/src/Input/style.module.css +0 -16
  114. package/src/Progress/Progress.tsx +0 -28
  115. package/src/Progress/style.module.css +0 -72
  116. package/src/Select/Optgroup.tsx +0 -19
  117. package/src/Select/Option.tsx +0 -47
  118. package/src/Select/Select.tsx +0 -143
  119. package/src/Select/index.tsx +0 -33
  120. package/src/Select/style.module.css +0 -117
  121. package/src/Spinner/Spinner.tsx +0 -21
  122. package/src/Spinner/index.tsx +0 -8
  123. package/src/Spinner/style.module.css +0 -65
  124. package/src/TextArea/TextArea.tsx +0 -57
  125. package/src/UploadImages/Image.tsx +0 -86
  126. package/src/UploadImages/UploadImages.tsx +0 -57
  127. package/src/UploadImages/index.tsx +0 -13
  128. package/src/UploadImages/style.module.css +0 -108
  129. package/src/index.ts +0 -62
  130. package/tsconfig.json +0 -118
  131. package/types.d.ts +0 -1
  132. package/webpack.config.js +0 -59
@@ -1,45 +0,0 @@
1
- /* Button */
2
-
3
- .container {
4
- position: relative;
5
- border: 1px solid #5EBED6;
6
- background-color: #BED4DB;
7
- }
8
-
9
- .container button {
10
- display: block;
11
- width: 100%;
12
- height: 100%;
13
- border: 0;
14
- padding: 5px 8px;
15
- font-size: 1.1em;
16
- color: #1D1D1B;
17
- cursor: pointer;
18
- border-radius: 0.1em;
19
- transition: background-color 0.3s;
20
- }
21
-
22
- .container button:hover {
23
- background-color: #ADCED8;
24
- color: #1D1D1B;
25
- }
26
-
27
- .container > .wait-indicator {
28
- position: absolute;
29
- display: flex;
30
- top: 0;
31
- left: 0;
32
- width: 100%;
33
- height: 100%;
34
- justify-content: center;
35
- align-items: center;
36
- background-color: inherit;
37
- z-index: -1;
38
- opacity: 0;
39
- transition: opacity 0.3s;
40
- }
41
-
42
- .container > .wait-indicator.active {
43
- opacity: 1;
44
- z-index: 1;
45
- }
@@ -1,22 +0,0 @@
1
- import { forwardRef } from "react";
2
- import Element,{
3
- IElement
4
- } from "../Form/Element";
5
- import styles from "./style.module.css";
6
-
7
- interface ICheckbox extends IElement<HTMLInputElement> {
8
- type?: 'checkbox' | 'radio';
9
- }
10
-
11
- const Checkbox = forwardRef<HTMLInputElement, ICheckbox>(({type = 'checkbox', hiddenContainer = true, placeholder, ...props}, ref) => {
12
-
13
- return(<Element {...props} hiddenContainer={hiddenContainer}>
14
- {(props) => <div className={'ui-checkbox-container ' + styles['container']}>
15
- <input {...props} className={'ui-checkbox' + (props.className ? ' ' + props.className : '')} type={type} ref={ref}/>
16
- <span className={'ui-checkbox-indicator ' + styles['indicator']}/>
17
- <span className={'ui-checkbox-text ' + styles['text']}>{placeholder}</span>
18
- </div>}
19
- </Element>);
20
- });
21
-
22
- export default Checkbox;
@@ -1,74 +0,0 @@
1
- /* Checkbox */
2
-
3
- .container {
4
- display: flex;
5
- flex-direction: row;
6
- justify-content: flex-start;
7
- align-items: center;
8
- height: 100%;
9
- cursor: pointer;
10
- user-select: none;
11
- gap: 10px;
12
- }
13
-
14
- .container > input {
15
- display: none;
16
- }
17
-
18
- .text {
19
- color: #1D1D1B;
20
- font-size: 1.1em;
21
- }
22
-
23
- .indicator {
24
- display: flex;
25
- position: relative;
26
- justify-content: center;
27
- align-items: center;
28
- border: 1px solid #5EBED6;
29
- background-color: #BED4DB;
30
- width: 20px;
31
- height: 20px;
32
- aspect-ratio: 1/1;
33
- }
34
-
35
- .container > input[type="radio"] ~ .indicator {
36
- border-radius: 50%;
37
- }
38
-
39
- .container:hover > .indicator {
40
- background-color: #5EBED65F;
41
- }
42
-
43
- .indicator::before {
44
- content: "";
45
- position: absolute;
46
- top: 0;
47
- width: 35%;
48
- height: 70%;
49
- border: solid #1D1D1B;
50
- border-width: 0 2px 2px 0;
51
- transform: rotate( 45deg);
52
- scale: 0;
53
- opacity: 0;
54
- transition: scale 0.1s, opacity 0.1s;
55
- }
56
-
57
- .container > input[type="radio"] ~ .indicator::before {
58
- border-width: 0;
59
- border-radius: inherit;
60
- top: unset;
61
- transform: unset;
62
- width: 70%;
63
- height: 70%;
64
- background-color: #1D1D1B;
65
- }
66
-
67
- .container > input:checked ~ .indicator {
68
- background-color: #5EBED65F;
69
- }
70
-
71
- .container > input:checked ~ .indicator::before {
72
- scale: 1;
73
- opacity: 1;
74
- }
@@ -1,18 +0,0 @@
1
- import { AllHTMLAttributes } from "react";
2
- import styles from "./style.module.css";
3
-
4
- interface IArrow extends AllHTMLAttributes<HTMLDivElement> {
5
- direction?: 'up' | 'down' | 'left' | 'right';
6
- };
7
-
8
- const Arrow = ({className, direction = 'down', ...props}: IArrow) => {
9
-
10
- const classes = ['ui-component-arrow'];
11
- classes.push(styles['container']);
12
- if (direction) classes.push(styles[direction]);
13
- if (className) classes.push(className);
14
-
15
- return(<div {...props} className={classes.join(' ')}/>);
16
- };
17
-
18
- export default Arrow;
@@ -1,40 +0,0 @@
1
- /* Arrow Component */
2
-
3
- .container {
4
- --ui-arrow-size: 10px;
5
- --ui-arrow-color: #5EBED6;
6
- --ui-arrow-max: var(--ui-arrow-size) solid var(--ui-arrow-color);
7
- --ui-arrow-min: calc(var(--ui-arrow-size) / 2) solid transparent;
8
- }
9
-
10
- .container::after {
11
- content: "";
12
- display: block;
13
- width: 0;
14
- height: 0;
15
- transition: rotate 0.1s;
16
- }
17
-
18
- .container.down::after {
19
- border-left: var(--ui-arrow-min);
20
- border-right: var(--ui-arrow-min);
21
- border-top: var(--ui-arrow-max);
22
- }
23
-
24
- .container.up::after {
25
- border-left: var(--ui-arrow-min);
26
- border-right: var(--ui-arrow-min);
27
- border-bottom: var(--ui-arrow-max);
28
- }
29
-
30
- .container.left::after {
31
- border-top: var(--ui-arrow-min);
32
- border-right: var(--ui-arrow-max);
33
- border-bottom: var(--ui-arrow-min);
34
- }
35
-
36
- .container.right::after {
37
- border-top: var(--ui-arrow-min);
38
- border-left: var(--ui-arrow-max);
39
- border-bottom: var(--ui-arrow-min);
40
- }
@@ -1,113 +0,0 @@
1
- import {
2
- AllHTMLAttributes,
3
- useRef,
4
- useState,
5
- FunctionComponentElement,
6
- useEffect,
7
- createContext,
8
- Children,
9
- type FocusEvent
10
- } from "react";
11
- import styles from "./style.module.css";
12
- import Arrow from "../Components/Arrow";
13
- import type {
14
- IItem,
15
- TChildrenAction
16
- } from "./Item";
17
- import Items from "./Items";
18
-
19
- export const Context = createContext<TChildrenAction>({
20
- close: () => {}
21
- });
22
-
23
- export interface IDropdown extends AllHTMLAttributes<HTMLDivElement> {
24
- direction?: 'down' | 'up';
25
- position?: 'left' | 'right';
26
- split?: boolean;
27
- hover?: boolean;
28
- items?: FunctionComponentElement<IItem> | FunctionComponentElement<IItem>[];
29
- disabled?: boolean;
30
- enableRerenderItems?: boolean;
31
- onShow?: () => void;
32
- onHide?: () => void;
33
- };
34
-
35
- const Dropdown = ({children, className, items, direction = 'down', position = 'right', split = false, disabled, hover = false, enableRerenderItems = true, onShow, onHide, ...props}: IDropdown) => {
36
- const containerRef = useRef<HTMLDivElement>(null);
37
- const hoverTimeout = useRef<ReturnType<typeof setTimeout>>();
38
- const [isOpen, setOpen] = useState(false);
39
-
40
- const close = () => {
41
- setOpen(false);
42
- };
43
-
44
- const toggle = () => {
45
- setOpen((isOpen) => {
46
- if (disabled) return false;
47
- return !isOpen;
48
- });
49
- };
50
-
51
- const handleClickArrow = () => {
52
- toggle();
53
- };
54
-
55
- const handleClick = () => {
56
- if (hoverTimeout.current) return;
57
- if (!split || hover) toggle();
58
- };
59
-
60
- const handleBlur = (e: FocusEvent) => {
61
- if (e.currentTarget.contains(e.relatedTarget)) return;
62
- close();
63
- };
64
-
65
- const handleMouseEnter = () => {
66
- if (!hover || isOpen) return;
67
- hoverTimeout.current = setTimeout(toggle, 50);
68
- };
69
-
70
- const handleMouseOut = () => {
71
- if (hoverTimeout.current) {
72
- clearTimeout(hoverTimeout.current);
73
- }
74
- };
75
-
76
- useEffect(() => {
77
- const element = containerRef.current;
78
- const classList = element?.classList;
79
- if (isOpen) {
80
- classList?.add(styles['opened']);
81
- element?.focus();
82
- if (typeof onShow === 'function') {
83
- onShow();
84
- }
85
- }else{
86
- classList?.remove(styles['opened']);
87
- if (typeof onHide === 'function') {
88
- onHide();
89
- }
90
- }
91
- }, [isOpen]);
92
-
93
- const classes = ['ui-dropdown'];
94
- classes.push(styles['container']);
95
- if (className) classes.push(className);
96
- if (direction) classes.push(styles[direction]);
97
- if (position) classes.push(styles[position]);
98
-
99
- return(<Context.Provider value={{
100
- close
101
- }}>
102
- <div {...props} className={classes.join(' ')} ref={containerRef} onMouseEnter={handleMouseEnter} onMouseLeave={handleMouseOut} tabIndex={1} onBlur={handleBlur}>
103
- {(position === 'left' && !disabled) && <Arrow className={styles['arrow']} onClick={handleClickArrow}/>}
104
- <div onClick={handleClick} className={'ui-dropdown-block' + (isOpen ? ' ' + styles['hide'] : '')}>
105
- {children}
106
- </div>
107
- {(position === 'right' && !disabled) && <Arrow className={styles['arrow']} onClick={handleClickArrow}/>}
108
- <Items isOpen={isOpen} disabled={disabled} enableRerenderItems={enableRerenderItems} items={items}/>
109
- </div>
110
- </Context.Provider>);
111
- };
112
-
113
- export default Dropdown;
@@ -1,42 +0,0 @@
1
- import {
2
- useContext,
3
- AllHTMLAttributes,
4
- ReactElement,
5
- MouseEvent
6
- } from "react";
7
- import styles from "./style.module.css";
8
- import { Context } from "./Dropdown";
9
-
10
- export type TChildrenAction = {
11
- close: () => void;
12
- };
13
-
14
- export interface IItem extends Omit<AllHTMLAttributes<HTMLLIElement>, 'children'> {
15
- children?: ((action: TChildrenAction) => ReactElement) | string | ReactElement;
16
- autoClose?: boolean;
17
- active?: boolean;
18
- };
19
-
20
- const Item = ({children, onClick, autoClose = true, active, className, ...props}: IItem) => {
21
- const context = useContext(Context);
22
-
23
- const handleClick = (e: MouseEvent<HTMLLIElement>) => {
24
- if (typeof onClick === 'function') {
25
- onClick(e);
26
- }
27
- if (autoClose) {
28
- context.close();
29
- }
30
- };
31
-
32
- const classes = ['ui-dropdown-item'];
33
- classes.push(styles['item']);
34
- if (active) classes.push(styles['active'], 'active');
35
- if (className) classes.push(className);
36
-
37
- return(<li {...props} onClick={handleClick} className={classes.join(' ')}>
38
- {typeof children === 'function' ? children(context) : children}
39
- </li>);
40
- };
41
-
42
- export default Item;
@@ -1,38 +0,0 @@
1
- import styles from "./style.module.css";
2
- import type { IDropdown } from "./Dropdown";
3
- import { useEffect, useMemo, useRef, useState } from "react";
4
-
5
- interface IItems extends Pick<IDropdown, 'items' | 'disabled' | 'enableRerenderItems'> {
6
- isOpen: boolean;
7
- };
8
-
9
- const Items = ({items, isOpen, enableRerenderItems, disabled}: IItems) => {
10
- const listRef = useRef<HTMLUListElement>(null);
11
-
12
- const renderItems = useMemo(() => {
13
- if (enableRerenderItems) {
14
- return isOpen ? items : null;
15
- }
16
- return items;
17
- }, [enableRerenderItems, items, isOpen]);
18
-
19
- useEffect(() => {
20
-
21
- if (!listRef.current) return;
22
- const screenWidth = window.innerWidth;
23
- const element = listRef.current.getBoundingClientRect();
24
-
25
-
26
- // console.log(element.left)
27
- if (element.left <= 0) {
28
-
29
- // listRef.current.style.transform = 'translateX(' + Math.abs(element.left) + 'px)';
30
- }
31
- },[isOpen]);
32
-
33
- if (disabled) return null;
34
-
35
- return(<ul className={styles['dropdown-list']} children={renderItems} ref={listRef}/>);
36
- };
37
-
38
- export default Items;
@@ -1,28 +0,0 @@
1
- import {
2
- forwardRef,
3
- RefAttributes,
4
- ForwardRefExoticComponent,
5
- FC
6
- } from "react";
7
- import {
8
- default as DropdownUI,
9
- IDropdown
10
- } from "./Dropdown";
11
- import Item,{
12
- IItem
13
- } from "./Item";
14
-
15
- interface StaticComponent extends ForwardRefExoticComponent<IDropdown & RefAttributes<HTMLInputElement>> {
16
- Item: FC<IItem>;
17
- };
18
-
19
- const Dropdown: StaticComponent = {
20
- ...forwardRef<HTMLInputElement, IDropdown>(({...args}, ref): JSX.Element => <DropdownUI {...args}/>),
21
- Item
22
- } as StaticComponent;
23
-
24
- export {
25
- Item as DropdownItem
26
- };
27
-
28
- export default Dropdown;
@@ -1,89 +0,0 @@
1
- /* Dropdown */
2
-
3
- .container {
4
- position: relative;
5
- display: inline-flex;
6
- flex-direction: row;
7
- align-items: center;
8
- outline: none;
9
- cursor: pointer;
10
- }
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
-
29
- .arrow {
30
- padding: 5px;
31
- }
32
-
33
- .dropdown-list {
34
- display: flex;
35
- position: absolute;
36
- padding: 0;
37
- margin: 0;
38
- flex-direction: column;
39
- background-color: #FFFFFF;
40
- border-radius: 2px;
41
- list-style-type: none;
42
- box-shadow: 0px 0px 9px 2px rgb(0 0 0 / 10%);
43
- opacity: 0;
44
- transform: translateY(-10%);
45
- visibility: hidden;
46
- z-index: 1;
47
- transition: opacity 0.3s, visibility 0.3s, transform 0.3s ease;
48
- }
49
-
50
- .container.down > .dropdown-list {
51
- top: 100%;
52
- }
53
-
54
- .container.up > .dropdown-list {
55
- bottom: 100%;
56
- }
57
-
58
- .container.left > .dropdown-list {
59
- left: 0;
60
- }
61
-
62
- .container.right > .dropdown-list {
63
- right: 0;
64
- }
65
-
66
- .dropdown-list > li.item {
67
- padding: 7px;
68
- font-size: 18px;
69
- font-weight: normal;
70
- color: #1D1D1B;
71
- white-space: nowrap;
72
- width: 100%;
73
- box-sizing: border-box;
74
- }
75
-
76
- .container.opened > .dropdown-list {
77
- opacity: 1;
78
- visibility: visible;
79
- transform: translateY(0);
80
- }
81
-
82
- .container.opened > .arrow::after {
83
- rotate: 180deg;
84
- }
85
-
86
- .dropdown-list > li.item:hover, .dropdown-list > li.item:has(:global(a.active)) {
87
- background-color: #BED4DB;
88
- border-radius: inherit;
89
- }
package/src/File/File.tsx DELETED
@@ -1,85 +0,0 @@
1
- import {
2
- useEffect,
3
- useRef,
4
- MouseEvent,
5
- AllHTMLAttributes
6
- } from "react";
7
-
8
- export type TFileMime = 'image/png' | 'image/jpg' | 'image/jpeg' | 'image/gif';
9
-
10
- export type TFileData = {
11
- name: string;
12
- type: TFileMime;
13
- size: number;
14
- mime: TFileMime;
15
- data: string;
16
- base64?: string | null | ArrayBuffer;
17
- };
18
-
19
- interface TFile<T = any> extends Omit<AllHTMLAttributes<T>, 'onChange' | 'accept'> {
20
- onChange?: (data: TFileData) => void;
21
- multiple?: boolean;
22
- accept?: TFileMime[];
23
- };
24
-
25
- const File = ({onChange, children, multiple, accept, ...props}: TFile) => {
26
- const selector = useRef<HTMLInputElement>();
27
-
28
- const handleChange = (e: Event) => {
29
- const target = e.target as HTMLInputElement
30
- if (target.files) {
31
- for(const file of target.files) {
32
- const reader = new FileReader();
33
- reader.onload = (evt) => {
34
- const data = evt.target?.result?.toString().split(';base64,');
35
- const mime = (data?.[0].replace('data:', '') ?? '') as TFileMime;
36
- const contentData = data?.[1] ?? '';
37
- if (typeof onChange === 'function') {
38
- selector.current!.value = '';
39
- onChange({
40
- name: file.name,
41
- type: file.type as TFileMime,
42
- size: file.size,
43
- mime: mime,
44
- data: contentData,
45
- base64: evt.target?.result
46
- })
47
- }
48
- };
49
- reader.readAsDataURL(file);
50
- }
51
- }
52
- };
53
-
54
- const handleDialog = (e: MouseEvent<HTMLDivElement>) => {
55
- if (props.disabled) return;
56
- selector.current!.click();
57
- e.preventDefault();
58
- };
59
-
60
- const mount = () => {
61
- const fileSelector = document.createElement('input');
62
- fileSelector.setAttribute('type', 'file');
63
- fileSelector.onchange = handleChange;
64
- if (accept && accept.length > 0) {
65
- fileSelector.setAttribute('accept', accept.join(','));
66
- }
67
-
68
- if (multiple) {
69
- fileSelector.setAttribute('multiple', 'multiple');
70
- }
71
- return fileSelector;
72
- };
73
-
74
- useEffect(() => {
75
- selector.current = mount();
76
- return () => {
77
- selector.current?.remove();
78
- }
79
- }, []);
80
- return(<div {...props} onClick={handleDialog}>
81
- {children}
82
- </div>)
83
- };
84
-
85
- export default File;
@@ -1,9 +0,0 @@
1
- import File,{
2
- TFileData,
3
- TFileMime
4
- } from "./File";
5
- export type {
6
- TFileData,
7
- TFileMime
8
- };
9
- export default File;
@@ -1,54 +0,0 @@
1
- import {
2
- useState,
3
- useEffect,
4
- AllHTMLAttributes,
5
- ReactElement,
6
- cloneElement
7
- } from "react";
8
- import styles from "./style.module.css";
9
-
10
- export interface IElement<T = any> extends Omit<AllHTMLAttributes<T>, 'children'> {
11
- children?: ((props: AllHTMLAttributes<T>) => ReactElement) | AllHTMLAttributes<T>["children"];
12
- error?: string;
13
- formValue?: string | number;
14
- disabled?: boolean;
15
- placeholder?: string;
16
- styleContainer?: React.HTMLAttributes<T>["style"];
17
- classNameContainer?: string;
18
- beforeElement?: React.ReactElement;
19
- afterElement?: React.ReactElement;
20
- hiddenContainer?: boolean;
21
- }
22
-
23
- const Element = ({children, beforeElement, afterElement, error, placeholder, styleContainer, classNameContainer, hiddenContainer, formValue, ...props}: IElement) => {
24
- const [currentError, setCurrentError] = useState('');
25
-
26
- useEffect(() => {
27
- setCurrentError(error ?? '');
28
- },[error]);
29
-
30
- const classes = ['ui-form-element-container'];
31
-
32
- classes.push(styles['container']);
33
- if (currentError) classes.push(styles['error']);
34
- if (props.disabled) classes.push(styles['disabled']);
35
- if (hiddenContainer) classes.push(styles['hidden']);
36
- if (classNameContainer) classes.push(classNameContainer);
37
-
38
- return(<>
39
- <label
40
- className={classes.join(' ')}
41
- style={styleContainer}
42
- >
43
- {beforeElement ? cloneElement(beforeElement, {key: 'ui-before-element'}) : null}
44
- <div className={'ui-form-element ' + styles['element']}>
45
- {typeof children === 'function' ? children(props) : null}
46
- {placeholder && <span className={'ui-form-element-placeholder ' + styles['placeholder']}>{placeholder}</span>}
47
- </div>
48
- {afterElement ? cloneElement(afterElement, {key: 'ui-after-element'}) : null}
49
- </label>
50
- {currentError && <div className={'ui-form-error ' + styles['error']}>{currentError}</div>}
51
- </>);
52
- }
53
-
54
- export default Element;
@@ -1,7 +0,0 @@
1
- import Element,{
2
- IElement
3
- } from "./Element";
4
- export type {
5
- IElement
6
- }
7
- export default Element;