types(Search): use tsx (#8161)

This commit is contained in:
neverland 2021-02-15 21:55:53 +08:00 committed by GitHub
parent a8060bb599
commit 6c36fadf59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 8 deletions

View File

@ -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)}>

View File

@ -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;
} }