Skip to content
Snippets Groups Projects
Commit 27c7f57a authored by Yannis Barlas's avatar Yannis Barlas Committed by chris
Browse files

add on click post function to comment box

parent 13604b39
No related branches found
No related tags found
1 merge request!161Connect ui
import React from 'react'
// import { lorem } from 'faker'
import CommentBox from '../wax-prosemirror-components/src/components/comments/CommentBox'
export const Base = () => <CommentBox comment="fkljslfj" />
export default {
component: CommentBox,
title: 'Test/Comment Box',
}
...@@ -11,6 +11,8 @@ const commentData = range(5).map(() => ({ ...@@ -11,6 +11,8 @@ const commentData = range(5).map(() => ({
timestamp: '3 days ago', timestamp: '3 days ago',
})); }));
const onClickPost = data => console.log(data);
export const Base = () => { export const Base = () => {
const [active, setActive] = useState(false); const [active, setActive] = useState(false);
...@@ -21,6 +23,7 @@ export const Base = () => { ...@@ -21,6 +23,7 @@ export const Base = () => {
commentData={commentData} commentData={commentData}
commentId="4" commentId="4"
onClickBox={id => setActive(true)} onClickBox={id => setActive(true)}
onClickPost={onClickPost}
onClickResolve={id => console.log('resolve id', id)} onClickResolve={id => console.log('resolve id', id)}
/> />
</Demo> </Demo>
...@@ -42,6 +45,7 @@ export const Active = () => ( ...@@ -42,6 +45,7 @@ export const Active = () => (
commentData={commentData} commentData={commentData}
commentId="4" commentId="4"
onClickBox={id => console.log('set active', id)} onClickBox={id => console.log('set active', id)}
onClickPost={onClickPost}
onClickResolve={id => console.log('resolve id', id)} onClickResolve={id => console.log('resolve id', id)}
/> />
); );
......
import React from 'react' import React from 'react';
import PropTypes from 'prop-types' import PropTypes from 'prop-types';
import styled, { css } from 'styled-components' import styled, { css } from 'styled-components';
// import { th } from '../_helpers' // import { th } from '../_helpers'
import CommentItemList from './CommentItemList' import CommentItemList from './CommentItemList';
import CommentReply from './CommentReply' import CommentReply from './CommentReply';
const inactive = css` const inactive = css`
background: #e2e2e2; background: #e2e2e2;
...@@ -16,7 +16,7 @@ const inactive = css` ...@@ -16,7 +16,7 @@ const inactive = css`
/* background: white; */ /* background: white; */
box-shadow: 0 0 1px 2px gray; box-shadow: 0 0 1px 2px gray;
} }
` `;
const Wrapper = styled.div` const Wrapper = styled.div`
background: white; background: white;
...@@ -28,13 +28,13 @@ const Wrapper = styled.div` ...@@ -28,13 +28,13 @@ const Wrapper = styled.div`
/* padding: 8px 0; */ /* padding: 8px 0; */
${props => !props.active && inactive} ${props => !props.active && inactive}
` `;
const Head = styled.div` const Head = styled.div`
display: flex; display: flex;
justify-content: flex-end; justify-content: flex-end;
padding: 8px 16px 0; padding: 8px 16px 0;
` `;
const Resolve = styled.button` const Resolve = styled.button`
align-self: flex-end; align-self: flex-end;
...@@ -44,11 +44,11 @@ const Resolve = styled.button` ...@@ -44,11 +44,11 @@ const Resolve = styled.button`
&:hover { &:hover {
background: blue; background: blue;
} }
` `;
const StyledReply = styled(CommentReply)` const StyledReply = styled(CommentReply)`
border-top: 1px solid gray; border-top: 1px solid gray;
` `;
const CommentBox = props => { const CommentBox = props => {
const { const {
...@@ -57,14 +57,15 @@ const CommentBox = props => { ...@@ -57,14 +57,15 @@ const CommentBox = props => {
commentId, commentId,
commentData, commentData,
onClickBox, onClickBox,
onClickPost,
onClickResolve, onClickResolve,
} = props } = props;
// send signal to make this comment active // send signal to make this comment active
const onClickWrapper = () => { const onClickWrapper = () => {
if (active) return if (active) return;
onClickBox(commentId) onClickBox(commentId);
} };
return ( return (
<Wrapper active={active} className={className} onClick={onClickWrapper}> <Wrapper active={active} className={className} onClick={onClickWrapper}>
...@@ -76,10 +77,10 @@ const CommentBox = props => { ...@@ -76,10 +77,10 @@ const CommentBox = props => {
<CommentItemList active={active} data={commentData} /> <CommentItemList active={active} data={commentData} />
{active && <StyledReply />} {active && <StyledReply onClickPost={onClickPost} />}
</Wrapper> </Wrapper>
) );
} };
CommentBox.propTypes = { CommentBox.propTypes = {
/** Whether this is the current active comment */ /** Whether this is the current active comment */
...@@ -100,13 +101,15 @@ CommentBox.propTypes = { ...@@ -100,13 +101,15 @@ CommentBox.propTypes = {
* Will only run if comment is not active already. * Will only run if comment is not active already.
*/ */
onClickBox: PropTypes.func.isRequired, onClickBox: PropTypes.func.isRequired,
/** Function to run when "post" button is clicked to send reply */
onClickPost: PropTypes.func.isRequired,
/** Function to run when "resolve" button is clicked */ /** Function to run when "resolve" button is clicked */
onClickResolve: PropTypes.func.isRequired, onClickResolve: PropTypes.func.isRequired,
} };
CommentBox.defaultProps = { CommentBox.defaultProps = {
active: false, active: false,
commentData: [], commentData: [],
} };
export default CommentBox export default CommentBox;
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment