Skip to content

Commit 04aee9a

Browse files
committed
feat: 修改props定义
1 parent 90d7460 commit 04aee9a

File tree

11 files changed

+55
-55
lines changed

11 files changed

+55
-55
lines changed

src/packages/switch/demo.taro.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const SwitchDemo = () => {
1818
basic: '非受控',
1919
disabled: '禁用状态',
2020
asyncControl: '受控',
21-
changingControl: 'loading 态受控',
21+
loadingControl: 'loading 态受控',
2222
customColor: '自定义颜色',
2323
supportText: '支持文字',
2424
supportIcon: '支持Icon',
@@ -28,7 +28,7 @@ const SwitchDemo = () => {
2828
basic: '非受控',
2929
disabled: '禁用狀態',
3030
asyncControl: '受控',
31-
changingControl: 'loading 態受控',
31+
loadingControl: 'loading 態受控',
3232
customColor: '自定義顏色',
3333
supportText: '支持文字',
3434
supportIcon: '支持Icon',
@@ -38,7 +38,7 @@ const SwitchDemo = () => {
3838
basic: 'Uncontrolled',
3939
disabled: 'Disabled',
4040
asyncControl: 'controlled',
41-
changingControl: 'Controlled with loading',
41+
loadingControl: 'Controlled with loading',
4242
customColor: 'Custom Color',
4343
supportText: 'Support Text',
4444
supportIcon: 'Support Icon',
@@ -53,7 +53,7 @@ const SwitchDemo = () => {
5353
<Demo1 />
5454
<View className="h2">{translated.asyncControl}</View>
5555
<Demo2 />
56-
<View className="h2">{translated.changingControl}</View>
56+
<View className="h2">{translated.loadingControl}</View>
5757
<Demo8 />
5858
<View className="h2">{translated.disabled}</View>
5959
<Demo3 />

src/packages/switch/demo.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const SwitchDemo = () => {
1515
basic: '非受控',
1616
disabled: '禁用状态',
1717
asyncControl: '受控',
18-
changingControl: 'loading 态受控',
18+
loadingControl: 'loading 态受控',
1919
customColor: '自定义颜色',
2020
supportText: '支持文字',
2121
supportIcon: '支持Icon',
@@ -25,7 +25,7 @@ const SwitchDemo = () => {
2525
basic: '非受控',
2626
disabled: '禁用狀態',
2727
asyncControl: '受控',
28-
changingControl: 'loading 態受控',
28+
loadingControl: 'loading 態受控',
2929
customColor: '自定義顏色',
3030
supportText: '支持文字',
3131
supportIcon: '支持Icon',
@@ -35,7 +35,7 @@ const SwitchDemo = () => {
3535
basic: 'Uncontrolled',
3636
disabled: 'Disabled',
3737
asyncControl: 'controlled',
38-
changingControl: 'Controlled with loading',
38+
loadingControl: 'Controlled with loading',
3939
customColor: 'Custom Color',
4040
supportText: 'Support Text',
4141
supportIcon: 'Support Icon',
@@ -49,7 +49,7 @@ const SwitchDemo = () => {
4949
<Demo1 />
5050
<h2>{translated.asyncControl}</h2>
5151
<Demo2 />
52-
<h2>{translated.changingControl}</h2>
52+
<h2>{translated.loadingControl}</h2>
5353
<Demo8 />
5454
<h2>{translated.disabled}</h2>
5555
<Demo3 />

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Cell, Switch, Toast } from '@nutui/nutui-react'
33

44
const Demo8 = () => {
55
const [checkedAsync, setCheckedAsync] = useState(true)
6-
const [externalChanging, setExternalChanging] = useState(false)
6+
const [externalLoading, setExternalLoading] = useState(false)
77

88
const mockRequest = (): Promise<void> => {
99
return new Promise((resolve) => {
@@ -21,9 +21,9 @@ const Demo8 = () => {
2121
return (
2222
<Cell>
2323
<Switch
24-
changing={externalChanging}
25-
onChangingChange={async (changing: boolean) => {
26-
setExternalChanging(changing)
24+
loading={externalLoading}
25+
onLoadingChange={async (loading: boolean) => {
26+
setExternalLoading(loading)
2727
}}
2828
checked={checkedAsync}
2929
onChange={(value) => onChangeAsync(value)}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const Demo8 = () => {
55
const [checkedAsync, setCheckedAsync] = useState(true)
66
const [value, setValue] = useState(false)
77
const [showToast, setShowToast] = useState(false)
8-
const [externalChanging, setExternalChanging] = useState(false)
8+
const [externalLoading, setExternalLoading] = useState(false)
99
const mockRequest = (): Promise<void> => {
1010
return new Promise((resolve) => {
1111
setTimeout(() => {
@@ -19,15 +19,15 @@ const Demo8 = () => {
1919
setShowToast(true)
2020
await mockRequest()
2121
setCheckedAsync(value)
22-
// setExternalChanging(false)
22+
// setExternalLoading(false)
2323
}
2424
return (
2525
<>
2626
<Cell>
2727
<Switch
28-
changing={externalChanging}
29-
onChangingChange={async (changing: boolean) => {
30-
setExternalChanging(changing)
28+
loading={externalLoading}
29+
onLoadingChange={async (loading: boolean) => {
30+
setExternalLoading(loading)
3131
}}
3232
checked={checkedAsync}
3333
onChange={(value) => onChangeAsync(value)}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ import { Switch } from '@nutui/nutui-react'
8686
| activeText | Text description when opening | `ReactNode` | `-` |
8787
| inactiveText | Text description when closed | `ReactNode` | `-` |
8888
| loadingIcon | Control the loading state icon, disable the loading state when a null | `ReactNode` | `<Loading1 />` |
89-
| changing | loading state, controlled | `boolean` | `-` |
90-
| onChangingChange | Triggered when switching loading | `onChangingChange:(value: boolean)` | `-` |
89+
| loading | loading state, controlled | `boolean` | `-` |
90+
| onLoadingChange | Triggered when switching loading | `onLoadingChange:(value: boolean)` | `-` |
9191
| onChange | Trigger when switching switches | `onChange:(value: boolean)` | `-` |
9292

9393
## Theming

src/packages/switch/doc.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ import { Switch } from '@nutui/nutui-react'
8686
| activeText | 打开时文字描述 | `ReactNode` | `-` |
8787
| inactiveText | 关闭时文字描述 | `ReactNode` | `-` |
8888
| loadingIcon | 控制加载状态的图标,传入空值时禁用 loading 态 | `ReactNode` | `<Loading1 />` |
89-
| changing | loading 态,受控 | `boolean` | `-` |
90-
| onChangingChange | 切换 loading 态时触发 | `onChangingChange:(value: boolean)` | `-` |
89+
| loading | loading 态,受控 | `boolean` | `-` |
90+
| onLoadingChange | 切换 loading 态时触发 | `onLoadingChange:(value: boolean)` | `-` |
9191
| onChange | 切换开关时触发 | `onChange:(value: boolean)` | `-` |
9292

9393
## 主题定制

src/packages/switch/doc.taro.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ import { Switch } from '@nutui/nutui-react-taro'
8686
| activeText | 打开时文字描述 | `ReactNode` | `-` |
8787
| inactiveText | 关闭时文字描述 | `ReactNode` | `-` |
8888
| loadingIcon | 控制加载状态的图标,传入空值时禁用 loading 态 | `ReactNode` | `<Loading1 />` |
89-
| changing | loading 态,受控 | `boolean` | `-` |
90-
| onChangingChange | 切换 loading 态时触发 | `onChangingChange:(value: boolean)` | `-` |
89+
| loading | loading 态,受控 | `boolean` | `-` |
90+
| onLoadingChange | 切换 loading 态时触发 | `onLoadingChange:(value: boolean)` | `-` |
9191
| onChange | 切换开关时触发 | `onChange:(value: boolean)` | `-` |
9292

9393
## 主题定制

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ import { Switch } from '@nutui/nutui-react'
8686
| activeText | 打開時文字描述 | `ReactNode` | `-` |
8787
| inactiveText | 關閉時文字描述 | `ReactNode` | `-` |
8888
| loadingIcon | 控制加載狀態的圖標,當傳入空值時禁用 loading 狀態 | `ReactNode` | `<Loading1 />` |
89-
| changing | loading 態,受控 | `boolean` | `-` |
90-
| onChangingChange | 切換 loading 態時觸發 | `onChangingChange:(value: boolean)` | `-` |
89+
| loading | loading 態,受控 | `boolean` | `-` |
90+
| onLoadingChange | 切換 loading 態時觸發 | `onLoadingChange:(value: boolean)` | `-` |
9191
| onChange | 切換開關時觸發 | `onChange:(value: boolean)` | `-` |
9292

9393
## 主題定製

src/packages/switch/switch.taro.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ const defaultProps = {
1313
activeText: '',
1414
inactiveText: '',
1515
loadingIcon: <Loading1 />,
16-
changing: undefined,
17-
onChangingChange: (changing: boolean) => {},
16+
loading: undefined,
17+
onLoadingChange: (loading: boolean) => {},
1818
} as TaroSwitchProps
1919
export const Switch: FunctionComponent<Partial<TaroSwitchProps>> = (props) => {
2020
const {
@@ -27,8 +27,8 @@ export const Switch: FunctionComponent<Partial<TaroSwitchProps>> = (props) => {
2727
className,
2828
style,
2929
onChange,
30-
changing: propChanging,
31-
onChangingChange,
30+
loading: propLoading,
31+
onLoadingChange,
3232
...rest
3333
} = {
3434
...defaultProps,
@@ -43,19 +43,19 @@ export const Switch: FunctionComponent<Partial<TaroSwitchProps>> = (props) => {
4343
defaultValue: defaultChecked,
4444
})
4545

46-
const [internalChanging, setInternalChanging] = useState(false)
47-
const changing = propChanging !== undefined ? propChanging : internalChanging
46+
const [internalLoading, setInternalLoading] = useState(false)
47+
const loading = propLoading !== undefined ? propLoading : internalLoading
4848

49-
const setChanging = (val: boolean) => {
50-
if (propChanging !== undefined) {
51-
onChangingChange(val)
49+
const setLoading = (val: boolean) => {
50+
if (propLoading !== undefined) {
51+
onLoadingChange(val)
5252
} else {
53-
setInternalChanging(val)
53+
setInternalLoading(val)
5454
}
5555
}
5656

5757
useEffect(() => {
58-
changing && setChanging(false)
58+
loading && setLoading(false)
5959
}, [value])
6060

6161
const classes = () => {
@@ -71,9 +71,9 @@ export const Switch: FunctionComponent<Partial<TaroSwitchProps>> = (props) => {
7171
}
7272

7373
const onClick = () => {
74-
if (disabled || changing) return
74+
if (disabled || loading) return
7575
if (onChange) {
76-
loadingIcon && setChanging(true)
76+
loadingIcon && setLoading(true)
7777
onChange(!value)
7878
}
7979
setValue(!value)
@@ -94,7 +94,7 @@ export const Switch: FunctionComponent<Partial<TaroSwitchProps>> = (props) => {
9494
},
9595
])}
9696
>
97-
{changing && loadingIcon ? (
97+
{loading && loadingIcon ? (
9898
<>{loadingIcon}</>
9999
) : (
100100
<>

src/packages/switch/switch.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ const defaultProps = {
1212
activeText: '',
1313
inactiveText: '',
1414
loadingIcon: <Loading1 />,
15-
changing: undefined,
16-
onChangingChange: (changing: boolean) => {},
15+
loading: undefined,
16+
onLoadingChange: (loading: boolean) => {},
1717
} as WebSwitchProps
1818
export const Switch: FunctionComponent<Partial<WebSwitchProps>> = (props) => {
1919
const {
@@ -26,8 +26,8 @@ export const Switch: FunctionComponent<Partial<WebSwitchProps>> = (props) => {
2626
className,
2727
style,
2828
onChange,
29-
changing: propChanging,
30-
onChangingChange,
29+
loading: propLoading,
30+
onLoadingChange,
3131
...rest
3232
} = {
3333
...defaultProps,
@@ -42,19 +42,19 @@ export const Switch: FunctionComponent<Partial<WebSwitchProps>> = (props) => {
4242
defaultValue: defaultChecked,
4343
})
4444

45-
const [internalChanging, setInternalChanging] = useState(false)
46-
const changing = propChanging !== undefined ? propChanging : internalChanging
45+
const [internalLoading, setInternalLoading] = useState(false)
46+
const loading = propLoading !== undefined ? propLoading : internalLoading
4747

48-
const setChanging = (val: boolean) => {
49-
if (propChanging !== undefined) {
50-
onChangingChange(val)
48+
const setLoading = (val: boolean) => {
49+
if (propLoading !== undefined) {
50+
onLoadingChange(val)
5151
} else {
52-
setInternalChanging(val)
52+
setInternalLoading(val)
5353
}
5454
}
5555

5656
useEffect(() => {
57-
changing && setChanging(false)
57+
loading && setLoading(false)
5858
}, [value])
5959

6060
const classes = () => {
@@ -70,9 +70,9 @@ export const Switch: FunctionComponent<Partial<WebSwitchProps>> = (props) => {
7070
}
7171

7272
const onClick = () => {
73-
if (disabled || changing) return
73+
if (disabled || loading) return
7474
if (onChange) {
75-
loadingIcon && setChanging(true)
75+
loadingIcon && setLoading(true)
7676
onChange(!value)
7777
}
7878
setValue(!value)
@@ -93,7 +93,7 @@ export const Switch: FunctionComponent<Partial<WebSwitchProps>> = (props) => {
9393
},
9494
])}
9595
>
96-
{changing && loadingIcon ? (
96+
{loading && loadingIcon ? (
9797
<>{loadingIcon}</>
9898
) : (
9999
<>

0 commit comments

Comments
 (0)