@xaypay/tui 0.0.55 → 0.0.57

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,50 +1,116 @@
1
1
  import React, {useEffect, useState, useRef} from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import classnames from 'classnames';
4
- import styles from './select.module.css';
5
- import Icon from '../icon/Icon'
6
-
4
+ import { compereConfigs } from "./../../utils";
7
5
 
8
- export const SelectTheme = {
9
- DEFAULT: 'select-default',
10
- PRIMARY: 'select-primary',
11
- SUCCESS: 'select-success',
12
- INFO: 'select-info',
13
- WARNING: 'select-warning',
14
- DANGER: 'select-danger',
15
- LINK: 'select-link'
16
- };
6
+ import ReactArrowIcon from './../../assets/icons/arrow.svg';
7
+ import ReactCloseIcon from './../../assets/icons/close-icon.svg';
17
8
 
18
- export const SelectSize = {
19
- SMALL: 'small',
20
- MEDIUM: 'medium',
21
- LARGE: 'large'
22
- };
9
+ import styles from './select.module.css';
23
10
 
24
11
  export const Select = ({
25
- theme,
26
- size,
27
- className,
28
12
  disabled,
29
- label,
30
13
  jsonData,
31
- eMessage,
32
14
  required,
33
- defaultOption,
34
15
  onChange,
35
16
  keyNames,
36
- selected
37
- }) => {
17
+ selected,
18
+ className,
19
+ arrowIcon,
20
+ closeIcon,
21
+ errorMessage,
22
+ defaultOption,
23
+
24
+ label,
25
+ labelColor,
26
+ labelWeight,
27
+ labelDisplay,
28
+ labelFontSize,
29
+ labelLineHeight,
30
+ labelMarginBottom,
31
+ labelTextTransform,
38
32
 
33
+ cursor,
34
+ errorSize,
35
+ errorColor,
36
+ selectedColor,
37
+ selectedRadius,
38
+ selectedHeight,
39
+ selectedBorder,
40
+ selectedPadding,
41
+ selectedFontSize,
42
+ selectedBoxSizing,
43
+ selectedFontWeight,
44
+ selectedLineHeight,
45
+ selectedHoverColor,
46
+ selectedTransition,
47
+ selectedBorderColor,
48
+
49
+ optionsBoxShadow,
50
+ optionsBorderRadius,
51
+ optionsBackgroundColor,
52
+
53
+ optionItemColor,
54
+ optionItemCursor,
55
+ optionItemPadding,
56
+ optionItemFontSize,
57
+ optionItemMinHeight,
58
+ optionItemBoxSizing,
59
+ optionItemFontWeight,
60
+ optionItemLineHeight,
61
+ optionItemColorHover,
62
+ optionItemMarginBottom,
63
+ optionItemBackgroudColor,
64
+ optionItemBackgroudColorHover,
65
+ }) => {
39
66
  const options = jsonData.length ? JSON.parse(jsonData) : [];
40
67
  const ref = useRef();
41
-
42
- let [opened, setOpened] = useState(false)
43
- let [newSelected, setNewSelected] = useState({})
68
+
69
+ const [opened, setOpened] = useState(false);
70
+ const [isHover, setIsHover] = useState(false);
71
+ const [newSelected, setNewSelected] = useState({});
72
+
73
+ const configStyles = compereConfigs();
74
+ const classProps = classnames(
75
+ className
76
+ );
77
+
78
+ const handleOpenClose = () => {
79
+ setOpened(!opened);
80
+ };
81
+
82
+ const handleClearSelect = (e) => {
83
+ onChange({});
84
+ setNewSelected({})
85
+ e.stopPropagation();
86
+ };
87
+
88
+ const handleSelectItem = (option) => {
89
+ onChange(option);
90
+ setOpened(!opened);
91
+ setNewSelected(option);
92
+ };
93
+
94
+ const handleMouseEnter = () => {
95
+ setIsHover(true);
96
+ };
97
+
98
+ const handleMouseLeave = () => {
99
+ setIsHover(false);
100
+ };
101
+
102
+ const handleMouseEnterOption = (e) => {
103
+ e.target.style.color = optionItemColorHover ? optionItemColorHover : configStyles.SELECT.optionItemColorHover;
104
+ e.target.style.backgroundColor = optionItemBackgroudColorHover ? optionItemBackgroudColorHover : configStyles.SELECT.optionItemBackgroudColorHover;
105
+ };
106
+
107
+ const handleMouseLeaveOption = (e) => {
108
+ e.target.style.color = optionItemColor ? optionItemColor : configStyles.SELECT.optionItemColor
109
+ e.target.style.backgroundColor = optionItemBackgroudColor ? optionItemBackgroudColor : configStyles.SELECT.optionItemBackgroudColor;
110
+ };
44
111
 
45
112
  useEffect(()=>{
46
- const parseSelectedData =
47
- selected.length !== 0 ? JSON.parse(selected) : {};
113
+ const parseSelectedData = selected.length !== 0 ? JSON.parse(selected) : {};
48
114
  setNewSelected(parseSelectedData);
49
115
  },[selected])
50
116
 
@@ -61,106 +127,189 @@ export const Select = ({
61
127
  }
62
128
  }
63
129
  }, [opened]);
64
-
65
- const classProps = classnames(
66
- styles[theme],
67
- styles[size],
68
- {
69
- [styles.disabled]: disabled,
70
- [styles.required]: required,
71
- },
72
- className
73
- );
74
130
 
75
131
  return (
76
- <div>
77
- {label ? <label className={`${styles['select-title']} select-title-rem`}>{label} {required && <sup style={{color: "#ee0000"}}>*</sup>}</label> : ""}
78
- <div className={`${styles['select-wrap']} select-wrap-rem`} ref={ref}>
79
- <div className={styles['select-content']} id={styles.selector}>
132
+ <div className={classProps}>
133
+ {
134
+ label ?
135
+ <label
136
+ style={{
137
+ color: labelColor ? labelColor : configStyles.SELECT.labelColor,
138
+ fontWeight: labelWeight ? labelWeight : configStyles.SELECT.labelWeight,
139
+ display: labelDisplay ? labelDisplay : configStyles.SELECT.labelDisplay,
140
+ fontSize: labelFontSize ? labelFontSize : configStyles.SELECT.labelFontSize,
141
+ lineHeight: labelLineHeight ? labelLineHeight : configStyles.SELECT.labelLineHeight,
142
+ marginBottom: labelMarginBottom ? labelMarginBottom : configStyles.SELECT.labelMarginBottom,
143
+ textTransform: labelTextTransform ? labelTextTransform : configStyles.SELECT.labelTextTransform
144
+ }}
145
+ >
146
+ {label}
147
+ {required && <sup style={{color: "#ee0000"}}>*</sup>}
148
+ </label> : ""
149
+ }
150
+
151
+ <div ref={ref}>
152
+ <div className={styles['select-content']}>
80
153
  <div
81
- className={`${styles['select-content-top']} select-content-top-rem ${eMessage ? styles['error-message'] : ''}`}
82
- onClick={() => {
83
- setOpened(!opened)
154
+ style={{
155
+ cursor: disabled ? 'not-allowed' : cursor ? cursor : configStyles.SELECT.cursor,
156
+ height: selectedHeight ? selectedHeight : configStyles.SELECT.selectedHeight,
157
+ border: selectedBorder ? selectedBorder : configStyles.SELECT.selectedBorder,
158
+ padding: selectedPadding ? selectedPadding : configStyles.SELECT.selectedPadding,
159
+ borderRadius: selectedRadius ? selectedRadius : configStyles.SELECT.selectedRadius,
160
+ fontSize: selectedFontSize ? selectedFontSize : configStyles.SELECT.selectedFontSize,
161
+ boxSizing: selectedBoxSizing ? selectedBoxSizing : configStyles.SELECT.selectedBoxSizing,
162
+ fontWeight: selectedFontWeight ? selectedFontWeight : configStyles.SELECT.selectedFontWeight,
163
+ lineHeight: selectedLineHeight ? selectedLineHeight : configStyles.SELECT.selectedLineHeight,
164
+ transition: selectedTransition ? selectedTransition : configStyles.SELECT.selectedTransition,
165
+ borderColor: errorMessage ? errorColor ? errorColor : configStyles.SELECT.errorColor : selectedBorderColor ? selectedBorderColor : configStyles.SELECT.selectedBorderColor
84
166
  }}
167
+ onClick={disabled ? _ => _ : _ => handleOpenClose()}
168
+ onMouseEnter={disabled ? _ => _ : handleMouseEnter}
169
+ onMouseLeave={disabled ? _ => _ : handleMouseLeave}
170
+ className={`${styles['select-content-top']}`}
85
171
  >
86
- <div className={`${styles['select-content-top-text']} select-content-top-text-rem`}>{newSelected && newSelected[keyNames.name] ? newSelected[keyNames.name] : defaultOption}</div>
87
- <div className={`${styles['select-content-top-icon']} select-content-top-icon-rem`}>
172
+ <div
173
+ className={`${styles['select-content-top-text']}`}
174
+ style={{
175
+ color: errorMessage ? errorColor ? errorColor : configStyles.SELECT.errorColor : isHover ? selectedHoverColor ? selectedHoverColor : configStyles.SELECT.selectedHoverColor : selectedColor ? selectedColor : configStyles.SELECT.selectedColor,
176
+ }}
177
+ >
178
+ {newSelected && newSelected[keyNames.name] ? newSelected[keyNames.name] : defaultOption}
179
+ </div>
180
+ <div className={`${styles['select-content-top-icon']}`}>
88
181
 
89
182
  {Object.keys(newSelected).length > 0 &&
90
- <i className="icon-close" onClick={
91
- (e) => {
92
- setNewSelected({})
93
- onChange({});
94
- e.stopPropagation()
95
- }
96
- }/>
183
+ <div
184
+ className={`${styles['close-icon']}`}
185
+ onClick={disabled ? _ => _ : handleClearSelect}
186
+ >
187
+ { closeIcon ? closeIcon : <img src={ReactCloseIcon} alt="icon" /> }
188
+ </div>
97
189
  }
98
- <i className={opened ? 'icon-icon-up' : 'icon-icon-down'}/>
99
190
 
191
+ <div
192
+ style={{
193
+ transform: opened ? 'rotate(180deg)' : 'rotate(0deg)',
194
+ }}
195
+ className={`${styles['arrow-icon']}`}>
196
+ {arrowIcon ? arrowIcon : <img src={ReactArrowIcon} alt="icon"/>}
197
+ </div>
100
198
  </div>
101
199
  </div>
102
200
  {
103
201
  opened && !disabled ?
104
- <div className={`${styles['select-content-bottom']} select-content-bottom-rem`}>
105
- <div className={`${styles['select-content-bottom-inner']} select-content-bottom-inner-rem`}>
106
- {/* <div
107
- className={styles['select-content-bottom-row']}
108
- onClick={() => {
109
- if (!required && !selected) {
110
- setNewSelected(defaultOption)
111
- onChange(defaultOption)
112
- setOpened(!opened)
113
- }
114
- }
115
- }
116
- >
117
- {defaultOption}
118
- </div> */}
119
- {
120
- options.map((option, i) => {
121
- return <div
122
- key={i}
123
- className={`${styles['select-content-bottom-row']} select-content-bottom-row-rem`}
124
- disabled={true}
125
- onClick={() => {
126
- setNewSelected(option);
127
- onChange(option);
128
- setOpened(!opened);
129
- }
130
- }
131
- defaultValue={option[keyNames.id]}
132
- >
202
+ <div
203
+ style={{
204
+ boxShadow: optionsBoxShadow ? optionsBoxShadow : configStyles.SELECT.optionsBoxShadow,
205
+ borderRadius: optionsBorderRadius ? optionsBorderRadius : configStyles.SELECT.optionsBorderRadius,
206
+ backgroundColor: optionsBackgroundColor ? optionsBackgroundColor : configStyles.SELECT.optionsBackgroundColor,
207
+ top: parseFloat( selectedHeight ? selectedHeight.substring(0, selectedHeight.length - 2) : configStyles.SELECT.selectedHeight.substring(0, configStyles.SELECT.selectedHeight.length - 2)) + 6 + 'px'
208
+ }}
209
+ className={`${styles['select-content-bottom']}`}
210
+ >
211
+ <div className={`${styles['select-content-bottom-inner']}`}>
212
+ {
213
+ options.map((option, i) => {
214
+ return <div
215
+ key={i}
216
+ disabled={true}
217
+ defaultValue={option[keyNames.id]}
218
+ onClick={disabled ? _ => _ : _ => handleSelectItem(option)}
219
+ onMouseEnter={disabled ? _ => _ : e => handleMouseEnterOption(e)}
220
+ onMouseLeave={disabled ? _ => _ : e => handleMouseLeaveOption(e)}
221
+ className={`${styles['select-content-bottom-row']}`}
222
+ style={{
223
+ color: optionItemColor ? optionItemColor : configStyles.SELECT.optionItemColor,
224
+ cursor: optionItemCursor ? optionItemCursor : configStyles.SELECT.optionItemCursor,
225
+ padding: optionItemPadding ? optionItemPadding : configStyles.SELECT.optionItemPadding,
226
+ fontSize: optionItemFontSize ? optionItemFontSize : configStyles.SELECT.optionItemFontSize,
227
+ boxSizing: optionItemBoxSizing ? optionItemBoxSizing : configStyles.SELECT.optionItemBoxSizing,
228
+ minHeight: optionItemMinHeight ? optionItemMinHeight : configStyles.SELECT.optionItemMinHeight,
229
+ fontWeight: optionItemFontWeight ? optionItemFontWeight : configStyles.SELECT.optionItemFontWeight,
230
+ lineHeight: optionItemLineHeight ? optionItemLineHeight : configStyles.SELECT.optionItemLineHeight,
231
+ marginBottom: optionItemMarginBottom ? optionItemMarginBottom : configStyles.SELECT.optionItemMarginBottom,
232
+ backgroundColor: optionItemBackgroudColor ? optionItemBackgroudColor : configStyles.SELECT.optionItemBackgroudColor,
233
+ }}
234
+ >
133
235
  {option[keyNames.name]}
134
- </div>
135
- })
136
- }
137
- </div>
236
+ </div>
237
+ })
238
+ }
138
239
  </div>
139
- : null
240
+ </div> : null
140
241
  }
141
242
  </div>
142
243
  </div>
143
- {eMessage ? <span className={styles.eMessage}>{eMessage}</span> : null}
244
+
245
+ {
246
+ errorMessage ?
247
+ <span
248
+ style={{
249
+ color: errorColor ? errorColor : configStyles.SELECT.errorColor,
250
+ fontSize: errorSize ? errorSize : configStyles.SELECT.errorSize
251
+ }}
252
+ >
253
+ {errorMessage}
254
+ </span>
255
+ : ''
256
+ }
144
257
  </div>
145
258
  );
146
259
  };
147
260
 
148
261
  Select.propTypes = {
149
- theme: PropTypes.oneOf(Object.values(SelectTheme)),
150
- size: PropTypes.oneOf(Object.values(SelectSize)),
151
- label: PropTypes.string,
152
- eMessage: PropTypes.string,
153
- defaultOption: PropTypes.string,
154
262
  onChange: PropTypes.func,
155
263
  required: PropTypes.bool,
156
264
  disabled: PropTypes.bool,
157
- className: PropTypes.string,
158
265
  selected: PropTypes.string,
159
266
  jsonData: PropTypes.string,
160
267
  keyNames: PropTypes.object,
161
- };
268
+ className: PropTypes.string,
269
+ arrowIcon: PropTypes.element,
270
+ closeIcon: PropTypes.element,
271
+ errorMessage: PropTypes.string,
272
+ defaultOption: PropTypes.string,
273
+
274
+ label: PropTypes.string,
275
+ labelColor: PropTypes.string,
276
+ labelWeight: PropTypes.string,
277
+ labelDisplay: PropTypes.string,
278
+ labelFontSize: PropTypes.string,
279
+ labelLineHeight: PropTypes.string,
280
+ labelMarginBottom: PropTypes.string,
281
+ labelTextTransform: PropTypes.string,
162
282
 
163
- Select.defaultProps = {
164
- size: 'medium',
165
- required: false
166
- };
283
+ cursor: PropTypes.string,
284
+ errorSize: PropTypes.string,
285
+ errorColor: PropTypes.string,
286
+ selectedColor: PropTypes.string,
287
+ selectedBorder: PropTypes.string,
288
+ selectedRadius: PropTypes.string,
289
+ selectedHeight: PropTypes.string,
290
+ selectedPadding: PropTypes.string,
291
+ selectedFontSize: PropTypes.string,
292
+ selectedBoxSizing: PropTypes.string,
293
+ selectedHoverColor: PropTypes.string,
294
+ selectedFontWeight: PropTypes.string,
295
+ selectedLineHeight: PropTypes.string,
296
+ selectedTransition: PropTypes.string,
297
+ selectedBorderColor: PropTypes.string,
298
+
299
+ optionsBoxShadow: PropTypes.string,
300
+ optionsBorderRadius: PropTypes.string,
301
+ optionsBackgroundColor: PropTypes.string,
302
+
303
+ optionItemColor: PropTypes.string,
304
+ optionItemCursor: PropTypes.string,
305
+ optionItemPadding: PropTypes.string,
306
+ optionItemFontSize: PropTypes.string,
307
+ optionItemMinHeight: PropTypes.string,
308
+ optionItemBoxSizing: PropTypes.string,
309
+ optionItemFontWeight: PropTypes.string,
310
+ optionItemColorHover: PropTypes.string,
311
+ optionItemLineHeight: PropTypes.string,
312
+ optionItemMarginBottom: PropTypes.string,
313
+ optionItemBackgroudColor: PropTypes.string,
314
+ optionItemBackgroudColorHover: PropTypes.string,
315
+ };
@@ -1,53 +1,28 @@
1
- .select-title {
2
- display: block;
3
- text-transform: none;
4
- font-size: 16px;
5
- color: #3C393E;
6
- line-height: 22px;
7
- font-weight: 500;
8
- margin-bottom: 6px;
9
- }
10
1
  .select-content {
11
2
  display: flex;
12
3
  flex-direction: column;
13
4
  position: relative;
14
5
  }
6
+
15
7
  .select-content-top {
16
8
  display: flex;
17
9
  flex-direction: row;
18
- max-width: 400px;
19
- height: 46px;
20
- padding: 0 15px;
21
- font-size: 16px;
22
- color: #3C393E;
23
- line-height: 22px;
24
- font-weight: 500;
25
- border: 2px solid #D1D1D1;
26
- border-radius: 6px;
27
- transition: border-color 240ms;
28
- box-sizing: border-box;
29
- cursor: pointer;
30
- }
31
- .select-content-top.active {
32
- border-color: #00236A;
33
- }
34
- .select-content-top:hover {
35
- border-color: #3C393E;
10
+ flex-wrap: nowrap;
11
+ align-items: center;
12
+ justify-content: space-between;
36
13
  }
14
+
37
15
  .select-content-bottom {
38
16
  position: absolute;
39
17
  width: 100%;
40
- top: 52px;
41
- left: 0;
18
+ left: 0px;
19
+ z-index: 1;
20
+ max-height: 0;
42
21
  overflow: hidden;
43
- max-width: 400px;
44
- background: #FBFBFB;
45
- box-shadow: 0 0 10px rgba(60, 57, 62, 0.08);
46
- border-radius: 6px;
47
22
  animation: select-show 640ms linear forwards;
48
- max-height: 0;
49
- z-index: 1;
23
+ -webkit-animation: select-show 640ms linear forwards;
50
24
  }
25
+
51
26
  .select-content-bottom-inner {
52
27
  display: flex;
53
28
  flex-direction: column;
@@ -55,66 +30,54 @@
55
30
  overflow-x: hidden;
56
31
  max-height: 234px;
57
32
  }
58
- @keyframes select-show {
59
- 100% {
60
- max-height: 400px;
61
- }
62
- }
63
- .select-content-top-text {
64
- flex: 1;
33
+
34
+ .select-content-top-icon {
65
35
  display: flex;
66
- flex-direction: row;
67
- flex-wrap: nowrap;
36
+ flex: 0 0 auto;
68
37
  align-items: center;
69
- }
70
- .select-content-top-icon {
71
38
  padding: 0 5px 0 20px;
72
39
  box-sizing: border-box;
73
40
  }
74
- .select-content-top-icon {
41
+
42
+ .select-content-top-icon > div {
75
43
  display: flex;
44
+ width: 14px;
45
+ height: 14px;
76
46
  align-items: center;
77
- flex: 0 0 auto;
47
+ justify-content: center;
78
48
  }
79
- .select-content-top-icon > i{
80
- font-size: 12px !important;
81
- color: #3C393E;
82
- }
83
- .select-content-top-icon > i:not(:last-child){
84
- padding: 0 8px;
49
+
50
+ .close-icon {
51
+ padding-right: 9px;
85
52
  border-right: 1px solid #EEEEEE;
86
- margin-right: 8px;
87
- height: 22px;
88
- display: flex;
89
- align-items: center;
90
53
  }
54
+
55
+ .arrow-icon{
56
+ margin-left: 9px;
57
+ transform-origin: center;
58
+ transition: all 640ms ease;
59
+ -webkit-transition: all 640ms ease;
60
+ -moz-transition: all 640ms ease;
61
+ -ms-transition: all 640ms ease;
62
+ -o-transition: all 640ms ease;
63
+ }
64
+
91
65
  .select-content-bottom-row {
92
66
  display: flex;
93
67
  align-items: center;
94
- background: #ffffff;
95
- padding: 0 15px;
96
- min-height: 46px;
97
- font-size: 16px;
98
- color: #3C393E;
99
- line-height: 22px;
100
- font-weight: 500;
101
- margin-bottom: 2px;
102
- box-sizing: border-box;
103
- transition: background 240ms, color 240ms;
104
- cursor: pointer;
105
- }
106
- .select-content-bottom-row:last-child {
107
- margin-bottom: 0;
108
- }
109
- .select-content-bottom-row:hover {
110
- background: unset;
111
- color: #00236A;;
68
+ transition: background-color 240ms, color 240ms;
69
+ -webkit-transition: background-color 240ms, color 240ms;
70
+ -moz-transition: background-color 240ms, color 240ms;
71
+ -ms-transition: background-color 240ms, color 240ms;
72
+ -o-transition: background-color 240ms, color 240ms;
112
73
  }
113
74
 
114
- .error-message {
115
- border: 2px solid rgb(238, 0, 0) !important;
75
+ .select-content-bottom-row:last-child {
76
+ margin-bottom: 0px;
116
77
  }
117
78
 
118
- .eMessage {
119
- color: rgba(238, 0, 0, 1);
79
+ @keyframes select-show {
80
+ 100% {
81
+ max-height: 234px;
82
+ }
120
83
  }
@@ -1,4 +1,4 @@
1
- import { Select, SelectTheme } from ".";
1
+ import { Select } from ".";
2
2
 
3
3
  export default {
4
4
  component: Select,
@@ -9,7 +9,6 @@ const Template = (args) => <Select label='' {...args} >Default</Select>;
9
9
 
10
10
  export const Default = Template.bind({});
11
11
  Default.args = {
12
- theme: SelectTheme.DEFAULT,
13
12
  label: 'վարչական շրջան',
14
13
  jsonData: '[{"bbb":"0", "value":"Արաբկիր"}, {"bbb":"1", "value":"Կենտրոն"}, {"bbb":"2", "value":"Մալաթիա"}]',
15
14
  onChange: (newValue)=> {
@@ -1,5 +1,5 @@
1
1
  import React, { useEffect, useState } from "react";
2
- import PropTypes, { bool, checkPropTypes, func } from "prop-types";
2
+ import PropTypes from "prop-types";
3
3
  import classnames from "classnames";
4
4
  import styles from "./table.module.css";
5
5
  import { Checkbox } from "../checkbox";