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

[EuiNotificationEvent] Render icon instead of button if onRead is undefined #4881

Merged
merged 13 commits into from
Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from 8 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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- Reverted `z-index: 1` on `EuiPageBody` ([#4892](https://github.com/elastic/eui/pull/4892))
- Added `updateButtonProps` to `EuiSuperDatePicker` to provide more control over the update/refresh button ([#4895](https://github.com/elastic/eui/pull/4895))
- Updated `EuiNotificationEvent` to render an icon instead of a button if `onRead` is undefined ([#4881](https://github.com/elastic/eui/pull/4881))

**Bug fixes**

Expand All @@ -14,7 +15,7 @@
- Updated styles for `EuiRange` ([#4815](https://github.com/elastic/eui/pull/4815)
- Fixed more unique focus states using `outline` ([#4876](https://github.com/elastic/eui/pull/4876))
- Fixed `border-radius` value of `EuiPanel` ([#4876](https://github.com/elastic/eui/pull/4876))
- Fixed `disabled` background color of `EuiCard` for better visiblity on subdued backgrounds ([#4876](https://github.com/elastic/eui/pull/4876))
- Fixed `disabled` background color of `EuiCard` for better visibility on subdued backgrounds ([#4876](https://github.com/elastic/eui/pull/4876))

## [`34.4.0`](https://github.com/elastic/eui/tree/v34.4.0)

Expand Down
64 changes: 64 additions & 0 deletions i18ntokens.json
Original file line number Diff line number Diff line change
Expand Up @@ -2735,6 +2735,70 @@
},
"filepath": "src/components/notification/notification_event_read_button.tsx"
},
{
"token": "euiNotificationEventReadIcon.readAria",
"defString": "{eventName} is read",
"highlighting": "string",
"loc": {
"start": {
"line": 50,
"column": 19
},
"end": {
"line": 56,
"column": 3
}
},
"filepath": "src/components/notification/notification_event_read_icon.tsx"
},
{
"token": "euiNotificationEventReadIcon.unreadAria",
"defString": "{eventName} is unread",
"highlighting": "string",
"loc": {
"start": {
"line": 58,
"column": 21
},
"end": {
"line": 64,
"column": 3
}
},
"filepath": "src/components/notification/notification_event_read_icon.tsx"
},
{
"token": "euiNotificationEventReadIcon.read",
"defString": "Read",
"highlighting": "string",
"loc": {
"start": {
"line": 65,
"column": 20
},
"end": {
"line": 65,
"column": 75
}
},
"filepath": "src/components/notification/notification_event_read_icon.tsx"
},
{
"token": "euiNotificationEventReadIcon.unread",
"defString": "Unread",
"highlighting": "string",
"loc": {
"start": {
"line": 66,
"column": 22
},
"end": {
"line": 69,
"column": 3
}
},
"filepath": "src/components/notification/notification_event_read_icon.tsx"
},
{
"token": "euiPaginationButton.longPageString",
"defString": "Page {page} of {totalPages}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ export const NotificationEventExample = {
<EuiText>
<ul style={{ listStyleType: 'upper-alpha' }}>
<li>
<EuiCode>isRead</EuiCode>: Shows a button that indicates the
current <EuiCode>isRead</EuiCode> state of the event. Use{' '}
<EuiCode>isRead</EuiCode>: Shows a button or icon that indicates
the current <EuiCode>isRead</EuiCode> state of the event. Use{' '}
<EuiCode>onRead</EuiCode> to allow users to toggle between read
and unread states.
</li>
Expand Down
1 change: 1 addition & 0 deletions src/components/notification/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
@import './notification_event_meta';
@import './notification_event_messages';
@import './notification_event_read_button';
@import './notification_event_read_icon';
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.euiNotificationEventReadIcon {
margin-left: $euiSizeXS;
margin-right: $euiSizeXS;
}
2 changes: 2 additions & 0 deletions src/components/notification/notification_event.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ describe('EuiNotificationEvent', () => {
type="Alert"
time="1 min ago"
isRead={true}
onRead={() => {}}
title="title"
messages={['message']}
/>
Expand Down Expand Up @@ -247,6 +248,7 @@ describe('EuiNotificationEvent', () => {
type="Alert"
time="1 min ago"
isRead={true}
onRead={() => {}}
onClickPrimaryAction={onClickPrimaryAction}
primaryAction="primary action label"
title="title"
Expand Down
21 changes: 15 additions & 6 deletions src/components/notification/notification_event.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { EuiButtonEmpty, EuiButtonEmptyProps } from '../button';
import { EuiLink } from '../link';
import { EuiContextMenuItem, EuiContextMenuItemProps } from '../context_menu';
import { htmlIdGenerator } from '../../services';
import { EuiNotificationEventReadIcon } from './notification_event_read_icon';

export type EuiNotificationHeadingLevel = 'h2' | 'h3' | 'h4' | 'h5' | 'h6';

Expand Down Expand Up @@ -135,12 +136,20 @@ export const EuiNotificationEvent: FunctionComponent<EuiNotificationEventProps>
<article aria-labelledby={randomHeadingId} className={classes} key={id}>
{typeof isRead === 'boolean' && (
<div className="euiNotificationEvent__readButton">
<EuiNotificationEventReadButton
isRead={isRead}
onClick={() => onRead?.(id, isRead)}
eventName={title}
id={id}
/>
{!!onRead ? (
<EuiNotificationEventReadButton
isRead={isRead}
onClick={() => onRead(id, isRead)}
eventName={title}
id={id}
/>
) : (
<EuiNotificationEventReadIcon
id={id}
isRead={isRead}
eventName={title}
/>
)}
</div>
)}

Expand Down
85 changes: 85 additions & 0 deletions src/components/notification/notification_event_read_icon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import React, { FunctionComponent } from 'react';
import { EuiButtonIconProps } from '../button';
wenchonglee marked this conversation as resolved.
Show resolved Hide resolved
import { useEuiI18n } from '../i18n';
import classNames from 'classnames';
import { EuiIcon } from '../icon';

export type EuiNotificationEventReadIconProps = Omit<
EuiButtonIconProps,
wenchonglee marked this conversation as resolved.
Show resolved Hide resolved
'iconType' | 'isDisabled' | 'isSelected' | 'size'
wenchonglee marked this conversation as resolved.
Show resolved Hide resolved
> & {
id: string;
/**
* Shows an indicator of the read state of the event
*/
isRead: boolean;
/**
* A unique, human-friendly name for the event to be used in aria attributes (e.g. "alert-critical-01", "cloud-no-severity-12", etc..).
*/
eventName: string;
};

export const EuiNotificationEventReadIcon: FunctionComponent<EuiNotificationEventReadIconProps> = ({
id,
isRead,
eventName,
}) => {
const classesReadState = classNames('euiNotificationEventReadIcon', {
'euiNotificationEventReadButton--isRead': isRead,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In EUI we don't use a class that belongs to a different component. So this class should be specific to this component:

Suggested change
'euiNotificationEventReadButton--isRead': isRead,
'euiNotificationEventReadIcon--isRead': isRead,

Then you need to add the styles .euiNotificationEventReadIcon--isRead svg into src/components/notification/_notification_event_read_icon.scss

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review! I wasn't sure about the practice for isolating classes.
I definitely missed the types though 😅

});

const readAria = useEuiI18n(
'euiNotificationEventReadIcon.readAria',
'{eventName} is read',
{
eventName,
}
);

const unreadAria = useEuiI18n(
'euiNotificationEventReadIcon.unreadAria',
'{eventName} is unread',
{
eventName,
}
);
const readTitle = useEuiI18n('euiNotificationEventReadIcon.read', 'Read');
const unreadTitle = useEuiI18n(
'euiNotificationEventReadIcon.unread',
'Unread'
);

const iconAriaLabel = isRead ? readAria : unreadAria;
const iconTitle = isRead ? readTitle : unreadTitle;

return (
<div className={classesReadState}>
<EuiIcon
type="dot"
aria-label={iconAriaLabel}
title={iconTitle}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 We could only use the title prop here. It would create an aria-labelledby attribute and wire it to the title tag inside the SVG. But then I think just read/unread as a title wouldn't be too descriptive for screen readers. And {eventName} is read would be good for screen readers but too long to display on hover.

So I think the way you did it by adding aria-label and title is better. What do you think @myasonik?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@miukimiu Your thinking on it perfect – exactly! 👍

color="primary"
data-test-subj={`${id}-notificationEventReadIcon`}
/>
</div>
);
};