index.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. "use client";
  2. var __rest = this && this.__rest || function (s, e) {
  3. var t = {};
  4. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
  5. if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  6. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
  7. }
  8. return t;
  9. };
  10. import * as React from 'react';
  11. import StarFilled from "@ant-design/icons/es/icons/StarFilled";
  12. import classNames from 'classnames';
  13. import RcRate from 'rc-rate';
  14. import { ConfigContext } from '../config-provider';
  15. import Tooltip from '../tooltip';
  16. import useStyle from './style';
  17. import DisabledContext from '../config-provider/DisabledContext';
  18. const Rate = /*#__PURE__*/React.forwardRef((props, ref) => {
  19. const {
  20. prefixCls,
  21. className,
  22. rootClassName,
  23. style,
  24. tooltips,
  25. character = /*#__PURE__*/React.createElement(StarFilled, null),
  26. disabled: customDisabled
  27. } = props,
  28. rest = __rest(props, ["prefixCls", "className", "rootClassName", "style", "tooltips", "character", "disabled"]);
  29. const characterRender = (node, {
  30. index
  31. }) => {
  32. if (!tooltips) {
  33. return node;
  34. }
  35. return /*#__PURE__*/React.createElement(Tooltip, {
  36. title: tooltips[index]
  37. }, node);
  38. };
  39. const {
  40. getPrefixCls,
  41. direction,
  42. rate
  43. } = React.useContext(ConfigContext);
  44. const ratePrefixCls = getPrefixCls('rate', prefixCls);
  45. // Style
  46. const [wrapCSSVar, hashId, cssVarCls] = useStyle(ratePrefixCls);
  47. const mergedStyle = Object.assign(Object.assign({}, rate === null || rate === void 0 ? void 0 : rate.style), style);
  48. // ===================== Disabled =====================
  49. const disabled = React.useContext(DisabledContext);
  50. const mergedDisabled = customDisabled !== null && customDisabled !== void 0 ? customDisabled : disabled;
  51. return wrapCSSVar(/*#__PURE__*/React.createElement(RcRate, Object.assign({
  52. ref: ref,
  53. character: character,
  54. characterRender: characterRender,
  55. disabled: mergedDisabled
  56. }, rest, {
  57. className: classNames(className, rootClassName, hashId, cssVarCls, rate === null || rate === void 0 ? void 0 : rate.className),
  58. style: mergedStyle,
  59. prefixCls: ratePrefixCls,
  60. direction: direction
  61. })));
  62. });
  63. if (process.env.NODE_ENV !== 'production') {
  64. Rate.displayName = 'Rate';
  65. }
  66. export default Rate;