@sj-distributor/react-iconfont-cli 2.6.0 → 2.6.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/README.md +1 -1
- package/package.json +1 -1
- package/templates/Icon.js.template +12 -1
- package/templates/Icon.tsx.template +13 -2
package/README.md
CHANGED
|
@@ -177,7 +177,7 @@ const handleIconClick = () => {
|
|
|
177
177
|
/>;
|
|
178
178
|
```
|
|
179
179
|
|
|
180
|
-
`buttonProps` 用于设置外层按钮的属性;`className`、`style` 等普通图标属性仍应用到内部 SVG
|
|
180
|
+
`buttonProps` 用于设置外层按钮的属性;`className`、`style` 等普通图标属性仍应用到内部 SVG。按钮默认为 `type="button"`,并进行最小样式重置:背景透明、无边框、无内边距,同时移除浏览器原生按钮外观。除此之外不附带布局、尺寸或颜色样式,调用方可以使用普通 CSS、CSS Modules 或 Tailwind CSS 自行控制。需要覆盖重置项时,可通过 `buttonProps.style` 设置。原生按钮已经支持 Enter/Space 键盘操作,因此不需要额外添加 `onKeyDown`。
|
|
181
181
|
|
|
182
182
|
交互模式下,顶层的 `aria-*`、`role` 和 `tabIndex` 会自动应用到外层按钮,不会留在已隐藏的 SVG 上。除 `aria-label` 和 `onClick` 外,也可以通过 `buttonProps` 设置按钮属性;同名属性以 `buttonProps` 为准。
|
|
183
183
|
|
package/package.json
CHANGED
|
@@ -4,6 +4,13 @@ import React from 'react';
|
|
|
4
4
|
#imports#
|
|
5
5
|
#exports#
|
|
6
6
|
|
|
7
|
+
const DEFAULT_BUTTON_STYLE = {
|
|
8
|
+
appearance: 'none',
|
|
9
|
+
background: 'transparent',
|
|
10
|
+
border: 0,
|
|
11
|
+
padding: 0,
|
|
12
|
+
};
|
|
13
|
+
|
|
7
14
|
const splitInteractiveProps = (props) => {
|
|
8
15
|
const buttonA11yProps = {};
|
|
9
16
|
const iconProps = {};
|
|
@@ -54,8 +61,11 @@ const IconFont = ({
|
|
|
54
61
|
return icon;
|
|
55
62
|
}
|
|
56
63
|
|
|
57
|
-
const { type = 'button', ...restButtonProps } = buttonProps;
|
|
64
|
+
const { style: buttonStyle, type = 'button', ...restButtonProps } = buttonProps;
|
|
58
65
|
delete restButtonProps.dangerouslySetInnerHTML;
|
|
66
|
+
const style = buttonStyle
|
|
67
|
+
? { ...DEFAULT_BUTTON_STYLE, ...buttonStyle }
|
|
68
|
+
: DEFAULT_BUTTON_STYLE;
|
|
59
69
|
const accessibilityLabel =
|
|
60
70
|
typeof ariaLabel === 'string' && ariaLabel.trim()
|
|
61
71
|
? ariaLabel.trim()
|
|
@@ -68,6 +78,7 @@ const IconFont = ({
|
|
|
68
78
|
type={type}
|
|
69
79
|
aria-label={accessibilityLabel}
|
|
70
80
|
onClick={onClick}
|
|
81
|
+
style={style}
|
|
71
82
|
>
|
|
72
83
|
{icon}
|
|
73
84
|
</button>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
|
|
4
|
-
import #reactName#{ ButtonHTMLAttributes, FunctionComponent, MouseEventHandler, ReactElement, SVGAttributes } from 'react';
|
|
4
|
+
import #reactName#{ ButtonHTMLAttributes, CSSProperties, FunctionComponent, MouseEventHandler, ReactElement, SVGAttributes } from 'react';
|
|
5
5
|
#imports#
|
|
6
6
|
#exports#
|
|
7
7
|
|
|
@@ -20,6 +20,13 @@ interface Props extends IconProps {
|
|
|
20
20
|
buttonProps?: ButtonProps;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
const DEFAULT_BUTTON_STYLE: CSSProperties = {
|
|
24
|
+
appearance: 'none',
|
|
25
|
+
background: 'transparent',
|
|
26
|
+
border: 0,
|
|
27
|
+
padding: 0,
|
|
28
|
+
};
|
|
29
|
+
|
|
23
30
|
const splitInteractiveProps = (props: IconProps) => {
|
|
24
31
|
const source = props as Record<string, unknown>;
|
|
25
32
|
const buttonA11yProps: Record<string, unknown> = {};
|
|
@@ -74,9 +81,12 @@ const IconFont: FunctionComponent<Props> = ({
|
|
|
74
81
|
return icon;
|
|
75
82
|
}
|
|
76
83
|
|
|
77
|
-
const { type = 'button', ...restButtonProps } = buttonProps;
|
|
84
|
+
const { style: buttonStyle, type = 'button', ...restButtonProps } = buttonProps;
|
|
78
85
|
const safeButtonProps = restButtonProps as ButtonHTMLAttributes<HTMLButtonElement>;
|
|
79
86
|
delete safeButtonProps.dangerouslySetInnerHTML;
|
|
87
|
+
const style = buttonStyle
|
|
88
|
+
? { ...DEFAULT_BUTTON_STYLE, ...buttonStyle }
|
|
89
|
+
: DEFAULT_BUTTON_STYLE;
|
|
80
90
|
const accessibilityLabel =
|
|
81
91
|
typeof ariaLabel === 'string' && ariaLabel.trim()
|
|
82
92
|
? ariaLabel.trim()
|
|
@@ -89,6 +99,7 @@ const IconFont: FunctionComponent<Props> = ({
|
|
|
89
99
|
type={type}
|
|
90
100
|
aria-label={accessibilityLabel}
|
|
91
101
|
onClick={onClick}
|
|
102
|
+
style={style}
|
|
92
103
|
>
|
|
93
104
|
{icon}
|
|
94
105
|
</button>
|