@yorkjs/hive-ui 2.1.1 → 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 +1 -1
- package/src/components/Overlay/index.module.styl +11 -0
- package/src/components/Overlay/index.tsx +66 -0
- package/src/components/RemoteImage/index.tsx +3 -1
- package/src/components/SimpleModal/index.module.styl +53 -0
- package/src/components/SimpleModal/index.tsx +78 -0
- package/src/index.ts +1 -0
- package/src/util/function.ts +7 -3
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
|
|
@@ -12,6 +12,7 @@ export interface IRemoteImageProps extends Omit<ImageProps, 'src'> {
|
|
|
12
12
|
height?: number
|
|
13
13
|
/** 是否不进行裁剪(等比缩放) */
|
|
14
14
|
noCrop?: boolean
|
|
15
|
+
imagePixelRatio?: number
|
|
15
16
|
/** 图片质量 1-100 */
|
|
16
17
|
quality?: string | number
|
|
17
18
|
/** 自定义样式类 */
|
|
@@ -25,6 +26,7 @@ const RemoteImage: React.FC<IRemoteImageProps> = (props) => {
|
|
|
25
26
|
height = 50,
|
|
26
27
|
noCrop = false,
|
|
27
28
|
quality,
|
|
29
|
+
imagePixelRatio,
|
|
28
30
|
mode = 'aspectFill',
|
|
29
31
|
className,
|
|
30
32
|
...restProps
|
|
@@ -37,9 +39,9 @@ const RemoteImage: React.FC<IRemoteImageProps> = (props) => {
|
|
|
37
39
|
height,
|
|
38
40
|
noCrop,
|
|
39
41
|
quality,
|
|
42
|
+
imagePixelRatio
|
|
40
43
|
})
|
|
41
44
|
}, [url, width, height, noCrop, quality])
|
|
42
|
-
console.log("🚀 ~ RemoteImage ~ responsiveSrc:", responsiveSrc)
|
|
43
45
|
|
|
44
46
|
const containerStyle: React.CSSProperties = {
|
|
45
47
|
width: width ? `${width}px` : 'auto',
|
|
@@ -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'
|
package/src/util/function.ts
CHANGED
|
@@ -87,7 +87,7 @@ function isResponsiveImage(uri: string) {
|
|
|
87
87
|
&& (uri.indexOf('clouddn') > 0 || uri.indexOf('img.finstao.com') > 0)
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
const
|
|
90
|
+
const DEFAULT_IMAGE_PIXEL_RATIO = Math.max(2, pixelRatio || 2)
|
|
91
91
|
|
|
92
92
|
export interface IWatermarkOptions {
|
|
93
93
|
text?: string
|
|
@@ -102,6 +102,7 @@ export interface IGetResponsiveImageOptions {
|
|
|
102
102
|
height?: number
|
|
103
103
|
noCrop?: boolean
|
|
104
104
|
quality?: string | number
|
|
105
|
+
imagePixelRatio?: number
|
|
105
106
|
supportWebp?: boolean
|
|
106
107
|
}
|
|
107
108
|
|
|
@@ -115,6 +116,7 @@ export default function getResponsiveImage(options: IGetResponsiveImageOptions):
|
|
|
115
116
|
height,
|
|
116
117
|
noCrop,
|
|
117
118
|
quality,
|
|
119
|
+
imagePixelRatio: customPixelRatio
|
|
118
120
|
} = options
|
|
119
121
|
|
|
120
122
|
if (!url) return ''
|
|
@@ -124,15 +126,17 @@ export default function getResponsiveImage(options: IGetResponsiveImageOptions):
|
|
|
124
126
|
return url
|
|
125
127
|
}
|
|
126
128
|
|
|
129
|
+
const ratio = customPixelRatio || DEFAULT_IMAGE_PIXEL_RATIO
|
|
130
|
+
|
|
127
131
|
const suffix: string[] = []
|
|
128
132
|
|
|
129
133
|
if (typeof width === 'number') {
|
|
130
|
-
const w = Math.floor(width *
|
|
134
|
+
const w = Math.floor(width * ratio)
|
|
131
135
|
suffix.push('w', w.toString())
|
|
132
136
|
}
|
|
133
137
|
|
|
134
138
|
if (typeof height === 'number') {
|
|
135
|
-
const h = Math.floor(height *
|
|
139
|
+
const h = Math.floor(height * ratio)
|
|
136
140
|
suffix.push('h', h.toString())
|
|
137
141
|
}
|
|
138
142
|
|