@ainias42/react-bootstrap-mobile 0.1.15 → 0.1.17
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/bin/updateCopies.js +9 -5
- package/bootstrapReactMobile.ts +13 -2
- package/dist/bootstrapReactMobile.d.ts +13 -2
- package/dist/bootstrapReactMobile.js +992 -395
- package/dist/bootstrapReactMobile.js.map +1 -1
- package/dist/src/Components/Clickable/Clickable.d.ts +7 -3
- package/dist/src/Components/Dialog/DialogBackground.d.ts +4 -5
- package/dist/src/Components/Dialog/DialogContainer.d.ts +7 -3
- package/dist/src/Components/DragAndDrop/DragItem.d.ts +1 -1
- package/dist/src/Components/Flavor.d.ts +4 -0
- package/dist/src/Components/FormElements/Button/Button.d.ts +8 -4
- package/dist/src/Components/FormElements/Button/ButtonType.d.ts +4 -0
- package/dist/src/Components/FormElements/Input/FileInput/FileInput.d.ts +12 -0
- package/dist/src/Components/FormElements/Input/FileInput/FileType.d.ts +7 -0
- package/dist/src/Components/FormElements/Input/FileInput/MultipleFileInput.d.ts +17 -0
- package/dist/src/Components/FormElements/Select/Select.d.ts +2 -1
- package/dist/src/Components/FormElements/Switch/Switch.d.ts +4 -4
- package/dist/src/Components/Hooks/useMousePosition.d.ts +5 -0
- package/dist/src/Components/Hooks/useWindowDimensions.d.ts +4 -0
- package/dist/src/Components/Icon/Icon.d.ts +2 -3
- package/dist/src/Components/Layout/Grid/Grid.d.ts +2 -1
- package/dist/src/Components/Layout/Grid/GridItem.d.ts +4 -1
- package/dist/src/Components/Menu/HoverMenu.d.ts +9 -0
- package/dist/src/Components/Menu/Menu.d.ts +16 -7
- package/dist/src/Components/Menu/MenuCloseContext.d.ts +3 -0
- package/dist/src/Components/Menu/MenuDivider.d.ts +2 -0
- package/dist/src/Components/Menu/MenuItem.d.ts +23 -0
- package/dist/src/Components/Menu/Submenu.d.ts +12 -0
- package/dist/src/Components/Menu/useMenu.d.ts +1 -1
- package/dist/src/Components/RbmComponentProps.d.ts +4 -0
- package/dist/src/Components/Text/Text.d.ts +1 -0
- package/dist/src/ListRow/ListRow.d.ts +1 -0
- package/package.json +8 -7
- package/src/Components/Clickable/Clickable.tsx +135 -19
- package/src/Components/Dialog/DialogBackground.tsx +5 -8
- package/src/Components/Dialog/DialogContainer.tsx +12 -8
- package/src/Components/Dialog/DialogContext.ts +1 -2
- package/src/Components/Dialog/dialogBackground.scss +5 -1
- package/src/Components/DragAndDrop/DragItem.tsx +7 -7
- package/src/Components/DragAndDrop/DropArea.tsx +2 -1
- package/src/Components/Flavor.ts +4 -0
- package/src/Components/FormElements/Button/Button.tsx +31 -13
- package/src/Components/FormElements/Button/ButtonType.ts +4 -0
- package/src/Components/FormElements/Button/button.scss +22 -5
- package/src/Components/FormElements/Input/FileInput/FileInput.tsx +55 -0
- package/src/Components/FormElements/Input/FileInput/FileType.ts +1 -0
- package/src/Components/FormElements/Input/FileInput/MultipleFileInput.tsx +281 -0
- package/src/Components/FormElements/{ImageInput/imageInput.scss → Input/FileInput/fileInput.scss} +37 -7
- package/src/Components/FormElements/Input/input.scss +1 -1
- package/src/Components/FormElements/SearchSelectInput/SearchSelectInput.tsx +2 -2
- package/src/Components/FormElements/SearchSelectInput/seachSelectInput.scss +1 -1
- package/src/Components/FormElements/Select/Select.tsx +3 -2
- package/src/Components/FormElements/Select/select.scss +5 -0
- package/src/Components/FormElements/Switch/Switch.tsx +9 -8
- package/src/Components/FormElements/Switch/switch.scss +1 -0
- package/src/Components/Hooks/useMousePosition.ts +13 -0
- package/src/Components/Hooks/useWindowDimensions.ts +17 -0
- package/src/Components/Icon/Icon.tsx +18 -14
- package/src/Components/Icon/icon.scss +9 -0
- package/src/Components/Layout/Grid/Grid.tsx +3 -2
- package/src/Components/Layout/Grid/GridItem.tsx +16 -1
- package/src/Components/Layout/Grid/grid.scss +113 -36
- package/src/Components/Menu/HoverMenu.tsx +82 -0
- package/src/Components/Menu/Menu.tsx +101 -47
- package/src/Components/Menu/MenuCloseContext.ts +10 -0
- package/src/Components/Menu/MenuDivider.tsx +22 -0
- package/src/Components/Menu/MenuItem.tsx +95 -0
- package/src/Components/Menu/Submenu.tsx +101 -0
- package/src/Components/Menu/menu.scss +99 -10
- package/src/Components/Menu/useMenu.ts +1 -1
- package/src/Components/RbmComponentProps.ts +6 -0
- package/src/Components/Text/Text.tsx +1 -0
- package/src/Components/Text/text.scss +13 -5
- package/src/ListRow/ListRow.tsx +20 -0
- package/src/WrongChildError.ts +0 -2
- package/src/scss/_colors.scss +1 -1
- package/src/scss/_flavorMixin.scss +10 -0
- package/dist/src/Components/FormElements/ImageInput/ImageInput.d.ts +0 -18
- package/dist/src/Components/FormElements/ImageInput/MultipleFileInput.d.ts +0 -21
- package/src/Components/FormElements/ImageInput/ImageInput.tsx +0 -98
- package/src/Components/FormElements/ImageInput/MultipleFileInput.tsx +0 -240
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import {RbmComponentProps, WithNoStringAndChildrenProps} from "../RbmComponentProps";
|
|
2
|
+
import {Icon, IconSource} from "../Icon/Icon";
|
|
3
|
+
import {Clickable} from "../Clickable/Clickable";
|
|
4
|
+
import classNames from "classnames";
|
|
5
|
+
import styles from "./menu.scss";
|
|
6
|
+
import React, {useCallback, useRef, useState} from "react";
|
|
7
|
+
import {Text} from "../Text/Text";
|
|
8
|
+
import {withMemo} from "../../helper/withMemo";
|
|
9
|
+
import {Block} from "../Layout/Block";
|
|
10
|
+
import {useWindow} from "../../WindowContext/WindowContext";
|
|
11
|
+
import {Flex} from "../Layout/Flex";
|
|
12
|
+
import {Grow} from "../Layout/Grow";
|
|
13
|
+
import {faChevronRight} from "@fortawesome/free-solid-svg-icons";
|
|
14
|
+
import {MenuCloseContextProvider, useMenuClose} from "./MenuCloseContext";
|
|
15
|
+
|
|
16
|
+
export type SubmenuProps = RbmComponentProps<{
|
|
17
|
+
label: string, icon?: IconSource;
|
|
18
|
+
iconColor?: string;
|
|
19
|
+
disabled?: boolean;
|
|
20
|
+
onMouseEnter?: () => void;
|
|
21
|
+
onMouseLeave?: () => void;
|
|
22
|
+
}, WithNoStringAndChildrenProps>;
|
|
23
|
+
|
|
24
|
+
export const Submenu = withMemo(function Submenu({
|
|
25
|
+
children,
|
|
26
|
+
label,
|
|
27
|
+
icon,
|
|
28
|
+
iconColor,
|
|
29
|
+
className,
|
|
30
|
+
style,
|
|
31
|
+
disabled = false,
|
|
32
|
+
onMouseEnter,
|
|
33
|
+
onMouseLeave,
|
|
34
|
+
}: SubmenuProps) {
|
|
35
|
+
// Refs
|
|
36
|
+
|
|
37
|
+
// States/Variables/Selectors
|
|
38
|
+
const window = useWindow();
|
|
39
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
40
|
+
const submenuRef = useRef<HTMLDivElement>(null);
|
|
41
|
+
|
|
42
|
+
const [openLeft, setOpenLeft] = useState(false);
|
|
43
|
+
const [openTop, setOpenTop] = useState(false);
|
|
44
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
45
|
+
|
|
46
|
+
// Dispatch
|
|
47
|
+
|
|
48
|
+
// Callbacks
|
|
49
|
+
const recalculateSubmenuPosition = useCallback(() => {
|
|
50
|
+
if (!submenuRef.current || !containerRef.current) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const {width, height} = getComputedStyle(containerRef.current);
|
|
54
|
+
const {right, top} = submenuRef.current.getBoundingClientRect();
|
|
55
|
+
|
|
56
|
+
setOpenLeft(right + parseFloat(width) >= (window?.innerWidth ?? 0));
|
|
57
|
+
setOpenTop(top + parseFloat(height) >= (window?.innerHeight ?? 0));
|
|
58
|
+
setIsOpen(true);
|
|
59
|
+
onMouseEnter?.();
|
|
60
|
+
}, [onMouseEnter, window?.innerHeight, window?.innerWidth]);
|
|
61
|
+
|
|
62
|
+
const closeSubmenu = useCallback(() => {
|
|
63
|
+
setIsOpen(false);
|
|
64
|
+
onMouseLeave?.();
|
|
65
|
+
}, [onMouseLeave]);
|
|
66
|
+
|
|
67
|
+
const closeParent = useMenuClose();
|
|
68
|
+
const closeAllMenus = useCallback(() => {
|
|
69
|
+
closeSubmenu();
|
|
70
|
+
closeParent();
|
|
71
|
+
}, [closeParent, closeSubmenu]);
|
|
72
|
+
|
|
73
|
+
// Effects
|
|
74
|
+
|
|
75
|
+
// Other
|
|
76
|
+
|
|
77
|
+
// RenderFunctions
|
|
78
|
+
|
|
79
|
+
return <MenuCloseContextProvider value={closeAllMenus}>
|
|
80
|
+
<Clickable
|
|
81
|
+
onMouseEnter={recalculateSubmenuPosition}
|
|
82
|
+
onMouseLeave={closeSubmenu}
|
|
83
|
+
className={classNames(styles.item, styles.submenu, {
|
|
84
|
+
[styles.open]: isOpen,
|
|
85
|
+
[styles.openLeft]: openLeft,
|
|
86
|
+
[styles.openTop]: openTop,
|
|
87
|
+
[styles.disabled]: disabled
|
|
88
|
+
}, className)}
|
|
89
|
+
style={style}
|
|
90
|
+
>
|
|
91
|
+
<Flex ref={submenuRef} className={classNames(styles.itemChildren)} horizontal={true}>
|
|
92
|
+
{!!icon && <Icon icon={icon} color={iconColor} className={styles.icon}/>}
|
|
93
|
+
<Grow><Text>{label}</Text></Grow>
|
|
94
|
+
<Icon icon={faChevronRight}/>
|
|
95
|
+
</Flex>
|
|
96
|
+
<Block className={styles.container} __allowChildren="all" ref={containerRef}>
|
|
97
|
+
{children}
|
|
98
|
+
</Block>
|
|
99
|
+
</Clickable>
|
|
100
|
+
</MenuCloseContextProvider>;
|
|
101
|
+
}, styles);
|
|
@@ -1,21 +1,110 @@
|
|
|
1
|
-
|
|
2
1
|
.menu {
|
|
3
2
|
position: fixed;
|
|
4
3
|
background: #ffffff;
|
|
5
4
|
border: 1px solid var(--border-light);
|
|
5
|
+
border-radius: 2px;
|
|
6
|
+
z-index: 1000;
|
|
7
|
+
|
|
8
|
+
&.hidden {
|
|
9
|
+
visibility: hidden;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.divider {
|
|
14
|
+
margin-left: 4px;
|
|
15
|
+
margin-right: 4px;
|
|
16
|
+
padding-top: 1px;
|
|
17
|
+
margin-top: 1px;
|
|
18
|
+
border-top: 1px solid var(--border-light);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.item {
|
|
22
|
+
padding: 0 4px;
|
|
23
|
+
display: flex;
|
|
24
|
+
//background: #ffffff;
|
|
25
|
+
|
|
26
|
+
&.active {
|
|
27
|
+
background-color: #e1e1e1;
|
|
28
|
+
}
|
|
6
29
|
|
|
7
|
-
.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
30
|
+
.itemChildren {
|
|
31
|
+
flex: 1;
|
|
32
|
+
padding: 1px;
|
|
33
|
+
display: flex;
|
|
34
|
+
flex-direction: row;
|
|
35
|
+
align-items: center;
|
|
36
|
+
//border-top: 1px solid var(--border-light);
|
|
37
|
+
white-space: nowrap;
|
|
12
38
|
|
|
13
|
-
|
|
14
|
-
|
|
39
|
+
.icon {
|
|
40
|
+
margin-right: 4px;
|
|
15
41
|
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
&.disabled {
|
|
45
|
+
pointer-events: none;
|
|
46
|
+
cursor: default;
|
|
47
|
+
|
|
48
|
+
> .itemChildren > * {
|
|
49
|
+
opacity: 0.3;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
&:hover {
|
|
54
|
+
background-color: #f5f5f5;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
&:first-child > .itemChildren {
|
|
58
|
+
border-top: none;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.hoverMenu {
|
|
63
|
+
padding: 0;
|
|
64
|
+
display: inline;
|
|
65
|
+
|
|
66
|
+
.menu {
|
|
67
|
+
visibility: hidden;
|
|
68
|
+
pointer-events: none;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
&.open:hover {
|
|
72
|
+
.menu {
|
|
73
|
+
visibility: visible;
|
|
74
|
+
pointer-events: initial;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.submenu {
|
|
80
|
+
position: relative;
|
|
81
|
+
|
|
82
|
+
.container {
|
|
83
|
+
visibility: hidden;
|
|
84
|
+
pointer-events: none;
|
|
85
|
+
position: absolute;
|
|
86
|
+
top: 3px;
|
|
87
|
+
left: calc(100% - 3px);
|
|
88
|
+
background: #ffffff;
|
|
89
|
+
border: 1px solid var(--border-light);
|
|
90
|
+
border-radius: 2px;
|
|
91
|
+
z-index: 10;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
&.openLeft .container {
|
|
95
|
+
left: initial;
|
|
96
|
+
right: calc(100% - 3px);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
&.openTop .container {
|
|
100
|
+
top: initial;
|
|
101
|
+
bottom: 3px;
|
|
102
|
+
}
|
|
16
103
|
|
|
17
|
-
|
|
18
|
-
|
|
104
|
+
&.open:hover {
|
|
105
|
+
.container {
|
|
106
|
+
visibility: visible;
|
|
107
|
+
pointer-events: initial;
|
|
19
108
|
}
|
|
20
109
|
}
|
|
21
110
|
}
|
|
@@ -26,6 +26,12 @@ export type WithStringProps = {
|
|
|
26
26
|
children?: Recursive<string>;
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
+
export type WithChildren =
|
|
30
|
+
| {
|
|
31
|
+
children: ReactNode
|
|
32
|
+
__allowChildren?: "text"|"all"|"html";
|
|
33
|
+
};
|
|
34
|
+
|
|
29
35
|
export type WithStringAndChildrenProps = {
|
|
30
36
|
children: Recursive<string>;
|
|
31
37
|
};
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
$primaryColor: #
|
|
2
|
-
$secondaryColor: #
|
|
1
|
+
$primaryColor: #18181B; // Gray-900
|
|
2
|
+
$secondaryColor: #71717a; // Gray-500
|
|
3
|
+
$tertiaryColor: #A1A1AA; // Gray-400
|
|
3
4
|
|
|
4
5
|
:root {
|
|
5
|
-
--text-primary-default-color: $primaryColor;
|
|
6
|
+
--text-primary-default-color: #{$primaryColor};
|
|
7
|
+
--text-prmary: #{$primaryColor};
|
|
8
|
+
--text-secondary: #{$secondaryColor};
|
|
9
|
+
--text-tertiary: #{$tertiaryColor};
|
|
6
10
|
}
|
|
7
11
|
|
|
8
12
|
.text {
|
|
@@ -21,11 +25,15 @@ $secondaryColor: #717171;
|
|
|
21
25
|
}
|
|
22
26
|
|
|
23
27
|
&.primary {
|
|
24
|
-
color:
|
|
28
|
+
color: var(--text-primary)
|
|
25
29
|
}
|
|
26
30
|
|
|
27
31
|
&.secondary {
|
|
28
|
-
color:
|
|
32
|
+
color: var(--text-secondary);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
&.tertiary {
|
|
36
|
+
color: var(--text-tertiary);
|
|
29
37
|
}
|
|
30
38
|
|
|
31
39
|
&.xsmall {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {withMemo} from "../helper/withMemo";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export const ListRow = withMemo(function ListRow() {
|
|
5
|
+
// Refs
|
|
6
|
+
|
|
7
|
+
// States/Variables/Selectors
|
|
8
|
+
|
|
9
|
+
// Dispatch
|
|
10
|
+
|
|
11
|
+
// Callbacks
|
|
12
|
+
|
|
13
|
+
// Effects
|
|
14
|
+
|
|
15
|
+
// Other
|
|
16
|
+
|
|
17
|
+
// RenderFunctions
|
|
18
|
+
|
|
19
|
+
return null;
|
|
20
|
+
});
|
package/src/WrongChildError.ts
CHANGED
package/src/scss/_colors.scss
CHANGED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { RbmComponentProps } from '../../RbmComponentProps';
|
|
3
|
-
import { Override } from '../../../TypeHelpers';
|
|
4
|
-
import { InputHTMLAttributes } from 'react';
|
|
5
|
-
import { OptionalListener } from '../../Hooks/useListener';
|
|
6
|
-
export type ImageType = {
|
|
7
|
-
name: string;
|
|
8
|
-
url: string;
|
|
9
|
-
};
|
|
10
|
-
export type ImageInputProps<OnChangeData> = RbmComponentProps<Override<InputHTMLAttributes<HTMLInputElement>, {
|
|
11
|
-
defaultValue?: ImageType;
|
|
12
|
-
value?: ImageType;
|
|
13
|
-
label?: string;
|
|
14
|
-
onChangeImage?: (image: ImageType, imageData: File) => void;
|
|
15
|
-
} & OptionalListener<'onChange', OnChangeData>>>;
|
|
16
|
-
declare function ImageInput<OnChangeData>({ className, style, value, defaultValue, onChangeImage, label, ...otherProps }: ImageInputProps<OnChangeData>): React.JSX.Element;
|
|
17
|
-
declare const ImageInputMemo: typeof ImageInput;
|
|
18
|
-
export { ImageInputMemo as ImageInput };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { RbmComponentProps } from '../../RbmComponentProps';
|
|
3
|
-
import { Override } from '../../../TypeHelpers';
|
|
4
|
-
import { InputHTMLAttributes } from 'react';
|
|
5
|
-
import { Listener } from '../../Hooks/useListener';
|
|
6
|
-
export type FileType = {
|
|
7
|
-
name: string;
|
|
8
|
-
url: string;
|
|
9
|
-
mimeType: string;
|
|
10
|
-
uploaded?: boolean;
|
|
11
|
-
blob?: Blob;
|
|
12
|
-
};
|
|
13
|
-
export type MultipleImageInputProps<OnChangeFilesData> = RbmComponentProps<Override<Omit<InputHTMLAttributes<HTMLInputElement>, 'defaultValue' | 'onChange'>, {
|
|
14
|
-
value: FileType[];
|
|
15
|
-
label?: string;
|
|
16
|
-
mimeTypes?: string[];
|
|
17
|
-
maxFiles?: number;
|
|
18
|
-
maxSizePerFile?: number;
|
|
19
|
-
onError?: (error: string) => void;
|
|
20
|
-
} & Listener<'onChangeFiles', OnChangeFilesData, FileType[]>>>;
|
|
21
|
-
export declare const MultipleFileInput: <OnChangeData>({ className, style, value, label, mimeTypes, maxFiles, maxSizePerFile, onError, ...otherProps }: MultipleImageInputProps<OnChangeData>) => React.JSX.Element;
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { RbmComponentProps } from '../../RbmComponentProps';
|
|
3
|
-
import { Override } from '../../../TypeHelpers';
|
|
4
|
-
import { ChangeEventHandler, InputHTMLAttributes, useCallback, useState } from 'react';
|
|
5
|
-
import { OptionalListener, useListener } from '../../Hooks/useListener';
|
|
6
|
-
import { Button } from '../Button/Button';
|
|
7
|
-
|
|
8
|
-
import styles from './imageInput.scss';
|
|
9
|
-
import { withMemo } from '../../../helper/withMemo';
|
|
10
|
-
import classNames from 'classnames';
|
|
11
|
-
|
|
12
|
-
export type ImageType = { name: string; url: string };
|
|
13
|
-
|
|
14
|
-
export type ImageInputProps<OnChangeData> = RbmComponentProps<
|
|
15
|
-
Override<
|
|
16
|
-
InputHTMLAttributes<HTMLInputElement>,
|
|
17
|
-
{
|
|
18
|
-
defaultValue?: ImageType;
|
|
19
|
-
value?: ImageType;
|
|
20
|
-
label?: string;
|
|
21
|
-
onChangeImage?: (image: ImageType, imageData: File) => void;
|
|
22
|
-
} & OptionalListener<'onChange', OnChangeData>
|
|
23
|
-
>
|
|
24
|
-
>;
|
|
25
|
-
|
|
26
|
-
// TODO use MultipleFileInput internal
|
|
27
|
-
function ImageInput<OnChangeData>({
|
|
28
|
-
className,
|
|
29
|
-
style,
|
|
30
|
-
value,
|
|
31
|
-
defaultValue,
|
|
32
|
-
onChangeImage,
|
|
33
|
-
label,
|
|
34
|
-
...otherProps
|
|
35
|
-
}: ImageInputProps<OnChangeData>) {
|
|
36
|
-
// Variables
|
|
37
|
-
const [image, setImage] = useState(defaultValue);
|
|
38
|
-
|
|
39
|
-
// Refs
|
|
40
|
-
|
|
41
|
-
// States
|
|
42
|
-
|
|
43
|
-
// Selectors
|
|
44
|
-
|
|
45
|
-
// Callbacks
|
|
46
|
-
const onChangeWithData = useListener<'onChange', OnChangeData>('onChange', otherProps);
|
|
47
|
-
const getBase64 = useCallback((file: Blob) => {
|
|
48
|
-
return new Promise<string>((resolve, reject) => {
|
|
49
|
-
const reader = new FileReader();
|
|
50
|
-
reader.onload = () => {
|
|
51
|
-
resolve(reader.result as string);
|
|
52
|
-
};
|
|
53
|
-
reader.onerror = reject;
|
|
54
|
-
reader.readAsDataURL(file);
|
|
55
|
-
});
|
|
56
|
-
}, []);
|
|
57
|
-
const onChange = useCallback<ChangeEventHandler<HTMLInputElement>>(
|
|
58
|
-
async (e) => {
|
|
59
|
-
if (!e.target.files || e.target.files.length === 0) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
onChangeWithData(e);
|
|
64
|
-
const newUrl = await getBase64(e.target.files[0]);
|
|
65
|
-
const newValue = { name: e.target.files[0].name, url: newUrl };
|
|
66
|
-
setImage(newValue);
|
|
67
|
-
|
|
68
|
-
if (onChangeImage) {
|
|
69
|
-
onChangeImage(newValue, e.target.files[0]);
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
[onChangeWithData, onChangeImage, getBase64]
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
// Effects
|
|
76
|
-
|
|
77
|
-
// Other
|
|
78
|
-
|
|
79
|
-
// Render Functions
|
|
80
|
-
|
|
81
|
-
return (
|
|
82
|
-
// eslint-disable-next-line jsx-a11y/label-has-associated-control
|
|
83
|
-
<label className={classNames(styles.fileInput, className)} style={style}>
|
|
84
|
-
{label ? <span>{label}</span> : null}
|
|
85
|
-
<img
|
|
86
|
-
src={(value ?? image)?.url}
|
|
87
|
-
alt={(value ?? image)?.name}
|
|
88
|
-
className={classNames(styles.preview, (value ?? image)?.url ? undefined : styles.empty)}
|
|
89
|
-
/>
|
|
90
|
-
<Button __allowChildren="all">{(value ?? image)?.name ?? <i>Select Image</i>}</Button>
|
|
91
|
-
<input {...otherProps} className={styles.value} onChange={onChange} type="file" />
|
|
92
|
-
</label>
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// Need ImageInputMemo for autocompletion of phpstorm
|
|
97
|
-
const ImageInputMemo = withMemo(ImageInput, styles);
|
|
98
|
-
export { ImageInputMemo as ImageInput };
|