groundfloor-react-ui 1.0.7 → 1.0.10

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,4 +1,4 @@
1
- import React from 'react';
1
+ import React, { useEffect, useState } from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import styled from 'styled-components';
4
4
  import defaultThemeColor from '../constants/defaultThemeColor';
@@ -6,137 +6,196 @@ import defaultStyles from '../constants/defaultStyle';
6
6
  import getDefaultStyles from '../constants/utils';
7
7
  import { Label } from '../Label';
8
8
  // import tick from '../../assets/icons/checkmark.svg';
9
- import { Icon } from '../Icon'
9
+ import { Icon } from '../Icon';
10
10
 
11
11
  const CheckBoxOuter = styled.div`
12
+ box-sizing: initial;
12
13
 
13
- box-sizing:initial;
14
-
15
- //Set the styles from the default styles object
16
- ${({ theme, defaultCheckBoxOuterStyle }) => {
14
+ //Set the styles from the default styles object
15
+ ${({ theme, defaultCheckBoxOuterStyle }) => {
17
16
  return getDefaultStyles(theme, defaultCheckBoxOuterStyle);
18
17
  }}
19
-
20
- border: 2px solid ${({ checkedCheckBoxColor, defaultBorderColor, checked }) => checked ? checkedCheckBoxColor : defaultBorderColor};
21
-
22
- // custom styles
23
- ${({ checkBoxOuterStyle }) => checkBoxOuterStyle}
18
+
19
+ border: 2px solid ${({ checkedCheckBoxColor, defaultBorderColor, checked }) =>
20
+ checked ? checkedCheckBoxColor : defaultBorderColor};
21
+
22
+ // custom styles
23
+ ${({ checkBoxOuterStyle }) => checkBoxOuterStyle}
24
24
  `;
25
25
 
26
26
  const CheckBoxInner = styled.div`
27
-
28
- box-sizing:initial;
27
+ box-sizing: initial;
29
28
 
30
- //Set the styles from the default styles object
31
- ${({ theme, defaultCheckBoxInnerStyle }) => {
29
+ //Set the styles from the default styles object
30
+ ${({ theme, defaultCheckBoxInnerStyle }) => {
32
31
  return getDefaultStyles(theme, defaultCheckBoxInnerStyle);
33
32
  }}
34
-
35
- // background-image: url(${({ signCheck }) => signCheck});
36
- background-color: ${({ checked, checkedCheckBoxColor }) => checked ? checkedCheckBoxColor : defaultThemeColor.bgColor};
37
- border: 2px solid ${({ checkedCheckBoxColor, defaultBorderColor, checked }) => checked ? checkedCheckBoxColor : defaultBorderColor};
38
- display: flex;
39
- justify-content: center;
40
- align-items: center;
41
- // custom styles
42
- ${({ checkBoxInnerStyle }) => checkBoxInnerStyle}
43
-
33
+
34
+ // background-image: url(${({ signCheck }) => signCheck});
35
+ background-color: ${({ checked, checkedCheckBoxColor }) =>
36
+ checked ? checkedCheckBoxColor : defaultThemeColor.bgColor};
37
+ border: 2px solid
38
+ ${({ checkedCheckBoxColor, defaultBorderColor, checked }) =>
39
+ checked ? checkedCheckBoxColor : defaultBorderColor};
40
+ display: flex;
41
+ justify-content: center;
42
+ align-items: center;
43
+ // custom styles
44
+ ${({ checkBoxInnerStyle }) => checkBoxInnerStyle}
44
45
  `;
45
46
  CheckBoxInner.defaultProps = {
46
47
  themeColor: defaultThemeColor,
47
48
  // signCheck: `${tick}`
48
- }
49
+ };
49
50
 
50
51
  const OptionText = styled.span`
51
-
52
- //Set the styles from the default styles object
53
- ${({ theme, type }) => {
52
+ //Set the styles from the default styles object
53
+ ${({ theme, type }) => {
54
54
  return getDefaultStyles(theme, type);
55
55
  }}
56
-
57
- color: ${({ checked, defaultTextColor, checkedTextColor }) => checked ? checkedTextColor : defaultTextColor};
58
-
59
- margin-right: ${({ inline }) => inline ? '30px' : '0px'};
60
-
61
- // custom styles
62
- ${({ optionTextStyle }) => optionTextStyle}
56
+
57
+ color: ${({ checked, defaultTextColor, checkedTextColor }) =>
58
+ checked ? checkedTextColor : defaultTextColor};
59
+
60
+ margin-right: ${({ inline }) => (inline ? '30px' : '0px')};
61
+
62
+ // custom styles
63
+ ${({ optionTextStyle }) => optionTextStyle}
63
64
  `;
64
65
 
65
66
  const WrapperDiv = styled.label`
66
- width: fit-content;
67
- margin-bottom: ${({ inline }) => !inline ? '18px !important' : ''};
68
- cursor: pointer;
69
- align-items: center;
70
- display: flex;
71
- gap: 10px;
72
-
73
- `
67
+ width: fit-content;
68
+ margin-bottom: ${({ inline }) => (!inline ? '18px !important' : '')};
69
+ cursor: pointer;
70
+ align-items: center;
71
+ display: flex;
72
+ gap: 10px;
73
+ `;
74
74
 
75
75
  const ParentDiv = styled.div`
76
- flex-direction: ${({ inline }) => inline ? "row" : "column"};
77
- width: ${({ inline }) => !inline ? "auto" : "initial"};
78
- `
76
+ flex-direction: ${({ inline }) => (inline ? 'row' : 'column')};
77
+ width: ${({ inline }) => (!inline ? 'auto' : 'initial')};
78
+ `;
79
79
 
80
+ export const CheckBoxInput = ({
81
+ getCheckedArr,
82
+ checkBoxOuterStyle,
83
+ checkBoxInnerStyle,
84
+ optionTextStyle,
85
+ defaultBorderColor,
86
+ defaultTextColor,
87
+ checkedTextColor,
88
+ checkedCheckBoxColor,
89
+ labelStyle,
90
+ label,
91
+ options,
92
+ setOptions,
93
+ inline,
94
+ wrapperStyle,
95
+ ...props
96
+ }) => {
97
+ useEffect(() => {
98
+ filterCheckedOptions(options);
99
+ }, []);
80
100
 
81
- export const CheckBoxInput = ({ checkBoxOuterStyle, checkBoxInnerStyle, optionTextStyle, defaultBorderColor, defaultTextColor, checkedTextColor, checkedCheckBoxColor, labelStyle, label, options, setOptions, inline, wrapperStyle, ...props }) => {
82
101
  const checkBox = (item, i) => {
83
- let newOptions = [...options]
102
+ let newOptions = [...options];
84
103
  newOptions[i].checked = !item.checked;
85
104
  setOptions(newOptions);
86
- }
105
+ filterCheckedOptions(newOptions);
106
+ };
107
+
108
+ const filterCheckedOptions = (newOptions) => {
109
+ let filteredOptions = newOptions.filter(
110
+ (option) => option.checked !== false
111
+ );
112
+ getCheckedArr(filteredOptions);
113
+ };
87
114
 
88
115
  const defaultStyleForWrapper = {
89
116
  display: 'flex',
90
117
  flexDirection: 'column',
91
- flexWrap: 'wrap'
92
- }
118
+ flexWrap: 'wrap',
119
+ };
93
120
  const returnedTarget = Object.assign(defaultStyleForWrapper, wrapperStyle);
94
121
 
95
-
96
122
  return (
97
- <div style={returnedTarget} {...props}>
123
+ <div style={returnedTarget} {...props}>
98
124
  <Label
99
125
  themeColor={defaultThemeColor}
100
126
  customStyles={labelStyle}
101
127
  type={'check-label'}
102
128
  text={label}
103
- {...props} />
104
- <ParentDiv style={{ display: 'flex', flexWrap: 'wrap' }} inline={inline} {...props}>
129
+ {...props}
130
+ />
131
+ <ParentDiv
132
+ style={{ display: 'flex', flexWrap: 'wrap' }}
133
+ inline={inline}
134
+ {...props}
135
+ >
105
136
  {options?.map((item, i) => {
106
- return <WrapperDiv inline={inline} key={`${item.name}-${i}`}
107
- onClick={() => { checkBox(item, i) }} {...props}>
108
- {item.checked ?
109
- <CheckBoxInner
110
- theme={defaultStyles}
111
- defaultCheckBoxInnerStyle={'checkBox-inner'}
112
- checkBoxInnerStyle={{ ...checkBoxInnerStyle, cursor: item?.disabled ? 'not-allowed ' : ' pointer', borderColor: item?.disabled && item?.disabledColor }}
113
- defaultBorderColor={defaultBorderColor}
114
- checkedCheckBoxColor={checkedCheckBoxColor}
115
- checked={!item?.disabled && item.checked} {...props} >
116
- <Icon icon='check-icon' size={18} color='white' />
117
- </CheckBoxInner>
118
- : <CheckBoxOuter
119
- theme={defaultStyles}
120
- defaultCheckBoxOuterStyle={'checkBox-outer'}
121
- checkBoxOuterStyle={{ ...checkBoxOuterStyle, cursor: item?.disabled ? 'not-allowed ' : ' pointer', borderColor: item?.disabledColor }}
122
- defaultBorderColor={defaultBorderColor}
123
- {...props} />}
124
- <OptionText
137
+ return (
138
+ <WrapperDiv
125
139
  inline={inline}
126
- optionTextStyle={{ ...optionTextStyle, cursor: item?.disabled ? 'not-allowed ' : ' pointer', color: item?.disabledColor }}
127
- checked={item.checked}
128
- defaultTextColor={defaultTextColor}
129
- checkedTextColor={checkedTextColor}>{item.label}</OptionText>
130
- </WrapperDiv>
140
+ key={`${item.name}-${i}`}
141
+ onClick={() => {
142
+ checkBox(item, i);
143
+ }}
144
+ {...props}
145
+ >
146
+ {item.checked ? (
147
+ <CheckBoxInner
148
+ theme={defaultStyles}
149
+ defaultCheckBoxInnerStyle={'checkBox-inner'}
150
+ checkBoxInnerStyle={{
151
+ ...checkBoxInnerStyle,
152
+ cursor: item?.disabled ? 'not-allowed ' : ' pointer',
153
+ borderColor: item?.disabled && item?.disabledColor,
154
+ }}
155
+ defaultBorderColor={defaultBorderColor}
156
+ checkedCheckBoxColor={checkedCheckBoxColor}
157
+ checked={!item?.disabled && item.checked}
158
+ {...props}
159
+ >
160
+ <Icon icon='check-icon' size={18} color='white' />
161
+ </CheckBoxInner>
162
+ ) : (
163
+ <CheckBoxOuter
164
+ theme={defaultStyles}
165
+ defaultCheckBoxOuterStyle={'checkBox-outer'}
166
+ checkBoxOuterStyle={{
167
+ ...checkBoxOuterStyle,
168
+ cursor: item?.disabled ? 'not-allowed ' : ' pointer',
169
+ borderColor: item?.disabledColor,
170
+ }}
171
+ defaultBorderColor={defaultBorderColor}
172
+ {...props}
173
+ />
174
+ )}
175
+ <OptionText
176
+ inline={inline}
177
+ optionTextStyle={{
178
+ ...optionTextStyle,
179
+ cursor: item?.disabled ? 'not-allowed ' : ' pointer',
180
+ color: item?.disabledColor,
181
+ }}
182
+ checked={item.checked}
183
+ defaultTextColor={defaultTextColor}
184
+ checkedTextColor={checkedTextColor}
185
+ >
186
+ {item.label}
187
+ </OptionText>
188
+ </WrapperDiv>
189
+ );
131
190
  })}
132
191
  </ParentDiv>
133
192
  </div>
134
- )
135
- }
193
+ );
194
+ };
136
195
 
137
196
  CheckBoxInput.propTypes = {
138
197
  /**
139
- * Style Custom for whole Checkbox Block
198
+ * Style Custom for whole Checkbox Block
140
199
  */
141
200
  wrapperStyle: PropTypes.object,
142
201
  /**
@@ -187,13 +246,18 @@ CheckBoxInput.propTypes = {
187
246
  * CheckBox value changeHandler
188
247
  */
189
248
  setOptions: PropTypes.func,
190
- }
249
+ /**
250
+ * CheckBox checked value changeHandler
251
+ */
252
+ getCheckedArr: PropTypes.func,
253
+ };
191
254
 
192
255
  CheckBoxInput.defaultProps = {
193
256
  label: '',
194
257
  inline: false,
195
258
  options: [],
196
259
  setOptions: () => { },
260
+ getCheckedArr: () => { },
197
261
  labelStyle: {},
198
262
  checkBoxOuterStyle: {},
199
263
  checkBoxInnerStyle: {},
@@ -201,4 +265,4 @@ CheckBoxInput.defaultProps = {
201
265
  checkedTextColor: `${defaultThemeColor.neutral['neutral-1']}`,
202
266
  defaultBorderColor: '#D4D7E3',
203
267
  checkedCheckBoxColor: `${defaultThemeColor.primary['primary-1']}`,
204
- }
268
+ };