Skip to content

Commit 73124b7

Browse files
committed
feat: mobile add basePopup components
1 parent 2bce795 commit 73124b7

File tree

12 files changed

+148
-19
lines changed

12 files changed

+148
-19
lines changed

config/config.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@ const config: IConfig = {
3535
'babel-plugin-import',
3636
{
3737
libraryName: 'antd-mobile',
38-
libraryDirectory: 'es',
39-
style: true,
38+
libraryDirectory: 'es/components',
39+
style: false,
40+
customStyleName: (name: string) => {
41+
return `antd-mobile/es/components/${name}/${name}.css`
42+
},
4043
},
4144
'antd-mobile',
4245
],

config/menus/mobile.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ const mobileComponent: ComponentMenus = {
88
navigation: [],
99
dataDisplay: [],
1010
dataEntry: [],
11-
feedback: [],
11+
feedback: [
12+
'src/base-popup',
13+
],
1214
guidance: [],
1315
other: [],
1416
}

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"@babel/core": "^7.18.10",
2525
"@babel/preset-env": "^7.18.10",
2626
"ahooks": "^3.7.0",
27-
"antd": "^4.22.7",
27+
"antd": "4.x",
28+
"antd-mobile": "5.x",
2829
"classnames": "^2.3.1",
2930
"less": "^4.1.3",
3031
"less-plugin-npm-import": "^2.1.0",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React, { useRef } from 'react'
2+
import { Button } from 'antd-mobile'
3+
import type { UseModalEnhancedAction, UseModalEnhancedContext } from '@template-pro/mobile-ui'
4+
import { BasePopup } from '@template-pro/mobile-ui'
5+
6+
const Content = ({ enhancedAction }: Partial<UseModalEnhancedContext>) => (
7+
<div style={{ padding: 24 }}>
8+
<h3>这是弹出层内容</h3>
9+
<Button onClick={enhancedAction?.close}>
10+
点击关闭弹出层
11+
</Button>
12+
</div>
13+
)
14+
15+
function App() {
16+
const drawerRef = useRef<UseModalEnhancedAction>(null)
17+
18+
return (
19+
<BasePopup
20+
content={<Content />}
21+
bodyStyle={{ height: '40vh' }}
22+
actionRef={drawerRef}
23+
>
24+
<Button>打开弹出层</Button>
25+
</BasePopup>
26+
)
27+
}
28+
29+
export default App
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from 'react'
2+
import { BasePopup } from '@template-pro/mobile-ui'
3+
import { Button, Toast } from 'antd-mobile'
4+
5+
export default () => (
6+
<>
7+
<BasePopup
8+
content={<span style={{ height: '10vh', display: 'inline-block' }}>这是弹出层内容</span>}
9+
triggerClick={(event, action) => {
10+
window.console.log({ event, action })
11+
Toast.show({
12+
content: '1秒后打开弹出层',
13+
icon: 'loading',
14+
duration: 1000,
15+
afterClose: action.open,
16+
})
17+
}}
18+
>
19+
<Button>Click me</Button>
20+
</BasePopup>
21+
</>
22+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# BasePopup
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 numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import React from 'react'
2+
import classNames from 'classnames'
3+
import type { PopupProps } from 'antd-mobile/es/components/popup'
4+
import Popup from 'antd-mobile/es/components/popup'
5+
import type { UseModalEnhancedProps } from '@template-pro/utils'
6+
import { useModalEnhanced } from '@template-pro/utils'
7+
import { defaultPrefixCls } from '../constants'
8+
9+
export type BasePopupProps = PopupProps & Omit<UseModalEnhancedProps, 'onClick'> & {
10+
triggerClick?: UseModalEnhancedProps['onClick']
11+
}
12+
13+
const BasePopup = (props: BasePopupProps) => {
14+
const {
15+
className,
16+
onClose,
17+
onClick,
18+
triggerClick,
19+
...restProps
20+
} = props
21+
22+
const [
23+
visible,
24+
{ close },
25+
{ trigger, content },
26+
] = useModalEnhanced({ ...restProps, onClick: triggerClick })
27+
28+
const handlePopupClose = () => {
29+
if (onClose)
30+
onClose()
31+
32+
return close()
33+
}
34+
35+
return (
36+
<>
37+
{trigger}
38+
<Popup
39+
visible={visible}
40+
onClose={handlePopupClose}
41+
className={classNames(`${defaultPrefixCls}-base-popup`, className)}
42+
destroyOnClose
43+
closeOnMaskClick
44+
onClick={onClick}
45+
{...restProps}
46+
>
47+
{content}
48+
</Popup>
49+
</>
50+
)
51+
}
52+
53+
export default BasePopup
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@import (less) '~antd-mobile/es/components/popup/popup.css';
2+
@import '../../styles/themes/default.less';
3+
4+
.@{cls-prefix}-base-popup {
5+
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './index.less'

packages/mobile-ui/src/index.tsx

+12
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
11
export type { ButtonProps } from './button'
22
export { default as Button } from './button'
3+
4+
export type { BasePopupProps } from './base-popup'
5+
export { default as BasePopup } from './base-popup'
6+
7+
// Third-party library
8+
export { ConditionInput } from '@template-pro/rc-ui'
9+
export type { ConditionInputProps, ConditionInputCoverProps } from '@template-pro/rc-ui'
10+
export type {
11+
UseModalEnhancedAction,
12+
UseModalEnhancedContext,
13+
UseModalEnhancedProps,
14+
} from '@template-pro/utils'
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
@import '~antd-mobile/es/global/global.css';
2+
13
@cls-prefix: temp-m;

pnpm-lock.yaml

+4-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)