intelicoreact 0.0.4 → 0.0.8

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.
Files changed (147) hide show
  1. package/dist/Atomic/FormElements/CheckboxInput/CheckboxInput.js +6 -2
  2. package/dist/Atomic/FormElements/CheckboxInput/CheckboxInput.scss +91 -60
  3. package/dist/Atomic/FormElements/CheckboxInput/CheckboxInput.stories.js +2 -1
  4. package/dist/Atomic/FormElements/DateTime/DateTime.stories.js +1 -1
  5. package/dist/Atomic/FormElements/Dropdown/Dropdown.js +64 -32
  6. package/dist/Atomic/FormElements/Dropdown/Dropdown.scss +26 -3
  7. package/dist/Atomic/FormElements/Dropdown/Dropdown.stories.js +40 -9
  8. package/dist/Atomic/FormElements/Input/Input.js +141 -97
  9. package/dist/Atomic/FormElements/Input/Input.scss +18 -15
  10. package/dist/Atomic/FormElements/Input/Input.stories.js +46 -29
  11. package/dist/Atomic/FormElements/InputCalendar/InputCalendar.js +89 -0
  12. package/dist/Atomic/FormElements/{Calendar/Calendar.stories.js → InputCalendar/InputCalendar.stories.js} +19 -20
  13. package/dist/Atomic/FormElements/InputDateRange/InputDateRange.js +234 -0
  14. package/dist/Atomic/FormElements/InputDateRange/InputDateRange.scss +626 -0
  15. package/dist/Atomic/FormElements/InputDateRange/InputDateRange.stories.js +91 -0
  16. package/dist/Atomic/FormElements/InputDateRange/components/Datepicker.js +491 -0
  17. package/dist/Atomic/FormElements/InputDateRange/components/OpenedPart.js +156 -0
  18. package/dist/Atomic/FormElements/InputDateRange/components/SelectItem.js +46 -0
  19. package/dist/Atomic/FormElements/InputDateRange/dependencies.js +249 -0
  20. package/dist/Atomic/FormElements/Label/Label.js +3 -10
  21. package/dist/Atomic/FormElements/Label/Label.scss +2 -0
  22. package/dist/Atomic/FormElements/Label/Label.stories.js +5 -4
  23. package/dist/Atomic/FormElements/Modal/Modal.stories.js +64 -18
  24. package/dist/Atomic/FormElements/NumericInput/NumericInput.js +254 -0
  25. package/dist/Atomic/FormElements/NumericInput/NumericInput.scss +135 -0
  26. package/dist/Atomic/FormElements/NumericInput/NumericInput.stories.js +121 -0
  27. package/dist/Atomic/FormElements/RangeCalendar/RangeCalendar.js +167 -0
  28. package/dist/Atomic/FormElements/RangeCalendar/RangeCalendar.scss +101 -0
  29. package/dist/Atomic/FormElements/RangeCalendar/RangeCalendar.stories.js +81 -0
  30. package/dist/Atomic/FormElements/Table/Table.scss +1 -1
  31. package/dist/Atomic/FormElements/Textarea/Textarea.scss +1 -1
  32. package/dist/Atomic/MainMenu/MainMenu.scss +2 -2
  33. package/dist/Atomic/UI/Accordion/Accordion.scss +2 -2
  34. package/dist/Atomic/UI/Arrow/Arrow.js +80 -0
  35. package/dist/Atomic/UI/Arrow/Arrow.scss +19 -0
  36. package/dist/Atomic/UI/Arrow/Arrow.stories.js +46 -0
  37. package/dist/Atomic/UI/Button/Button.js +4 -2
  38. package/dist/Atomic/UI/Button/Button.scss +26 -0
  39. package/dist/Atomic/UI/Button/Button.stories.js +2 -2
  40. package/dist/Atomic/UI/Calendar/Calendar.js +146 -0
  41. package/dist/Atomic/UI/Calendar/Calendar.scss +544 -0
  42. package/dist/Atomic/UI/Calendar/Calendar.stories.js +38 -0
  43. package/dist/Atomic/UI/Price/Price.js +1 -0
  44. package/dist/Atomic/UI/Status/Status.scss +1 -1
  45. package/dist/Constants/index.constants.js +8 -0
  46. package/dist/Functions/inputExecutor.js +58 -0
  47. package/dist/Functions/useClickOutside.js +25 -0
  48. package/dist/Functions/utils.js +10 -2
  49. package/dist/Molecular/Datepicker/Datepicker.js +451 -0
  50. package/dist/Molecular/Datepicker/Datepicker.scss +8 -0
  51. package/dist/Molecular/Datepicker/Datepicker.stories.js +44 -0
  52. package/dist/Molecular/Datepicker/components/Calendar.js +156 -0
  53. package/dist/Molecular/FormElements/FormElement.js +40 -0
  54. package/dist/Molecular/FormElements/FormElement.scss +8 -0
  55. package/dist/Molecular/FormElements/FormElement.stories.js +73 -0
  56. package/dist/scss/_vars.scss +3 -1
  57. package/dist/scss/main.scss +3 -3
  58. package/package.json +9 -4
  59. package/src/Atomic/FormElements/CheckboxInput/CheckboxInput.js +12 -2
  60. package/src/Atomic/FormElements/CheckboxInput/CheckboxInput.scss +91 -60
  61. package/src/Atomic/FormElements/CheckboxInput/CheckboxInput.stories.js +4 -3
  62. package/src/Atomic/FormElements/DateTime/DateTime.stories.js +1 -1
  63. package/src/Atomic/FormElements/Dropdown/Dropdown.js +57 -19
  64. package/src/Atomic/FormElements/Dropdown/Dropdown.scss +26 -3
  65. package/src/Atomic/FormElements/Dropdown/Dropdown.stories.js +37 -15
  66. package/src/Atomic/FormElements/Input/Input.js +136 -79
  67. package/src/Atomic/FormElements/Input/Input.scss +18 -15
  68. package/src/Atomic/FormElements/Input/Input.stories.js +48 -31
  69. package/src/Atomic/FormElements/InputCalendar/InputCalendar.js +43 -0
  70. package/src/Atomic/FormElements/InputCalendar/InputCalendar.stories.js +27 -0
  71. package/src/Atomic/FormElements/InputDateRange/InputDateRange.js +214 -0
  72. package/src/Atomic/FormElements/InputDateRange/InputDateRange.scss +626 -0
  73. package/src/Atomic/FormElements/InputDateRange/InputDateRange.stories.js +61 -0
  74. package/src/Atomic/FormElements/InputDateRange/components/Datepicker.js +412 -0
  75. package/src/Atomic/FormElements/InputDateRange/components/OpenedPart.js +114 -0
  76. package/src/Atomic/FormElements/InputDateRange/components/SelectItem.js +24 -0
  77. package/src/Atomic/FormElements/InputDateRange/dependencies.js +161 -0
  78. package/src/Atomic/FormElements/Label/Label.js +3 -4
  79. package/src/Atomic/FormElements/Label/Label.scss +2 -0
  80. package/src/Atomic/FormElements/Label/Label.stories.js +5 -4
  81. package/src/Atomic/FormElements/Modal/Modal.stories.js +60 -15
  82. package/src/Atomic/FormElements/NumericInput/NumericInput.js +220 -0
  83. package/src/Atomic/FormElements/NumericInput/NumericInput.scss +135 -0
  84. package/src/Atomic/FormElements/NumericInput/NumericInput.stories.js +94 -0
  85. package/src/Atomic/FormElements/RangeCalendar/RangeCalendar.js +146 -0
  86. package/src/Atomic/FormElements/RangeCalendar/RangeCalendar.scss +101 -0
  87. package/src/Atomic/FormElements/RangeCalendar/RangeCalendar.stories.js +54 -0
  88. package/src/Atomic/FormElements/Table/Table.scss +1 -1
  89. package/src/Atomic/FormElements/Textarea/Textarea.scss +1 -1
  90. package/src/Atomic/MainMenu/MainMenu.scss +2 -2
  91. package/src/Atomic/UI/Accordion/Accordion.scss +2 -2
  92. package/src/Atomic/UI/Arrow/Arrow.js +41 -0
  93. package/src/Atomic/UI/Arrow/Arrow.scss +19 -0
  94. package/src/Atomic/UI/Arrow/Arrow.stories.js +32 -0
  95. package/src/Atomic/UI/Button/Button.js +3 -3
  96. package/src/Atomic/UI/Button/Button.scss +26 -0
  97. package/src/Atomic/UI/Button/Button.stories.js +4 -3
  98. package/src/Atomic/{FormElements → UI}/Calendar/Calendar.js +26 -23
  99. package/src/Atomic/UI/Calendar/Calendar.scss +544 -0
  100. package/src/Atomic/UI/Calendar/Calendar.stories.js +24 -0
  101. package/src/Atomic/UI/Price/Price.js +1 -0
  102. package/src/Atomic/UI/Status/Status.scss +1 -1
  103. package/src/Constants/index.constants.js +41 -0
  104. package/src/Functions/inputExecutor.js +62 -0
  105. package/src/Functions/useClickOutside.js +15 -0
  106. package/src/Functions/utils.js +10 -1
  107. package/src/Molecular/Datepicker/Datepicker.js +346 -0
  108. package/src/Molecular/Datepicker/Datepicker.scss +8 -0
  109. package/src/Molecular/Datepicker/Datepicker.stories.js +27 -0
  110. package/src/Molecular/Datepicker/components/Calendar.js +118 -0
  111. package/src/Molecular/FormElements/FormElement.js +18 -0
  112. package/src/Molecular/FormElements/FormElement.scss +8 -0
  113. package/src/Molecular/FormElements/FormElement.stories.js +59 -0
  114. package/src/scss/_vars.scss +3 -1
  115. package/src/scss/main.scss +3 -3
  116. package/dist/Atomic/FormElements/Calendar/Calendar.js +0 -127
  117. package/dist/Atomic/FormElements/Calendar/Calendar.scss +0 -498
  118. package/dist/scss/anme/_anme-bootstrap-grid.scss +0 -748
  119. package/dist/scss/anme/_anme-elements.scss +0 -269
  120. package/dist/scss/anme/_anme-grid.scss +0 -111
  121. package/dist/scss/anme/_anme-justify.scss +0 -111
  122. package/dist/scss/anme/_anme-mixins-media.scss +0 -116
  123. package/dist/scss/anme/_anme-mixins.scss +0 -166
  124. package/dist/scss/anme/_anme-normalize.scss +0 -8
  125. package/dist/scss/anme/_anme-overall.scss +0 -34
  126. package/dist/scss/anme/_anme-padding-margins.scss +0 -419
  127. package/dist/scss/anme/_anme-table.scss +0 -81
  128. package/dist/scss/anme/_anme-theme.scss +0 -275
  129. package/dist/scss/anme/_anme-vars.scss +0 -91
  130. package/dist/scss/anme/_code-styling.scss +0 -23
  131. package/dist/scss/anme/styles.scss +0 -12
  132. package/src/Atomic/FormElements/Calendar/Calendar.scss +0 -498
  133. package/src/Atomic/FormElements/Calendar/Calendar.stories.js +0 -26
  134. package/src/scss/anme/_anme-bootstrap-grid.scss +0 -748
  135. package/src/scss/anme/_anme-elements.scss +0 -269
  136. package/src/scss/anme/_anme-grid.scss +0 -111
  137. package/src/scss/anme/_anme-justify.scss +0 -111
  138. package/src/scss/anme/_anme-mixins-media.scss +0 -116
  139. package/src/scss/anme/_anme-mixins.scss +0 -166
  140. package/src/scss/anme/_anme-normalize.scss +0 -8
  141. package/src/scss/anme/_anme-overall.scss +0 -34
  142. package/src/scss/anme/_anme-padding-margins.scss +0 -419
  143. package/src/scss/anme/_anme-table.scss +0 -81
  144. package/src/scss/anme/_anme-theme.scss +0 -275
  145. package/src/scss/anme/_anme-vars.scss +0 -91
  146. package/src/scss/anme/_code-styling.scss +0 -23
  147. package/src/scss/anme/styles.scss +0 -12
@@ -1,33 +1,54 @@
1
1
  import React, { useState } from 'react';
2
2
  import Dropdown from './Dropdown';
3
3
 
4
-
5
4
  global.lng = 'en';
6
5
  export default {
7
6
  title: 'Dropdown',
8
- component: Dropdown
7
+ component: Dropdown,
8
+ argTypes: {
9
+ className: {
10
+ description: 'string',
11
+ },
12
+ value: { description: 'string - current option' },
13
+ isSearchable: {
14
+ description: 'boolean - enable search',
15
+ },
16
+ onChange: { description: 'callback return selected value' },
17
+ entity: {
18
+ description: 'string',
19
+ },
20
+ },
9
21
  };
10
22
 
11
- const Template = args => {
12
- const [value, setValue] = useState({});
23
+ const buttonStyles={
24
+ border: 'solid 1px #000',
25
+ padding: '5px'
26
+ };
27
+
28
+ const Template = (args) => {
29
+ const [value, setValue] = useState('');
13
30
  return (
14
- <div style={{ width: 200 }}>
15
- <Dropdown {...args} value={value} onChange={setValue} />
16
- </div>
31
+ <>
32
+ <div style={{ width: 200 }}>
33
+ <Dropdown {...args} value={value} onChange={setValue} />
34
+ </div>
35
+ <button style={buttonStyles} className='mt10' onClick={() => {console.log('click!'); setValue('')}} >Reset</button>
36
+ </>
17
37
  );
18
38
  };
19
39
 
20
40
  export const DropdownTemplate = Template.bind({});
21
41
 
22
42
  DropdownTemplate.args = {
43
+ entity: 'entity',
44
+ value: 'drop6',
23
45
  placeholder: 'Placeholder',
24
- label: '',
25
46
  isSearchable: true,
26
47
  options: [
27
- { label: 'Dropdown1', value: 'drop1' },
28
48
  { label: 'Dropdown2', value: 'drop2' },
29
49
  { label: 'Dropdown3', value: 'drop3', disabled: true },
30
50
  { label: 'Dropdown4', value: 'drop4' },
51
+ { label: 'Dropdown1', value: 'drop1', className: 'status status--approved' },
31
52
  { label: 'Dropdown5', value: 'drop5' },
32
53
  { label: 'Dropdown6', value: 'drop6' },
33
54
  {
@@ -35,16 +56,17 @@ DropdownTemplate.args = {
35
56
  items: [
36
57
  { label: 'Group 11', value: 'group11' },
37
58
  { label: 'Group 12', value: 'group12', disabled: true },
38
- { label: 'Group 13', value: 'group13' }
39
- ]
59
+ { label: 'Group 13', value: 'group13' },
60
+ ],
40
61
  },
41
62
  {
42
63
  label: 'Some Group 2',
43
64
  items: [
44
65
  { label: 'Group 21', value: 'group21' },
45
66
  { label: 'Group 22', value: 'group22' },
46
- { label: 'Group 23', value: 'group23' }
47
- ]
48
- }
49
- ]
67
+ { label: 'Group 23', value: 'group23' },
68
+ ],
69
+ },
70
+ ],
71
+ error: '',
50
72
  };
@@ -1,110 +1,167 @@
1
1
  import React, { useState, useEffect, useRef } from 'react';
2
2
  import cn from 'classnames';
3
- import { Minus, Plus } from 'react-feather';
4
-
5
- import Label from '../Label/Label';
3
+ import InputMask from 'react-input-mask';
4
+ import { KEYBOARD_SERVICE_KEYS } from '../../../Constants/index.constants';
5
+ import { formatInput } from '../../../Functions/inputExecutor';
6
6
 
7
7
  import './Input.scss';
8
8
 
9
9
  const Input = ({
10
- error,
11
10
  onChange,
11
+ onBlur,
12
+ onFocus,
13
+ onKeyUp,
14
+ isNotBlinkErrors,
15
+ isPriceInput,
16
+ isOnlyNumber,
17
+ isOnlyString,
18
+ isTwoDigitAfterDot,
12
19
  disabled,
13
20
  withDelete,
14
- isNumeric,
15
- min,
16
- max,
17
- value = min,
21
+ value,
18
22
  placeholder,
19
- hint,
20
- label,
21
- hintSide,
22
23
  className,
23
- isLabelBold,
24
24
  type = 'text',
25
- onBlur = () => {},
25
+ mask,
26
+ maskChar,
27
+ formatChars,
28
+ error,
26
29
  icon,
27
- isRequired,
28
- ...props
30
+ symbolsLimit,
31
+ blinkTime
29
32
  }) => {
33
+ const DEFAULT_BLINK_TIME = 100;
34
+ // STATES
30
35
  const [isFocused, setIsFocused] = useState(false);
31
- const [onInputHover, setOnInputHover] = useState(false);
32
36
  const [isEditing, setEditing] = useState(false);
33
37
  const inputRef = useRef(null);
38
+ const previousValueRef = useRef(value);
39
+ const [isAttemptToChange, setIsAttemptToChange] = useState(false);
40
+ const [isToHighlightError, setIsToHighlightError] = useState(false);
41
+
42
+ const { onlyNumbers, onlyString } = formatInput;
43
+ const { addCommas, removeComma } = formatInput.priceInput;
44
+ // HANDLES
45
+ const handle = {
46
+ change: (e) => {
47
+ let inputValue = e.target ? e.target.value : e;
48
+ if (symbolsLimit && inputValue.length > +symbolsLimit) {
49
+ inputValue = inputValue.substring(0, +symbolsLimit);
50
+ }
51
+
52
+ if (isOnlyNumber && !isTwoDigitAfterDot)
53
+ inputValue = onlyNumbers(inputValue);
54
+ if (isTwoDigitAfterDot) inputValue = onlyNumbers(inputValue, true);
55
+ if (isOnlyString) inputValue = onlyString(inputValue);
56
+
57
+ onChange(inputValue.toString());
58
+ },
59
+ toggleEdit: () => {
60
+ setEditing(!isEditing);
61
+ onChange('');
62
+ },
63
+ focus: (e) => {
64
+ setIsFocused(true);
65
+ if (isPriceInput && isOnlyNumber && !isTwoDigitAfterDot)
66
+ onChange(removeComma(value));
67
+
68
+ if (onFocus) onFocus(e);
69
+ },
70
+ blur: (e) => {
71
+ setIsFocused(false);
72
+ setEditing(false);
73
+ if (isPriceInput && isOnlyNumber && !isTwoDigitAfterDot) {
74
+ onChange(addCommas(value));
75
+ }
76
+ if (isTwoDigitAfterDot && !isPriceInput) {
77
+ onChange(cutOffsingleDot(value));
78
+ }
79
+ if (onBlur) onBlur(e);
80
+ },
81
+ keyUp: (e) => {
82
+ if (!isNotBlinkErrors) {
83
+ const changedValue = '' + (value ?? '');
84
+ const previousValue = '' + (previousValueRef.current ?? '');
85
+ const currentSet = (() => {
86
+ if (previousValue.length < changedValue.length)
87
+ return value.slice(previousValue.length - changedValue.length);
88
+ else return changedValue.includes(e.key) ? e.key : '';
89
+ })();
90
+
91
+ if (
92
+ !KEYBOARD_SERVICE_KEYS.includes(e.key) &&
93
+ changedValue === previousValue
94
+ )
95
+ setIsAttemptToChange(true);
96
+
97
+ console.log(changedValue, previousValue);
98
+ if (KEYBOARD_SERVICE_KEYS.includes(e.key) || !currentSet)
99
+ previousValueRef.current = value;
100
+ else previousValueRef.current = previousValue + currentSet[0];
101
+ }
34
102
 
35
- const changeHandler = inputValue => {
36
- if (isNumeric || (type === 'number' && inputValue !== '')) {
37
- const totalValue = Number(+inputValue);
38
- if (totalValue >= (min ?? -Infinity) && totalValue <= (max ?? Infinity)) onChange(totalValue);
39
- return;
103
+ if (onKeyUp) onKeyUp(e.keyCode, e);
40
104
  }
41
- onChange(inputValue);
42
105
  };
43
106
 
44
- const toggleEditing = () => {
45
- setEditing(!isEditing);
107
+ function cutOffsingleDot(value) {
108
+ return value.slice(-1) === '.' ? value.slice(0, -1) : value;
109
+ }
110
+
111
+ useEffect(() => {
112
+ if (isEditing) inputRef.current.focus();
113
+ }, [isEditing, isFocused]);
114
+
115
+ const uniProps = {
116
+ className: `input ${className}`,
117
+ placeholder,
118
+ value: value || '',
119
+ disabled,
120
+ onChange: handle.change,
121
+ onFocus: handle.focus,
122
+ onBlur: handle.blur,
123
+ onKeyUp: handle.keyUp,
124
+ ...(maskChar ? { maskChar } : {}),
125
+ ...(formatChars ? { formatChars } : {})
46
126
  };
47
127
 
128
+ function renderInput() {
129
+ if (mask) {
130
+ return <InputMask {...uniProps} ref={inputRef} mask={mask} />;
131
+ }
132
+
133
+ return (
134
+ <input {...uniProps} ref={inputRef} type={isPriceInput ? 'text' : type} />
135
+ );
136
+ }
137
+
48
138
  useEffect(() => {
49
- if (isEditing) {
50
- inputRef.current.focus();
139
+ if (!isNotBlinkErrors && isAttemptToChange) {
140
+ setIsAttemptToChange(null);
141
+ setIsToHighlightError(true);
142
+ setTimeout(() => {
143
+ setIsToHighlightError(false);
144
+ }, blinkTime || DEFAULT_BLINK_TIME);
51
145
  }
52
- }, [isEditing, isFocused]);
146
+ }, [isAttemptToChange]);
53
147
 
54
148
  return (
55
- <div className={cn('input-classic', className)}>
56
- {label && <Label className="input-classic-label" isBold={isLabelBold} label={label} hint={hint} hintSide={hintSide} isRequired={isRequired} />}
57
-
58
- <div
59
- onMouseEnter={() => setOnInputHover(true)}
60
- onMouseLeave={() => setOnInputHover(false)}
61
- className={cn(
62
- `input-classic__wrap`,
63
- { [`input-classic__wrap_focus`]: isFocused },
64
- { [`input-classic__wrap_error`]: error },
65
- { [`input-classic__wrap_disabled`]: disabled }
66
- )}
67
- >
68
- <input
69
- ref={inputRef}
70
- className="input-classic__input"
71
- type={isNumeric ? 'number' : type}
72
- onChange={e => changeHandler(e.target.value)}
73
- value={value || ''}
74
- disabled={disabled}
75
- onBlur={() => {
76
- setIsFocused(false);
77
- setEditing(false);
78
- onBlur();
79
- }}
80
- onFocus={() => setIsFocused(true)}
81
- placeholder={placeholder}
82
- {...props}
149
+ <div
150
+ className={cn(
151
+ `input__wrap`,
152
+ { [`input__wrap_focus`]: isFocused },
153
+ { [`input__wrap_error`]: error || isToHighlightError },
154
+ { [`input__wrap_disabled`]: disabled }
155
+ )}
156
+ >
157
+ {renderInput()}
158
+ {icon}
159
+ {withDelete && (
160
+ <span
161
+ className={cn(`input__close`, { hidden: !value })}
162
+ onClick={handle.toggleEdit}
83
163
  />
84
- {isNumeric && (
85
- <div className="input-classic__nums">
86
- <button onClick={() => changeHandler(value - 1)} className={cn(`input-classic__num-btn`, { disabled: value === min })}>
87
- <Minus />
88
- </button>
89
- <button onClick={() => changeHandler(value + 1)} className={cn(`input-classic__num-btn`, { disabled: value === max })}>
90
- <Plus />
91
- </button>
92
- </div>
93
- )}
94
-
95
- {withDelete && onInputHover && !isNumeric && (
96
- <button
97
- className={cn(`input-classic__close`, { hidden: !value })}
98
- onClick={() => {
99
- toggleEditing();
100
- onChange('');
101
- }}
102
- />
103
- )}
104
- {icon ?? null}
105
- </div>
106
-
107
- {error && <span className="input-classic__error">{error}</span>}
164
+ )}
108
165
  </div>
109
166
  );
110
167
  };
@@ -1,9 +1,12 @@
1
- .input-classic {
1
+ .input {
2
2
  position: relative;
3
3
  word-break: break-all;
4
-
5
- input::-webkit-outer-spin-button,
6
- input::-webkit-inner-spin-button {
4
+ border: none;
5
+ background: none;
6
+ padding: 0 10px;
7
+ width: 100%;
8
+ &::-webkit-outer-spin-button,
9
+ &::-webkit-inner-spin-button {
7
10
  -webkit-appearance: none;
8
11
  }
9
12
 
@@ -60,15 +63,6 @@
60
63
  border-radius: 4px;
61
64
  }
62
65
 
63
- &__error {
64
- margin-top: 2px;
65
- margin-left: 1px;
66
- position: absolute;
67
- display: block;
68
- font-size: 10px;
69
- color: #f06d8d;
70
- }
71
-
72
66
  &__close {
73
67
  position: relative;
74
68
  opacity: 0.6;
@@ -77,7 +71,8 @@
77
71
  background: none;
78
72
  cursor: pointer;
79
73
  margin-right: 4px;
80
-
74
+ visibility: hidden;
75
+ pointer-events: none;
81
76
  &:hover {
82
77
  opacity: 1;
83
78
  }
@@ -121,7 +116,9 @@
121
116
  background: none;
122
117
  font-size: 20px;
123
118
  user-select: none;
124
-
119
+ &.disabled {
120
+ opacity: 0.3;
121
+ }
125
122
  svg {
126
123
  margin-right: 0;
127
124
  }
@@ -131,3 +128,9 @@
131
128
  margin-bottom: 5px;
132
129
  }
133
130
  }
131
+
132
+ .input__wrap:hover .input__close {
133
+ visibility: visible;
134
+ pointer-events: all;
135
+ }
136
+
@@ -1,4 +1,5 @@
1
1
  import React, { useState } from 'react';
2
+ import { User } from 'react-feather';
2
3
  import Input from './Input';
3
4
 
4
5
  global.lng = 'en';
@@ -7,51 +8,66 @@ export default {
7
8
  title: 'Form Elements/Input',
8
9
  component: Input,
9
10
  argTypes: {
10
- hintSide: {
11
- description: 'string: ["right", "bottom", "top", "left"]',
12
- control: {
13
- type: 'select',
14
- options: ['right', 'bottom', 'top', 'left']
15
- }
16
- },
17
- hint: {
18
- description: 'string'
19
- },
20
11
  disabled: {
21
12
  description: 'boolean'
22
13
  },
23
14
  error: {
24
- description: 'text'
15
+ description: 'text - coloring input if is errored'
16
+ },
17
+ isPriceInput: {
18
+ description: 'boolean - if true, the input will be styled as PriceInput'
25
19
  },
26
20
  withDelete: {
27
- description: 'boolean'
21
+ description: 'boolean - add clear-cross by hover'
28
22
  },
29
- isNumeric: {
30
- description: 'boolean'
23
+ isOnlyNumber: {
24
+ description: 'boolean - only numbers'
31
25
  },
32
- min: {
33
- description: 'number'
26
+ isOnlyString: {
27
+ description: 'boolean - only strings'
34
28
  },
35
- max: {
36
- description: 'number'
29
+ isTwoDigitAfterDot: {
30
+ description: 'boolean - only two digits after dot'
37
31
  },
38
32
  placeholder: {
39
33
  description: 'text'
40
34
  },
41
- label: {
42
- description: 'text'
43
- },
44
35
  type: {
45
- description: 'string: any input type',
36
+ description:
37
+ "'text', 'number', 'password', 'color', 'date', 'datetime-local', 'month', 'time', 'email', 'range'",
46
38
  control: {
47
39
  type: 'select',
48
- options: ['text', 'number']
40
+ options: [
41
+ 'text',
42
+ 'number',
43
+ 'password',
44
+ 'color',
45
+ 'date',
46
+ 'datetime-local',
47
+ 'month',
48
+ 'time',
49
+ 'email',
50
+ 'range'
51
+ ]
49
52
  }
50
- }
53
+ },
54
+ icon: { description: 'JSX' },
55
+ value: { description: '(* - required prop)' },
56
+ className: { description: 'string' },
57
+ mask: {
58
+ description:
59
+ 'string: force input to masked https://www.npmjs.com/package/react-input-mask'
60
+ },
61
+ symbolsLimit: {
62
+ description: 'Set limit of symbols in input, overhead will be ignored'
63
+ },
64
+ onBlur: { description: 'custom callback on blur' },
65
+ onFocus: { description: 'custom callback on focus' },
66
+ onKeyUp: { description: 'custom callback on keyup, returns event keyCode' }
51
67
  }
52
68
  };
53
69
 
54
- const Template = args => {
70
+ const Template = (args) => {
55
71
  const [value, setValue] = useState('');
56
72
  return <Input {...args} value={value} onChange={setValue} />;
57
73
  };
@@ -60,14 +76,15 @@ export const InputTemplate = Template.bind({});
60
76
 
61
77
  InputTemplate.args = {
62
78
  type: 'text',
79
+ isOnlyNumber: false,
80
+ isOnlyString: false,
81
+ isPriceInput: false,
82
+ isTwoDigitAfterDot: false,
63
83
  disabled: false,
64
84
  error: '',
85
+ mask: '',
65
86
  withDelete: true,
66
- isNumeric: false,
67
- min: '0',
68
- max: 5,
87
+ symbolsLimit: 255,
69
88
  placeholder: 'Placeholder',
70
- label: 'label',
71
- hint: 'hint',
72
- hintSide: 'bottom'
89
+ icon: <User />
73
90
  };
@@ -0,0 +1,43 @@
1
+ import React, { useState, useRef } from 'react';
2
+ import moment from 'moment';
3
+ import InputMask from 'react-input-mask';
4
+ import Calendar from '../../UI/Calendar/Calendar';
5
+ import { useClickOutside } from '../../../Functions/useClickOutside';
6
+
7
+ const InputCalendar = ({ data, params }) => {
8
+ const [date, setDate] = useState(data);
9
+ const [inputValue, setInputValue] = useState(date);
10
+ const [isOpened, setIsOpened] = useState(false);
11
+ const calendarRef = useRef(null);
12
+
13
+ useClickOutside(calendarRef, () => setIsOpened(false));
14
+
15
+ const changeInputValue = value => {
16
+ if (!value.includes('_') && value) {
17
+ setDate(moment(value).format('L'));
18
+ setInputValue(moment(value).format('L'));
19
+ } else {
20
+ setInputValue(value);
21
+ }
22
+ };
23
+
24
+ const changeCalendarDay = value => {
25
+ setDate(value);
26
+ setInputValue(value);
27
+ };
28
+
29
+ return (
30
+ <div className="calendar-container" ref={calendarRef}>
31
+ <InputMask
32
+ mask="99/99/9999"
33
+ value={inputValue}
34
+ onChange={e => changeInputValue(e.target.value)}
35
+ className="calendar-dropdown"
36
+ onFocus={() => setIsOpened(!isOpened)}
37
+ />
38
+ {isOpened ? <Calendar date={date} setDate={(newDate) => changeCalendarDay(newDate)} params={params} /> : null}
39
+ </div>
40
+ );
41
+ };
42
+
43
+ export default InputCalendar;
@@ -0,0 +1,27 @@
1
+ import React, { useRef, useState } from 'react';
2
+ import { ref } from 'yup';
3
+ import InputCalendar from './InputCalendar';
4
+
5
+ global.lng = 'en';
6
+
7
+ export default {
8
+ title: 'Form Elements/InputCalendar',
9
+ component: InputCalendar,
10
+ };
11
+
12
+ const Template = (args) => {
13
+ const params = {
14
+ minDate: args?.minDate,
15
+ maxDate: args?.maxDate,
16
+ };
17
+
18
+ return <InputCalendar data={args.date} params={params} />;
19
+ };
20
+
21
+ export const Calendar = Template.bind({});
22
+
23
+ Calendar.args = {
24
+ date: '10/14/2021',
25
+ minDate: '10/11/2021',
26
+ maxDate: '10/25/2021',
27
+ };