From 728e26548fca7702e65626367a8cce61dee04859 Mon Sep 17 00:00:00 2001
From: tangjinzhou <415800467@qq.com>
Date: Fri, 12 Jan 2018 16:10:41 +0800
Subject: [PATCH] add popover
---
components/_util/BaseMixin.js | 16 ++
components/_util/props-util.js | 22 ++
components/align/Align.vue | 3 +-
components/align/demo/simple.vue | 4 +-
components/badge/ScrollNumber.vue | 4 +-
components/checkbox/Checkbox.vue | 2 +-
components/checkbox/Group.vue | 2 +-
components/index.js | 2 +
components/input/Input.vue | 2 +-
components/input/TextArea.vue | 2 +-
components/menu/src/Menu.vue | 14 +-
components/menu/src/MenuItem.vue | 37 ++-
components/menu/src/MenuMixin.js | 2 +-
components/menu/src/SubMenu.vue | 52 ++---
components/menu/src/SubPopupMenu.vue | 14 +-
components/popconfirm/index.vue | 0
components/popconfirm/index.zh-CN.md | 34 +++
components/popconfirm/style/index.js | 5 +
.../popover/demo/arrow-point-at-center.vue | 42 ++++
components/popover/demo/basic.vue | 27 +++
components/popover/demo/control.vue | 39 ++++
components/popover/demo/index.vue | 30 +++
components/popover/demo/placement.vue | 184 +++++++++++++++
components/popover/demo/triggerType.vue | 45 ++++
components/popover/index.vue | 67 ++++++
components/popover/index.zh-CN.md | 27 +++
components/popover/style/index.js | 2 +
components/popover/style/index.less | 221 ++++++++++++++++++
components/radio/Radio.vue | 2 +-
components/rate/Rate.vue | 2 +-
components/style.js | 1 +
components/tabs/Tabs.vue | 2 +-
components/tabs/index.vue | 2 +-
components/tooltip/abstractTooltipProps.js | 19 ++
components/tooltip/index.zh-CN.md | 45 ++++
components/tooltip/src/Tooltip.vue | 17 +-
components/tooltip/tooltip.vue | 30 +--
components/trigger/Popup.vue | 16 +-
components/trigger/PopupInner.vue | 18 +-
components/trigger/index.vue | 15 +-
contributors.md | 2 +-
41 files changed, 923 insertions(+), 149 deletions(-)
create mode 100644 components/_util/BaseMixin.js
create mode 100644 components/_util/props-util.js
create mode 100644 components/popconfirm/index.vue
create mode 100644 components/popconfirm/index.zh-CN.md
create mode 100644 components/popconfirm/style/index.js
create mode 100644 components/popover/demo/arrow-point-at-center.vue
create mode 100644 components/popover/demo/basic.vue
create mode 100644 components/popover/demo/control.vue
create mode 100644 components/popover/demo/index.vue
create mode 100644 components/popover/demo/placement.vue
create mode 100644 components/popover/demo/triggerType.vue
create mode 100644 components/popover/index.vue
create mode 100644 components/popover/index.zh-CN.md
create mode 100644 components/popover/style/index.js
create mode 100644 components/popover/style/index.less
create mode 100644 components/tooltip/abstractTooltipProps.js
create mode 100644 components/tooltip/index.zh-CN.md
diff --git a/components/_util/BaseMixin.js b/components/_util/BaseMixin.js
new file mode 100644
index 000000000..66d6bfa94
--- /dev/null
+++ b/components/_util/BaseMixin.js
@@ -0,0 +1,16 @@
+export default {
+ methods: {
+ setState (state, callback) {
+ Object.assign(this.$data, state)
+ this.$nextTick(() => {
+ callback && callback()
+ })
+ },
+ __emit () { // 直接调用listeners,底层组件不需要vueTool记录events
+ const args = [].slice.call(arguments, 0)
+ if (args.length && this.$listeners[args[0]]) {
+ this.$listeners[args[0]](...args.slice(1))
+ }
+ },
+ },
+}
diff --git a/components/_util/props-util.js b/components/_util/props-util.js
new file mode 100644
index 000000000..d98722fc2
--- /dev/null
+++ b/components/_util/props-util.js
@@ -0,0 +1,22 @@
+const hasProp = (instance, prop) => {
+ const $options = instance.$options || {}
+ const propsData = $options.propsData || {}
+ return prop in propsData
+}
+const filterProps = (props, propsData = {}) => {
+ const res = {}
+ Object.keys(props).forEach((k) => {
+ if (k in propsData || props[k] !== undefined) {
+ res[k] = props[k]
+ }
+ })
+ return res
+}
+
+const getOptionProps = (instance) => {
+ const { $options = {}, $props = {}} = instance
+ return filterProps($props, $options.propsData)
+}
+
+export { hasProp, filterProps, getOptionProps }
+export default hasProp
diff --git a/components/align/Align.vue b/components/align/Align.vue
index 36f1d9e6a..f4cdf0bb1 100644
--- a/components/align/Align.vue
+++ b/components/align/Align.vue
@@ -102,7 +102,8 @@ export default {
const props = this.$props
if (!props.disabled) {
const source = this.$el
- this.$emit('align', source, align(source, props.target(), props.align))
+ // this.$emit('align', source, align(source, props.target(), props.align))
+ this.$listeners.align && this.$listeners.align(source, align(source, props.target(), props.align))
}
},
},
diff --git a/components/align/demo/simple.vue b/components/align/demo/simple.vue
index 84b11f40f..7c5c991e2 100644
--- a/components/align/demo/simple.vue
+++ b/components/align/demo/simple.vue
@@ -1,9 +1,9 @@
diff --git a/components/popover/demo/basic.vue b/components/popover/demo/basic.vue
new file mode 100644
index 000000000..20cb76fd3
--- /dev/null
+++ b/components/popover/demo/basic.vue
@@ -0,0 +1,27 @@
+
+
+
+## 基本
+最简单的用法,浮层的大小由内容区域决定。
+
+
+
+
+
+ Hover me
+
+
+
+
+
diff --git a/components/popover/demo/control.vue b/components/popover/demo/control.vue
new file mode 100644
index 000000000..8d8fa9b47
--- /dev/null
+++ b/components/popover/demo/control.vue
@@ -0,0 +1,39 @@
+
+
+
+ ## 从浮层内关闭
+ 使用 `visible` 属性控制浮层显示。
+
+
+
+ Close
+
+ Click me
+
+
+
+
+
diff --git a/components/popover/demo/index.vue b/components/popover/demo/index.vue
new file mode 100644
index 000000000..d6c50e639
--- /dev/null
+++ b/components/popover/demo/index.vue
@@ -0,0 +1,30 @@
+
+
+
Basic
+
+
ArrowCenter
+
+
Control
+
+
Placement
+
+
TriggerType
+
+
+
+
diff --git a/components/popover/demo/placement.vue b/components/popover/demo/placement.vue
new file mode 100644
index 000000000..2c80b16c6
--- /dev/null
+++ b/components/popover/demo/placement.vue
@@ -0,0 +1,184 @@
+
+
+
+## 位置
+位置有 12 个方向。
+
+
+
+
+
+
+
+ Title
+
+ TL
+
+
+
+
+
+
+ Title
+
+ Top
+
+
+
+
+
+
+ Title
+
+ TR
+
+
+
+
+
+
+
+
+ Title
+
+ LT
+
+
+
+
+
+
+ Title
+
+ Left
+
+
+
+
+
+
+ Title
+
+ LB
+
+
+
+
+
+
+
+
+ Title
+
+ RT
+
+
+
+
+
+
+ Title
+
+ Right
+
+
+
+
+
+
+ Title
+
+ RB
+
+
+
+
+
+
+
+
+ Title
+
+ BL
+
+
+
+
+
+
+ Title
+
+ Bottom
+
+
+
+
+
+
+ Title
+
+ BR
+
+
+
+
+
+
+
diff --git a/components/popover/demo/triggerType.vue b/components/popover/demo/triggerType.vue
new file mode 100644
index 000000000..bbf14fb98
--- /dev/null
+++ b/components/popover/demo/triggerType.vue
@@ -0,0 +1,45 @@
+
+
+
+## 三种触发方式
+鼠标移入、聚集、点击。
+
+
+
+
+
+ Hover me
+
+
+
+
+
+ Focus me
+
+
+
+
+
+ Click me
+
+
+
+
+
diff --git a/components/popover/index.vue b/components/popover/index.vue
new file mode 100644
index 000000000..da31a1806
--- /dev/null
+++ b/components/popover/index.vue
@@ -0,0 +1,67 @@
+
diff --git a/components/popover/index.zh-CN.md b/components/popover/index.zh-CN.md
new file mode 100644
index 000000000..986b670c5
--- /dev/null
+++ b/components/popover/index.zh-CN.md
@@ -0,0 +1,27 @@
+---
+category: Components
+subtitle: 气泡卡片
+type: Data Display
+title: Popover
+---
+
+点击/鼠标移入元素,弹出气泡式的卡片浮层。
+
+## 何时使用
+
+当目标元素有进一步的描述和相关操作时,可以收纳到卡片中,根据用户的操作行为进行展现。
+
+和 `Tooltip` 的区别是,用户可以对浮层上的元素进行操作,因此它可以承载更复杂的内容,比如链接或按钮等。
+
+## API
+
+| 参数 | 说明 | 类型 | 默认值 |
+| --- | --- | --- | --- |
+| content | 卡片内容 | string\|function\|slot | 无 |
+| title | 卡片标题 | string\|function\|slot | 无 |
+
+更多属性请参考 [Tooltip](/components/tooltip/#API)。
+
+## 注意
+
+请确保 `Popover` 的子元素能接受 `mouseenter`、`mouseleave`、`focus`、`click` 事件。
diff --git a/components/popover/style/index.js b/components/popover/style/index.js
new file mode 100644
index 000000000..cf31ed80f
--- /dev/null
+++ b/components/popover/style/index.js
@@ -0,0 +1,2 @@
+import '../../style/index.less'
+import './index.less'
diff --git a/components/popover/style/index.less b/components/popover/style/index.less
new file mode 100644
index 000000000..227d2bc5a
--- /dev/null
+++ b/components/popover/style/index.less
@@ -0,0 +1,221 @@
+@import "../../style/themes/default";
+@import "../../style/mixins/index";
+
+@popover-prefix-cls: ~"@{ant-prefix}-popover";
+
+.@{popover-prefix-cls} {
+ position: absolute;
+ top: 0;
+ left: 0;
+ z-index: @zindex-popover;
+ cursor: auto;
+ user-select: text;
+ white-space: normal;
+ font-size: @font-size-base;
+ line-height: @line-height-base;
+ font-weight: normal;
+ text-align: left;
+
+ &:after {
+ content: "";
+ position: absolute;
+ background: rgba(255, 255, 255, 0.01);
+ }
+
+ &-hidden {
+ display: none;
+ }
+
+ // Offset the popover to account for the popover arrow
+ &-placement-top,
+ &-placement-topLeft,
+ &-placement-topRight {
+ padding-bottom: @popover-distance;
+ }
+
+ &-placement-right,
+ &-placement-rightTop,
+ &-placement-rightBottom {
+ padding-left: @popover-distance;
+ }
+
+ &-placement-bottom,
+ &-placement-bottomLeft,
+ &-placement-bottomRight {
+ padding-top: @popover-distance;
+ }
+
+ &-placement-left,
+ &-placement-leftTop,
+ &-placement-leftBottom {
+ padding-right: @popover-distance;
+ }
+
+ &-inner {
+ background-color: @popover-bg;
+ background-clip: padding-box;
+ border-radius: @border-radius-base;
+ box-shadow: @box-shadow-base;
+ }
+
+ &-title {
+ min-width: @popover-min-width;
+ margin: 0; // reset heading margin
+ padding: 8px 16px;
+ min-height: 32px;
+ border-bottom: 1px solid @border-color-split;
+ color: @popover-color;
+ font-weight: 500;
+ }
+
+ &-inner-content {
+ padding: 8px 16px;
+ color: @popover-color;
+ }
+
+ &-message {
+ padding: 8px 0 16px;
+ font-size: @font-size-base;
+ color: @popover-color;
+ > .@{iconfont-css-prefix} {
+ color: @warning-color;
+ line-height: 17px;
+ position: absolute;
+ }
+ &-title {
+ padding-left: 20px;
+ }
+ }
+
+ &-buttons {
+ text-align: right;
+ margin-bottom: 8px;
+ button {
+ margin-left: 8px;
+ }
+ }
+
+ // Arrows
+ // .popover-arrow is outer, .popover-arrow:after is inner
+
+ &-arrow {
+ &,
+ &:after {
+ position: absolute;
+ display: block;
+ width: 0;
+ height: 0;
+ border-color: transparent;
+ border-style: solid;
+ }
+ }
+
+ &-arrow {
+ border-width: @popover-arrow-outer-width;
+ }
+
+ &-arrow:after {
+ border-width: @popover-arrow-width;
+ content: "";
+ }
+
+ &-placement-top > &-content > &-arrow,
+ &-placement-topLeft > &-content > &-arrow,
+ &-placement-topRight > &-content > &-arrow {
+ border-bottom-width: 0;
+ border-top-color: @popover-arrow-outer-color;
+ bottom: @popover-distance - @popover-arrow-outer-width;
+ &:after {
+ content: " ";
+ bottom: 1px;
+ margin-left: -@popover-arrow-width;
+ border-bottom-width: 0;
+ border-top-color: @popover-arrow-color;
+ }
+ }
+ &-placement-top > &-content > &-arrow {
+ left: 50%;
+ margin-left: -@popover-arrow-outer-width;
+ }
+ &-placement-topLeft > &-content > &-arrow {
+ left: 16px;
+ }
+ &-placement-topRight > &-content > &-arrow {
+ right: 16px;
+ }
+
+ &-placement-right > &-content > &-arrow,
+ &-placement-rightTop > &-content > &-arrow,
+ &-placement-rightBottom > &-content > &-arrow {
+ left: @popover-distance - @popover-arrow-outer-width;
+ border-left-width: 0;
+ border-right-color: @popover-arrow-outer-color;
+ &:after {
+ content: " ";
+ left: 1px;
+ bottom: -@popover-arrow-width;
+ border-left-width: 0;
+ border-right-color: @popover-arrow-color;
+ }
+ }
+ &-placement-right > &-content > &-arrow {
+ top: 50%;
+ margin-top: -@popover-arrow-outer-width;
+ }
+ &-placement-rightTop > &-content > &-arrow {
+ top: 12px;
+ }
+ &-placement-rightBottom > &-content > &-arrow {
+ bottom: 12px;
+ }
+
+ &-placement-bottom > &-content > &-arrow,
+ &-placement-bottomLeft > &-content > &-arrow,
+ &-placement-bottomRight > &-content > &-arrow {
+ border-top-width: 0;
+ border-bottom-color: @popover-arrow-outer-color;
+ top: @popover-distance - @popover-arrow-outer-width;
+ &:after {
+ content: " ";
+ top: 1px;
+ margin-left: -@popover-arrow-width;
+ border-top-width: 0;
+ border-bottom-color: @popover-arrow-color;
+ }
+ }
+ &-placement-bottom > &-content > &-arrow {
+ left: 50%;
+ margin-left: -@popover-arrow-outer-width;
+ }
+ &-placement-bottomLeft > &-content > &-arrow {
+ left: 16px;
+ }
+ &-placement-bottomRight > &-content > &-arrow {
+ right: 16px;
+ }
+
+ &-placement-left > &-content > &-arrow,
+ &-placement-leftTop > &-content > &-arrow,
+ &-placement-leftBottom > &-content > &-arrow {
+ right: @popover-distance - @popover-arrow-outer-width;
+ border-right-width: 0;
+ border-left-color: @popover-arrow-outer-color;
+ &:after {
+ content: " ";
+ right: 1px;
+ border-right-width: 0;
+ border-left-color: @popover-arrow-color;
+ bottom: -@popover-arrow-width;
+ }
+ }
+ &-placement-left > &-content > &-arrow {
+ top: 50%;
+ margin-top: -@popover-arrow-outer-width;
+ }
+ &-placement-leftTop > &-content > &-arrow {
+ top: 12px;
+ }
+ &-placement-leftBottom > &-content > &-arrow {
+ bottom: 12px;
+ }
+}
diff --git a/components/radio/Radio.vue b/components/radio/Radio.vue
index 60e4b6bfe..616f3c765 100644
--- a/components/radio/Radio.vue
+++ b/components/radio/Radio.vue
@@ -13,7 +13,7 @@