1 line
26 KiB
JSON
1 line
26 KiB
JSON
|
{"ast":null,"code":"import _extends from \"@babel/runtime/helpers/esm/extends\";\nimport _defineProperty from \"@babel/runtime/helpers/esm/defineProperty\";\nimport _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport _objectWithoutProperties from \"@babel/runtime/helpers/esm/objectWithoutProperties\";\nvar _excluded = [\"prefixCls\", \"className\", \"defaultValue\", \"value\", \"count\", \"allowHalf\", \"allowClear\", \"keyboard\", \"character\", \"characterRender\", \"disabled\", \"direction\", \"tabIndex\", \"autoFocus\", \"onHoverChange\", \"onChange\", \"onFocus\", \"onBlur\", \"onKeyDown\", \"onMouseLeave\"];\nimport classNames from 'classnames';\nimport useMergedState from \"rc-util/es/hooks/useMergedState\";\nimport KeyCode from \"rc-util/es/KeyCode\";\nimport pickAttrs from \"rc-util/es/pickAttrs\";\nimport React from 'react';\nimport Star from \"./Star\";\nimport useRefs from \"./useRefs\";\nimport { getOffsetLeft } from \"./util\";\nfunction Rate(props, ref) {\n var _props$prefixCls = props.prefixCls,\n prefixCls = _props$prefixCls === void 0 ? 'rc-rate' : _props$prefixCls,\n className = props.className,\n defaultValue = props.defaultValue,\n propValue = props.value,\n _props$count = props.count,\n count = _props$count === void 0 ? 5 : _props$count,\n _props$allowHalf = props.allowHalf,\n allowHalf = _props$allowHalf === void 0 ? false : _props$allowHalf,\n _props$allowClear = props.allowClear,\n allowClear = _props$allowClear === void 0 ? true : _props$allowClear,\n _props$keyboard = props.keyboard,\n keyboard = _props$keyboard === void 0 ? true : _props$keyboard,\n _props$character = props.character,\n character = _props$character === void 0 ? '★' : _props$character,\n characterRender = props.characterRender,\n disabled = props.disabled,\n _props$direction = props.direction,\n direction = _props$direction === void 0 ? 'ltr' : _props$direction,\n _props$tabIndex = props.tabIndex,\n tabIndex = _props$tabIndex === void 0 ? 0 : _props$tabIndex,\n autoFocus = props.autoFocus,\n onHoverChange = props.onHoverChange,\n onChange = props.onChange,\n onFocus = props.onFocus,\n onBlur = props.onBlur,\n onKeyDown = props.onKeyDown,\n onMouseLeave = props.onMouseLeave,\n restProps = _objectWithoutProperties(props, _excluded);\n var _useRefs = useRefs(),\n _useRefs2 = _slicedToArray(_useRefs, 2),\n getStarRef = _useRefs2[0],\n setStarRef = _useRefs2[1];\n var rateRef = React.useRef(null);\n\n // ============================ Ref =============================\n var triggerFocus = function triggerFocus() {\n if (!disabled) {\n var _rateRef$current;\n (_rateRef$current = rateRef.current) === null || _rateRef$current === void 0 || _rateRef$current.focus();\n }\n };\n React.useImperativeHandle(ref, function () {\n return {\n focus: triggerFocus,\n blur: function blur() {\n if (!disabled) {\n var _rateRef$current2;\n (_rateRef$current2 = rateRef.current) === null || _rateRef$current2 === void 0 || _rateRef$current2.blur();\n }\n }\n };\n });\n\n // =========================== Value ============================\n var _useMergedState = useMergedState(defaultValue || 0, {\n value: propValue\n }),\n _useMergedState2 = _slicedToArray(_useMergedState, 2),\n value = _useMergedState2[0],\n setValue = _useMergedState2[1];\n var _useMergedState3 = useMergedState(null),\n _useMergedState4 = _slicedToArray(_useMergedState3, 2),\n cleanedValue = _useMergedState4[0],\n setCleanedValue = _useMergedState4[1];\n var getStarValue = function getStarValue(index, x) {\n var reverse = direction === 'rtl';\n var starValue = index + 1;\n if (allowHalf) {\n var starEle = getStarRef(index);\n var leftDis = getOffsetLeft(starEle);\n var width = starEle.clientWidth;\n if (reverse && x - leftDis > width / 2) {\n starValue -= 0.5;\n } else if (!reverse && x - leftDis < width / 2) {\n starValu
|