@onehat/ui 0.3.6 → 0.3.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onehat/ui",
3
- "version": "0.3.6",
3
+ "version": "0.3.7",
4
4
  "description": "Base UI for OneHat apps",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -1,15 +1,17 @@
1
1
  import UiGlobals from '../UiGlobals.js';
2
+ import Attachments from '../PlatformImports/Web/Attachments.js';
2
3
  // import CKEditor from '../Components/Form/Field/CKEditor/CKEditor.js';
3
4
  import Datetime from '../PlatformImports/Web/Datetime.js';
4
5
  import Draggable from '../PlatformImports/Web/Draggable.js';
5
- import File from '../PlatformImports/Web/File.js';
6
+ // import File from '../PlatformImports/Web/Attachments.js';
6
7
  import _ from 'lodash';
7
8
 
8
9
  export default function registerWebComponents() {
9
10
  _.merge(UiGlobals.components, {
11
+ Attachments,
10
12
  // CKEditor, // The CKEditor was giving me CSS import errors, so had to disable it until I can fix those
11
13
  Datetime,
12
14
  Draggable,
13
- File,
15
+ // File,
14
16
  });
15
17
  }
@@ -0,0 +1,122 @@
1
+ import React, { useState, useEffect, useRef, } from 'react';
2
+ import {
3
+ Box,
4
+ Icon,
5
+ Row,
6
+ Text,
7
+ Tooltip,
8
+ } from 'native-base';
9
+ import {
10
+ CURRENT_MODE,
11
+ UI_MODE_WEB,
12
+ UI_MODE_REACT_NATIVE,
13
+ } from '../../../Constants/UiModes.js';
14
+ import UiGlobals from '../../../UiGlobals.js';
15
+ import {
16
+ FILE_MODE_IMAGE,
17
+ FILE_MODE_FILE,
18
+ } from '../../../Constants/File.js';
19
+ import { Avatar, Dropzone, FileMosaic, FileCard, FileInputButton, } from "@files-ui/react";
20
+ import withData from '../../Components/Hoc/withData.js';
21
+ import _ from 'lodash';
22
+
23
+ function AttachmentsElement(props) {
24
+
25
+ if (CURRENT_MODE !== UI_MODE_WEB) {
26
+ throw new Error('Not yet implemented except for web.');
27
+ }
28
+
29
+ const {
30
+ canCrud = true,
31
+ _dropZone = {},
32
+ _fileMosaic = {},
33
+ accept = '*', // 'image/*'
34
+ maxFiles = null,
35
+ maxFileSize = 28 * 1024,
36
+ disabled = false,
37
+ clickable = true,
38
+ isImageOnly = false,
39
+
40
+ // withData
41
+ Repository,
42
+
43
+ } = props,
44
+ styles = UiGlobals.styles,
45
+ WhichFile = isImageOnly ? Avatar : FileMosaic,
46
+ onDelete = (a,b,c,d,e) => {
47
+
48
+ };
49
+
50
+ if (canCrud) {
51
+ return <Dropzone
52
+ value={files}
53
+ onChange={updateFiles}
54
+ accept={accept}
55
+ maxFiles={maxFiles}
56
+ maxFileSize={maxFileSize}
57
+ validator={() => {}}
58
+ autoClean={true}
59
+ uploadConfig={{
60
+ url: Repository.api.baseURL + Repository.name + '/uploadAttachments',
61
+ method: 'POST',
62
+ headers: Repository.headers,
63
+ autoUpload: true,
64
+ }}
65
+ onUploadFinish={handleFinishUpload}
66
+ background={styles.ATTACHMENTS_BG}
67
+ color={styles.ATTACHMENTS_COLOR}
68
+ minHeight={150}
69
+ clickable={clickable}
70
+ {..._dropZone}
71
+ >
72
+ {files.map((file) => {
73
+ // const ExtFile = {
74
+ // id string | number The identifier of the file
75
+ // file File The file object obtained from client drop or selection
76
+ // name string The name of the file
77
+ // type string The file mime type.
78
+ // size number The size of the file in bytes.
79
+ // valid boolean If present, it will show a valid or rejected message ("valid", "denied"). By default valid is undefined.
80
+ // errors string[] The list of errors according to the validation criteria or the result of the given custom validation function.
81
+ // uploadStatus UPLOADSTATUS The current upload status. (e.g. "uploading").
82
+ // uploadMessage string A message that shows the result of the upload process.
83
+ // imageUrl string A string representation or web url of the image that will be set to the "src" prop of an <img/> tag. If given, the component will use this image source instead of reading the image file.
84
+ // downloadUrl string The url to be used to perform a GET request in order to download the file. If defined, the download icon will be shown.
85
+ // progress number The current percentage of upload progress. This value will have a higher priority over the upload progress value calculated inside the component.
86
+ // extraUploadData Record<string, any> The additional data that will be sent to the server when files are uploaded individually
87
+ // extraData Object Any kind of extra data that could be needed.
88
+ // serverResponse ServerResponse The upload response from server.
89
+ // xhr XMLHttpRequest A reference to the XHR object that allows the upload, progress and abort events.
90
+ // };
91
+ return <WhichFile
92
+ key={file.id}
93
+ {...file}
94
+ backgroundBlurImage={false}
95
+ onDelete={onDelete}
96
+ info
97
+ {..._fileMosaic}
98
+ />;
99
+ })}
100
+ </Dropzone>;
101
+
102
+ }
103
+
104
+ return <Row
105
+ flex={1}
106
+ minHeight={150}
107
+ background={styles.ATTACHMENTS_BG}
108
+ color={styles.ATTACHMENTS_COLOR}
109
+ >
110
+ {files.map((file) => {
111
+ return <WhichFile
112
+ key={file.id}
113
+ {...file}
114
+ onDelete={removeFile}
115
+ info
116
+ {..._fileMosaic}
117
+ />;
118
+ })}
119
+ </Row>;
120
+ }
121
+
122
+ export default withData(AttachmentsElement);
@@ -1,138 +0,0 @@
1
- import React, { useState, useEffect, useRef, } from 'react';
2
- import {
3
- Box,
4
- Icon,
5
- Row,
6
- Text,
7
- Tooltip,
8
- } from 'native-base';
9
- import {
10
- CURRENT_MODE,
11
- UI_MODE_WEB,
12
- UI_MODE_REACT_NATIVE,
13
- } from '../../../Constants/UiModes.js';
14
- import UiGlobals from '../../../UiGlobals.js';
15
- import {
16
- FILE_MODE_IMAGE,
17
- FILE_MODE_FILE,
18
- } from '../../../Constants/File.js';
19
- import { Dropzone, FileMosaic, FileCard, FileInputButton, } from "@files-ui/react";
20
- import IconButton from '../../Buttons/IconButton.js';
21
- import withValue from '../../Hoc/withValue.js';
22
- import File from '../../Icons/File.js';
23
- import Trash from '../../Icons/Trash.js';
24
- import _ from 'lodash';
25
-
26
- function FileElement(props) {
27
-
28
- if (CURRENT_MODE !== UI_MODE_WEB) {
29
- throw new Error('Not yet implemented except for web.');
30
- }
31
-
32
- const {
33
- name,
34
- value = {
35
- dataUri: null,
36
- control: null,
37
- filename: null,
38
- },
39
- setValue,
40
-
41
- mode = FILE_MODE_IMAGE, // FILE_MODE_IMAGE, FILE_MODE_FILE
42
- imagePath = '',
43
- tooltip = 'Choose or drag a file on top of this control.',
44
- tooltipPlacement = 'bottom',
45
- } = props,
46
- styles = UiGlobals.styles,
47
- dragRef = useRef(),
48
- fileInputRef = useRef(),
49
- [isDropping, setIsDropping] = useState(false),
50
- onSelect = () => {
51
- fileInputRef.current.click();
52
-
53
- setValue({
54
- dataUri: null,
55
- control: null,
56
- filename: null,
57
- version,
58
- });
59
- },
60
- setBase64 = (file, readerResult) => {
61
- const
62
- base64 = btoa(readerResult), // 'btoa' is deprecated in Node.js, but not browsers, so use it! // https://developer.mozilla.org/en-US/docs/Web/API/btoa
63
- dataUri = `data:${file.type};base64,${base64}`,
64
- control = '',
65
- filename = file.name;
66
-
67
- },
68
- onDrop = (e) => {
69
- e.preventDefault();
70
- const
71
- files = e.dataTransfer && e.dataTransfer.files,
72
- file = files[0],
73
- reader = new FileReader();
74
-
75
- reader.readAsDataURL(file);
76
- reader.onload = (e) => {
77
- setBase64(file, e.target.result);
78
- };
79
- setIsDropping(false);
80
- };
81
-
82
- return null;
83
-
84
- return <div ref={dragRef} style={{ flex: 1, height: '100%', }} onDragEnter={onDragEnter} onDragLeave={onDragLeave} onDragOver={onDragOver} onDrop={onDrop}>
85
- <Tooltip label={tooltip} placement={tooltipPlacement}>
86
- <Row flex={1} h={10} alignItems="center">
87
- {isDropping && <Box position="absolute" borderWidth={isDropping ? 2 : 0} borderColor="primary.800" top={0} left={0} w="100%" h="100%" bg="trueGray.200" zIndex={10000} justifyContent="center" alignItems="center">
88
- <Text>Set File</Text>
89
- </Box>}
90
- <IconButton
91
- icon={<Icon as={File} color={styles.FORM_FILE_ICON_COLOR} />}
92
- onPress={onSelect}
93
- h={10}
94
- w={10}
95
- bg={styles.FORM_FILE_ICON_BG}
96
- _hover={{
97
- bg: styles.FORM_FILE_ICON_BG_HOVER,
98
- }}
99
- />
100
- <IconButton
101
- icon={<Icon as={Trash} color={styles.FORM_FILE_ICON_COLOR} />}
102
- onPress={onClear}
103
- h={10}
104
- w={10}
105
- ml={1}
106
- isDisabled={!value?.dataUri}
107
- bg={value?.dataUri ? styles.FORM_FILE_ICON_BG : 'disabled'}
108
- _hover={{
109
- bg: value?.dataUri ? styles.FORM_FILE_ICON_BG_HOVER : 'disabled',
110
- }}
111
- />
112
- {mode === FILE_MODE_FILE && <Text
113
- flex={1}
114
- ml={3}
115
- fontSize={styles.FORM_FILE_READOUT_FONTSIZE}
116
- fontStyle="italic"
117
- numberOfLines={1}
118
- ellipsizeMode="head"
119
- bg={styles.FORM_FILE_READOUT_BG}
120
- >{value.filename || 'No file'}</Text>}
121
- {mode === FILE_MODE_IMAGE && <Box
122
- flex={1}
123
- h="100%"
124
- ml={1}
125
- bg={styles.FORM_FILE_READOUT_BG}
126
- backgroundImage={value?.dataUri ? 'url(' + imagePath + encodeURIComponent(value.dataUri) + ')' : 'none'}
127
- backgroundSize="contain"
128
- backgroundRepeat="no-repeat"
129
- borderRadius={4}
130
- borderWidth={1}
131
- />}
132
- <input type="file" ref={fileInputRef} name={name} onChange={onChangeFile} style={{ position: 'absolute', opacity: 0, height: 0, width: 0, }} />
133
- </Row>
134
- </Tooltip>
135
- </div>;
136
- }
137
-
138
- export default withValue(FileElement);