feat: update anchor (#2373)

pull/2371/head
xrkffgg 2020-06-08 15:45:14 +08:00 committed by GitHub
parent 4ef17f8144
commit d591e4b298
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 15 deletions

View File

@ -1,3 +1,4 @@
import { inject } from 'vue';
import PropTypes from '../_util/vue-types'; import PropTypes from '../_util/vue-types';
import classNames from 'classnames'; import classNames from 'classnames';
import addEventListener from '../vc-util/Dom/addEventListener'; import addEventListener from '../vc-util/Dom/addEventListener';
@ -98,8 +99,10 @@ export default {
showInkInFixed: false, showInkInFixed: false,
getContainer: getDefaultContainer, getContainer: getDefaultContainer,
}), }),
inject: { setup() {
configProvider: { default: () => ConfigConsumerProps }, return {
configProvider: inject('configProvider', ConfigConsumerProps),
};
}, },
data() { data() {
this.links = []; this.links = [];
@ -294,7 +297,7 @@ export default {
<div class={`${prefixCls}-ink`}> <div class={`${prefixCls}-ink`}>
<span class={inkClass} ref="inkNode" /> <span class={inkClass} ref="inkNode" />
</div> </div>
{$slots.default} {$slots.default && $slots.default()}
</div> </div>
</div> </div>
); );

View File

@ -1,5 +1,6 @@
import { inject } from 'vue';
import PropTypes from '../_util/vue-types'; import PropTypes from '../_util/vue-types';
import { initDefaultProps, getComponentFromProp } from '../_util/props-util'; import { initDefaultProps, getComponent } from '../_util/props-util';
import classNames from 'classnames'; import classNames from 'classnames';
import { ConfigConsumerProps } from '../config-provider'; import { ConfigConsumerProps } from '../config-provider';
@ -15,10 +16,12 @@ export default {
props: initDefaultProps(AnchorLinkProps, { props: initDefaultProps(AnchorLinkProps, {
href: '#', href: '#',
}), }),
inject: { setup() {
antAnchor: { default: () => ({}) }, return {
antAnchorContext: { default: () => ({}) }, antAnchor: inject('antAnchor', {}),
configProvider: { default: () => ConfigConsumerProps }, antAnchorContext: inject('antAnchorContext', {}),
configProvider: inject('configProvider', ConfigConsumerProps),
};
}, },
watch: { watch: {
href(val, oldVal) { href(val, oldVal) {
@ -53,7 +56,7 @@ export default {
const getPrefixCls = this.configProvider.getPrefixCls; const getPrefixCls = this.configProvider.getPrefixCls;
const prefixCls = getPrefixCls('anchor', customizePrefixCls); const prefixCls = getPrefixCls('anchor', customizePrefixCls);
const title = getComponentFromProp(this, 'title'); const title = getComponent(this, 'title');
const active = this.antAnchor.$data.activeLink === href; const active = this.antAnchor.$data.activeLink === href;
const wrapperClassName = classNames(`${prefixCls}-link`, { const wrapperClassName = classNames(`${prefixCls}-link`, {
[`${prefixCls}-link-active`]: active, [`${prefixCls}-link-active`]: active,
@ -72,7 +75,7 @@ export default {
> >
{title} {title}
</a> </a>
{$slots.default} {$slots.default && $slots.default()}
</div> </div>
); );
}, },

View File

@ -1,14 +1,12 @@
import Anchor from './Anchor'; import Anchor from './Anchor';
import AnchorLink from './AnchorLink'; import AnchorLink from './AnchorLink';
import Base from '../base';
Anchor.Link = AnchorLink; Anchor.Link = AnchorLink;
/* istanbul ignore next */ /* istanbul ignore next */
Anchor.install = function(Vue) { Anchor.install = function(app) {
Vue.use(Base); app.component(Anchor.name, Anchor);
Vue.component(Anchor.name, Anchor); app.component(Anchor.Link.name, Anchor.Link);
Vue.component(Anchor.Link.name, Anchor.Link);
}; };
export { AnchorProps } from './Anchor'; export { AnchorProps } from './Anchor';
export { AnchorLinkProps } from './AnchorLink'; export { AnchorLinkProps } from './AnchorLink';

View File

@ -8,6 +8,7 @@ import Drawer from 'ant-design-vue/drawer';
import Affix from 'ant-design-vue/affix'; import Affix from 'ant-design-vue/affix';
import Alert from 'ant-design-vue/alert'; import Alert from 'ant-design-vue/alert';
import Divider from 'ant-design-vue/divider'; import Divider from 'ant-design-vue/divider';
import Anchor from 'ant-design-vue/anchor';
import ConfigProvider from 'ant-design-vue/config-provider'; import ConfigProvider from 'ant-design-vue/config-provider';
import Result from 'ant-design-vue/result'; import Result from 'ant-design-vue/result';
import Spin from 'ant-design-vue/spin'; import Spin from 'ant-design-vue/spin';
@ -25,6 +26,7 @@ createApp(App)
.use(Alert) .use(Alert)
.use(Divider) .use(Divider)
.use(Result) .use(Result)
.use(Anchor)
.use(Spin) .use(Spin)
.use(Empty) .use(Empty)
.use(Timeline) .use(Timeline)