@gm-mobile/c-react 3.9.3-beta.3 → 3.9.3-beta.8

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gm-mobile/c-react",
3
- "version": "3.9.3-beta.3",
3
+ "version": "3.9.3-beta.8",
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.3-beta.3",
25
- "@gm-mobile/c-tool": "^3.9.3-beta.3",
26
- "@gm-mobile/locales": "^3.9.3-beta.3"
24
+ "@gm-mobile/c-font": "^3.9.3-beta.8",
25
+ "@gm-mobile/c-tool": "^3.9.3-beta.8",
26
+ "@gm-mobile/locales": "^3.9.3-beta.8"
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": "9f44aa37c49971d60bc29358ce64aaf0c0d15ed8"
36
+ "gitHead": "1a399bd891e2971777a509ddf1968d77dcd514a7"
37
37
  }
@@ -73,7 +73,9 @@ export const Button: FC<ButtonProps> = ({
73
73
  onClick={handleClick}
74
74
  >
75
75
  {loadFlag && <Loading className='m-btn-loading' />}
76
- <Flex alignCenter>{children}</Flex>
76
+ <Flex alignCenter justifyCenter style={{ display: 'inline-flex' }}>
77
+ {children}
78
+ </Flex>
77
79
  </BaseButton>
78
80
  )
79
81
  }
@@ -5,5 +5,6 @@ export { default as MultipleCalendar } from './multiple_calendar'
5
5
  export type {
6
6
  BaseCalendarProps,
7
7
  RangeCalendarProps,
8
+ CalendarProps,
8
9
  MultipleCalendarProps,
9
10
  } from './types'
@@ -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
  }
@@ -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 Btn from './Btn'
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 Btn({ label: v })),
15
- ...['4', '5', '6'].map((v, _) => new Btn({ label: v })),
16
- ...['1', '2', '3'].map((v, _) => new Btn({ label: v })),
17
- new Btn({ label: '0' }),
18
- new Btn({
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 Btn({
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 Btn({ label: '取消', fn: (_) => '' }),
43
- new Btn({ label: '完成', className: 'm-bg-primary' }),
44
- new Btn({
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: Btn) => void
60
+ onInput?: (value: string | undefined, key: DKBtn) => void
61
61
  /** 虚拟键盘的功能键(actionKeys)点击事件 */
62
- onAction?: (key: Btn) => void
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: 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 Btn {
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 }: Btn) {
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 Btn
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 Btn from './Btn'
7
+ import { DKBtn } from './Btn'
8
8
  import { Popup } from '../popup'
9
9
 
10
10
  /** 是否小程序端 */
@@ -49,7 +49,7 @@ export class DigitalKeyboard {
49
49
  }: DigitalKeyboardProps) {
50
50
  this.form = form
51
51
  this.active = active || Object.keys(form)[0]
52
- const Children = observer(() => {
52
+ const Node = observer(() => {
53
53
  const sys = mp && wx.getSystemInfoSync()
54
54
  const safeMargin =
55
55
  withSafeArea && mp ? sys.screenHeight - sys.safeArea.bottom : 5
@@ -125,7 +125,7 @@ export class DigitalKeyboard {
125
125
  </View>
126
126
  )
127
127
  })
128
- this.children = <Children />
128
+ this.node = <Node />
129
129
  makeObservable(this, {
130
130
  form: true,
131
131
  active: true,
@@ -135,6 +135,8 @@ export class DigitalKeyboard {
135
135
  int: true,
136
136
  setInt: true,
137
137
  })
138
+ // eslint-disable-next-line react-hooks/rules-of-hooks
139
+ return useRef(this).current
138
140
  }
139
141
 
140
142
  active: string
@@ -144,7 +146,7 @@ export class DigitalKeyboard {
144
146
  }
145
147
 
146
148
  /** 键盘组件 */
147
- readonly children: ReactNode
149
+ readonly node: ReactNode
148
150
  /** 整数型键盘 */
149
151
  int = false
150
152
  /** 设置为整数型键盘 */
@@ -156,8 +158,8 @@ export class DigitalKeyboard {
156
158
  /** 自定义功能按钮 */
157
159
  get actionKeys() {
158
160
  return [
159
- new Btn({ label: '清零', fn: (_) => '' }),
160
- new Btn({
161
+ new DKBtn({ label: '清零', fn: (_) => '' }),
162
+ new DKBtn({
161
163
  label: '下一个',
162
164
  className: 'm-bg-primary m-text-white',
163
165
  fn: (value) => {
@@ -165,7 +167,7 @@ export class DigitalKeyboard {
165
167
  return this.form[this.active]
166
168
  },
167
169
  }),
168
- new Btn({
170
+ new DKBtn({
169
171
  label: '确认',
170
172
  flex: 2,
171
173
  className: 'm-bg-primary m-text-white',
@@ -211,7 +213,7 @@ export class DigitalKeyboard {
211
213
  disabledHeader: true,
212
214
  disabledAnimate: false,
213
215
  bottom: true,
214
- children: this.children,
216
+ children: this.node,
215
217
  })
216
218
  mp && wx.hideKeyboard()
217
219
  }
@@ -222,4 +224,4 @@ export class DigitalKeyboard {
222
224
  }
223
225
  export default DigitalKeyboard
224
226
 
225
- export { Btn } from './Btn'
227
+ 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 { Btn } from './Btn'
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 { current: keyboard } = useRef(
23
- new DigitalKeyboard({
24
- ...args,
25
- form: form,
26
- active: '',
27
- async onAction(btn) {
28
- if (btn.label === '确认') {
29
- console.log('result:', 'apple', keyboard.get('apple'))
30
- keyboard.hide()
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' }}>
@@ -122,13 +120,13 @@ Usage.argTypes = {
122
120
  },
123
121
  onInput: {
124
122
  description:
125
- '`(value: string | undefined, key: Btn) => void` 虚拟键盘的点击事件',
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: Btn) => void` 虚拟键盘的功能键(actionKeys)点击事件',
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
- '.children': {
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 { current: keyboard } = useRef(
214
- new DigitalKeyboard({
215
- form: form,
216
- active: '',
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.children}</View>
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 Btn({
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 Btn({
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 { current: keyboard } = useRef(
271
- new Keyboard({
272
- rewriteMode: true,
273
- fractionDigits: 2,
274
- min: 0,
275
- max: 9999.99,
276
- // 也可以通过这里自定义keys
277
- // digitalKeys: [],
278
- // actionKeys: [],
279
- form: {
280
- input: '',
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
@@ -197,6 +197,7 @@ export const Draggable: FC<DraggableProps> = ({
197
197
  justifyContent: 'center',
198
198
  cursor: 'pointer',
199
199
  userSelect: 'none',
200
+ zIndex: 2,
200
201
  }
201
202
  const options: any = mp
202
203
  ? {
@@ -24,7 +24,6 @@ const LayoutRoot: FC & LayoutRootStatic = () => {
24
24
  [type]: component,
25
25
  }))
26
26
  }
27
-
28
27
  return () => {
29
28
  delete cbMap[path]
30
29
  }
@@ -170,6 +170,7 @@ export class TextField extends Component<TextFieldProps, TextFieldState> {
170
170
  onClick,
171
171
  onConfirm,
172
172
  fractionDigits,
173
+ alwaysEmbed = true,
173
174
  ...rest
174
175
  // 注意,不用传给input或area的props要在此列出来,不然rest会带过去
175
176
  } = this.props
@@ -207,6 +208,7 @@ export class TextField extends Component<TextFieldProps, TextFieldState> {
207
208
  focus,
208
209
  password,
209
210
  placeholderClass: 'text-field-placeholder',
211
+ alwaysEmbed: alwaysEmbed,
210
212
  onConfirm,
211
213
  })
212
214
  } else {
@@ -300,7 +302,9 @@ export class TextField extends Component<TextFieldProps, TextFieldState> {
300
302
  </Flex>
301
303
  )}
302
304
  <View
303
- className={classNames('text-field-error-message', errClassName)}
305
+ className={classNames('text-field-error-message', errClassName, {
306
+ 'has-error': err,
307
+ })}
304
308
  >
305
309
  {err}
306
310
  </View>
package/src/index.less CHANGED
@@ -42,6 +42,7 @@
42
42
  // 公共
43
43
  @import './less/mixin';
44
44
  @import './less/base';
45
+ @import './less/button';
45
46
  @import './less/distance';
46
47
  @import './less/bg';
47
48
  @import './less/display';
@@ -51,7 +52,6 @@
51
52
  @import './less/border';
52
53
  @import './less/animation';
53
54
  @import './less/shadow';
54
- @import './less/btn';
55
55
  @import './less/ellipsis';
56
56
  @import './less/lineheight';
57
- @import './less/opacity';
57
+ @import './less/opacity';
package/src/less/bg.less CHANGED
@@ -26,6 +26,10 @@
26
26
  background: var(--m-color-bg-accent-light) !important;
27
27
  }
28
28
 
29
+ .m-bg-transparent {
30
+ background: transparent !important;
31
+ }
32
+
29
33
  .m-bg-white-active-with {
30
34
  .mBgWhiteActiveWith();
31
35
  }
@@ -61,4 +65,7 @@ each(@colors,.(@color,@colorKey,@index){
61
65
  .generate-colors(@opacity+1);
62
66
  }
63
67
  .generate-colors(0);
68
+ .m-bg-@{colorKey}{
69
+ background-color: @color!important;
70
+ }
64
71
  });
@@ -46,7 +46,7 @@
46
46
  padding: 0 10px;
47
47
  border-radius: 3px;
48
48
  box-sizing: border-box;
49
- line-height: 1;
49
+ line-height: 2;
50
50
  min-height: @button-normal;
51
51
  cursor: pointer;
52
52
  user-select: none;
@@ -68,6 +68,7 @@
68
68
  }
69
69
  .m-button {
70
70
  .m-button-text();
71
+ line-height: 1;
71
72
  background-color: @button-with-white-text[default];
72
73
  }
73
74
 
@@ -112,6 +113,7 @@ each(@button-with-black-text,.(@value,@key,@index){
112
113
 
113
114
  .m-button-icon {
114
115
  .m-button-text();
116
+ line-height: 1;
115
117
  min-width: @button-normal;
116
118
  padding: 10px;
117
119
  border-radius: 50%;
@@ -1,27 +1,3 @@
1
- .m-text-20 {
2
- font-size: var(--m-size-text-20) !important;
3
- }
4
-
5
- .m-text-18 {
6
- font-size: var(--m-size-text-18) !important;
7
- }
8
-
9
- .m-text-16 {
10
- font-size: var(--m-size-text-16) !important;
11
- }
12
-
13
- .m-text-14 {
14
- font-size: var(--m-size-text-14) !important;
15
- }
16
-
17
- .m-text-12 {
18
- font-size: var(--m-size-text-12) !important;
19
- }
20
-
21
- .m-text-10 {
22
- font-size: var(--m-size-text-10) !important;
23
- }
24
-
25
1
  .m-text-center {
26
2
  text-align: center !important;
27
3
  }
@@ -123,4 +99,20 @@ each(@colors,.(@color,@colorKey,@index){
123
99
  .generate-colors(@opacity+1);
124
100
  }
125
101
  .generate-colors(0);
102
+ .m-text-@{colorKey}{
103
+ color: @color!important;
104
+ }
126
105
  });
106
+
107
+ // 生成size, .m-text-{8-32}, --m-size-text-{8-32}
108
+ .generate-size(@size) when (@size<=32) {
109
+ :root,
110
+ page {
111
+ --m-size-text-@{size}: ~'@{size}px';
112
+ }
113
+ .m-text-@{size} {
114
+ font-size: e(%('var(--m-size-text-%s)!important', @size));
115
+ }
116
+ .generate-size(@size + 2);
117
+ }
118
+ .generate-size(8);
@@ -91,14 +91,6 @@ page {
91
91
  // 非颜色
92
92
  :root,
93
93
  page {
94
- // 字体尺寸
95
- --m-size-text-10: 10px;
96
- --m-size-text-12: 12px;
97
- --m-size-text-14: 14px;
98
- --m-size-text-16: 16px;
99
- --m-size-text-18: 18px;
100
- --m-size-text-20: 20px;
101
-
102
94
  // line-height
103
95
  --m-size-line-height: 1.6;
104
96