mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
types(Search): use tsx (#8161)
This commit is contained in:
parent
a8060bb599
commit
6c36fadf59
@ -1,4 +1,4 @@
|
|||||||
import { ref } from 'vue';
|
import { ref, PropType, CSSProperties } from 'vue';
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
import { pick, createNamespace, preventDefault } from '../utils';
|
import { pick, createNamespace, preventDefault } from '../utils';
|
||||||
@ -9,8 +9,13 @@ import { useExpose } from '../composables/use-expose';
|
|||||||
// Components
|
// Components
|
||||||
import Field from '../field';
|
import Field from '../field';
|
||||||
|
|
||||||
|
// Types
|
||||||
|
import type { FieldClearTrigger } from '../field/types';
|
||||||
|
|
||||||
const [createComponent, bem, t] = createNamespace('search');
|
const [createComponent, bem, t] = createNamespace('search');
|
||||||
|
|
||||||
|
export type SearchShape = 'square' | 'round';
|
||||||
|
|
||||||
export default createComponent({
|
export default createComponent({
|
||||||
inheritAttrs: false,
|
inheritAttrs: false,
|
||||||
|
|
||||||
@ -21,9 +26,9 @@ export default createComponent({
|
|||||||
actionText: String,
|
actionText: String,
|
||||||
background: String,
|
background: String,
|
||||||
showAction: Boolean,
|
showAction: Boolean,
|
||||||
clearTrigger: String,
|
clearTrigger: String as PropType<FieldClearTrigger>,
|
||||||
shape: {
|
shape: {
|
||||||
type: String,
|
type: String as PropType<SearchShape>,
|
||||||
default: 'square',
|
default: 'square',
|
||||||
},
|
},
|
||||||
clearable: {
|
clearable: {
|
||||||
@ -48,7 +53,7 @@ export default createComponent({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onKeypress = (event) => {
|
const onKeypress = (event: KeyboardEvent) => {
|
||||||
const ENTER_CODE = 13;
|
const ENTER_CODE = 13;
|
||||||
if (event.keyCode === ENTER_CODE) {
|
if (event.keyCode === ENTER_CODE) {
|
||||||
preventDefault(event);
|
preventDefault(event);
|
||||||
@ -73,7 +78,7 @@ export default createComponent({
|
|||||||
<div
|
<div
|
||||||
class={bem('action')}
|
class={bem('action')}
|
||||||
role="button"
|
role="button"
|
||||||
tabindex="0"
|
tabindex={0}
|
||||||
onClick={onCancel}
|
onClick={onCancel}
|
||||||
>
|
>
|
||||||
{slots.action ? slots.action() : text}
|
{slots.action ? slots.action() : text}
|
||||||
@ -110,7 +115,7 @@ export default createComponent({
|
|||||||
class: null,
|
class: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
const onInput = (value) => {
|
const onInput = (value: string) => {
|
||||||
emit('update:modelValue', value);
|
emit('update:modelValue', value);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -132,7 +137,10 @@ export default createComponent({
|
|||||||
return () => (
|
return () => (
|
||||||
<div
|
<div
|
||||||
class={[bem({ 'show-action': props.showAction }), attrs.class]}
|
class={[bem({ 'show-action': props.showAction }), attrs.class]}
|
||||||
style={{ background: props.background, ...attrs.style }}
|
style={{
|
||||||
|
background: props.background,
|
||||||
|
...(attrs.style as CSSProperties),
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{slots.left?.()}
|
{slots.left?.()}
|
||||||
<div class={bem('content', props.shape)}>
|
<div class={bem('content', props.shape)}>
|
1
src/vue-tsx-shim.d.ts
vendored
1
src/vue-tsx-shim.d.ts
vendored
@ -22,6 +22,7 @@ declare module 'vue' {
|
|||||||
onSelect?: EventHandler;
|
onSelect?: EventHandler;
|
||||||
onToggle?: EventHandler;
|
onToggle?: EventHandler;
|
||||||
onConfirm?: EventHandler;
|
onConfirm?: EventHandler;
|
||||||
|
onKeypress?: EventHandler;
|
||||||
onClickStep?: EventHandler;
|
onClickStep?: EventHandler;
|
||||||
onTouchstart?: EventHandler;
|
onTouchstart?: EventHandler;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user