groundfloor-react-ui 1.0.19 → 1.0.20

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,35 +1,39 @@
1
- import React, { useState, createRef } from 'react';
2
- import styled from 'styled-components';
3
- import defaultThemeColor from '../constants/defaultThemeColor';
4
1
  import PropTypes from 'prop-types';
2
+ import React, { createRef, useState } from 'react';
3
+ import styled, { useTheme } from 'styled-components';
5
4
  import defaultStyles from '../constants/defaultStyle';
6
- import getDefaultStyles from '../constants/utils';
7
- import { hexToRGB } from '../constants/utils';
5
+ import defaultThemeColor from '../constants/defaultThemeColor';
6
+ import getDefaultStyles, { hexToRGB } from '../constants/utils';
8
7
 
9
8
  import { Icon } from '../Icon';
10
9
  import { Label } from '../Label';
11
10
 
12
11
  const ParentDiv = styled.div`
13
12
  //Set the styles from the default styles object
14
- ${({ theme, defaultStyles }) => {
15
- return getDefaultStyles(theme, defaultStyles);
13
+ ${({ inBuiltCss, defaultStyles }) => {
14
+ return getDefaultStyles(inBuiltCss, defaultStyles);
16
15
  }}
17
16
 
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)};
17
+ background-color:${({ hover, isValid, fileArr, backgroundColor, theme }) => {
18
+ if (!isValid) return 'rgba(215, 0, 0, 0.05)';
19
+ else if (isValid && hover && backgroundColor) return backgroundColor;
20
+ else if (isValid && hover && !backgroundColor)
21
+ return theme.primary['primary-1'];
22
+ else if (isValid && !hover && fileArr.length > 0) return theme.bgColor;
23
+ else if (isValid && !hover && fileArr.length == 0)
24
+ return hexToRGB(theme.primary['primary-1'], 0.05);
25
+ }}
26
+
27
+ };
26
28
  border: 1px
27
- ${({ isValid, fileArr, backgroundColor }) =>
29
+ ${({ isValid, fileArr, backgroundColor, theme }) =>
28
30
  !isValid
29
- ? 'dashed ' + defaultThemeColor.ui['error']
31
+ ? 'dashed ' + theme.ui['error']
30
32
  : fileArr.length > 0
31
- ? 'solid ' + backgroundColor
32
- : 'dashed ' + backgroundColor};
33
+ ? `solid ` +
34
+ `${backgroundColor ? backgroundColor : theme.primary['primary-1']}`
35
+ : `dashed ` +
36
+ `${backgroundColor ? backgroundColor : theme.primary['primary-1']}`};
33
37
 
34
38
  &:hover {
35
39
  cursor: pointer;
@@ -42,8 +46,8 @@ const ParentDiv = styled.div`
42
46
 
43
47
  const FileDiv = styled.div`
44
48
  //Set the styles from the default styles object
45
- ${({ theme, defaultStyles }) => {
46
- return getDefaultStyles(theme, defaultStyles);
49
+ ${({ inBuiltCss, defaultStyles }) => {
50
+ return getDefaultStyles(inBuiltCss, defaultStyles);
47
51
  }}
48
52
 
49
53
  // custom styles
@@ -56,8 +60,8 @@ const InputFile = styled.input`
56
60
 
57
61
  const TextDiv = styled.div`
58
62
  //Set the styles from the default styles object
59
- ${({ theme, defaultStyles }) => {
60
- return getDefaultStyles(theme, defaultStyles);
63
+ ${({ inBuiltCss, defaultStyles }) => {
64
+ return getDefaultStyles(inBuiltCss, defaultStyles);
61
65
  }}
62
66
 
63
67
  // custom styles
@@ -66,8 +70,8 @@ const TextDiv = styled.div`
66
70
 
67
71
  const FileName = styled.span`
68
72
  //Set the styles from the default styles object
69
- ${({ theme, type }) => {
70
- return getDefaultStyles(theme, type);
73
+ ${({ inBuiltCss, type }) => {
74
+ return getDefaultStyles(inBuiltCss, type);
71
75
  }}
72
76
 
73
77
  // custom styles
@@ -86,8 +90,6 @@ const CrossDiv = styled.div`
86
90
  const IconDiv = styled.div`
87
91
  margin-left: 11px;
88
92
  padding-left: 2px;
89
- display: flex;
90
- justify-content: center;
91
93
  `;
92
94
 
93
95
  const OtherInfoDiv = styled.div`
@@ -106,8 +108,6 @@ const AdditionalText = styled.p`
106
108
  `;
107
109
 
108
110
  export const DropzoneInput = ({
109
- theme,
110
- themeColor,
111
111
  isValid,
112
112
  label,
113
113
  labelStyle,
@@ -127,6 +127,8 @@ export const DropzoneInput = ({
127
127
  additionalText,
128
128
  ...props
129
129
  }) => {
130
+ const activeTheme = useTheme() || defaultThemeColor;
131
+
130
132
  const [hover, setHover] = useState(false);
131
133
  const fileInputRef = createRef();
132
134
 
@@ -196,13 +198,11 @@ export const DropzoneInput = ({
196
198
  function openFileDialog() {
197
199
  fileInputRef.current.click();
198
200
  }
199
- return (
200
- <div
201
201
 
202
- >
202
+ return (
203
+ <div>
203
204
  <div style={{ display: 'flex', width: 'inherit' }}>
204
205
  <Label
205
- themeColor={defaultThemeColor}
206
206
  customStyles={labelStyle}
207
207
  type={'label-text'}
208
208
  labelInline={labelInline}
@@ -218,7 +218,7 @@ export const DropzoneInput = ({
218
218
  <div
219
219
  style={{
220
220
  marginLeft: '4px',
221
- color: `${themeColor.variant['error']}`,
221
+ color: `${activeTheme.variant['error']}`,
222
222
  }}
223
223
  >
224
224
  *
@@ -226,8 +226,8 @@ export const DropzoneInput = ({
226
226
  )}
227
227
  </div>
228
228
  <ParentDiv
229
- theme={defaultStyles}
230
- themeColor={defaultThemeColor}
229
+ theme={activeTheme}
230
+ inBuiltCss={defaultStyles}
231
231
  defaultStyles={'dropzone-parent'}
232
232
  backgroundColor={backgroundColor}
233
233
  customDropzoneStyles={customDropzoneStyles}
@@ -250,7 +250,9 @@ export const DropzoneInput = ({
250
250
  {isValid ? (
251
251
  <Icon
252
252
  icon='file-upload'
253
- color={hover ? themeColor.bgColor : backgroundColor}
253
+ color={
254
+ hover ? activeTheme.bgColor : activeTheme.primary['primary-1']
255
+ }
254
256
  size={24}
255
257
  />
256
258
  ) : null}
@@ -258,28 +260,32 @@ export const DropzoneInput = ({
258
260
  isValid={isValid}
259
261
  hover={hover}
260
262
  customTextStyles={customTextStyles}
261
- theme={defaultStyles}
263
+ inBuiltCss={defaultStyles}
262
264
  defaultStyles={'dropzone-text-div'}
263
265
  >
264
266
  {isValid ? (
265
267
  <div>
266
268
  <span
267
- style={{ color: hover ? themeColor.bgColor : backgroundColor }}
269
+ style={{
270
+ color: hover
271
+ ? activeTheme.bgColor
272
+ : activeTheme.primary['primary-1'],
273
+ }}
268
274
  >
269
275
  Choose a file{' '}
270
276
  </span>
271
277
  <span
272
278
  style={{
273
279
  color: hover
274
- ? themeColor.bgColor
275
- : themeColor.neutral['neutral-2'],
280
+ ? activeTheme.bgColor
281
+ : activeTheme.neutral['neutral-2'],
276
282
  }}
277
283
  >
278
284
  or{' '}
279
285
  </span>
280
286
  <span
281
287
  style={{
282
- color: hover ? themeColor.bgColor : themeColor.textColor,
288
+ color: hover ? activeTheme.bgColor : activeTheme.textColor,
283
289
  }}
284
290
  >
285
291
  drag {singleFile ? 'it' : 'them'} here
@@ -287,12 +293,12 @@ export const DropzoneInput = ({
287
293
  </div>
288
294
  ) : (
289
295
  <div>
290
- <span style={{ color: themeColor.variant['error'] }}>
296
+ <span style={{ color: activeTheme.variant['error'] }}>
291
297
  Try again!!{' '}
292
298
  </span>
293
299
  <span
294
300
  style={{
295
- color: theme.textColor,
301
+ color: activeTheme.textColor,
296
302
  }}
297
303
  >
298
304
  {message.length > messageSize
@@ -309,38 +315,54 @@ export const DropzoneInput = ({
309
315
  {fileArr?.map((item, i) => {
310
316
  return (
311
317
  <FileDiv
312
- theme={defaultStyles}
318
+ inBuiltCss={defaultStyles}
313
319
  defaultStyles={'dropzone-file-div'}
314
320
  key={`${item}-${i}`}
315
321
  customFileStyles={customFileStyles}
316
322
  >
317
323
  <IconDiv>
318
- <Icon icon='file-icon' />
324
+ <Icon icon='file-icon' color={activeTheme.primary['primary-1']} />
319
325
  </IconDiv>
320
326
 
321
- {!(item instanceof File) ? <a style={{ color: defaultThemeColor.variant['primary-1'], marginLeft: '5px' }} href={item?.path} target="_blank" rel="noreferrer"> {item.name}
322
- </a> : <FileName
323
- theme={defaultStyles}
324
- type={'dropzone-file-name'}
325
- customFileNameStyles={customFileNameStyles}
326
- >
327
- {item.name}
328
- </FileName>}
329
-
330
-
331
-
327
+ {!(item instanceof File) ? (
328
+ <a
329
+ style={{
330
+ color: activeTheme.variant['primary-1'],
331
+ marginLeft: '5px',
332
+ }}
333
+ href={item?.path}
334
+ target='_blank'
335
+ rel='noreferrer'
336
+ >
337
+ {' '}
338
+ {item.name}
339
+ </a>
340
+ ) : (
341
+ <FileName
342
+ inBuiltCss={defaultStyles}
343
+ type={'dropzone-file-name'}
344
+ customFileNameStyles={customFileNameStyles}
345
+ >
346
+ {item.name}
347
+ </FileName>
348
+ )}
332
349
 
333
350
  <OtherInfoDiv>{item?.otherInfo}</OtherInfoDiv>
334
- <IconDiv>
335
- <Icon icon={`${!(item instanceof File) && 'cloud-icon'}`} />
336
- </IconDiv>
351
+
337
352
  <CrossDiv
338
353
  key={(Math.random() * 101) | 0}
339
354
  onClick={() => fileRemoveFromArary(item, i)}
340
355
  >
356
+ <div style={{ marginRight: '7px' }}>
357
+ <Icon
358
+ icon={`${!(item instanceof File) && 'cloud-icon'}`}
359
+ color={activeTheme.primary['primary-1']}
360
+ />
361
+ </div>
362
+
341
363
  <Icon
342
364
  icon='cross-icon'
343
- color={themeColor.neutral['neutral-2']}
365
+ color={activeTheme.neutral['neutral-2']}
344
366
  size={13}
345
367
  />
346
368
  </CrossDiv>
@@ -352,10 +374,6 @@ export const DropzoneInput = ({
352
374
  };
353
375
 
354
376
  DropzoneInput.propTypes = {
355
- /**
356
- * Theme props of the default css style
357
- */
358
- theme: PropTypes.object,
359
377
  /**
360
378
  * onFileAdd function
361
379
  */
@@ -411,12 +429,9 @@ DropzoneInput.propTypes = {
411
429
  };
412
430
 
413
431
  DropzoneInput.defaultProps = {
414
- themeColor: defaultThemeColor,
415
- theme: defaultStyles,
416
432
  onFilesAdded: () => null,
417
433
  isValid: true,
418
434
  message: '',
419
- backgroundColor: `${defaultThemeColor.primary['primary-1']}`,
420
435
  fileArr: [],
421
436
  setFileArr: () => { },
422
437
  customDropzoneStyles: {},
@@ -1,8 +1,7 @@
1
- import React from 'react';
2
1
  import PropTypes from 'prop-types';
3
- import styled from 'styled-components';
4
- import defaultThemeColor from '../constants/defaultThemeColor';
2
+ import styled, { useTheme } from 'styled-components';
5
3
  import defaultStyles from '../constants/defaultStyle';
4
+ import defaultThemeColor from '../constants/defaultThemeColor';
6
5
  import getDefaultStyles from '../constants/utils';
7
6
  import { Label } from '../Label';
8
7
 
@@ -10,8 +9,8 @@ const RadioOuterCircle = styled.div`
10
9
  box-sizing: initial;
11
10
 
12
11
  //Set the styles from the default styles object
13
- ${({ theme, defaultRadioOuterCircleStyle }) => {
14
- return getDefaultStyles(theme, defaultRadioOuterCircleStyle);
12
+ ${({ inBuiltCss, defaultRadioOuterCircleStyle }) => {
13
+ return getDefaultStyles(inBuiltCss, defaultRadioOuterCircleStyle);
15
14
  }}
16
15
 
17
16
  border: 2px solid ${({
@@ -19,41 +18,74 @@ const RadioOuterCircle = styled.div`
19
18
  selected,
20
19
  selectedCircleColor,
21
20
  defaultBorderColor,
22
- }) => (value !== selected ? defaultBorderColor : selectedCircleColor)};
21
+ theme,
22
+ }) => {
23
+ if (value !== selected && defaultBorderColor) return defaultBorderColor;
24
+ else if (value !== selected && !defaultBorderColor) return theme.border;
25
+ else if (value === selected && selectedCircleColor)
26
+ return selectedCircleColor;
27
+ else if (value === selected && !selectedCircleColor)
28
+ return theme.primary['primary-1'];
29
+ }};
23
30
 
24
31
  // custom styles
25
32
  ${({ radioOuterCircleStyle }) => radioOuterCircleStyle}
26
33
  `;
27
34
 
35
+ RadioOuterCircle.defaultProps = {
36
+ theme: defaultThemeColor,
37
+ };
38
+
28
39
  const RadioInnerCircle = styled.div`
29
40
  box-sizing: initial;
30
41
 
31
42
  //Set the styles from the default styles object
32
- ${({ theme, defaultRadioInnerCircleStyle }) => {
33
- return getDefaultStyles(theme, defaultRadioInnerCircleStyle);
43
+ ${({ inBuiltCss, defaultRadioInnerCircleStyle }) => {
44
+ return getDefaultStyles(inBuiltCss, defaultRadioInnerCircleStyle);
34
45
  }}
35
46
 
36
47
  width: ${({ value, selected, width }) => (value === selected ? width : 0)};
37
48
  height: ${({ value, selected, height }) => (value === selected ? height : 0)};
38
- background-color: ${({ value, selected, selectedCircleColor }) =>
39
- value === selected ? selectedCircleColor : 'transparent'};
49
+ background-color: ${({ value, selected, selectedCircleColor, theme }) => {
50
+ if (value === selected && selectedCircleColor) return selectedCircleColor;
51
+ else if (value === selected && !selectedCircleColor)
52
+ return theme.primary['primary-1'];
53
+ else if (value !== selected) return 'transparent';
54
+ }};
40
55
 
41
56
  // custom styles
42
57
  ${({ radioInnerCircleStyle }) => radioInnerCircleStyle}
43
58
  `;
59
+ RadioInnerCircle.defaultProps = {
60
+ theme: defaultThemeColor,
61
+ };
44
62
 
45
63
  const OptionText = styled.div`
46
64
  //Set the styles from the default styles object
47
- ${({ theme, defaultOptionStyle }) => {
48
- return getDefaultStyles(theme, defaultOptionStyle);
65
+ ${({ inBuiltCss, defaultOptionStyle }) => {
66
+ return getDefaultStyles(inBuiltCss, defaultOptionStyle);
49
67
  }}
50
68
  margin-right: ${({ inline }) => (!inline ? '30px' : '')};
51
- color: ${({ selected, selectedOptionTextColor, defaultOptionColor }) =>
52
- selected ? selectedOptionTextColor : defaultOptionColor};
69
+ color: ${({
70
+ selected,
71
+ selectedOptionTextColor,
72
+ defaultOptionColor,
73
+ theme,
74
+ }) => {
75
+ if (selected && selectedOptionTextColor) return selectedOptionTextColor;
76
+ else if (selected && !selectedOptionTextColor)
77
+ return theme.neutral['neutral-1'];
78
+ else if (!selected && defaultOptionColor) return defaultOptionColor;
79
+ else if (!selected && !defaultOptionColor)
80
+ return theme.neutral['neutral-2'];
81
+ }};
53
82
 
54
83
  // custom styles
55
84
  ${({ optionStyle }) => optionStyle}
56
85
  `;
86
+ OptionText.defaultProps = {
87
+ theme: defaultThemeColor,
88
+ };
57
89
 
58
90
  const WrapperDiv = styled.div`
59
91
  margin-bottom: ${({ inline }) => (!inline ? '14px' : '')};
@@ -87,14 +119,11 @@ export const RadioInput = ({
87
119
  defaultOptionColor,
88
120
  ...props
89
121
  }) => {
122
+ const activeTheme = useTheme() || defaultThemeColor;
123
+
90
124
  return (
91
125
  <div>
92
- <Label
93
- themeColor={defaultThemeColor}
94
- customStyles={labelStyle}
95
- type={'radio-label'}
96
- text={label}
97
- />
126
+ <Label customStyles={labelStyle} type={'radio-label'} text={label} />
98
127
  <ParentDiv inline={inline}>
99
128
  {options.map((item, i) => {
100
129
  return (
@@ -106,8 +135,8 @@ export const RadioInput = ({
106
135
  }}
107
136
  >
108
137
  <RadioOuterCircle
109
- theme={defaultStyles}
110
- themeColor={defaultThemeColor}
138
+ theme={activeTheme}
139
+ inBuiltCss={defaultStyles}
111
140
  defaultBorderColor={defaultBorderColor}
112
141
  selectedCircleColor={selectedCircleColor}
113
142
  radioOuterCircleStyle={{
@@ -120,7 +149,8 @@ export const RadioInput = ({
120
149
  selected={!item?.disabled && selected}
121
150
  >
122
151
  <RadioInnerCircle
123
- theme={defaultStyles}
152
+ inBuiltCss={defaultStyles}
153
+ theme={activeTheme}
124
154
  width={width}
125
155
  height={height}
126
156
  selectedCircleColor={selectedCircleColor}
@@ -145,10 +175,10 @@ export const RadioInput = ({
145
175
  cursor: item?.disabled ? 'not-allowed ' : ' pointer',
146
176
  color: item?.disabled && item?.disabledColor,
147
177
  }}
148
- theme={defaultStyles}
178
+ inBuiltCss={defaultStyles}
149
179
  defaultOptionStyle={'option-text'}
150
180
  selectedOptionTextColor={selectedOptionTextColor}
151
- // selected={item.value === selected}
181
+ theme={activeTheme}
152
182
  selected={!item?.disabled && item.value === selected}
153
183
  >
154
184
  {item.label}
@@ -237,10 +267,6 @@ RadioInput.defaultProps = {
237
267
  onChange: () => { },
238
268
  radioOuterCircleStyle: {},
239
269
  radioInnerCircleStyle: {},
240
- defaultOptionColor: `${defaultThemeColor.neutral['neutral-2']}`,
241
- defaultBorderColor: '#D4D7E3',
242
270
  width: '14px',
243
271
  height: '14px',
244
- selectedCircleColor: `${defaultThemeColor.primary['primary-1']}`,
245
- selectedOptionTextColor: `${defaultThemeColor.neutral['neutral-1']}`,
246
272
  };