Skip to content

Commit f3e2b10

Browse files
committed
chore: 还原部分改动
1 parent 4d19218 commit f3e2b10

10 files changed

Lines changed: 55 additions & 33 deletions

File tree

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ description: >-
88
scripts/px-to-scale-px-in-component-scss.cjs on component SCSS in memory; profiles standard / large / elderly;
99
commit-backed rules e.g. never scale 0px. Use when implementing 多尺寸适配,
1010
等比适配, 大字版, 老年版, scale-px, viewport or native bridge scaling, or
11-
editing component SCSS for resize.
11+
editing component SCSS for resize; SCSS: prefer calc($token + Npx) over
12+
#{} in calc, use outer calc() when mixing tokens that compile to
13+
var(--nutui-*).
1214
---
1315

1416
# NutUI React 等比适配
@@ -51,8 +53,9 @@ description: >-
5153

5254
### 2.1 `npm run build` / `npm run build:taro` 时的 px → `scale-px`
5355

54-
-`package.json` 中顺序一致:先跑 **`scripts/replace-css-var.js`**,再 **`scripts/build.mjs`****`scripts/build-taro.mjs`**;上述脚本在读取 **`src/packages/**/\*.scss`(不含 demo)** 后,会经 **`scripts/px-to-scale-px-in-component-scss.cjs`****内存**里把声明值中的裸 **`Npx`** 转为 **`scale-px(Npx)`**(规则见 §3),**不写回\*\*仓库文件
56+
-`package.json` 中顺序一致:先跑 **`scripts/replace-css-var.js`**,再 **`scripts/build.mjs`****`scripts/build-taro.mjs`**;上述脚本在读取 **`src/packages/**/\*.scss`(不含 demo)** 后,会经 **`scripts/px-to-scale-px-in-component-scss.cjs`****内存**里把声明值中的裸 **`Npx`** 转为 **`scale-px(Npx)`**(规则见 §3),**不写回\*\*仓库里的组件 SCSS
5557
- 源码里可继续手写 **`scale-px` / `scale-font-px` / `scale-icon-px`**;构建不会重复嵌套 `scale-px`
58+
- 该脚本对 **`calc(...)` 体内同时含 `$``/`** 的整段先做占位再替换裸 `px`,避免 postcss-scss 把 **`calc($var / 2)`** 等拆坏;其它 `calc` 内的裸 `Npx` 仍会按规则转为 `scale-px`
5659

5760
---
5861

@@ -76,6 +79,14 @@ description: >-
7679
- 图标占位:**`scale-icon-px`** 或已有 `--nut-icon-*`
7780
- 保持与 **无障碍/大屏** 相关提交协同:同一文件改尺度时,勿回退 `dialog` 等对大字兼容的改动。
7881

82+
### 3.4 `calc()`、Sass 变量与 `#{}`(与 `variables.scss` / 主题 token 一致)
83+
84+
- **推荐**:在 `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` 的操作数**即可。
85+
- **`var(--nutui-*)` 一起运算时**:许多 token 会展开为 **`var(--nutui-…, calc(Npx * var(--nut-scale-f, 1)))`**。此时**不要**指望纯 Sass 括号在声明值里做「减法 + 固定 px」,例如
86+
**`margin: 0 ($switch-height - $switch-border-width + 3px) 0 7px`**
87+
会在编译结果里拼成 **`var(...)var(...)`** 一类**缺少运算符**的非法片段。应写成 **`margin: 0 calc($switch-height - $switch-border-width + 3px) 0 7px`**,让整条长度在**一个** CSS `calc()` 里由浏览器解析。
88+
- **`100%` 与长度相减**:用 **`calc(100% - Npx)`** 一层即可,避免出现 **`100% - calc(...)`** 这类单位不合法的组合(历史上有过 postcss / 手工替换导致的损坏,以当前组件 SCSS 为准)。
89+
7990
---
8091

8192
## 4. 业务接入清单
@@ -91,6 +102,8 @@ description: >-
91102

92103
- [ ] 新增 **0** 尺寸未误用 `scale-px(0px)`
93104
- [ ] 字体/图标是否应走 **`scale-font-px` / `scale-icon-px`** 而非误用 `scale-px`
105+
- [ ]**`$token` 与裸 `px` 的混合运算**:若 token 会变成 **`var(--nutui-*)`**,是否已用 **`calc($a - $b + Npx)`**,而不是 **`($a - $b + Npx)`** 写在 `margin` / `width` 等非纯编译期长度位置。
106+
- [ ] `calc()` 内对设计 token 是否优先 **`calc($var + 1px)`**,避免无必要的 **`#{}`**
94107
- [ ] TS 侧改 `scale-f*` 已同步考虑 **Taro** 文件。
95108
- [ ] 修改 `formatScaleValue` / 断点时,已通读 **视口与平板常量** 是否仍与文档、设计一致。
96109

src/packages/avatarcropper/avatarcropper.taro.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ import React, {
44
useMemo,
55
useCallback,
66
FunctionComponent,
7-
useLayoutEffect,
87
} from 'react'
9-
import Taro, { createSelectorQuery } from '@tarojs/taro'
8+
import Taro, { useReady, createSelectorQuery } from '@tarojs/taro'
109
import classNames from 'classnames'
1110
import { Canvas, CommonEventFunction, View } from '@tarojs/components'
1211
import { getWindowInfo } from '@/utils/taro/get-system-info'
@@ -138,7 +137,7 @@ export const AvatarCropper: FunctionComponent<
138137
cropperCanvasContext: null,
139138
})
140139

141-
useLayoutEffect(() => {
140+
useReady(() => {
142141
if (showAlipayCanvas2D) {
143142
const { canvasId } = canvasAll
144143
createSelectorQuery()
@@ -150,7 +149,7 @@ export const AvatarCropper: FunctionComponent<
150149
})
151150
.exec()
152151
}
153-
}, [showAlipayCanvas2D, state.displayHeight, state.displayWidth])
152+
})
154153

155154
useEffect(() => {
156155
setCanvasAll({

src/packages/button/button.taro.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import React, { CSSProperties, useCallback, useMemo } from 'react'
22
import type { MouseEvent } from 'react'
33
import classNames from 'classnames'
4-
import { View } from '@tarojs/components'
4+
import {
5+
View,
6+
// Button as TaroButton,
7+
} from '@tarojs/components'
58
import { Loading } from '@nutui/icons-react-taro'
69
import { ComponentDefaults } from '@/utils/typings'
710
import { harmony } from '@/utils/taro/platform'

src/packages/checkbox/checkbox.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
height: 12px;
118118
position: absolute;
119119
color: $white;
120-
right: 0px;
120+
right: 0;
121121
bottom: 0;
122122
transform: translate(-1px, -2px);
123123
}

src/packages/fixednav/fixednav.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
right: 0;
9090
.nut-fixednav-btn {
9191
right: 0;
92-
border-radius: 45px 0 0 45px;
92+
border-radius: 45px 0px 0px 45px;
9393
.nut-icon {
9494
margin-right: 5px;
9595
transform: rotate(0deg);
@@ -98,7 +98,7 @@
9898
.nut-fixednav-list {
9999
right: 0;
100100
transform: translateX(100%);
101-
border-radius: 25px 0 0 25px;
101+
border-radius: 25px 0px 0px 25px;
102102
padding: {
103103
left: 20px;
104104
right: 80px;
@@ -121,7 +121,7 @@
121121
.nut-fixednav-list {
122122
transform: translateX(-100%);
123123
left: 0;
124-
border-radius: 0 25px 25px 0;
124+
border-radius: 0px 25px 25px 0px;
125125
padding: {
126126
left: 80px;
127127
right: 20px;

src/packages/lottie/lottiemp.taro.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import React, { useImperativeHandle, useLayoutEffect, useRef } from 'react'
2-
import { createSelectorQuery, getEnv, useUnload } from '@tarojs/taro'
1+
import React, { useImperativeHandle, useRef } from 'react'
2+
import { createSelectorQuery, getEnv, useReady, useUnload } from '@tarojs/taro'
33
import lottie from '@nutui/lottie-miniprogram'
44
import { getWindowInfo } from '@/utils/taro/get-system-info'
55
import { useUuid } from '@/hooks/use-uuid'
@@ -21,9 +21,16 @@ export const Lottie = React.forwardRef((props: TaroLottieProps, ref: any) => {
2121
dpr = true,
2222
} = props
2323

24+
const setSpeed = () => {
25+
if (animation.current) {
26+
animation.current.setSpeed(Math.abs(speed))
27+
animation.current.setDirection(speed > 0 ? 1 : -1)
28+
}
29+
}
30+
2431
useImperativeHandle(ref, () => animation.current || {})
2532
const pixelRatio = useRef(getWindowInfo().pixelRatio)
26-
useLayoutEffect(() => {
33+
useReady(() => {
2734
createSelectorQuery()
2835
.select(`#${id}`)
2936
.fields(
@@ -57,22 +64,17 @@ export const Lottie = React.forwardRef((props: TaroLottieProps, ref: any) => {
5764
context,
5865
},
5966
})
60-
if (onComplete) {
67+
onComplete &&
6168
animation.current.addEventListener('complete', onComplete)
62-
}
63-
64-
if (animation.current) {
65-
animation.current.setSpeed(Math.abs(speed))
66-
animation.current.setDirection(speed > 0 ? 1 : -1)
67-
}
69+
setSpeed()
6870
inited.current = true
6971
} catch (error) {
7072
console.error(error)
7173
}
7274
}
7375
)
7476
.exec()
75-
}, [autoPlay, dpr, id, loop, onComplete, source, speed, style])
77+
})
7678

7779
useUnload(() => {
7880
onComplete &&

src/packages/overlay/overlay.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import classNames from 'classnames'
1010
import { ComponentDefaults } from '@/utils/typings'
1111
import { useLockScroll } from '@/hooks/use-lock-scroll'
1212
import { WebOverlayProps } from '@/types'
13+
import { useConfig } from '@/packages/configprovider'
1314

1415
export const defaultOverlayProps: WebOverlayProps = {
1516
...ComponentDefaults,
@@ -37,12 +38,14 @@ export const Overlay: FunctionComponent<
3738
afterShow,
3839
afterClose,
3940
onClick,
41+
ariaLabel,
4042
...rest
4143
} = { ...defaultOverlayProps, ...props }
4244

4345
const classPrefix = 'nut-overlay'
4446
const [innerVisible, setInnerVisible] = useState(visible)
4547
const nodeRef = useRef(null)
48+
const { locale } = useConfig()
4649

4750
useEffect(() => {
4851
setInnerVisible(visible)
@@ -78,6 +81,9 @@ export const Overlay: FunctionComponent<
7881
style={styles}
7982
{...rest}
8083
onClick={handleClick}
84+
{...(closeOnOverlayClick
85+
? { ariaLabel: ariaLabel || locale.mask }
86+
: {})}
8187
>
8288
{children}
8389
</div>

src/packages/popover/popover.taro.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ export const Popover: FunctionComponent<
265265
<View className="nut-popover-content-group" ref={popoverContentRef}>
266266
{showArrow && (
267267
<View className={popoverArrow()} style={popoverArrowStyle()}>
268-
<ArrowRadius width={8} height={4} />
268+
<ArrowRadius />
269269
</View>
270270
)}
271271
{Array.isArray(children) ? children[1] : null}

src/packages/rate/rate.taro.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import React, {
22
FunctionComponent,
33
ReactElement,
4-
useCallback,
54
useEffect,
6-
useLayoutEffect,
75
useRef,
86
useState,
97
} from 'react'
108
import classNames from 'classnames'
119
import { StarFill } from '@nutui/icons-react-taro'
10+
import { useReady } from '@tarojs/taro'
1211
import { ITouchEvent, Text, View } from '@tarojs/components'
1312
import { ComponentDefaults } from '@/utils/typings'
1413
import { usePropsValue } from '@/hooks/use-props-value'
@@ -132,7 +131,7 @@ export const Rate: FunctionComponent<Partial<TaroRateProps>> = (props) => {
132131
}
133132
}
134133

135-
const updateRects = useCallback(() => {
134+
const updateRects = () => {
136135
for (let index = 0; index < refs.length; index++) {
137136
const item = refs[index]
138137
if (item) {
@@ -141,11 +140,11 @@ export const Rate: FunctionComponent<Partial<TaroRateProps>> = (props) => {
141140
})
142141
}
143142
}
144-
}, [refs])
143+
}
145144

146-
useLayoutEffect(() => {
145+
useReady(() => {
147146
updateRects()
148-
}, [updateRects])
147+
})
149148

150149
const handleTouchStart = (e: any) => {
151150
if (!touchable || readOnly || disabled) {

src/packages/switch/switch.scss

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,16 @@
7878
color: $switch-label-text-color;
7979
}
8080
&-open {
81-
margin: 0 ($switch-height - $switch-border-width + 3px) 0 7px;
81+
margin: 0 calc($switch-height - $switch-border-width + 3px) 0 7px;
8282
&-rtl {
83-
margin: 0 7px 0 ($switch-height - $switch-border-width + 3px);
83+
margin: 0 7px 0 calc($switch-height - $switch-border-width + 3px);
8484
}
8585
}
8686

8787
&-close {
88-
margin: 0 7px 0 ($switch-height - $switch-border-width + 3px);
88+
margin: 0 7px 0 calc($switch-height - $switch-border-width + 3px);
8989
&-rtl {
90-
margin: 0 ($switch-height - $switch-border-width + 3px) 0 7px;
90+
margin: 0 calc($switch-height - $switch-border-width + 3px) 0 7px;
9191
}
9292
}
9393

0 commit comments

Comments
 (0)