No Description

index.js 8.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 '../_commonjsHelpers-97e6d7b1.js';
  5. import { c as classnames } from '../index-c9837619.js';
  6. import { e as exportStyleSizeClass } from '../utils-6b513b37.js';
  7. import { _ as _slicedToArray } from '../slicedToArray-4cd9e6d3.js';
  8. import { Input } from 'antd';
  9. 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 height: 72px;\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";
  10. var styles = {
  11. "options": "PriceOptions_options__ifYbC",
  12. "infoItem": "PriceOptions_infoItem__246mx",
  13. "priceItem": "PriceOptions_priceItem__3CPe3",
  14. "active": "PriceOptions_active__154by",
  15. "priceInput": "PriceOptions_priceInput__2JFc0",
  16. "rate": "PriceOptions_rate__17U-9",
  17. "multi": "PriceOptions_multi__2fM8z",
  18. "priceBtn": "PriceOptions_priceBtn__1UaE8"
  19. };
  20. styleInject(css);
  21. function ownKeys(object, enumerableOnly) {
  22. var keys = Object.keys(object);
  23. if (Object.getOwnPropertySymbols) {
  24. var symbols = Object.getOwnPropertySymbols(object);
  25. if (enumerableOnly) symbols = symbols.filter(function (sym) {
  26. return Object.getOwnPropertyDescriptor(object, sym).enumerable;
  27. });
  28. keys.push.apply(keys, symbols);
  29. }
  30. return keys;
  31. }
  32. function _objectSpread(target) {
  33. for (var i = 1; i < arguments.length; i++) {
  34. var source = arguments[i] != null ? arguments[i] : {};
  35. if (i % 2) {
  36. ownKeys(Object(source), true).forEach(function (key) {
  37. _defineProperty(target, key, source[key]);
  38. });
  39. } else if (Object.getOwnPropertyDescriptors) {
  40. Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
  41. } else {
  42. ownKeys(Object(source)).forEach(function (key) {
  43. Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
  44. });
  45. }
  46. }
  47. return target;
  48. }
  49. var PriceOptions = function PriceOptions(_ref) {
  50. var price = _ref.price,
  51. onPriceChange = _ref.onPriceChange,
  52. _ref$rowMode = _ref.rowMode,
  53. rowMode = _ref$rowMode === void 0 ? "single" : _ref$rowMode,
  54. _ref$size = _ref.size,
  55. size = _ref$size === void 0 ? "normal" : _ref$size,
  56. _ref$focusScroll = _ref.focusScroll,
  57. focusScroll = _ref$focusScroll === void 0 ? true : _ref$focusScroll,
  58. _ref$withTitle = _ref.withTitle,
  59. withTitle = _ref$withTitle === void 0 ? true : _ref$withTitle,
  60. _ref$titleText = _ref.titleText,
  61. titleText = _ref$titleText === void 0 ? "Price" : _ref$titleText,
  62. _ref$inputPlaceholder = _ref.inputPlaceholderText,
  63. inputPlaceholderText = _ref$inputPlaceholder === void 0 ? "Others" : _ref$inputPlaceholder,
  64. _ref$priceOptions = _ref.priceOptions,
  65. priceOptions = _ref$priceOptions === void 0 ? [100, 600, 800] : _ref$priceOptions,
  66. _ref$priceRender = _ref.priceRender,
  67. priceRender = _ref$priceRender === void 0 ? function (i) {
  68. return i / 100;
  69. } : _ref$priceRender,
  70. _ref$inputPriceRender = _ref.inputPriceRender,
  71. inputPriceRender = _ref$inputPriceRender === void 0 ? function (i) {
  72. return i ? i / 100 : "";
  73. } : _ref$inputPriceRender,
  74. _ref$inputSuffix = _ref.inputSuffix,
  75. inputSuffix = _ref$inputSuffix === void 0 ? "¥" : _ref$inputSuffix,
  76. _ref$injectOptions = _ref.injectOptions,
  77. injectOptions = _ref$injectOptions === void 0 ? {
  78. priceBtnClass: function priceBtnClass() {
  79. return undefined;
  80. },
  81. priceInputClass: function priceInputClass() {
  82. return undefined;
  83. }
  84. } : _ref$injectOptions,
  85. inputRef = _ref.inputRef;
  86. var defaultOptions = priceOptions;
  87. var _useState = useState(false),
  88. _useState2 = _slicedToArray(_useState, 2),
  89. inputStatus = _useState2[0],
  90. setInputStatus = _useState2[1];
  91. var _useState3 = useState(''),
  92. _useState4 = _slicedToArray(_useState3, 2),
  93. inputPrice = _useState4[0],
  94. setInputPrice = _useState4[1];
  95. return React.createElement("div", {
  96. className: classnames(styles.options, _objectSpread(_defineProperty({}, styles.multi, rowMode === "multi"), exportStyleSizeClass(styles, size)))
  97. }, withTitle ? titleText || null : null, React.createElement("div", {
  98. className: styles.infoItem
  99. }, React.createElement("span", {
  100. className: styles.priceBtn
  101. }, defaultOptions.map(function (item) {
  102. var _objectSpread3;
  103. return React.createElement("span", {
  104. className: classnames(_objectSpread((_objectSpread3 = {}, _defineProperty(_objectSpread3, styles.priceItem, true), _defineProperty(_objectSpread3, styles.active, price === item && !inputStatus), _objectSpread3), injectOptions.priceBtnClass(price === item && !inputStatus))),
  105. key: item,
  106. onClick: function onClick() {
  107. onPriceChange(item);
  108. setInputStatus(false);
  109. }
  110. }, priceRender(item));
  111. })), React.createElement(Input, {
  112. ref: inputRef,
  113. className: 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. export default PriceOptions;
  160. //# sourceMappingURL=index.js.map