@mezzanine-ui/react 0.7.1 → 0.8.0
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/Drawer/Drawer.d.ts +2 -7
- package/Drawer/Drawer.js +5 -21
- package/Form/useAutoCompleteValueControl.d.ts +2 -2
- package/Form/useAutoCompleteValueControl.js +9 -5
- package/Form/useSelectValueControl.d.ts +25 -8
- package/Form/useSelectValueControl.js +38 -20
- package/Icon/Icon.d.ts +4 -0
- package/Icon/Icon.js +3 -2
- package/Modal/Modal.d.ts +2 -7
- package/Modal/Modal.js +8 -57
- package/Modal/index.d.ts +1 -0
- package/Modal/index.js +1 -0
- package/Modal/useModalContainer.d.ts +6 -0
- package/Modal/useModalContainer.js +27 -0
- package/Select/AutoComplete.js +5 -3
- package/Select/Option.js +13 -1
- package/Select/Select.d.ts +90 -12
- package/Select/Select.js +8 -3
- package/Select/SelectTrigger.d.ts +37 -9
- package/Select/SelectTrigger.js +29 -5
- package/Select/typings.d.ts +2 -2
- package/Transition/Transition.d.ts +1 -1
- package/Upload/UploadInput.js +2 -0
- package/Upload/UploadPicture.d.ts +48 -0
- package/Upload/UploadPicture.js +52 -0
- package/Upload/UploadPictureBlock.d.ts +13 -0
- package/Upload/UploadPictureBlock.js +86 -0
- package/Upload/UploadPictureWall.d.ts +71 -0
- package/Upload/UploadPictureWall.js +156 -0
- package/Upload/UploadPictureWallItem.d.ts +13 -0
- package/Upload/UploadPictureWallItem.js +19 -0
- package/Upload/index.d.ts +3 -0
- package/Upload/index.js +3 -0
- package/_internal/SlideFadeOverlay/SlideFadeOverlay.d.ts +21 -0
- package/_internal/SlideFadeOverlay/SlideFadeOverlay.js +66 -0
- package/_internal/SlideFadeOverlay/index.d.ts +1 -0
- package/_internal/SlideFadeOverlay/index.js +1 -0
- package/_internal/SlideFadeOverlay/useTopStack.d.ts +1 -0
- package/{Modal/useIsTopModal.js → _internal/SlideFadeOverlay/useTopStack.js} +3 -3
- package/index.d.ts +3 -4
- package/index.js +5 -1
- package/package.json +3 -3
- package/Modal/useIsTopModal.d.ts +0 -1
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { Ref } from 'react';
|
|
2
|
-
import { SelectMode } from '@mezzanine-ui/core/select';
|
|
3
2
|
import { TextFieldProps } from '../TextField';
|
|
4
3
|
import { SelectValue } from './typings';
|
|
5
4
|
import { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types';
|
|
6
5
|
export declare type SelectTriggerInputProps = Omit<NativeElementPropsWithoutKeyAndRef<'input'>, 'autoComplete' | 'children' | 'defaultValue' | 'disabled' | 'readOnly' | 'required' | 'type' | 'value' | `aria-${'autocomplete' | 'disabled' | 'haspopup' | 'multiline' | 'readonly' | 'required'}`>;
|
|
7
|
-
export interface
|
|
6
|
+
export interface SelectTriggerBaseProps extends Omit<TextFieldProps, 'active' | 'children' | 'defaultChecked' | 'suffix'> {
|
|
8
7
|
/**
|
|
9
8
|
* Controls the chevron icon layout.
|
|
10
9
|
*/
|
|
@@ -13,6 +12,10 @@ export interface SelectTriggerProps extends Omit<TextFieldProps, 'active' | 'chi
|
|
|
13
12
|
* force hide suffixAction icons
|
|
14
13
|
*/
|
|
15
14
|
forceHideSuffixActionIcon?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* The ref for SelectTrigger root.
|
|
17
|
+
*/
|
|
18
|
+
innerRef?: Ref<HTMLDivElement>;
|
|
16
19
|
/**
|
|
17
20
|
* Other props you may provide to input element.
|
|
18
21
|
*/
|
|
@@ -21,10 +24,6 @@ export interface SelectTriggerProps extends Omit<TextFieldProps, 'active' | 'chi
|
|
|
21
24
|
* The ref object for input element.
|
|
22
25
|
*/
|
|
23
26
|
inputRef?: Ref<HTMLInputElement>;
|
|
24
|
-
/**
|
|
25
|
-
* Controls the layout of trigger.
|
|
26
|
-
*/
|
|
27
|
-
mode?: SelectMode;
|
|
28
27
|
/**
|
|
29
28
|
* The click handler for the cross icon on tags
|
|
30
29
|
*/
|
|
@@ -38,17 +37,46 @@ export interface SelectTriggerProps extends Omit<TextFieldProps, 'active' | 'chi
|
|
|
38
37
|
* Provide if you have a customize value rendering logic.
|
|
39
38
|
* By default will have a comma between values.
|
|
40
39
|
*/
|
|
41
|
-
renderValue?: (value: SelectValue[]) => string;
|
|
40
|
+
renderValue?: (value: SelectValue[] | SelectValue | null) => string;
|
|
42
41
|
/**
|
|
43
42
|
* Whether the input is required.
|
|
44
43
|
* @default false
|
|
45
44
|
*/
|
|
46
45
|
required?: boolean;
|
|
46
|
+
}
|
|
47
|
+
export declare type SelectTriggerMultipleProps = SelectTriggerBaseProps & {
|
|
48
|
+
/**
|
|
49
|
+
* Controls the layout of trigger.
|
|
50
|
+
*/
|
|
51
|
+
mode: 'multiple';
|
|
47
52
|
/**
|
|
48
53
|
* The value of selection.
|
|
49
54
|
* @default undefined
|
|
50
55
|
*/
|
|
51
56
|
value?: SelectValue[];
|
|
52
|
-
|
|
53
|
-
|
|
57
|
+
/**
|
|
58
|
+
* Provide if you have a customize value rendering logic.
|
|
59
|
+
* By default will have a comma between values.
|
|
60
|
+
*/
|
|
61
|
+
renderValue?: (value: SelectValue[]) => string;
|
|
62
|
+
};
|
|
63
|
+
export declare type SelectTriggerSingleProps = SelectTriggerBaseProps & {
|
|
64
|
+
/**
|
|
65
|
+
* Controls the layout of trigger.
|
|
66
|
+
*/
|
|
67
|
+
mode?: 'single';
|
|
68
|
+
/**
|
|
69
|
+
* The value of selection.
|
|
70
|
+
* @default undefined
|
|
71
|
+
*/
|
|
72
|
+
value?: SelectValue | null;
|
|
73
|
+
/**
|
|
74
|
+
* Provide if you have a customize value rendering logic.
|
|
75
|
+
* By default will have a comma between values.
|
|
76
|
+
*/
|
|
77
|
+
renderValue?: (value: SelectValue | null) => string;
|
|
78
|
+
};
|
|
79
|
+
export declare type SelectTriggerComponentProps = SelectTriggerMultipleProps | SelectTriggerSingleProps;
|
|
80
|
+
export declare type SelectTriggerProps = Omit<SelectTriggerComponentProps, 'innerRef'>;
|
|
81
|
+
declare const SelectTrigger: import("react").ForwardRefExoticComponent<Pick<SelectTriggerComponentProps, "disabled" | "placeholder" | "readOnly" | "required" | "size" | "value" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "slot" | "spellCheck" | "style" | "tabIndex" | "title" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "active" | "clearable" | "error" | "fullWidth" | "onClear" | "suffixActionIcon" | "forceHideSuffixActionIcon" | "inputProps" | "inputRef" | "onTagClose" | "renderValue" | "mode"> & import("react").RefAttributes<HTMLDivElement>>;
|
|
54
82
|
export default SelectTrigger;
|
package/Select/SelectTrigger.js
CHANGED
|
@@ -7,21 +7,45 @@ import TextField from '../TextField/TextField.js';
|
|
|
7
7
|
import Tag from '../Tag/Tag.js';
|
|
8
8
|
import cx from 'clsx';
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
function SelectTriggerComponent(props) {
|
|
11
|
+
var _a;
|
|
12
|
+
const { active, className, disabled, forceHideSuffixActionIcon, inputProps, innerRef, inputRef, mode, onTagClose, readOnly, renderValue: renderValueProp, required, size, suffixActionIcon: suffixActionIconProp, value, ...restTextFieldProps } = props;
|
|
12
13
|
/** Render value to string for input */
|
|
13
14
|
const renderValue = () => {
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
if (typeof renderValueProp === 'function') {
|
|
16
|
+
return renderValueProp(value || (mode === 'multiple' ? [] : null));
|
|
17
|
+
}
|
|
18
|
+
if (value) {
|
|
19
|
+
if (Array.isArray(value)) {
|
|
20
|
+
return value.map((v) => v.name).join(', ');
|
|
21
|
+
}
|
|
22
|
+
return value.name;
|
|
23
|
+
}
|
|
24
|
+
return '';
|
|
16
25
|
};
|
|
17
26
|
/** Compute suffix action icon */
|
|
18
27
|
const suffixActionIcon = suffixActionIconProp || (jsx(Icon, { icon: ChevronDownIcon, className: cx(selectClasses.triggerSuffixActionIcon, {
|
|
19
28
|
[selectClasses.triggerSuffixActionIconActive]: active,
|
|
20
29
|
}) }, void 0));
|
|
21
|
-
|
|
30
|
+
const getTextFieldActive = () => {
|
|
31
|
+
if (value) {
|
|
32
|
+
if (Array.isArray(value)) {
|
|
33
|
+
return !!(value === null || value === void 0 ? void 0 : value.length);
|
|
34
|
+
}
|
|
35
|
+
return !!value;
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
};
|
|
39
|
+
return (jsx(TextField, Object.assign({ ref: innerRef }, restTextFieldProps, { active: getTextFieldActive(), className: cx(selectClasses.trigger, className), disabled: disabled, size: size, suffixActionIcon: forceHideSuffixActionIcon ? undefined : suffixActionIcon }, { children: mode === 'multiple' && ((_a = value) === null || _a === void 0 ? void 0 : _a.length) ? (jsx("div", Object.assign({ className: selectClasses.triggerTags }, { children: value.map((selection) => (jsx(Tag, Object.assign({ closable: true, disabled: disabled, onClose: (e) => {
|
|
22
40
|
e.stopPropagation();
|
|
23
41
|
onTagClose === null || onTagClose === void 0 ? void 0 : onTagClose(selection);
|
|
24
42
|
}, size: size }, { children: selection.name }), selection.id))) }), void 0)) : (jsx("input", Object.assign({}, inputProps, { ref: inputRef, "aria-autocomplete": "list", "aria-disabled": disabled, "aria-haspopup": "listbox", "aria-readonly": readOnly, "aria-required": required, autoComplete: "false", disabled: disabled, readOnly: readOnly, required: required, type: "search", value: renderValue() }), void 0)) }), void 0));
|
|
43
|
+
}
|
|
44
|
+
const SelectTrigger = forwardRef((props, ref) => {
|
|
45
|
+
if (props.mode === 'multiple') {
|
|
46
|
+
return (jsx(SelectTriggerComponent, Object.assign({}, props, { innerRef: ref }), void 0));
|
|
47
|
+
}
|
|
48
|
+
return (jsx(SelectTriggerComponent, Object.assign({}, props, { innerRef: ref }), void 0));
|
|
25
49
|
});
|
|
26
50
|
var SelectTrigger$1 = SelectTrigger;
|
|
27
51
|
|
package/Select/typings.d.ts
CHANGED
|
@@ -6,6 +6,6 @@ export interface TreeSelectOption extends SelectValue {
|
|
|
6
6
|
siblings?: TreeSelectOption[];
|
|
7
7
|
}
|
|
8
8
|
export interface SelectControl {
|
|
9
|
-
value: SelectValue[];
|
|
10
|
-
onChange: (v: SelectValue | null) => SelectValue[];
|
|
9
|
+
value: SelectValue[] | SelectValue | null;
|
|
10
|
+
onChange: (v: SelectValue | null) => SelectValue[] | SelectValue | null;
|
|
11
11
|
}
|
|
@@ -19,7 +19,7 @@ export interface TransitionImplementationChildProps {
|
|
|
19
19
|
style?: CSSProperties;
|
|
20
20
|
}
|
|
21
21
|
export interface TransitionImplementationProps extends Omit<TransitionProps, 'addEndListener' | 'children' | 'nodeRef'> {
|
|
22
|
-
children
|
|
22
|
+
children: ReactElement<TransitionImplementationChildProps, NativeElementTag | JSXElementConstructor<TransitionImplementationChildProps>>;
|
|
23
23
|
/**
|
|
24
24
|
* The delay of the transition, in milliseconds
|
|
25
25
|
*/
|
package/Upload/UploadInput.js
CHANGED
|
@@ -5,6 +5,8 @@ import { uploadInputClasses } from '@mezzanine-ui/core/upload';
|
|
|
5
5
|
const UploadInput = forwardRef((props, ref) => {
|
|
6
6
|
const { accept, disabled = false, multiple = false, onUpload, } = props;
|
|
7
7
|
return (jsx("input", { ref: ref, accept: accept, "aria-disabled": disabled, className: uploadInputClasses.host, disabled: disabled, multiple: multiple, onClick: (event) => {
|
|
8
|
+
// eslint-disable-next-line no-param-reassign
|
|
9
|
+
event.currentTarget.value = '';
|
|
8
10
|
event.stopPropagation();
|
|
9
11
|
event.nativeEvent.stopImmediatePropagation();
|
|
10
12
|
}, onChange: (event) => {
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Ref } from 'react';
|
|
2
|
+
import { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types';
|
|
3
|
+
export declare type UploadPictureControl = {
|
|
4
|
+
getData: () => void;
|
|
5
|
+
};
|
|
6
|
+
export interface UploadPictureProps extends Omit<NativeElementPropsWithoutKeyAndRef<'div'>, 'children' | 'onChange' | 'onError' | 'value'> {
|
|
7
|
+
/**
|
|
8
|
+
* The accept attributes of native input element.
|
|
9
|
+
* @default 'image/*'
|
|
10
|
+
*/
|
|
11
|
+
accept?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Provide `controllerRef` if you need detail data of file.
|
|
14
|
+
*/
|
|
15
|
+
controllerRef?: Ref<UploadPictureControl | null>;
|
|
16
|
+
/**
|
|
17
|
+
* The default value of uploader.
|
|
18
|
+
*/
|
|
19
|
+
defaultValue?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Whether the input which is disabled.
|
|
22
|
+
* @default false
|
|
23
|
+
*/
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Fired after value changed.
|
|
27
|
+
*/
|
|
28
|
+
onChange?: (url: string) => void;
|
|
29
|
+
/**
|
|
30
|
+
* Fired after user delete image.
|
|
31
|
+
*/
|
|
32
|
+
onDelete?: () => void;
|
|
33
|
+
/**
|
|
34
|
+
* Fired after user upload image failed.
|
|
35
|
+
*/
|
|
36
|
+
onError?: (file: File) => void;
|
|
37
|
+
/**
|
|
38
|
+
* Fired when user upload image, need to return Promise<string>.
|
|
39
|
+
* Arg1 is target file, arg2 `setProgress` can set the progress of uploading.
|
|
40
|
+
*/
|
|
41
|
+
onUpload?: (file: File, setProgress: (progress: number) => void) => Promise<string>;
|
|
42
|
+
/**
|
|
43
|
+
* Fired after user upload image success.
|
|
44
|
+
*/
|
|
45
|
+
onUploadSuccess?: (file: File, url: string) => void;
|
|
46
|
+
}
|
|
47
|
+
declare const UploadPicture: import("react").ForwardRefExoticComponent<UploadPictureProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
48
|
+
export default UploadPicture;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { forwardRef, useRef, useCallback, useImperativeHandle } from 'react';
|
|
3
|
+
import { ImageUploader, uploadPictureClasses } from '@mezzanine-ui/core/upload';
|
|
4
|
+
import UploadPictureBlock from './UploadPictureBlock.js';
|
|
5
|
+
import cx from 'clsx';
|
|
6
|
+
|
|
7
|
+
const UploadPicture = forwardRef(function UploadPicture(props, ref) {
|
|
8
|
+
const { accept = 'image/*', className, controllerRef, defaultValue, disabled = false, onChange, onDelete, onError, onUpload, onUploadSuccess, style, } = props;
|
|
9
|
+
const defaultImageUploader = new ImageUploader(undefined, defaultValue);
|
|
10
|
+
const uploadPictureImageLoader = useRef(defaultImageUploader);
|
|
11
|
+
const onImageUpload = useCallback((files) => {
|
|
12
|
+
if (files.length) {
|
|
13
|
+
const currentFile = files[0];
|
|
14
|
+
uploadPictureImageLoader.current.setNewFile(currentFile);
|
|
15
|
+
uploadPictureImageLoader.current.setPreview();
|
|
16
|
+
if (onUpload) {
|
|
17
|
+
const setProgress = (progress) => uploadPictureImageLoader.current.setPercentage(progress);
|
|
18
|
+
uploadPictureImageLoader.current.setLoadingStatus(true);
|
|
19
|
+
onUpload(currentFile, setProgress)
|
|
20
|
+
.then((url) => {
|
|
21
|
+
uploadPictureImageLoader.current.setUrl(url);
|
|
22
|
+
uploadPictureImageLoader.current.setLoadingStatus(false);
|
|
23
|
+
setProgress(100);
|
|
24
|
+
if (onUploadSuccess) {
|
|
25
|
+
onUploadSuccess(currentFile, url);
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
.catch(() => {
|
|
29
|
+
uploadPictureImageLoader.current.setErrorStatus(true);
|
|
30
|
+
uploadPictureImageLoader.current.setLoadingStatus(false);
|
|
31
|
+
setProgress(100);
|
|
32
|
+
if (onError) {
|
|
33
|
+
onError(currentFile);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}, [onUpload, onUploadSuccess, onError]);
|
|
39
|
+
const onImageDelete = useCallback(() => {
|
|
40
|
+
uploadPictureImageLoader.current.clear();
|
|
41
|
+
if (onDelete) {
|
|
42
|
+
onDelete();
|
|
43
|
+
}
|
|
44
|
+
}, [onDelete]);
|
|
45
|
+
useImperativeHandle(controllerRef, () => ({
|
|
46
|
+
getData: () => uploadPictureImageLoader.current.getAll(),
|
|
47
|
+
}));
|
|
48
|
+
return (jsx("div", Object.assign({ ref: ref, className: cx(uploadPictureClasses.host, className), style: style }, { children: jsx(UploadPictureBlock, { accept: accept, disabled: disabled, imageLoader: uploadPictureImageLoader.current, multiple: false, onDelete: onImageDelete, onUpload: onImageUpload, onValueChange: onChange }, void 0) }), void 0));
|
|
49
|
+
});
|
|
50
|
+
var UploadPicture$1 = UploadPicture;
|
|
51
|
+
|
|
52
|
+
export { UploadPicture$1 as default };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MouseEventHandler } from 'react';
|
|
2
|
+
import { ImageUploader } from '@mezzanine-ui/core/upload';
|
|
3
|
+
import { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types';
|
|
4
|
+
export interface UploadPictureBlockProps extends Omit<NativeElementPropsWithoutKeyAndRef<'button'>, 'children' | 'onChange' | 'value'> {
|
|
5
|
+
accept?: string;
|
|
6
|
+
imageLoader: ImageUploader;
|
|
7
|
+
multiple?: boolean;
|
|
8
|
+
onDelete?: MouseEventHandler;
|
|
9
|
+
onUpload?: (files: File[]) => void;
|
|
10
|
+
onValueChange?: (value: string) => void;
|
|
11
|
+
}
|
|
12
|
+
declare const UploadPictureBlock: import("react").ForwardRefExoticComponent<UploadPictureBlockProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
13
|
+
export default UploadPictureBlock;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
2
|
+
import { forwardRef, useState, useRef, useEffect, useCallback, useMemo } from 'react';
|
|
3
|
+
import { toUploadPictureBlockCssVars, uploadPictureBlockClasses } from '@mezzanine-ui/core/upload';
|
|
4
|
+
import { TimesIcon, SpinnerIcon, UploadIcon, TrashIcon } from '@mezzanine-ui/icons';
|
|
5
|
+
import { usePreviousValue } from '../hooks/usePreviousValue.js';
|
|
6
|
+
import UploadInput from './UploadInput.js';
|
|
7
|
+
import Icon from '../Icon/Icon.js';
|
|
8
|
+
import cx from 'clsx';
|
|
9
|
+
|
|
10
|
+
const UploadPictureBlock = forwardRef(function UploadPictureBlock(props, ref) {
|
|
11
|
+
const { accept = 'image/*', disabled = false, imageLoader, multiple = false, onDelete, onUpload, onValueChange, } = props;
|
|
12
|
+
const [previewImage, setPreviewImage] = useState(imageLoader.getPreview() || '');
|
|
13
|
+
const [value, setValue] = useState(imageLoader.getUrl() || '');
|
|
14
|
+
const [percentage, setPercentage] = useState(imageLoader.getPercentage() || 0);
|
|
15
|
+
const [isLoading, setIsLoading] = useState(imageLoader.getIsLoading() || false);
|
|
16
|
+
const [isError, setIsError] = useState(imageLoader.getIsError() || false);
|
|
17
|
+
const inputRef = useRef(null);
|
|
18
|
+
const prevValue = usePreviousValue(value);
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (onValueChange && value !== prevValue) {
|
|
21
|
+
onValueChange(value);
|
|
22
|
+
}
|
|
23
|
+
}, [onValueChange, prevValue, value]);
|
|
24
|
+
const setImageUploaderData = useCallback(() => {
|
|
25
|
+
const data = imageLoader.getAll();
|
|
26
|
+
setPreviewImage(data.preview);
|
|
27
|
+
setValue(data.url);
|
|
28
|
+
setPercentage(data.percentage);
|
|
29
|
+
setIsLoading(data.isLoading);
|
|
30
|
+
setIsError(data.isError);
|
|
31
|
+
}, [imageLoader]);
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
imageLoader.on('fileChange', () => {
|
|
34
|
+
setImageUploaderData();
|
|
35
|
+
});
|
|
36
|
+
imageLoader.on('previewChange', () => {
|
|
37
|
+
setPreviewImage(imageLoader.getPreview());
|
|
38
|
+
});
|
|
39
|
+
imageLoader.on('percentageChange', () => {
|
|
40
|
+
setPercentage(imageLoader.getPercentage());
|
|
41
|
+
});
|
|
42
|
+
imageLoader.on('urlChange', () => {
|
|
43
|
+
setValue(imageLoader.getUrl());
|
|
44
|
+
});
|
|
45
|
+
imageLoader.on('loadingStatusChange', () => {
|
|
46
|
+
setIsLoading(imageLoader.getIsLoading());
|
|
47
|
+
});
|
|
48
|
+
imageLoader.on('errorStatusChange', () => {
|
|
49
|
+
setIsError(imageLoader.getIsError());
|
|
50
|
+
});
|
|
51
|
+
imageLoader.on('clear', () => {
|
|
52
|
+
setImageUploaderData();
|
|
53
|
+
});
|
|
54
|
+
return () => {
|
|
55
|
+
imageLoader.removeAllListeners();
|
|
56
|
+
};
|
|
57
|
+
}, [imageLoader, setImageUploaderData]);
|
|
58
|
+
const cssVars = toUploadPictureBlockCssVars({ percentage });
|
|
59
|
+
const style = {
|
|
60
|
+
...cssVars,
|
|
61
|
+
};
|
|
62
|
+
const showImage = useMemo(() => ((value || previewImage) && !isError), [previewImage, value, isError]);
|
|
63
|
+
const canDeleteImage = useMemo(() => ((showImage || isError) && !isLoading), [showImage, isError, isLoading]);
|
|
64
|
+
return (jsxs("button", Object.assign({ ref: ref, type: "button", "aria-disabled": disabled, disabled: disabled, onClick: (event) => {
|
|
65
|
+
var _a;
|
|
66
|
+
if (!showImage && !isError) {
|
|
67
|
+
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.click();
|
|
68
|
+
}
|
|
69
|
+
if (canDeleteImage && onDelete) {
|
|
70
|
+
onDelete(event);
|
|
71
|
+
}
|
|
72
|
+
}, className: cx(uploadPictureBlockClasses.host, {
|
|
73
|
+
[uploadPictureBlockClasses.loading]: isLoading,
|
|
74
|
+
[uploadPictureBlockClasses.error]: isError,
|
|
75
|
+
[uploadPictureBlockClasses.disabled]: disabled,
|
|
76
|
+
}), style: style }, { children: [jsx(UploadInput, { ref: inputRef, accept: accept, disabled: disabled, multiple: multiple, onUpload: onUpload }, void 0),
|
|
77
|
+
isError ? (jsxs("div", Object.assign({ className: uploadPictureBlockClasses.group }, { children: [jsx(Icon, { icon: TimesIcon }, void 0),
|
|
78
|
+
jsx("span", Object.assign({ className: uploadPictureBlockClasses.status }, { children: "\u4E0A\u50B3\u932F\u8AA4" }), void 0)] }), void 0)) : (jsx(Fragment, { children: showImage ? (jsxs(Fragment, { children: [jsx("img", { alt: "", src: (value || previewImage), className: uploadPictureBlockClasses.preview }, void 0),
|
|
79
|
+
isLoading ? (jsxs("div", Object.assign({ className: uploadPictureBlockClasses.group }, { children: [jsx(Icon, { icon: SpinnerIcon, spin: true }, void 0),
|
|
80
|
+
jsx("span", Object.assign({ className: uploadPictureBlockClasses.status }, { children: "\u4E0A\u50B3\u4E2D..." }), void 0)] }), void 0)) : null] }, void 0)) : (jsxs("div", Object.assign({ className: uploadPictureBlockClasses.group }, { children: [jsx(Icon, { icon: UploadIcon }, void 0),
|
|
81
|
+
jsx("span", Object.assign({ className: uploadPictureBlockClasses.status }, { children: "\u4E0A\u50B3\u5F71\u50CF" }), void 0)] }), void 0)) }, void 0)),
|
|
82
|
+
!disabled && canDeleteImage && (jsx("div", Object.assign({ className: uploadPictureBlockClasses.delete }, { children: jsx(Icon, { icon: TrashIcon }, void 0) }), void 0))] }), void 0));
|
|
83
|
+
});
|
|
84
|
+
var UploadPictureBlock$1 = UploadPictureBlock;
|
|
85
|
+
|
|
86
|
+
export { UploadPictureBlock$1 as default };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Ref } from 'react';
|
|
2
|
+
import { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types';
|
|
3
|
+
export declare type UploadPictureWallControl = {
|
|
4
|
+
getAllData: () => void;
|
|
5
|
+
};
|
|
6
|
+
export interface UploadPictureWallBaseProps extends Omit<NativeElementPropsWithoutKeyAndRef<'div'>, 'children' | 'onChange' | 'onError' | 'value'> {
|
|
7
|
+
/**
|
|
8
|
+
* The accept attributes of native input element.
|
|
9
|
+
* @default 'image/*'
|
|
10
|
+
*/
|
|
11
|
+
accept?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Provide `controllerRef` if you need detail data of files.
|
|
14
|
+
*/
|
|
15
|
+
controllerRef?: Ref<UploadPictureWallControl | null>;
|
|
16
|
+
/**
|
|
17
|
+
* The default values of uploader.
|
|
18
|
+
*/
|
|
19
|
+
defaultValues?: string[];
|
|
20
|
+
/**
|
|
21
|
+
* Whether the input which is disabled.
|
|
22
|
+
* @default false
|
|
23
|
+
*/
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Whether the input which is multiple.
|
|
27
|
+
* @default true
|
|
28
|
+
*/
|
|
29
|
+
multiple?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Fired after values changed.
|
|
32
|
+
*/
|
|
33
|
+
onChange?: (urls: string[]) => void;
|
|
34
|
+
/**
|
|
35
|
+
* Fired after user delete image.
|
|
36
|
+
*/
|
|
37
|
+
onDelete?: (urls: string[]) => void;
|
|
38
|
+
/**
|
|
39
|
+
* Fired after user upload images failed.
|
|
40
|
+
*/
|
|
41
|
+
onError?: (files: File | File[]) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Fired after user upload images success.
|
|
44
|
+
*/
|
|
45
|
+
onUploadSuccess?: (files: File | File[], urls: string | string[]) => void;
|
|
46
|
+
}
|
|
47
|
+
export interface UploadPictureWallSingleUploadProps extends UploadPictureWallBaseProps {
|
|
48
|
+
onMultiUpload?: undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Fired when user upload image, need to return Promise<string>.
|
|
51
|
+
* Arg1 is target file, arg2 `setProgress` can set the progress of uploading.
|
|
52
|
+
*/
|
|
53
|
+
onUpload?: (file: File, setProgress: (progress: number) => void) => Promise<string>;
|
|
54
|
+
/**
|
|
55
|
+
* Whether the uploading which is parallel, only enabled when `onUpload` is given .
|
|
56
|
+
* @default false
|
|
57
|
+
*/
|
|
58
|
+
parallel?: boolean;
|
|
59
|
+
}
|
|
60
|
+
export interface UploadPictureWallMultiUploadProps extends UploadPictureWallBaseProps {
|
|
61
|
+
/**
|
|
62
|
+
* Fired when user upload images, need to return Promise<string[]>.
|
|
63
|
+
* Arg1 is target files, arg2 `setProgress` can set the progress of uploading.
|
|
64
|
+
*/
|
|
65
|
+
onMultiUpload?: (files: File[], setProgress: (progress: number) => void) => Promise<string[]>;
|
|
66
|
+
onUpload?: undefined;
|
|
67
|
+
parallel?: undefined;
|
|
68
|
+
}
|
|
69
|
+
export declare type UploadPictureWallProps = UploadPictureWallSingleUploadProps | UploadPictureWallMultiUploadProps;
|
|
70
|
+
declare const UploadPictureWall: import("react").ForwardRefExoticComponent<(UploadPictureWallSingleUploadProps & import("react").RefAttributes<HTMLDivElement>) | (UploadPictureWallMultiUploadProps & import("react").RefAttributes<HTMLDivElement>)>;
|
|
71
|
+
export default UploadPictureWall;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { forwardRef, useState, useMemo, useEffect, useCallback, useImperativeHandle } from 'react';
|
|
3
|
+
import { ImageUploader, uploadPictureWallClasses } from '@mezzanine-ui/core/upload';
|
|
4
|
+
import compact from 'lodash/compact';
|
|
5
|
+
import drop from 'lodash/drop';
|
|
6
|
+
import isEqual from 'lodash/isEqual';
|
|
7
|
+
import { usePreviousValue } from '../hooks/usePreviousValue.js';
|
|
8
|
+
import UploadPictureWallItem from './UploadPictureWallItem.js';
|
|
9
|
+
import cx from 'clsx';
|
|
10
|
+
|
|
11
|
+
const UploadPictureWall = forwardRef(function UploadPictureWall(props, ref) {
|
|
12
|
+
const { accept = 'image/*', className, controllerRef, defaultValues, disabled = false, multiple = true, onChange, onDelete, onError, onMultiUpload, onUpload, onUploadSuccess, parallel = false, style, } = props;
|
|
13
|
+
const [uploadPictureImageLoaders, setUploadPictureImageLoader] = useState(defaultValues ? compact(defaultValues).map((value) => new ImageUploader(undefined, value)) : []);
|
|
14
|
+
const [needUploadImageLoaders, setNeedUploadImageLoaders] = useState([]);
|
|
15
|
+
const [needUploadImageLoaderSets, setNeedUploadImageLoaderSets] = useState([]);
|
|
16
|
+
const [values, setValues] = useState(compact(defaultValues) || []);
|
|
17
|
+
const loaderList = useMemo(() => uploadPictureImageLoaders, [uploadPictureImageLoaders]);
|
|
18
|
+
const prevNeedUploadImageLoadersLength = usePreviousValue(needUploadImageLoaders.length);
|
|
19
|
+
const prevNeedUploadImageLoaderSetsLength = usePreviousValue(needUploadImageLoaderSets.length);
|
|
20
|
+
const prevValues = usePreviousValue(values);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (onChange && !isEqual(prevValues, values)) {
|
|
23
|
+
onChange(values);
|
|
24
|
+
}
|
|
25
|
+
}, [onChange, prevValues, values]);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (prevNeedUploadImageLoadersLength > needUploadImageLoaders.length ||
|
|
28
|
+
prevNeedUploadImageLoaderSetsLength > needUploadImageLoaderSets.length) {
|
|
29
|
+
setValues(compact(uploadPictureImageLoaders.map((loader) => loader.getUrl())));
|
|
30
|
+
}
|
|
31
|
+
}, [
|
|
32
|
+
uploadPictureImageLoaders,
|
|
33
|
+
needUploadImageLoaders,
|
|
34
|
+
prevNeedUploadImageLoadersLength,
|
|
35
|
+
needUploadImageLoaderSets,
|
|
36
|
+
prevNeedUploadImageLoaderSetsLength,
|
|
37
|
+
]);
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (needUploadImageLoaderSets.length && onUpload) {
|
|
40
|
+
const imageLoaderSet = needUploadImageLoaderSets[0];
|
|
41
|
+
if (!imageLoaderSet[0].getIsLoading()) {
|
|
42
|
+
imageLoaderSet.forEach((imageLoader, index) => {
|
|
43
|
+
const setProgress = (progress) => imageLoader.setPercentage(progress);
|
|
44
|
+
imageLoader.setLoadingStatus(true);
|
|
45
|
+
onUpload(imageLoader.getFile(), setProgress)
|
|
46
|
+
.then((url) => {
|
|
47
|
+
imageLoader.setUrl(url);
|
|
48
|
+
imageLoader.setLoadingStatus(false);
|
|
49
|
+
setProgress(100);
|
|
50
|
+
if (onUploadSuccess) {
|
|
51
|
+
onUploadSuccess(imageLoader.getFile(), url);
|
|
52
|
+
}
|
|
53
|
+
if (index === imageLoaderSet.length - 1) {
|
|
54
|
+
setNeedUploadImageLoaderSets((nup) => drop(nup));
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
.catch(() => {
|
|
58
|
+
imageLoader.setErrorStatus(true);
|
|
59
|
+
imageLoader.setLoadingStatus(false);
|
|
60
|
+
setProgress(100);
|
|
61
|
+
if (index === imageLoaderSet.length - 1) {
|
|
62
|
+
setNeedUploadImageLoaderSets((nup) => drop(nup));
|
|
63
|
+
}
|
|
64
|
+
if (onError) {
|
|
65
|
+
onError(imageLoader.getFile());
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}, [needUploadImageLoaderSets, onError, onUpload, onUploadSuccess]);
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
if (needUploadImageLoaders.length && onUpload) {
|
|
74
|
+
const imageLoader = needUploadImageLoaders[0];
|
|
75
|
+
if (imageLoader && imageLoader.getFile() && !imageLoader.getIsLoading()) {
|
|
76
|
+
const setProgress = (progress) => imageLoader.setPercentage(progress);
|
|
77
|
+
imageLoader.setLoadingStatus(true);
|
|
78
|
+
onUpload(imageLoader.getFile(), setProgress)
|
|
79
|
+
.then((url) => {
|
|
80
|
+
imageLoader.setUrl(url);
|
|
81
|
+
imageLoader.setLoadingStatus(false);
|
|
82
|
+
setProgress(100);
|
|
83
|
+
setNeedUploadImageLoaders((nup) => drop(nup));
|
|
84
|
+
if (onUploadSuccess) {
|
|
85
|
+
onUploadSuccess(imageLoader.getFile(), url);
|
|
86
|
+
}
|
|
87
|
+
})
|
|
88
|
+
.catch(() => {
|
|
89
|
+
imageLoader.setErrorStatus(true);
|
|
90
|
+
imageLoader.setLoadingStatus(false);
|
|
91
|
+
setProgress(100);
|
|
92
|
+
setNeedUploadImageLoaders((nup) => drop(nup));
|
|
93
|
+
if (onError) {
|
|
94
|
+
onError(imageLoader.getFile());
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}, [needUploadImageLoaders, onError, onUpload, onUploadSuccess]);
|
|
100
|
+
const onImagesUpload = useCallback((files) => {
|
|
101
|
+
if (files.length) {
|
|
102
|
+
const imageLoaders = files.map((file) => new ImageUploader(file));
|
|
103
|
+
setUploadPictureImageLoader((ups) => [...ups, ...imageLoaders]);
|
|
104
|
+
if (onMultiUpload) {
|
|
105
|
+
const uploadFiles = imageLoaders.map((loader) => loader.getFile());
|
|
106
|
+
const setProgress = (progress) => imageLoaders.forEach((loader) => loader.setPercentage(progress));
|
|
107
|
+
imageLoaders.forEach((loader) => loader.setLoadingStatus(true));
|
|
108
|
+
onMultiUpload(uploadFiles, setProgress)
|
|
109
|
+
.then((urls) => {
|
|
110
|
+
imageLoaders.forEach((loader, index) => loader.setUrl(urls[index]));
|
|
111
|
+
imageLoaders.forEach((loader) => loader.setLoadingStatus(false));
|
|
112
|
+
setProgress(100);
|
|
113
|
+
setValues((v) => [...v, ...urls]);
|
|
114
|
+
if (onUploadSuccess) {
|
|
115
|
+
onUploadSuccess(uploadFiles, urls);
|
|
116
|
+
}
|
|
117
|
+
})
|
|
118
|
+
.catch(() => {
|
|
119
|
+
imageLoaders.forEach((loader) => loader.setErrorStatus(true));
|
|
120
|
+
imageLoaders.forEach((loader) => loader.setLoadingStatus(false));
|
|
121
|
+
setProgress(100);
|
|
122
|
+
if (onError) {
|
|
123
|
+
onError(uploadFiles);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (onUpload) {
|
|
129
|
+
if (!parallel) {
|
|
130
|
+
setNeedUploadImageLoaders((nups) => [...nups, ...imageLoaders]);
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
setNeedUploadImageLoaderSets((set) => [...set, imageLoaders]);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}, [onError, onMultiUpload, onUpload, onUploadSuccess, parallel]);
|
|
138
|
+
const onImageDelete = useCallback((uid) => {
|
|
139
|
+
setUploadPictureImageLoader((ups) => ups.filter((up) => up.getUid() !== uid));
|
|
140
|
+
setNeedUploadImageLoaders((nUps) => nUps.filter((nUp) => nUp.getUid() !== uid));
|
|
141
|
+
const nowUploadPictureImageLoaders = uploadPictureImageLoaders.filter((up) => up.getUid() !== uid);
|
|
142
|
+
const urls = compact(nowUploadPictureImageLoaders.map((loader) => loader.getUrl()));
|
|
143
|
+
setValues(urls);
|
|
144
|
+
if (onDelete) {
|
|
145
|
+
onDelete(urls);
|
|
146
|
+
}
|
|
147
|
+
}, [onDelete, uploadPictureImageLoaders]);
|
|
148
|
+
useImperativeHandle(controllerRef, () => ({
|
|
149
|
+
getAllData: () => uploadPictureImageLoaders.map((loader) => loader.getAll()),
|
|
150
|
+
}));
|
|
151
|
+
return (jsxs("div", Object.assign({ ref: ref, className: cx(uploadPictureWallClasses.host, className), style: style }, { children: [loaderList.map((up) => (jsx(UploadPictureWallItem, { accept: accept, disabled: disabled, imageLoader: up, multiple: multiple, onDelete: () => onImageDelete(up.getUid()) }, up.getUid()))),
|
|
152
|
+
jsx(UploadPictureWallItem, { accept: accept, disabled: disabled, imageLoader: new ImageUploader(), multiple: multiple, onUpload: onImagesUpload }, void 0)] }), void 0));
|
|
153
|
+
});
|
|
154
|
+
var UploadPictureWall$1 = UploadPictureWall;
|
|
155
|
+
|
|
156
|
+
export { UploadPictureWall$1 as default };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MouseEventHandler } from 'react';
|
|
2
|
+
import { ImageUploader } from '@mezzanine-ui/core/upload';
|
|
3
|
+
import { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types';
|
|
4
|
+
export interface UploadPictureWallItemProps extends Omit<NativeElementPropsWithoutKeyAndRef<'div'>, 'value' | 'onChange' | 'children'> {
|
|
5
|
+
accept?: string;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
imageLoader: ImageUploader;
|
|
8
|
+
multiple?: boolean;
|
|
9
|
+
onDelete?: MouseEventHandler;
|
|
10
|
+
onUpload?: (files: File[]) => void;
|
|
11
|
+
}
|
|
12
|
+
declare const UploadPictureWallItem: (props: UploadPictureWallItemProps) => JSX.Element;
|
|
13
|
+
export default UploadPictureWallItem;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useRef, useEffect } from 'react';
|
|
3
|
+
import { uploadPictureWallClasses } from '@mezzanine-ui/core/upload';
|
|
4
|
+
import UploadPictureBlock from './UploadPictureBlock.js';
|
|
5
|
+
import cx from 'clsx';
|
|
6
|
+
|
|
7
|
+
const UploadPictureWallItem = (props) => {
|
|
8
|
+
const { accept, disabled, imageLoader, multiple, onDelete, onUpload, } = props;
|
|
9
|
+
const loader = useRef(imageLoader);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (!loader.current.getPreview()) {
|
|
12
|
+
loader.current.setPreview();
|
|
13
|
+
}
|
|
14
|
+
}, []);
|
|
15
|
+
return (jsx("div", Object.assign({ className: cx(uploadPictureWallClasses.item) }, { children: jsx(UploadPictureBlock, { accept: accept, disabled: disabled, imageLoader: loader.current, multiple: multiple, onDelete: onDelete, onUpload: onUpload }, void 0) }), void 0));
|
|
16
|
+
};
|
|
17
|
+
var UploadPictureWallItem$1 = UploadPictureWallItem;
|
|
18
|
+
|
|
19
|
+
export { UploadPictureWallItem$1 as default };
|