index.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import _mergeJSXProps2 from "@vue/babel-helper-vue-jsx-merge-props";
  2. import _mergeJSXProps from "@vue/babel-helper-vue-jsx-merge-props";
  3. import _extends from "@babel/runtime/helpers/esm/extends";
  4. import { use } from '../utils';
  5. import { inherit, emit } from '../utils/functional';
  6. import { preventDefault } from '../utils/event';
  7. import Field from '../field'; // Types
  8. var _use = use('search'),
  9. sfc = _use[0],
  10. bem = _use[1],
  11. t = _use[2];
  12. function Search(h, props, slots, ctx) {
  13. var Label = function Label() {
  14. if (!slots.label && !props.label) {
  15. return null;
  16. }
  17. return h("div", {
  18. "class": bem('label')
  19. }, [slots.label ? slots.label() : props.label]);
  20. };
  21. var Action = function Action() {
  22. if (!props.showAction) {
  23. return null;
  24. }
  25. var onCancel = function onCancel() {
  26. emit(ctx, 'input', '');
  27. emit(ctx, 'cancel');
  28. };
  29. return h("div", {
  30. "class": bem('action')
  31. }, [slots.action ? slots.action() : h("div", {
  32. "on": {
  33. "click": onCancel
  34. }
  35. }, [t('cancel')])]);
  36. };
  37. var fieldData = {
  38. attrs: ctx.data.attrs,
  39. on: _extends({}, ctx.listeners, {
  40. input: function input(value) {
  41. emit(ctx, 'input', value);
  42. },
  43. keypress: function keypress(event) {
  44. // press enter
  45. if (event.keyCode === 13) {
  46. preventDefault(event);
  47. emit(ctx, 'search', props.value);
  48. }
  49. emit(ctx, 'keypress', event);
  50. }
  51. })
  52. };
  53. var inheritData = inherit(ctx);
  54. delete inheritData.attrs;
  55. return h("div", _mergeJSXProps2([{
  56. "class": bem({
  57. 'show-action': props.showAction
  58. }),
  59. "style": {
  60. background: props.background
  61. }
  62. }, inheritData]), [h("div", {
  63. "class": bem('content', props.shape)
  64. }, [Label(), h(Field, _mergeJSXProps([{
  65. "attrs": {
  66. "clearable": true,
  67. "type": "search",
  68. "value": props.value,
  69. "border": false,
  70. "leftIcon": "search"
  71. },
  72. "scopedSlots": {
  73. 'left-icon': slots['left-icon']
  74. }
  75. }, fieldData]))]), Action()]);
  76. }
  77. Search.props = {
  78. value: String,
  79. label: String,
  80. showAction: Boolean,
  81. shape: {
  82. type: String,
  83. "default": 'square'
  84. },
  85. background: {
  86. type: String,
  87. "default": '#fff'
  88. }
  89. };
  90. export default sfc(Search);