Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EuiComment] Revert username prop to accept a ReactNode #6071

Merged
merged 15 commits into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src-docs/src/views/comment/comment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default () => (
<EuiCommentList>
<EuiComment
username="janed"
timelineAvatarAriaLabel="Jane Doe"
event="added a comment"
actions={copyAction}
timestamp="on Jan 1, 2020"
Expand Down
4 changes: 3 additions & 1 deletion src-docs/src/views/comment/comment_actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export default () => {
<EuiCommentList aria-label="Actions">
<EuiComment
username="janed"
timelineAvatarAriaLabel="Jane Doe"
event="added a comment"
actions={customActions}
timestamp="on Jan 1, 2020"
Expand All @@ -129,7 +130,8 @@ export default () => {
</EuiComment>
<EuiComment
username="system"
timelineIcon="dot"
timelineAvatarAriaLabel="System"
timelineAvatar="dot"
event={
<>
pushed a new incident <EuiLink>malware detection</EuiLink>
Expand Down
18 changes: 12 additions & 6 deletions src-docs/src/views/comment/comment_avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import {

export default () => (
<EuiCommentList aria-label="An example with different timeline icons">
<EuiComment username="andred" event="is using a default avatar">
<EuiComment
username="andred"
timelineAvatarAriaLabel="Andre Diaz"
event="is using a default avatar"
>
<EuiText size="s">
<p>
The avatar initials is generated from the <EuiCode>username</EuiCode>{' '}
Expand All @@ -20,19 +24,21 @@ export default () => (

<EuiComment
username="system"
timelineIcon="dot"
timelineAvatarAriaLabel="System"
timelineAvatar="dot"
event={
<>
The <EuiCode>timelineIcon</EuiCode> is using a <EuiCode>dot</EuiCode>{' '}
icon.
The <EuiCode>timelineAvatar</EuiCode> is using a{' '}
<EuiCode>dot</EuiCode> icon.
</>
}
/>

<EuiComment
username="cat"
timelineAvatarAriaLabel="Beatiful cat"
event="is using a custom avatar"
timelineIcon={
timelineAvatar={
<EuiAvatar
name="cat"
imageUrl="https://source.unsplash.com/64x64/?cat"
Expand All @@ -41,7 +47,7 @@ export default () => (
>
<EuiText size="s">
<p>
The <EuiCode>timelineIcon</EuiCode> is using a custom{' '}
The <EuiCode>timelineAvatar</EuiCode> is using a custom{' '}
<strong>EuiAvatar</strong>.
</p>
</EuiText>
Expand Down
43 changes: 21 additions & 22 deletions src-docs/src/views/comment/comment_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ const commentAvatarSnippet = [
</EuiCommentList>
`,
`<EuiCommentList aria-label="Timeline icon example">
<EuiComment timelineIcon="tag" username="janed" />
<EuiComment timelineAvatar="tag" username="janed" />
</EuiCommentList>
`,
`<EuiCommentList aria-label="Timeline icon example">
<EuiComment timelineIcon={avatar} username="janed">
<EuiComment timelineAvatar={avatar} username="janed">
{body}
</EuiComment>
</EuiCommentList>
Expand Down Expand Up @@ -96,7 +96,10 @@ export const CommentListExample = {
For accessibility, it is highly recommended to provide a descriptive{' '}
<EuiCode>aria-label</EuiCode> or the ID of an external label to the{' '}
<EuiCode>aria-labelledby</EuiCode> prop of the{' '}
<strong>EuiCommentList</strong>.
<strong>EuiCommentList</strong>. A{' '}
<EuiCode>timelineAvatarAriaLabel</EuiCode> should be provided for
every <strong>EuiComment</strong> with or without a{' '}
<EuiCode>timelineAvatar</EuiCode> as <EuiCode>IconType</EuiCode>.
</>
}
/>
Expand Down Expand Up @@ -145,17 +148,17 @@ export const CommentListExample = {
<EuiText>
<ol style={{ listStyleType: 'upper-alpha' }}>
<li>
<EuiCode>timelineIcon</EuiCode>: Shows an icon that should
<EuiCode>timelineAvatar</EuiCode>: Shows an avatar that should
indicate who is the author of the comment. To customize, pass a{' '}
<EuiCode>string</EuiCode> as a{' '}
<EuiCode>EuiIcon[&apos;type&apos;]</EuiCode> or a{' '}
<EuiCode>ReactNode</EuiCode>, preferably a{' '}
<EuiCode>EuiIcon[&apos;type&apos;]</EuiCode> or a a{' '}
<Link to="/display/avatar">
<strong>EuiAvatar</strong>
</Link>
. If no icon is provided, it will default to the{' '}
<EuiCode>username</EuiCode>
&apos;s initials.
. Use in conjunction with{' '}
<EuiCode>timelineAvatarAriaLabel</EuiCode> to pass an aria label
to the avatar. If no avatar is provided, it will default to an
avatar with a <EuiCode>userAvatar</EuiCode> icon.
</li>
<li>
<EuiCode>eventIcon</EuiCode>: Icon that shows before the
Expand Down Expand Up @@ -207,7 +210,7 @@ export const CommentListExample = {
playground: commentConfig,
},
{
title: 'Timeline icon',
title: 'Timeline avatar',
source: [
{
type: GuideSectionTypes.JS,
Expand All @@ -220,28 +223,24 @@ export const CommentListExample = {
<ul>
<li>
By default, each <strong>EuiComment</strong> shows an avatar with
the initial letter of the <EuiCode>username</EuiCode>. It also
uses the <EuiCode>username</EuiCode> for the avatar title
attribute.
the <EuiCode>userAvatar</EuiCode> icon. A{' '}
<EuiCode>timelineAvatarAriaLabel</EuiCode>
should be provided when using this default option.
</li>
<li>
If your <strong>EuiComment</strong> doesn&apos;t have a{' '}
<EuiCode>username</EuiCode>, or if you don&apos;t want to use it
for generating the title attribute and initials you can use the{' '}
<EuiCode>timelineIcon</EuiCode> prop instead.
</li>
<li>
You can also show an icon by passing to the{' '}
<EuiCode>timelineIcon</EuiCode> any of the icon types that{' '}
You can customize your avatar by passing to the{' '}
<EuiCode>timelineAvatar</EuiCode> any of the icon types that{' '}
<Link to="/display/icons">
<strong>EuiIcon</strong>
</Link>{' '}
supports. The icon will show inside a <EuiCode>subdued</EuiCode>{' '}
avatar. Consider this option when showing a system update.
Providing a <EuiCode>timelineAvatarAriaLabel</EuiCode> is
recommended.
</li>
<li>
You can further customize the timeline icon by passing to the{' '}
<EuiCode>timelineIcon</EuiCode> a{' '}
<EuiCode>timelineAvatar</EuiCode> a{' '}
<Link to="/display/avatar">
<strong>EuiAvatar</strong>
</Link>
Expand Down
6 changes: 5 additions & 1 deletion src-docs/src/views/comment/comment_flexible.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ const eventWithMultipleTags = (
const commentsData: EuiCommentListProps['comments'] = [
{
username: 'janed',
timelineAvatarAriaLabel: 'Jane Doe',
event: 'added a comment',
timestamp: 'on Jan 1, 2020',
children: body,
actions: copyAction,
},
{
username: 'luisg',
timelineAvatarAriaLabel: 'Luis G',
event: eventWithMultipleTags,
timestamp: '22 hours ago',
eventIcon: 'tag',
Expand All @@ -64,13 +66,15 @@ const commentsData: EuiCommentListProps['comments'] = [
},
{
username: 'system',
timelineIcon: 'dot',
timelineAvatarAriaLabel: 'System',
timelineAvatar: 'dot',
event: 'pushed a new incident',
timestamp: '20 hours ago',
eventColor: 'danger',
},
{
username: 'pancho1',
timelineAvatarAriaLabel: 'Pancho Pérez',
children: (
<EuiTextArea
fullWidth
Expand Down
6 changes: 5 additions & 1 deletion src-docs/src/views/comment/comment_list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,30 @@ const longBody = (
const comments: EuiCommentProps[] = [
{
username: 'janed',
timelineAvatarAriaLabel: 'Jane Doe',
event: 'added a comment',
timestamp: 'on Jan 1, 2020',
children: body,
actions: copyAction,
},
{
username: 'juanab',
timelineAvatarAriaLabel: 'Juana Barros',
actions: copyAction,
event: 'pushed incident X0Z235',
timestamp: 'on Jan 3, 2020',
},
{
username: 'pancho1',
timelineAvatarAriaLabel: 'Pancho Pérez',
event: 'edited case',
timestamp: 'on Jan 9, 2020',
eventIcon: 'pencil',
eventIconAriaLabel: 'edit',
},
{
username: 'pedror',
timelineAvatarAriaLabel: 'Pedro Rodriguez',
actions: copyAction,
event: complexEvent,
timestamp: 'on Jan 11, 2020',
Expand All @@ -85,7 +89,7 @@ const comments: EuiCommentProps[] = [
},
{
username: 'elohar',

timelineAvatarAriaLabel: 'Elohar Jackson',
event: 'added a comment',
timestamp: 'on Jan 14, 2020',
children: longBody,
Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/views/comment/comment_props.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default ({ snippet }: { snippet: ReactNode }) => {
style={{ maxWidth: '540px' }}
>
<EuiCommentList>
<EuiComment username="Avatar">
<EuiComment username="avatar" timelineAvatarAriaLabel="Avatar">
<div
css={css`
border-radius: ${euiTheme.border.radius.small};
Expand Down
41 changes: 34 additions & 7 deletions src-docs/src/views/comment/comment_system.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
EuiFlexGroup,
EuiFlexItem,
EuiButton,
EuiToolTip,
EuiAvatar,
} from '../../../../src/components';

const actionButton = (
Expand All @@ -38,9 +40,24 @@ const complexEvent = (
</EuiFlexGroup>
);

const UserActionUsername = ({
username,
fullname,
}: {
username: string;
fullname: string;
}) => {
return (
<EuiToolTip position="top" content={<p>{fullname}</p>}>
<strong>{username}</strong>
</EuiToolTip>
);
};

const initialComments: EuiCommentProps[] = [
{
username: 'emma',
username: <UserActionUsername username="emma" fullname="Emma Watson" />,
timelineAvatar: <EuiAvatar name="emma" />,
event: 'added a comment',
timestamp: 'on 3rd March 2022',
children: (
Expand All @@ -51,21 +68,24 @@ const initialComments: EuiCommentProps[] = [
actions: actionButton,
},
{
username: 'emma',
username: <UserActionUsername username="emma" fullname="Emma Watson" />,
timelineAvatar: <EuiAvatar name="emma" />,
event: complexEvent,
timestamp: 'on 3rd March 2022',
eventIcon: 'tag',
eventIconAriaLabel: 'tag',
},
{
username: 'system',
timelineIcon: 'dot',
timelineAvatar: 'dot',
timelineAvatarAriaLabel: 'System',
event: 'pushed a new incident',
timestamp: 'on 4th March 2022',
eventColor: 'danger',
},
{
username: 'tiago',
username: <UserActionUsername username="tiago" fullname="Tiago Pontes" />,
timelineAvatar: <EuiAvatar name="tiago" />,
event: 'added a comment',
timestamp: 'on 4th March 2022',
actions: actionButton,
Expand All @@ -77,7 +97,8 @@ const initialComments: EuiCommentProps[] = [
),
},
{
username: 'emma',
username: <UserActionUsername username="emma" fullname="Emma Watson" />,
timelineAvatar: <EuiAvatar name="emma" />,
event: (
<>
marked case as <EuiBadge color="warning">In progress</EuiBadge>
Expand Down Expand Up @@ -119,7 +140,10 @@ export default () => {
setComments([
...comments,
{
username: 'emma',
username: (
<UserActionUsername username="emma" fullname="Emma Watson" />
),
timelineAvatar: <EuiAvatar name="emma" />,
event: 'added a comment',
timestamp: `on ${date}`,
actions: actionButton,
Expand All @@ -143,7 +167,10 @@ export default () => {
<>
<EuiCommentList aria-label="Comment system example">
{commentsList}
<EuiComment username="juana">
<EuiComment
username="juana"
timelineAvatar={<EuiAvatar name="juana" />}
>
<EuiMarkdownEditor
aria-label="Markdown editor"
aria-describedby={errorElementId.current}
Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/views/copy/copy_to_clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export default () => {
return (
<EuiCommentList aria-label="Copy to clipboard example">
<EuiComment
component="div"
username="Gusteau"
timelineAvatarAriaLabel="Gusteau"
event="added a comment"
actions={
<EuiToolTip
Expand Down
Loading