@gm-mobile/c-react 3.9.2 → 3.9.3-beta.11
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/package.json +5 -5
- package/src/component/button/button.tsx +12 -3
- package/src/component/button/stories.tsx +2 -3
- package/src/component/button/style.less +6 -9
- package/src/component/button/types.ts +2 -1
- package/src/component/calendar/index.ts +1 -0
- package/src/component/cell/cell.tsx +29 -27
- package/src/component/cell/style.less +8 -5
- package/src/component/dialog/dialog.tsx +6 -1
- package/src/component/dialog/types.ts +9 -8
- package/src/component/digital_keyboard/Base.tsx +13 -13
- package/src/component/digital_keyboard/Btn.ts +3 -3
- package/src/component/digital_keyboard/index.tsx +14 -10
- package/src/component/digital_keyboard/stories.tsx +35 -41
- package/src/component/draggable/draggable.tsx +1 -0
- package/src/component/error/error.tsx +23 -0
- package/src/component/error/index.ts +1 -0
- package/src/component/error/style.less +42 -0
- package/src/component/error/types.ts +5 -0
- package/src/component/layout_root/layout_root.tsx +0 -1
- package/src/component/popup/popup.tsx +4 -1
- package/src/component/popup/popup_v1.tsx +2 -1
- package/src/component/popup/style.less +1 -1
- package/src/component/popup/types.ts +4 -0
- package/src/component/text_field/TextField.tsx +12 -15
- package/src/component/text_field/stories.tsx +0 -1
- package/src/component/text_field/style.less +12 -0
- package/src/component/text_field/types.ts +1 -1
- package/src/index.less +19 -13
- package/src/index.ts +1 -0
- package/src/less/animation.less +9 -4
- package/src/less/bg.less +24 -0
- package/src/less/border.less +23 -0
- package/src/less/button.less +120 -0
- package/src/less/distance.less +2 -0
- package/src/less/ellipsis.less +17 -0
- package/src/less/lineheight.less +19 -0
- package/src/less/opacity.less +15 -0
- package/src/less/shadow.less +9 -0
- package/src/less/text.less +33 -24
- package/src/less/variable.less +12 -11
- package/src/less/variable_page.less +0 -116
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gm-mobile/c-react",
|
|
3
|
-
"version": "3.9.
|
|
3
|
+
"version": "3.9.3-beta.11",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "liyatang <liyatang@qq.com>",
|
|
6
6
|
"homepage": "https://github.com/gmfe/gm-mobile#readme",
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
"url": "https://github.com/gmfe/gm-mobile/issues"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@gm-mobile/c-font": "^3.9.
|
|
25
|
-
"@gm-mobile/c-tool": "^3.9.
|
|
26
|
-
"@gm-mobile/locales": "^3.9.
|
|
24
|
+
"@gm-mobile/c-font": "^3.9.3-beta.11",
|
|
25
|
+
"@gm-mobile/c-tool": "^3.9.3-beta.11",
|
|
26
|
+
"@gm-mobile/locales": "^3.9.3-beta.11"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"@tarojs/components": "3.0.18",
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"prop-types": "^15.7.2",
|
|
34
34
|
"react": "^16.13.1"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "99380ef9295d7feceb202907caa045dbbf610699"
|
|
37
37
|
}
|
|
@@ -5,19 +5,22 @@ import { Loading } from '../loading'
|
|
|
5
5
|
import BaseButton from './base'
|
|
6
6
|
import { is } from '@gm-mobile/c-tool'
|
|
7
7
|
import type { ButtonProps } from './types'
|
|
8
|
+
import { Flex } from '../flex'
|
|
8
9
|
|
|
9
10
|
export const Button: FC<ButtonProps> = ({
|
|
10
11
|
type = 'default',
|
|
11
12
|
plain,
|
|
12
13
|
mini,
|
|
13
14
|
block,
|
|
14
|
-
|
|
15
|
+
round,
|
|
15
16
|
disabled,
|
|
16
17
|
onClick = _.noop,
|
|
17
18
|
loading,
|
|
18
19
|
children,
|
|
19
20
|
htmlType = 'button',
|
|
20
21
|
className,
|
|
22
|
+
style,
|
|
23
|
+
minWidth,
|
|
21
24
|
...rest
|
|
22
25
|
}) => {
|
|
23
26
|
const [isLoading, setIsLoading] = useState<boolean>(false)
|
|
@@ -57,16 +60,22 @@ export const Button: FC<ButtonProps> = ({
|
|
|
57
60
|
{
|
|
58
61
|
'm-btn-block': block,
|
|
59
62
|
'm-btn-mini': mini,
|
|
60
|
-
'm-btn-
|
|
63
|
+
'm-btn-round': round,
|
|
61
64
|
'm-btn-plain': type !== 'link' && plain,
|
|
62
65
|
},
|
|
63
66
|
className
|
|
64
67
|
)}
|
|
68
|
+
style={{
|
|
69
|
+
...style,
|
|
70
|
+
minWidth,
|
|
71
|
+
}}
|
|
65
72
|
disabled={!!(loadFlag || disabled)}
|
|
66
73
|
onClick={handleClick}
|
|
67
74
|
>
|
|
68
75
|
{loadFlag && <Loading className='m-btn-loading' />}
|
|
69
|
-
{
|
|
76
|
+
<Flex alignCenter justifyCenter style={{ display: 'inline-flex' }}>
|
|
77
|
+
{children}
|
|
78
|
+
</Flex>
|
|
70
79
|
</BaseButton>
|
|
71
80
|
)
|
|
72
81
|
}
|
|
@@ -64,16 +64,15 @@ export const normal: FC<ButtonProps> = (args) => (
|
|
|
64
64
|
</View>
|
|
65
65
|
block
|
|
66
66
|
<View>
|
|
67
|
-
<Button {...args} block type='primary'>
|
|
67
|
+
<Button {...args} block type='primary' round>
|
|
68
68
|
主色
|
|
69
69
|
</Button>
|
|
70
70
|
<Button {...args} block mini plain>
|
|
71
71
|
主色
|
|
72
72
|
</Button>
|
|
73
73
|
</View>
|
|
74
|
-
noRound
|
|
75
74
|
<View>
|
|
76
|
-
<Button {...args}
|
|
75
|
+
<Button {...args} type='primary'>
|
|
77
76
|
主色
|
|
78
77
|
</Button>
|
|
79
78
|
</View>
|
|
@@ -2,18 +2,16 @@
|
|
|
2
2
|
height: var(--m-size-form-height);
|
|
3
3
|
line-height: var(--m-size-form-height);
|
|
4
4
|
border-width: 0;
|
|
5
|
-
border-radius: var(--m-size-form-height);
|
|
6
5
|
display: inline-block;
|
|
7
6
|
text-align: center;
|
|
8
7
|
vertical-align: middle;
|
|
9
8
|
cursor: pointer;
|
|
10
9
|
white-space: nowrap;
|
|
11
|
-
padding: 0
|
|
10
|
+
padding: 0 15px;
|
|
12
11
|
font-size: var(--m-size-text-16);
|
|
13
12
|
user-select: none;
|
|
14
13
|
outline: none;
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
border-radius: var(--m-btn-border-radius);
|
|
17
15
|
&.m-btn-default {
|
|
18
16
|
.mBtnVariants(var(--m-btn-color-bg-default), var(--m-btn-color-bg-default-active));
|
|
19
17
|
|
|
@@ -51,7 +49,6 @@
|
|
|
51
49
|
|
|
52
50
|
&.m-btn-link {
|
|
53
51
|
background: transparent;
|
|
54
|
-
border-radius: 0;
|
|
55
52
|
color: var(--m-color-link);
|
|
56
53
|
padding: 0 15px;
|
|
57
54
|
min-width: 0;
|
|
@@ -78,11 +75,11 @@
|
|
|
78
75
|
width: 100%;
|
|
79
76
|
}
|
|
80
77
|
|
|
81
|
-
&.m-btn-
|
|
82
|
-
border-radius:
|
|
78
|
+
&.m-btn-round {
|
|
79
|
+
border-radius: var(--m-size-form-height);
|
|
83
80
|
|
|
84
81
|
&::after {
|
|
85
|
-
border-radius:
|
|
82
|
+
border-radius: var(--m-size-form-height);
|
|
86
83
|
}
|
|
87
84
|
}
|
|
88
85
|
|
|
@@ -131,7 +128,7 @@
|
|
|
131
128
|
top: 0;
|
|
132
129
|
left: 0;
|
|
133
130
|
border: 1px solid @borderColor;
|
|
134
|
-
border-radius:
|
|
131
|
+
border-radius: calc(var(--m-btn-border-radius) * 2);
|
|
135
132
|
transform: scale(0.5);
|
|
136
133
|
transform-origin: 0 0;
|
|
137
134
|
box-sizing: border-box;
|
|
@@ -14,7 +14,7 @@ interface ButtonProps extends HTMLAttributes<HTMLButtonElement> {
|
|
|
14
14
|
plain?: boolean
|
|
15
15
|
mini?: boolean
|
|
16
16
|
block?: boolean
|
|
17
|
-
|
|
17
|
+
round?: boolean
|
|
18
18
|
loading?: boolean
|
|
19
19
|
/** 仅web 用。原生的 type */
|
|
20
20
|
htmlType?: ButtonHTMLType
|
|
@@ -25,6 +25,7 @@ interface ButtonProps extends HTMLAttributes<HTMLButtonElement> {
|
|
|
25
25
|
/** 返回 Promise 才有 loading */
|
|
26
26
|
onClick?: (event: MouseEvent<HTMLButtonElement>) => void
|
|
27
27
|
disabled?: boolean
|
|
28
|
+
minWidth?: string
|
|
28
29
|
}
|
|
29
30
|
interface ButtonTimeProps extends ButtonProps {
|
|
30
31
|
/** 计时的时间 */
|
|
@@ -19,35 +19,37 @@ export const Cell: FC<CellProps> = ({
|
|
|
19
19
|
...rest
|
|
20
20
|
}) => {
|
|
21
21
|
return (
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
onClick={onClick}
|
|
35
|
-
>
|
|
36
|
-
{icon && <View className='m-cell-icon'>{icon}</View>}
|
|
37
|
-
{left && <View className='m-cell-left'>{left}</View>}
|
|
38
|
-
<View className='m-cell-body'>{children}</View>
|
|
39
|
-
<Flex alignCenter>
|
|
40
|
-
{right &&
|
|
41
|
-
(_.isString(right) ? (
|
|
42
|
-
<View className='m-cell-right'>{right}</View>
|
|
43
|
-
) : (
|
|
44
|
-
right
|
|
45
|
-
))}
|
|
46
|
-
{access && (
|
|
47
|
-
<Text className='m-font m-font-angle-right m-cell-access-icon' />
|
|
22
|
+
<>
|
|
23
|
+
<Flex
|
|
24
|
+
{...rest}
|
|
25
|
+
alignCenter
|
|
26
|
+
className={classNames(
|
|
27
|
+
'm-cell',
|
|
28
|
+
{
|
|
29
|
+
'm-cell-access': access,
|
|
30
|
+
'm-cell-with-icon': icon,
|
|
31
|
+
'm-cell-no-active': noActive,
|
|
32
|
+
},
|
|
33
|
+
className
|
|
48
34
|
)}
|
|
35
|
+
onClick={onClick}
|
|
36
|
+
>
|
|
37
|
+
{icon && <View className='m-cell-icon'>{icon}</View>}
|
|
38
|
+
{left && <View className='m-cell-left'>{left}</View>}
|
|
39
|
+
<View className='m-cell-body'>{children}</View>
|
|
40
|
+
<Flex alignCenter>
|
|
41
|
+
{right &&
|
|
42
|
+
(_.isString(right) ? (
|
|
43
|
+
<View className='m-cell-right'>{right}</View>
|
|
44
|
+
) : (
|
|
45
|
+
right
|
|
46
|
+
))}
|
|
47
|
+
{access && (
|
|
48
|
+
<Text className='m-font m-font-angle-right m-cell-access-icon' />
|
|
49
|
+
)}
|
|
50
|
+
</Flex>
|
|
49
51
|
</Flex>
|
|
50
|
-
|
|
52
|
+
</>
|
|
51
53
|
)
|
|
52
54
|
}
|
|
53
55
|
|
|
@@ -30,7 +30,6 @@
|
|
|
30
30
|
background: var(--m-color-bg-white);
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
.mCellBorderBottomAfter(15px, 0);
|
|
34
33
|
|
|
35
34
|
&.m-cell-access {
|
|
36
35
|
cursor: pointer;
|
|
@@ -41,10 +40,6 @@
|
|
|
41
40
|
}
|
|
42
41
|
}
|
|
43
42
|
|
|
44
|
-
&.m-cell-with-icon {
|
|
45
|
-
.mCellBorderBottomAfter(50px, 0);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
43
|
.m-cell-icon {
|
|
49
44
|
width: 35px;
|
|
50
45
|
}
|
|
@@ -105,4 +100,12 @@
|
|
|
105
100
|
.m-cell:not(.m-cell-form):last-child::after {
|
|
106
101
|
display: none;
|
|
107
102
|
}
|
|
103
|
+
|
|
104
|
+
.m-cell {
|
|
105
|
+
.mCellBorderBottomAfter(15px, 0);
|
|
106
|
+
|
|
107
|
+
&.m-cell-with-icon {
|
|
108
|
+
.mCellBorderBottomAfter(50px, 0);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
108
111
|
}
|
|
@@ -44,6 +44,11 @@ const ErrorInput: FC<ErrorInputProps> = ({
|
|
|
44
44
|
|
|
45
45
|
const DialogStatics: DialogStaticsTypes<string | RenderOptions> = {
|
|
46
46
|
render(options, type) {
|
|
47
|
+
const autoHide = !(
|
|
48
|
+
typeof options === 'object' &&
|
|
49
|
+
options.onConfirm &&
|
|
50
|
+
typeof options.children === 'object'
|
|
51
|
+
)
|
|
47
52
|
if (typeof options === 'string') {
|
|
48
53
|
options = {
|
|
49
54
|
children: options as string,
|
|
@@ -92,7 +97,7 @@ const DialogStatics: DialogStaticsTypes<string | RenderOptions> = {
|
|
|
92
97
|
}
|
|
93
98
|
|
|
94
99
|
Promise.resolve(result).then(() => {
|
|
95
|
-
DialogStatics.hide()
|
|
100
|
+
if (autoHide) DialogStatics.hide()
|
|
96
101
|
|
|
97
102
|
return setTimeout(() => {
|
|
98
103
|
resolve(type === 'prompt' ? inputValue : undefined)
|
|
@@ -23,22 +23,23 @@ interface DialogBaseProps {
|
|
|
23
23
|
promptGetError?: (value: string) => string | void
|
|
24
24
|
hideBottom?: boolean
|
|
25
25
|
}
|
|
26
|
-
interface RenderOptions extends PromptOptions {
|
|
27
|
-
children?: string | React.ReactNode
|
|
28
|
-
confirmText?: React.ReactNode
|
|
29
|
-
onCancel?: () => void
|
|
30
|
-
otherText?: string
|
|
31
|
-
onOther?: () => void
|
|
32
|
-
hideBottom?: boolean
|
|
33
|
-
}
|
|
34
26
|
|
|
35
27
|
interface PromptOptions {
|
|
28
|
+
title?: string
|
|
36
29
|
promptGetError?: (value: string) => string | void
|
|
37
30
|
promptText?: string
|
|
38
31
|
promptInputProps?: ErrorInputProps
|
|
39
32
|
onConfirm?: (value: string) => void | boolean
|
|
40
33
|
}
|
|
41
34
|
|
|
35
|
+
interface RenderOptions extends PromptOptions {
|
|
36
|
+
children?: string | React.ReactNode
|
|
37
|
+
confirmText?: React.ReactNode
|
|
38
|
+
onCancel?: () => void
|
|
39
|
+
otherText?: string
|
|
40
|
+
onOther?: () => void
|
|
41
|
+
hideBottom?: boolean
|
|
42
|
+
}
|
|
42
43
|
interface DialogStaticsTypes<T> {
|
|
43
44
|
render: (options: T, type?: string) => Promise<void | string>
|
|
44
45
|
alert: (options: string | RenderOptions) => Promise<void | string>
|
|
@@ -2,7 +2,7 @@ import React, { FC, HTMLAttributes } from 'react'
|
|
|
2
2
|
// import { Flex, Popup, View } from '@gm-mobile/mp'
|
|
3
3
|
import _ from 'lodash'
|
|
4
4
|
import classNames from 'classnames'
|
|
5
|
-
import
|
|
5
|
+
import DKBtn from './Btn'
|
|
6
6
|
import './base.less'
|
|
7
7
|
import './font/iconfont.css'
|
|
8
8
|
import { View } from '../view'
|
|
@@ -11,11 +11,11 @@ import { Flex } from '../flex'
|
|
|
11
11
|
|
|
12
12
|
/** 数字按钮 */
|
|
13
13
|
export const defaultDigitalKeys = [
|
|
14
|
-
...['7', '8', '9'].map((v, _) => new
|
|
15
|
-
...['4', '5', '6'].map((v, _) => new
|
|
16
|
-
...['1', '2', '3'].map((v, _) => new
|
|
17
|
-
new
|
|
18
|
-
new
|
|
14
|
+
...['7', '8', '9'].map((v, _) => new DKBtn({ label: v })),
|
|
15
|
+
...['4', '5', '6'].map((v, _) => new DKBtn({ label: v })),
|
|
16
|
+
...['1', '2', '3'].map((v, _) => new DKBtn({ label: v })),
|
|
17
|
+
new DKBtn({ label: '0' }),
|
|
18
|
+
new DKBtn({
|
|
19
19
|
label: '.',
|
|
20
20
|
fn: (value = '') => {
|
|
21
21
|
if (value === '') {
|
|
@@ -28,7 +28,7 @@ export const defaultDigitalKeys = [
|
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
}),
|
|
31
|
-
new
|
|
31
|
+
new DKBtn({
|
|
32
32
|
className: 'iconfont icon-backspace',
|
|
33
33
|
fn: (value) => {
|
|
34
34
|
if (value.length === 0) return value
|
|
@@ -39,9 +39,9 @@ export const defaultDigitalKeys = [
|
|
|
39
39
|
|
|
40
40
|
/** 右侧功能按钮 */
|
|
41
41
|
export const defaultActionKeys = [
|
|
42
|
-
new
|
|
43
|
-
new
|
|
44
|
-
new
|
|
42
|
+
new DKBtn({ label: '取消', fn: (_) => '' }),
|
|
43
|
+
new DKBtn({ label: '完成', className: 'm-bg-primary' }),
|
|
44
|
+
new DKBtn({
|
|
45
45
|
label: '大按钮',
|
|
46
46
|
flex: 2,
|
|
47
47
|
className: 'm-bg-primary',
|
|
@@ -57,9 +57,9 @@ export interface KeyboardProps
|
|
|
57
57
|
/** 输入框当前值 */
|
|
58
58
|
value: string
|
|
59
59
|
/** 虚拟键盘的点击事件 */
|
|
60
|
-
onInput?: (value: string | undefined, key:
|
|
60
|
+
onInput?: (value: string | undefined, key: DKBtn) => void
|
|
61
61
|
/** 虚拟键盘的功能键(actionKeys)点击事件 */
|
|
62
|
-
onAction?: (key:
|
|
62
|
+
onAction?: (key: DKBtn) => void
|
|
63
63
|
/** 自定义功能键盘 */
|
|
64
64
|
actionKeys?: typeof defaultActionKeys
|
|
65
65
|
/** 自定义数字键盘 */
|
|
@@ -81,7 +81,7 @@ export const Keyboard: FC<KeyboardProps> = ({
|
|
|
81
81
|
int,
|
|
82
82
|
...rest
|
|
83
83
|
}) => {
|
|
84
|
-
const handleInput = (btn:
|
|
84
|
+
const handleInput = (btn: DKBtn) => {
|
|
85
85
|
if (!btn.fn) {
|
|
86
86
|
onInput && onInput(undefined, btn)
|
|
87
87
|
return
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export class
|
|
1
|
+
export class DKBtn {
|
|
2
2
|
/** 按钮文本 */
|
|
3
3
|
label?: string
|
|
4
4
|
/** 按钮占位,默认1个位置 */
|
|
@@ -8,7 +8,7 @@ export class Btn {
|
|
|
8
8
|
/** 按钮功能,传入value为输入框当前值,返回一个按钮功能处理后的值 */
|
|
9
9
|
fn?: (value: string) => string
|
|
10
10
|
type?: 'digit' | 'action'
|
|
11
|
-
constructor({ label = '', flex = 0, className = '', fn }:
|
|
11
|
+
constructor({ label = '', flex = 0, className = '', fn }: DKBtn) {
|
|
12
12
|
this.type = /([0-9.])/.test(label) ? 'digit' : 'action'
|
|
13
13
|
if (!fn && this.type === 'digit') {
|
|
14
14
|
fn = (value = '') => value + label
|
|
@@ -17,4 +17,4 @@ export class Btn {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
export default
|
|
20
|
+
export default DKBtn
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import React, { ReactNode, useEffect, useState } from 'react'
|
|
1
|
+
import React, { ReactNode, useEffect, useRef, useState } from 'react'
|
|
2
2
|
import { makeObservable } from 'mobx'
|
|
3
3
|
import { Keyboard, KeyboardProps } from './Base'
|
|
4
4
|
import { observer } from 'mobx-react'
|
|
5
5
|
import { clamp } from 'lodash'
|
|
6
6
|
import { View } from '../view'
|
|
7
|
-
import
|
|
7
|
+
import { DKBtn } from './Btn'
|
|
8
8
|
import { Popup } from '../popup'
|
|
9
9
|
|
|
10
10
|
/** 是否小程序端 */
|
|
@@ -30,6 +30,7 @@ export type DigitalKeyboardProps = Omit<KeyboardProps, 'value' | 'int'> & {
|
|
|
30
30
|
min?: number
|
|
31
31
|
/** 最大值 */
|
|
32
32
|
max?: number
|
|
33
|
+
withUseRef?: boolean
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
export class DigitalKeyboard {
|
|
@@ -45,11 +46,12 @@ export class DigitalKeyboard {
|
|
|
45
46
|
min,
|
|
46
47
|
max,
|
|
47
48
|
style,
|
|
49
|
+
withUseRef = true,
|
|
48
50
|
...rest
|
|
49
51
|
}: DigitalKeyboardProps) {
|
|
50
52
|
this.form = form
|
|
51
53
|
this.active = active || Object.keys(form)[0]
|
|
52
|
-
const
|
|
54
|
+
const Node = observer(() => {
|
|
53
55
|
const sys = mp && wx.getSystemInfoSync()
|
|
54
56
|
const safeMargin =
|
|
55
57
|
withSafeArea && mp ? sys.screenHeight - sys.safeArea.bottom : 5
|
|
@@ -125,7 +127,7 @@ export class DigitalKeyboard {
|
|
|
125
127
|
</View>
|
|
126
128
|
)
|
|
127
129
|
})
|
|
128
|
-
this.
|
|
130
|
+
this.node = <Node />
|
|
129
131
|
makeObservable(this, {
|
|
130
132
|
form: true,
|
|
131
133
|
active: true,
|
|
@@ -135,6 +137,8 @@ export class DigitalKeyboard {
|
|
|
135
137
|
int: true,
|
|
136
138
|
setInt: true,
|
|
137
139
|
})
|
|
140
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
141
|
+
return withUseRef ? useRef(this).current : this
|
|
138
142
|
}
|
|
139
143
|
|
|
140
144
|
active: string
|
|
@@ -144,7 +148,7 @@ export class DigitalKeyboard {
|
|
|
144
148
|
}
|
|
145
149
|
|
|
146
150
|
/** 键盘组件 */
|
|
147
|
-
readonly
|
|
151
|
+
readonly node: ReactNode
|
|
148
152
|
/** 整数型键盘 */
|
|
149
153
|
int = false
|
|
150
154
|
/** 设置为整数型键盘 */
|
|
@@ -156,8 +160,8 @@ export class DigitalKeyboard {
|
|
|
156
160
|
/** 自定义功能按钮 */
|
|
157
161
|
get actionKeys() {
|
|
158
162
|
return [
|
|
159
|
-
new
|
|
160
|
-
new
|
|
163
|
+
new DKBtn({ label: '清零', fn: (_) => '' }),
|
|
164
|
+
new DKBtn({
|
|
161
165
|
label: '下一个',
|
|
162
166
|
className: 'm-bg-primary m-text-white',
|
|
163
167
|
fn: (value) => {
|
|
@@ -165,7 +169,7 @@ export class DigitalKeyboard {
|
|
|
165
169
|
return this.form[this.active]
|
|
166
170
|
},
|
|
167
171
|
}),
|
|
168
|
-
new
|
|
172
|
+
new DKBtn({
|
|
169
173
|
label: '确认',
|
|
170
174
|
flex: 2,
|
|
171
175
|
className: 'm-bg-primary m-text-white',
|
|
@@ -211,7 +215,7 @@ export class DigitalKeyboard {
|
|
|
211
215
|
disabledHeader: true,
|
|
212
216
|
disabledAnimate: false,
|
|
213
217
|
bottom: true,
|
|
214
|
-
children: this.
|
|
218
|
+
children: this.node,
|
|
215
219
|
})
|
|
216
220
|
mp && wx.hideKeyboard()
|
|
217
221
|
}
|
|
@@ -222,4 +226,4 @@ export class DigitalKeyboard {
|
|
|
222
226
|
}
|
|
223
227
|
export default DigitalKeyboard
|
|
224
228
|
|
|
225
|
-
export {
|
|
229
|
+
export { DKBtn } from './Btn'
|
|
@@ -3,7 +3,7 @@ import { Story } from '@storybook/react'
|
|
|
3
3
|
import { TextField } from '../text_field'
|
|
4
4
|
import { DigitalKeyboard, DigitalKeyboardProps } from '.'
|
|
5
5
|
import { Text } from '../text'
|
|
6
|
-
import {
|
|
6
|
+
import { DKBtn } from './Btn'
|
|
7
7
|
import { View } from '../view'
|
|
8
8
|
import { Toast } from '../toast'
|
|
9
9
|
import { Page } from '../page'
|
|
@@ -19,19 +19,17 @@ const Template: Story<DigitalKeyboardProps> = (args) => {
|
|
|
19
19
|
apple: '1.00',
|
|
20
20
|
peach: '0.50',
|
|
21
21
|
}
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
})
|
|
34
|
-
)
|
|
22
|
+
const keyboard = new DigitalKeyboard({
|
|
23
|
+
...args,
|
|
24
|
+
form: form,
|
|
25
|
+
active: '',
|
|
26
|
+
async onAction(btn) {
|
|
27
|
+
if (btn.label === '确认') {
|
|
28
|
+
console.log('result:', 'apple', keyboard.get('apple'))
|
|
29
|
+
keyboard.hide()
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
})
|
|
35
33
|
|
|
36
34
|
return (
|
|
37
35
|
<View style={{ height: '300px' }}>
|
|
@@ -60,7 +58,7 @@ const Template: Story<DigitalKeyboardProps> = (args) => {
|
|
|
60
58
|
export const Usage = Template.bind({})
|
|
61
59
|
Usage.argTypes = {
|
|
62
60
|
form: {
|
|
63
|
-
description: '`Object`
|
|
61
|
+
description: '`Object` 表单的字段键值对,可以通过.set增改,通过.get读取',
|
|
64
62
|
type: {
|
|
65
63
|
required: true,
|
|
66
64
|
},
|
|
@@ -122,13 +120,13 @@ Usage.argTypes = {
|
|
|
122
120
|
},
|
|
123
121
|
onInput: {
|
|
124
122
|
description:
|
|
125
|
-
'`(value: string | undefined, key:
|
|
123
|
+
'`(value: string | undefined, key: DKBtn) => void` 虚拟键盘的点击事件',
|
|
126
124
|
control: false,
|
|
127
125
|
type: {},
|
|
128
126
|
},
|
|
129
127
|
onAction: {
|
|
130
128
|
description:
|
|
131
|
-
'`(value: string | undefined, key:
|
|
129
|
+
'`(value: string | undefined, key: DKBtn) => void` 虚拟键盘的功能键(actionKeys)点击事件',
|
|
132
130
|
control: false,
|
|
133
131
|
type: {},
|
|
134
132
|
},
|
|
@@ -154,7 +152,7 @@ Usage.argTypes = {
|
|
|
154
152
|
name: 'function',
|
|
155
153
|
},
|
|
156
154
|
},
|
|
157
|
-
'.
|
|
155
|
+
'.node': {
|
|
158
156
|
description: '`ReactComponent` 键盘组件节点',
|
|
159
157
|
type: {
|
|
160
158
|
name: 'function',
|
|
@@ -210,12 +208,10 @@ export const CustomLayout = () => {
|
|
|
210
208
|
apple: '1.00',
|
|
211
209
|
peach: '0.50',
|
|
212
210
|
}
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
})
|
|
218
|
-
)
|
|
211
|
+
const keyboard = new DigitalKeyboard({
|
|
212
|
+
form: form,
|
|
213
|
+
active: '',
|
|
214
|
+
})
|
|
219
215
|
|
|
220
216
|
return (
|
|
221
217
|
<Page style={{ width: '100%' }}>
|
|
@@ -228,7 +224,7 @@ export const CustomLayout = () => {
|
|
|
228
224
|
头部
|
|
229
225
|
</Flex>
|
|
230
226
|
<View>显示在指定位置</View>
|
|
231
|
-
<View>{keyboard.
|
|
227
|
+
<View>{keyboard.node}</View>
|
|
232
228
|
<Flex
|
|
233
229
|
height='100px'
|
|
234
230
|
className='m-bg-accent m-margin-tb-10'
|
|
@@ -246,7 +242,7 @@ export const CustomActions = () => {
|
|
|
246
242
|
class Keyboard extends DigitalKeyboard {
|
|
247
243
|
get actionKeys() {
|
|
248
244
|
return [
|
|
249
|
-
new
|
|
245
|
+
new DKBtn({
|
|
250
246
|
className: 'm-bg-accent m-text-white',
|
|
251
247
|
label: '自定义',
|
|
252
248
|
fn: (value) => {
|
|
@@ -254,7 +250,7 @@ export const CustomActions = () => {
|
|
|
254
250
|
return '一键输入自定义内容'
|
|
255
251
|
},
|
|
256
252
|
}),
|
|
257
|
-
new
|
|
253
|
+
new DKBtn({
|
|
258
254
|
label: '确认',
|
|
259
255
|
flex: 3,
|
|
260
256
|
className: 'm-bg-primary m-text-white',
|
|
@@ -267,20 +263,18 @@ export const CustomActions = () => {
|
|
|
267
263
|
}
|
|
268
264
|
}
|
|
269
265
|
|
|
270
|
-
const
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
})
|
|
283
|
-
)
|
|
266
|
+
const keyboard = new Keyboard({
|
|
267
|
+
rewriteMode: true,
|
|
268
|
+
fractionDigits: 2,
|
|
269
|
+
min: 0,
|
|
270
|
+
max: 9999.99,
|
|
271
|
+
// 也可以通过这里自定义keys
|
|
272
|
+
// digitalKeys: [],
|
|
273
|
+
// actionKeys: [],
|
|
274
|
+
form: {
|
|
275
|
+
input: '',
|
|
276
|
+
},
|
|
277
|
+
})
|
|
284
278
|
return (
|
|
285
279
|
<View style={{ height: '300px' }}>
|
|
286
280
|
<TextField
|