@yorkjs/hive-ui 0.0.1 → 0.0.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
@@ -1,10 +1,14 @@
1
1
  {
2
2
  "name": "@yorkjs/hive-ui",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "Hive UI - Taro React component library",
5
5
  "main": "src/index.ts",
6
6
  "module": "src/index.ts",
7
7
  "types": "src/index.ts",
8
+ "sideEffects": [
9
+ "**/*.styl",
10
+ "**/*.css"
11
+ ],
8
12
  "files": [
9
13
  "src"
10
14
  ],
@@ -0,0 +1,153 @@
1
+ import React from 'react'
2
+ import { View } from '@tarojs/components'
3
+
4
+ import { formatClassNames } from '../../util/function'
5
+
6
+ import CellTitle from './CellTitle'
7
+ import CellValue from './CellValue'
8
+ import CellArrow from './CellArrow'
9
+
10
+ import styles from './index.module.styl'
11
+
12
+ export interface CellProps {
13
+ vertical?: boolean
14
+ icon?: React.ReactNode
15
+ title?: React.ReactNode | string
16
+ placeholder?: string | number
17
+ value?: string | number
18
+ content?: React.ReactNode
19
+ titleWidth?: number
20
+ tooltip?: string
21
+ required?: boolean
22
+ showArrow?: boolean
23
+ showSeparator?: boolean
24
+ showTopBorder?: boolean
25
+ showBottomBorder?: boolean
26
+ onClick?: () => void
27
+ className?: string
28
+ children?: React.ReactNode
29
+ }
30
+
31
+ const Cell: React.FC<CellProps> = (props) => {
32
+ const {
33
+ vertical = false,
34
+ icon,
35
+ title,
36
+ placeholder,
37
+ value,
38
+ content,
39
+ titleWidth,
40
+ tooltip,
41
+ required = false,
42
+ showArrow = false,
43
+ showSeparator = false,
44
+ showTopBorder = false,
45
+ showBottomBorder = false,
46
+ onClick,
47
+ className,
48
+ children
49
+ } = props
50
+
51
+ const containerClass = formatClassNames(
52
+ styles['cell-container'],
53
+ vertical ? styles['is-vertical'] : styles['is-horizontal'],
54
+ {
55
+ [styles['is-clickable']]: !!onClick,
56
+ [styles['border-top']]: showTopBorder,
57
+ [styles['border-bottom']]: showBottomBorder,
58
+ },
59
+ className
60
+ )
61
+
62
+ const innerClass = formatClassNames(styles['cell-inner'], {
63
+ [styles['show-separator']]: showSeparator,
64
+ })
65
+
66
+ const renderContent = () => {
67
+ if (content) return content
68
+ if (value != null || placeholder != null) {
69
+ return (
70
+ <CellValue
71
+ value={value}
72
+ placeholder={placeholder}
73
+ />
74
+ )
75
+ }
76
+ return null
77
+ }
78
+
79
+ return (
80
+ <View className={containerClass} onClick={onClick}>
81
+ <View className={innerClass}>
82
+ {
83
+ vertical ? (
84
+ <>
85
+ <View className={styles['header-row']}>
86
+ <View style={{
87
+ display: 'flex',
88
+ flexDirection: 'row',
89
+ alignItems: 'center',
90
+ flex: 1
91
+ }}>
92
+ {
93
+ icon
94
+ ? (
95
+ <View className={styles['icon-wrapper']}>
96
+ {icon}
97
+ </View>
98
+ ) : undefined
99
+ }
100
+ <View className={styles['title-section']}>
101
+ {
102
+ typeof title === 'string'
103
+ ? <CellTitle title={title} required={required} tooltip={tooltip} />
104
+ : title
105
+ }
106
+ </View>
107
+ </View>
108
+ {
109
+ showArrow
110
+ ? <View className={styles['arrow-wrapper']}><CellArrow /></View>
111
+ : undefined
112
+ }
113
+ </View>
114
+ <View className={styles['content-section']}>
115
+ {renderContent()}
116
+ </View>
117
+ </>
118
+ )
119
+ : (
120
+ <>
121
+ {
122
+ icon
123
+ ? <View className={styles['icon-wrapper']}>{icon}</View>
124
+ : undefined
125
+ }
126
+ <View
127
+ className={styles['title-section']}
128
+ style={titleWidth ? { width: `${titleWidth}px` } : { maxWidth: '60%' }}
129
+ >
130
+ {
131
+ typeof title === 'string'
132
+ ? <CellTitle title={title} required={required} tooltip={tooltip} />
133
+ : title
134
+ }
135
+ </View>
136
+ <View className={styles['content-section']}>
137
+ {renderContent()}
138
+ </View>
139
+ {
140
+ showArrow
141
+ ? <View className={styles['arrow-wrapper']}><CellArrow /></View>
142
+ : undefined
143
+ }
144
+ </>
145
+ )
146
+ }
147
+ {children}
148
+ </View>
149
+ </View>
150
+ )
151
+ }
152
+
153
+ export default Cell
@@ -0,0 +1,25 @@
1
+ import React from 'react'
2
+
3
+ import Icon from '../Icon'
4
+ import { formatClassNames } from '../../util/function'
5
+
6
+ import styles from './index.module.styl'
7
+
8
+ export interface CellArrowProps {
9
+ className?: string
10
+ }
11
+ const CellArrow: React.FC<CellArrowProps> = ({
12
+ className
13
+ }) => (
14
+ <Icon
15
+ name="right"
16
+ className={formatClassNames(
17
+ styles['arrow-icon'],
18
+ className
19
+ )}
20
+ color="var(--textPlaceholder)"
21
+ size={12}
22
+ />
23
+ )
24
+
25
+ export default CellArrow
@@ -0,0 +1,44 @@
1
+ import React from 'react'
2
+ import { View } from '@tarojs/components'
3
+ import { formatClassNames } from '../../util/function'
4
+ import styles from './index.module.styl'
5
+
6
+ export interface CellCardProps {
7
+ className?: string
8
+ showTopGutter?: boolean
9
+ showBottomGutter?: boolean
10
+ showTopBlank?: boolean
11
+ children?: React.ReactNode
12
+ onClick?: () => void
13
+ }
14
+
15
+ const CellCard: React.FC<CellCardProps> = ({
16
+ showTopGutter = false,
17
+ showBottomGutter = false,
18
+ showTopBlank = false,
19
+ onClick,
20
+ className,
21
+ children
22
+ }) => {
23
+ const combinedClass = formatClassNames(
24
+ styles['cell-card'],
25
+ {
26
+ [styles['show-top-gutter']]: showTopGutter,
27
+ [styles['show-bottom-gutter']]: showBottomGutter,
28
+ [styles['show-top-blank']]: showTopBlank,
29
+ [styles['is-clickable']]: !!onClick,
30
+ },
31
+ className
32
+ )
33
+
34
+ return (
35
+ <View
36
+ className={combinedClass}
37
+ onClick={onClick}
38
+ >
39
+ {children}
40
+ </View>
41
+ )
42
+ }
43
+
44
+ export default CellCard
@@ -0,0 +1,28 @@
1
+ import { View, Text } from "@tarojs/components"
2
+ import { formatClassNames } from "../../util/function"
3
+
4
+ import styles from './index.module.styl'
5
+
6
+ export interface CellDescriptionProps {
7
+ desc: string
8
+ align?: 'left' | 'center' | 'right'
9
+ className?: string
10
+ }
11
+
12
+ const CellDescription: React.FC<CellDescriptionProps> = ({ desc, align = 'left', className }) => {
13
+ return (
14
+ <View className={formatClassNames(
15
+ styles['cell-description'],
16
+ className)
17
+ }>
18
+ <Text
19
+ className={styles['desc-text']}
20
+ style={{ textAlign: align }}
21
+ >
22
+ {desc}
23
+ </Text>
24
+ </View>
25
+ )
26
+ }
27
+
28
+ export default CellDescription
@@ -0,0 +1,46 @@
1
+ import React from 'react'
2
+ import { View, Text, ITouchEvent } from '@tarojs/components'
3
+
4
+ import { formatClassNames } from '../../util/function'
5
+
6
+ import Icon from '../Icon'
7
+ import { getCellConfig } from './config'
8
+
9
+ import styles from './index.module.styl'
10
+
11
+ export interface CellGroupProps {
12
+ title: string
13
+ tooltip?: any
14
+ className?: string
15
+ }
16
+
17
+ const CellGroup: React.FC<CellGroupProps> = ({ title, tooltip, className }) => {
18
+ const handleTooltip = (e: ITouchEvent) => {
19
+ e.stopPropagation()
20
+
21
+ const data = { title, tooltip }
22
+ const config = getCellConfig()
23
+ config.onTooltipPress(data)
24
+ }
25
+
26
+ return (
27
+ <View className={formatClassNames(styles['cell-group'], className)}>
28
+ <Text className={styles['group-text']}>
29
+ {title}
30
+ </Text>
31
+ {
32
+ tooltip ? (
33
+ <Icon
34
+ className={styles['tooltip-icon']}
35
+ name='question-circle'
36
+ onClick={handleTooltip}
37
+ size={14}
38
+ />
39
+ )
40
+ : undefined
41
+ }
42
+ </View>
43
+ )
44
+ }
45
+
46
+ export default CellGroup
@@ -0,0 +1,71 @@
1
+ import React from 'react'
2
+ import { View, Text, ITouchEvent } from '@tarojs/components'
3
+
4
+ import { formatClassNames } from '../../util/function'
5
+
6
+ import Icon from '../Icon'
7
+
8
+ import { getCellConfig } from './config'
9
+
10
+ import styles from './index.module.styl'
11
+
12
+ export interface CellTitleProps {
13
+ className?: string
14
+ required?: boolean
15
+ title: string
16
+ tooltip?: any
17
+ style?: React.CSSProperties
18
+ }
19
+
20
+ const CellTitle: React.FC<CellTitleProps> = ({
21
+ required,
22
+ title,
23
+ tooltip,
24
+ style,
25
+ className
26
+ }) => {
27
+ const handleTooltip = (e: ITouchEvent) => {
28
+ e.stopPropagation()
29
+
30
+ const data = { title, tooltip }
31
+ const config = getCellConfig()
32
+ config.onTooltipPress(data)
33
+ }
34
+
35
+ return (
36
+ <View className={formatClassNames(
37
+ styles['title-view'],
38
+ className,
39
+ )}>
40
+ {
41
+ required
42
+ ? (
43
+ <Icon
44
+ name="asterisk"
45
+ color="#FF0000"
46
+ size={7}
47
+ className={styles['required-icon']}
48
+ />
49
+ )
50
+ : undefined
51
+ }
52
+ <Text className={styles['title-text']} style={style}>
53
+ {title}
54
+ </Text>
55
+ {
56
+ tooltip
57
+ ? (
58
+ <Icon
59
+ className={styles['tooltip-icon']}
60
+ name='question-circle'
61
+ onClick={handleTooltip}
62
+ size={14}
63
+ />
64
+ )
65
+ : undefined
66
+ }
67
+ </View>
68
+ )
69
+ }
70
+
71
+ export default CellTitle
@@ -0,0 +1,50 @@
1
+ import React from 'react'
2
+ import { Text } from '@tarojs/components'
3
+
4
+ import { formatClassNames } from '../../util/function'
5
+
6
+ import styles from './index.module.styl'
7
+
8
+ export interface CellValueProps {
9
+ className?: string
10
+ value?: string | number
11
+ placeholder?: string | number
12
+ maxLines?: number
13
+ }
14
+
15
+ const CellValue: React.FC<CellValueProps> = ({ value, placeholder, maxLines, className }) => {
16
+ const hasValue = value !== undefined && value !== null && value !== ''
17
+
18
+ const dynamicStyle: React.CSSProperties = maxLines !== 1 ? {
19
+ WebkitLineClamp: maxLines,
20
+ } : {}
21
+
22
+ if (hasValue) {
23
+ return (
24
+ <Text
25
+ className={formatClassNames(
26
+ styles['value-text'],
27
+ className
28
+ )}
29
+ style={dynamicStyle}
30
+ >
31
+ {value}
32
+ </Text>
33
+ )
34
+ }
35
+
36
+ if (placeholder !== undefined && placeholder !== null) {
37
+ return (
38
+ <Text className={formatClassNames(
39
+ styles['placeholder-text'],
40
+ className
41
+ )}>
42
+ {placeholder}
43
+ </Text>
44
+ )
45
+ }
46
+
47
+ return null
48
+ }
49
+
50
+ export default CellValue
@@ -0,0 +1,13 @@
1
+ let onTooltipPress = (data: { title: string; tooltip: any }) => {
2
+ console.log('触发 Tooltip:', data)
3
+ }
4
+
5
+ export const setCellConfig = (config: { onTooltipPress: typeof onTooltipPress }) => {
6
+ if (config.onTooltipPress) {
7
+ onTooltipPress = config.onTooltipPress
8
+ }
9
+ }
10
+
11
+ export const getCellConfig = () => ({
12
+ onTooltipPress
13
+ })
@@ -0,0 +1,145 @@
1
+ @import '../../styles/mixin.styl'
2
+
3
+ $CELL_PADDING_HORIZONTAL = 16PX
4
+ $CELL_PADDING_VERTICAL = 14PX
5
+ $TITLE_FONT_SIZE = 16PX
6
+ $VALUE_FONT_SIZE = 14PX
7
+ $DESC_FONT_SIZE = 13PX
8
+
9
+ .cell-card
10
+ border-radius 10PX
11
+ overflow hidden
12
+ background-color var(--containerCard)
13
+ margin 0 $WING_BLANK
14
+ &.show-top-gutter
15
+ margin-top $GUTTER_BLANK
16
+ &.show-bottom-gutter
17
+ margin-bottom $GUTTER_BLANK
18
+ &.show-top-blank
19
+ margin-top $CARD_BLANK
20
+
21
+ .cell-description
22
+ padding 6PX $CELL_PADDING_HORIZONTAL 0 $CELL_PADDING_HORIZONTAL
23
+ .desc-text
24
+ color var(--textMuted)
25
+ font-size $DESC_FONT_SIZE
26
+ line-height calc($DESC_FONT_SIZE + 6PX)
27
+ display block
28
+
29
+ .cell-group
30
+ display flex
31
+ flex-direction row
32
+ align-items center
33
+ margin 0 $WING_BLANK
34
+ padding 20PX $CELL_PADDING_HORIZONTAL 8PX $CELL_PADDING_HORIZONTAL
35
+ .group-text
36
+ color var(--textMuted)
37
+ font-size $VALUE_FONT_SIZE
38
+
39
+ .cell-container
40
+ background-color var(--containerCard)
41
+ padding 0 $CELL_PADDING_HORIZONTAL
42
+ position relative
43
+ transition background-color 0.1s
44
+
45
+ &.border-top
46
+ halfBorder(top, var(--lineBorder))
47
+
48
+ &.border-bottom
49
+ halfBorder(bottom, var(--lineBorder))
50
+
51
+ &.is-clickable
52
+ cursor pointer
53
+ &:active
54
+ background-color rgba(0, 0, 0, 0.03)
55
+
56
+ .cell-inner
57
+ padding $CELL_PADDING_VERTICAL 0
58
+ display flex
59
+ flex-direction column
60
+ position relative
61
+
62
+ &.show-separator
63
+ halfBorder(bottom, var(--lineBorder))
64
+
65
+ .is-horizontal
66
+ .cell-inner
67
+ flex-direction row
68
+ align-items center
69
+
70
+ .title-section
71
+ flex-shrink 0
72
+ margin-right 10PX
73
+
74
+ .content-section
75
+ flex 1
76
+ display flex
77
+ flex-direction row
78
+ justify-content flex-end
79
+ align-items center
80
+ text-align right
81
+
82
+ .is-vertical
83
+ .header-row
84
+ display flex
85
+ flex-direction row
86
+ align-items center
87
+ justify-content space-between
88
+ width 100%
89
+
90
+ .title-section
91
+ flex 1
92
+
93
+ .content-section
94
+ margin-top 8PX
95
+ width 100%
96
+ display flex
97
+ flex-direction row
98
+ justify-content flex-start
99
+ text-align left
100
+
101
+ .icon-wrapper
102
+ margin-right 12PX
103
+ display flex
104
+ align-items center
105
+ justify-content center
106
+
107
+ .title-view
108
+ display flex
109
+ flex-direction row
110
+ align-items center
111
+ position relative
112
+
113
+ .title-text
114
+ color var(--textTitle)
115
+ font-size $TITLE_FONT_SIZE
116
+ line-height 1.4
117
+
118
+ .required-icon
119
+ position absolute
120
+ left -10PX
121
+ top 7PX
122
+
123
+ .tooltip-icon
124
+ margin-left 4PX
125
+ color var(--textMuted)
126
+ display flex
127
+ align-items center
128
+
129
+ .value-text
130
+ color var(--textContent)
131
+ font-size $VALUE_FONT_SIZE
132
+ line-height 1.4
133
+ lineClamp(1)
134
+
135
+ .placeholder-text
136
+ color var(--textPlaceholder)
137
+ font-size $VALUE_FONT_SIZE
138
+ line-height 1.4
139
+
140
+ .arrow-wrapper
141
+ margin-left 6PX
142
+ display flex
143
+ align-items center
144
+ color var(--textPlaceholder)
145
+ font-size 12PX
@@ -0,0 +1,24 @@
1
+ import CellMain from './Cell'
2
+ import CellGroup from './CellGroup'
3
+ import CellCard from './CellCard'
4
+ import CellTitle from './CellTitle'
5
+ import CellValue from './CellValue'
6
+ import CellArrow from './CellArrow'
7
+ import CellDescription from './CellDescription'
8
+
9
+ export type { CellProps } from './Cell'
10
+ export type { CellCardProps } from './CellCard'
11
+ export type { CellTitleProps } from './CellTitle'
12
+
13
+ export { setCellConfig } from './config'
14
+
15
+ const Cell = Object.assign(CellMain, {
16
+ Group: CellGroup,
17
+ Card: CellCard,
18
+ Title: CellTitle,
19
+ Value: CellValue,
20
+ Arrow: CellArrow,
21
+ Description: CellDescription
22
+ })
23
+
24
+ export default Cell
@@ -0,0 +1,68 @@
1
+ @import '../../styles/mixin.styl'
2
+
3
+ .checkbox-component
4
+ display flex
5
+ flex-direction row
6
+ align-items center
7
+ cursor pointer
8
+ position relative
9
+
10
+ &:active
11
+ &:not(.is-disabled)
12
+ opacity 0.7
13
+
14
+ &:after
15
+ position absolute
16
+ content ''
17
+ top -6PX
18
+ bottom -6PX
19
+ left -6PX
20
+ right -6PX
21
+
22
+ // 选中状态文字颜色
23
+ &.is-checked
24
+ .label-text
25
+ color var(--primary)
26
+
27
+ // ✨ 禁用状态逻辑:不使用透明度
28
+ &.is-disabled
29
+ cursor not-allowed
30
+ .label-text
31
+ color var(--textPlaceholder)
32
+
33
+ // 大尺寸样式
34
+ &.size-large
35
+ .checkbox-icon-container
36
+ width 36PX
37
+ height 36PX
38
+ .label-text
39
+ font-size 16PX
40
+ margin-left 12PX
41
+
42
+ &.size-small
43
+ .checkbox-icon-container
44
+ width 16PX
45
+ height 16PX
46
+ .label-text
47
+ font-size 12PX
48
+ margin-left 6PX
49
+
50
+ // 图标容器
51
+ .checkbox-icon-container
52
+ display flex
53
+ align-items center
54
+ justify-content center
55
+ width 20PX
56
+ height 20PX
57
+ line-height 1
58
+ flex-shrink 0 // 防止被压缩
59
+ overflow visible
60
+
61
+ // 文字样式
62
+ .label-text
63
+ color var(--textContent)
64
+ font-size 13PX
65
+ margin-left 6PX
66
+ line-height 1
67
+ &.is-app-android
68
+ padding-top 1.5PX