Skip to content

Commit e85fd2d

Browse files
authored
Comments polish - Day 1, v2 (codesandbox#3801)
* sidebar comment shadow yay * fix shadow on comments top bar * remove redundant borders * fix overlap on safari * missed a spot! * disable body overflow with drag handle
1 parent 7f42c84 commit e85fd2d

File tree

3 files changed

+33
-18
lines changed

3 files changed

+33
-18
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,10 @@ export const AddComment: React.FC = () => {
2828
paddingX={2}
2929
paddingY={4}
3030
css={css({
31+
zIndex: 2,
3132
borderTop: '1px solid',
3233
borderColor: 'sideBar.border',
33-
// super custom shadow, TODO: check if this works in other themes
34-
boxShadow:
35-
'0px -4px 8px rgba(21, 21, 21, 0.4), 0px -8px 8px rgba(21, 21, 21, 0.4)',
34+
boxShadow: theme => `0px -32px 32px ${theme.colors.dialog.background}`,
3635
})}
3736
>
3837
<form onSubmit={onSubmit}>

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@ export const Reply = ({ reply }: ReplyProps) => {
1818
const [editing, setEditing] = useState(false);
1919

2020
return (
21-
<>
21+
<Element
22+
as="li"
23+
css={{
24+
'&:last-child > div': {
25+
border: 'none',
26+
},
27+
}}
28+
>
2229
<Element key={id} marginLeft={4} marginRight={2} paddingTop={6}>
2330
<Stack align="flex-start" justify="space-between" marginBottom={4}>
2431
<AvatarBlock comment={reply} />
@@ -70,7 +77,7 @@ export const Reply = ({ reply }: ReplyProps) => {
7077
/>
7178
)}
7279
</Element>
73-
</>
80+
</Element>
7481
);
7582
};
7683

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

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
Text,
99
Textarea,
1010
} from '@codesandbox/components';
11+
import { createGlobalStyle } from 'styled-components';
1112
import css from '@styled-system/css';
1213
import { CommentFragment } from 'app/graphql/types';
1314
import { useOvermind } from 'app/overmind';
@@ -127,23 +128,20 @@ export const Dialog: React.FC = () => {
127128
<DragHandle onPan={onDragHandlerPan}>
128129
<DialogHeader comment={comment} hasShadow={scrollTop > 0} />
129130
</DragHandle>
130-
<Stack
131-
direction="vertical"
132-
css={{ overflow: 'auto' }}
133-
ref={listRef}
134-
>
131+
<Element as="div" css={{ overflow: 'auto' }} ref={listRef}>
135132
<CommentBody
136133
comment={comment}
137134
editing={editing}
138135
setEditing={setEditing}
136+
hasReplies={replies.length}
139137
/>
140138
{replies.length ? (
141139
<Replies
142140
replies={replies}
143141
repliesRenderedCallback={() => setRepliesRendered(true)}
144142
/>
145143
) : null}
146-
</Stack>
144+
</Element>
147145
<AddReply
148146
comment={comment}
149147
onSubmit={() => {
@@ -226,15 +224,25 @@ const DialogAddComment: React.FC<{
226224
);
227225
};
228226

227+
/** When the dialog is dragged outside the window
228+
* It creates a scrollbar. We want to disable overflow
229+
* when the drag handle is DOM
230+
*/
231+
232+
const GlobalStyles = createGlobalStyle`
233+
body { overflow: hidden; }
234+
`;
235+
229236
const DragHandle: React.FC<{
230237
onPan: (deltaX: number, deltaY: number) => void;
231238
}> = ({ onPan, children }) => (
232239
<motion.div
233240
onPan={(_, info) => {
234241
onPan(info.delta.x, info.delta.y);
235242
}}
236-
style={{ cursor: 'move' }}
243+
style={{ cursor: 'move', zIndex: 2 }}
237244
>
245+
<GlobalStyles />
238246
{children}
239247
</motion.div>
240248
);
@@ -252,7 +260,6 @@ const DialogHeader = ({ comment, hasShadow }) => {
252260
paddingRight={2}
253261
marginBottom={2}
254262
css={css({
255-
zIndex: 2,
256263
boxShadow: theme =>
257264
hasShadow
258265
? `0px 32px 32px ${theme.colors.dialog.background}`
@@ -293,7 +300,7 @@ const DialogHeader = ({ comment, hasShadow }) => {
293300
);
294301
};
295302

296-
const CommentBody = ({ comment, editing, setEditing }) => {
303+
const CommentBody = ({ comment, editing, setEditing, hasReplies }) => {
297304
const { state, actions } = useOvermind();
298305

299306
return (
@@ -333,7 +340,7 @@ const CommentBody = ({ comment, editing, setEditing }) => {
333340
marginX={4}
334341
paddingBottom={6}
335342
css={css({
336-
borderBottom: '1px solid',
343+
borderBottom: hasReplies ? '1px solid' : 'none',
337344
borderColor: 'sideBar.border',
338345
})}
339346
>
@@ -371,7 +378,7 @@ const Replies = ({ replies, repliesRenderedCallback }) => {
371378
}, [repliesLoaded, isAnimating, repliesRenderedCallback]);
372379

373380
return (
374-
<motion.div
381+
<motion.ul
375382
initial={{ height: repliesLoaded ? 0 : SKELETON_HEIGHT }}
376383
animate={{ height: 'auto' }}
377384
transition={{
@@ -381,6 +388,7 @@ const Replies = ({ replies, repliesRenderedCallback }) => {
381388
style={{
382389
minHeight: repliesLoaded ? 0 : SKELETON_HEIGHT,
383390
overflow: 'visible',
391+
paddingLeft: 0,
384392
}}
385393
onAnimationComplete={() => setAnimating(false)}
386394
>
@@ -393,7 +401,7 @@ const Replies = ({ replies, repliesRenderedCallback }) => {
393401
) : (
394402
<SkeletonReply />
395403
)}
396-
</motion.div>
404+
</motion.ul>
397405
);
398406
};
399407

@@ -418,7 +426,8 @@ const AddReply = ({ comment, ...props }) => {
418426
border: 'none',
419427
borderTop: '1px solid',
420428
borderColor: 'sideBar.border',
421-
paddingX: 4,
429+
borderRadius: 0,
430+
padding: 4,
422431
})}
423432
value={value}
424433
onChange={e => setValue(e.target.value)}

0 commit comments

Comments
 (0)