mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-05-22 22:49:15 +08:00
types(NumberKeyboard): use tsx (#8156)
This commit is contained in:
parent
4cb974ab02
commit
d8e7489081
@ -23,9 +23,11 @@ const DeleteIcon = (
|
|||||||
</svg>
|
</svg>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export type KeyType = '' | 'delete' | 'extra' | 'close';
|
||||||
|
|
||||||
export default createComponent({
|
export default createComponent({
|
||||||
props: {
|
props: {
|
||||||
type: String as PropType<'delete' | 'extra' | 'close'>,
|
type: String as PropType<KeyType>,
|
||||||
text: [Number, String],
|
text: [Number, String],
|
||||||
color: String,
|
color: String,
|
||||||
wider: Boolean,
|
wider: Boolean,
|
||||||
|
@ -1,22 +1,40 @@
|
|||||||
import { ref, watch, computed, Teleport, Transition } from 'vue';
|
import {
|
||||||
|
ref,
|
||||||
|
Slot,
|
||||||
|
watch,
|
||||||
|
computed,
|
||||||
|
Teleport,
|
||||||
|
PropType,
|
||||||
|
Transition,
|
||||||
|
TeleportProps,
|
||||||
|
} from 'vue';
|
||||||
import { createNamespace, stopPropagation } from '../utils';
|
import { createNamespace, stopPropagation } from '../utils';
|
||||||
import { useClickAway } from '@vant/use';
|
import { useClickAway } from '@vant/use';
|
||||||
import Key from './Key';
|
import Key, { KeyType } from './Key';
|
||||||
|
|
||||||
const [createComponent, bem] = createNamespace('number-keyboard');
|
const [createComponent, bem] = createNamespace('number-keyboard');
|
||||||
|
|
||||||
|
export type NumberKeyboardTheme = 'default' | 'custom';
|
||||||
|
|
||||||
|
type KeyConfig = {
|
||||||
|
text?: number | string;
|
||||||
|
type?: KeyType;
|
||||||
|
color?: string;
|
||||||
|
wider?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
export default createComponent({
|
export default createComponent({
|
||||||
props: {
|
props: {
|
||||||
show: Boolean,
|
show: Boolean,
|
||||||
title: String,
|
title: String,
|
||||||
zIndex: [Number, String],
|
zIndex: [Number, String],
|
||||||
teleport: [String, Object],
|
teleport: [String, Object] as PropType<TeleportProps['to']>,
|
||||||
randomKeyOrder: Boolean,
|
randomKeyOrder: Boolean,
|
||||||
closeButtonText: String,
|
closeButtonText: String,
|
||||||
deleteButtonText: String,
|
deleteButtonText: String,
|
||||||
closeButtonLoading: Boolean,
|
closeButtonLoading: Boolean,
|
||||||
theme: {
|
theme: {
|
||||||
type: String,
|
type: String as PropType<NumberKeyboardTheme>,
|
||||||
default: 'default',
|
default: 'default',
|
||||||
},
|
},
|
||||||
modelValue: {
|
modelValue: {
|
||||||
@ -24,7 +42,7 @@ export default createComponent({
|
|||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
extraKey: {
|
extraKey: {
|
||||||
type: [String, Array],
|
type: [String, Array] as PropType<string | string[]>,
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
maxlength: {
|
maxlength: {
|
||||||
@ -64,10 +82,10 @@ export default createComponent({
|
|||||||
],
|
],
|
||||||
|
|
||||||
setup(props, { emit, slots }) {
|
setup(props, { emit, slots }) {
|
||||||
const root = ref();
|
const root = ref<HTMLElement>();
|
||||||
|
|
||||||
const genBasicKeys = () => {
|
const genBasicKeys = () => {
|
||||||
const keys = [];
|
const keys: KeyConfig[] = [];
|
||||||
for (let i = 1; i <= 9; i++) {
|
for (let i = 1; i <= 9; i++) {
|
||||||
keys.push({ text: i });
|
keys.push({ text: i });
|
||||||
}
|
}
|
||||||
@ -79,9 +97,9 @@ export default createComponent({
|
|||||||
return keys;
|
return keys;
|
||||||
};
|
};
|
||||||
|
|
||||||
const genDefaultKeys = () => [
|
const genDefaultKeys = (): KeyConfig[] => [
|
||||||
...genBasicKeys(),
|
...genBasicKeys(),
|
||||||
{ text: props.extraKey, type: 'extra' },
|
{ text: props.extraKey as string, type: 'extra' },
|
||||||
{ text: 0 },
|
{ text: 0 },
|
||||||
{
|
{
|
||||||
text: props.showDeleteKey ? props.deleteButtonText : '',
|
text: props.showDeleteKey ? props.deleteButtonText : '',
|
||||||
@ -129,11 +147,10 @@ export default createComponent({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onAnimationEnd = () => {
|
const onAnimationEnd = () => {
|
||||||
console.log('onAnimationEnd');
|
|
||||||
emit(props.show ? 'show' : 'hide');
|
emit(props.show ? 'show' : 'hide');
|
||||||
};
|
};
|
||||||
|
|
||||||
const onPress = (text, type) => {
|
const onPress = (text: string, type: KeyType) => {
|
||||||
if (text === '') {
|
if (text === '') {
|
||||||
if (type === 'extra') {
|
if (type === 'extra') {
|
||||||
onBlur();
|
onBlur();
|
||||||
@ -179,7 +196,7 @@ export default createComponent({
|
|||||||
|
|
||||||
const renderKeys = () => {
|
const renderKeys = () => {
|
||||||
return keys.value.map((key) => {
|
return keys.value.map((key) => {
|
||||||
const keySlots = {};
|
const keySlots: Record<string, Slot | undefined> = {};
|
||||||
|
|
||||||
if (key.type === 'delete') {
|
if (key.type === 'delete') {
|
||||||
keySlots.default = slots.delete;
|
keySlots.default = slots.delete;
|
||||||
@ -248,13 +265,16 @@ export default createComponent({
|
|||||||
<div
|
<div
|
||||||
v-show={props.show}
|
v-show={props.show}
|
||||||
ref={root}
|
ref={root}
|
||||||
style={{ zIndex: props.zIndex }}
|
style={{
|
||||||
|
zIndex: props.zIndex !== undefined ? +props.zIndex : undefined,
|
||||||
|
}}
|
||||||
class={bem({
|
class={bem({
|
||||||
unfit: !props.safeAreaInsetBottom,
|
unfit: !props.safeAreaInsetBottom,
|
||||||
'with-title': !!Title,
|
'with-title': !!Title,
|
||||||
})}
|
})}
|
||||||
onTouchstart={stopPropagation}
|
onTouchstart={stopPropagation}
|
||||||
onAnimationend={onAnimationEnd}
|
onAnimationend={onAnimationEnd}
|
||||||
|
// @ts-ignore
|
||||||
onWebkitAnimationEnd={onAnimationEnd}
|
onWebkitAnimationEnd={onAnimationEnd}
|
||||||
>
|
>
|
||||||
{Title}
|
{Title}
|
1
src/vue-tsx-shim.d.ts
vendored
1
src/vue-tsx-shim.d.ts
vendored
@ -14,6 +14,7 @@ declare module 'vue' {
|
|||||||
onFocus?: EventHandler;
|
onFocus?: EventHandler;
|
||||||
onInput?: EventHandler;
|
onInput?: EventHandler;
|
||||||
onClick?: EventHandler;
|
onClick?: EventHandler;
|
||||||
|
onPress?: EventHandler;
|
||||||
onCancel?: EventHandler;
|
onCancel?: EventHandler;
|
||||||
onClosed?: EventHandler;
|
onClosed?: EventHandler;
|
||||||
onChange?: EventHandler;
|
onChange?: EventHandler;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user