From a58cb3cd399911602672135ea743cb057aff4e12 Mon Sep 17 00:00:00 2001
From: tanjinzhou <415800467@qq.com>
Date: Wed, 2 Jun 2021 11:42:14 +0800
Subject: [PATCH] perf: remove rate
---
components/vc-rate/assets/index.less | 103 -------------
components/vc-rate/index.js | 3 -
components/vc-rate/src/Rate.jsx | 215 ---------------------------
components/vc-rate/src/Star.jsx | 92 ------------
components/vc-rate/src/index.js | 2 -
components/vc-rate/src/util.js | 39 -----
6 files changed, 454 deletions(-)
delete mode 100644 components/vc-rate/assets/index.less
delete mode 100644 components/vc-rate/index.js
delete mode 100644 components/vc-rate/src/Rate.jsx
delete mode 100644 components/vc-rate/src/Star.jsx
delete mode 100644 components/vc-rate/src/index.js
delete mode 100644 components/vc-rate/src/util.js
diff --git a/components/vc-rate/assets/index.less b/components/vc-rate/assets/index.less
deleted file mode 100644
index 177e9074e..000000000
--- a/components/vc-rate/assets/index.less
+++ /dev/null
@@ -1,103 +0,0 @@
-@rate-prefix-cls: rc-rate;
-@rate-star-color: #f5a623;
-@font-size-base: 13px;
-
-.@{rate-prefix-cls} {
- margin: 0;
- padding: 0;
- list-style: none;
- font-size: 18px;
- display: inline-block;
- vertical-align: middle;
- font-weight: normal;
- font-style: normal;
- outline: none;
-
- &-disabled &-star {
- &:before,
- &-content:before {
- cursor: default;
- }
- &:hover {
- transform: scale(1);
- }
- }
-
- &-star {
- margin: 0;
- padding: 0;
- display: inline-block;
- margin-right: 8px;
- position: relative;
- transition: all 0.3s;
- color: #e9e9e9;
- cursor: pointer;
- line-height: 1.5;
-
- &-first,
- &-second {
- transition: all 0.3s;
- }
-
- &-focused,
- &:hover {
- transform: scale(1.1);
- }
-
- &-first {
- position: absolute;
- left: 0;
- top: 0;
- width: 50%;
- height: 100%;
- overflow: hidden;
- opacity: 0;
- }
-
- &-half &-first,
- &-half &-second {
- opacity: 1;
- }
-
- &-half &-first,
- &-full &-second {
- color: @rate-star-color;
- }
-
- &-half:hover &-first,
- &-full:hover &-second {
- color: tint(@rate-star-color, 30%);
- }
- }
-}
-
-@icon-url: '//at.alicdn.com/t/font_r5u29ls31bgldi';
-
-@font-face {
- font-family: 'anticon';
- src: url('@{icon-url}.eot'); /* IE9*/
- src: url('@{icon-url}.eot?#iefix') format('embedded-opentype'),
- /* IE6-IE8 */ url('@{icon-url}.woff') format('woff'),
- /* chrome、firefox */ url('@{icon-url}.ttf') format('truetype'),
- /* chrome、firefox、opera、Safari, Android, iOS 4.2+*/ url('@{icon-url}.svg#iconfont')
- format('svg'); /* iOS 4.1- */
-}
-
-.anticon {
- font-style: normal;
- vertical-align: baseline;
- text-align: center;
- text-transform: none;
- line-height: 1;
- text-rendering: optimizeLegibility;
- -webkit-font-smoothing: antialiased;
- -moz-osx-font-smoothing: grayscale;
- &:before {
- display: block;
- font-family: 'anticon' !important;
- }
-}
-
-.anticon-star:before {
- content: '\e660';
-}
diff --git a/components/vc-rate/index.js b/components/vc-rate/index.js
deleted file mode 100644
index 57725e06a..000000000
--- a/components/vc-rate/index.js
+++ /dev/null
@@ -1,3 +0,0 @@
-// based on rc-rate 2.5.0
-import Rate from './src/';
-export default Rate;
diff --git a/components/vc-rate/src/Rate.jsx b/components/vc-rate/src/Rate.jsx
deleted file mode 100644
index cbcd699ff..000000000
--- a/components/vc-rate/src/Rate.jsx
+++ /dev/null
@@ -1,215 +0,0 @@
-import PropTypes from '../../_util/vue-types';
-import classNames from '../../_util/classNames';
-import KeyCode from '../../_util/KeyCode';
-import {
- initDefaultProps,
- hasProp,
- getOptionProps,
- getComponent,
- findDOMNode,
-} from '../../_util/props-util';
-import BaseMixin from '../../_util/BaseMixin';
-import { getOffsetLeft } from './util';
-import Star from './Star';
-import { defineComponent } from 'vue';
-
-const rateProps = {
- disabled: PropTypes.looseBool,
- value: PropTypes.number,
- defaultValue: PropTypes.number,
- count: PropTypes.number,
- allowHalf: PropTypes.looseBool,
- allowClear: PropTypes.looseBool,
- prefixCls: PropTypes.string,
- character: PropTypes.any,
- characterRender: PropTypes.func,
- tabindex: PropTypes.number,
- autofocus: PropTypes.looseBool,
-};
-
-function noop() {}
-
-export default defineComponent({
- name: 'Rate',
- mixins: [BaseMixin],
- inheritAttrs: false,
- props: initDefaultProps(rateProps, {
- defaultValue: 0,
- count: 5,
- allowHalf: false,
- allowClear: true,
- prefixCls: 'rc-rate',
- tabindex: 0,
- character: '★',
- }),
- data() {
- let value = this.value;
- if (!hasProp(this, 'value')) {
- value = this.defaultValue;
- }
- return {
- sValue: value,
- focused: false,
- cleanedValue: null,
- hoverValue: undefined,
- };
- },
- watch: {
- value(val) {
- this.setState({
- sValue: val,
- });
- },
- },
- mounted() {
- this.$nextTick(() => {
- if (this.autofocus && !this.disabled) {
- this.focus();
- }
- });
- },
- methods: {
- onHover(event, index) {
- const hoverValue = this.getStarValue(index, event.pageX);
- const { cleanedValue } = this;
- if (hoverValue !== cleanedValue) {
- this.setState({
- hoverValue,
- cleanedValue: null,
- });
- }
- this.__emit('hoverChange', hoverValue);
- },
- onMouseLeave() {
- this.setState({
- hoverValue: undefined,
- cleanedValue: null,
- });
- this.__emit('hoverChange', undefined);
- },
- onClick(event, index) {
- const { allowClear, sValue: value } = this;
- const newValue = this.getStarValue(index, event.pageX);
- let isReset = false;
- if (allowClear) {
- isReset = newValue === value;
- }
- this.onMouseLeave(true);
- this.changeValue(isReset ? 0 : newValue);
- this.setState({
- cleanedValue: isReset ? newValue : null,
- });
- },
- onFocus() {
- this.setState({
- focused: true,
- });
- this.__emit('focus');
- },
- onBlur() {
- this.setState({
- focused: false,
- });
- this.__emit('blur');
- },
- onKeyDown(event) {
- const { keyCode } = event;
- const { count, allowHalf } = this;
- let { sValue } = this;
- if (keyCode === KeyCode.RIGHT && sValue < count) {
- if (allowHalf) {
- sValue += 0.5;
- } else {
- sValue += 1;
- }
- this.changeValue(sValue);
- event.preventDefault();
- } else if (keyCode === KeyCode.LEFT && sValue > 0) {
- if (allowHalf) {
- sValue -= 0.5;
- } else {
- sValue -= 1;
- }
- this.changeValue(sValue);
- event.preventDefault();
- }
- this.__emit('keydown', event);
- },
- getStarDOM(index) {
- return findDOMNode(this.$refs['stars' + index]);
- },
- getStarValue(index, x) {
- let value = index + 1;
- if (this.allowHalf) {
- const starEle = this.getStarDOM(index);
- const leftDis = getOffsetLeft(starEle);
- const width = starEle.clientWidth;
- if (x - leftDis < width / 2) {
- value -= 0.5;
- }
- }
- return value;
- },
- focus() {
- if (!this.disabled) {
- this.$refs.rateRef.focus();
- }
- },
- blur() {
- if (!this.disabled) {
- this.$refs.rateRef.blur();
- }
- },
- changeValue(value) {
- if (!hasProp(this, 'value')) {
- this.setState({
- sValue: value,
- });
- }
- this.__emit('update:value', value);
- this.__emit('change', value);
- },
- },
- render() {
- const { count, allowHalf, prefixCls, disabled, tabindex } = getOptionProps(this);
- const { sValue, hoverValue, focused } = this;
- const { class: className, style } = this.$attrs;
- const stars = [];
- const disabledClass = disabled ? `${prefixCls}-disabled` : '';
- const character = getComponent(this, 'character');
- const characterRender = this.characterRender || this.$slots.characterRender;
- for (let index = 0; index < count; index++) {
- const starProps = {
- index,
- count,
- disabled,
- prefixCls: `${prefixCls}-star`,
- allowHalf,
- value: hoverValue === undefined ? sValue : hoverValue,
- character,
- characterRender,
- focused,
- onClick: this.onClick,
- onHover: this.onHover,
- key: index,
- ref: `stars${index}`,
- };
- stars.push(