@gm-pc/react 1.21.0 → 1.21.1-alpha.5

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-pc/react",
3
- "version": "1.21.0",
3
+ "version": "1.21.1-alpha.5",
4
4
  "description": "观麦前端基础组件库",
5
5
  "author": "liyatang <liyatang@qq.com>",
6
6
  "homepage": "https://github.com/gmfe/gm-pc#readme",
@@ -24,7 +24,7 @@
24
24
  "dependencies": {
25
25
  "@gm-common/hooks": "^2.10.0",
26
26
  "@gm-common/tool": "^2.10.0",
27
- "@gm-pc/locales": "^1.21.0",
27
+ "@gm-pc/locales": "^1.21.1-alpha.5",
28
28
  "big.js": "^6.0.1",
29
29
  "classnames": "^2.2.5",
30
30
  "lodash": "^4.17.19",
@@ -48,5 +48,5 @@
48
48
  "react-router-dom": "^5.2.0",
49
49
  "react-window": "^1.8.5"
50
50
  },
51
- "gitHead": "79604d9169f1202b19a501fcfe2a51d0a513f493"
51
+ "gitHead": "9fa8a4ec1cc2fd5edd7d9decdae5c557a4750afd"
52
52
  }
@@ -1,8 +1,9 @@
1
- import React, { FC, useState, MouseEvent, AnchorHTMLAttributes } from 'react'
1
+ import React, { FC, useState, MouseEvent, AnchorHTMLAttributes, useContext } from 'react'
2
2
  import _ from 'lodash'
3
3
  import classNames from 'classnames'
4
4
  import { is } from '@gm-common/tool'
5
5
  import { Loading } from '../loading'
6
+ import { ConfigContext } from '../config_provider'
6
7
 
7
8
  type ButtonType = 'default' | 'primary' | 'success' | 'danger' | 'link'
8
9
  type ButtonSize = 'small' | 'middle' | 'large'
@@ -36,6 +37,7 @@ const Button: FC<ButtonProps> = ({
36
37
  ...rest
37
38
  }) => {
38
39
  const [isLoading, setIsLoading] = useState(false)
40
+ const { fontSize } = useContext(ConfigContext)
39
41
 
40
42
  const loadFlag = loading || isLoading
41
43
 
@@ -69,8 +71,9 @@ const Button: FC<ButtonProps> = ({
69
71
  `gm-btn gm-btn-${type}`,
70
72
  {
71
73
  'gm-btn-block': block,
72
- [`gm-btn-${size}`]: size,
73
74
  'gm-btn-plain': type !== 'link' && plain,
75
+ [`gm-btn-${size}`]: size,
76
+ [`gm-btn-text-${fontSize}`]: !!fontSize,
74
77
  },
75
78
  className
76
79
  )}
@@ -77,6 +77,11 @@
77
77
  &:focus {
78
78
  outline: none;
79
79
  }
80
+
81
+ /** 字体大小 */
82
+ &.gm-btn-text-sm {
83
+ font-size: 14px;
84
+ }
80
85
  }
81
86
 
82
87
  @keyframes gm-btn-rotating {
@@ -0,0 +1,16 @@
1
+ import React, { FC } from 'react'
2
+ import { ConfigContext } from './context'
3
+
4
+ /** xs: 12px sm: 14px */
5
+ export type FontSizeType = 'xs' | 'sm'
6
+
7
+ export interface ConfigProviderProps {
8
+ fontSize?: FontSizeType
9
+ }
10
+
11
+ // 加一个div加上css var
12
+ const ConfigProvider: FC<ConfigProviderProps> = ({ children, ...config }) => {
13
+ return <ConfigContext.Provider value={config}>{children}</ConfigContext.Provider>
14
+ }
15
+
16
+ export default ConfigProvider
@@ -0,0 +1,10 @@
1
+ import { createContext } from 'react'
2
+ import { FontSizeType } from './config_provider'
3
+
4
+ export interface ConfigConsumerProps {
5
+ fontSize?: FontSizeType
6
+ }
7
+
8
+ export const ConfigContext = createContext<ConfigConsumerProps>({})
9
+
10
+ export const ConfigConsumer = ConfigContext.Consumer
@@ -0,0 +1,3 @@
1
+ export { default as ConfigProvider } from './config_provider'
2
+ export type { ConfigProviderProps } from './config_provider'
3
+ export * from './context'
@@ -4,6 +4,7 @@ import Dialog from './dialog'
4
4
  import { PromptProps } from './types'
5
5
  import { getLocale } from '@gm-pc/locales'
6
6
  import { Input } from '../input'
7
+ import { ConfigProvider } from '../config_provider'
7
8
 
8
9
  const Prompt = (props: string | PromptProps): Promise<string> => {
9
10
  let p = props
@@ -20,6 +21,7 @@ const Prompt = (props: string | PromptProps): Promise<string> => {
20
21
  defaultValue,
21
22
  placeholder,
22
23
  onValidate,
24
+ fontSize,
23
25
  ...rest
24
26
  } = p as PromptProps
25
27
 
@@ -43,24 +45,26 @@ const Prompt = (props: string | PromptProps): Promise<string> => {
43
45
  }
44
46
 
45
47
  const child = (
46
- <div>
48
+ <ConfigProvider fontSize={fontSize}>
47
49
  <div>
48
- <Input
49
- type='text'
50
- defaultValue={value}
51
- onChange={(e: ChangeEvent<HTMLInputElement>) => {
52
- value = e.target.value
53
- }}
54
- placeholder={placeholder}
55
- onKeyDown={(e: KeyboardEvent) => {
56
- if (e.key === 'Enter') {
57
- handleOk()
58
- }
59
- }}
60
- />
50
+ <div>
51
+ <Input
52
+ type='text'
53
+ defaultValue={value}
54
+ onChange={(e: ChangeEvent<HTMLInputElement>) => {
55
+ value = e.target.value
56
+ }}
57
+ placeholder={placeholder}
58
+ onKeyDown={(e: KeyboardEvent) => {
59
+ if (e.key === 'Enter') {
60
+ handleOk()
61
+ }
62
+ }}
63
+ />
64
+ </div>
65
+ {children}
61
66
  </div>
62
- {children}
63
- </div>
67
+ </ConfigProvider>
64
68
  )
65
69
 
66
70
  Dialog.render({
@@ -4,6 +4,7 @@ import Alert from './alert'
4
4
  import Confirm from './confirm'
5
5
  import Prompt from './prompt'
6
6
  import Delete from './delete_com'
7
+ import { ConfigProvider } from '../config_provider'
7
8
 
8
9
  export const ComDialog = () => {
9
10
  return (
@@ -156,6 +157,7 @@ export const ComPrompt = () => {
156
157
  <button
157
158
  onClick={() => {
158
159
  Prompt({
160
+ fontSize: 'sm',
159
161
  size: 'sm',
160
162
  children: '请填写,< 5 不通过',
161
163
  // @ts-ignore
@@ -182,6 +184,12 @@ export const ComPrompt = () => {
182
184
  )
183
185
  }
184
186
 
187
+ export const ComPromptFontSize = () => (
188
+ <ConfigProvider fontSize='sm'>
189
+ <ComPrompt />
190
+ </ConfigProvider>
191
+ )
192
+
185
193
  export default {
186
194
  title: '反馈/Dialog',
187
195
  }
@@ -1,5 +1,6 @@
1
1
  import { HTMLAttributes, ReactNode } from 'react'
2
2
  import { ButtonType } from '../button'
3
+ import { ConfigProviderProps } from '../config_provider'
3
4
 
4
5
  type DialogSize = 'sm' | 'md' | 'lg' | 'xl'
5
6
 
@@ -12,7 +13,7 @@ interface DialogButtonProps {
12
13
  disabled?: boolean
13
14
  }
14
15
 
15
- interface DialogProps {
16
+ interface DialogProps extends ConfigProviderProps {
16
17
  title?: string
17
18
  size?: DialogSize
18
19
  buttons?: DialogButtonProps[]
@@ -42,7 +43,7 @@ interface ConfirmProps extends SpecificDialogProps {
42
43
  read?: boolean | string
43
44
  }
44
45
 
45
- interface PromptProps extends ConfirmProps {
46
+ interface PromptProps extends ConfirmProps, ConfigProviderProps {
46
47
  defaultValue?: string
47
48
  placeholder?: string
48
49
  }
@@ -11,6 +11,7 @@ import classNames from 'classnames'
11
11
  import FormContext from './context'
12
12
  import Validator from '../../validator'
13
13
  import { FormProps, FormItemProps } from './types'
14
+ import { ConfigConsumer } from '../config_provider'
14
15
  const { Provider } = FormContext
15
16
 
16
17
  interface FormState {
@@ -117,14 +118,22 @@ class Form extends Component<FormProps, FormState> {
117
118
  <Provider
118
119
  value={{ labelWidth, disabledCol, inline, btnPosition, colWidth, canValidate }}
119
120
  >
120
- <form
121
- {...rest}
122
- className={classNames('gm-form', { 'form-inline': inline }, className)}
123
- onSubmit={this._handleSubmit}
124
- >
125
- {children}
126
- {hasButtonInGroup && <button type='submit' style={{ display: 'none' }} />}
127
- </form>
121
+ <ConfigConsumer>
122
+ {({ fontSize }) => (
123
+ <form
124
+ {...rest}
125
+ className={classNames(
126
+ 'gm-form',
127
+ { 'form-inline': inline, [`gm-form-text-${fontSize}`]: fontSize },
128
+ className
129
+ )}
130
+ onSubmit={this._handleSubmit}
131
+ >
132
+ {children}
133
+ {hasButtonInGroup && <button type='submit' style={{ display: 'none' }} />}
134
+ </form>
135
+ )}
136
+ </ConfigConsumer>
128
137
  </Provider>
129
138
  )
130
139
  }
@@ -58,6 +58,19 @@
58
58
  right: -28px;
59
59
  top: 7px;
60
60
  }
61
+
62
+ /** 字体大小 */
63
+ &.gm-form-text-sm {
64
+ font-size: var(--gm-size-text-sm);
65
+
66
+ .gm-form-label {
67
+ font-size: var(--gm-size-text-sm);
68
+ }
69
+
70
+ .gm-form-control {
71
+ font-size: var(--gm-size-text-sm);
72
+ }
73
+ }
61
74
  }
62
75
 
63
76
  @media (max-width: 768px) {
@@ -5,6 +5,7 @@ import Overlay from './overlay'
5
5
  import { Button } from '../button'
6
6
  import { getLocale } from '@gm-pc/locales'
7
7
  import { IconDownUp } from '../icon_down_up'
8
+ import { ConfigConsumer, ConfigProvider } from '../config_provider'
8
9
 
9
10
  interface InnerProps extends HTMLAttributes<HTMLDivElement> {
10
11
  disabled: boolean
@@ -59,16 +60,24 @@ class FunctionSet extends Component<FunctionSetProps> {
59
60
  return null
60
61
  }
61
62
  return (
62
- <Popover
63
- ref={this._popoverRef}
64
- popup={<Overlay data={newData} onSelect={this._handleSelect} isReverse={right} />}
65
- right={right}
66
- type='hover'
67
- disabled={disabled}
68
- pureContainer
69
- >
70
- <Inner disabled={!!disabled}>{children}</Inner>
71
- </Popover>
63
+ <ConfigConsumer>
64
+ {(config) => (
65
+ <Popover
66
+ ref={this._popoverRef}
67
+ popup={
68
+ <ConfigProvider {...config}>
69
+ <Overlay data={newData} onSelect={this._handleSelect} isReverse={right} />
70
+ </ConfigProvider>
71
+ }
72
+ right={right}
73
+ type='hover'
74
+ disabled={disabled}
75
+ pureContainer
76
+ >
77
+ <Inner disabled={!!disabled}>{children}</Inner>
78
+ </Popover>
79
+ )}
80
+ </ConfigConsumer>
72
81
  )
73
82
  }
74
83
  }
@@ -1,17 +1,21 @@
1
- import React, { forwardRef, InputHTMLAttributes } from 'react'
1
+ import React, { forwardRef, InputHTMLAttributes, useContext } from 'react'
2
2
  import classNames from 'classnames'
3
+ import { ConfigContext } from '../config_provider'
3
4
 
4
5
  type InputProps = InputHTMLAttributes<HTMLInputElement>
5
6
 
6
7
  /** 没什么,就一个input,多了个类名 gm-input 用来和库配合做UI */
7
8
  const Input = forwardRef<HTMLInputElement, InputProps>((props, ref) => {
8
9
  const { className, value = '', ...rest } = props
10
+ const { fontSize } = useContext(ConfigContext)
9
11
  return (
10
12
  <input
11
13
  ref={ref}
12
14
  {...rest}
13
15
  value={value}
14
- className={classNames('gm-input', className)}
16
+ className={classNames('gm-input', className, {
17
+ [`gm-input-${fontSize}`]: fontSize,
18
+ })}
15
19
  />
16
20
  )
17
21
  })
@@ -2,6 +2,11 @@
2
2
  .gmFormControl();
3
3
 
4
4
  .gmDisabledBgWith();
5
+
6
+ /** 字体大小 */
7
+ &.gm-input-sm {
8
+ font-size: var(--gm-size-text-sm);
9
+ }
5
10
  }
6
11
 
7
12
  .gm-input-close {
@@ -7,6 +7,7 @@ import { LevelList } from '../level_list'
7
7
  import { getLevel } from '../level_list/utils'
8
8
  import _ from 'lodash'
9
9
  import { judgeFunction } from '../../common/utils'
10
+ import { ConfigConsumer, ConfigProvider, ConfigProviderProps } from '../config_provider'
10
11
 
11
12
  interface LevelSelectState<V> {
12
13
  willActiveSelected: V[]
@@ -48,22 +49,24 @@ class LevelSelect<V = any> extends Component<LevelSelectProps<V>, LevelSelectSta
48
49
  this.setState({ willActiveSelected })
49
50
  }
50
51
 
51
- private _renderPopup = (): ReactNode => {
52
+ private _renderPopup = (config: ConfigProviderProps): ReactNode => {
52
53
  const { titles, data, selected, right, onlySelectLeaf } = this.props
53
54
  const { willActiveSelected } = this.state
54
55
  return (
55
- <Flex justifyEnd={right}>
56
- <LevelList<V>
57
- isReverse={right}
58
- data={data}
59
- onWillActiveSelect={this._handleWillActiveSelect}
60
- willActiveSelected={willActiveSelected}
61
- selected={selected}
62
- onSelect={this._handleSelect}
63
- titles={titles}
64
- onlySelectLeaf={onlySelectLeaf}
65
- />
66
- </Flex>
56
+ <ConfigProvider {...config}>
57
+ <Flex justifyEnd={right}>
58
+ <LevelList<V>
59
+ isReverse={right}
60
+ data={data}
61
+ onWillActiveSelect={this._handleWillActiveSelect}
62
+ willActiveSelected={willActiveSelected}
63
+ selected={selected}
64
+ onSelect={this._handleSelect}
65
+ titles={titles}
66
+ onlySelectLeaf={onlySelectLeaf}
67
+ />
68
+ </Flex>
69
+ </ConfigProvider>
67
70
  )
68
71
  }
69
72
 
@@ -192,16 +195,20 @@ class LevelSelect<V = any> extends Component<LevelSelectProps<V>, LevelSelectSta
192
195
  render() {
193
196
  const { disabled, children, popoverType, right } = this.props
194
197
  return (
195
- <Popover
196
- ref={this._popoverRef}
197
- right={right}
198
- disabled={disabled}
199
- popup={this._renderPopup()}
200
- type={popoverType}
201
- pureContainer
202
- >
203
- {children ?? this._renderTarget()}
204
- </Popover>
198
+ <ConfigConsumer>
199
+ {(config) => (
200
+ <Popover
201
+ ref={this._popoverRef}
202
+ right={right}
203
+ disabled={disabled}
204
+ popup={this._renderPopup(config)}
205
+ type={popoverType}
206
+ pureContainer
207
+ >
208
+ {children ?? this._renderTarget()}
209
+ </Popover>
210
+ )}
211
+ </ConfigConsumer>
205
212
  )
206
213
  }
207
214
  }
@@ -3,6 +3,7 @@ import classNames from 'classnames'
3
3
  import { xor, flatMap, isNil, noop } from 'lodash'
4
4
  import { ListBaseProps } from './types'
5
5
  import { ListDataItem } from '../../types'
6
+ import { ConfigConsumer } from '../config_provider'
6
7
 
7
8
  class Base<V = any> extends Component<ListBaseProps<V>> {
8
9
  static defaultProps = {
@@ -83,34 +84,45 @@ class Base<V = any> extends Component<ListBaseProps<V>> {
83
84
 
84
85
  let sequenceDataIndex = -1
85
86
  return (
86
- <div
87
- {...rest}
88
- ref={this._listRef}
89
- className={classNames('gm-list', { 'gm-list-group': isGroupList }, className)}
90
- >
91
- {data.map((group, gIndex) => (
92
- <div key={gIndex} className='gm-list-group-item'>
93
- <div className='gm-list-label'>{group.label}</div>
94
- {group.children.map((item, index) => {
95
- sequenceDataIndex++
96
- return (
97
- <div
98
- key={`${index}_${item.value}`}
99
- {...getItemProps!(item)}
100
- className={classNames('gm-list-item', {
101
- active: selected.includes(item.value),
102
- 'will-active': willActiveIndex === sequenceDataIndex,
103
- disabled: item.disabled,
104
- })}
105
- onClick={() => this._handleSelect(item)}
106
- >
107
- {renderItem!(item, index)}
108
- </div>
109
- )
110
- })}
87
+ <ConfigConsumer>
88
+ {({ fontSize }) => (
89
+ <div
90
+ {...rest}
91
+ ref={this._listRef}
92
+ className={classNames(
93
+ 'gm-list',
94
+ {
95
+ 'gm-list-group': isGroupList,
96
+ [`gm-list-text-${fontSize}`]: fontSize,
97
+ },
98
+ className
99
+ )}
100
+ >
101
+ {data.map((group, gIndex) => (
102
+ <div key={gIndex} className='gm-list-group-item'>
103
+ <div className='gm-list-label'>{group.label}</div>
104
+ {group.children.map((item, index) => {
105
+ sequenceDataIndex++
106
+ return (
107
+ <div
108
+ key={`${index}_${item.value}`}
109
+ {...getItemProps!(item)}
110
+ className={classNames('gm-list-item', {
111
+ active: selected.includes(item.value),
112
+ 'will-active': willActiveIndex === sequenceDataIndex,
113
+ disabled: item.disabled,
114
+ })}
115
+ onClick={() => this._handleSelect(item)}
116
+ >
117
+ {renderItem!(item, index)}
118
+ </div>
119
+ )
120
+ })}
121
+ </div>
122
+ ))}
111
123
  </div>
112
- ))}
113
- </div>
124
+ )}
125
+ </ConfigConsumer>
114
126
  )
115
127
  }
116
128
  }
@@ -48,4 +48,11 @@
48
48
  padding: 9px 10px 9px 22px;
49
49
  }
50
50
  }
51
+
52
+ /** 字体大小 */
53
+ &.gm-list-text-sm {
54
+ .gm-list-item {
55
+ font-size: var(--gm-size-text-sm);
56
+ }
57
+ }
51
58
  }