@weareconceptstudio/form 0.2.5 → 0.2.7
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/form/hooks/rules.js
CHANGED
|
@@ -30,7 +30,7 @@ export const useRules = ({ rules, required, requiredMessage, childType, errorKey
|
|
|
30
30
|
if (childType.toLowerCase() === 'phone') {
|
|
31
31
|
r.push({
|
|
32
32
|
validator: (value) => {
|
|
33
|
-
if (required || value
|
|
33
|
+
if (required || value?.length > 0) {
|
|
34
34
|
return isValidPhoneNumber(value);
|
|
35
35
|
}
|
|
36
36
|
return true;
|
package/dist/input/Input.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React, { forwardRef, useImperativeHandle } from 'react';
|
|
2
|
-
import BaseInput from './BaseInput';
|
|
3
|
-
import { useInput } from '../form/hooks/useInput';
|
|
4
2
|
import { useTranslation } from '@weareconceptstudio/core';
|
|
3
|
+
import { useInput } from '../form/hooks/useInput';
|
|
4
|
+
import BaseInput from './BaseInput';
|
|
5
5
|
const Input = forwardRef((props, ref) => {
|
|
6
6
|
useImperativeHandle(ref, () => ({ childType: 'input' }));
|
|
7
|
-
const { name, autoComplete = 'new-password', onChange, onFocus, onBlur, onKeyDown, onKeyUp, disabled, className, type = 'text',
|
|
7
|
+
const { name, autoComplete = 'new-password', onChange, onFocus, onBlur, onKeyDown, onKeyUp, disabled, className, placeholder, type = 'text', uppercase = true } = props;
|
|
8
8
|
const { translate } = useTranslation();
|
|
9
9
|
const { field } = useInput({
|
|
10
10
|
type,
|
|
@@ -12,8 +12,17 @@ const Input = forwardRef((props, ref) => {
|
|
|
12
12
|
onChange,
|
|
13
13
|
onBlur,
|
|
14
14
|
});
|
|
15
|
+
//! On Uppercase
|
|
16
|
+
const inputFirstLatterUppercase = type == 'text' && uppercase
|
|
17
|
+
? (e) => {
|
|
18
|
+
let inputValue = e.target.value.trimStart();
|
|
19
|
+
if (e.target.value.length > 0) {
|
|
20
|
+
e.target.value = inputValue.charAt(0).toUpperCase() + inputValue.slice(1);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
: null;
|
|
15
24
|
return (React.createElement(BaseInput, { ...props, value: field.value, disabled: disabled },
|
|
16
|
-
React.createElement("input", { type: type, onFocus: onFocus, onKeyUp: onKeyUp, disabled: disabled, className: className, onKeyDown: onKeyDown, placeholder: translate(placeholder),
|
|
25
|
+
React.createElement("input", { type: type, onFocus: onFocus, onKeyUp: onKeyUp, disabled: disabled, className: className, onKeyDown: onKeyDown, autoComplete: autoComplete, onInput: inputFirstLatterUppercase, placeholder: translate(placeholder), ...field })));
|
|
17
26
|
});
|
|
18
27
|
if (process.env.NODE_ENV !== 'production') {
|
|
19
28
|
Input.displayName = 'Input';
|
|
@@ -3,25 +3,28 @@ import Input from '../Input';
|
|
|
3
3
|
const Number = (props) => {
|
|
4
4
|
//! Disable number input scroll
|
|
5
5
|
useEffect(() => {
|
|
6
|
-
const
|
|
7
|
-
e.target.
|
|
6
|
+
const handleWheel = (e) => {
|
|
7
|
+
if (e.target.type === 'number') {
|
|
8
|
+
e.target.blur();
|
|
9
|
+
}
|
|
8
10
|
};
|
|
9
11
|
const handleKeyDown = (e) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
if (e.target.type === 'number') {
|
|
13
|
+
const key = e.charCode || e.keyCode;
|
|
14
|
+
//! Prevent arrow keys (38 = Up, 40 = Down)
|
|
15
|
+
if (key === 38 || key === 40) {
|
|
16
|
+
e.preventDefault();
|
|
17
|
+
}
|
|
13
18
|
}
|
|
14
19
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
});
|
|
20
|
+
document.addEventListener('wheel', handleWheel, { passive: false });
|
|
21
|
+
document.addEventListener('mousewheel', handleWheel, { passive: false });
|
|
22
|
+
document.addEventListener('keydown', handleKeyDown);
|
|
23
|
+
//! ✅ Correct cleanup function
|
|
20
24
|
return () => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
});
|
|
25
|
+
document.removeEventListener('wheel', handleWheel);
|
|
26
|
+
document.removeEventListener('mousewheel', handleWheel);
|
|
27
|
+
document.removeEventListener('keydown', handleKeyDown);
|
|
25
28
|
};
|
|
26
29
|
}, []);
|
|
27
30
|
return (React.createElement(Input, { type: 'number', ...props }));
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React, { forwardRef, useImperativeHandle } from 'react';
|
|
2
|
-
import BaseInput from '../BaseInput';
|
|
3
|
-
import { useInput } from '../../form/hooks/useInput';
|
|
4
2
|
import { useTranslation } from '@weareconceptstudio/core';
|
|
5
|
-
|
|
3
|
+
import { useInput } from '../../form/hooks/useInput';
|
|
4
|
+
import BaseInput from '../BaseInput';
|
|
5
|
+
const TextArea = forwardRef(({ uppercase = true, ...props }, ref) => {
|
|
6
6
|
useImperativeHandle(ref, () => ({ childType: 'textarea' }));
|
|
7
7
|
const { translate } = useTranslation();
|
|
8
8
|
const { name, placeholder, rows = 5, onChange, onFocus, onBlur, onKeyDown, onKeyUp, disabled, className, autoComplete } = props;
|
|
@@ -11,8 +11,17 @@ const TextArea = forwardRef((props, ref) => {
|
|
|
11
11
|
onChange: onChange,
|
|
12
12
|
onBlur: onBlur,
|
|
13
13
|
};
|
|
14
|
+
//! On Uppercase
|
|
15
|
+
const inputFirstLatterUppercase = uppercase
|
|
16
|
+
? (e) => {
|
|
17
|
+
let inputValue = e.target.value.trimStart();
|
|
18
|
+
if (e.target.value.length > 0) {
|
|
19
|
+
e.target.value = inputValue.charAt(0).toUpperCase() + inputValue.slice(1);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
: null;
|
|
14
23
|
return (React.createElement(BaseInput, { ...props },
|
|
15
|
-
React.createElement("textarea", { ...field, rows: rows, onFocus: onFocus, onKeyUp: onKeyUp, disabled: disabled, className: className, onKeyDown: onKeyDown, autoComplete: autoComplete, placeholder: translate(placeholder) })));
|
|
24
|
+
React.createElement("textarea", { ...field, rows: rows, onFocus: onFocus, onKeyUp: onKeyUp, disabled: disabled, className: className, onKeyDown: onKeyDown, autoComplete: autoComplete, onInput: inputFirstLatterUppercase, placeholder: translate(placeholder) })));
|
|
16
25
|
});
|
|
17
26
|
if (process.env.NODE_ENV !== 'production') {
|
|
18
27
|
TextArea.displayName = 'TextArea';
|
|
@@ -26,9 +26,10 @@ const PhoneNumber = forwardRef(({ name, className, autoComplete = 'new-password'
|
|
|
26
26
|
return (React.createElement(PhoneInput, { name: name, international: true, value: value, country: country, maxLength: maxLength, withCountryCallingCode: true, className: classString, autoComplete: autoComplete, onChange: (value) => {
|
|
27
27
|
onChange({ value: value || '' });
|
|
28
28
|
setValue(name, value || '');
|
|
29
|
-
trigger(name);
|
|
29
|
+
control._options.mode == 'onChange' && trigger(name);
|
|
30
30
|
}, onBlur: () => {
|
|
31
31
|
onBlur();
|
|
32
|
+
control._options.mode == 'onBlur' && trigger(name);
|
|
32
33
|
}, ...options }));
|
|
33
34
|
} }));
|
|
34
35
|
});
|
package/dist/styles/formStyle.js
CHANGED
|
@@ -46,11 +46,11 @@ const FormStyle = createGlobalStyle `${css `
|
|
|
46
46
|
input[type='search']::-webkit-search-cancel-button,
|
|
47
47
|
input[type='search']::-webkit-search-results-button,
|
|
48
48
|
input[type='search']::-webkit-search-results-decoration {
|
|
49
|
-
-webkit-appearance: none;
|
|
49
|
+
-webkit-appearance: none !important;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
input[type='number'] {
|
|
53
|
-
-moz-appearance: textfield;
|
|
53
|
+
-moz-appearance: textfield !important;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
input:focus::placeholder {
|