forstok-ui-lib 5.11.11 → 5.11.13
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.d.ts +3 -2
- package/dist/index.js +17 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +17 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/assets/images/icons/back.svg +9 -0
- package/src/components/icon/styles.ts +8 -0
- package/src/components/input/otp.tsx +62 -0
- package/src/components/input/styles.ts +16 -0
- package/src/typeds/base.typed.ts +2 -1
package/package.json
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 22.989 16.009" style="enable-background:new 0 0 22.989 16.009; fill: rgb(72,72,72);" xml:space="preserve">
|
|
2
|
+
<g>
|
|
3
|
+
<path style="fill-rule:evenodd;clip-rule:evenodd;" d="M21.989,7.004H3.393l5.309-5.309c0.388-0.388,0.388-1.017,0-1.404
|
|
4
|
+
c-0.388-0.388-1.017-0.388-1.404,0L0.342,7.247C0.321,7.264,0.295,7.271,0.275,7.291C0.047,7.519-0.03,7.829,0.01,8.127
|
|
5
|
+
c0.005,0.049,0.014,0.091,0.027,0.139C0.073,8.39,0.133,8.505,0.219,8.61c0.026,0.033,0.026,0.077,0.057,0.108
|
|
6
|
+
c0.019,0.019,0.044,0.025,0.064,0.041l6.958,6.959c0.388,0.388,1.017,0.388,1.404,0c0.388-0.388,0.388-1.017,0-1.404L3.393,9.004
|
|
7
|
+
h18.595c0.552,0,1-0.448,1-1C22.989,7.452,22.541,7.004,21.989,7.004z"></path>
|
|
8
|
+
</g>
|
|
9
|
+
</svg>
|
|
@@ -3,6 +3,7 @@ import styled, { css } from 'styled-components';
|
|
|
3
3
|
import IconPerson from '../../assets/images/icons/person.svg';
|
|
4
4
|
import IconPersonRed from '../../assets/images/icons/person-red.svg';
|
|
5
5
|
import IconCart from '../../assets/images/icons/cart.svg';
|
|
6
|
+
import IconBack from '../../assets/images/icons/back.svg';
|
|
6
7
|
|
|
7
8
|
const NotificationStyled = css`
|
|
8
9
|
width: 44px;
|
|
@@ -267,6 +268,13 @@ const getIconContainerStyled = ({ $mode, $name, $width, onClick }:{ $mode?: stri
|
|
|
267
268
|
content: url(${IconCart});
|
|
268
269
|
}`
|
|
269
270
|
break;
|
|
271
|
+
case 'back':
|
|
272
|
+
style += `
|
|
273
|
+
&:before {
|
|
274
|
+
content: url(${IconBack});
|
|
275
|
+
}
|
|
276
|
+
`
|
|
277
|
+
break;
|
|
270
278
|
default:
|
|
271
279
|
break;
|
|
272
280
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { InputOtpContainer } from './styles';
|
|
2
|
+
import { TChangeEvent, TKeyboadEvent, TPasteEvent, TState } from '../../typeds';
|
|
3
|
+
|
|
4
|
+
const InputOTPComponent = ({ otpLength = 6, value, onChange, ...props }: {otpLength: number, value: string, onChange: TState<string>}) => {
|
|
5
|
+
|
|
6
|
+
const handleChange: TChangeEvent = (e) => {
|
|
7
|
+
const target = e.target as HTMLInputElement;
|
|
8
|
+
const inputValue = target.value;
|
|
9
|
+
const inputIndex = target.dataset.index ? parseInt(target.dataset.index) : 0;
|
|
10
|
+
if (inputValue === '' || /^\d$/.test(inputValue)) {
|
|
11
|
+
let updatedValue = value.split('');
|
|
12
|
+
updatedValue[inputIndex] = inputValue;
|
|
13
|
+
const newOtpValue = updatedValue.join('');
|
|
14
|
+
onChange(newOtpValue);
|
|
15
|
+
if (inputValue !== '' && inputIndex < otpLength - 1) {
|
|
16
|
+
(document.getElementById(`otp-inputbox-${inputIndex + 1}`) as HTMLInputElement)?.focus();
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const handleKeyDown: TKeyboadEvent = (e) => {
|
|
22
|
+
const target = e.target as HTMLInputElement;
|
|
23
|
+
const inputIndex = target.dataset.index ? parseInt(target.dataset.index) : 0;
|
|
24
|
+
if (e.key === 'Backspace' && !value[inputIndex] && inputIndex > 0) {
|
|
25
|
+
(document.getElementById(`otp-inputbox-${inputIndex - 1}`) as HTMLInputElement)?.focus();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const handlePaste: TPasteEvent<HTMLDivElement> = (e) => {
|
|
30
|
+
e.preventDefault();
|
|
31
|
+
const pastedValue = e.clipboardData.getData('Text').replace(/\D/g, '').slice(0, otpLength);
|
|
32
|
+
onChange(pastedValue);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let inputEls = [];
|
|
36
|
+
for (let i = 0; i < otpLength; i++) {
|
|
37
|
+
inputEls.push(
|
|
38
|
+
<InputOtpContainer
|
|
39
|
+
key={i}
|
|
40
|
+
data-index={i}
|
|
41
|
+
id={`otp-inputbox-${i}`}
|
|
42
|
+
name={`otp-input-${i}`}
|
|
43
|
+
autoComplete='one-time-code'
|
|
44
|
+
inputMode='numeric'
|
|
45
|
+
required
|
|
46
|
+
value={value[i] || ''}
|
|
47
|
+
onChange={(e) => handleChange(e)}
|
|
48
|
+
onKeyDown={(e) => handleKeyDown(e)}
|
|
49
|
+
onFocus={(e) => {e.target.addEventListener('wheel', function (e) { e.preventDefault() }, { passive: false }); e.target.select()}}
|
|
50
|
+
{...props}
|
|
51
|
+
/>
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<div onPaste={handlePaste}>
|
|
57
|
+
{inputEls}
|
|
58
|
+
</div>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export default InputOTPComponent;
|
|
@@ -89,4 +89,20 @@ export const InputLabel = styled.label`
|
|
|
89
89
|
top: 50%;
|
|
90
90
|
transform: translateY(-50%);
|
|
91
91
|
color: var(--mt-clr);
|
|
92
|
+
`
|
|
93
|
+
export const InputOtpContainer = styled.input`
|
|
94
|
+
text-align: center;
|
|
95
|
+
height: 40px;
|
|
96
|
+
width: 38px;
|
|
97
|
+
font-size: 20px;
|
|
98
|
+
margin-right: 5px;
|
|
99
|
+
&:last-child {
|
|
100
|
+
margin-right: 0;
|
|
101
|
+
}
|
|
102
|
+
@media only screen and (min-width: 768px) {
|
|
103
|
+
height: 55px;
|
|
104
|
+
width: 45px;
|
|
105
|
+
font-size: 28px;
|
|
106
|
+
margin-right: 16px;
|
|
107
|
+
}
|
|
92
108
|
`
|
package/src/typeds/base.typed.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { MouseEvent, ChangeEvent, DragEvent, Dispatch, SetStateAction, KeyboardEvent, FocusEvent } from 'react';
|
|
1
|
+
import type { MouseEvent, ChangeEvent, DragEvent, Dispatch, SetStateAction, KeyboardEvent, FocusEvent, ClipboardEvent } from 'react';
|
|
2
2
|
|
|
3
3
|
type RemoveUnderscoreFirstLetter<S extends string> =
|
|
4
4
|
S extends `${infer FirstLetter}${infer U}`
|
|
@@ -24,6 +24,7 @@ export type TChangeEvent = (e: ChangeEvent) => void;
|
|
|
24
24
|
export type TDragEvent = (e:DragEvent) => void;
|
|
25
25
|
export type TEnterEvent = (e:KeyboardEvent<HTMLInputElement | HTMLElement> | FocusEvent<HTMLInputElement | HTMLElement | Element> | MouseEvent<HTMLElement>) => void;
|
|
26
26
|
export type TKeyboadEvent = (e: KeyboardEvent<HTMLInputElement>) => void;
|
|
27
|
+
export type TPasteEvent<T> = (e:ClipboardEvent<T>) => void;
|
|
27
28
|
export type TPage = {
|
|
28
29
|
totalCount: number
|
|
29
30
|
totalPageCount: number
|