Skip to content

Commit e606a0b

Browse files
committed
feat: 组件图标尺寸治理
1 parent 0dcd2b4 commit e606a0b

21 files changed

Lines changed: 74 additions & 27 deletions

File tree

.cursor/skills/nutui-proportional-scaling/SKILL.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ description: >-
7979
- 图标占位:**`scale-icon-px`** 或已有 `--nut-icon-*`
8080
- 保持与 **无障碍/大屏** 相关提交协同:同一文件改尺度时,勿回退 `dialog` 等对大字兼容的改动。
8181

82+
### 3.5 组件 `.tsx` 图标尺寸治理(props → class → 变量)
83+
84+
-`@nutui/icons-react` / `@nutui/icons-react-taro`:尽量避免在组件上写死 `size={12}``width={16}``height={16}`
85+
- **推荐模式**:在 `.tsx` 里只加语义化 `className`,到对应 `.scss` 里用变量控制尺寸(优先 `$icon-size-*` 阶梯,或组件专用变量)。
86+
- 若是内联 `<svg>`(非 NutUI 图标组件)也遵循同一规则:移除 `width/height` 字面量,改为 class,并在 SCSS 用变量(可新增如 `$xxx-icon-size`,默认 `scale-icon-px(Npx)`)。
87+
- 新增尺寸档优先沉淀到 `variables.scss`(如 `$icon-size-11``$icon-size-16`),避免同一像素值在多个组件重复散落。
88+
8289
### 3.4 `calc()`、Sass 变量与 `#{}`(与 `variables.scss` / 主题 token 一致)
8390

8491
- **推荐**:在 `calc()` 里直接写 Sass 变量,如 **`calc($steps-vertical-head-icon-size + 1px)`****`calc($rate-item-margin / 2)`**,而不是 **`calc(#{$steps-vertical-head-icon-size} + 1px)`**`#{}` 只在需要把值**硬插成无引号 CSS 片段**、或要避免 Sass 对单位做提前合并时再考虑;普通设计 token 用 **`$var` 作为 `calc` 的操作数**即可。
@@ -104,6 +111,7 @@ description: >-
104111
- [ ] 字体/图标是否应走 **`scale-font-px` / `scale-icon-px`** 而非误用 `scale-px`
105112
- [ ]**`$token` 与裸 `px` 的混合运算**:若 token 会变成 **`var(--nutui-*)`**,是否已用 **`calc($a - $b + Npx)`**,而不是 **`($a - $b + Npx)`** 写在 `margin` / `width` 等非纯编译期长度位置。
106113
- [ ] `calc()` 内对设计 token 是否优先 **`calc($var + 1px)`**,避免无必要的 **`#{}`**
114+
- [ ] 组件 `.tsx` 是否仍有写死图标尺寸(`size/width/height`);如有,是否已改为 **class + SCSS 变量**(内联 `svg` 同理)。
107115
- [ ] TS 侧改 `scale-f*` 已同步考虑 **Taro** 文件。
108116
- [ ] 修改 `formatScaleValue` / 断点时,已通读 **视口与平板常量** 是否仍与文档、设计一致。
109117

src/packages/calendarcard/calendarcard.scss

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
border-radius: 12px;
44
overflow: hidden;
55
font-size: $calendar-base-font-size;
6-
line-height: $line-height-l;
7-
line-height: $calendar-base-font-size;
86
color: $color-title;
97

108
&-header {
@@ -13,6 +11,7 @@
1311
align-items: center;
1412
justify-content: space-between;
1513
font-weight: normal;
14+
line-height: $line-height-l;
1615

1716
&-left,
1817
&-right {

src/packages/card/card.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
&-title {
2929
@include moreline-ellipsis();
30-
line-height: $line-height-xl;
30+
line-height: $line-height-2xl;
3131
font-size: $font-size-base;
3232
color: $color-title;
3333
}

src/packages/inputnumber/inputnumber.taro.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ export const InputNumber: FunctionComponent<
184184
<View className={classes} style={style}>
185185
<View className={`${classPrefix}-minus`} onClick={handleReduce}>
186186
<Minus
187-
size={10}
188187
className={classNames(
189188
`${classPrefix}-icon ${classPrefix}-icon-minus`,
190189
{
@@ -211,7 +210,6 @@ export const InputNumber: FunctionComponent<
211210

212211
<View className={`${classPrefix}-add`} onClick={handlePlus}>
213212
<Plus
214-
size={10}
215213
className={classNames(
216214
`${classPrefix}-icon ${classPrefix}-icon-plus`,
217215
{

src/packages/menuitem/menuitem.taro.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ export const MenuItem = forwardRef((props: Partial<WebMenuItemProps>, ref) => {
233233
) : (
234234
<Check
235235
color={activeColor}
236-
size={16}
237236
className={`nut-menu-container-item-icon ${getIconCName(item.value, value)}`}
238237
/>
239238
)}

src/packages/noticebar/noticebar.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@
7474
}
7575
}
7676

77+
&-right-icon-default {
78+
width: $icon-size-12;
79+
height: $icon-size-12;
80+
}
81+
7782
&-wrap {
7883
display: flex;
7984
flex: 1;

src/packages/noticebar/noticebar.taro.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const defaultProps = {
2626
content: '',
2727
closeable: false,
2828
wrap: false,
29-
leftIcon: <Notice size={16} />,
29+
leftIcon: <Notice />,
3030
rightIcon: null,
3131
right: null,
3232
delay: 1,
@@ -490,7 +490,9 @@ export const NoticeBar: FunctionComponent<
490490
className="nut-noticebar-box-right-icon"
491491
onClick={handleClickIcon}
492492
>
493-
{rightIcon || <Close size={12} />}
493+
{rightIcon || (
494+
<Close className="nut-noticebar-box-right-icon-default" />
495+
)}
494496
</View>
495497
) : null}
496498
</>

src/packages/noticebar/noticebar.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const defaultProps = {
2424
content: '',
2525
closeable: false,
2626
wrap: false,
27-
leftIcon: <Notice width={16} height={16} />,
27+
leftIcon: <Notice />,
2828
rightIcon: null,
2929
right: null,
3030
delay: 1,
@@ -475,7 +475,9 @@ export const NoticeBar: FunctionComponent<
475475
) : null}
476476
{closeable || rightIcon ? (
477477
<div className="nut-noticebar-box-right-icon" onClick={onClickIcon}>
478-
{rightIcon || <Close width={12} height={12} />}
478+
{rightIcon || (
479+
<Close className="nut-noticebar-box-right-icon-default" />
480+
)}
479481
</div>
480482
) : null}
481483
</div>
@@ -534,7 +536,10 @@ export const NoticeBar: FunctionComponent<
534536
handleClickIcon(e)
535537
}}
536538
>
537-
{rightIcon || (closeable ? <Close width={12} height={12} /> : null)}
539+
{rightIcon ||
540+
(closeable ? (
541+
<Close className="nut-noticebar-box-right-icon-default" />
542+
) : null)}
538543
</div>
539544
</div>
540545
) : null}

src/packages/notify/notify.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,9 @@
9898
width: 12px;
9999
}
100100
}
101+
102+
&-close-icon {
103+
height: $icon-size-12;
104+
width: $icon-size-12;
105+
}
101106
}

src/packages/notify/notify.taro.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,10 @@ export const Notify: FunctionComponent<Partial<TaroNotifyProps>> & {
142142
className={`${classPrefix}-right-icon`}
143143
onClick={handleClickIcon}
144144
>
145-
{rightIcon || (closeable ? <Close size={12} /> : null)}
145+
{rightIcon ||
146+
(closeable ? (
147+
<Close className={`${classPrefix}-close-icon`} />
148+
) : null)}
146149
</View>
147150
) : null}
148151
</View>

0 commit comments

Comments
 (0)