Skip to content

feat: update anchor #2373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions components/anchor/Anchor.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { inject } from 'vue';
import PropTypes from '../_util/vue-types';
import classNames from 'classnames';
import addEventListener from '../vc-util/Dom/addEventListener';
Expand Down Expand Up @@ -98,8 +99,10 @@ export default {
showInkInFixed: false,
getContainer: getDefaultContainer,
}),
inject: {
configProvider: { default: () => ConfigConsumerProps },
setup() {
return {
configProvider: inject('configProvider', ConfigConsumerProps),
};
},
data() {
this.links = [];
Expand Down Expand Up @@ -294,7 +297,7 @@ export default {
<div class={`${prefixCls}-ink`}>
<span class={inkClass} ref="inkNode" />
</div>
{$slots.default}
{$slots.default && $slots.default()}
</div>
</div>
);
Expand Down
17 changes: 10 additions & 7 deletions components/anchor/AnchorLink.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { inject } from 'vue';
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 { ConfigConsumerProps } from '../config-provider';

Expand All @@ -15,10 +16,12 @@ export default {
props: initDefaultProps(AnchorLinkProps, {
href: '#',
}),
inject: {
antAnchor: { default: () => ({}) },
antAnchorContext: { default: () => ({}) },
configProvider: { default: () => ConfigConsumerProps },
setup() {
return {
antAnchor: inject('antAnchor', {}),
antAnchorContext: inject('antAnchorContext', {}),
configProvider: inject('configProvider', ConfigConsumerProps),
};
},
watch: {
href(val, oldVal) {
Expand Down Expand Up @@ -53,7 +56,7 @@ export default {
const getPrefixCls = this.configProvider.getPrefixCls;
const prefixCls = getPrefixCls('anchor', customizePrefixCls);

const title = getComponentFromProp(this, 'title');
const title = getComponent(this, 'title');
const active = this.antAnchor.$data.activeLink === href;
const wrapperClassName = classNames(`${prefixCls}-link`, {
[`${prefixCls}-link-active`]: active,
Expand All @@ -72,7 +75,7 @@ export default {
>
{title}
</a>
{$slots.default}
{$slots.default && $slots.default()}
</div>
);
},
Expand Down
8 changes: 3 additions & 5 deletions components/anchor/index.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import Anchor from './Anchor';
import AnchorLink from './AnchorLink';
import Base from '../base';

Anchor.Link = AnchorLink;

/* istanbul ignore next */
Anchor.install = function(Vue) {
Vue.use(Base);
Vue.component(Anchor.name, Anchor);
Vue.component(Anchor.Link.name, Anchor.Link);
Anchor.install = function(app) {
app.component(Anchor.name, Anchor);
app.component(Anchor.Link.name, Anchor.Link);
};
export { AnchorProps } from './Anchor';
export { AnchorLinkProps } from './AnchorLink';
Expand Down
2 changes: 2 additions & 0 deletions examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Drawer from 'ant-design-vue/drawer';
import Affix from 'ant-design-vue/affix';
import Alert from 'ant-design-vue/alert';
import Divider from 'ant-design-vue/divider';
import Anchor from 'ant-design-vue/anchor';
import ConfigProvider from 'ant-design-vue/config-provider';
import Result from 'ant-design-vue/result';
import Spin from 'ant-design-vue/spin';
Expand All @@ -23,6 +24,7 @@ createApp(App)
.use(Alert)
.use(Divider)
.use(Result)
.use(Anchor)
.use(Spin)
.use(Empty)
.use(Timeline)
Expand Down