@weareconceptstudio/form 0.2.6 → 0.2.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.
@@ -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', placeholder } = props;
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' && (name == 'first_name' || name == 'firstName' || name == 'last_name' || name == 'lastName' || name == 'name') && 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), autoComplete: autoComplete, ...field })));
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 handleMouseWheel = (e) => {
7
- e.target.blur();
6
+ const handleWheel = (e) => {
7
+ if (e.target.type === 'number') {
8
+ e.target.blur();
9
+ }
8
10
  };
9
11
  const handleKeyDown = (e) => {
10
- const key = e.charCode || e.keyCode;
11
- if (key === 38 || key === 40) {
12
- e.preventDefault();
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
- const numberInputs = document.querySelectorAll('input[type="number"]');
16
- numberInputs.forEach((input) => {
17
- input.addEventListener('mousewheel', handleMouseWheel);
18
- input.addEventListener('keydown', handleKeyDown);
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
- numberInputs.forEach((input) => {
22
- input.removeEventListener('mousewheel', handleMouseWheel);
23
- input.removeEventListener('keydown', handleKeyDown);
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
- const TextArea = forwardRef((props, ref) => {
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';
@@ -24,12 +24,13 @@ const PhoneNumber = forwardRef(({ name, className, autoComplete = 'new-password'
24
24
  }, [name, getValues, setValue, country]);
25
25
  return (React.createElement(Controller, { name: name, control: control, render: ({ field: { onChange, value, onBlur } }) => {
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
- onChange({ value: value || '' });
27
+ onChange(value || '');
28
28
  setValue(name, value || '');
29
- control._options.mode == 'onChange' && trigger(name);
29
+ // control._options.mode == 'onChange' && trigger(name);
30
+ trigger(name);
30
31
  }, onBlur: () => {
31
32
  onBlur();
32
- control._options.mode == 'onBlur' && trigger(name);
33
+ // control._options.mode == 'onBlur' && trigger(name);
33
34
  }, ...options }));
34
35
  } }));
35
36
  });
@@ -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 {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weareconceptstudio/form",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "description": "Concept Studio Form",
5
5
  "author": "Concept Studio",
6
6
  "license": "ISC",