@@ -4,10 +4,11 @@ import alertIcon from '@ui5/webcomponents-icons/dist/alert.js';
4
4
import errorIcon from '@ui5/webcomponents-icons/dist/error.js' ;
5
5
import informationIcon from '@ui5/webcomponents-icons/dist/information.js' ;
6
6
import sysEnter2Icon from '@ui5/webcomponents-icons/dist/sys-enter-2.js' ;
7
- import { useStylesheet } from '@ui5/webcomponents-react-base' ;
7
+ import { useI18nBundle , useStylesheet } from '@ui5/webcomponents-react-base' ;
8
8
import { clsx } from 'clsx' ;
9
9
import { forwardRef } from 'react' ;
10
10
import { ValueState } from '../../enums/index.js' ;
11
+ import { ERROR_TYPE , WARNING_TYPE , INFORMATION_TYPE , SUCCESS_TYPE } from '../../i18n/i18n-defaults.js' ;
11
12
import type { ButtonDomRef , ButtonPropTypes } from '../../webComponents/index.js' ;
12
13
import { Button } from '../../webComponents/index.js' ;
13
14
import { classNames , styleData } from './MessageViewButton.module.css.js' ;
@@ -28,30 +29,45 @@ export interface MessageViewButtonProptypes
28
29
counter ?: number ;
29
30
}
30
31
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 => {
32
38
switch ( type ) {
33
39
case ValueState . Error :
34
- return errorIcon ;
40
+ return { icon : errorIcon , i18nLabel : ERROR_TYPE } ;
35
41
case ValueState . Success :
36
- return sysEnter2Icon ;
42
+ return { icon : sysEnter2Icon , i18nLabel : WARNING_TYPE } ;
37
43
case ValueState . Warning :
38
- return alertIcon ;
44
+ return { icon : alertIcon , i18nLabel : INFORMATION_TYPE } ;
39
45
default :
40
- return informationIcon ;
46
+ return { icon : informationIcon , i18nLabel : SUCCESS_TYPE } ;
41
47
}
42
48
} ;
43
49
44
50
/**
45
51
* The `MessageViewButton` can be used for opening a `Popover` containing the `MessageView` component. It should always reflect the message `type` with the highest severity.
46
52
*/
47
53
const MessageViewButton = forwardRef < ButtonDomRef , MessageViewButtonProptypes > ( ( props , ref ) => {
48
- const { type = ValueState . Error , counter, className, ...rest } = props ;
54
+ const { type = ValueState . Error , counter, className, tooltip , accessibleName , ...rest } = props ;
49
55
useStylesheet ( styleData , MessageViewButton . displayName ) ;
50
56
const classes = clsx ( classNames . btn , className ) ;
51
- const icon = getIcon ( type ) ;
57
+ const { icon, i18nLabel } = getTypes ( type ) ;
52
58
59
+ const i18nBundle = useI18nBundle ( '@ui5/webcomponents-react' ) ;
60
+ const label = i18nBundle . getText ( i18nLabel ) ;
53
61
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
+ >
55
71
{ counter > 1 && counter }
56
72
</ Button >
57
73
) ;
0 commit comments