-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: dialog、toast、notify新增创建全局唯一组件方法
- Loading branch information
kongjing
committed
Mar 7, 2023
1 parent
c5e4fdc
commit 516181e
Showing
12 changed files
with
162 additions
and
23 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,33 @@ | ||
import { Dialog } from './index' | ||
|
||
let idIndex = 1 | ||
|
||
export function createOnlyDialog() { | ||
const id = `van-create-dialog${idIndex++}` | ||
const Dialog_ = function Modal(props = {}) { | ||
return <Dialog {...props} id={id} /> | ||
} | ||
|
||
const actionNames = [ | ||
'alert', | ||
'confirm', | ||
'setDefaultOptions', | ||
'resetDefaultOptions', | ||
'close', | ||
'stopLoading', | ||
'createOnlyDialog', | ||
] | ||
|
||
for (let i = 0; i < actionNames.length; i++) { | ||
const name = actionNames[i] | ||
if (name && Dialog[name]) | ||
Dialog_[name] = function (props) { | ||
Dialog[name]({ | ||
...props, | ||
selector: `#${id}`, | ||
}) | ||
} | ||
} | ||
|
||
return Dialog_ | ||
} |
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,26 @@ | ||
import { Notify } from './index' | ||
|
||
let idIndex = 1 | ||
|
||
export function createOnlyNotify() { | ||
const id = `van-create-notify${idIndex++}` | ||
const Notify_ = function Modal(props) { | ||
return <Notify {...props} id={id} /> | ||
} | ||
|
||
const actionNames = ['show', 'clear'] | ||
|
||
for (let i = 0; i < actionNames.length; i++) { | ||
const name = actionNames[i] | ||
if (name && Notify_[name]) { | ||
Notify_[name] = function (props) { | ||
Notify[name]({ | ||
...props, | ||
selector: `#${id}`, | ||
}) | ||
} | ||
} | ||
} | ||
|
||
return Notify_ | ||
} |
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,39 @@ | ||
import { ToastProps, toastProps } from '../../types/toast' | ||
import { Toast } from './index' | ||
|
||
let idIndex = 1 | ||
|
||
export function createOnlyToast() { | ||
const id = `van-create-toast${idIndex++}` | ||
const Toast_ = function Modal(props: ToastProps) { | ||
return <Toast {...props} id={id} /> | ||
} | ||
|
||
const actionNames: Array<keyof toastProps> = [ | ||
'show', | ||
'loading', | ||
'success', | ||
'fail', | ||
'setDefaultOptions', | ||
'resetDefaultOptions', | ||
'createOnlyToast', | ||
] | ||
|
||
for (let i = 0; i < actionNames.length; i++) { | ||
const actName = actionNames[i] | ||
if (actName) { | ||
Toast_[actName] = function (props) { | ||
let params: any = {} | ||
if (typeof props === 'string') { | ||
params = { | ||
message: props, | ||
selector: `#${id}`, | ||
} | ||
} else params = props | ||
Toast[actName](params) | ||
} | ||
} | ||
} | ||
|
||
return Toast_ as React.FunctionComponent<ToastProps> & toastProps | ||
} |
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