diff --git a/packages/search/index.js b/packages/search/index.js new file mode 100644 index 000000000..e7356b0d0 --- /dev/null +++ b/packages/search/index.js @@ -0,0 +1,76 @@ +import { use } from '../utils'; +import Field from '../field'; + +const [sfc, bem, t] = use('search'); + +export default sfc({ + inheritAttrs: false, + + props: { + value: String, + showAction: Boolean, + background: { + type: String, + default: '#f2f2f2' + } + }, + + computed: { + listeners() { + return { + ...this.$listeners, + input: this.onInput, + keypress: this.onKeypress + }; + } + }, + + methods: { + onInput(value) { + this.$emit('input', value); + }, + + onKeypress(event) { + // press enter + if (event.keyCode === 13) { + event.preventDefault(); + this.$emit('search', this.value); + } + this.$emit('keypress', event); + }, + + onBack() { + this.$emit('input', ''); + this.$emit('cancel'); + } + }, + + render(h) { + const { showAction } = this; + + const props = { + attrs: this.$attrs, + on: this.listeners + }; + + return ( +