Skip to content

Commit 07cf318

Browse files
committed
style multi comments
1 parent ef2e18b commit 07cf318

File tree

2 files changed

+110
-22
lines changed

2 files changed

+110
-22
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import React from 'react';
2+
import { formatDistanceStrict } from 'date-fns';
3+
import { css } from '@styled-system/css';
4+
import { useOvermind } from 'app/overmind';
5+
import { Text } from '@codesandbox/components';
6+
7+
export const MultiComment = ({ x, y, ids }) => {
8+
const {
9+
state: {
10+
comments: { currentComments },
11+
},
12+
actions: { comments },
13+
} = useOvermind();
14+
15+
const list = css({
16+
position: 'fixed',
17+
left: x - 10,
18+
top: y + 20,
19+
backgroundColor: 'sideBar.background',
20+
border: '1px solid',
21+
borderColor: 'sideBar.border',
22+
paddingY: 2,
23+
paddingX: 0,
24+
zIndex: 999999999999999,
25+
listStyle: 'none',
26+
borderRadius: 4,
27+
28+
'&::before': {
29+
content: "''",
30+
display: 'block',
31+
position: 'absolute',
32+
left: '7px',
33+
width: 0,
34+
height: 0,
35+
borderStyle: 'solid',
36+
top: '-11px',
37+
borderColor: 'transparent',
38+
borderBottomColor: 'sideBar.border',
39+
40+
borderWidth: '11px',
41+
borderTopWidth: 0,
42+
},
43+
44+
'&::after': {
45+
content: "''",
46+
display: 'block',
47+
position: 'absolute',
48+
left: 2,
49+
width: 0,
50+
height: 0,
51+
borderStyle: 'solid',
52+
top: '-10px',
53+
borderColor: 'transparent',
54+
borderBottomColor: 'sideBar.background',
55+
borderWidth: '10px',
56+
borderTopWidth: 0,
57+
},
58+
});
59+
60+
const item = css({
61+
border: 'none',
62+
backgroundColor: 'transparent',
63+
padding: 2,
64+
width: 200,
65+
cursor: 'pointer',
66+
position: 'relative',
67+
'&:hover': {
68+
color: 'list.hoverForeground',
69+
backgroundColor: 'list.hoverBackground',
70+
},
71+
});
72+
73+
return (
74+
<ul css={list}>
75+
{ids.map(id => (
76+
<li key={id}>
77+
<button
78+
type="button"
79+
// @ts-ignore
80+
onClick={() => comments.selectComment(id)}
81+
css={item}
82+
>
83+
<Text
84+
size={2}
85+
weight="bold"
86+
paddingRight={2}
87+
css={css({
88+
color: 'sideBar.foreground',
89+
})}
90+
>
91+
{currentComments.find(c => c.id === id).user.username}
92+
</Text>
93+
<Text size={2} variant="muted">
94+
{formatDistanceStrict(
95+
new Date(currentComments.find(c => c.id === id).insertedAt),
96+
new Date(),
97+
{
98+
addSuffix: true,
99+
}
100+
)}
101+
</Text>
102+
</button>
103+
</li>
104+
))}
105+
</ul>
106+
);
107+
};

packages/app/src/app/pages/Sandbox/Editor/Workspace/screens/Comments/index.tsx

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { CommentsFilterOption } from '@codesandbox/common/lib/types';
2+
23
import {
34
Icon,
45
List,
@@ -14,6 +15,7 @@ import React from 'react';
1415
import { AddComment } from './AddComment';
1516
import { Comment } from './Comment';
1617
import { CommentDialog } from './Dialog';
18+
import { MultiComment } from './components/MultiComment';
1719

1820
export const Comments: React.FC = () => {
1921
const {
@@ -138,28 +140,7 @@ export const Comments: React.FC = () => {
138140
{currentComments.length ? null : <Empty />}
139141
<AddComment />
140142
{currentCommentId && <CommentDialog />}
141-
{multiCommentsSelector && (
142-
<ul
143-
style={{
144-
position: 'fixed',
145-
left: multiCommentsSelector.x,
146-
top: multiCommentsSelector.y,
147-
backgroundColor: 'red',
148-
zIndex: 999999999999999,
149-
}}
150-
>
151-
{multiCommentsSelector.ids.map(id => (
152-
<li key={id}>
153-
<button
154-
type="button"
155-
onClick={() => commentsActions.selectComment(id)}
156-
>
157-
{id}
158-
</button>
159-
</li>
160-
))}
161-
</ul>
162-
)}
143+
{multiCommentsSelector && <MultiComment {...multiCommentsSelector} />}
163144
</Stack>
164145
);
165146
};

0 commit comments

Comments
 (0)