Skip to content

Commit

Permalink
feat: custom component support tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
tangjinzhou committed May 14, 2020
1 parent 529f81c commit 741897b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 23 deletions.
9 changes: 9 additions & 0 deletions components/_util/props-util.js
Expand Up @@ -198,6 +198,15 @@ export function getEvents(child) {
return { ...events };
}

// 获取 xxx.native 或者 原生标签 事件
export function getDataEvents(child) {
let events = {};
if (child.data && child.data.on) {
events = child.data.on;
}
return { ...events };
}

// use getListeners instead this.$listeners
// https://github.com/vueComponent/ant-design-vue/issues/1705
export function getListeners(context) {
Expand Down
3 changes: 2 additions & 1 deletion components/_util/vnode.js
Expand Up @@ -67,7 +67,7 @@ export function cloneElement(n, nodeProps = {}, deep) {
// !(node.fnOptions && node.fnOptions.functional),
// `can not use cloneElement for functional component (${node.fnOptions && node.fnOptions.name})`,
// );
const { props = {}, key, on = {}, children, directives = [] } = nodeProps;
const { props = {}, key, on = {}, nativeOn = {}, children, directives = [] } = nodeProps;
const data = node.data || {};
let cls = {};
let style = {};
Expand Down Expand Up @@ -134,6 +134,7 @@ export function cloneElement(n, nodeProps = {}, deep) {
}
node.data.on = { ...(node.data.on || {}), ...on };
}
node.data.on = { ...(node.data.on || {}), ...nativeOn };

if (key !== undefined) {
node.key = key;
Expand Down
2 changes: 1 addition & 1 deletion components/form/__tests__/__snapshots__/demo.test.js.snap
Expand Up @@ -381,7 +381,7 @@ exports[`renders ./antdv-demo/docs/form/demo/register.vue correctly 1`] = `
<div class="ant-row ant-form-item">
<div class="ant-col ant-col-xs-24 ant-col-sm-8 ant-form-item-label"><label for="register_nickname" title="" class="ant-form-item-required"><span>
Nickname&nbsp;
<i aria-label="icon: question-circle-o" tabindex="-1" class="anticon anticon-question-circle-o"><svg viewBox="64 64 896 896" data-icon="question-circle" width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"></path><path d="M623.6 316.7C593.6 290.4 554 276 512 276s-81.6 14.5-111.6 40.7C369.2 344 352 380.7 352 420v7.6c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8V420c0-44.1 43.1-80 96-80s96 35.9 96 80c0 31.1-22 59.6-56.1 72.7-21.2 8.1-39.2 22.3-52.1 40.9-13.1 19-19.9 41.8-19.9 64.9V620c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8v-22.7a48.3 48.3 0 0 1 30.9-44.8c59-22.7 97.1-74.7 97.1-132.5.1-39.3-17.1-76-48.3-103.3zM472 732a40 40 0 1 0 80 0 40 40 0 1 0-80 0z"></path></svg></i></span></label></div>
<i aria-label="icon: question-circle-o" class="anticon anticon-question-circle-o"><svg viewBox="64 64 896 896" data-icon="question-circle" width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"></path><path d="M623.6 316.7C593.6 290.4 554 276 512 276s-81.6 14.5-111.6 40.7C369.2 344 352 380.7 352 420v7.6c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8V420c0-44.1 43.1-80 96-80s96 35.9 96 80c0 31.1-22 59.6-56.1 72.7-21.2 8.1-39.2 22.3-52.1 40.9-13.1 19-19.9 41.8-19.9 64.9V620c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8v-22.7a48.3 48.3 0 0 1 30.9-44.8c59-22.7 97.1-74.7 97.1-132.5.1-39.3-17.1-76-48.3-103.3zM472 732a40 40 0 1 0 80 0 40 40 0 1 0-80 0z"></path></svg></i></span></label></div>
<div class="ant-col ant-col-xs-24 ant-col-sm-16 ant-form-item-control-wrapper">
<div class="ant-form-item-control"><span class="ant-form-item-children"><input type="text" data-__meta="[object Object]" data-__field="[object Object]" id="register_nickname" class="ant-input"></span>
<!---->
Expand Down
2 changes: 1 addition & 1 deletion components/input/__tests__/__snapshots__/demo.test.js.snap
Expand Up @@ -71,7 +71,7 @@ exports[`renders ./antdv-demo/docs/input/demo/group.md correctly 1`] = `
exports[`renders ./antdv-demo/docs/input/demo/password-input.md correctly 1`] = `<span class="ant-input-affix-wrapper ant-input-password"><input placeholder="input password" type="password" class="ant-input"><span class="ant-input-suffix"><i aria-label="icon: eye-invisible" tabindex="-1" class="anticon anticon-eye-invisible ant-input-password-icon"><svg viewBox="64 64 896 896" data-icon="eye-invisible" width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><path d="M942.2 486.2Q889.47 375.11 816.7 305l-50.88 50.88C807.31 395.53 843.45 447.4 874.7 512 791.5 684.2 673.4 766 512 766q-72.67 0-133.87-22.38L323 798.75Q408 838 512 838q288.3 0 430.2-300.3a60.29 60.29 0 0 0 0-51.5zm-63.57-320.64L836 122.88a8 8 0 0 0-11.32 0L715.31 232.2Q624.86 186 512 186q-288.3 0-430.2 300.3a60.3 60.3 0 0 0 0 51.5q56.69 119.4 136.5 191.41L112.48 835a8 8 0 0 0 0 11.31L155.17 889a8 8 0 0 0 11.31 0l712.15-712.12a8 8 0 0 0 0-11.32zM149.3 512C232.6 339.8 350.7 258 512 258c54.54 0 104.13 9.36 149.12 28.39l-70.3 70.3a176 176 0 0 0-238.13 238.13l-83.42 83.42C223.1 637.49 183.3 582.28 149.3 512zm246.7 0a112.11 112.11 0 0 1 146.2-106.69L401.31 546.2A112 112 0 0 1 396 512z"></path><path d="M508 624c-3.46 0-6.87-.16-10.25-.47l-52.82 52.82a176.09 176.09 0 0 0 227.42-227.42l-52.82 52.82c.31 3.38.47 6.79.47 10.25a111.94 111.94 0 0 1-112 112z"></path></svg></i></span></span>`;
exports[`renders ./antdv-demo/docs/input/demo/presuffix.md correctly 1`] = `<div class="components-input-demo-presuffix"><span class="ant-input-affix-wrapper"><span class="ant-input-prefix"><i aria-label="icon: user" class="anticon anticon-user"><svg viewBox="64 64 896 896" data-icon="user" width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><path d="M858.5 763.6a374 374 0 0 0-80.6-119.5 375.63 375.63 0 0 0-119.5-80.6c-.4-.2-.8-.3-1.2-.5C719.5 518 760 444.7 760 362c0-137-111-248-248-248S264 225 264 362c0 82.7 40.5 156 102.8 201.1-.4.2-.8.3-1.2.5-44.8 18.9-85 46-119.5 80.6a375.63 375.63 0 0 0-80.6 119.5A371.7 371.7 0 0 0 136 901.8a8 8 0 0 0 8 8.2h60c4.4 0 7.9-3.5 8-7.8 2-77.2 33-149.5 87.8-204.3 56.7-56.7 132-87.9 212.2-87.9s155.5 31.2 212.2 87.9C779 752.7 810 825 812 902.2c.1 4.4 3.6 7.8 8 7.8h60a8 8 0 0 0 8-8.2c-1-47.8-10.9-94.3-29.5-138.2zM512 534c-45.9 0-89.1-17.9-121.6-50.4S340 407.9 340 362c0-45.9 17.9-89.1 50.4-121.6S466.1 190 512 190s89.1 17.9 121.6 50.4S684 316.1 684 362c0 45.9-17.9 89.1-50.4 121.6S557.9 534 512 534z"></path></svg></i></span><input placeholder="Basic usage" type="text" class="ant-input"><span class="ant-input-suffix"><i aria-label="icon: info-circle" tabindex="-1" class="anticon anticon-info-circle" style="color: rgba(0, 0, 0, 0.45);"><svg viewBox="64 64 896 896" data-icon="info-circle" width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"></path><path d="M464 336a48 48 0 1 0 96 0 48 48 0 1 0-96 0zm72 112h-48c-4.4 0-8 3.6-8 8v272c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8V456c0-4.4-3.6-8-8-8z"></path></svg></i></span></span> <br> <br> <span class="ant-input-affix-wrapper"><span class="ant-input-prefix">¥</span><input type="text" class="ant-input"><span class="ant-input-suffix">RMB</span></span></div>`;
exports[`renders ./antdv-demo/docs/input/demo/presuffix.md correctly 1`] = `<div class="components-input-demo-presuffix"><span class="ant-input-affix-wrapper"><span class="ant-input-prefix"><i aria-label="icon: user" class="anticon anticon-user"><svg viewBox="64 64 896 896" data-icon="user" width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><path d="M858.5 763.6a374 374 0 0 0-80.6-119.5 375.63 375.63 0 0 0-119.5-80.6c-.4-.2-.8-.3-1.2-.5C719.5 518 760 444.7 760 362c0-137-111-248-248-248S264 225 264 362c0 82.7 40.5 156 102.8 201.1-.4.2-.8.3-1.2.5-44.8 18.9-85 46-119.5 80.6a375.63 375.63 0 0 0-80.6 119.5A371.7 371.7 0 0 0 136 901.8a8 8 0 0 0 8 8.2h60c4.4 0 7.9-3.5 8-7.8 2-77.2 33-149.5 87.8-204.3 56.7-56.7 132-87.9 212.2-87.9s155.5 31.2 212.2 87.9C779 752.7 810 825 812 902.2c.1 4.4 3.6 7.8 8 7.8h60a8 8 0 0 0 8-8.2c-1-47.8-10.9-94.3-29.5-138.2zM512 534c-45.9 0-89.1-17.9-121.6-50.4S340 407.9 340 362c0-45.9 17.9-89.1 50.4-121.6S466.1 190 512 190s89.1 17.9 121.6 50.4S684 316.1 684 362c0 45.9-17.9 89.1-50.4 121.6S557.9 534 512 534z"></path></svg></i></span><input placeholder="Basic usage" type="text" class="ant-input"><span class="ant-input-suffix"><i aria-label="icon: info-circle" class="anticon anticon-info-circle" style="color: rgba(0, 0, 0, 0.45);"><svg viewBox="64 64 896 896" data-icon="info-circle" width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"></path><path d="M464 336a48 48 0 1 0 96 0 48 48 0 1 0-96 0zm72 112h-48c-4.4 0-8 3.6-8 8v272c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8V456c0-4.4-3.6-8-8-8z"></path></svg></i></span></span> <br> <br> <span class="ant-input-affix-wrapper"><span class="ant-input-prefix">¥</span><input type="text" class="ant-input"><span class="ant-input-suffix">RMB</span></span></div>`;
exports[`renders ./antdv-demo/docs/input/demo/search-input.md correctly 1`] = `<div><span class="ant-input-search ant-input-affix-wrapper" style="width: 200px;"><input placeholder="input search text" type="text" class="ant-input"><span class="ant-input-suffix"><i aria-label="icon: search" tabindex="-1" class="anticon anticon-search ant-input-search-icon"><svg viewBox="64 64 896 896" data-icon="search" width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><path d="M909.6 854.5L649.9 594.8C690.2 542.7 712 479 712 412c0-80.2-31.3-155.4-87.9-212.1-56.6-56.7-132-87.9-212.1-87.9s-155.5 31.3-212.1 87.9C143.2 256.5 112 331.8 112 412c0 80.1 31.3 155.5 87.9 212.1C256.5 680.8 331.8 712 412 712c67 0 130.6-21.8 182.7-62l259.7 259.6a8.2 8.2 0 0 0 11.6 0l43.6-43.5a8.2 8.2 0 0 0 0-11.6zM570.4 570.4C528 612.7 471.8 636 412 636s-116-23.3-158.4-65.6C211.3 528 188 471.8 188 412s23.3-116.1 65.6-158.4C296 211.3 352.2 188 412 188s116.1 23.2 158.4 65.6S636 352.2 636 412s-23.3 116.1-65.6 158.4z"></path></svg></i></span></span> <br><br> <span class="ant-input-search ant-input-search-enter-button ant-input-group-wrapper"><span class="ant-input-wrapper ant-input-group"><input placeholder="input search text" type="text" class="ant-input"><span class="ant-input-group-addon"><button type="button" class="ant-btn ant-btn-primary ant-input-search-button"><i aria-label="icon: search" class="anticon anticon-search"><svg viewBox="64 64 896 896" data-icon="search" width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><path d="M909.6 854.5L649.9 594.8C690.2 542.7 712 479 712 412c0-80.2-31.3-155.4-87.9-212.1-56.6-56.7-132-87.9-212.1-87.9s-155.5 31.3-212.1 87.9C143.2 256.5 112 331.8 112 412c0 80.1 31.3 155.5 87.9 212.1C256.5 680.8 331.8 712 412 712c67 0 130.6-21.8 182.7-62l259.7 259.6a8.2 8.2 0 0 0 11.6 0l43.6-43.5a8.2 8.2 0 0 0 0-11.6zM570.4 570.4C528 612.7 471.8 636 412 636s-116-23.3-158.4-65.6C211.3 528 188 471.8 188 412s23.3-116.1 65.6-158.4C296 211.3 352.2 188 412 188s116.1 23.2 158.4 65.6S636 352.2 636 412s-23.3 116.1-65.6 158.4z"></path></svg></i></button></span></span></span> <br><br> <span class="ant-input-search ant-input-search-enter-button ant-input-search-large ant-input-group-wrapper ant-input-group-wrapper-lg"><span class="ant-input-wrapper ant-input-group"><input placeholder="input search text" type="text" class="ant-input ant-input-lg"><span class="ant-input-group-addon"><button type="button" class="ant-btn ant-btn-primary ant-btn-lg ant-input-search-button"><span>Search</span></button></span></span></span> <br><br> <span class="ant-input-search ant-input-search-enter-button ant-input-search-large ant-input-group-wrapper ant-input-group-wrapper-lg"><span class="ant-input-wrapper ant-input-group"><input placeholder="input search text" type="text" class="ant-input ant-input-lg"><span class="ant-input-group-addon"><button type="button" class="ant-btn ant-btn-lg ant-input-search-button"><span>Custom</span></button></span></span></span></div>`;
Expand Down
40 changes: 20 additions & 20 deletions components/vc-trigger/Trigger.jsx
Expand Up @@ -5,7 +5,7 @@ import contains from '../vc-util/Dom/contains';
import {
hasProp,
getComponentFromProp,
getEvents,
getDataEvents,
filterEmpty,
getListeners,
} from '../_util/props-util';
Expand Down Expand Up @@ -595,48 +595,48 @@ export default {
warning(false, 'Trigger $slots.default.length > 1, just support only one default', true);
}
const child = children[0];
this.childOriginEvents = getEvents(child);
this.childOriginEvents = getDataEvents(child);
const newChildProps = {
props: {},
on: {},
nativeOn: {},
key: 'trigger',
};

if (this.isContextmenuToShow()) {
newChildProps.on.contextmenu = this.onContextmenu;
newChildProps.nativeOn.contextmenu = this.onContextmenu;
} else {
newChildProps.on.contextmenu = this.createTwoChains('contextmenu');
newChildProps.nativeOn.contextmenu = this.createTwoChains('contextmenu');
}

if (this.isClickToHide() || this.isClickToShow()) {
newChildProps.on.click = this.onClick;
newChildProps.on.mousedown = this.onMousedown;
newChildProps.on.touchstart = this.onTouchstart;
newChildProps.nativeOn.click = this.onClick;
newChildProps.nativeOn.mousedown = this.onMousedown;
newChildProps.nativeOn.touchstart = this.onTouchstart;
} else {
newChildProps.on.click = this.createTwoChains('click');
newChildProps.on.mousedown = this.createTwoChains('mousedown');
newChildProps.on.touchstart = this.createTwoChains('onTouchstart');
newChildProps.nativeOn.click = this.createTwoChains('click');
newChildProps.nativeOn.mousedown = this.createTwoChains('mousedown');
newChildProps.nativeOn.touchstart = this.createTwoChains('onTouchstart');
}
if (this.isMouseEnterToShow()) {
newChildProps.on.mouseenter = this.onMouseenter;
newChildProps.nativeOn.mouseenter = this.onMouseenter;
if (alignPoint) {
newChildProps.on.mousemove = this.onMouseMove;
newChildProps.nativeOn.mousemove = this.onMouseMove;
}
} else {
newChildProps.on.mouseenter = this.createTwoChains('mouseenter');
newChildProps.nativeOn.mouseenter = this.createTwoChains('mouseenter');
}
if (this.isMouseLeaveToHide()) {
newChildProps.on.mouseleave = this.onMouseleave;
newChildProps.nativeOn.mouseleave = this.onMouseleave;
} else {
newChildProps.on.mouseleave = this.createTwoChains('mouseleave');
newChildProps.nativeOn.mouseleave = this.createTwoChains('mouseleave');
}

if (this.isFocusToShow() || this.isBlurToHide()) {
newChildProps.on.focus = this.onFocus;
newChildProps.on.blur = this.onBlur;
newChildProps.nativeOn.focus = this.onFocus;
newChildProps.nativeOn.blur = this.onBlur;
} else {
newChildProps.on.focus = this.createTwoChains('focus');
newChildProps.on.blur = e => {
newChildProps.nativeOn.focus = this.createTwoChains('focus');
newChildProps.nativeOn.blur = e => {
if (e && (!e.relatedTarget || !contains(e.target, e.relatedTarget))) {
this.createTwoChains('blur')(e);
}
Expand Down

0 comments on commit 741897b

Please sign in to comment.