@yorkjs/hive-ui 2.0.2 → 2.0.4

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.0.2",
3
+ "version": "2.0.4",
4
4
  "description": "Hive UI - Taro React component library",
5
5
  "main": "src/index.ts",
6
6
  "module": "src/index.ts",
@@ -0,0 +1,24 @@
1
+ @import '../../styles/mixin.styl'
2
+
3
+ .switch-component
4
+ &.is-readonly
5
+ opacity 0.8
6
+ cursor default
7
+ &.is-disabled
8
+ cursor not-allowed
9
+
10
+ :global
11
+ .weui-switch, .wx-switch-input
12
+ border-color var(--switch-inactive-color) !important
13
+ background-color var(--switch-inactive-color) !important
14
+
15
+ &:before
16
+ background-color var(--switch-inactive-color) !important
17
+ border-color var(--switch-inactive-color) !important
18
+
19
+ &:checked, &.wx-switch-input-checked
20
+ border-color var(--switch-active-color) !important
21
+ background-color var(--switch-active-color) !important
22
+ &:before
23
+ background-color var(--switch-active-color) !important
24
+ border-color var(--switch-active-color) !important
@@ -0,0 +1,80 @@
1
+ import React, { useMemo } from 'react'
2
+ import { BaseEventOrig, Switch as TaroSwitch } from '@tarojs/components'
3
+ import { formatClassNames } from '../../util/function'
4
+
5
+ import { useTheme } from '../../config'
6
+
7
+ import styles from './index.module.styl'
8
+
9
+ export interface SwitchProps {
10
+ /** 是否选中 */
11
+ checked?: boolean
12
+ /** 改变事件 */
13
+ onChange?: (checked: boolean) => void
14
+ /** 是否禁用 */
15
+ disabled?: boolean
16
+ /** 只读状态 */
17
+ readOnly?: boolean
18
+ /** 自定义类名 */
19
+ className?: string
20
+ /** 选中时的背景颜色 (不传则使用主题色) */
21
+ color?: string
22
+ }
23
+
24
+ const Switch: React.FC<SwitchProps> = (props) => {
25
+ const {
26
+ checked = false,
27
+ onChange,
28
+ disabled = false,
29
+ readOnly = false,
30
+ className,
31
+ color,
32
+ } = props
33
+
34
+ const { isDark, themeSelect } = useTheme()
35
+
36
+ const colors = useMemo(() => {
37
+ let activeTrack = color || 'var(--primary)'
38
+ let inactiveTrack = themeSelect('#CCCCCC', 'var(--containerInner)')
39
+
40
+ if (disabled) {
41
+ activeTrack = '#ffc097'
42
+ inactiveTrack = '#E6E6E6'
43
+ }
44
+
45
+ return {
46
+ activeTrack,
47
+ inactiveTrack,
48
+ }
49
+ }, [color, disabled, themeSelect])
50
+
51
+ const handleChange = (e: BaseEventOrig<{ value: boolean }>) => {
52
+ if (disabled || readOnly) return
53
+ onChange?.(e.detail.value)
54
+ }
55
+
56
+ const dynamicStyle = {
57
+ '--switch-active-color': colors.activeTrack,
58
+ '--switch-inactive-color': colors.inactiveTrack,
59
+ } as React.CSSProperties
60
+
61
+ return (
62
+ <TaroSwitch
63
+ checked={checked}
64
+ disabled={disabled || readOnly}
65
+ color={colors.activeTrack}
66
+ onChange={handleChange}
67
+ style={dynamicStyle}
68
+ className={formatClassNames(
69
+ styles['switch-component'],
70
+ {
71
+ [styles['is-readonly']]: readOnly,
72
+ [styles['is-disabled']]: disabled,
73
+ },
74
+ className
75
+ )}
76
+ />
77
+ )
78
+ }
79
+
80
+ export default React.memo(Switch)
package/src/index.ts CHANGED
@@ -10,6 +10,7 @@ export { default as DisplayCard } from './components/DisplayCard'
10
10
  export { default as Card } from './components/Card'
11
11
  export { default as RemoteImage } from './components/RemoteImage'
12
12
  export { default as Alert } from './components/Alert'
13
+ export { default as Switch } from './components/Switch'
13
14
 
14
15
  export { default as FlowItem } from './item/FlowItem'
15
16
  export { default as ProductItem, setProductItemConfig } from './item/ProductItem'
@@ -38,6 +38,7 @@
38
38
  margin-right 10PX
39
39
  flex 1
40
40
  overflow hidden
41
+ min-width 0
41
42
 
42
43
  .flow-item-icon
43
44
  flex-shrink 0
@@ -51,11 +52,16 @@
51
52
  justify-content center
52
53
  padding 2PX
53
54
  box-sizing border-box
55
+ overflow hidden
54
56
 
55
57
  .icon-img
56
58
  width 100%
57
59
  height 100%
58
60
 
61
+ .flow-item-icon-custom
62
+ flex-shrink 0
63
+ margin-right 10PX
64
+
59
65
  .flow-item-content
60
66
  flex 1
61
67
  display flex
@@ -63,14 +69,29 @@
63
69
  justify-content center
64
70
  align-items flex-start
65
71
  overflow hidden
72
+ min-width 0
73
+
74
+ .flow-item-title-row
75
+ display flex
76
+ flex-direction row
77
+ align-items center
78
+ width 100%
79
+ overflow hidden
66
80
 
67
81
  .flow-item-title
68
82
  font-size 16PX
69
83
  color var(--textTitle)
70
84
  text-align left
71
- width 100%
85
+ flex-shrink 1
86
+ min-width 0
72
87
  lineClamp(1)
73
88
 
89
+ .flow-item-title-extra
90
+ flex-shrink 0
91
+ margin-left 5PX
92
+ display flex
93
+ align-items center
94
+
74
95
  .flow-item-time-container
75
96
  display flex
76
97
  margin-top 5PX
@@ -10,9 +10,11 @@ import styles from './index.module.styl'
10
10
 
11
11
  interface IProps {
12
12
  /** 左侧图标链接 */
13
- icon?: string
13
+ icon?: string | React.ReactNode
14
14
  /** 标题 */
15
15
  title?: string
16
+ /** 标题右侧的额外内容(如标签、状态) */
17
+ titleExtra?: React.ReactNode
16
18
  /** 时间或下方副标题 */
17
19
  time?: string | React.ReactNode
18
20
  /** 右侧金额 */
@@ -35,6 +37,7 @@ const FlowItem: React.FC<IProps> = (props) => {
35
37
  icon,
36
38
  title,
37
39
  time,
40
+ titleExtra,
38
41
  amount,
39
42
  amountColor,
40
43
  desc,
@@ -44,6 +47,29 @@ const FlowItem: React.FC<IProps> = (props) => {
44
47
  className
45
48
  } = props
46
49
 
50
+ const renderIcon = () => {
51
+ if (isEmpty(icon)) return null
52
+
53
+ if (typeof icon === 'string') {
54
+ return (
55
+ <View className="flow-item-icon">
56
+ <Image
57
+ src={icon}
58
+ className="icon-img"
59
+ mode="aspectFit"
60
+ />
61
+ </View>
62
+ )
63
+ }
64
+
65
+ // 如果是自定义元素
66
+ return (
67
+ <View className="flow-item-icon-custom">
68
+ {icon}
69
+ </View>
70
+ )
71
+ }
72
+
47
73
  return (
48
74
  <View
49
75
  className={formatClassNames(
@@ -54,29 +80,30 @@ const FlowItem: React.FC<IProps> = (props) => {
54
80
  >
55
81
  <View className={showSeparator ? 'flow-content-no-border' : 'flow-content'}>
56
82
  <View className="flow-item-left">
57
- {
58
- !isEmpty(icon)
59
- ? (
60
- <View className="flow-item-icon">
61
- <Image
62
- src={icon}
63
- className="icon-img"
64
- mode="aspectFit"
65
- />
66
- </View>
67
- ) : undefined
68
- }
83
+ {renderIcon()}
69
84
 
70
85
  <View className="flow-item-content">
71
- {
72
- !isEmpty(title)
73
- ? (
74
- <Text className="flow-item-title">
75
- {title}
76
- </Text>
77
- )
78
- : undefined
79
- }
86
+
87
+ <View className="flow-item-title-row">
88
+ {
89
+ !isEmpty(title)
90
+ ? (
91
+ <Text className="flow-item-title">
92
+ {title}
93
+ </Text>
94
+ )
95
+ : undefined
96
+ }
97
+ {
98
+ !isEmpty(titleExtra)
99
+ ? (
100
+ <View className="flow-item-title-extra">
101
+ {titleExtra}
102
+ </View>
103
+ )
104
+ : undefined
105
+ }
106
+ </View>
80
107
  {
81
108
  !isEmpty(time)
82
109
  ? (