mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
types(Toast): use tsx (#8091)
This commit is contained in:
parent
efa8c0e798
commit
45cbd17b1e
@ -1,4 +1,4 @@
|
|||||||
import { watch, onMounted, onUnmounted } from 'vue';
|
import { watch, onMounted, onUnmounted, PropType } from 'vue';
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
import { createNamespace, isDef } from '../utils';
|
import { createNamespace, isDef } from '../utils';
|
||||||
@ -7,31 +7,37 @@ import { lockClick } from './lock-click';
|
|||||||
// Components
|
// Components
|
||||||
import Icon from '../icon';
|
import Icon from '../icon';
|
||||||
import Popup from '../popup';
|
import Popup from '../popup';
|
||||||
import Loading from '../loading';
|
import Loading, { LoadingType } from '../loading';
|
||||||
|
|
||||||
const [createComponent, bem] = createNamespace('toast');
|
const [createComponent, bem] = createNamespace('toast');
|
||||||
|
|
||||||
|
export type ToastType = 'text' | 'loading' | 'success' | 'fail' | 'html';
|
||||||
|
export type ToastPosition = 'top' | 'middle' | 'bottom';
|
||||||
|
|
||||||
export default createComponent({
|
export default createComponent({
|
||||||
props: {
|
props: {
|
||||||
icon: String,
|
icon: String,
|
||||||
show: Boolean,
|
show: Boolean,
|
||||||
message: [Number, String],
|
message: [Number, String],
|
||||||
duration: Number,
|
|
||||||
className: null,
|
className: null,
|
||||||
iconPrefix: String,
|
iconPrefix: String,
|
||||||
lockScroll: Boolean,
|
lockScroll: Boolean,
|
||||||
loadingType: String,
|
loadingType: String as PropType<LoadingType>,
|
||||||
forbidClick: Boolean,
|
forbidClick: Boolean,
|
||||||
overlayClass: null,
|
overlayClass: null,
|
||||||
overlayStyle: Object,
|
overlayStyle: Object,
|
||||||
closeOnClick: Boolean,
|
closeOnClick: Boolean,
|
||||||
closeOnClickOverlay: Boolean,
|
closeOnClickOverlay: Boolean,
|
||||||
type: {
|
type: {
|
||||||
type: String,
|
type: String as PropType<ToastType>,
|
||||||
default: 'text',
|
default: 'text',
|
||||||
},
|
},
|
||||||
|
duration: {
|
||||||
|
type: Number,
|
||||||
|
default: 2000,
|
||||||
|
},
|
||||||
position: {
|
position: {
|
||||||
type: String,
|
type: String as PropType<ToastPosition>,
|
||||||
default: 'middle',
|
default: 'middle',
|
||||||
},
|
},
|
||||||
transition: {
|
transition: {
|
||||||
@ -43,7 +49,7 @@ export default createComponent({
|
|||||||
emits: ['update:show'],
|
emits: ['update:show'],
|
||||||
|
|
||||||
setup(props, { emit }) {
|
setup(props, { emit }) {
|
||||||
let timer;
|
let timer: NodeJS.Timeout;
|
||||||
let clickable = false;
|
let clickable = false;
|
||||||
|
|
||||||
const toggleClickable = () => {
|
const toggleClickable = () => {
|
||||||
@ -64,7 +70,7 @@ export default createComponent({
|
|||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
};
|
};
|
||||||
|
|
||||||
const toggle = (show) => {
|
const toggle = (show: boolean) => {
|
||||||
emit('update:show', show);
|
emit('update:show', show);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -92,7 +98,7 @@ export default createComponent({
|
|||||||
|
|
||||||
if (isDef(message) && message !== '') {
|
if (isDef(message) && message !== '') {
|
||||||
return type === 'html' ? (
|
return type === 'html' ? (
|
||||||
<div class={bem('text')} innerHTML={message} />
|
<div class={bem('text')} innerHTML={String(message)} />
|
||||||
) : (
|
) : (
|
||||||
<div class={bem('text')}>{message}</div>
|
<div class={bem('text')}>{message}</div>
|
||||||
);
|
);
|
Loading…
x
Reference in New Issue
Block a user