-
Notifications
You must be signed in to change notification settings - Fork 435
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
74b0c4e
commit 614f402
Showing
18 changed files
with
172 additions
and
92 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
packages/sanity/src/core/comments/components/avatars/CommentsAvatar.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React from 'react' | ||
import styled from 'styled-components' | ||
import {Avatar, AvatarProps} from '@sanity/ui' | ||
import {User} from '@sanity/types' | ||
|
||
const StyledAvatar = styled(Avatar)` | ||
svg > ellipse { | ||
stroke: transparent; | ||
} | ||
` | ||
|
||
const SYMBOLS = /[^\p{Alpha}\p{White_Space}]/gu | ||
const WHITESPACE = /\p{White_Space}+/u | ||
|
||
function nameToInitials(fullName: string) { | ||
const namesArray = fullName.replace(SYMBOLS, '').split(WHITESPACE) | ||
|
||
if (namesArray.length === 1) { | ||
return `${namesArray[0].charAt(0)}`.toUpperCase() | ||
} | ||
|
||
return `${namesArray[0].charAt(0)}${namesArray[namesArray.length - 1].charAt(0)}` | ||
} | ||
|
||
interface CommentsAvatarProps extends AvatarProps { | ||
user: User | undefined | null | ||
} | ||
|
||
export function CommentsAvatar(props: CommentsAvatarProps) { | ||
const {user: userProp, ...restProps} = props | ||
const user = userProp as User | ||
const initials = nameToInitials(user?.displayName || '') | ||
|
||
const avatar = user ? ( | ||
<StyledAvatar src={user?.imageUrl} initials={initials} {...restProps} /> | ||
) : ( | ||
<StyledAvatar {...restProps} /> | ||
) | ||
|
||
return avatar | ||
} |
13 changes: 13 additions & 0 deletions
13
packages/sanity/src/core/comments/components/avatars/SpacerAvatar.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react' | ||
|
||
const INLINE_STYLE: React.CSSProperties = { | ||
minWidth: 25, | ||
} | ||
|
||
/** | ||
* This component is used to as a spacer in situations where we want to align | ||
* components without avatars with components that have avatars. | ||
*/ | ||
export function SpacerAvatar() { | ||
return <div style={INLINE_STYLE} /> | ||
} |
2 changes: 2 additions & 0 deletions
2
packages/sanity/src/core/comments/components/avatars/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './CommentsAvatar' | ||
export * from './SpacerAvatar' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import {FlexProps} from '@sanity/ui' | ||
|
||
export const FLEX_GAP: FlexProps['gap'] = 3 | ||
export const AVATAR_SIZE = 25 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export * from './Serializer' | ||
export * from './CommentMessageSerializer' | ||
export * from './comment-input' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.