@yorkjs/hive-ui 2.1.8 → 2.1.9

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": "@yorkjs/hive-ui",
3
- "version": "2.1.8",
3
+ "version": "2.1.9",
4
4
  "description": "Hive UI - Taro React component library",
5
5
  "main": "src/index.ts",
6
6
  "module": "src/index.ts",
@@ -0,0 +1,63 @@
1
+ .progress
2
+ display flex
3
+ align-items center
4
+ position relative
5
+ width 100%
6
+
7
+ .track
8
+ flex auto
9
+ position relative
10
+ border-radius 6PX
11
+
12
+ .fill
13
+ height 100%
14
+ display flex
15
+ flex-direction column
16
+ justify-content center
17
+ transition all 0.4s
18
+ border-radius 6PX
19
+ position relative
20
+
21
+ .shimmer
22
+ content ''
23
+ position absolute
24
+ top 0
25
+ left 0
26
+ right 0
27
+ bottom 0
28
+ border-radius 6PX
29
+ animation shimmer 2s ease-in-out infinite
30
+
31
+ @keyframes shimmer
32
+ 0%
33
+ background rgba(255, 255, 255, 0.1)
34
+ width 0
35
+ 20%
36
+ background rgba(255, 255, 255, 0.5)
37
+ width 0
38
+ 100%
39
+ background rgba(255, 255, 255, 0)
40
+ width 100%
41
+
42
+ .text
43
+ display flex
44
+ align-items center
45
+ position absolute
46
+ top 50%
47
+ transform translateY(-50%)
48
+ transition all 0.4s
49
+
50
+ .textOutside
51
+ display flex
52
+ align-items center
53
+ margin-left 8PX
54
+
55
+ .textInner
56
+ display flex
57
+ align-items center
58
+ padding 4PX 10PX
59
+ font-size 12PX
60
+ line-height 1
61
+ color #fff
62
+ white-space nowrap
63
+ border-radius 20PX
@@ -0,0 +1,148 @@
1
+ import React, { FC, useMemo } from 'react'
2
+ import { View, Text } from '@tarojs/components'
3
+
4
+ import { formatClassNames } from '../../util/function'
5
+
6
+ import styles from './index.module.styl'
7
+
8
+ export interface ProgressProps {
9
+ /**
10
+ * 百分比
11
+ * @default 0
12
+ */
13
+ percent?: number
14
+ /**
15
+ * 进度条背景颜色
16
+ * @default #f3f3f3
17
+ */
18
+ background?: string
19
+ /**
20
+ * 进度条线条颜色
21
+ * @default linear-gradient(135deg, #fa2c19 0%, #fa6419 100%)
22
+ */
23
+ color?: string
24
+ /**
25
+ * 进度条宽度
26
+ */
27
+ strokeWidth?: string
28
+ /**
29
+ * 是否显示文字内容
30
+ * @default false
31
+ */
32
+ showText?: boolean
33
+ /**
34
+ * 百分比文字是否外显(在进度条右侧)
35
+ * @default false
36
+ */
37
+ textOutside?: boolean
38
+ /**
39
+ * 是否展示动画效果
40
+ * @default false
41
+ */
42
+ animated?: boolean
43
+ /**
44
+ * 自定义类名
45
+ */
46
+ className?: string
47
+ }
48
+
49
+ const Progress: FC<ProgressProps> = ({
50
+ percent = 0,
51
+ background = 'var(--containerInner)',
52
+ color = 'linear-gradient(135deg, #fa2c19 0%, #fa6419 100%)',
53
+ strokeWidth = 10,
54
+ showText = false,
55
+ textOutside = false,
56
+ animated = false,
57
+ className = '',
58
+ }) => {
59
+ // 限制百分比在 0-100 之间,最多保留两位小数
60
+ const validPercent = useMemo(() => {
61
+ const p = Math.min(100, Math.max(0, percent))
62
+ return Math.round(p * 100) / 100
63
+ }, [percent])
64
+
65
+ const trackStyle: React.CSSProperties = {
66
+ height: `${strokeWidth}px`,
67
+ backgroundColor: background,
68
+ borderRadius: `${strokeWidth}px`,
69
+ }
70
+
71
+ const fillStyle: React.CSSProperties = {
72
+ width: `${validPercent}%`,
73
+ height: `${strokeWidth}px`,
74
+ borderRadius: `${strokeWidth}px`,
75
+ background: color,
76
+ }
77
+
78
+ const textStyle: React.CSSProperties = textOutside
79
+ ? { marginLeft: '8px' }
80
+ : { right: `${100 - validPercent}%` }
81
+
82
+ const textInnerStyle: React.CSSProperties = textOutside
83
+ ? { color: 'var(--textTitle' }
84
+ : { background: color }
85
+
86
+ return (
87
+ <View
88
+ className={
89
+ formatClassNames(
90
+ styles.progress,
91
+ className
92
+ )
93
+ }
94
+ >
95
+ <View
96
+ className={styles.track}
97
+ style={trackStyle}
98
+ >
99
+ <View className={styles.fill} style={fillStyle}>
100
+ {
101
+ animated
102
+ ?
103
+ <View className={styles.shimmer} />
104
+ : null
105
+ }
106
+ </View>
107
+
108
+ {
109
+ (showText && !textOutside)
110
+ ? (
111
+ <View
112
+ className={styles.text}
113
+ style={textStyle}
114
+ >
115
+ <Text
116
+ className={styles.textInner}
117
+ style={textInnerStyle}
118
+ >
119
+ {validPercent}%
120
+ </Text>
121
+ </View>
122
+ )
123
+ : null
124
+ }
125
+ </View>
126
+
127
+ {
128
+ (showText && textOutside)
129
+ ? (
130
+ <View
131
+ className={styles.textOutside}
132
+ style={textStyle}
133
+ >
134
+ <Text
135
+ className={styles.textInner}
136
+ style={textInnerStyle}
137
+ >
138
+ {validPercent}%
139
+ </Text>
140
+ </View>
141
+ )
142
+ : null
143
+ }
144
+ </View>
145
+ )
146
+ }
147
+
148
+ export default React.memo(Progress)
package/src/index.ts CHANGED
@@ -14,6 +14,7 @@ export { default as RemoteImage } from './components/RemoteImage'
14
14
  export { default as Alert } from './components/Alert'
15
15
  export { default as Switch } from './components/Switch'
16
16
  export { default as SimpleModal } from './components/SimpleModal'
17
+ export { default as Progress } from './components/Progress'
17
18
 
18
19
  export { default as FlowItem } from './item/FlowItem'
19
20
  export { default as ListItem } from './item/ListItem'