@@ -18,34 +18,38 @@ import { useConstCallback } from "./tools/powerhooks/useConstCallback";
18
18
import { createComponentI18nApi } from "./i18n" ;
19
19
import { useAnalyticsId } from "./tools/useAnalyticsId" ;
20
20
21
- export type NoticeProps = {
22
- id ?: string ;
23
- className ?: string ;
24
- classes ?: Partial < Record < "root" | "title" | "close" , string > > ;
25
- title : NonNullable < ReactNode > ;
26
- style ?: CSSProperties ;
27
- } & ( NoticeProps . NonClosable | NoticeProps . Closable ) ;
21
+ export type NoticeProps = NoticeProps . NonClosable | NoticeProps . Closable ;
28
22
29
23
export namespace NoticeProps {
30
- export type NonClosable = {
24
+ type Common = {
25
+ id ?: string ;
26
+ className ?: string ;
27
+ classes ?: Partial < Record < "root" | "title" | "close" , string > > ;
28
+ title : NonNullable < ReactNode > ;
29
+ style ?: CSSProperties ;
30
+ } ;
31
+
32
+ export type NonClosable = Common & {
31
33
isClosable ?: false ;
32
- isClosed ?: undefined ;
33
- onClose ?: undefined ;
34
+
35
+ isClosed ?: never ;
36
+ onClose ?: never ;
34
37
} ;
35
38
36
- export type Closable = {
37
- isClosable : true ;
38
- } & ( Closable . Controlled | Closable . Uncontrolled ) ;
39
+ export type Closable = Closable . Controlled | Closable . Uncontrolled ;
39
40
40
41
export namespace Closable {
41
- export type Controlled = {
42
+ export type Controlled = Common & {
43
+ isClosable : true ;
42
44
isClosed : boolean ;
43
- onClose : ( ) => void ;
45
+ onClose : ( event : React . MouseEvent < HTMLButtonElement , MouseEvent > ) => void ;
44
46
} ;
45
47
46
- export type Uncontrolled = {
47
- isClosed ?: undefined ;
48
- onClose ?: ( ) => void ;
48
+ export type Uncontrolled = Common & {
49
+ isClosable : true ;
50
+ onClose ?: ( event : React . MouseEvent < HTMLButtonElement , MouseEvent > ) => void ;
51
+
52
+ isClosed ?: never ;
49
53
} ;
50
54
}
51
55
}
@@ -107,16 +111,18 @@ export const Notice = memo(
107
111
buttonElement . focus ( ) ;
108
112
} , [ buttonElement ] ) ;
109
113
110
- const onCloseButtonClick = useConstCallback ( ( ) => {
111
- if ( props_isClosed === undefined ) {
112
- //Uncontrolled
113
- setIsClosed ( true ) ;
114
- onClose ?.( ) ;
115
- } else {
116
- //Controlled
117
- onClose ( ) ;
114
+ const onCloseButtonClick = useConstCallback (
115
+ ( event : React . MouseEvent < HTMLButtonElement , MouseEvent > ) => {
116
+ if ( props_isClosed === undefined ) {
117
+ //Uncontrolled
118
+ setIsClosed ( true ) ;
119
+ onClose ?.( event ) ;
120
+ } else {
121
+ //Controlled
122
+ onClose ( event ) ;
123
+ }
118
124
}
119
- } ) ;
125
+ ) ;
120
126
121
127
const { t } = useTranslation ( ) ;
122
128
@@ -133,8 +139,8 @@ export const Notice = memo(
133
139
style = { style }
134
140
{ ...rest }
135
141
>
136
- < div className = "fr-container" >
137
- < div className = "fr-notice__body" >
142
+ < div className = { fr . cx ( "fr-container" ) } >
143
+ < div className = { fr . cx ( "fr-notice__body" ) } >
138
144
< p className = { cx ( fr . cx ( `fr-notice__title` ) , classes . title ) } > { title } </ p >
139
145
{ /* TODO: Use our button once we have one */ }
140
146
{ isClosable && (
0 commit comments