@yorkjs/hive-ui 2.1.2 → 2.1.3
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
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import React, { useMemo, useEffect, useState } from 'react'
|
|
2
|
+
import { View, ITouchEvent } from '@tarojs/components'
|
|
3
|
+
import { formatClassNames } from '../../util/function'
|
|
4
|
+
import styles from './index.module.styl'
|
|
5
|
+
|
|
6
|
+
export interface OverlayProps {
|
|
7
|
+
visible: boolean
|
|
8
|
+
zIndex?: number
|
|
9
|
+
duration?: number
|
|
10
|
+
className?: string
|
|
11
|
+
style?: React.CSSProperties
|
|
12
|
+
closeOnOverlayClick?: boolean
|
|
13
|
+
lockScroll?: boolean
|
|
14
|
+
onClick?: (event: ITouchEvent) => void
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const Overlay: React.FC<OverlayProps> = (props) => {
|
|
18
|
+
const {
|
|
19
|
+
visible = false,
|
|
20
|
+
zIndex = 1000,
|
|
21
|
+
duration = 300,
|
|
22
|
+
className,
|
|
23
|
+
style,
|
|
24
|
+
closeOnOverlayClick = true,
|
|
25
|
+
lockScroll = true,
|
|
26
|
+
onClick,
|
|
27
|
+
} = props
|
|
28
|
+
|
|
29
|
+
const [innerVisible, setInnerVisible] = useState(visible)
|
|
30
|
+
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
setInnerVisible(visible)
|
|
33
|
+
}, [visible])
|
|
34
|
+
|
|
35
|
+
const handleClick = (e: ITouchEvent) => {
|
|
36
|
+
if (closeOnOverlayClick) {
|
|
37
|
+
onClick?.(e)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const preventTouchMove = (e: any) => {
|
|
42
|
+
if (lockScroll) {
|
|
43
|
+
e.stopPropagation()
|
|
44
|
+
return false
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const combinedStyle: React.CSSProperties = useMemo(() => ({
|
|
49
|
+
...style,
|
|
50
|
+
zIndex,
|
|
51
|
+
transitionDuration: `${duration}ms`,
|
|
52
|
+
display: innerVisible ? 'block' : 'none'
|
|
53
|
+
}), [style, zIndex, duration, innerVisible])
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<View
|
|
57
|
+
className={formatClassNames(styles['overlay-root'], className)}
|
|
58
|
+
style={combinedStyle}
|
|
59
|
+
onClick={handleClick}
|
|
60
|
+
catchMove={lockScroll}
|
|
61
|
+
onTouchMove={preventTouchMove}
|
|
62
|
+
/>
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export default Overlay
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
@import '../../styles/mixin.styl'
|
|
2
|
+
|
|
3
|
+
.simple-modal-root
|
|
4
|
+
position fixed
|
|
5
|
+
top 0
|
|
6
|
+
left 0
|
|
7
|
+
right 0
|
|
8
|
+
bottom 0
|
|
9
|
+
z-index 1500
|
|
10
|
+
display flex
|
|
11
|
+
align-items center
|
|
12
|
+
justify-content center
|
|
13
|
+
pointer-events auto
|
|
14
|
+
|
|
15
|
+
:global
|
|
16
|
+
.modal-main-wrapper
|
|
17
|
+
position relative
|
|
18
|
+
z-index 1501
|
|
19
|
+
width 80%
|
|
20
|
+
max-width 320PX
|
|
21
|
+
display flex
|
|
22
|
+
flex-direction column
|
|
23
|
+
align-items center
|
|
24
|
+
|
|
25
|
+
.modal-content-box
|
|
26
|
+
width 100%
|
|
27
|
+
background-color #fff
|
|
28
|
+
border-radius 10PX
|
|
29
|
+
padding 15PX
|
|
30
|
+
box-sizing border-box
|
|
31
|
+
overflow hidden
|
|
32
|
+
animation modal-show 0.3s ease-out
|
|
33
|
+
|
|
34
|
+
.modal-close-section
|
|
35
|
+
display flex
|
|
36
|
+
flex-direction column
|
|
37
|
+
align-items center
|
|
38
|
+
margin-top 24PX
|
|
39
|
+
|
|
40
|
+
.close-circle-btn
|
|
41
|
+
display flex
|
|
42
|
+
align-items center
|
|
43
|
+
justify-content center
|
|
44
|
+
&:active
|
|
45
|
+
opacity 0.7
|
|
46
|
+
|
|
47
|
+
@keyframes modal-show
|
|
48
|
+
from
|
|
49
|
+
transform scale(0.8)
|
|
50
|
+
opacity 0
|
|
51
|
+
to
|
|
52
|
+
transform scale(1)
|
|
53
|
+
opacity 1
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import Taro from '@tarojs/taro'
|
|
2
|
+
import React, { useEffect } from 'react'
|
|
3
|
+
import { View } from '@tarojs/components'
|
|
4
|
+
|
|
5
|
+
import Overlay from '../Overlay'
|
|
6
|
+
import Icon from '../Icon'
|
|
7
|
+
import { formatClassNames } from '../../util/function'
|
|
8
|
+
|
|
9
|
+
import styles from './index.module.styl'
|
|
10
|
+
|
|
11
|
+
export interface SimpleModalProps {
|
|
12
|
+
/** 是否显示 */
|
|
13
|
+
visible: boolean
|
|
14
|
+
/** 关闭回调 */
|
|
15
|
+
onClose: () => void
|
|
16
|
+
/** 弹窗内容 */
|
|
17
|
+
children?: React.ReactNode
|
|
18
|
+
/** 自定义内容区类名 */
|
|
19
|
+
className?: string
|
|
20
|
+
/** 点击遮罩层是否关闭 */
|
|
21
|
+
closeOnOverlayClick?: boolean
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const SimpleModal: React.FC<SimpleModalProps> = (props) => {
|
|
25
|
+
const {
|
|
26
|
+
visible,
|
|
27
|
+
onClose,
|
|
28
|
+
children,
|
|
29
|
+
className,
|
|
30
|
+
closeOnOverlayClick = true
|
|
31
|
+
} = props
|
|
32
|
+
|
|
33
|
+
if (!visible) return null
|
|
34
|
+
|
|
35
|
+
const stopPropagation = (e: any) => {
|
|
36
|
+
e.stopPropagation()
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
if (visible && Taro.getEnv() === Taro.ENV_TYPE.WEB) {
|
|
41
|
+
document.body.style.overflow = 'hidden'
|
|
42
|
+
}
|
|
43
|
+
return () => {
|
|
44
|
+
if (Taro.getEnv() === Taro.ENV_TYPE.WEB) {
|
|
45
|
+
document.body.style.overflow = 'auto'
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}, [visible])
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<View className={styles['simple-modal-root']}
|
|
52
|
+
catchMove
|
|
53
|
+
onTouchMove={stopPropagation}
|
|
54
|
+
>
|
|
55
|
+
<Overlay
|
|
56
|
+
visible={visible}
|
|
57
|
+
onClick={() => closeOnOverlayClick && onClose()}
|
|
58
|
+
/>
|
|
59
|
+
|
|
60
|
+
<View className="modal-main-wrapper">
|
|
61
|
+
|
|
62
|
+
<View className={formatClassNames('modal-content-box', className)}>
|
|
63
|
+
{children}
|
|
64
|
+
</View>
|
|
65
|
+
|
|
66
|
+
<View className="modal-close-section" onClick={onClose}>
|
|
67
|
+
<View className="close-line" />
|
|
68
|
+
<View className="close-circle-btn">
|
|
69
|
+
<Icon name="close-circle" size={33} color="#fff" />
|
|
70
|
+
</View>
|
|
71
|
+
</View>
|
|
72
|
+
|
|
73
|
+
</View>
|
|
74
|
+
</View>
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export default SimpleModal
|
package/src/index.ts
CHANGED
|
@@ -12,6 +12,7 @@ export { default as SectionCard } from './components/SectionCard'
|
|
|
12
12
|
export { default as RemoteImage } from './components/RemoteImage'
|
|
13
13
|
export { default as Alert } from './components/Alert'
|
|
14
14
|
export { default as Switch } from './components/Switch'
|
|
15
|
+
export { default as SimpleModal } from './components/SimpleModal'
|
|
15
16
|
|
|
16
17
|
export { default as FlowItem } from './item/FlowItem'
|
|
17
18
|
export { default as ListItem } from './item/ListItem'
|