groundfloor-react-ui 1.0.0 → 1.0.1

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.
@@ -1,90 +1,134 @@
1
- import React, { useState, createRef } from "react";
1
+ import React, { useState, createRef } from 'react';
2
2
  import styled from 'styled-components';
3
3
  import defaultThemeColor from '../constants/defaultThemeColor';
4
- import PropTypes from "prop-types";
4
+ import PropTypes from 'prop-types';
5
5
  import defaultStyles from '../constants/defaultStyle';
6
- import getDefaultStyles from "../constants/utils";
7
- import { hexToRGB } from "../constants/utils";
8
-
9
- import { Icon } from "../Icon";
10
- import { Label } from "../Label";
6
+ import getDefaultStyles from '../constants/utils';
7
+ import { hexToRGB } from '../constants/utils';
11
8
 
9
+ import { Icon } from '../Icon';
10
+ import { Label } from '../Label';
12
11
 
13
12
  const ParentDiv = styled.div`
14
-
15
- //Set the styles from the default styles object
16
- ${({ theme, defaultStyles }) => {
13
+ //Set the styles from the default styles object
14
+ ${({ theme, defaultStyles }) => {
17
15
  return getDefaultStyles(theme, defaultStyles);
18
16
  }}
19
-
20
- background-color:${({ hover, isValid, fileArr, backgroundColor }) => !isValid ?
21
- 'rgba(215, 0, 0, 0.05)' : hover ? backgroundColor :
22
- fileArr.length > 0 ? defaultThemeColor.bgColor : hexToRGB(backgroundColor, 0.05)};
23
- border: 1px ${({ isValid, fileArr, backgroundColor }) => !isValid ? 'dashed ' +
24
- defaultThemeColor.ui['error'] : fileArr.length > 0 ? 'solid ' + backgroundColor : 'dashed ' + backgroundColor};
25
-
26
- &:hover{
27
- cursor: pointer;
28
- }
29
- transition: all 500ms linear;
30
17
 
31
-
32
- // custom styles
33
- ${({ customDropzoneStyles }) => customDropzoneStyles}
34
- `;
18
+ background-color:${({ hover, isValid, fileArr, backgroundColor }) =>
19
+ !isValid
20
+ ? 'rgba(215, 0, 0, 0.05)'
21
+ : hover
22
+ ? backgroundColor
23
+ : fileArr.length > 0
24
+ ? defaultThemeColor.bgColor
25
+ : hexToRGB(backgroundColor, 0.05)};
26
+ border: 1px
27
+ ${({ isValid, fileArr, backgroundColor }) =>
28
+ !isValid
29
+ ? 'dashed ' + defaultThemeColor.ui['error']
30
+ : fileArr.length > 0
31
+ ? 'solid ' + backgroundColor
32
+ : 'dashed ' + backgroundColor};
33
+
34
+ &:hover {
35
+ cursor: pointer;
36
+ }
37
+ transition: all 500ms linear;
35
38
 
39
+ // custom styles
40
+ ${({ customDropzoneStyles }) => customDropzoneStyles}
41
+ `;
36
42
 
37
43
  const FileDiv = styled.div`
38
- //Set the styles from the default styles object
39
- ${({ theme, defaultStyles }) => {
44
+ //Set the styles from the default styles object
45
+ ${({ theme, defaultStyles }) => {
40
46
  return getDefaultStyles(theme, defaultStyles);
41
47
  }}
42
-
43
- // custom styles
48
+
49
+ // custom styles
44
50
  ${({ customFileStyles }) => customFileStyles}
45
51
  `;
46
52
 
47
53
  const InputFile = styled.input`
48
- display: none;
54
+ display: none;
49
55
  `;
50
56
 
51
57
  const TextDiv = styled.div`
52
- //Set the styles from the default styles object
53
- ${({ theme, defaultStyles }) => {
58
+ //Set the styles from the default styles object
59
+ ${({ theme, defaultStyles }) => {
54
60
  return getDefaultStyles(theme, defaultStyles);
55
61
  }}
56
-
57
- // custom styles
62
+
63
+ // custom styles
58
64
  ${({ customTextStyles }) => customTextStyles}
59
65
  `;
60
66
 
61
67
  const FileName = styled.span`
62
- //Set the styles from the default styles object
63
- ${({ theme, type }) => {
68
+ //Set the styles from the default styles object
69
+ ${({ theme, type }) => {
64
70
  return getDefaultStyles(theme, type);
65
71
  }}
66
-
67
- // custom styles
72
+
73
+ // custom styles
68
74
  ${({ customFileNameStyles }) => customFileNameStyles}
69
75
  `;
70
76
 
71
77
  const CrossDiv = styled.div`
72
- cursor: pointer;
73
- padding-left: 1px;
74
- margin-left: auto;
75
- margin-right: 10px;
76
- display: flex;
77
- justify-content: center;
78
+ cursor: pointer;
79
+ padding-left: 1px;
80
+ margin-left: auto;
81
+ margin-right: 10px;
82
+ display: flex;
83
+ justify-content: center;
78
84
  `;
79
85
 
80
86
  const IconDiv = styled.div`
81
- margin-left: 11px;
82
- padding-left: 2px;
83
- display: flex;
84
- justify-content: center;
87
+ margin-left: 11px;
88
+ padding-left: 2px;
89
+ display: flex;
90
+ justify-content: center;
85
91
  `;
86
92
 
87
- export const DropzoneInput = ({ theme, themeColor, isValid, label, labelStyle, labelInline, required, message, fileArr, setFileArr, deleteFile, customDropzoneStyles, customFileStyles, customTextStyles, customFileNameStyles, backgroundColor, singleFile, messageSize, ...props }) => {
93
+ const OtherInfoDiv = styled.div`
94
+ color: #494949;
95
+ margin-left: 11px;
96
+ padding-left: 2px;
97
+ `
98
+
99
+ const AdditionalText = styled.p`
100
+ color: #494949;
101
+ display: flex;
102
+ justify-content: center;
103
+ align-items: center;
104
+ max-width: 514px;
105
+ margin:20px 0px;
106
+ font-size: 14px;
107
+
108
+ `
109
+
110
+ export const DropzoneInput = ({
111
+ theme,
112
+ themeColor,
113
+ isValid,
114
+ label,
115
+ labelStyle,
116
+ labelInline,
117
+ required,
118
+ message,
119
+ fileArr,
120
+ setFileArr,
121
+ deleteFile,
122
+ customDropzoneStyles,
123
+ customFileStyles,
124
+ customTextStyles,
125
+ customFileNameStyles,
126
+ backgroundColor,
127
+ singleFile,
128
+ messageSize,
129
+ additionalText,
130
+ ...props
131
+ }) => {
88
132
  const [hover, setHover] = useState(false);
89
133
  const fileInputRef = createRef();
90
134
 
@@ -99,13 +143,11 @@ export const DropzoneInput = ({ theme, themeColor, isValid, label, labelStyle, l
99
143
  setHover(true);
100
144
  }
101
145
 
102
-
103
146
  function onDragLeave(event) {
104
147
  stopEvent(event);
105
148
  setHover(false);
106
149
  }
107
150
 
108
-
109
151
  function onDrop(event) {
110
152
  stopEvent(event);
111
153
 
@@ -114,24 +156,24 @@ export const DropzoneInput = ({ theme, themeColor, isValid, label, labelStyle, l
114
156
  props.onFilesAdded(fileListToArray(files, singleFile));
115
157
  }
116
158
 
117
-
118
159
  function stopEvent(event) {
119
160
  event.preventDefault();
120
161
  event.stopPropagation();
121
162
  }
122
163
 
123
-
124
164
  function fileListToArray(list, singleFile) {
125
165
  let result = singleFile == true ? [] : [...fileArr];
126
166
  for (let i = 0; i < list.length; i++) {
127
167
  result.push(list.item(i));
128
168
  }
129
169
  if (!singleFile) {
130
- result = result.filter((value, index, self) =>
131
- index === self.findIndex((t) => (
132
- t.place === value.place && t.name === value.name
133
- ))
134
- )
170
+ result = result.filter(
171
+ (value, index, self) =>
172
+ index ===
173
+ self.findIndex(
174
+ (t) => t.place === value.place && t.name === value.name
175
+ )
176
+ );
135
177
  }
136
178
  setFileArr(result);
137
179
  setHover(false);
@@ -139,36 +181,29 @@ export const DropzoneInput = ({ theme, themeColor, isValid, label, labelStyle, l
139
181
  }
140
182
 
141
183
  function deleteItemFromServer(file, i) {
142
- const updateFiles = fileArr.filter(item => item.name !== file.name);
184
+ const updateFiles = fileArr.filter((item) => item.name !== file.name);
143
185
  setFileArr(updateFiles);
144
186
  deleteFile(file);
145
187
  }
146
188
 
147
189
  function fileRemoveFromArary(file, i) {
148
190
  if (file instanceof File) {
149
- const updateFiles = fileArr.filter(item => item.name !== file.name);
191
+ const updateFiles = fileArr.filter((item) => item.name !== file.name);
150
192
  setFileArr(updateFiles);
151
- // console.log(updateFiles,fileArr);
152
193
  } else {
153
194
  deleteItemFromServer(file, i);
154
195
  }
155
196
  }
156
197
 
157
-
158
198
  function openFileDialog() {
159
199
  fileInputRef.current.click();
160
200
  }
161
201
  return (
162
- <div style={{
163
- // display: 'flex',
164
- // flexDirection: 'column',
165
- // alignItems: 'center',
166
- /* align-content: stretch; */
167
- // width: '532px',
168
- // boxSizing: 'border-box',
169
- // maxHeight: 'calc(70vh - 129px)',
170
- paddingBottom: '5px',
171
- }}>
202
+ <div
203
+ style={{
204
+ paddingBottom: '5px',
205
+ }}
206
+ >
172
207
  <div style={{ display: 'flex' }}>
173
208
  <Label
174
209
  themeColor={defaultThemeColor}
@@ -177,14 +212,21 @@ export const DropzoneInput = ({ theme, themeColor, isValid, label, labelStyle, l
177
212
  labelInline={labelInline}
178
213
  text={label}
179
214
  style={{
180
- 'display': 'flex',
181
- 'paddingBottom': `${!labelInline ? '16.64px' : ''}`,
215
+ display: 'flex',
216
+ paddingBottom: `${!labelInline ? '16.64px' : ''}`,
182
217
  }}
183
- {...props} />
184
- {required && <div style={{
185
- marginLeft: '4px',
186
- color: `${themeColor.variant['error']}`
187
- }} >*</div>}
218
+ {...props}
219
+ />
220
+ {required && (
221
+ <div
222
+ style={{
223
+ marginLeft: '4px',
224
+ color: `${themeColor.variant['error']}`,
225
+ }}
226
+ >
227
+ *
228
+ </div>
229
+ )}
188
230
  </div>
189
231
  <ParentDiv
190
232
  theme={defaultStyles}
@@ -202,63 +244,109 @@ export const DropzoneInput = ({ theme, themeColor, isValid, label, labelStyle, l
202
244
  >
203
245
  <InputFile
204
246
  ref={fileInputRef}
205
- type="file"
247
+ type='file'
206
248
  multiple={singleFile == true ? false : true}
207
249
  onChange={onFilesAdded}
208
- onClick={(e) => e.target.value = null}
250
+ onClick={(e) => (e.target.value = null)}
209
251
  {...props}
210
252
  />
211
- {isValid ?
253
+ {isValid ? (
212
254
  <Icon
213
- icon='file-attach'
255
+ icon='file-upload'
214
256
  color={hover ? themeColor.bgColor : backgroundColor}
215
- size={24} />
216
- : null}
217
- <TextDiv isValid={isValid} hover={hover} customTextStyles={customTextStyles}
257
+ size={24}
258
+ />
259
+ ) : null}
260
+ <TextDiv
261
+ isValid={isValid}
262
+ hover={hover}
263
+ customTextStyles={customTextStyles}
218
264
  theme={defaultStyles}
219
- defaultStyles={'dropzone-text-div'}>
220
- {isValid ?
265
+ defaultStyles={'dropzone-text-div'}
266
+ >
267
+ {isValid ? (
221
268
  <div>
222
- <span style={{ color: hover ? themeColor.bgColor : backgroundColor }}>Choose a file </span>
223
- <span style={{ color: hover ? themeColor.bgColor : themeColor.neutral['neutral-2'] }}>or </span>
224
- <span style={{ color: hover ? themeColor.bgColor : themeColor.textColor }}>drag {singleFile ? 'it' : 'them'} here</span>
269
+ <span
270
+ style={{ color: hover ? themeColor.bgColor : backgroundColor }}
271
+ >
272
+ Choose a file{' '}
273
+ </span>
274
+ <span
275
+ style={{
276
+ color: hover
277
+ ? themeColor.bgColor
278
+ : themeColor.neutral['neutral-2'],
279
+ }}
280
+ >
281
+ or{' '}
282
+ </span>
283
+ <span
284
+ style={{
285
+ color: hover ? themeColor.bgColor : themeColor.textColor,
286
+ }}
287
+ >
288
+ drag {singleFile ? 'it' : 'them'} here
289
+ </span>
225
290
  </div>
226
- :
291
+ ) : (
227
292
  <div>
228
- <span style={{ color: themeColor.variant['error'] }}>Try again!! </span>
229
- <span style={{
230
- color: theme.textColor,
231
- }}>{message.length > messageSize ? message.slice(0, messageSize) : message}</span>
293
+ <span style={{ color: themeColor.variant['error'] }}>
294
+ Try again!!{' '}
295
+ </span>
296
+ <span
297
+ style={{
298
+ color: theme.textColor,
299
+ }}
300
+ >
301
+ {message.length > messageSize
302
+ ? message.slice(0, messageSize)
303
+ : message}
304
+ </span>
232
305
  </div>
233
- }
306
+ )}
234
307
  </TextDiv>
235
308
  </ParentDiv>
309
+ <AdditionalText>{additionalText}</AdditionalText>
236
310
  {fileArr?.map((item, i) => {
237
- // console.log("item", item)
238
- return <FileDiv
239
- theme={defaultStyles}
240
- defaultStyles={'dropzone-file-div'}
241
- key={`${item}-${i}`}
242
- customFileStyles={customFileStyles}>
243
- <IconDiv><Icon icon='pdf-icon' /></IconDiv>
244
- <FileName
311
+ return (
312
+ <FileDiv
245
313
  theme={defaultStyles}
246
- type={'dropzone-file-name'}
247
- customFileNameStyles={customFileNameStyles}
248
- >{item.name}</FileName>
249
- <IconDiv><Icon
250
- icon={`${item instanceof File ? 'plus-outlined' : 'cloud-icon'}`}
251
- />
252
- </IconDiv>
253
- <CrossDiv key={Math.random() * 101 | 0}
254
- onClick={() => fileRemoveFromArary(item, i)}>
255
- <Icon icon='cross-icon' color={themeColor.neutral['neutral-2']} />
256
- </CrossDiv>
257
- </FileDiv>
314
+ defaultStyles={'dropzone-file-div'}
315
+ key={`${item}-${i}`}
316
+ customFileStyles={customFileStyles}
317
+ >
318
+ <IconDiv>
319
+ <Icon icon='pdf-icon' />
320
+ </IconDiv>
321
+ <FileName
322
+ theme={defaultStyles}
323
+ type={'dropzone-file-name'}
324
+ customFileNameStyles={customFileNameStyles}
325
+ >
326
+ {item.name}
327
+ </FileName>
328
+
329
+
330
+ <IconDiv>
331
+ <Icon icon={`${!(item instanceof File) && 'cloud-icon'}`} />
332
+ </IconDiv>
333
+ <OtherInfoDiv>{item?.otherInfo}</OtherInfoDiv>
334
+ <CrossDiv
335
+ key={(Math.random() * 101) | 0}
336
+ onClick={() => fileRemoveFromArary(item, i)}
337
+ >
338
+ <Icon
339
+ icon='cross-icon'
340
+ color={themeColor.neutral['neutral-2']}
341
+ size={13}
342
+ />
343
+ </CrossDiv>
344
+ </FileDiv>
345
+ );
258
346
  })}
259
347
  </div>
260
- )
261
- }
348
+ );
349
+ };
262
350
 
263
351
  DropzoneInput.propTypes = {
264
352
  /**
@@ -275,46 +363,48 @@ DropzoneInput.propTypes = {
275
363
  isValid: PropTypes.bool,
276
364
  /**
277
365
  * invalid error messages (limit 100 characters)
278
- */
366
+ */
279
367
  message: PropTypes.string,
280
368
  /**
281
369
  * files that are added
282
- */
370
+ */
283
371
  fileArr: PropTypes.array,
284
372
  /**
285
373
  * files setter
286
- */
374
+ */
287
375
  setFileArr: PropTypes.func,
288
376
  /**
289
377
  * custom style of the dropzoneInput box
290
- */
378
+ */
291
379
  customDropzoneStyles: PropTypes.object,
292
380
  /**
293
381
  * custom style of the uploaded files
294
- */
382
+ */
295
383
  customFileStyles: PropTypes.object,
296
384
  /**
297
385
  * custom style of the text
298
- */
386
+ */
299
387
  customTextStyles: PropTypes.object,
300
388
  /**
301
389
  * custom style of the file name that are added on the preview
302
- */
390
+ */
303
391
  customFileNameStyles: PropTypes.object,
304
392
  /**
305
393
  * background color (in HEX format) of the dropzoneInput box
306
- */
394
+ */
307
395
  backgroundColor: PropTypes.string,
308
396
  /**
309
- * sting length of the message
310
- */
311
- messageSize: PropTypes.number
312
-
313
-
397
+ * sting length of the message
398
+ */
399
+ messageSize: PropTypes.number,
400
+ /**
401
+ * Additional text between dropzone and files
402
+ */
403
+ additionalText: PropTypes.string,
314
404
 
315
405
  /**
316
406
  * Plus icon after file name is for file from local and cloud icon is for file from server
317
- */
407
+ */
318
408
  };
319
409
 
320
410
  DropzoneInput.defaultProps = {
@@ -330,6 +420,6 @@ DropzoneInput.defaultProps = {
330
420
  customFileStyles: {},
331
421
  customTextStyles: {},
332
422
  customFileNameStyles: {},
333
- messageSize: 100
334
- };
335
-
423
+ messageSize: 100,
424
+ additionalText: ''
425
+ };
@@ -3,10 +3,9 @@ import PropTypes from 'prop-types';
3
3
  import styled, { css, useTheme } from 'styled-components';
4
4
  import defaultThemeColor from '../constants/defaultThemeColor';
5
5
 
6
- const border = `#D4D7E3`;
7
6
 
8
7
  const TextBox = styled.div`
9
- border: 1px solid ${({ theme }) => theme ? border : theme.variant['primary-1']};
8
+ border: 1px solid ${({ theme }) => theme ? defaultThemeColor.border : theme.variant['primary-1']};
10
9
  border-radius: 4px;
11
10
  padding: 5px 12px;
12
11
  display: flex;