@arcblock/ux 2.13.35 → 2.13.36

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.
@@ -0,0 +1,9 @@
1
+ import type { SxProps } from '@mui/material';
2
+ export declare const VERIFY_CODE_LENGTH = 6;
3
+ export default function VerificationCode({ length, code, onChange, onComplete, sx, }: {
4
+ length?: number;
5
+ code: string;
6
+ onChange?: (_code: string) => void;
7
+ onComplete?: (_code: string) => void;
8
+ sx?: SxProps;
9
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,67 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useEffect } from 'react';
3
+ import { Box, TextField } from '@mui/material';
4
+ import trim from 'lodash/trim';
5
+ import noop from 'lodash/noop';
6
+ import { mergeSx } from '../Util/style';
7
+ export const VERIFY_CODE_LENGTH = 6;
8
+ export default function VerificationCode({
9
+ length = VERIFY_CODE_LENGTH,
10
+ code,
11
+ onChange = noop,
12
+ onComplete = noop,
13
+ sx
14
+ }) {
15
+ useEffect(() => {
16
+ if (code.length === length) {
17
+ onComplete?.(code);
18
+ }
19
+ // eslint-disable-next-line react-hooks/exhaustive-deps
20
+ }, [code, length]);
21
+ return /*#__PURE__*/_jsx(Box, {
22
+ sx: mergeSx({
23
+ width: '100%',
24
+ maxWidth: 360,
25
+ display: 'flex',
26
+ justifyContent: 'space-between',
27
+ gap: 1.5
28
+ }, sx),
29
+ children: [...Array(length)].map((_, index) => /*#__PURE__*/_jsx(TextField, {
30
+ id: `code-input-${index}`
31
+ // eslint-disable-next-line react/no-array-index-key
32
+ ,
33
+
34
+ value: trim(code[index]) || '',
35
+ type: "number",
36
+ inputProps: {
37
+ maxLength: 1,
38
+ sx: {
39
+ textAlign: 'center',
40
+ fontSize: '1.5rem',
41
+ '&::-webkit-inner-spin-button, &::-webkit-outer-spin-button': {
42
+ WebkitAppearance: 'none',
43
+ margin: 0
44
+ }
45
+ },
46
+ autoComplete: 'off',
47
+ pattern: '[0-9]',
48
+ inputMode: 'numeric'
49
+ },
50
+ onChange: e => {
51
+ const newCode = code.split('');
52
+ newCode[index] = e.target.value;
53
+ onChange?.(newCode.join(''));
54
+ if (e.target.value && index < 5) {
55
+ document.getElementById(`code-input-${index + 1}`)?.focus();
56
+ }
57
+ },
58
+ onKeyDown: e => {
59
+ if (e.key === 'Backspace' && !trim(code[index]) && index > 0) {
60
+ document.getElementById(`code-input-${index - 1}`)?.focus();
61
+ }
62
+ },
63
+ required: true,
64
+ autoComplete: "off"
65
+ }, `code-input-${index}`))
66
+ });
67
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcblock/ux",
3
- "version": "2.13.35",
3
+ "version": "2.13.36",
4
4
  "description": "Common used react components for arcblock products",
5
5
  "keywords": [
6
6
  "react",
@@ -71,14 +71,14 @@
71
71
  "react": ">=18.2.0",
72
72
  "react-router-dom": ">=6.22.3"
73
73
  },
74
- "gitHead": "0637c76e4c1036802b2fef273f785cc9bf00edd0",
74
+ "gitHead": "9df953c70b6808afe748ea91d58bb1b3e7acc066",
75
75
  "dependencies": {
76
76
  "@arcblock/did-motif": "^1.1.13",
77
- "@arcblock/icons": "^2.13.35",
78
- "@arcblock/nft-display": "^2.13.35",
79
- "@arcblock/react-hooks": "^2.13.35",
77
+ "@arcblock/icons": "^2.13.36",
78
+ "@arcblock/nft-display": "^2.13.36",
79
+ "@arcblock/react-hooks": "^2.13.36",
80
80
  "@babel/plugin-syntax-dynamic-import": "^7.8.3",
81
- "@blocklet/theme": "^2.13.35",
81
+ "@blocklet/theme": "^2.13.36",
82
82
  "@fontsource/roboto": "~5.1.1",
83
83
  "@fontsource/ubuntu-mono": "^5.0.18",
84
84
  "@iconify-icons/logos": "^1.2.36",
@@ -0,0 +1,81 @@
1
+ import { useEffect } from 'react';
2
+ import { Box, TextField } from '@mui/material';
3
+ import type { SxProps } from '@mui/material';
4
+ import trim from 'lodash/trim';
5
+ import noop from 'lodash/noop';
6
+ import { mergeSx } from '../Util/style';
7
+
8
+ export const VERIFY_CODE_LENGTH = 6;
9
+
10
+ export default function VerificationCode({
11
+ length = VERIFY_CODE_LENGTH,
12
+ code,
13
+ onChange = noop,
14
+ onComplete = noop,
15
+ sx,
16
+ }: {
17
+ length?: number;
18
+ code: string;
19
+ onChange?: (_code: string) => void;
20
+ onComplete?: (_code: string) => void;
21
+ sx?: SxProps;
22
+ }) {
23
+ useEffect(() => {
24
+ if (code.length === length) {
25
+ onComplete?.(code);
26
+ }
27
+ // eslint-disable-next-line react-hooks/exhaustive-deps
28
+ }, [code, length]);
29
+ return (
30
+ <Box
31
+ sx={mergeSx(
32
+ {
33
+ width: '100%',
34
+ maxWidth: 360,
35
+ display: 'flex',
36
+ justifyContent: 'space-between',
37
+ gap: 1.5,
38
+ },
39
+ sx
40
+ )}>
41
+ {[...Array(length)].map((_, index) => (
42
+ <TextField
43
+ id={`code-input-${index}`}
44
+ // eslint-disable-next-line react/no-array-index-key
45
+ key={`code-input-${index}`}
46
+ value={trim(code[index]) || ''}
47
+ type="number"
48
+ inputProps={{
49
+ maxLength: 1,
50
+ sx: {
51
+ textAlign: 'center',
52
+ fontSize: '1.5rem',
53
+ '&::-webkit-inner-spin-button, &::-webkit-outer-spin-button': {
54
+ WebkitAppearance: 'none',
55
+ margin: 0,
56
+ },
57
+ },
58
+ autoComplete: 'off',
59
+ pattern: '[0-9]',
60
+ inputMode: 'numeric',
61
+ }}
62
+ onChange={(e) => {
63
+ const newCode = code.split('');
64
+ newCode[index] = e.target.value;
65
+ onChange?.(newCode.join(''));
66
+ if (e.target.value && index < 5) {
67
+ document.getElementById(`code-input-${index + 1}`)?.focus();
68
+ }
69
+ }}
70
+ onKeyDown={(e) => {
71
+ if (e.key === 'Backspace' && !trim(code[index]) && index > 0) {
72
+ document.getElementById(`code-input-${index - 1}`)?.focus();
73
+ }
74
+ }}
75
+ required
76
+ autoComplete="off"
77
+ />
78
+ ))}
79
+ </Box>
80
+ );
81
+ }