Skip to content

fix(MessageViewButton): add default tooltip & aria-label #6597

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

Merged
merged 1 commit into from
Nov 14, 2024
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
17 changes: 0 additions & 17 deletions .storybook/mockData/generateMessageItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,6 @@ const informationMessageItems = (count) => {
));
};

const successMessageItems = (count) => {
if (!count) {
return [];
}
return new Array(count).fill('').map((_, index) => (
<MessageItem
key={`SuccessMessage${index}`}
titleText={'Success Message'}
type={ValueState.Success}
groupName={`Group${index}`}
>
{LoremIpsum}
</MessageItem>
));
};

const warningMessageItems = (count) => {
if (!count) {
return [];
Expand Down Expand Up @@ -75,6 +59,5 @@ const errorMessageItems = (count) => {
export const generateMessageItems = (numberOfMessageTypes) => [
...informationMessageItems(numberOfMessageTypes.information),
...warningMessageItems(numberOfMessageTypes.warning),
...successMessageItems(numberOfMessageTypes.success),
...errorMessageItems(numberOfMessageTypes.error)
];
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import type {
import { Bar } from '../../webComponents/Bar/index.js';
import { Button } from '../../webComponents/Button/index.js';
import { Dialog as OriginalDialog } from '../../webComponents/Dialog';
import { Link } from '../../webComponents/Link/index.js';
import { ResponsivePopover as OriginalResponsivePopover } from '../../webComponents/ResponsivePopover';
import { Title } from '../../webComponents/Title/index.js';
import { FlexBox } from '../FlexBox/index.js';
Expand Down Expand Up @@ -60,16 +59,6 @@ const meta = {
>
First Error Message Description.
</MessageItem>,
<MessageItem
key={2}
titleText={'Success Message Type'}
subtitleText={'You can also use subtitles'}
type={ValueState.Success}
counter={2}
>
This is a success message! You can even use{' '}
<Link href={'https://github.com/SAP/ui5-webcomponents-react'}>links here</Link>.
</MessageItem>,
<MessageItem
key={3}
titleText={'Warning Message Type'}
Expand Down
34 changes: 25 additions & 9 deletions packages/main/src/components/MessageViewButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import alertIcon from '@ui5/webcomponents-icons/dist/alert.js';
import errorIcon from '@ui5/webcomponents-icons/dist/error.js';
import informationIcon from '@ui5/webcomponents-icons/dist/information.js';
import sysEnter2Icon from '@ui5/webcomponents-icons/dist/sys-enter-2.js';
import { useStylesheet } from '@ui5/webcomponents-react-base';
import { useI18nBundle, useStylesheet } from '@ui5/webcomponents-react-base';
import { clsx } from 'clsx';
import { forwardRef } from 'react';
import { ValueState } from '../../enums/index.js';
import { ERROR_TYPE, WARNING_TYPE, INFORMATION_TYPE, SUCCESS_TYPE } from '../../i18n/i18n-defaults.js';
import type { ButtonDomRef, ButtonPropTypes } from '../../webComponents/index.js';
import { Button } from '../../webComponents/index.js';
import { classNames, styleData } from './MessageViewButton.module.css.js';
Expand All @@ -28,30 +29,45 @@ export interface MessageViewButtonProptypes
counter?: number;
}

const getIcon = (type) => {
interface Types {
icon: string;
i18nLabel: { key: string; defaultText: string };
}

const getTypes = (type: MessageViewButtonProptypes['type']): Types => {
switch (type) {
case ValueState.Error:
return errorIcon;
return { icon: errorIcon, i18nLabel: ERROR_TYPE };
case ValueState.Success:
return sysEnter2Icon;
return { icon: sysEnter2Icon, i18nLabel: WARNING_TYPE };
case ValueState.Warning:
return alertIcon;
return { icon: alertIcon, i18nLabel: INFORMATION_TYPE };
default:
return informationIcon;
return { icon: informationIcon, i18nLabel: SUCCESS_TYPE };
}
};

/**
* The `MessageViewButton` can be used for opening a `Popover` containing the `MessageView` component. It should always reflect the message `type` with the highest severity.
*/
const MessageViewButton = forwardRef<ButtonDomRef, MessageViewButtonProptypes>((props, ref) => {
const { type = ValueState.Error, counter, className, ...rest } = props;
const { type = ValueState.Error, counter, className, tooltip, accessibleName, ...rest } = props;
useStylesheet(styleData, MessageViewButton.displayName);
const classes = clsx(classNames.btn, className);
const icon = getIcon(type);
const { icon, i18nLabel } = getTypes(type);

const i18nBundle = useI18nBundle('@ui5/webcomponents-react');
const label = i18nBundle.getText(i18nLabel);
return (
<Button ref={ref} className={classes} icon={icon} {...rest} data-type={type}>
<Button
ref={ref}
className={classes}
icon={icon}
{...rest}
data-type={type}
tooltip={tooltip ?? label}
accessibleName={accessibleName ?? label}
>
{counter > 1 && counter}
</Button>
);
Expand Down
12 changes: 12 additions & 0 deletions packages/main/src/i18n/messagebundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -339,3 +339,15 @@ NO_DATA_FILTERED=No data found. Try adjusting the filter settings.
#XACT: Number of items in a pseudo list
WITH_X_ITEMS=with {0} items

#XACT: Message View error button label
ERROR_TYPE=Error Type

#XACT: Message View warning button label
WARNING_TYPE=Warning Type

#XACT: Message View information button label
INFORMATION_TYPE=Information Type

#XACT: Message View success button label
SUCCESS_TYPE=Success Type

Loading