index.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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/dom/event");
  10. var _field = _interopRequireDefault(require("../field"));
  11. // Utils
  12. // Components
  13. var _createNamespace = (0, _utils.createNamespace)('search'),
  14. createComponent = _createNamespace[0],
  15. bem = _createNamespace[1],
  16. t = _createNamespace[2];
  17. function Search(h, props, slots, ctx) {
  18. function Label() {
  19. if (slots.label || props.label) {
  20. return h("div", {
  21. "class": bem('label')
  22. }, [slots.label ? slots.label() : props.label]);
  23. }
  24. }
  25. function Action() {
  26. if (!props.showAction) {
  27. return;
  28. }
  29. function onCancel() {
  30. if (slots.action) {
  31. return;
  32. }
  33. (0, _functional.emit)(ctx, 'input', '');
  34. (0, _functional.emit)(ctx, 'cancel');
  35. }
  36. return h("div", {
  37. "class": bem('action'),
  38. "attrs": {
  39. "role": "button",
  40. "tabindex": "0"
  41. },
  42. "on": {
  43. "click": onCancel
  44. }
  45. }, [slots.action ? slots.action() : props.actionText || t('cancel')]);
  46. }
  47. var fieldData = {
  48. attrs: ctx.data.attrs,
  49. on: (0, _extends2.default)({}, ctx.listeners, {
  50. keypress: function keypress(event) {
  51. // press enter
  52. if (event.keyCode === 13) {
  53. (0, _event.preventDefault)(event);
  54. (0, _functional.emit)(ctx, 'search', props.value);
  55. }
  56. (0, _functional.emit)(ctx, 'keypress', event);
  57. }
  58. })
  59. };
  60. var inheritData = (0, _functional.inherit)(ctx);
  61. inheritData.attrs = undefined;
  62. return h("div", (0, _babelHelperVueJsxMergeProps.default)([{
  63. "class": bem({
  64. 'show-action': props.showAction
  65. }),
  66. "style": {
  67. background: props.background
  68. }
  69. }, inheritData]), [slots.left == null ? void 0 : slots.left(), h("div", {
  70. "class": bem('content', props.shape)
  71. }, [Label(), h(_field.default, (0, _babelHelperVueJsxMergeProps.default)([{
  72. "attrs": {
  73. "type": "search",
  74. "border": false,
  75. "value": props.value,
  76. "leftIcon": props.leftIcon,
  77. "rightIcon": props.rightIcon,
  78. "clearable": props.clearable,
  79. "clearTrigger": props.clearTrigger
  80. },
  81. "scopedSlots": {
  82. 'left-icon': slots['left-icon'],
  83. 'right-icon': slots['right-icon']
  84. }
  85. }, fieldData]))]), Action()]);
  86. }
  87. Search.props = {
  88. value: String,
  89. label: String,
  90. rightIcon: String,
  91. actionText: String,
  92. background: String,
  93. showAction: Boolean,
  94. clearTrigger: String,
  95. shape: {
  96. type: String,
  97. default: 'square'
  98. },
  99. clearable: {
  100. type: Boolean,
  101. default: true
  102. },
  103. leftIcon: {
  104. type: String,
  105. default: 'search'
  106. }
  107. };
  108. var _default = createComponent(Search);
  109. exports.default = _default;