@sj-distributor/react-iconfont-cli 2.6.0 → 2.6.2

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