@ainias42/react-bootstrap-mobile 0.1.29 → 0.1.31
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/bootstrapReactMobile.js +67 -19
- package/dist/bootstrapReactMobile.js.map +1 -1
- package/dist/src/Components/FormElements/Input/Input.d.ts +2 -10
- package/package.json +1 -1
- package/src/Components/FormElements/Input/Input.tsx +77 -50
- package/src/Components/Toast/Toast.tsx +3 -1
- package/src/Components/Toast/toast.scss +2 -0
|
@@ -2,18 +2,10 @@ import { InputHTMLAttributes } from 'react';
|
|
|
2
2
|
import { RbmComponentProps } from '../../RbmComponentProps';
|
|
3
3
|
import { Override } from '../../../TypeHelpers';
|
|
4
4
|
import { OptionalListener } from '../../Hooks/useListener';
|
|
5
|
-
type
|
|
6
|
-
export type InputProps<OnChangeData, OnBlurData, OnChangeDoneData> = RbmComponentProps<Override<Omit<InputHTMLAttributes<HTMLInputElement>, 'onInput' | "type">, {
|
|
5
|
+
export type InputProps<OnChangeData, OnBlurData, OnChangeDoneData> = RbmComponentProps<Override<Omit<InputHTMLAttributes<HTMLInputElement>, 'onInput'>, {
|
|
7
6
|
label?: string;
|
|
8
7
|
inline?: boolean;
|
|
9
|
-
} & OptionalListener<'onChange', OnChangeData> & OptionalListener<'onBlur', OnBlurData> & OptionalListener<'onChangeDone', OnChangeDoneData> & ({
|
|
10
|
-
type?: InputTypes;
|
|
11
8
|
onChangeText?: (newText: string) => void;
|
|
12
9
|
onEnter?: (newText: string) => void;
|
|
13
|
-
}
|
|
14
|
-
type: "number";
|
|
15
|
-
onChangeText?: (newNumber: number) => void;
|
|
16
|
-
onEnter?: (newNumber: number) => void;
|
|
17
|
-
})>>;
|
|
10
|
+
} & OptionalListener<'onChange', OnChangeData> & OptionalListener<'onBlur', OnBlurData> & OptionalListener<'onChangeDone', OnChangeDoneData>>>;
|
|
18
11
|
export declare const Input: import("../../../helper/withForwardRef").RefComponent<InputProps<unknown, unknown, unknown>, HTMLInputElement>;
|
|
19
|
-
export {};
|
package/package.json
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
ChangeEvent,
|
|
4
|
+
ChangeEventHandler,
|
|
5
|
+
InputHTMLAttributes,
|
|
6
|
+
KeyboardEvent, KeyboardEventHandler,
|
|
7
|
+
MutableRefObject,
|
|
8
|
+
useCallback, useMemo,
|
|
9
|
+
useRef,
|
|
10
|
+
useState
|
|
11
|
+
} from 'react';
|
|
3
12
|
import { RbmComponentProps } from '../../RbmComponentProps';
|
|
4
13
|
import { Override } from '../../../TypeHelpers';
|
|
5
14
|
import { OptionalListener, useListenerWithExtractedProps } from '../../Hooks/useListener';
|
|
@@ -10,47 +19,17 @@ import classNames from 'classnames';
|
|
|
10
19
|
import { useComposedRef } from '../../Hooks/useComposedRef';
|
|
11
20
|
import { useOnChangeDone } from '../hooks/useOnChangeDone';
|
|
12
21
|
|
|
13
|
-
type InputTypes =
|
|
14
|
-
| 'button'
|
|
15
|
-
| 'checkbox'
|
|
16
|
-
| 'color'
|
|
17
|
-
| 'date'
|
|
18
|
-
| 'datetime-local'
|
|
19
|
-
| 'email'
|
|
20
|
-
| 'file'
|
|
21
|
-
| 'hidden'
|
|
22
|
-
| 'image'
|
|
23
|
-
| 'month'
|
|
24
|
-
| 'password'
|
|
25
|
-
| 'radio'
|
|
26
|
-
| 'range'
|
|
27
|
-
| 'reset'
|
|
28
|
-
| 'search'
|
|
29
|
-
| 'submit'
|
|
30
|
-
| 'tel'
|
|
31
|
-
| 'text'
|
|
32
|
-
| 'time'
|
|
33
|
-
| 'url'
|
|
34
|
-
| 'week';
|
|
35
|
-
|
|
36
22
|
export type InputProps<OnChangeData, OnBlurData, OnChangeDoneData> = RbmComponentProps<
|
|
37
23
|
Override<
|
|
38
|
-
Omit<InputHTMLAttributes<HTMLInputElement>, 'onInput'
|
|
24
|
+
Omit<InputHTMLAttributes<HTMLInputElement>, 'onInput'>,
|
|
39
25
|
{
|
|
40
26
|
label?: string;
|
|
41
|
-
inline?: boolean
|
|
27
|
+
inline?: boolean;
|
|
28
|
+
onChangeText?: (newText: string) => void;
|
|
29
|
+
onEnter?: (newText: string) => void;
|
|
42
30
|
} & OptionalListener<'onChange', OnChangeData> &
|
|
43
31
|
OptionalListener<'onBlur', OnBlurData> &
|
|
44
32
|
OptionalListener<'onChangeDone', OnChangeDoneData>
|
|
45
|
-
& ({
|
|
46
|
-
type?: InputTypes
|
|
47
|
-
onChangeText?: (newText: string) => void;
|
|
48
|
-
onEnter?: (newText: string) => void;
|
|
49
|
-
} | {
|
|
50
|
-
type: "number"
|
|
51
|
-
onChangeText?: (newNumber: number) => void;
|
|
52
|
-
onEnter?: (newNumber: number) => void;
|
|
53
|
-
})
|
|
54
33
|
>
|
|
55
34
|
>;
|
|
56
35
|
|
|
@@ -61,6 +40,7 @@ export const Input = withForwardRef(function Input<OnChangeData, OnBlurData, OnC
|
|
|
61
40
|
style,
|
|
62
41
|
onKeyDown,
|
|
63
42
|
inline = false,
|
|
43
|
+
value,
|
|
64
44
|
...otherProps
|
|
65
45
|
}: InputProps<OnChangeData, OnBlurData, OnChangeDoneData>,
|
|
66
46
|
ref: MutableRefObject<HTMLInputElement> | null
|
|
@@ -68,28 +48,56 @@ export const Input = withForwardRef(function Input<OnChangeData, OnBlurData, OnC
|
|
|
68
48
|
// Variables
|
|
69
49
|
|
|
70
50
|
// States
|
|
51
|
+
const usedValue = useMemo(() => {
|
|
52
|
+
if (otherProps.type !== "number" || typeof value === "number") {
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
55
|
+
if (typeof value === "string") {
|
|
56
|
+
if (value === "-"){
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const numberValue = parseFloat(value);
|
|
61
|
+
if (!Number.isNaN(numberValue) && Number.isFinite(numberValue)) {
|
|
62
|
+
if (otherProps.max !== undefined && numberValue > Number(otherProps.max)) {
|
|
63
|
+
return otherProps.max;
|
|
64
|
+
}
|
|
65
|
+
if (otherProps.min !== undefined && numberValue < Number(otherProps.min)) {
|
|
66
|
+
return otherProps.min;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
71
69
|
|
|
70
|
+
if (!Number.isNaN(Number(value))) {
|
|
71
|
+
// Do not parse to allow ., and so on
|
|
72
|
+
return value;
|
|
73
|
+
}
|
|
74
|
+
if (!Number.isNaN(numberValue)) {
|
|
75
|
+
return parseFloat(value);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return "";
|
|
79
|
+
}, [value])
|
|
72
80
|
// Refs
|
|
73
81
|
const innerRef = useComposedRef(ref);
|
|
74
|
-
const lastValueRef = useRef(NaN);
|
|
75
82
|
|
|
76
83
|
// Callbacks
|
|
77
84
|
const [onChangeWithData, otherPropsWithoutOnchange] = useListenerWithExtractedProps<'onChange', OnChangeData>(
|
|
78
85
|
'onChange',
|
|
79
86
|
otherProps
|
|
80
87
|
);
|
|
81
|
-
const onChange = useCallback
|
|
82
|
-
(e) => {
|
|
88
|
+
const onChange = useCallback(
|
|
89
|
+
(e: ChangeEvent<HTMLInputElement>|KeyboardEvent<HTMLInputElement>) => {
|
|
83
90
|
if (otherProps.onChangeText) {
|
|
84
91
|
if (otherProps.type === "number") {
|
|
85
|
-
if (
|
|
86
|
-
otherProps.onChangeText(
|
|
87
|
-
|
|
88
|
-
otherProps.onChangeText(e.target.valueAsNumber);
|
|
89
|
-
lastValueRef.current = e.target.valueAsNumber;
|
|
92
|
+
if (e.currentTarget.value === "-") {
|
|
93
|
+
otherProps.onChangeText(e.currentTarget.value);
|
|
94
|
+
return;
|
|
90
95
|
}
|
|
96
|
+
|
|
97
|
+
const val = !Number.isNaN(Number(e.currentTarget.value)) ? e.currentTarget.value : !Number.isNaN(parseFloat(e.currentTarget.value)) ? String(parseFloat(e.currentTarget.value)) : "";
|
|
98
|
+
otherProps.onChangeText(val);
|
|
91
99
|
} else {
|
|
92
|
-
otherProps.onChangeText(e.
|
|
100
|
+
otherProps.onChangeText(e.currentTarget.value);
|
|
93
101
|
}
|
|
94
102
|
}
|
|
95
103
|
onChangeWithData(e);
|
|
@@ -112,16 +120,32 @@ export const Input = withForwardRef(function Input<OnChangeData, OnBlurData, OnC
|
|
|
112
120
|
onKeyDown?.(e);
|
|
113
121
|
if (otherProps.onEnter && e.key === 'Enter' && !e.defaultPrevented) {
|
|
114
122
|
if (otherProps.type === "number") {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
otherProps.onEnter((e.target as HTMLInputElement).valueAsNumber);
|
|
119
|
-
lastValueRef.current = (e.target as HTMLInputElement).valueAsNumber;
|
|
120
|
-
}
|
|
123
|
+
const stringValue = (e.target as HTMLInputElement).value;
|
|
124
|
+
const val = !Number.isNaN(Number(stringValue)) ? stringValue : !Number.isNaN(parseFloat(stringValue)) ? String(parseFloat(stringValue)) : "";
|
|
125
|
+
otherProps.onEnter(val)
|
|
121
126
|
} else {
|
|
122
127
|
otherProps.onEnter((e.target as HTMLInputElement).value);
|
|
123
128
|
}
|
|
129
|
+
}
|
|
124
130
|
|
|
131
|
+
if (otherProps.type === "number") {
|
|
132
|
+
const step = otherProps.step ? Number(otherProps.step) : 1;
|
|
133
|
+
if (e.key === "ArrowUp"){
|
|
134
|
+
let newValue = (parseFloat(e.currentTarget.value) || 0) + step;
|
|
135
|
+
if (otherProps.max !== undefined && newValue > Number(otherProps.max)) {
|
|
136
|
+
newValue = Number(otherProps.max);
|
|
137
|
+
}
|
|
138
|
+
e.currentTarget.value = newValue.toString();
|
|
139
|
+
onChange(e);
|
|
140
|
+
}
|
|
141
|
+
else if (e.key === "ArrowDown"){
|
|
142
|
+
let newValue = (parseFloat(e.currentTarget.value) || 0) - step;
|
|
143
|
+
if (otherProps.min !== undefined && newValue < Number(otherProps.min)) {
|
|
144
|
+
newValue = Number(otherProps.min);
|
|
145
|
+
}
|
|
146
|
+
e.currentTarget.value = newValue.toString();
|
|
147
|
+
onChange(e);
|
|
148
|
+
}
|
|
125
149
|
}
|
|
126
150
|
},
|
|
127
151
|
[otherProps.onEnter, onKeyDown, otherProps.type]
|
|
@@ -139,7 +163,10 @@ export const Input = withForwardRef(function Input<OnChangeData, OnBlurData, OnC
|
|
|
139
163
|
<label className={classNames(styles.input, {[styles.inline]: inline}, className)} style={style}>
|
|
140
164
|
{label ? <span className={styles.label}>{label}</span> : null}
|
|
141
165
|
<input
|
|
166
|
+
inputMode={otherProps.type === "number" ? "numeric" : undefined}
|
|
142
167
|
{...otherPropsWithoutData}
|
|
168
|
+
value={usedValue}
|
|
169
|
+
type={otherProps.type === "number" ? "text" : otherProps.type}
|
|
143
170
|
ref={innerRef}
|
|
144
171
|
className={styles.text}
|
|
145
172
|
onBlur={onBlur}
|
|
@@ -34,13 +34,14 @@ function Toast<ActionData, DismissedData>({
|
|
|
34
34
|
// States
|
|
35
35
|
const [hidingStart, setHidingStart] = useState<number>(0);
|
|
36
36
|
const [startShow] = useState(new Date().getTime());
|
|
37
|
-
const isHidden =
|
|
37
|
+
const [isHidden, setIsHidden] = useState<boolean>(false);
|
|
38
38
|
|
|
39
39
|
// Refs
|
|
40
40
|
|
|
41
41
|
// Callbacks
|
|
42
42
|
const updateHidingStart = useCallback(() => {
|
|
43
43
|
setHidingStart((oldHidingStart) => (oldHidingStart > 0 ? oldHidingStart : new Date().getTime()));
|
|
44
|
+
setTimeout(() => setIsHidden(true), ANIMATION_DURATION);
|
|
44
45
|
}, [setHidingStart]);
|
|
45
46
|
|
|
46
47
|
const onDismissed = useListener('onDismissed', otherProps);
|
|
@@ -78,6 +79,7 @@ function Toast<ActionData, DismissedData>({
|
|
|
78
79
|
|
|
79
80
|
// Render Functions
|
|
80
81
|
if (isHidden) {
|
|
82
|
+
console.log("LOG-d isHidden");
|
|
81
83
|
return null;
|
|
82
84
|
}
|
|
83
85
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
@import "../../scss/designMixin";
|
|
3
3
|
|
|
4
4
|
.toastContainer {
|
|
5
|
+
pointer-events: none;
|
|
5
6
|
position: fixed;
|
|
6
7
|
left: 0;
|
|
7
8
|
right: 0;
|
|
@@ -15,6 +16,7 @@
|
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
.toast {
|
|
19
|
+
pointer-events: auto;
|
|
18
20
|
background-color: rgba(0, 0, 0, 0.8);
|
|
19
21
|
min-height: 48px;
|
|
20
22
|
line-height: 1.5;
|