From 8a267f0e32b3e0c7b33386dd0c5ed109c14d737d Mon Sep 17 00:00:00 2001 From: wangxueliang Date: Wed, 1 Nov 2017 17:03:42 +0800 Subject: [PATCH] rate --- components/index.js | 3 + components/rate/Rate.vue | 119 +++++++++++++++++++++++++++++++ components/rate/Star.vue | 52 ++++++++++++++ components/rate/index.js | 3 + components/rate/style/index.js | 2 + components/rate/style/index.less | 73 +++++++++++++++++++ components/util/util.js | 40 +++++++++++ examples/index.js | 3 + examples/rate.vue | 63 ++++++++++++++++ 9 files changed, 358 insertions(+) create mode 100644 components/rate/Rate.vue create mode 100644 components/rate/Star.vue create mode 100644 components/rate/index.js create mode 100644 components/rate/style/index.js create mode 100644 components/rate/style/index.less create mode 100644 components/util/util.js create mode 100644 examples/rate.vue diff --git a/components/index.js b/components/index.js index e37bca7b2..c86f04856 100644 --- a/components/index.js +++ b/components/index.js @@ -3,6 +3,7 @@ import './checkbox/style' import './icon/style' import './radio/style' import './grid/style' +import './rate/style' export { default as Button } from './button' @@ -13,3 +14,5 @@ export { default as Icon } from './icon' export { default as Radio } from './radio' export { default as Grid } from './grid' + +export { default as Rate } from './rate' diff --git a/components/rate/Rate.vue b/components/rate/Rate.vue new file mode 100644 index 000000000..ee6f9276b --- /dev/null +++ b/components/rate/Rate.vue @@ -0,0 +1,119 @@ + + + diff --git a/components/rate/Star.vue b/components/rate/Star.vue new file mode 100644 index 000000000..3c4ec3d30 --- /dev/null +++ b/components/rate/Star.vue @@ -0,0 +1,52 @@ + + diff --git a/components/rate/index.js b/components/rate/index.js new file mode 100644 index 000000000..0c1d021f2 --- /dev/null +++ b/components/rate/index.js @@ -0,0 +1,3 @@ +import Rate from './Rate'; + +export default Rate; diff --git a/components/rate/style/index.js b/components/rate/style/index.js new file mode 100644 index 000000000..3a3ab0de5 --- /dev/null +++ b/components/rate/style/index.js @@ -0,0 +1,2 @@ +import '../../style/index.less'; +import './index.less'; diff --git a/components/rate/style/index.less b/components/rate/style/index.less new file mode 100644 index 000000000..e22dbbd0d --- /dev/null +++ b/components/rate/style/index.less @@ -0,0 +1,73 @@ +@import "../../style/themes/default"; +@import "../../style/mixins/index"; + +@rate-prefix-cls: ~"@{ant-prefix}-rate"; + +.@{rate-prefix-cls} { + margin: 0; + padding: 0; + list-style: none; + font-size: 20px; + display: inline-block; + vertical-align: middle; + + &-disabled &-star { + cursor: not-allowed; + &:hover { + transform: scale(1); + } + } + + &-star { + margin: 0; + padding: 0; + display: inline-block; + margin-right: 8px; + position: relative; + transition: all .3s; + color: @rate-star-bg; + cursor: pointer; + + &-first, + &-second { + user-select: none; + transition: all .3s; + } + + &: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, 20%); + } + } + + &-text { + margin-left: 8px; + vertical-align: middle; + display: inline-block; + font-size: @font-size-base; + } +} diff --git a/components/util/util.js b/components/util/util.js new file mode 100644 index 000000000..6d0070323 --- /dev/null +++ b/components/util/util.js @@ -0,0 +1,40 @@ +function getScroll(w, top) { + let ret = top ? w.pageYOffset : w.pageXOffset; + const method = top ? 'scrollTop' : 'scrollLeft'; + if (typeof ret !== 'number') { + const d = w.document; + // ie6,7,8 standard mode + ret = d.documentElement[method]; + if (typeof ret !== 'number') { + // quirks mode + ret = d.body[method]; + } + } + return ret; +} + +function getClientPosition(elem) { + let box; + let x; + let y; + const doc = elem.ownerDocument; + const body = doc.body; + const docElem = doc && doc.documentElement; + box = elem.getBoundingClientRect(); + x = box.left; + y = box.top; + x -= docElem.clientLeft || body.clientLeft || 0; + y -= docElem.clientTop || body.clientTop || 0; + return { + left: x, + top: y, + }; +} + +export const getOffsetLeft = (el) => { + const pos = getClientPosition(el); + const doc = el.ownerDocument; + const w = doc.defaultView || doc.parentWindow; + pos.left += getScroll(w); + return pos.left; +} diff --git a/examples/index.js b/examples/index.js index 4a4d55917..39fea342b 100644 --- a/examples/index.js +++ b/examples/index.js @@ -4,6 +4,7 @@ import Button from './button.vue' import Radio from './radio.vue' import Grid from './grid.vue' // import Dialog from './dialog.vue' +import Rate from './rate.vue' import './index.less' new Vue({ el: '#app', @@ -13,6 +14,7 @@ new Vue({ + `, components: { @@ -21,5 +23,6 @@ new Vue({ Checkbox, Grid, Radio, + Rate, }, }) diff --git a/examples/rate.vue b/examples/rate.vue new file mode 100644 index 000000000..b6f624e7f --- /dev/null +++ b/examples/rate.vue @@ -0,0 +1,63 @@ + +