No Description

index.js 8.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 _rollupPluginBabelHelpers = require('../_rollupPluginBabelHelpers-0494a5d0.js');
  5. var React = require('react');
  6. var React__default = _interopDefault(React);
  7. var styleInject_es = require('../style-inject.es-dcee06b6.js');
  8. require('../_commonjsHelpers-72d386ba.js');
  9. var index = require('../index-44e17595.js');
  10. var antd = require('antd');
  11. 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_small__2UZ7N {\n padding: 0 0 12px 0;\n border-bottom: none;\n}\n.PriceOptions_options__ifYbC.PriceOptions_small__2UZ7N p {\n margin-bottom: 8px;\n}\n.PriceOptions_options__ifYbC.PriceOptions_small__2UZ7N .PriceOptions_infoItem__246mx {\n text-align: center;\n}\n.PriceOptions_options__ifYbC.PriceOptions_small__2UZ7N .PriceOptions_infoItem__246mx .PriceOptions_priceItem__3CPe3 {\n border-radius: 6px;\n height: 32px;\n width: 72px;\n margin: 0 0 12px 19px;\n}\n.PriceOptions_options__ifYbC.PriceOptions_small__2UZ7N .PriceOptions_infoItem__246mx .PriceOptions_priceItem__3CPe3:first-child {\n margin: 0 0 12px 0px;\n}\n.PriceOptions_options__ifYbC.PriceOptions_small__2UZ7N .PriceOptions_infoItem__246mx .PriceOptions_priceInput__2JFc0 {\n display: block;\n width: 254px;\n border-radius: 6px;\n height: 32px;\n}\n.PriceOptions_options__ifYbC.PriceOptions_multi__2fM8z {\n padding: 20px 20px;\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 width: 74px;\n height: 36px;\n line-height: 36px;\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-radius: 4px;\n border: 1px solid #ff3266;\n}\n.PriceOptions_options__ifYbC.PriceOptions_multi__2fM8z .PriceOptions_infoItem__246mx .PriceOptions_priceInput__2JFc0 {\n border-radius: 6px;\n height: 36px;\n width: auto;\n}\n";
  12. var styles = {
  13. "options": "PriceOptions_options__ifYbC",
  14. "infoItem": "PriceOptions_infoItem__246mx",
  15. "priceItem": "PriceOptions_priceItem__3CPe3",
  16. "active": "PriceOptions_active__154by",
  17. "priceInput": "PriceOptions_priceInput__2JFc0",
  18. "rate": "PriceOptions_rate__17U-9",
  19. "small": "PriceOptions_small__2UZ7N",
  20. "multi": "PriceOptions_multi__2fM8z",
  21. "priceBtn": "PriceOptions_priceBtn__1UaE8"
  22. };
  23. styleInject_es.styleInject(css);
  24. var PriceOptions = function PriceOptions(_ref) {
  25. var price = _ref.price,
  26. onPriceChange = _ref.onPriceChange,
  27. _ref$rowMode = _ref.rowMode,
  28. rowMode = _ref$rowMode === void 0 ? "single" : _ref$rowMode,
  29. _ref$size = _ref.size,
  30. _ref$focusScroll = _ref.focusScroll,
  31. focusScroll = _ref$focusScroll === void 0 ? true : _ref$focusScroll,
  32. _ref$withTitle = _ref.withTitle,
  33. withTitle = _ref$withTitle === void 0 ? true : _ref$withTitle,
  34. _ref$titleText = _ref.titleText,
  35. titleText = _ref$titleText === void 0 ? "Price" : _ref$titleText,
  36. _ref$inputPlaceholder = _ref.inputPlaceholderText,
  37. inputPlaceholderText = _ref$inputPlaceholder === void 0 ? "Others" : _ref$inputPlaceholder,
  38. _ref$priceOptions = _ref.priceOptions,
  39. priceOptions = _ref$priceOptions === void 0 ? [100, 600, 800] : _ref$priceOptions,
  40. _ref$priceRender = _ref.priceRender,
  41. priceRender = _ref$priceRender === void 0 ? function (i) {
  42. return i / 100;
  43. } : _ref$priceRender,
  44. _ref$inputPriceRender = _ref.inputPriceRender,
  45. inputPriceRender = _ref$inputPriceRender === void 0 ? function (i) {
  46. return i ? i / 100 : "";
  47. } : _ref$inputPriceRender,
  48. _ref$inputSuffix = _ref.inputSuffix,
  49. inputSuffix = _ref$inputSuffix === void 0 ? "¥" : _ref$inputSuffix,
  50. _ref$injectOptions = _ref.injectOptions,
  51. injectOptions = _ref$injectOptions === void 0 ? {
  52. priceBtnClass: {},
  53. priceInputClass: {}
  54. } : _ref$injectOptions,
  55. inputRef = _ref.inputRef;
  56. var defaultOptions = priceOptions;
  57. var _useState = React.useState(false),
  58. _useState2 = _rollupPluginBabelHelpers._slicedToArray(_useState, 2),
  59. inputStatus = _useState2[0],
  60. setInputStatus = _useState2[1];
  61. var _useState3 = React.useState(''),
  62. _useState4 = _rollupPluginBabelHelpers._slicedToArray(_useState3, 2),
  63. inputPrice = _useState4[0],
  64. setInputPrice = _useState4[1];
  65. return React__default.createElement("div", {
  66. className: index.classnames(styles.options, _rollupPluginBabelHelpers._defineProperty({}, styles.multi, rowMode === "multi"))
  67. }, withTitle ? titleText || null : null, React__default.createElement("div", {
  68. className: styles.infoItem
  69. }, React__default.createElement("span", {
  70. className: styles.priceBtn
  71. }, defaultOptions.map(function (item) {
  72. var _objectSpread2;
  73. return React__default.createElement("span", {
  74. className: index.classnames(_rollupPluginBabelHelpers._objectSpread2((_objectSpread2 = {}, _rollupPluginBabelHelpers._defineProperty(_objectSpread2, styles.priceItem, true), _rollupPluginBabelHelpers._defineProperty(_objectSpread2, styles.active, price === item && !inputStatus), _objectSpread2), injectOptions.priceBtnClass)),
  75. key: item,
  76. onClick: function onClick() {
  77. onPriceChange(item);
  78. setInputStatus(false);
  79. }
  80. }, priceRender(item));
  81. })), React__default.createElement(antd.Input, {
  82. ref: inputRef,
  83. className: index.classnames(styles.priceInput, _rollupPluginBabelHelpers._objectSpread2({}, injectOptions.priceInputClass)),
  84. onMouseEnter: function onMouseEnter() {
  85. if (inputStatus && inputRef && inputRef.current) {
  86. inputRef.current.focus();
  87. inputRef.current.select();
  88. }
  89. },
  90. suffix: inputSuffix,
  91. value: inputStatus ? inputPriceRender(inputPrice) : "",
  92. placeholder: inputPlaceholderText,
  93. onChange: function onChange(e) {
  94. var n = +e.target.value;
  95. if (Number.isNaN(n)) {
  96. return;
  97. }
  98. setInputPrice("".concat(n * 100));
  99. onPriceChange(n * 100);
  100. },
  101. onClick: function onClick(e) {
  102. if (!inputStatus) {
  103. setInputPrice('');
  104. setInputStatus(true);
  105. }
  106. },
  107. onFocus: function onFocus(e) {
  108. e.target.placeholder = "";
  109. if (inputStatus) {
  110. setInputPrice("".concat(price));
  111. } else {
  112. setInputPrice('');
  113. setInputStatus(true);
  114. }
  115. if (focusScroll) {
  116. e.target.scrollIntoView();
  117. }
  118. },
  119. onBlur: function onBlur(e) {
  120. e.target.placeholder = inputPlaceholderText;
  121. if (inputPrice) {
  122. setInputStatus(true);
  123. } else {
  124. setInputStatus(false);
  125. }
  126. }
  127. })));
  128. };
  129. exports.default = PriceOptions;
  130. //# sourceMappingURL=index.js.map