暫無描述

index.js 8.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. import React, { useState } from 'react';
  2. import { s as styleInject } from '../style-inject.es-1f59c1d0.js';
  3. import { _ as _defineProperty } from '../defineProperty-18999f8e.js';
  4. import { c as classnames } from '../index-b8d80d39.js';
  5. import { e as exportStyleSizeClass } from '../utils-6b513b37.js';
  6. import { _ as _slicedToArray } from '../slicedToArray-4cd9e6d3.js';
  7. import { Input } from 'antd';
  8. var css = ".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";
  9. var styles = {
  10. "options": "PriceOptions_options__ifYbC",
  11. "infoItem": "PriceOptions_infoItem__246mx",
  12. "priceItem": "PriceOptions_priceItem__3CPe3",
  13. "active": "PriceOptions_active__154by",
  14. "priceInput": "PriceOptions_priceInput__2JFc0",
  15. "rate": "PriceOptions_rate__17U-9",
  16. "multi": "PriceOptions_multi__2fM8z",
  17. "priceBtn": "PriceOptions_priceBtn__1UaE8"
  18. };
  19. styleInject(css);
  20. function ownKeys(object, enumerableOnly) {
  21. var keys = Object.keys(object);
  22. if (Object.getOwnPropertySymbols) {
  23. var symbols = Object.getOwnPropertySymbols(object);
  24. if (enumerableOnly) symbols = symbols.filter(function (sym) {
  25. return Object.getOwnPropertyDescriptor(object, sym).enumerable;
  26. });
  27. keys.push.apply(keys, symbols);
  28. }
  29. return keys;
  30. }
  31. function _objectSpread(target) {
  32. for (var i = 1; i < arguments.length; i++) {
  33. var source = arguments[i] != null ? arguments[i] : {};
  34. if (i % 2) {
  35. ownKeys(Object(source), true).forEach(function (key) {
  36. _defineProperty(target, key, source[key]);
  37. });
  38. } else if (Object.getOwnPropertyDescriptors) {
  39. Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
  40. } else {
  41. ownKeys(Object(source)).forEach(function (key) {
  42. Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
  43. });
  44. }
  45. }
  46. return target;
  47. }
  48. var PriceOptions = function PriceOptions(_ref) {
  49. var price = _ref.price,
  50. onPriceChange = _ref.onPriceChange,
  51. _ref$rowMode = _ref.rowMode,
  52. rowMode = _ref$rowMode === void 0 ? "single" : _ref$rowMode,
  53. _ref$size = _ref.size,
  54. size = _ref$size === void 0 ? "normal" : _ref$size,
  55. _ref$focusScroll = _ref.focusScroll,
  56. focusScroll = _ref$focusScroll === void 0 ? true : _ref$focusScroll,
  57. _ref$withTitle = _ref.withTitle,
  58. withTitle = _ref$withTitle === void 0 ? true : _ref$withTitle,
  59. _ref$titleText = _ref.titleText,
  60. titleText = _ref$titleText === void 0 ? "Price" : _ref$titleText,
  61. _ref$inputPlaceholder = _ref.inputPlaceholderText,
  62. inputPlaceholderText = _ref$inputPlaceholder === void 0 ? "Others" : _ref$inputPlaceholder,
  63. _ref$priceOptions = _ref.priceOptions,
  64. priceOptions = _ref$priceOptions === void 0 ? [100, 600, 800] : _ref$priceOptions,
  65. _ref$priceRender = _ref.priceRender,
  66. priceRender = _ref$priceRender === void 0 ? function (i) {
  67. return i / 100;
  68. } : _ref$priceRender,
  69. _ref$inputPriceRender = _ref.inputPriceRender,
  70. inputPriceRender = _ref$inputPriceRender === void 0 ? function (i) {
  71. return i ? i / 100 : "";
  72. } : _ref$inputPriceRender,
  73. _ref$inputSuffix = _ref.inputSuffix,
  74. inputSuffix = _ref$inputSuffix === void 0 ? "¥" : _ref$inputSuffix,
  75. _ref$injectOptions = _ref.injectOptions,
  76. injectOptions = _ref$injectOptions === void 0 ? {
  77. priceBtnClass: function priceBtnClass() {
  78. return undefined;
  79. },
  80. priceInputClass: function priceInputClass() {
  81. return undefined;
  82. }
  83. } : _ref$injectOptions,
  84. inputRef = _ref.inputRef;
  85. var defaultOptions = priceOptions;
  86. var _useState = useState(false),
  87. _useState2 = _slicedToArray(_useState, 2),
  88. inputStatus = _useState2[0],
  89. setInputStatus = _useState2[1];
  90. var _useState3 = useState(''),
  91. _useState4 = _slicedToArray(_useState3, 2),
  92. inputPrice = _useState4[0],
  93. setInputPrice = _useState4[1];
  94. return React.createElement("div", {
  95. className: classnames(styles.options, _objectSpread(_defineProperty({}, styles.multi, rowMode === "multi"), exportStyleSizeClass(styles, size)))
  96. }, withTitle ? titleText || null : null, React.createElement("div", {
  97. className: styles.infoItem
  98. }, React.createElement("span", {
  99. className: styles.priceBtn
  100. }, defaultOptions.map(function (item) {
  101. var _objectSpread3;
  102. return React.createElement("span", {
  103. className: classnames(_objectSpread((_objectSpread3 = {}, _defineProperty(_objectSpread3, styles.priceItem, true), _defineProperty(_objectSpread3, styles.active, price === item && !inputStatus), _objectSpread3), injectOptions.priceBtnClass(price === item && !inputStatus))),
  104. key: item,
  105. onClick: function onClick() {
  106. onPriceChange(item);
  107. setInputStatus(false);
  108. }
  109. }, priceRender(item));
  110. })), React.createElement(Input, {
  111. ref: inputRef,
  112. className: classnames(styles.priceInput, _objectSpread({}, injectOptions.priceInputClass())),
  113. onMouseEnter: function onMouseEnter() {
  114. if (inputStatus && inputRef && inputRef.current) {
  115. inputRef.current.focus();
  116. inputRef.current.select();
  117. }
  118. },
  119. suffix: inputSuffix,
  120. value: inputStatus ? inputPriceRender(inputPrice) : "",
  121. placeholder: inputPlaceholderText,
  122. onChange: function onChange(e) {
  123. var n = +e.target.value;
  124. if (Number.isNaN(n)) {
  125. return;
  126. }
  127. setInputPrice("".concat(n * 100));
  128. onPriceChange(n * 100);
  129. },
  130. onClick: function onClick(e) {
  131. if (!inputStatus) {
  132. setInputPrice('');
  133. setInputStatus(true);
  134. }
  135. },
  136. onFocus: function onFocus(e) {
  137. e.target.placeholder = "";
  138. if (inputStatus) {
  139. setInputPrice("".concat(price));
  140. } else {
  141. setInputPrice('');
  142. setInputStatus(true);
  143. }
  144. if (focusScroll) {
  145. e.target.scrollIntoView();
  146. }
  147. },
  148. onBlur: function onBlur(e) {
  149. e.target.placeholder = inputPlaceholderText;
  150. if (inputPrice) {
  151. setInputStatus(true);
  152. } else {
  153. setInputStatus(false);
  154. }
  155. }
  156. })));
  157. };
  158. export default PriceOptions;
  159. //# sourceMappingURL=index.js.map