File tree 15 files changed +179
-14
lines changed
15 files changed +179
-14
lines changed Original file line number Diff line number Diff line change 9
9
"**/demo/**/*.jsx"
10
10
],
11
11
"rules": {
12
- "no-console": "off"
12
+ "no-console": "off",
13
+ "no-alert": "off"
13
14
}
14
15
}
15
16
]
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ const mobileComponent: ComponentMenus = {
10
10
dataEntry : [ ] ,
11
11
feedback : [
12
12
'src/base-popup' ,
13
+ 'src/base-mask' ,
13
14
] ,
14
15
guidance : [ ] ,
15
16
other : [ ] ,
Original file line number Diff line number Diff line change
1
+ import React , { useRef } from 'react'
2
+ import type { UseModalEnhancedAction , UseModalEnhancedContext } from '@template-pro/mobile-ui'
3
+ import { BaseMask , Button } from '@template-pro/mobile-ui'
4
+ import styles from './style.less'
5
+
6
+ const Content = ( { enhancedAction } : Partial < UseModalEnhancedContext > ) => (
7
+ < div className = { styles . overlayContent } >
8
+ < h3 > 这是背景蒙层内容</ h3 >
9
+ < Button onClick = { enhancedAction ?. close } >
10
+ 点击关闭背景蒙层
11
+ </ Button >
12
+ </ div >
13
+ )
14
+
15
+ function App ( ) {
16
+ const maskRef = useRef < UseModalEnhancedAction > ( null )
17
+ return (
18
+ < >
19
+ < BaseMask
20
+ trigger = { < Button > 打开背景蒙层</ Button > }
21
+ actionRef = { maskRef }
22
+ onMaskClick = { ( ) => window . console . log ( '点击了背景蒙层' ) }
23
+ >
24
+ < Content />
25
+ </ BaseMask >
26
+
27
+ < Button onClick = { ( ) => maskRef . current ?. open ( ) } > App ref 打开背景蒙层</ Button >
28
+ </ >
29
+ )
30
+ }
31
+
32
+ export default App
Original file line number Diff line number Diff line change
1
+ import React from 'react'
2
+ import { BaseMask } from '@template-pro/mobile-ui'
3
+ import { Button , Toast } from 'antd-mobile'
4
+ import styles from './style.less'
5
+
6
+ export default ( ) => (
7
+ < >
8
+ < BaseMask
9
+ trigger = { < Button > Click me</ Button > }
10
+ onClick = { ( event , action ) => {
11
+ window . console . log ( { event, action } )
12
+ Toast . show ( {
13
+ content : '1秒后打开背景蒙层' ,
14
+ icon : 'loading' ,
15
+ duration : 1000 ,
16
+ afterClose ( ) {
17
+ action . open ( )
18
+ setTimeout ( ( ) => {
19
+ Toast . show ( {
20
+ content : '1秒后关闭背景蒙层' ,
21
+ duration : 1000 ,
22
+ afterClose : action . close ,
23
+ } )
24
+ } , 500 )
25
+ } ,
26
+ } )
27
+ } }
28
+ >
29
+ < div className = { styles . overlayContent } > 这是背景蒙层内容</ div >
30
+ </ BaseMask >
31
+ </ >
32
+ )
Original file line number Diff line number Diff line change
1
+ .overlayContent {
2
+ position : absolute ;
3
+ top : 50% ;
4
+ left : 50% ;
5
+ display : flex ;
6
+ flex-direction : column ;
7
+ align-items : center ;
8
+ justify-content : space-around ;
9
+ width : 200px ;
10
+ height : 200px ;
11
+ margin-top : -100px ;
12
+ margin-left : -100px ;
13
+ background : white ;
14
+ border-radius : 16px ;
15
+ }
Original file line number Diff line number Diff line change
1
+ # BaseMask
2
+
3
+ ## 基础用法
4
+
5
+ <code hideActions =' ["CSB", "EXTERNAL"] ' src =" ./demo/Base.tsx " />
6
+
7
+ ## 通过事件手动控制打开
8
+
9
+ <code hideActions =' ["CSB", "EXTERNAL"] ' src =" ./demo/Event.tsx " />
Original file line number Diff line number Diff line change
1
+ import React from 'react'
2
+ import classNames from 'classnames'
3
+ import type { MaskProps } from 'antd-mobile/es/components/mask'
4
+ import Mask from 'antd-mobile/es/components/mask'
5
+ import type { UseModalEnhancedProps } from '@template-pro/utils'
6
+ import { useModalEnhanced } from '@template-pro/utils'
7
+ import { defaultPrefixCls } from '../constants'
8
+
9
+ export type BaseMaskProps = MaskProps & Omit < UseModalEnhancedProps , 'content' > & {
10
+ trigger ?: React . ReactNode
11
+ }
12
+
13
+ const BaseMask = ( props : BaseMaskProps ) => {
14
+ const {
15
+ className,
16
+ children,
17
+ trigger : propsTrigger ,
18
+ afterClose,
19
+ ...restProps
20
+ } = props
21
+
22
+ const [
23
+ visible ,
24
+ { close } ,
25
+ { trigger, content } ,
26
+ ] = useModalEnhanced ( {
27
+ children : propsTrigger ,
28
+ content : children ,
29
+ ...restProps ,
30
+ } )
31
+
32
+ const handleMaskClose = ( ) => {
33
+ afterClose ?.( )
34
+ close ( )
35
+ }
36
+
37
+ return (
38
+ < >
39
+ { trigger }
40
+ < Mask
41
+ visible = { visible }
42
+ afterClose = { handleMaskClose }
43
+ className = { classNames ( `${ defaultPrefixCls } -base-mask` , className ) }
44
+ destroyOnClose
45
+ { ...restProps }
46
+ >
47
+ { content }
48
+ </ Mask >
49
+ </ >
50
+ )
51
+ }
52
+
53
+ export default BaseMask
Original file line number Diff line number Diff line change
1
+ @import (less ) ' ~antd-mobile/es/components/mask/mask.css' ;
2
+ @import ' ../../styles/themes/default.less' ;
3
+
4
+ .@{cls-prefix} -base-mask {
5
+
6
+ }
Original file line number Diff line number Diff line change
1
+ import './index.less'
Original file line number Diff line number Diff line change 1
1
import React , { useRef } from 'react'
2
- import { Button } from 'antd-mobile'
3
2
import type { UseModalEnhancedAction , UseModalEnhancedContext } from '@template-pro/mobile-ui'
4
- import { BasePopup } from '@template-pro/mobile-ui'
3
+ import { BasePopup , Button } from '@template-pro/mobile-ui'
5
4
6
5
const Content = ( { enhancedAction } : Partial < UseModalEnhancedContext > ) => (
7
6
< div style = { { padding : 24 } } >
@@ -13,16 +12,22 @@ const Content = ({ enhancedAction }: Partial<UseModalEnhancedContext>) => (
13
12
)
14
13
15
14
function App ( ) {
16
- const drawerRef = useRef < UseModalEnhancedAction > ( null )
15
+ const popupRef = useRef < UseModalEnhancedAction > ( null )
17
16
18
17
return (
19
- < BasePopup
20
- content = { < Content /> }
21
- bodyStyle = { { height : '40vh' } }
22
- actionRef = { drawerRef }
23
- >
24
- < Button > 打开弹出层</ Button >
25
- </ BasePopup >
18
+ < >
19
+ < BasePopup
20
+ content = { < Content /> }
21
+ bodyStyle = { { height : '40vh' } }
22
+ actionRef = { popupRef }
23
+ >
24
+ < Button > 打开弹出层</ Button >
25
+ </ BasePopup >
26
+
27
+ < Button onClick = { ( ) => popupRef . current ?. open ( ) } >
28
+ App ref 打开弹出层
29
+ </ Button >
30
+ </ >
26
31
)
27
32
}
28
33
Original file line number Diff line number Diff line change 1
1
import React from 'react'
2
- import { BasePopup } from '@template-pro/mobile-ui'
3
- import { Button , Toast } from 'antd-mobile'
2
+ import { BasePopup , Button } from '@template-pro/mobile-ui'
3
+ import { Toast } from 'antd-mobile'
4
4
5
5
export default ( ) => (
6
6
< >
Original file line number Diff line number Diff line change 2
2
@import ' ../../styles/themes/default.less' ;
3
3
4
4
.@{cls-prefix} -button {
5
- box-sizing : border-box ;
5
+
6
6
}
Original file line number Diff line number Diff line change @@ -4,6 +4,9 @@ export { default as Button } from './button'
4
4
export type { BasePopupProps } from './base-popup'
5
5
export { default as BasePopup } from './base-popup'
6
6
7
+ export type { BaseMaskProps } from './base-mask'
8
+ export { default as BaseMask } from './base-mask'
9
+
7
10
// Third-party library
8
11
export { ConditionInput } from '@template-pro/rc-ui'
9
12
export type { ConditionInputProps , ConditionInputCoverProps } from '@template-pro/rc-ui'
Original file line number Diff line number Diff line change 17
17
"@template-pro/utils" : [" ./packages/utils/src/index" ]
18
18
},
19
19
"types" : [" node" , " jest" ],
20
+ "typeRoots" : [" ./typings" , " ./node_modules/@types" ],
20
21
"allowSyntheticDefaultImports" : true ,
21
22
"skipLibCheck" : true ,
22
23
"declaration" : false ,
Original file line number Diff line number Diff line change
1
+ declare module '*.less' {
2
+ const value : {
3
+ [ key : string ] : string
4
+ }
5
+ export = value
6
+ }
You can’t perform that action at this time.
0 commit comments