Skip to content

feat: update comment #2366

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 2 commits 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
29 changes: 15 additions & 14 deletions components/comment/index.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { inject } from 'vue';
import PropsTypes from '../_util/vue-types';
import { getComponentFromProp, getListeners } from '../_util/props-util';
import { getComponent } from '../_util/props-util';
import { ConfigConsumerProps } from '../config-provider';
import Base from '../base';
export const CommentProps = {
actions: PropsTypes.array,
/** The element to display as the comment author. */
Expand All @@ -19,8 +19,10 @@ export const CommentProps = {
const Comment = {
name: 'AComment',
props: CommentProps,
inject: {
configProvider: { default: () => ConfigConsumerProps },
setup() {
return {
configProvider: inject('configProvider', ConfigConsumerProps),
};
},
methods: {
getAction(actions) {
Expand All @@ -41,11 +43,11 @@ const Comment = {
const getPrefixCls = this.configProvider.getPrefixCls;
const prefixCls = getPrefixCls('comment', customizePrefixCls);

const actions = getComponentFromProp(this, 'actions');
const author = getComponentFromProp(this, 'author');
const avatar = getComponentFromProp(this, 'avatar');
const content = getComponentFromProp(this, 'content');
const datetime = getComponentFromProp(this, 'datetime');
const actions = getComponent(this, 'actions');
const author = getComponent(this, 'author');
const avatar = getComponent(this, 'avatar');
const content = getComponent(this, 'content');
const datetime = getComponent(this, 'datetime');

const avatarDom = (
<div class={`${prefixCls}-avatar`}>
Expand Down Expand Up @@ -79,9 +81,9 @@ const Comment = {
{contentDom}
</div>
);
const children = this.$slots.default;
const children = this.$slots.default && this.$slots.default();
return (
<div class={prefixCls} {...{ on: getListeners(this) }}>
<div class={prefixCls}>
{comment}
{children ? this.renderNested(prefixCls, children) : null}
</div>
Expand All @@ -90,8 +92,7 @@ const Comment = {
};

/* istanbul ignore next */
Comment.install = function(Vue) {
Vue.use(Base);
Vue.component(Comment.name, Comment);
Comment.install = function(app) {
app.component(Comment.name, Comment);
};
export default Comment;
2 changes: 2 additions & 0 deletions examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import '@babel/polyfill';
import { createApp } from 'vue';
import App from './App.vue';
import Button from 'ant-design-vue/button';
import Comment from 'ant-design-vue/comment';
import Drawer from 'ant-design-vue/drawer';
import Affix from 'ant-design-vue/affix';
import Alert from 'ant-design-vue/alert';
Expand All @@ -12,6 +13,7 @@ import 'ant-design-vue/style.js';

createApp(App)
.use(Button)
.use(Comment)
.use(ConfigProvider)
.use(Drawer)
.use(Affix)
Expand Down