antd#Comment JavaScript Examples

The following examples show how to use antd#Comment. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: editor.jsx    From virtuoso-design-system with MIT License 8 votes vote down vote up
render() {
    const { comments, submitting, value } = this.state;

    return (
      <>
        {comments.length > 0 && <CommentList comments={comments} />}
        <Comment
          avatar={
            <Avatar
              src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png"
              alt="Han Solo"
            />
          }
          content={
            <Editor
              onChange={this.handleChange}
              onSubmit={this.handleSubmit}
              submitting={submitting}
              value={value}
            />
          }
        />
      </>
    );
  }
Example #2
Source File: list.jsx    From virtuoso-design-system with MIT License 6 votes vote down vote up
storiesOf('antd/comment', module).add('list', () => 
  <List
    className="comment-list"
    header={`${data.length} replies`}
    itemLayout="horizontal"
    dataSource={data}
    renderItem={item => (
      <li>
        <Comment
          actions={item.actions}
          author={item.author}
          avatar={item.avatar}
          content={item.content}
          datetime={item.datetime}
        />
      </li>
    )}
  />,
  { docs: { page: () => (<><h1 id="enus">en-US</h1>
<p>Displaying a series of comments using the <code>antd</code> List Component.</p></>) } });
Example #3
Source File: nested.jsx    From virtuoso-design-system with MIT License 6 votes vote down vote up
ExampleComment = ({ children }) => (
  <Comment
    actions={[<span key="comment-nested-reply-to">Reply to</span>]}
    author={<a>Han Solo</a>}
    avatar={
      <Avatar
        src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png"
        alt="Han Solo"
      />
    }
    content={
      <p>
        We supply a series of design principles, practical patterns and high quality design
        resources (Sketch and Axure).
      </p>
    }
  >
    {children}
  </Comment>
)
Example #4
Source File: Comment.jsx    From ResoBin with MIT License 6 votes vote down vote up
StyledComment = styled(Comment)`
  .ant-comment-avatar {
    cursor: default;
  }

  .ant-comment-actions {
    display: flex;
    align-items: center;
    height: 1.75rem;
  }
`
Example #5
Source File: basic.jsx    From virtuoso-design-system with MIT License 5 votes vote down vote up
Demo = () => {
  const [likes, setLikes] = useState(0);
  const [dislikes, setDislikes] = useState(0);
  const [action, setAction] = useState(null);

  const like = () => {
    setLikes(1);
    setDislikes(0);
    setAction('liked');
  };

  const dislike = () => {
    setLikes(0);
    setDislikes(1);
    setAction('disliked');
  };

  const actions = [
    <Tooltip key="comment-basic-like" title="Like">
      <span onClick={like}>
        {createElement(action === 'liked' ? LikeFilled : LikeOutlined)}
        <span className="comment-action">{likes}</span>
      </span>
    </Tooltip>,
    <Tooltip key="comment-basic-dislike" title="Dislike">
      <span onClick={dislike}>
        {React.createElement(action === 'disliked' ? DislikeFilled : DislikeOutlined)}
        <span className="comment-action">{dislikes}</span>
      </span>
    </Tooltip>,
    <span key="comment-basic-reply-to">Reply to</span>,
  ];

  return (
    <Comment
      actions={actions}
      author={<a>Han Solo</a>}
      avatar={
        <Avatar
          src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png"
          alt="Han Solo"
        />
      }
      content={
        <p>
          We supply a series of design principles, practical patterns and high quality design
          resources (Sketch and Axure), to help people create their product prototypes beautifully
          and efficiently.
        </p>
      }
      datetime={
        <Tooltip title={moment().format('YYYY-MM-DD HH:mm:ss')}>
          <span>{moment().fromNow()}</span>
        </Tooltip>
      }
    />
  );
}
Example #6
Source File: editor.jsx    From virtuoso-design-system with MIT License 5 votes vote down vote up
CommentList = ({ comments }) => (
  <List
    dataSource={comments}
    header={`${comments.length} ${comments.length > 1 ? 'replies' : 'reply'}`}
    itemLayout="horizontal"
    renderItem={props => <Comment {...props} />}
  />
)
Example #7
Source File: CommentSection.js    From react-portal with MIT License 4 votes vote down vote up
CommentSection = ({ details }) => {
	const [replyingTo, setReplyingTo] = useState(null);
	const myRef = useRef();
	const formRef = useRef();
	const [refresh, setRefresh] = useState(false);
	const [comments, setComments] = useState([]);
	const [user, setUser] = useState({});
	const userData = getRole();

	const [form] = Form.useForm();

	const handleReply = id => {
		myRef.current.scrollIntoView({ behavior: "smooth" });
		formRef.current.focus();
		setReplyingTo(id);
	};

	useEffect(() => {
		details &&
			(async () => {
				try {
					const res = await getCommentService(details._id);
					console.log(res.data);
					setUser((await getUserService(userData.id)).data);
					if (!res.error && res.message === "success") {
						setComments(res.data);
					}
				} catch (err) {
					console.log(err);
				}
			})();
		//eslint-disable-next-line
	}, [refresh, details]);

	const onSubmit = async val => {
		let data = { text: val.comment };
		try {
			const res = await addCommentService(details._id, data);
			if (!res.error && res.message === "success") {
				form.setFieldsValue({ comment: "" });
				setRefresh(!refresh);
			}
		} catch (err) {
			_notification("error", "Error", err.message);
		}
	};

	return (
		<div className="comment-section-container">
			{comments?.map((comment, id) => (
				<div key={id}>
					<Comment
						className={`comment-container ${
							comment.userData[0].role === "lead"
								? "comment-lead"
								: comment.userData[0].role === "head"
								? "comment-head"
								: "comment-member"
						}`}
						actions={[
							<span
								className="reply-button"
								key="comment-nested-reply-to"
								onClick={() => handleReply(comment._id)}
							>
								<GoReply style={{ marginRight: ".25rem" }} />
								Reply{" "}
							</span>
						]}
						author={<h3>{comment.userData[0].name}</h3>}
						avatar={
							<Avatar
								src={comment.userData[0].image}
								alt={comment.userData[0].name}
							/>
						}
						content={<p>{comment.text}</p>}
					/>
					{/* {comment.replies.length > 0
						? comment.replies.map((reply, id) => (
								<Comment
									key={id}
									className={`reply-container ${
										reply.role === "lead"
											? "comment-lead"
											: reply.role === "head"
											? "comment-head"
											: "comment-member"
									}`}
									author={<h3>{reply.author}</h3>}
									avatar={
										<Avatar
											src={reply.image}
											alt={reply.image}
										/>
									}
									content={<p>{reply.comment}</p>}
								/>
						  ))
						: null} */}
				</div>
			))}

			<Comment
				style={{ padding: "0 .5rem" }}
				avatar={<Avatar src={user && user.image} alt={userData.name} />}
				content={
					<Form form={form} onFinish={onSubmit}>
						{replyingTo ? (
							<>
								<Row
									style={{
										border: "1px solid #D9D9D9",
										borderRadius: "3px",
										marginBottom: ".5rem",
										padding: ".25rem .75rem ",
										color: "#BFBFBF",
										justifyContent: "space-between"
									}}
								>
									<Col>
										<Row>
											<p>
												replying to :{" "}
												<span
													style={{ color: "#262626" }}
												>
													{
														comments.filter(
															comment =>
																comment._id ===
																replyingTo
														)[0].text
													}
												</span>
											</p>
										</Row>
										<Row>
											<p>
												author :{" "}
												<span
													style={{ color: "#262626" }}
												>
													{
														comments.filter(
															comment =>
																comment.id ===
																replyingTo
														)[0].userData[0].name
													}
												</span>
											</p>
										</Row>
									</Col>
									<Col
										style={{
											display: "flex",
											alignItems: "center",
											color: "#262626",
											padding: ".5rem"
										}}
										onClick={() => setReplyingTo(null)}
									>
										<AiOutlineClose
											style={{ cursor: "pointer" }}
										/>
									</Col>
								</Row>
							</>
						) : null}
						<Form.Item name="comment">
							<TextArea
								ref={formRef}
								type="text"
								placeholder="Enter your comment ..."
								rows={3}
							/>
						</Form.Item>
						<Form.Item>
							<Button
								ref={myRef}
								htmlType="submit"
								// loading={submitting}
								type="primary"
							>
								Add Comment
							</Button>
						</Form.Item>
					</Form>
				}
			/>
		</div>
	);
}
Example #8
Source File: index.js    From gobench with Apache License 2.0 4 votes vote down vote up
render() {
    const { likes, dislikes, action } = this.state

    const actions = [
      <span key="comment-basic-like">
        <Tooltip title="Like">
          {action === 'liked' && <LikeFilled onClick={this.like} />}
          {action !== 'liked' && <LikeOutlined onClick={this.like} />}
        </Tooltip>
        <span style={{ paddingLeft: 8, cursor: 'auto' }}>{likes}</span>
      </span>,
      <span key="comment-basic-dislike">
        <Tooltip title="Dislike">
          {action === 'disliked' && <LikeFilled onClick={this.dislike} />}
          {action !== 'disliked' && <LikeOutlined onClick={this.dislike} />}
        </Tooltip>
        <span style={{ paddingLeft: 8, cursor: 'auto' }}>{dislikes}</span>
      </span>,
      <span key="comment-basic-reply-to">Reply to</span>,
    ]

    return (
      <div>
        <h5 className="mb-3">
          <strong>Basic</strong>
        </h5>
        <div className="mb-5">
          <Comment
            actions={actions}
            author={<a>Han Solo</a>}
            avatar={
              <Avatar
                src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png"
                alt="Han Solo"
              />
            }
            content={
              <p>
                We supply a series of design principles, practical patterns and high quality design
                resources (Sketch and Axure), to help people create their product prototypes
                beautifully and efficiently.
              </p>
            }
            datetime={
              <Tooltip title={moment().format('YYYY-MM-DD HH:mm:ss')}>
                <span>{moment().fromNow()}</span>
              </Tooltip>
            }
          />
        </div>
        <h5 className="mb-3">
          <strong>Nested</strong>
        </h5>
        <div className="mb-5">
          <Comment
            actions={actions}
            author={<a>Han Solo</a>}
            avatar={
              <Avatar
                src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png"
                alt="Han Solo"
              />
            }
            content={
              <p>
                We supply a series of design principles, practical patterns and high quality design
                resources (Sketch and Axure), to help people create their product prototypes
                beautifully and efficiently.
              </p>
            }
            datetime={
              <Tooltip title={moment().format('YYYY-MM-DD HH:mm:ss')}>
                <span>{moment().fromNow()}</span>
              </Tooltip>
            }
          >
            <Comment
              actions={actions}
              author={<a>Han Solo</a>}
              avatar={
                <Avatar
                  src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png"
                  alt="Han Solo"
                />
              }
              content={
                <p>
                  We supply a series of design principles, practical patterns and high quality
                  design resources (Sketch and Axure), to help people create their product
                  prototypes beautifully and efficiently.
                </p>
              }
              datetime={
                <Tooltip title={moment().format('YYYY-MM-DD HH:mm:ss')}>
                  <span>{moment().fromNow()}</span>
                </Tooltip>
              }
            />
          </Comment>
        </div>
      </div>
    )
  }