index.js 2.7 KB

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