No Description

index.js 8.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
  4. var React = require('react');
  5. var React__default = _interopDefault(React);
  6. var styleInject_es = require('../style-inject.es-dcee06b6.js');
  7. var defineProperty = require('../defineProperty-ba7cd53d.js');
  8. require('../_commonjsHelpers-72d386ba.js');
  9. var index = require('../index-44e17595.js');
  10. var utils = require('../utils-b800dc99.js');
  11. var slicedToArray = require('../slicedToArray-172f4624.js');
  12. var antd = require('antd');
  13. var css = ".PriceOptions_options__ifYbC {\n border-bottom: 1px dashed #00000017;\n}\n.PriceOptions_options__ifYbC p {\n font-size: 14px;\n font-weight: 400;\n color: #616a79;\n margin-bottom: 20px;\n}\n.PriceOptions_options__ifYbC .PriceOptions_infoItem__246mx {\n padding-right: 0;\n}\n.PriceOptions_options__ifYbC .PriceOptions_infoItem__246mx .PriceOptions_priceItem__3CPe3 {\n background: rgba(243, 243, 243, 0.14);\n border-radius: 4px;\n border: 1px solid #cfcfcf;\n font-size: 14px;\n font-weight: 600;\n color: #616a79;\n display: inline-block;\n text-align: center;\n vertical-align: top;\n height: 30px;\n width: 70px;\n line-height: 30px;\n cursor: pointer;\n margin: 6px;\n}\n.PriceOptions_options__ifYbC .PriceOptions_infoItem__246mx .PriceOptions_priceItem__3CPe3.PriceOptions_active__154by {\n background: rgba(255, 50, 102, 0.1);\n border-radius: 4px;\n border: 1px solid #ff3266;\n color: #616a79;\n}\n.PriceOptions_options__ifYbC .PriceOptions_infoItem__246mx .PriceOptions_priceInput__2JFc0 {\n display: inline-block;\n min-width: 70px;\n width: auto;\n margin: 6px;\n text-align: center;\n}\n.PriceOptions_options__ifYbC .PriceOptions_infoItem__246mx button {\n border-top-left-radius: 0;\n border-bottom-left-radius: 0;\n height: 30px;\n width: 50px;\n vertical-align: top;\n padding: 0 5px;\n}\n.PriceOptions_options__ifYbC .PriceOptions_infoItem__246mx .PriceOptions_rate__17U-9 {\n margin-left: 10px;\n}\n.PriceOptions_options__ifYbC .PriceOptions_infoItem__246mx .PriceOptions_rate__17U-9 i {\n margin-right: 5px;\n color: #1790FF;\n}\n.PriceOptions_options__ifYbC.PriceOptions_multi__2fM8z p {\n font-size: 14px;\n font-weight: 400;\n color: #616a79;\n}\n.PriceOptions_options__ifYbC.PriceOptions_multi__2fM8z .PriceOptions_infoItem__246mx {\n padding-right: 0;\n display: flex;\n flex-direction: column;\n justify-content: center;\n}\n.PriceOptions_options__ifYbC.PriceOptions_multi__2fM8z .PriceOptions_infoItem__246mx .PriceOptions_priceBtn__1UaE8 {\n display: flex;\n justify-content: space-between;\n}\n.PriceOptions_options__ifYbC.PriceOptions_multi__2fM8z .PriceOptions_infoItem__246mx .PriceOptions_priceItem__3CPe3 {\n display: inline-block;\n background-color: #fff;\n border-radius: 4px;\n border: 1px solid #cfcfcf;\n}\n.PriceOptions_options__ifYbC.PriceOptions_multi__2fM8z .PriceOptions_infoItem__246mx .PriceOptions_priceItem__3CPe3.PriceOptions_active__154by {\n background-color: #fff;\n color: #FF3266FF;\n border: 1px solid #ff3266;\n}\n.PriceOptions_options__ifYbC.PriceOptions_multi__2fM8z .PriceOptions_infoItem__246mx .PriceOptions_priceInput__2JFc0 {\n width: 222px;\n width: auto;\n}\n";
  14. var styles = {
  15. "options": "PriceOptions_options__ifYbC",
  16. "infoItem": "PriceOptions_infoItem__246mx",
  17. "priceItem": "PriceOptions_priceItem__3CPe3",
  18. "active": "PriceOptions_active__154by",
  19. "priceInput": "PriceOptions_priceInput__2JFc0",
  20. "rate": "PriceOptions_rate__17U-9",
  21. "multi": "PriceOptions_multi__2fM8z",
  22. "priceBtn": "PriceOptions_priceBtn__1UaE8"
  23. };
  24. styleInject_es.styleInject(css);
  25. function ownKeys(object, enumerableOnly) {
  26. var keys = Object.keys(object);
  27. if (Object.getOwnPropertySymbols) {
  28. var symbols = Object.getOwnPropertySymbols(object);
  29. if (enumerableOnly) symbols = symbols.filter(function (sym) {
  30. return Object.getOwnPropertyDescriptor(object, sym).enumerable;
  31. });
  32. keys.push.apply(keys, symbols);
  33. }
  34. return keys;
  35. }
  36. function _objectSpread(target) {
  37. for (var i = 1; i < arguments.length; i++) {
  38. var source = arguments[i] != null ? arguments[i] : {};
  39. if (i % 2) {
  40. ownKeys(Object(source), true).forEach(function (key) {
  41. defineProperty._defineProperty(target, key, source[key]);
  42. });
  43. } else if (Object.getOwnPropertyDescriptors) {
  44. Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
  45. } else {
  46. ownKeys(Object(source)).forEach(function (key) {
  47. Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
  48. });
  49. }
  50. }
  51. return target;
  52. }
  53. var PriceOptions = function PriceOptions(_ref) {
  54. var price = _ref.price,
  55. onPriceChange = _ref.onPriceChange,
  56. _ref$rowMode = _ref.rowMode,
  57. rowMode = _ref$rowMode === void 0 ? "single" : _ref$rowMode,
  58. _ref$size = _ref.size,
  59. size = _ref$size === void 0 ? "normal" : _ref$size,
  60. _ref$focusScroll = _ref.focusScroll,
  61. focusScroll = _ref$focusScroll === void 0 ? true : _ref$focusScroll,
  62. _ref$withTitle = _ref.withTitle,
  63. withTitle = _ref$withTitle === void 0 ? true : _ref$withTitle,
  64. _ref$titleText = _ref.titleText,
  65. titleText = _ref$titleText === void 0 ? "Price" : _ref$titleText,
  66. _ref$inputPlaceholder = _ref.inputPlaceholderText,
  67. inputPlaceholderText = _ref$inputPlaceholder === void 0 ? "Others" : _ref$inputPlaceholder,
  68. _ref$priceOptions = _ref.priceOptions,
  69. priceOptions = _ref$priceOptions === void 0 ? [100, 600, 800] : _ref$priceOptions,
  70. _ref$priceRender = _ref.priceRender,
  71. priceRender = _ref$priceRender === void 0 ? function (i) {
  72. return i / 100;
  73. } : _ref$priceRender,
  74. _ref$inputPriceRender = _ref.inputPriceRender,
  75. inputPriceRender = _ref$inputPriceRender === void 0 ? function (i) {
  76. return i ? i / 100 : "";
  77. } : _ref$inputPriceRender,
  78. _ref$inputSuffix = _ref.inputSuffix,
  79. inputSuffix = _ref$inputSuffix === void 0 ? "¥" : _ref$inputSuffix,
  80. _ref$injectOptions = _ref.injectOptions,
  81. injectOptions = _ref$injectOptions === void 0 ? {
  82. priceBtnClass: {},
  83. priceInputClass: {}
  84. } : _ref$injectOptions,
  85. inputRef = _ref.inputRef;
  86. var defaultOptions = priceOptions;
  87. var _useState = React.useState(false),
  88. _useState2 = slicedToArray._slicedToArray(_useState, 2),
  89. inputStatus = _useState2[0],
  90. setInputStatus = _useState2[1];
  91. var _useState3 = React.useState(''),
  92. _useState4 = slicedToArray._slicedToArray(_useState3, 2),
  93. inputPrice = _useState4[0],
  94. setInputPrice = _useState4[1];
  95. return React__default.createElement("div", {
  96. className: index.classnames(styles.options, _objectSpread(defineProperty._defineProperty({}, styles.multi, rowMode === "multi"), utils.exportStyleSizeClass(styles, size)))
  97. }, withTitle ? titleText || null : null, React__default.createElement("div", {
  98. className: styles.infoItem
  99. }, React__default.createElement("span", {
  100. className: styles.priceBtn
  101. }, defaultOptions.map(function (item) {
  102. var _objectSpread3;
  103. return React__default.createElement("span", {
  104. className: index.classnames(_objectSpread((_objectSpread3 = {}, defineProperty._defineProperty(_objectSpread3, styles.priceItem, true), defineProperty._defineProperty(_objectSpread3, styles.active, price === item && !inputStatus), _objectSpread3), injectOptions.priceBtnClass)),
  105. key: item,
  106. onClick: function onClick() {
  107. onPriceChange(item);
  108. setInputStatus(false);
  109. }
  110. }, priceRender(item));
  111. })), React__default.createElement(antd.Input, {
  112. ref: inputRef,
  113. className: index.classnames(styles.priceInput, _objectSpread({}, injectOptions.priceInputClass)),
  114. onMouseEnter: function onMouseEnter() {
  115. if (inputStatus && inputRef && inputRef.current) {
  116. inputRef.current.focus();
  117. inputRef.current.select();
  118. }
  119. },
  120. suffix: inputSuffix,
  121. value: inputStatus ? inputPriceRender(inputPrice) : "",
  122. placeholder: inputPlaceholderText,
  123. onChange: function onChange(e) {
  124. var n = +e.target.value;
  125. if (Number.isNaN(n)) {
  126. return;
  127. }
  128. setInputPrice("".concat(n * 100));
  129. onPriceChange(n * 100);
  130. },
  131. onClick: function onClick(e) {
  132. if (!inputStatus) {
  133. setInputPrice('');
  134. setInputStatus(true);
  135. }
  136. },
  137. onFocus: function onFocus(e) {
  138. e.target.placeholder = "";
  139. if (inputStatus) {
  140. setInputPrice("".concat(price));
  141. } else {
  142. setInputPrice('');
  143. setInputStatus(true);
  144. }
  145. if (focusScroll) {
  146. e.target.scrollIntoView();
  147. }
  148. },
  149. onBlur: function onBlur(e) {
  150. e.target.placeholder = inputPlaceholderText;
  151. if (inputPrice) {
  152. setInputStatus(true);
  153. } else {
  154. setInputStatus(false);
  155. }
  156. }
  157. })));
  158. };
  159. exports.default = PriceOptions;
  160. //# sourceMappingURL=index.js.map