-
Notifications
You must be signed in to change notification settings - Fork 329
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(switch): add before-change API (#3167)
* feat(switch): support beforeChange API * test(switch): 更新测试快照
- Loading branch information
1 parent
4f54dc3
commit 291c790
Showing
8 changed files
with
169 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React, { useState } from 'react'; | ||
import { Switch, Space } from 'tdesign-react'; | ||
|
||
export default function SwitchBeforeChange() { | ||
const [resolveChecked, setResolveChecked] = useState(true); | ||
const [rejectedChecked, setRejectedChecked] = useState(true); | ||
const [loadingResolve, setLoadingResolve] = useState(false); | ||
const [loadingReject, setLoadingReject] = useState(false); | ||
|
||
const beforeChangeResolve = (): Promise<boolean> => { | ||
setLoadingResolve(true); | ||
return new Promise((resolve) => { | ||
setTimeout(() => { | ||
setLoadingResolve(false); | ||
resolve(true); | ||
}, 1000); | ||
}); | ||
}; | ||
|
||
const beforeChangeReject = (): Promise<boolean> => { | ||
setLoadingReject(true); | ||
return new Promise((_resolve, reject) => { | ||
setTimeout(() => { | ||
setLoadingReject(false); | ||
reject(new Error('reject')); | ||
}, 1000); | ||
}); | ||
}; | ||
|
||
const onChangeResolve = (v: boolean) => { | ||
console.log(v); | ||
setResolveChecked(v); | ||
}; | ||
|
||
const onChangeReject = (v: boolean) => { | ||
console.log(v); | ||
setRejectedChecked(v); | ||
}; | ||
|
||
return ( | ||
<Space> | ||
<Switch | ||
size="large" | ||
loading={loadingResolve} | ||
onChange={onChangeResolve} | ||
value={resolveChecked} | ||
beforeChange={beforeChangeResolve} | ||
/> | ||
<Switch | ||
size="large" | ||
loading={loadingReject} | ||
onChange={onChangeReject} | ||
value={rejectedChecked} | ||
beforeChange={beforeChangeReject} | ||
/> | ||
</Space> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters