@xaypay/tui 0.0.66 → 0.0.67

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.
package/dist/index.es.js CHANGED
@@ -637,17 +637,18 @@ const Input = ({
637
637
  const handleChange = event => {
638
638
  const currentValue = event.target.value;
639
639
  if (onChange) {
640
- currentValue.length > maxLength ? onChange(currentValue.substr(0, maxLength)) : onChange(currentValue);
641
- }
642
- setInnerValue(currentValue);
643
- if (type === 'tel') {
644
- !phoneNumberRegex.test(parseInt(currentValue)) ? setInnerErrorMessage(telErrorMessage) : setInnerErrorMessage('');
645
- }
646
- if (maxLength) {
647
- currentValue.length > maxLength ? setInnerValue(currentValue.substr(0, maxLength)) : setInnerValue(currentValue);
648
- }
649
- if (regexp) {
650
- !regexp.test(currentValue) ? setInnerErrorMessage(regexpErrorMessage) : setInnerErrorMessage('');
640
+ onChange(currentValue);
641
+ } else {
642
+ setInnerValue(currentValue);
643
+ if (type === 'tel') {
644
+ !phoneNumberRegex.test(parseInt(currentValue)) ? setInnerErrorMessage(telErrorMessage) : setInnerErrorMessage('');
645
+ }
646
+ if (maxLength) {
647
+ currentValue.length > maxLength ? setInnerValue(currentValue.substr(0, maxLength)) : setInnerValue(currentValue);
648
+ }
649
+ if (regexp) {
650
+ !regexp.test(currentValue) ? setInnerErrorMessage(regexpErrorMessage) : setInnerErrorMessage('');
651
+ }
651
652
  }
652
653
  };
653
654
  const handleMouseEnter = () => {
@@ -657,7 +658,7 @@ const Input = ({
657
658
  setIsHover(false);
658
659
  };
659
660
  useEffect(() => {
660
- if (value && value !== '') {
661
+ if (value !== undefined && value !== null) {
661
662
  setInnerValue(value);
662
663
  if (type === 'tel') {
663
664
  !phoneNumberRegex.test(parseInt(value)) ? setInnerErrorMessage(telErrorMessage) : setInnerErrorMessage('');
@@ -669,7 +670,10 @@ const Input = ({
669
670
  !regexp.test(value) ? setInnerErrorMessage(regexpErrorMessage) : setInnerErrorMessage('');
670
671
  }
671
672
  }
672
- }, [value]);
673
+ if (onChange && (value === undefined || value === null)) {
674
+ alert('Please add value prop on input component');
675
+ }
676
+ }, [value, onChange]);
673
677
  useEffect(() => {
674
678
  if (errorMessage) {
675
679
  setInnerErrorMessage(errorMessage);
package/dist/index.js CHANGED
@@ -667,17 +667,18 @@ const Input = ({
667
667
  const handleChange = event => {
668
668
  const currentValue = event.target.value;
669
669
  if (onChange) {
670
- currentValue.length > maxLength ? onChange(currentValue.substr(0, maxLength)) : onChange(currentValue);
671
- }
672
- setInnerValue(currentValue);
673
- if (type === 'tel') {
674
- !phoneNumberRegex.test(parseInt(currentValue)) ? setInnerErrorMessage(telErrorMessage) : setInnerErrorMessage('');
675
- }
676
- if (maxLength) {
677
- currentValue.length > maxLength ? setInnerValue(currentValue.substr(0, maxLength)) : setInnerValue(currentValue);
678
- }
679
- if (regexp) {
680
- !regexp.test(currentValue) ? setInnerErrorMessage(regexpErrorMessage) : setInnerErrorMessage('');
670
+ onChange(currentValue);
671
+ } else {
672
+ setInnerValue(currentValue);
673
+ if (type === 'tel') {
674
+ !phoneNumberRegex.test(parseInt(currentValue)) ? setInnerErrorMessage(telErrorMessage) : setInnerErrorMessage('');
675
+ }
676
+ if (maxLength) {
677
+ currentValue.length > maxLength ? setInnerValue(currentValue.substr(0, maxLength)) : setInnerValue(currentValue);
678
+ }
679
+ if (regexp) {
680
+ !regexp.test(currentValue) ? setInnerErrorMessage(regexpErrorMessage) : setInnerErrorMessage('');
681
+ }
681
682
  }
682
683
  };
683
684
  const handleMouseEnter = () => {
@@ -687,7 +688,7 @@ const Input = ({
687
688
  setIsHover(false);
688
689
  };
689
690
  React.useEffect(() => {
690
- if (value && value !== '') {
691
+ if (value !== undefined && value !== null) {
691
692
  setInnerValue(value);
692
693
  if (type === 'tel') {
693
694
  !phoneNumberRegex.test(parseInt(value)) ? setInnerErrorMessage(telErrorMessage) : setInnerErrorMessage('');
@@ -699,7 +700,10 @@ const Input = ({
699
700
  !regexp.test(value) ? setInnerErrorMessage(regexpErrorMessage) : setInnerErrorMessage('');
700
701
  }
701
702
  }
702
- }, [value]);
703
+ if (onChange && (value === undefined || value === null)) {
704
+ alert('Please add value prop on input component');
705
+ }
706
+ }, [value, onChange]);
703
707
  React.useEffect(() => {
704
708
  if (errorMessage) {
705
709
  setInnerErrorMessage(errorMessage);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xaypay/tui",
3
- "version": "0.0.66",
3
+ "version": "0.0.67",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.es.js",
@@ -98,20 +98,20 @@ export const Input = ({
98
98
  const handleChange = (event) => {
99
99
  const currentValue = event.target.value;
100
100
  if (onChange) {
101
- currentValue.length > maxLength ? onChange(currentValue.substr(0, maxLength)) : onChange(currentValue);
102
- }
103
-
104
- setInnerValue(currentValue);
105
- if (type === 'tel') {
106
- !phoneNumberRegex.test(parseInt(currentValue)) ? setInnerErrorMessage(telErrorMessage) : setInnerErrorMessage('');
107
- }
101
+ onChange(currentValue);
102
+ } else {
103
+ setInnerValue(currentValue);
104
+ if (type === 'tel') {
105
+ !phoneNumberRegex.test(parseInt(currentValue)) ? setInnerErrorMessage(telErrorMessage) : setInnerErrorMessage('');
106
+ }
108
107
 
109
- if (maxLength) {
110
- currentValue.length > maxLength ? setInnerValue(currentValue.substr(0, maxLength)) : setInnerValue(currentValue);
111
- }
108
+ if (maxLength) {
109
+ currentValue.length > maxLength ? setInnerValue(currentValue.substr(0, maxLength)) : setInnerValue(currentValue);
110
+ }
112
111
 
113
- if (regexp) {
114
- !regexp.test(currentValue) ? setInnerErrorMessage(regexpErrorMessage) : setInnerErrorMessage('');
112
+ if (regexp) {
113
+ !regexp.test(currentValue) ? setInnerErrorMessage(regexpErrorMessage) : setInnerErrorMessage('');
114
+ }
115
115
  }
116
116
  };
117
117
 
@@ -124,11 +124,11 @@ export const Input = ({
124
124
  };
125
125
 
126
126
  useEffect(() => {
127
- if (value && value !== '') {
127
+ if (value !== undefined && value !== null) {
128
128
  setInnerValue(value);
129
129
  if (type === 'tel') {
130
130
  !phoneNumberRegex.test(parseInt(value)) ? setInnerErrorMessage(telErrorMessage) : setInnerErrorMessage('');
131
- }
131
+ }
132
132
 
133
133
  if (maxLength) {
134
134
  value.length > maxLength ? setInnerValue(value.substr(0, maxLength)) : setInnerValue(value);
@@ -138,7 +138,11 @@ export const Input = ({
138
138
  !regexp.test(value) ? setInnerErrorMessage(regexpErrorMessage) : setInnerErrorMessage('');
139
139
  }
140
140
  }
141
- }, [value]);
141
+
142
+ if (onChange && (value === undefined || value === null)) {
143
+ alert('Please add value prop on input component');
144
+ }
145
+ }, [value, onChange]);
142
146
 
143
147
  useEffect(() => {
144
148
  if (errorMessage) {
@@ -0,0 +1,153 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import PropTypes from 'prop-types';
3
+
4
+ import { compereConfigs } from "./../../utils";
5
+
6
+ import './textarea.module.css';
7
+
8
+ export const Textarea = ({
9
+ size,
10
+ label,
11
+ width,
12
+ value,
13
+ height,
14
+ resize,
15
+ border,
16
+ radius,
17
+ padding,
18
+ required,
19
+ onChange,
20
+ minWidth,
21
+ maxWidth,
22
+ minHeight,
23
+ maxHeight,
24
+ boxSizing,
25
+ maxLength,
26
+ labelSize,
27
+ labelColor,
28
+ borderColor,
29
+ labelWeight,
30
+ placeholder,
31
+ labelDisplay,
32
+ backgroundColor,
33
+ borderFocusColor,
34
+ borderHoverColor,
35
+ labelRequiredColor
36
+ }) => {
37
+ const [isHover, setIsHover] = useState(false);
38
+ const [isFocus, setIsFocus] = useState(false);
39
+
40
+ const configStyles = compereConfigs();
41
+
42
+ const handleMouseEnter = () => {
43
+ setIsHover(true);
44
+ };
45
+
46
+ const handleMouseLeave = () => {
47
+ setIsHover(false);
48
+ };
49
+
50
+ const handleFocus = () => {
51
+ setIsFocus(true);
52
+ };
53
+
54
+ const handleBlur = () => {
55
+ setIsFocus(false);
56
+ };
57
+
58
+ useEffect(() => {
59
+ if (value === undefined) {
60
+ alert('Please add value prop on Textarea component');
61
+ }
62
+
63
+ if (!onChange) {
64
+ alert('Please add onChange function on Textarea component');
65
+ }
66
+ }, [value, onChange]);
67
+
68
+ return (
69
+ <>
70
+ {
71
+ label
72
+ ? <label
73
+ style={{
74
+ color: labelColor ? labelColor : configStyles.TEXTAREA.labelColor,
75
+ fontSize: labelSize ? labelSize : configStyles.TEXTAREA.labelSize,
76
+ display: labelDisplay ? labelDisplay : configStyles.TEXTAREA.labelDisplay,
77
+ fontWeight: labelWeight ? labelWeight : configStyles.TEXTAREA.labelWeight
78
+ }}
79
+ >
80
+ {label}
81
+ {
82
+ required &&
83
+ <sup style={{color: labelRequiredColor ? labelRequiredColor : configStyles.TEXTAREA.labelRequiredColor}}>*</sup>
84
+ }
85
+ </label>
86
+ : ''
87
+ }
88
+ <textarea
89
+ style={{
90
+ outline: 'none',
91
+ overflow: 'auto',
92
+ fontSize: size ? size : configStyles.TEXTAREA.size,
93
+ width: width ? width : configStyles.TEXTAREA.width,
94
+ height: height ? height : configStyles.TEXTAREA.height,
95
+ border: border ? border : configStyles.TEXTAREA.border,
96
+ padding: padding ? padding : configStyles.TEXTAREA.padding,
97
+ borderRadius: radius ? radius : configStyles.TEXTAREA.radius,
98
+ minWidth: minWidth ? minWidth : configStyles.TEXTAREA.minWidth,
99
+ maxWidth: maxWidth ? maxWidth : configStyles.TEXTAREA.maxWidth,
100
+ minHeight: minHeight ? minHeight : configStyles.TEXTAREA.minHeight,
101
+ maxHeight: maxHeight ? maxHeight : configStyles.TEXTAREA.maxHeight,
102
+ boxSizing: boxSizing ? boxSizing : configStyles.TEXTAREA.boxSizing,
103
+ backgroundColor: backgroundColor ? backgroundColor : configStyles.TEXTAREA.backgroundColor,
104
+ borderColor: isFocus ? borderFocusColor ? borderFocusColor : configStyles.TEXTAREA.borderFocusColor :
105
+ isHover ? borderHoverColor ? borderHoverColor : configStyles.TEXTAREA.borderHoverColor :
106
+ borderColor ? borderColor : configStyles.TEXTAREA.borderColor,
107
+ resize: resize ? resize : configStyles.TEXTAREA.resize,
108
+ }}
109
+ onBlur={handleBlur}
110
+ onChange={onChange}
111
+ onFocus={handleFocus}
112
+ placeholder={placeholder}
113
+ onMouseEnter={handleMouseEnter}
114
+ onMouseLeave={handleMouseLeave}
115
+ value={
116
+ maxLength ? value.length > maxLength ? value.substr(0, maxLength) : value :
117
+ configStyles.TEXTAREA.maxLength ? value.length > configStyles.TEXTAREA.maxLength ? value.substr(0, configStyles.TEXTAREA.maxLength) : value :
118
+ value
119
+ }
120
+ ></textarea>
121
+ </>
122
+ );
123
+ };
124
+
125
+ Textarea.propTypes = {
126
+ size: PropTypes.string,
127
+ label: PropTypes.string,
128
+ width: PropTypes.string,
129
+ height: PropTypes.string,
130
+ resize: PropTypes.string,
131
+ border: PropTypes.string,
132
+ radius: PropTypes.string,
133
+ required: PropTypes.bool,
134
+ padding: PropTypes.string,
135
+ minWidth: PropTypes.string,
136
+ maxWidth: PropTypes.string,
137
+ boxSizing: PropTypes.string,
138
+ minHeight: PropTypes.string,
139
+ maxHeight: PropTypes.string,
140
+ maxLength: PropTypes.number,
141
+ labelSize: PropTypes.string,
142
+ labelColor: PropTypes.string,
143
+ labelWeight: PropTypes.string,
144
+ borderColor: PropTypes.string,
145
+ placeholder: PropTypes.string,
146
+ labelDisplay: PropTypes.string,
147
+ backgroundColor: PropTypes.string,
148
+ value: PropTypes.string.isRequired,
149
+ borderFocusColor: PropTypes.string,
150
+ borderHoverColor: PropTypes.string,
151
+ onChange: PropTypes.func.isRequired,
152
+ labelRequiredColor: PropTypes.string
153
+ }
@@ -0,0 +1,21 @@
1
+ textarea::-webkit-scrollbar {
2
+ width: 6px;
3
+ }
4
+
5
+ textarea::-webkit-scrollbar-track {
6
+ background: #EEEEEE;
7
+ border-radius: 3px;
8
+ -webkit-border-radius: 3px;
9
+ -moz-border-radius: 3px;
10
+ -ms-border-radius: 3px;
11
+ -o-border-radius: 3px;
12
+ }
13
+
14
+ textarea::-webkit-scrollbar-thumb {
15
+ background: #D1D1D1;
16
+ border-radius: 3px;
17
+ -webkit-border-radius: 3px;
18
+ -moz-border-radius: 3px;
19
+ -ms-border-radius: 3px;
20
+ -o-border-radius: 3px;
21
+ }
@@ -0,0 +1,49 @@
1
+ import React, { useState } from 'react';
2
+ import { Textarea } from '.';
3
+
4
+ export default {
5
+ Comment: Textarea,
6
+ title: 'Components/Textarea'
7
+ }
8
+
9
+ const Template = (args) => {
10
+ const [val, setVal] = useState('');
11
+
12
+ const handleChangeValue = (e) => {
13
+ setVal(e.target.value);
14
+ }
15
+
16
+ return (
17
+ <Textarea value={val} onChange={handleChangeValue} {...args} />
18
+ );
19
+ };
20
+
21
+ export const Default = Template.bind({});
22
+ Default.args = {
23
+ label: 'Label for textarea',
24
+ required: true,
25
+ size: '16px',
26
+ radius: '6px',
27
+ width: '400px',
28
+ noResize: false,
29
+ height: '134px',
30
+ maxLength: 1500,
31
+ color: '#3C393E',
32
+ minWidth: '200px',
33
+ maxWidth: '500px',
34
+ labelSize: '16px',
35
+ resize: 'vertical',
36
+ minHeight: '100px',
37
+ maxHeight: '300px',
38
+ border: '2px solid',
39
+ padding: '12px 15px',
40
+ labelColor: '#3C393E',
41
+ labelWeight: 'normal',
42
+ labelDisplay: 'block',
43
+ borderColor: '#D1D1D1',
44
+ boxSizing: 'border-box',
45
+ backgroundColor: 'white',
46
+ borderHoverColor: '#3C393E',
47
+ borderFocusColor: '#00236A',
48
+ labelRequiredColor: '#ee0000',
49
+ }
@@ -403,3 +403,33 @@ import StackAlt from './assets/stackalt.svg';
403
403
  });
404
404
  }
405
405
  ```
406
+
407
+ ### Textarea
408
+
409
+ ```
410
+ {
411
+ size: '16px', // for font size
412
+ radius: '6px', // for border radius
413
+ width: '400px', // for width
414
+ resize: 'none', // for resize
415
+ height: '134px', // for height
416
+ maxLength: 1500, // for characters maximum count
417
+ color: '#3C393E', // for color
418
+ minWidth: '200px', // for minimum width
419
+ maxWidth: '500px', // for maximum width
420
+ labelSize: '16px', // for label font size
421
+ minHeight: '100px', // for minimum height
422
+ maxHeight: '300px', // for maximum height
423
+ border: '2px solid', // for border
424
+ padding: '12px 15px', // for padding
425
+ labelColor: '#3C393E', // for label color
426
+ labelWeight: 'normal', // for label font weight
427
+ labelDisplay: 'block', // for label display
428
+ borderColor: '#D1D1D1', // for border color
429
+ boxSizing: 'border-box', // for box sizing
430
+ backgroundColor: 'white', // for background color
431
+ borderHoverColor: '#3C393E', // for border color when hover action is happaning
432
+ borderFocusColor: '#00236A', // for boredr color when focus action is happaning
433
+ labelRequiredColor: '#ee0000', // for label required mark color
434
+ }
435
+ ```
@@ -12,7 +12,8 @@ import buttonImage from './static/button-usage.png';
12
12
  import selectImage from './static/select-usage.png';
13
13
  import inputTooltipImage from './static/input-tooltip-usage.png';
14
14
  import toasterImage from './static/toaster-container-usage.png';
15
- import toastImage from './static/toaster-usage.png'
15
+ import toastImage from './static/toaster-usage.png';
16
+ import textareaImage from './static/textarea-usage.png';
16
17
 
17
18
  <Meta title="Intro/Usage" />
18
19
 
@@ -145,3 +146,7 @@ import toastImage from './static/toaster-usage.png'
145
146
 
146
147
  #### createToast function usage
147
148
  <img src={toastImage} alt="toaster image" />
149
+
150
+ ### Textarea
151
+
152
+ <img src={textareaImage} alt="textarea image" />
package/tui.config.js CHANGED
@@ -225,5 +225,30 @@ module.exports = {
225
225
  optionItemBoxSizing: 'border-box', // for option box sizing
226
226
  optionItemBackgroudColor: '#ffffff', // for option background color
227
227
  optionItemBackgroudColorHover: 'unset', // for option background color ( when hover )
228
+ },
229
+ // default properties for <Textarea /> component
230
+ TEXTAREA: {
231
+ size: '16px',
232
+ radius: '6px',
233
+ width: '400px',
234
+ height: '134px',
235
+ color: '#3C393E',
236
+ minWidth: '200px',
237
+ maxWidth: '500px',
238
+ labelSize: '16px',
239
+ resize: 'vertical',
240
+ minHeight: '100px',
241
+ maxHeight: '300px',
242
+ border: '2px solid',
243
+ padding: '12px 15px',
244
+ labelColor: '#3C393E',
245
+ labelWeight: 'normal',
246
+ labelDisplay: 'block',
247
+ borderColor: '#D1D1D1',
248
+ boxSizing: 'border-box',
249
+ backgroundColor: 'white',
250
+ borderHoverColor: '#3C393E',
251
+ borderFocusColor: '#00236A',
252
+ labelRequiredColor: '#ee0000',
228
253
  }
229
254
  };