antd-mobile 5.17.2 → 5.20.0
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/2x/bundle/antd-mobile.cjs.js +47 -19174
- package/2x/bundle/antd-mobile.compatible.umd.js +25815 -0
- package/2x/bundle/antd-mobile.es.js +16532 -17127
- package/2x/bundle/antd-mobile.umd.js +64 -0
- package/2x/bundle/style.css +237 -273
- package/2x/cjs/components/action-sheet/action-sheet.d.ts +1 -1
- package/2x/cjs/components/button/button.js +1 -1
- package/2x/cjs/components/calendar/calendar.d.ts +3 -3
- package/2x/cjs/components/calendar/index.d.ts +1 -1
- package/2x/cjs/components/cascader/cascader.d.ts +2 -0
- package/2x/cjs/components/cascader/index.d.ts +1 -0
- package/2x/cjs/components/cascader-view/cascader-view.d.ts +2 -1
- package/2x/cjs/components/cascader-view/cascader-view.js +2 -1
- package/2x/cjs/components/dialog/show.d.ts +1 -1
- package/2x/cjs/components/form/context.d.ts +1 -1
- package/2x/cjs/components/form/form-item.js +9 -4
- package/2x/cjs/components/image/test/image.test.js +57 -8
- package/2x/cjs/components/image-viewer/slide.js +75 -56
- package/2x/cjs/components/input/input.js +9 -2
- package/2x/cjs/components/modal/show.d.ts +1 -1
- package/2x/cjs/components/notice-bar/notice-bar.css +9 -0
- package/2x/cjs/components/notice-bar/notice-bar.js +5 -3
- package/2x/cjs/components/number-keyboard/number-keyboard.css +11 -15
- package/2x/cjs/components/number-keyboard/number-keyboard.d.ts +1 -1
- package/2x/cjs/components/number-keyboard/number-keyboard.js +19 -17
- package/2x/cjs/components/passcode-input/index.d.ts +1 -1
- package/2x/cjs/components/passcode-input/passcode-input.css +12 -12
- package/2x/cjs/components/passcode-input/passcode-input.js +16 -8
- package/2x/cjs/components/rate/rate.css +1 -0
- package/2x/cjs/components/rate/rate.js +38 -5
- package/2x/cjs/components/rate/star.js +0 -10
- package/2x/cjs/components/result/result.d.ts +1 -1
- package/2x/cjs/components/result/result.js +7 -1
- package/2x/cjs/components/search-bar/search-bar.js +12 -2
- package/2x/cjs/components/swipe-action/swipe-action.d.ts +2 -0
- package/2x/cjs/components/swipe-action/swipe-action.js +34 -6
- package/2x/cjs/components/swiper/swiper.js +14 -0
- package/2x/cjs/components/switch/switch.d.ts +2 -1
- package/2x/cjs/components/switch/switch.js +16 -3
- package/2x/cjs/locales/base.d.ts +9 -0
- package/2x/cjs/locales/base.js +9 -0
- package/2x/cjs/locales/en-US.d.ts +9 -0
- package/2x/cjs/locales/es-ES.d.ts +9 -0
- package/2x/cjs/locales/fa-IR.d.ts +9 -0
- package/2x/cjs/locales/fr-FR.d.ts +9 -0
- package/2x/cjs/locales/id-ID.d.ts +9 -0
- package/2x/cjs/locales/id-ID.js +13 -0
- package/2x/cjs/locales/kk-KZ.d.ts +9 -0
- package/2x/cjs/locales/ko-KR.d.ts +9 -0
- package/2x/cjs/locales/zh-CN.d.ts +9 -0
- package/2x/cjs/locales/zh-CN.js +9 -0
- package/2x/cjs/locales/zh-HK.d.ts +9 -0
- package/2x/cjs/locales/zh-TW.d.ts +9 -0
- package/2x/cjs/utils/matrix.d.ts +10 -0
- package/2x/cjs/utils/matrix.js +60 -0
- package/2x/cjs/utils/merge-locale.d.ts +1 -1
- package/2x/cjs/utils/merge-locale.js +15 -5
- package/2x/cjs/utils/use-drag-and-pinch.d.ts +1 -1
- package/2x/cjs/utils/use-props-value.js +1 -1
- package/2x/cjs/utils/use-resize-effect.js +3 -1
- package/2x/cjs/utils/with-default-props.js +2 -6
- package/2x/es/components/action-sheet/action-sheet.d.ts +1 -1
- package/2x/es/components/button/button.js +1 -1
- package/2x/es/components/calendar/calendar.d.ts +3 -3
- package/2x/es/components/calendar/index.d.ts +1 -1
- package/2x/es/components/cascader/cascader.d.ts +2 -0
- package/2x/es/components/cascader/index.d.ts +1 -0
- package/2x/es/components/cascader-view/cascader-view.d.ts +2 -1
- package/2x/es/components/cascader-view/cascader-view.js +2 -1
- package/2x/es/components/dialog/show.d.ts +1 -1
- package/2x/es/components/form/context.d.ts +1 -1
- package/2x/es/components/form/form-item.js +8 -4
- package/2x/es/components/image/test/image.test.js +54 -8
- package/2x/es/components/image-viewer/slide.js +73 -56
- package/2x/es/components/input/input.js +8 -2
- package/2x/es/components/modal/show.d.ts +1 -1
- package/2x/es/components/notice-bar/notice-bar.css +9 -0
- package/2x/es/components/notice-bar/notice-bar.js +5 -3
- package/2x/es/components/number-keyboard/number-keyboard.css +11 -15
- package/2x/es/components/number-keyboard/number-keyboard.d.ts +1 -1
- package/2x/es/components/number-keyboard/number-keyboard.js +19 -17
- package/2x/es/components/passcode-input/index.d.ts +1 -1
- package/2x/es/components/passcode-input/passcode-input.css +12 -12
- package/2x/es/components/passcode-input/passcode-input.js +15 -8
- package/2x/es/components/rate/rate.css +1 -0
- package/2x/es/components/rate/rate.js +32 -5
- package/2x/es/components/rate/star.js +0 -10
- package/2x/es/components/result/result.d.ts +1 -1
- package/2x/es/components/result/result.js +6 -1
- package/2x/es/components/search-bar/search-bar.js +12 -2
- package/2x/es/components/swipe-action/swipe-action.d.ts +2 -0
- package/2x/es/components/swipe-action/swipe-action.js +34 -6
- package/2x/es/components/swiper/swiper.js +14 -0
- package/2x/es/components/switch/switch.d.ts +2 -1
- package/2x/es/components/switch/switch.js +15 -3
- package/2x/es/locales/base.d.ts +9 -0
- package/2x/es/locales/base.js +9 -0
- package/2x/es/locales/en-US.d.ts +9 -0
- package/2x/es/locales/es-ES.d.ts +9 -0
- package/2x/es/locales/fa-IR.d.ts +9 -0
- package/2x/es/locales/fr-FR.d.ts +9 -0
- package/2x/es/locales/id-ID.d.ts +9 -0
- package/2x/es/locales/id-ID.js +13 -0
- package/2x/es/locales/kk-KZ.d.ts +9 -0
- package/2x/es/locales/ko-KR.d.ts +9 -0
- package/2x/es/locales/zh-CN.d.ts +9 -0
- package/2x/es/locales/zh-CN.js +9 -0
- package/2x/es/locales/zh-HK.d.ts +9 -0
- package/2x/es/locales/zh-TW.d.ts +9 -0
- package/2x/es/utils/matrix.d.ts +10 -0
- package/2x/es/utils/matrix.js +27 -0
- package/2x/es/utils/merge-locale.d.ts +1 -1
- package/2x/es/utils/merge-locale.js +17 -3
- package/2x/es/utils/use-drag-and-pinch.d.ts +1 -1
- package/2x/es/utils/use-props-value.js +1 -1
- package/2x/es/utils/use-resize-effect.js +3 -1
- package/2x/es/utils/with-default-props.js +2 -4
- package/2x/package.json +6 -6
- package/2x/umd/antd-mobile.js +25815 -2
- package/bundle/antd-mobile.cjs.js +47 -19174
- package/bundle/antd-mobile.compatible.umd.js +25815 -0
- package/bundle/antd-mobile.es.js +16532 -17127
- package/bundle/antd-mobile.umd.js +64 -0
- package/bundle/style.css +1 -4080
- package/cjs/components/action-sheet/action-sheet.d.ts +1 -1
- package/cjs/components/button/button.js +1 -1
- package/cjs/components/calendar/calendar.d.ts +3 -3
- package/cjs/components/calendar/index.d.ts +1 -1
- package/cjs/components/cascader/cascader.d.ts +2 -0
- package/cjs/components/cascader/index.d.ts +1 -0
- package/cjs/components/cascader-view/cascader-view.d.ts +2 -1
- package/cjs/components/cascader-view/cascader-view.js +2 -1
- package/cjs/components/dialog/show.d.ts +1 -1
- package/cjs/components/form/context.d.ts +1 -1
- package/cjs/components/form/form-item.js +9 -4
- package/cjs/components/image/test/image.test.js +57 -8
- package/cjs/components/image-viewer/slide.js +75 -56
- package/cjs/components/input/input.js +9 -2
- package/cjs/components/modal/show.d.ts +1 -1
- package/cjs/components/notice-bar/notice-bar.css +8 -0
- package/cjs/components/notice-bar/notice-bar.js +5 -3
- package/cjs/components/number-keyboard/number-keyboard.css +11 -14
- package/cjs/components/number-keyboard/number-keyboard.d.ts +1 -1
- package/cjs/components/number-keyboard/number-keyboard.js +19 -17
- package/cjs/components/passcode-input/index.d.ts +1 -1
- package/cjs/components/passcode-input/passcode-input.css +12 -12
- package/cjs/components/passcode-input/passcode-input.js +16 -8
- package/cjs/components/rate/rate.css +1 -0
- package/cjs/components/rate/rate.js +38 -5
- package/cjs/components/rate/star.js +0 -10
- package/cjs/components/result/result.d.ts +1 -1
- package/cjs/components/result/result.js +7 -1
- package/cjs/components/search-bar/search-bar.js +12 -2
- package/cjs/components/swipe-action/swipe-action.d.ts +2 -0
- package/cjs/components/swipe-action/swipe-action.js +34 -6
- package/cjs/components/swiper/swiper.js +14 -0
- package/cjs/components/switch/switch.d.ts +2 -1
- package/cjs/components/switch/switch.js +16 -3
- package/cjs/locales/base.d.ts +9 -0
- package/cjs/locales/base.js +9 -0
- package/cjs/locales/en-US.d.ts +9 -0
- package/cjs/locales/es-ES.d.ts +9 -0
- package/cjs/locales/fa-IR.d.ts +9 -0
- package/cjs/locales/fr-FR.d.ts +9 -0
- package/cjs/locales/id-ID.d.ts +9 -0
- package/cjs/locales/id-ID.js +13 -0
- package/cjs/locales/kk-KZ.d.ts +9 -0
- package/cjs/locales/ko-KR.d.ts +9 -0
- package/cjs/locales/zh-CN.d.ts +9 -0
- package/cjs/locales/zh-CN.js +9 -0
- package/cjs/locales/zh-HK.d.ts +9 -0
- package/cjs/locales/zh-TW.d.ts +9 -0
- package/cjs/utils/matrix.d.ts +10 -0
- package/cjs/utils/matrix.js +60 -0
- package/cjs/utils/merge-locale.d.ts +1 -1
- package/cjs/utils/merge-locale.js +15 -5
- package/cjs/utils/use-drag-and-pinch.d.ts +1 -1
- package/cjs/utils/use-props-value.js +1 -1
- package/cjs/utils/use-resize-effect.js +3 -1
- package/cjs/utils/with-default-props.js +2 -6
- package/es/components/action-sheet/action-sheet.d.ts +1 -1
- package/es/components/button/button.js +1 -1
- package/es/components/calendar/calendar.d.ts +3 -3
- package/es/components/calendar/index.d.ts +1 -1
- package/es/components/cascader/cascader.d.ts +2 -0
- package/es/components/cascader/index.d.ts +1 -0
- package/es/components/cascader-view/cascader-view.d.ts +2 -1
- package/es/components/cascader-view/cascader-view.js +2 -1
- package/es/components/dialog/show.d.ts +1 -1
- package/es/components/form/context.d.ts +1 -1
- package/es/components/form/form-item.js +8 -4
- package/es/components/image/test/image.test.js +54 -8
- package/es/components/image-viewer/slide.js +73 -56
- package/es/components/input/input.js +8 -2
- package/es/components/modal/show.d.ts +1 -1
- package/es/components/notice-bar/notice-bar.css +8 -0
- package/es/components/notice-bar/notice-bar.js +5 -3
- package/es/components/number-keyboard/number-keyboard.css +11 -14
- package/es/components/number-keyboard/number-keyboard.d.ts +1 -1
- package/es/components/number-keyboard/number-keyboard.js +19 -17
- package/es/components/passcode-input/index.d.ts +1 -1
- package/es/components/passcode-input/passcode-input.css +12 -12
- package/es/components/passcode-input/passcode-input.js +15 -8
- package/es/components/rate/rate.css +1 -0
- package/es/components/rate/rate.js +32 -5
- package/es/components/rate/star.js +0 -10
- package/es/components/result/result.d.ts +1 -1
- package/es/components/result/result.js +6 -1
- package/es/components/search-bar/search-bar.js +12 -2
- package/es/components/swipe-action/swipe-action.d.ts +2 -0
- package/es/components/swipe-action/swipe-action.js +34 -6
- package/es/components/swiper/swiper.js +14 -0
- package/es/components/switch/switch.d.ts +2 -1
- package/es/components/switch/switch.js +15 -3
- package/es/locales/base.d.ts +9 -0
- package/es/locales/base.js +9 -0
- package/es/locales/en-US.d.ts +9 -0
- package/es/locales/es-ES.d.ts +9 -0
- package/es/locales/fa-IR.d.ts +9 -0
- package/es/locales/fr-FR.d.ts +9 -0
- package/es/locales/id-ID.d.ts +9 -0
- package/es/locales/id-ID.js +13 -0
- package/es/locales/kk-KZ.d.ts +9 -0
- package/es/locales/ko-KR.d.ts +9 -0
- package/es/locales/zh-CN.d.ts +9 -0
- package/es/locales/zh-CN.js +9 -0
- package/es/locales/zh-HK.d.ts +9 -0
- package/es/locales/zh-TW.d.ts +9 -0
- package/es/utils/matrix.d.ts +10 -0
- package/es/utils/matrix.js +27 -0
- package/es/utils/merge-locale.d.ts +1 -1
- package/es/utils/merge-locale.js +17 -3
- package/es/utils/use-drag-and-pinch.d.ts +1 -1
- package/es/utils/use-props-value.js +1 -1
- package/es/utils/use-resize-effect.js +3 -1
- package/es/utils/with-default-props.js +2 -4
- package/package.json +6 -6
- package/umd/antd-mobile.js +1 -1
- package/2x/umd/antd-mobile.js.LICENSE.txt +0 -35
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
import { __awaiter } from "tslib";
|
|
2
1
|
import React from 'react';
|
|
3
|
-
import { fireEvent, render,
|
|
2
|
+
import { fireEvent, render, act } from 'testing';
|
|
4
3
|
import Image from '../index';
|
|
4
|
+
const classPrefix = `adm-image`;
|
|
5
5
|
const demoSrc = 'https://images.unsplash.com/photo-1567945716310-4745a6b7844b?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=300&q=60';
|
|
6
|
-
describe('
|
|
7
|
-
test('a11y', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
8
|
-
yield testA11y(React.createElement(Image, {
|
|
9
|
-
src: demoSrc
|
|
10
|
-
}));
|
|
11
|
-
}));
|
|
6
|
+
describe('Image', () => {
|
|
12
7
|
test('onContainerClick can work', () => {
|
|
13
8
|
const onContainerClick = jest.fn();
|
|
14
9
|
const {
|
|
@@ -21,4 +16,55 @@ describe('image', () => {
|
|
|
21
16
|
fireEvent.click(getByTestId('img'));
|
|
22
17
|
expect(onContainerClick).toBeCalledTimes(1);
|
|
23
18
|
});
|
|
19
|
+
test('load successfully', () => {
|
|
20
|
+
render(React.createElement(Image, {
|
|
21
|
+
src: demoSrc
|
|
22
|
+
}));
|
|
23
|
+
const img = document.querySelectorAll(`.${classPrefix}-img`)[0];
|
|
24
|
+
fireEvent.load(img);
|
|
25
|
+
expect(img).toHaveAttribute('src', demoSrc);
|
|
26
|
+
});
|
|
27
|
+
test('load failed', () => {
|
|
28
|
+
render(React.createElement(Image, {
|
|
29
|
+
src: '404'
|
|
30
|
+
}));
|
|
31
|
+
const img = document.querySelectorAll(`.${classPrefix}-img`)[0];
|
|
32
|
+
fireEvent.error(img);
|
|
33
|
+
expect(img).not.toBeInTheDocument();
|
|
34
|
+
expect(document.querySelectorAll(`.${classPrefix}-tip`)[0]).toBeInTheDocument();
|
|
35
|
+
});
|
|
36
|
+
test('lazy load should be work', () => {
|
|
37
|
+
// mock useInViewport
|
|
38
|
+
// https://github.com/alibaba/hooks/blob/master/packages/hooks/src/useInViewport/__tests__/index.test.ts
|
|
39
|
+
const mockIntersectionObserver = jest.fn().mockReturnValue({
|
|
40
|
+
observe: () => null,
|
|
41
|
+
disconnect: () => null
|
|
42
|
+
});
|
|
43
|
+
window.IntersectionObserver = mockIntersectionObserver;
|
|
44
|
+
render(React.createElement(Image, {
|
|
45
|
+
src: demoSrc,
|
|
46
|
+
lazy: true
|
|
47
|
+
}));
|
|
48
|
+
const img = document.querySelectorAll(`.${classPrefix}-img`)[0];
|
|
49
|
+
expect(img).not.toHaveAttribute('src');
|
|
50
|
+
const calls = mockIntersectionObserver.mock.calls;
|
|
51
|
+
const [onChange] = calls[calls.length - 1];
|
|
52
|
+
act(() => {
|
|
53
|
+
onChange([{
|
|
54
|
+
isIntersecting: true
|
|
55
|
+
}]);
|
|
56
|
+
});
|
|
57
|
+
expect(img).toHaveAttribute('src', demoSrc);
|
|
58
|
+
});
|
|
59
|
+
test('renders with width and height', () => {
|
|
60
|
+
const {
|
|
61
|
+
getByTestId
|
|
62
|
+
} = render(React.createElement(Image, {
|
|
63
|
+
src: demoSrc,
|
|
64
|
+
width: 100,
|
|
65
|
+
height: 100,
|
|
66
|
+
"data-testid": 'image'
|
|
67
|
+
}));
|
|
68
|
+
expect(getByTestId('image')).toHaveStyle('--width: 100px;--height: 100px');
|
|
69
|
+
});
|
|
24
70
|
});
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import React, { useRef } from 'react';
|
|
2
2
|
import { useSpring, animated } from '@react-spring/web';
|
|
3
|
+
import { useSize } from 'ahooks';
|
|
3
4
|
import { rubberbandIfOutOfBounds } from '../../utils/rubberband';
|
|
4
5
|
import { useDragAndPinch } from '../../utils/use-drag-and-pinch';
|
|
5
6
|
import { bound } from '../../utils/bound';
|
|
7
|
+
import * as mat from '../../utils/matrix';
|
|
6
8
|
const classPrefix = `adm-image-viewer`;
|
|
7
9
|
export const Slide = props => {
|
|
8
10
|
const {
|
|
@@ -11,54 +13,71 @@ export const Slide = props => {
|
|
|
11
13
|
const controlRef = useRef(null);
|
|
12
14
|
const imgRef = useRef(null);
|
|
13
15
|
const [{
|
|
14
|
-
|
|
15
|
-
x,
|
|
16
|
-
y
|
|
16
|
+
matrix
|
|
17
17
|
}, api] = useSpring(() => ({
|
|
18
|
-
|
|
19
|
-
x: 0,
|
|
20
|
-
y: 0,
|
|
18
|
+
matrix: mat.create(),
|
|
21
19
|
config: {
|
|
22
20
|
tension: 200
|
|
23
21
|
}
|
|
24
22
|
}));
|
|
23
|
+
const controlSize = useSize(controlRef);
|
|
24
|
+
const imgSize = useSize(imgRef);
|
|
25
25
|
const pinchLockRef = useRef(false);
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
const boundMatrix = (nextMatrix, type, last = false) => {
|
|
28
|
+
if (!controlSize || !imgSize) return nextMatrix;
|
|
29
|
+
const controlLeft = -controlSize.width / 2;
|
|
30
|
+
const controlTop = -controlSize.height / 2;
|
|
31
|
+
const imgLeft = -imgSize.width / 2;
|
|
32
|
+
const imgTop = -imgSize.height / 2;
|
|
33
|
+
const zoom = mat.getScaleX(nextMatrix);
|
|
34
|
+
const scaledImgWidth = zoom * imgSize.width;
|
|
35
|
+
const scaledImgHeight = zoom * imgSize.height;
|
|
36
|
+
const [x, y] = mat.apply(nextMatrix, [imgLeft, imgTop]);
|
|
31
37
|
|
|
32
|
-
if (
|
|
33
|
-
|
|
34
|
-
|
|
38
|
+
if (type === 'translate') {
|
|
39
|
+
let boundedX = x;
|
|
40
|
+
let boundedY = y;
|
|
41
|
+
|
|
42
|
+
if (scaledImgWidth > controlSize.width) {
|
|
43
|
+
const minX = controlLeft - (scaledImgWidth - controlSize.width);
|
|
44
|
+
const maxX = controlLeft;
|
|
45
|
+
boundedX = last ? bound(x, minX, maxX) : rubberbandIfOutOfBounds(x, minX, maxX, zoom * 50);
|
|
46
|
+
} else {
|
|
47
|
+
boundedX = -scaledImgWidth / 2;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (scaledImgHeight > controlSize.height) {
|
|
51
|
+
const minY = controlTop - (scaledImgHeight - controlSize.height);
|
|
52
|
+
const maxY = controlTop;
|
|
53
|
+
boundedY = last ? bound(y, minY, maxY) : rubberbandIfOutOfBounds(y, minY, maxY, zoom * 50);
|
|
54
|
+
} else {
|
|
55
|
+
boundedY = -scaledImgHeight / 2;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return mat.translate(nextMatrix, boundedX - x, boundedY - y);
|
|
35
59
|
}
|
|
36
60
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
left: -xOffset,
|
|
41
|
-
right: xOffset,
|
|
42
|
-
top: -yOffset,
|
|
43
|
-
bottom: yOffset
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
if (rubberband) {
|
|
47
|
-
return [rubberbandIfOutOfBounds(x, bounds.left, bounds.right, currentZoom * 50), rubberbandIfOutOfBounds(y, bounds.top, bounds.bottom, currentZoom * 50)];
|
|
48
|
-
} else {
|
|
49
|
-
return [bound(x, bounds.left, bounds.right), bound(y, bounds.top, bounds.bottom)];
|
|
61
|
+
if (type === 'scale' && last) {
|
|
62
|
+
const [boundedX, boundedY] = [scaledImgWidth > controlSize.width ? bound(x, controlLeft - (scaledImgWidth - controlSize.width), controlLeft) : -scaledImgWidth / 2, scaledImgHeight > controlSize.height ? bound(y, controlTop - (scaledImgHeight - controlSize.height), controlTop) : -scaledImgHeight / 2];
|
|
63
|
+
return mat.translate(nextMatrix, boundedX - x, boundedY - y);
|
|
50
64
|
}
|
|
51
|
-
|
|
65
|
+
|
|
66
|
+
return nextMatrix;
|
|
67
|
+
};
|
|
52
68
|
|
|
53
69
|
useDragAndPinch({
|
|
54
70
|
onDrag: state => {
|
|
71
|
+
if (state.first) return;
|
|
72
|
+
if (state.pinching) return state.cancel();
|
|
73
|
+
|
|
55
74
|
if (state.tap && state.elapsedTime > 0 && state.elapsedTime < 1000) {
|
|
56
75
|
// 判断点击时间>0是为了过滤掉非正常操作,例如用户长按选择图片之后的取消操作(也是一次点击)
|
|
57
76
|
props.onTap();
|
|
58
77
|
return;
|
|
59
78
|
}
|
|
60
79
|
|
|
61
|
-
const currentZoom =
|
|
80
|
+
const currentZoom = mat.getScaleX(matrix.get());
|
|
62
81
|
|
|
63
82
|
if (dragLockRef) {
|
|
64
83
|
dragLockRef.current = currentZoom !== 1;
|
|
@@ -66,24 +85,16 @@ export const Slide = props => {
|
|
|
66
85
|
|
|
67
86
|
if (!pinchLockRef.current && currentZoom <= 1) {
|
|
68
87
|
api.start({
|
|
69
|
-
|
|
70
|
-
y: 0
|
|
88
|
+
matrix: mat.create()
|
|
71
89
|
});
|
|
72
90
|
} else {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
const [x, y] = boundXY(state.offset, true);
|
|
81
|
-
api.start({
|
|
82
|
-
x,
|
|
83
|
-
y,
|
|
84
|
-
immediate: true
|
|
85
|
-
});
|
|
86
|
-
}
|
|
91
|
+
const currentMatrix = matrix.get();
|
|
92
|
+
const offset = [state.offset[0] - mat.getTranslateX(currentMatrix), state.offset[1] - mat.getTranslateY(currentMatrix)];
|
|
93
|
+
const nextMatrix = mat.translate(currentMatrix, ...(state.last ? [offset[0] + state.velocity[0] * state.direction[0] * 200, offset[1] + state.velocity[1] * state.direction[1] * 200] : offset));
|
|
94
|
+
api.start({
|
|
95
|
+
matrix: boundMatrix(nextMatrix, 'translate', state.last),
|
|
96
|
+
immediate: !state.last
|
|
97
|
+
});
|
|
87
98
|
}
|
|
88
99
|
},
|
|
89
100
|
onPinch: state => {
|
|
@@ -93,22 +104,30 @@ export const Slide = props => {
|
|
|
93
104
|
const [d] = state.offset;
|
|
94
105
|
if (d < 0) return;
|
|
95
106
|
const nextZoom = state.last ? bound(d, 1, props.maxZoom) : d;
|
|
96
|
-
api.start({
|
|
97
|
-
zoom: nextZoom,
|
|
98
|
-
immediate: !state.last
|
|
99
|
-
});
|
|
100
107
|
(_a = props.onZoomChange) === null || _a === void 0 ? void 0 : _a.call(props, nextZoom);
|
|
101
108
|
|
|
102
109
|
if (state.last && nextZoom <= 1) {
|
|
103
110
|
api.start({
|
|
104
|
-
|
|
105
|
-
y: 0
|
|
111
|
+
matrix: mat.create()
|
|
106
112
|
});
|
|
107
113
|
|
|
108
114
|
if (dragLockRef) {
|
|
109
115
|
dragLockRef.current = false;
|
|
110
116
|
}
|
|
111
117
|
} else {
|
|
118
|
+
if (!controlSize) return;
|
|
119
|
+
const currentMatrix = matrix.get();
|
|
120
|
+
const currentZoom = mat.getScaleX(currentMatrix);
|
|
121
|
+
const originOffsetX = state.origin[0] - controlSize.width / 2;
|
|
122
|
+
const originOffsetY = state.origin[1] - controlSize.height / 2;
|
|
123
|
+
let nextMatrix = mat.translate(currentMatrix, -originOffsetX, -originOffsetY);
|
|
124
|
+
nextMatrix = mat.scale(nextMatrix, nextZoom / currentZoom);
|
|
125
|
+
nextMatrix = mat.translate(nextMatrix, originOffsetX, originOffsetY);
|
|
126
|
+
api.start({
|
|
127
|
+
matrix: boundMatrix(nextMatrix, 'scale', state.last),
|
|
128
|
+
immediate: !state.last
|
|
129
|
+
});
|
|
130
|
+
|
|
112
131
|
if (dragLockRef) {
|
|
113
132
|
dragLockRef.current = true;
|
|
114
133
|
}
|
|
@@ -118,13 +137,13 @@ export const Slide = props => {
|
|
|
118
137
|
target: controlRef,
|
|
119
138
|
drag: {
|
|
120
139
|
// filterTaps: true,
|
|
121
|
-
from: () => [
|
|
140
|
+
from: () => [mat.getTranslateX(matrix.get()), mat.getTranslateY(matrix.get())],
|
|
122
141
|
pointer: {
|
|
123
142
|
touch: true
|
|
124
143
|
}
|
|
125
144
|
},
|
|
126
145
|
pinch: {
|
|
127
|
-
from: () => [
|
|
146
|
+
from: () => [mat.getScaleX(matrix.get()), 0],
|
|
128
147
|
pointer: {
|
|
129
148
|
touch: true
|
|
130
149
|
}
|
|
@@ -133,7 +152,7 @@ export const Slide = props => {
|
|
|
133
152
|
return React.createElement("div", {
|
|
134
153
|
className: `${classPrefix}-slide`,
|
|
135
154
|
onPointerMove: e => {
|
|
136
|
-
if (
|
|
155
|
+
if (mat.getScaleX(matrix.get()) !== 1) {
|
|
137
156
|
e.stopPropagation();
|
|
138
157
|
}
|
|
139
158
|
}
|
|
@@ -143,9 +162,7 @@ export const Slide = props => {
|
|
|
143
162
|
}, React.createElement(animated.div, {
|
|
144
163
|
className: `${classPrefix}-image-wrapper`,
|
|
145
164
|
style: {
|
|
146
|
-
|
|
147
|
-
translateY: y,
|
|
148
|
-
scale: zoom
|
|
165
|
+
matrix
|
|
149
166
|
}
|
|
150
167
|
}, React.createElement("img", {
|
|
151
168
|
ref: imgRef,
|
|
@@ -7,6 +7,7 @@ import classNames from 'classnames';
|
|
|
7
7
|
import { useIsomorphicLayoutEffect } from 'ahooks';
|
|
8
8
|
import { bound } from '../../utils/bound';
|
|
9
9
|
import { isIOS } from '../../utils/validate';
|
|
10
|
+
import { useConfig } from '../config-provider';
|
|
10
11
|
const classPrefix = `adm-input`;
|
|
11
12
|
const defaultProps = {
|
|
12
13
|
defaultValue: '',
|
|
@@ -18,6 +19,9 @@ export const Input = forwardRef((p, ref) => {
|
|
|
18
19
|
const [hasFocus, setHasFocus] = useState(false);
|
|
19
20
|
const compositionStartRef = useRef(false);
|
|
20
21
|
const nativeInputRef = useRef(null);
|
|
22
|
+
const {
|
|
23
|
+
locale
|
|
24
|
+
} = useConfig();
|
|
21
25
|
useImperativeHandle(ref, () => ({
|
|
22
26
|
clear: () => {
|
|
23
27
|
setValue('');
|
|
@@ -139,7 +143,8 @@ export const Input = forwardRef((p, ref) => {
|
|
|
139
143
|
role: props.role,
|
|
140
144
|
"aria-valuenow": props['aria-valuenow'],
|
|
141
145
|
"aria-valuemax": props['aria-valuemax'],
|
|
142
|
-
"aria-valuemin": props['aria-valuemin']
|
|
146
|
+
"aria-valuemin": props['aria-valuemin'],
|
|
147
|
+
"aria-label": props['aria-label']
|
|
143
148
|
}), shouldShowClear && React.createElement("div", {
|
|
144
149
|
className: `${classPrefix}-clear`,
|
|
145
150
|
onMouseDown: e => {
|
|
@@ -155,6 +160,7 @@ export const Input = forwardRef((p, ref) => {
|
|
|
155
160
|
compositionStartRef.current = false;
|
|
156
161
|
(_b = nativeInputRef.current) === null || _b === void 0 ? void 0 : _b.blur();
|
|
157
162
|
}
|
|
158
|
-
}
|
|
163
|
+
},
|
|
164
|
+
"aria-label": locale.Input.clear
|
|
159
165
|
}, React.createElement(CloseCircleFill, null))));
|
|
160
166
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ModalProps } from './modal';
|
|
2
|
-
export declare type ModalShowProps = Omit<ModalProps, 'visible'>;
|
|
2
|
+
export declare type ModalShowProps = Omit<ModalProps, 'visible' | 'destroyOnClose' | 'forceRender'>;
|
|
3
3
|
export declare type ModalShowHandler = {
|
|
4
4
|
close: () => void;
|
|
5
5
|
};
|
|
@@ -61,6 +61,14 @@
|
|
|
61
61
|
flex-shrink: 0;
|
|
62
62
|
margin-left: 12px;
|
|
63
63
|
}
|
|
64
|
+
.adm-notice-bar-close {
|
|
65
|
+
width: 24px;
|
|
66
|
+
height: 24px;
|
|
67
|
+
margin-right: -3px;
|
|
68
|
+
display: flex;
|
|
69
|
+
align-items: center;
|
|
70
|
+
justify-content: center;
|
|
71
|
+
}
|
|
64
72
|
.adm-notice-bar-close-icon {
|
|
65
73
|
font-size: var(--adm-font-size-10);
|
|
66
74
|
}
|
|
@@ -82,13 +82,15 @@ export const NoticeBar = memo(p => {
|
|
|
82
82
|
className: `${classPrefix}-content-inner`
|
|
83
83
|
}, props.content)), (props.closeable || props.extra) && React.createElement("span", {
|
|
84
84
|
className: `${classPrefix}-right`
|
|
85
|
-
}, props.extra, props.closeable && React.createElement(
|
|
86
|
-
className: `${classPrefix}-close
|
|
85
|
+
}, props.extra, props.closeable && React.createElement("div", {
|
|
86
|
+
className: `${classPrefix}-close`,
|
|
87
87
|
onClick: () => {
|
|
88
88
|
var _a;
|
|
89
89
|
|
|
90
90
|
setVisible(false);
|
|
91
91
|
(_a = props.onClose) === null || _a === void 0 ? void 0 : _a.call(props);
|
|
92
92
|
}
|
|
93
|
-
}
|
|
93
|
+
}, React.createElement(CloseOutline, {
|
|
94
|
+
className: `${classPrefix}-close-icon`
|
|
95
|
+
})))));
|
|
94
96
|
});
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
flex-wrap: wrap;
|
|
4
4
|
flex: 1;
|
|
5
5
|
}
|
|
6
|
-
.adm-number-keyboard-main.confirmed-style .
|
|
6
|
+
.adm-number-keyboard-main.adm-number-keyboard-main-confirmed-style .adm-number-keyboard-key-sign {
|
|
7
7
|
background-color: var(--adm-color-white);
|
|
8
8
|
}
|
|
9
9
|
.adm-number-keyboard-popup.adm-popup {
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
padding: 0 12px;
|
|
34
34
|
font-size: 16px;
|
|
35
35
|
}
|
|
36
|
-
.adm-number-keyboard-header.with-title {
|
|
36
|
+
.adm-number-keyboard-header.adm-number-keyboard-header-with-title {
|
|
37
37
|
justify-content: space-between;
|
|
38
38
|
}
|
|
39
|
-
.adm-number-keyboard-header.with-title .adm-number-keyboard-header-close-button {
|
|
39
|
+
.adm-number-keyboard-header.adm-number-keyboard-header-with-title .adm-number-keyboard-header-close-button {
|
|
40
40
|
padding-right: 0;
|
|
41
41
|
}
|
|
42
42
|
.adm-number-keyboard-footer {
|
|
@@ -82,31 +82,28 @@
|
|
|
82
82
|
content: ' ';
|
|
83
83
|
box-sizing: content-box;
|
|
84
84
|
}
|
|
85
|
-
.adm-number-keyboard-key.
|
|
85
|
+
.adm-number-keyboard-key.adm-number-keyboard-key-mid {
|
|
86
86
|
flex-basis: 66.67%;
|
|
87
87
|
}
|
|
88
|
-
.adm-number-keyboard-key.
|
|
88
|
+
.adm-number-keyboard-key.adm-number-keyboard-key-sign:active::before {
|
|
89
89
|
opacity: 0.1;
|
|
90
90
|
}
|
|
91
|
-
.adm-number-keyboard-key.
|
|
91
|
+
.adm-number-keyboard-key.adm-number-keyboard-key-extra {
|
|
92
92
|
border-left: solid 1px var(--adm-color-border);
|
|
93
93
|
border-right: none;
|
|
94
94
|
}
|
|
95
|
-
.adm-number-keyboard-key.
|
|
96
|
-
.adm-number-keyboard-key.number-key {
|
|
95
|
+
.adm-number-keyboard-key.adm-number-keyboard-key-extra,
|
|
96
|
+
.adm-number-keyboard-key.adm-number-keyboard-key-number {
|
|
97
97
|
background-color: var(--adm-color-background);
|
|
98
98
|
}
|
|
99
|
-
.adm-number-keyboard-key.
|
|
100
|
-
.adm-number-keyboard-key.number-key:active::before {
|
|
99
|
+
.adm-number-keyboard-key.adm-number-keyboard-key-extra:active::before,
|
|
100
|
+
.adm-number-keyboard-key.adm-number-keyboard-key-number:active::before {
|
|
101
101
|
opacity: 0.1;
|
|
102
102
|
}
|
|
103
|
-
.adm-number-keyboard-key.
|
|
103
|
+
.adm-number-keyboard-key.adm-number-keyboard-key-ok {
|
|
104
104
|
background-color: var(--adm-color-primary);
|
|
105
105
|
color: var(--adm-color-white);
|
|
106
106
|
height: 144px;
|
|
107
107
|
font-size: 16px;
|
|
108
108
|
border: none;
|
|
109
109
|
}
|
|
110
|
-
.adm-number-keyboard-bs-key {
|
|
111
|
-
height: 20px;
|
|
112
|
-
}
|
|
@@ -5,7 +5,7 @@ export declare type NumberKeyboardProps = {
|
|
|
5
5
|
visible?: boolean;
|
|
6
6
|
title?: string;
|
|
7
7
|
confirmText?: string | null;
|
|
8
|
-
customKey?:
|
|
8
|
+
customKey?: string | [string, string];
|
|
9
9
|
randomOrder?: boolean;
|
|
10
10
|
showCloseButton?: boolean;
|
|
11
11
|
onInput?: (v: string) => void;
|
|
@@ -34,13 +34,18 @@ export const NumberKeyboard = p => {
|
|
|
34
34
|
const keys = useMemo(() => {
|
|
35
35
|
const defaultKeys = ['1', '2', '3', '4', '5', '6', '7', '8', '9'];
|
|
36
36
|
const keyList = randomOrder ? shuffle(defaultKeys) : defaultKeys;
|
|
37
|
+
const customKeys = Array.isArray(customKey) ? customKey : [customKey];
|
|
37
38
|
keyList.push('0');
|
|
38
39
|
|
|
39
40
|
if (confirmText) {
|
|
40
|
-
|
|
41
|
+
if (customKeys.length === 2) {
|
|
42
|
+
keyList.splice(9, 0, customKeys.pop());
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
keyList.push(customKeys[0] || '');
|
|
41
46
|
} else {
|
|
42
|
-
keyList.splice(9, 0,
|
|
43
|
-
keyList.push('BACKSPACE');
|
|
47
|
+
keyList.splice(9, 0, customKeys[0] || '');
|
|
48
|
+
keyList.push(customKeys[1] || 'BACKSPACE');
|
|
44
49
|
}
|
|
45
50
|
|
|
46
51
|
return keyList;
|
|
@@ -63,8 +68,7 @@ export const NumberKeyboard = p => {
|
|
|
63
68
|
const onBackspacePressEnd = () => {
|
|
64
69
|
clearTimeout(timeoutRef.current);
|
|
65
70
|
clearInterval(intervalRef.current);
|
|
66
|
-
};
|
|
67
|
-
|
|
71
|
+
};
|
|
68
72
|
|
|
69
73
|
const onKeyPress = (e, key) => {
|
|
70
74
|
var _a, _b;
|
|
@@ -86,18 +90,17 @@ export const NumberKeyboard = p => {
|
|
|
86
90
|
break;
|
|
87
91
|
|
|
88
92
|
default:
|
|
89
|
-
//
|
|
93
|
+
// onInput should't be called when customKey doesn't exist
|
|
90
94
|
if (key !== '') onInput === null || onInput === void 0 ? void 0 : onInput(key);
|
|
91
95
|
break;
|
|
92
96
|
}
|
|
93
|
-
};
|
|
94
|
-
|
|
97
|
+
};
|
|
95
98
|
|
|
96
99
|
const renderHeader = () => {
|
|
97
100
|
if (!showCloseButton && !title) return null;
|
|
98
101
|
return React.createElement("div", {
|
|
99
102
|
className: classNames(`${classPrefix}-header`, {
|
|
100
|
-
|
|
103
|
+
[`${classPrefix}-header-with-title`]: !!title
|
|
101
104
|
})
|
|
102
105
|
}, title && React.createElement("div", {
|
|
103
106
|
className: `${classPrefix}-title`
|
|
@@ -111,15 +114,14 @@ export const NumberKeyboard = p => {
|
|
|
111
114
|
role: 'button',
|
|
112
115
|
title: 'CLOSE'
|
|
113
116
|
}, React.createElement(DownOutline, null)));
|
|
114
|
-
};
|
|
115
|
-
|
|
117
|
+
};
|
|
116
118
|
|
|
117
119
|
const renderKey = (key, index) => {
|
|
118
120
|
const isNumberKey = /^\d$/.test(key);
|
|
119
121
|
const className = classNames(`${classPrefix}-key`, {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
122
|
+
[`${classPrefix}-key-number`]: isNumberKey,
|
|
123
|
+
[`${classPrefix}-key-sign`]: !isNumberKey && key,
|
|
124
|
+
[`${classPrefix}-key-mid`]: index === 9 && !!confirmText && keys.length < 12
|
|
123
125
|
});
|
|
124
126
|
const ariaProps = key ? {
|
|
125
127
|
role: 'button',
|
|
@@ -163,12 +165,12 @@ export const NumberKeyboard = p => {
|
|
|
163
165
|
className: `${classPrefix}-wrapper`
|
|
164
166
|
}, React.createElement("div", {
|
|
165
167
|
className: classNames(`${classPrefix}-main`, {
|
|
166
|
-
|
|
168
|
+
[`${classPrefix}-main-confirmed-style`]: !!confirmText
|
|
167
169
|
})
|
|
168
170
|
}, keys.map(renderKey)), !!confirmText && React.createElement("div", {
|
|
169
171
|
className: `${classPrefix}-confirm`
|
|
170
172
|
}, React.createElement("div", {
|
|
171
|
-
className: `${classPrefix}-key
|
|
173
|
+
className: `${classPrefix}-key ${classPrefix}-key-extra ${classPrefix}-key-bs`,
|
|
172
174
|
onTouchStart: () => {
|
|
173
175
|
onBackspacePressStart();
|
|
174
176
|
},
|
|
@@ -179,7 +181,7 @@ export const NumberKeyboard = p => {
|
|
|
179
181
|
title: 'BACKSPACE',
|
|
180
182
|
role: 'button'
|
|
181
183
|
}, React.createElement(TextDeletionOutline, null)), React.createElement("div", {
|
|
182
|
-
className: `${classPrefix}-key
|
|
184
|
+
className: `${classPrefix}-key ${classPrefix}-key-extra ${classPrefix}-key-ok`,
|
|
183
185
|
onTouchEnd: e => onKeyPress(e, 'OK'),
|
|
184
186
|
role: 'button'
|
|
185
187
|
}, confirmText))), props.safeArea && React.createElement("div", {
|
|
@@ -22,53 +22,53 @@
|
|
|
22
22
|
height: var(--cell-size);
|
|
23
23
|
background: var(--adm-color-background);
|
|
24
24
|
}
|
|
25
|
-
.adm-passcode-input:not(.seperated) {
|
|
25
|
+
.adm-passcode-input:not(.adm-passcode-input-seperated) {
|
|
26
26
|
border-radius: var(--border-radius);
|
|
27
27
|
overflow: hidden;
|
|
28
28
|
border: 1px solid var(--border-color);
|
|
29
29
|
}
|
|
30
|
-
.adm-passcode-input:not(.seperated) .adm-passcode-input-cell:not(:last-child) {
|
|
30
|
+
.adm-passcode-input:not(.adm-passcode-input-seperated) .adm-passcode-input-cell:not(:last-child) {
|
|
31
31
|
border-right: 1px solid var(--border-color);
|
|
32
32
|
}
|
|
33
|
-
.adm-passcode-input:not(.seperated).focused {
|
|
33
|
+
.adm-passcode-input:not(.adm-passcode-input-seperated).adm-passcode-input-focused {
|
|
34
34
|
border-color: var(--adm-color-primary);
|
|
35
35
|
box-shadow: 0 0 2px 0 var(--adm-color-primary);
|
|
36
36
|
outline: none;
|
|
37
37
|
}
|
|
38
|
-
.adm-passcode-input:not(.seperated).error {
|
|
38
|
+
.adm-passcode-input:not(.adm-passcode-input-seperated).adm-passcode-input-error {
|
|
39
39
|
border-color: var(--adm-color-danger);
|
|
40
40
|
box-shadow: 0 0 2px 0 var(--adm-color-danger);
|
|
41
41
|
animation: 100ms ease-in-out 0s 3 normal none running adm-shake-horizontal;
|
|
42
42
|
}
|
|
43
|
-
.adm-passcode-input.seperated .adm-passcode-input-cell {
|
|
43
|
+
.adm-passcode-input.adm-passcode-input-seperated .adm-passcode-input-cell {
|
|
44
44
|
border-radius: var(--border-radius);
|
|
45
45
|
border: 1px solid var(--border-color);
|
|
46
46
|
}
|
|
47
|
-
.adm-passcode-input.seperated .adm-passcode-input-cell:not(:last-child) {
|
|
47
|
+
.adm-passcode-input.adm-passcode-input-seperated .adm-passcode-input-cell:not(:last-child) {
|
|
48
48
|
margin-right: var(--cell-gap);
|
|
49
49
|
}
|
|
50
|
-
.adm-passcode-input.seperated .adm-passcode-input-cell
|
|
50
|
+
.adm-passcode-input.adm-passcode-input-seperated .adm-passcode-input-cell-focused {
|
|
51
51
|
border-color: var(--adm-color-primary);
|
|
52
52
|
box-shadow: 0 0 2px 0 var(--adm-color-primary);
|
|
53
53
|
}
|
|
54
|
-
.adm-passcode-input
|
|
54
|
+
.adm-passcode-input-seperated.adm-passcode-input-focused {
|
|
55
55
|
outline: none;
|
|
56
56
|
}
|
|
57
|
-
.adm-passcode-input.seperated.error {
|
|
57
|
+
.adm-passcode-input.adm-passcode-input-seperated.adm-passcode-input-error {
|
|
58
58
|
animation: 100ms ease-in-out 0s 3 normal none running adm-shake-horizontal;
|
|
59
59
|
}
|
|
60
|
-
.adm-passcode-input.seperated.error .adm-passcode-input-cell {
|
|
60
|
+
.adm-passcode-input.adm-passcode-input-seperated.adm-passcode-input-error .adm-passcode-input-cell {
|
|
61
61
|
border-color: var(--adm-color-danger);
|
|
62
62
|
box-shadow: 0 0 2px 0 var(--adm-color-danger);
|
|
63
63
|
}
|
|
64
|
-
.adm-passcode-input-cell
|
|
64
|
+
.adm-passcode-input-cell-dot::before {
|
|
65
65
|
content: '';
|
|
66
66
|
width: var(--dot-size);
|
|
67
67
|
height: var(--dot-size);
|
|
68
68
|
border-radius: 50%;
|
|
69
69
|
background: var(--adm-color-text);
|
|
70
70
|
}
|
|
71
|
-
.adm-passcode-input-cell
|
|
71
|
+
.adm-passcode-input-cell-caret::after {
|
|
72
72
|
content: '';
|
|
73
73
|
width: 2px;
|
|
74
74
|
height: 1.1em;
|
|
@@ -4,6 +4,7 @@ import { withNativeProps } from '../../utils/native-props';
|
|
|
4
4
|
import classNames from 'classnames';
|
|
5
5
|
import { bound } from '../../utils/bound';
|
|
6
6
|
import { usePropsValue } from '../../utils/use-props-value';
|
|
7
|
+
import { useConfig } from '../config-provider';
|
|
7
8
|
const classPrefix = 'adm-passcode-input';
|
|
8
9
|
const defaultProps = {
|
|
9
10
|
defaultValue: '',
|
|
@@ -17,6 +18,9 @@ export const PasscodeInput = forwardRef((p, ref) => {
|
|
|
17
18
|
const props = mergeProps(defaultProps, p); // 防止 length 值不合法
|
|
18
19
|
|
|
19
20
|
const cellLength = props.length > 0 && props.length < Infinity ? Math.floor(props.length) : defaultProps.length;
|
|
21
|
+
const {
|
|
22
|
+
locale
|
|
23
|
+
} = useConfig();
|
|
20
24
|
const [focused, setFocused] = useState(false);
|
|
21
25
|
const [value, setValue] = usePropsValue(props);
|
|
22
26
|
const rootRef = useRef(null);
|
|
@@ -87,9 +91,9 @@ export const PasscodeInput = forwardRef((p, ref) => {
|
|
|
87
91
|
for (let i = 0; i < cellLength; i++) {
|
|
88
92
|
cells.push(React.createElement("div", {
|
|
89
93
|
className: classNames(`${classPrefix}-cell`, {
|
|
90
|
-
caret: props.caret && caretIndex === i && focused,
|
|
91
|
-
focused: focusedIndex === i && focused,
|
|
92
|
-
dot: !props.plain && chars[i]
|
|
94
|
+
[`${classPrefix}-cell-caret`]: props.caret && caretIndex === i && focused,
|
|
95
|
+
[`${classPrefix}-cell-focused`]: focusedIndex === i && focused,
|
|
96
|
+
[`${classPrefix}-cell-dot`]: !props.plain && chars[i]
|
|
93
97
|
}),
|
|
94
98
|
key: i
|
|
95
99
|
}, chars[i] && props.plain ? chars[i] : ''));
|
|
@@ -99,16 +103,18 @@ export const PasscodeInput = forwardRef((p, ref) => {
|
|
|
99
103
|
};
|
|
100
104
|
|
|
101
105
|
const cls = classNames(classPrefix, {
|
|
102
|
-
focused: focused,
|
|
103
|
-
error: props.error,
|
|
104
|
-
seperated: props.seperated
|
|
106
|
+
[`${classPrefix}-focused`]: focused,
|
|
107
|
+
[`${classPrefix}-error`]: props.error,
|
|
108
|
+
[`${classPrefix}-seperated`]: props.seperated
|
|
105
109
|
});
|
|
106
110
|
return React.createElement(React.Fragment, null, withNativeProps(props, React.createElement("div", {
|
|
107
111
|
ref: rootRef,
|
|
108
112
|
tabIndex: 0,
|
|
109
113
|
className: cls,
|
|
110
114
|
onFocus: onFocus,
|
|
111
|
-
onBlur: onBlur
|
|
115
|
+
onBlur: onBlur,
|
|
116
|
+
role: 'button',
|
|
117
|
+
"aria-label": locale.PasscodeInput.name
|
|
112
118
|
}, React.createElement("div", {
|
|
113
119
|
className: `${classPrefix}-cell-container`
|
|
114
120
|
}, renderCells()), React.createElement("input", {
|
|
@@ -120,7 +126,8 @@ export const PasscodeInput = forwardRef((p, ref) => {
|
|
|
120
126
|
inputMode: 'numeric',
|
|
121
127
|
onChange: e => {
|
|
122
128
|
setValue(e.target.value.slice(0, props.length));
|
|
123
|
-
}
|
|
129
|
+
},
|
|
130
|
+
"aria-hidden": true
|
|
124
131
|
}))), props.keyboard && React.cloneElement(props.keyboard, {
|
|
125
132
|
visible: focused,
|
|
126
133
|
onInput: v => {
|