1
1
import { hues } from '@sanity/color'
2
2
import { type CurrentUser } from '@sanity/types'
3
- import { Box , Card , Flex , Stack , Text , TextSkeleton , useClickOutside } from '@sanity/ui'
3
+ import {
4
+ type AvatarSize ,
5
+ Box ,
6
+ Card ,
7
+ Flex ,
8
+ Stack ,
9
+ Text ,
10
+ TextSkeleton ,
11
+ useClickOutside ,
12
+ } from '@sanity/ui'
13
+ // eslint-disable-next-line camelcase
14
+ import { getTheme_v2 } from '@sanity/ui/theme'
4
15
import { useCallback , useEffect , useMemo , useRef , useState } from 'react'
5
16
import {
6
17
type RelativeTimeOptions ,
@@ -26,7 +37,7 @@ import {
26
37
type CommentsUIMode ,
27
38
type CommentUpdatePayload ,
28
39
} from '../../types'
29
- import { AVATAR_HEIGHT , CommentsAvatar , SpacerAvatar } from '../avatars'
40
+ import { CommentsAvatar , SpacerAvatar } from '../avatars'
30
41
import { FLEX_GAP } from '../constants'
31
42
import { CommentMessageSerializer } from '../pte'
32
43
import { CommentInput , type CommentInputHandle } from '../pte/comment-input'
@@ -53,6 +64,14 @@ const TimeText = styled(Text)(({theme}) => {
53
64
`
54
65
} )
55
66
67
+ const HeaderFlex = styled ( Flex ) < { $size : AvatarSize } > ( ( props ) => {
68
+ const theme = getTheme_v2 ( props . theme )
69
+
70
+ return css `
71
+ min-height : ${ theme . avatar . sizes [ props . $size ] ?. size } px;
72
+ `
73
+ } )
74
+
56
75
const IntentText = styled ( Text ) ( ( { theme} ) => {
57
76
const isDark = theme . sanity . color . dark
58
77
const fg = hues . gray [ isDark ? 200 : 800 ] . hex
@@ -72,9 +91,13 @@ const InnerStack = styled(Stack)`
72
91
}
73
92
`
74
93
75
- const ErrorFlex = styled ( Flex ) `
76
- min-height: ${ AVATAR_HEIGHT } px;
77
- `
94
+ const ErrorFlex = styled ( Flex ) < { $size : AvatarSize } > ( ( props ) => {
95
+ const theme = getTheme_v2 ( props . theme )
96
+
97
+ return css `
98
+ min-height : ${ theme . avatar . sizes [ props . $size ] ?. size } px;
99
+ `
100
+ } )
78
101
79
102
const RetryCardButton = styled ( Card ) `
80
103
// Add not on hover
@@ -122,6 +145,7 @@ const RootStack = styled(Stack)(({theme}) => {
122
145
} )
123
146
124
147
interface CommentsListItemLayoutProps {
148
+ avatarSize ?: AvatarSize
125
149
canDelete ?: boolean
126
150
canEdit ?: boolean
127
151
comment : CommentDocument
@@ -141,12 +165,14 @@ interface CommentsListItemLayoutProps {
141
165
onReactionSelect ?: ( id : string , reaction : CommentReactionOption ) => void
142
166
onStatusChange ?: ( id : string , status : CommentStatus ) => void
143
167
readOnly ?: boolean
168
+ withAvatar ?: boolean
144
169
}
145
170
146
171
const RELATIVE_TIME_OPTIONS : RelativeTimeOptions = { useTemporalPhrase : true }
147
172
148
173
export function CommentsListItemLayout ( props : CommentsListItemLayoutProps ) {
149
174
const {
175
+ avatarSize = 1 ,
150
176
canDelete,
151
177
canEdit,
152
178
comment,
@@ -166,6 +192,7 @@ export function CommentsListItemLayout(props: CommentsListItemLayoutProps) {
166
192
onReactionSelect,
167
193
onStatusChange,
168
194
readOnly,
195
+ withAvatar = true ,
169
196
} = props
170
197
const { _createdAt, authorId, message, _id, lastEditedAt} = comment
171
198
const [ user ] = useUser ( authorId )
@@ -324,8 +351,8 @@ export function CommentsListItemLayout(props: CommentsListItemLayoutProps) {
324
351
space = { 4 }
325
352
>
326
353
< InnerStack space = { 1 } data-muted = { displayError } >
327
- < Flex align = "center" gap = { FLEX_GAP } flex = { 1 } >
328
- < CommentsAvatar user = { user } />
354
+ < HeaderFlex align = "center" gap = { FLEX_GAP } flex = { 1 } $size = { avatarSize } >
355
+ { withAvatar && < CommentsAvatar user = { user } size = { avatarSize } /> }
329
356
330
357
< Flex direction = "column" gap = { 2 } paddingY = { intent ? 2 : 0 } >
331
358
< Flex
@@ -397,11 +424,11 @@ export function CommentsListItemLayout(props: CommentsListItemLayoutProps) {
397
424
/>
398
425
</ ContextMenuBox >
399
426
) }
400
- </ Flex >
427
+ </ HeaderFlex >
401
428
402
429
{ isTextSelectionComment ( comment ) && Boolean ( comment ?. contentSnapshot ) && (
403
430
< Flex gap = { FLEX_GAP } marginBottom = { 3 } >
404
- < SpacerAvatar />
431
+ { withAvatar && < SpacerAvatar $size = { avatarSize } /> }
405
432
406
433
< CommentsListItemReferencedValue
407
434
hasReferencedValue = { hasReferencedValue }
@@ -412,7 +439,7 @@ export function CommentsListItemLayout(props: CommentsListItemLayoutProps) {
412
439
413
440
{ isEditing && (
414
441
< Flex align = "flex-start" gap = { 2 } >
415
- < SpacerAvatar />
442
+ { withAvatar && < SpacerAvatar $size = { avatarSize } /> }
416
443
417
444
< Stack flex = { 1 } >
418
445
< CommentInput
@@ -435,15 +462,15 @@ export function CommentsListItemLayout(props: CommentsListItemLayoutProps) {
435
462
436
463
{ ! isEditing && (
437
464
< Flex gap = { FLEX_GAP } >
438
- < SpacerAvatar />
465
+ { withAvatar && < SpacerAvatar $size = { avatarSize } /> }
439
466
440
467
< CommentMessageSerializer blocks = { message } />
441
468
</ Flex >
442
469
) }
443
470
444
471
{ hasReactions && (
445
472
< Flex gap = { FLEX_GAP } marginTop = { 2 } >
446
- < SpacerAvatar />
473
+ { withAvatar && < SpacerAvatar $size = { avatarSize } /> }
447
474
448
475
< Box onClick = { stopPropagation } >
449
476
< CommentReactionsBar
@@ -459,8 +486,8 @@ export function CommentsListItemLayout(props: CommentsListItemLayoutProps) {
459
486
</ InnerStack >
460
487
461
488
{ displayError && (
462
- < ErrorFlex gap = { FLEX_GAP } >
463
- < SpacerAvatar />
489
+ < ErrorFlex gap = { FLEX_GAP } $size = { avatarSize } >
490
+ { withAvatar && < SpacerAvatar $size = { avatarSize } /> }
464
491
465
492
< Flex align = "center" gap = { 1 } flex = { 1 } >
466
493
< Text muted size = { 1 } >
0 commit comments