@yorkjs/hive-ui 2.0.6 → 2.0.7

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.6",
3
+ "version": "2.0.7",
4
4
  "description": "Hive UI - Taro React component library",
5
5
  "main": "src/index.ts",
6
6
  "module": "src/index.ts",
@@ -0,0 +1,15 @@
1
+ .has-hitSlop
2
+ position relative
3
+ display inline-block
4
+ vertical-align middle
5
+
6
+ &:after
7
+ content ''
8
+ position absolute
9
+ top var(--hit-slop-top, 0)
10
+ right var(--hit-slop-right, 0)
11
+ bottom var(--hit-slop-bottom, 0)
12
+ left var(--hit-slop-left, 0)
13
+
14
+ background-color transparent
15
+ z-index 1
@@ -1,8 +1,17 @@
1
- import React from 'react'
1
+ import React, { useMemo } from 'react'
2
2
  import { Text } from '@tarojs/components'
3
3
 
4
4
  import { formatClassNames } from '../../util/function'
5
5
 
6
+ import styles from './index.module.styl'
7
+
8
+ interface HitSlop {
9
+ top?: number
10
+ right?: number
11
+ bottom?: number
12
+ left?: number
13
+ }
14
+
6
15
  interface IconProps {
7
16
  /** 图标名称,对应 iconfont 中的类名后缀 */
8
17
  name: string
@@ -16,6 +25,8 @@ interface IconProps {
16
25
  style?: React.CSSProperties
17
26
  /** 点击事件 */
18
27
  onClick?: (event: any) => void
28
+ /** 扩大选区*/
29
+ hitSlop?: number | HitSlop
19
30
  }
20
31
 
21
32
  const Icon: React.FC<IconProps> = (props) => {
@@ -25,11 +36,28 @@ const Icon: React.FC<IconProps> = (props) => {
25
36
  size,
26
37
  className,
27
38
  style,
39
+ hitSlop,
28
40
  onClick
29
41
  } = props
30
42
 
43
+ const hitSlopVars = useMemo(() => {
44
+ if (!hitSlop) return {}
45
+ const { top = 0, right = 0, bottom = 0, left = 0 } =
46
+ typeof hitSlop === 'number'
47
+ ? { top: hitSlop, right: hitSlop, bottom: hitSlop, left: hitSlop }
48
+ : hitSlop
49
+
50
+ return {
51
+ '--hit-slop-top': `-${top}px`,
52
+ '--hit-slop-right': `-${right}px`,
53
+ '--hit-slop-bottom': `-${bottom}px`,
54
+ '--hit-slop-left': `-${left}px`,
55
+ }
56
+ }, [hitSlop])
57
+
31
58
  const iconStyle: React.CSSProperties = {
32
59
  ...style,
60
+ ...hitSlopVars,
33
61
  lineHeight: 1,
34
62
  color: color,
35
63
  fontSize: typeof size === 'number' ? `${size}PX` : size
@@ -40,6 +68,7 @@ const Icon: React.FC<IconProps> = (props) => {
40
68
  className={formatClassNames(
41
69
  'iconfont',
42
70
  `icon-${name}`,
71
+ hitSlop ? styles['has-hitSlop'] : '',
43
72
  className)
44
73
  }
45
74
  style={iconStyle}