@@ -5,9 +5,10 @@ import alertIcon from '@ui5/webcomponents-icons/dist/alert.js';
55import errorIcon from '@ui5/webcomponents-icons/dist/error.js' ;
66import informationIcon from '@ui5/webcomponents-icons/dist/information.js' ;
77import sysEnter2Icon from '@ui5/webcomponents-icons/dist/sys-enter-2.js' ;
8- import { useStylesheet } from '@ui5/webcomponents-react-base' ;
8+ import { useI18nBundle , useStylesheet } from '@ui5/webcomponents-react-base' ;
99import { clsx } from 'clsx' ;
1010import { forwardRef } from 'react' ;
11+ import { ERROR_TYPE , WARNING_TYPE , INFORMATION_TYPE , SUCCESS_TYPE } from '../../i18n/i18n-defaults.js' ;
1112import type { ButtonDomRef , ButtonPropTypes } from '../../webComponents/index.js' ;
1213import { Button } from '../../webComponents/index.js' ;
1314import { classNames , styleData } from './MessageViewButton.module.css.js' ;
@@ -28,30 +29,45 @@ export interface MessageViewButtonProptypes
2829 counter ?: number ;
2930}
3031
31- const getIcon = ( type ) => {
32+ interface Types {
33+ icon : string ;
34+ i18nLabel : { key : string ; defaultText : string } ;
35+ }
36+
37+ const getTypes = ( type : MessageViewButtonProptypes [ 'type' ] ) : Types => {
3238 switch ( type ) {
3339 case ValueState . Negative :
34- return errorIcon ;
40+ return { icon : errorIcon , i18nLabel : ERROR_TYPE } ;
3541 case ValueState . Positive :
36- return sysEnter2Icon ;
42+ return { icon : sysEnter2Icon , i18nLabel : WARNING_TYPE } ;
3743 case ValueState . Critical :
38- return alertIcon ;
44+ return { icon : alertIcon , i18nLabel : INFORMATION_TYPE } ;
3945 default :
40- return informationIcon ;
46+ return { icon : informationIcon , i18nLabel : SUCCESS_TYPE } ;
4147 }
4248} ;
4349
4450/**
4551 * The `MessageViewButton` can be used for opening a `Popover` containing the `MessageView` component. It should always reflect the message `type` with the highest severity.
4652 */
4753const MessageViewButton = forwardRef < ButtonDomRef , MessageViewButtonProptypes > ( ( props , ref ) => {
48- const { type = ValueState . Negative , counter, className, ...rest } = props ;
54+ const { type = ValueState . Negative , counter, className, tooltip , accessibleName , ...rest } = props ;
4955 useStylesheet ( styleData , MessageViewButton . displayName ) ;
5056 const classes = clsx ( classNames . btn , className ) ;
51- const icon = getIcon ( type ) ;
57+ const { icon, i18nLabel } = getTypes ( type ) ;
5258
59+ const i18nBundle = useI18nBundle ( '@ui5/webcomponents-react' ) ;
60+ const label = i18nBundle . getText ( i18nLabel ) ;
5361 return (
54- < Button ref = { ref } className = { classes } icon = { icon } { ...rest } data-type = { type } >
62+ < Button
63+ ref = { ref }
64+ className = { classes }
65+ icon = { icon }
66+ { ...rest }
67+ data-type = { type }
68+ tooltip = { tooltip ?? label }
69+ accessibleName = { accessibleName ?? label }
70+ >
5571 { counter > 1 && counter }
5672 </ Button >
5773 ) ;
0 commit comments