@yorkjs/hive-ui 2.2.8 → 2.3.1

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.2.8",
3
+ "version": "2.3.1",
4
4
  "description": "Hive UI - Taro React component library",
5
5
  "main": "src/index.ts",
6
6
  "module": "src/index.ts",
@@ -22,20 +22,11 @@
22
22
  position absolute
23
23
  top -6PX
24
24
  right -6PX
25
- width 16PX
26
- height 16PX
27
- line-height 16PX
28
- text-align center
29
- border-radius 50%
30
25
  z-index 2
31
-
32
- .delete-icon
33
- position absolute
34
- top 50%
35
- left 50%
36
- transform translate(-50%, -50%)
37
- line-height 1
38
- display block
26
+ width 17PX
27
+ height 17PX
28
+ line-height 1
29
+ flexHVCenter()
39
30
 
40
31
  .text-block
41
32
  background-color var(--containerCard)
@@ -97,9 +97,10 @@ const RichTextEditor: React.FC<RichTextEditorProps> = (props) => {
97
97
  const textareaRefs = useRef<Record<number, any>>({})
98
98
  const skipHeightSyncRef = useRef(false)
99
99
 
100
- const deleteBtnStyle = useMemo(() => ({
101
- backgroundColor: themeSelect('rgba(0, 0, 0, 0.5)', 'rgba(255, 255, 255, 0.5)'),
102
- }), [themeSelect])
100
+ const deleteIconColor = useMemo(
101
+ () => themeSelect('rgba(0, 0, 0, 0.5)', 'rgba(255, 255, 255, 0.5)'),
102
+ [themeSelect]
103
+ )
103
104
 
104
105
  const updateBlock = useCallback((index: number, patch: Partial<RichTextBlock>) => {
105
106
  onChange?.(
@@ -175,14 +176,12 @@ const RichTextEditor: React.FC<RichTextEditorProps> = (props) => {
175
176
  >
176
177
  <View
177
178
  className={styles['delete-btn']}
178
- style={deleteBtnStyle}
179
179
  onClick={(e) => handleDelete(e, index)}
180
180
  >
181
181
  <Icon
182
- name='close'
183
- size={10}
184
- color="var(--containerCard)"
185
- className={styles['delete-icon']}
182
+ name="close-circle-fill"
183
+ size={17}
184
+ color={deleteIconColor}
186
185
  />
187
186
  </View>
188
187
 
@@ -21,6 +21,8 @@ export interface TableColumn<T extends object> {
21
21
  render?: (value: T[keyof T], record: T, index: number) => React.ReactNode
22
22
  }
23
23
 
24
+ export type TableTextAlign = 'left' | 'center' | 'right'
25
+
24
26
  export interface TableProps<T extends object> {
25
27
  /** 列配置 */
26
28
  columns: TableColumn<T>[]
@@ -28,6 +30,12 @@ export interface TableProps<T extends object> {
28
30
  dataSource: T[]
29
31
  /** 行唯一标识对应的数据字段 */
30
32
  rowKey: keyof T
33
+ /** 表头背景色 */
34
+ headerBackgroundColor?: string
35
+ /** 表头文字加粗 */
36
+ headerTextBold?: boolean
37
+ /** 表格文字对齐方式 */
38
+ textAlign?: TableTextAlign
31
39
  /** 自定义类名 */
32
40
  className?: string
33
41
  /** 自定义样式 */
@@ -46,16 +54,29 @@ function formatWidth(width?: number | string) {
46
54
  }
47
55
 
48
56
  /**
49
- * 根据列宽生成单元格 flex 样式;未指定宽度时均分剩余空间
57
+ * 根据列宽和对齐方式生成单元格样式;未指定宽度时均分剩余空间
50
58
  */
51
- function getCellStyle(width?: number | string): React.CSSProperties {
59
+ function getCellStyle(width?: number | string, align: TableTextAlign = 'left'): React.CSSProperties {
52
60
  const formattedWidth = formatWidth(width)
61
+ const justifyContent = align === 'center'
62
+ ? 'center'
63
+ : align === 'right'
64
+ ? 'flex-end'
65
+ : 'flex-start'
53
66
 
54
67
  if (formattedWidth) {
55
- return { flex: `0 0 ${formattedWidth}` }
68
+ return {
69
+ flex: `0 0 ${formattedWidth}`,
70
+ justifyContent,
71
+ textAlign: align,
72
+ }
56
73
  }
57
74
 
58
- return { flex: 1 }
75
+ return {
76
+ flex: 1,
77
+ justifyContent,
78
+ textAlign: align,
79
+ }
59
80
  }
60
81
 
61
82
  /**
@@ -82,10 +103,14 @@ function getRowKey<T extends object>(
82
103
  /**
83
104
  * 渲染文本节点;字符串/数字包一层 Text,其它节点原样返回
84
105
  */
85
- function renderText(content: React.ReactNode, className: string) {
106
+ function renderText(
107
+ content: React.ReactNode,
108
+ className: string,
109
+ style?: React.CSSProperties,
110
+ ) {
86
111
  if (typeof content === 'string' || typeof content === 'number') {
87
112
  return (
88
- <Text className={className}>
113
+ <Text className={className} style={style}>
89
114
  {content}
90
115
  </Text>
91
116
  )
@@ -99,6 +124,9 @@ function Table<T extends object>(props: TableProps<T>) {
99
124
  dataSource,
100
125
  columns,
101
126
  rowKey,
127
+ headerBackgroundColor,
128
+ headerTextBold = false,
129
+ textAlign = 'left',
102
130
  className,
103
131
  style,
104
132
  } = props
@@ -112,15 +140,22 @@ function Table<T extends object>(props: TableProps<T>) {
112
140
  className={formatClassNames(styles['table'], className)}
113
141
  style={style}
114
142
  >
115
- <View className={styles['table-header']}>
143
+ <View
144
+ className={styles['table-header']}
145
+ style={headerBackgroundColor ? { background: headerBackgroundColor } : undefined}
146
+ >
116
147
  {
117
148
  columns.map(column => (
118
149
  <View
119
150
  key={String(column.dataIndex)}
120
151
  className={styles['table-cell']}
121
- style={getCellStyle(column.width)}
152
+ style={getCellStyle(column.width, textAlign)}
122
153
  >
123
- {renderText(column.title, styles['table-header-text'])}
154
+ {renderText(
155
+ column.title,
156
+ styles['table-header-text'],
157
+ headerTextBold ? { fontWeight: 500 } : undefined,
158
+ )}
124
159
  </View>
125
160
  ))
126
161
  }
@@ -147,9 +182,13 @@ function Table<T extends object>(props: TableProps<T>) {
147
182
  <View
148
183
  key={`${currentRowKey}-${String(column.dataIndex)}`}
149
184
  className={styles['table-cell']}
150
- style={getCellStyle(column.width)}
185
+ style={getCellStyle(column.width, textAlign)}
151
186
  >
152
- {renderText(content as React.ReactNode, styles['table-cell-text'])}
187
+ {renderText(
188
+ content as React.ReactNode,
189
+ styles['table-cell-text'],
190
+ { textAlign },
191
+ )}
153
192
  </View>
154
193
  )
155
194
  })