Skip to content

Commit cdac788

Browse files
committed
fix: modify cr
1 parent feeb8b6 commit cdac788

File tree

10 files changed

+34
-31
lines changed

10 files changed

+34
-31
lines changed

src/packages/switch/demos/h5/demo2.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ import { Cell, Switch, Toast } from '@nutui/nutui-react'
44
const Demo2 = () => {
55
const [checkedAsync, setCheckedAsync] = useState(true)
66

7-
const mockRequest = (): Promise<void> => {
8-
return new Promise((resolve) => {
7+
const onChangeAsync = async (value: boolean) => {
8+
Toast.show(`2秒后异步触发 ${value}`)
9+
const res = await new Promise((resolve) => {
910
setTimeout(() => {
10-
resolve()
11+
resolve(true)
1112
}, 2000)
1213
})
13-
}
14-
15-
const onChangeAsync = async (value: boolean) => {
16-
Toast.show(`2秒后异步触发 ${value}`)
17-
await mockRequest()
18-
setCheckedAsync(value)
14+
if (!res) {
15+
throw new Error()
16+
} else {
17+
setCheckedAsync(value)
18+
}
1919
}
2020
return (
2121
<Cell>

src/packages/switch/demos/taro/demo2.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,20 @@ const Demo2 = () => {
55
const [checkedAsync, setCheckedAsync] = useState(true)
66
const [value, setValue] = useState(false)
77
const [showToast, setShowToast] = useState(false)
8-
const mockRequest = (): Promise<void> => {
9-
return new Promise((resolve) => {
10-
setTimeout(() => {
11-
resolve()
12-
}, 2000)
13-
})
14-
}
158

169
const onChangeAsync = async (value: boolean) => {
1710
setValue(value)
1811
setShowToast(true)
19-
await mockRequest()
20-
setCheckedAsync(value)
12+
const res = await new Promise((resolve) => {
13+
setTimeout(() => {
14+
resolve(true)
15+
}, 2000)
16+
})
17+
if (!res) {
18+
throw new Error()
19+
} else {
20+
setCheckedAsync(value)
21+
}
2122
}
2223
return (
2324
<>

src/packages/switch/doc.en-US.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ import { Switch } from '@nutui/nutui-react'
7777
| disabled | Disabled | `boolean` | `false` |
7878
| activeText | Text description when opening | `ReactNode` | `-` |
7979
| inactiveText | Text description when closed | `ReactNode` | `-` |
80-
| loadingIcon | Control the loading state icon, disable the loading state when a null | `ReactNode` | `<Loading1 />` |
8180
| onChange | Trigger when switching switches | `onChange:(value: boolean, event: Event)` | `-` |
8281

8382
## Theming

src/packages/switch/doc.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ import { Switch } from '@nutui/nutui-react'
7777
| disabled | 禁用状态 | `boolean` | `false` |
7878
| activeText | 打开时文字描述 | `ReactNode` | `-` |
7979
| inactiveText | 关闭时文字描述 | `ReactNode` | `-` |
80-
| loadingIcon | 控制加载状态的图标,传入空值时禁用 loading 态 | `ReactNode` | `<Loading1 />` |
8180
| onChange | 切换开关时触发 | `onChange:(value: boolean, event: Event)` | `-` |
8281

8382
## 主题定制

src/packages/switch/doc.taro.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ import { Switch } from '@nutui/nutui-react-taro'
7777
| disabled | 禁用状态 | `boolean` | `false` |
7878
| activeText | 打开时文字描述 | `ReactNode` | `-` |
7979
| inactiveText | 关闭时文字描述 | `ReactNode` | `-` |
80-
| loadingIcon | 控制加载状态的图标,传入空值时禁用 loading 态 | `ReactNode` | `<Loading1 />` |
8180
| onChange | 切换开关时触发 | `onChange:(value: boolean, event: Event)` | `-` |
8281

8382
## 主题定制

src/packages/switch/doc.zh-TW.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ import { Switch } from '@nutui/nutui-react'
7777
| disabled | 禁用狀態 | `boolean` | `false` |
7878
| activeText | 打開時文字描述 | `ReactNode` | `-` |
7979
| inactiveText | 關閉時文字描述 | `ReactNode` | `-` |
80-
| loadingIcon | 控制加載狀態的圖標,當傳入空值時禁用 loading 狀態 | `ReactNode` | `<Loading1 />` |
8180
| onChange | 切換開關時觸發 | `onChange:(value: boolean, event: Event)` | `-` |
8281

8382
## 主題定製

src/packages/switch/switch.taro.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const Switch: FunctionComponent<Partial<TaroSwitchProps>> = (props) => {
3434
const classPrefix = 'nut-switch'
3535

3636
const rtl = useRtl()
37-
37+
console.log('checked', checked)
3838
const [value, setValue] = usePropsValue<boolean>({
3939
value: checked,
4040
defaultValue: defaultChecked,
@@ -58,11 +58,15 @@ export const Switch: FunctionComponent<Partial<TaroSwitchProps>> = (props) => {
5858
])
5959
}
6060

61-
const onClick = () => {
61+
const onClick = async () => {
6262
if (disabled || changing) return
6363
if (onChange) {
64-
loadingIcon && setChanging(true)
65-
onChange(!value)
64+
setChanging(true)
65+
try {
66+
await onChange(!value)
67+
} catch (e) {
68+
setChanging(false)
69+
}
6670
}
6771
setValue(!value)
6872
}

src/packages/switch/switch.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,15 @@ export const Switch: FunctionComponent<Partial<WebSwitchProps>> = (props) => {
5656
])
5757
}
5858

59-
const onClick = () => {
59+
const onClick = async () => {
6060
if (disabled || changing) return
6161
if (onChange) {
62-
loadingIcon && setChanging(true)
63-
onChange(!value)
62+
setChanging(true)
63+
try {
64+
await onChange(!value)
65+
} catch (e) {
66+
setChanging(false)
67+
}
6468
}
6569
setValue(!value)
6670
}

src/sites/sites-react/doc/docs/react/migrate-from-v2.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ plugins: [
238238

239239
- `activeText` 属性类型更改为`ReactNode`
240240
- `inactiveText` 属性类型更改为 `ReactNode`
241-
- 新增 `loadingIcon` 属性,受控 loading 态图标
242241

243242
[//]: # '#### Toast'
244243

src/sites/sites-react/doc/docs/taro/migrate-from-v2.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ plugins: [
237237

238238
- `activeText` 属性类型更改为`ReactNode`
239239
- `inactiveText` 属性类型更改为 `ReactNode`
240-
- 新增 `loadingIcon` 属性,受控 loading 态图标
241240

242241
[//]: # '#### Toast'
243242

0 commit comments

Comments
 (0)