@@ -27,8 +27,13 @@ export type AlertProps = {
27
27
as ?: `h${2 | 3 | 4 | 5 | 6 } `;
28
28
classes ?: Partial < Record < "root" | "title" | "description" | "close" , string > > ;
29
29
style ?: CSSProperties ;
30
- } & ( AlertProps . DefaultSize | AlertProps . Small ) &
31
- ( AlertProps . NonClosable | AlertProps . Closable ) ;
30
+
31
+ /** Display the cross icon (understand isClosableByUser) */
32
+ closable ?: boolean ;
33
+ /** To provide if you want the Alert to be controlled */
34
+ isClosed ?: boolean ;
35
+ onClose ?: ( ) => void ;
36
+ } & ( AlertProps . DefaultSize | AlertProps . Small ) ;
32
37
33
38
export namespace AlertProps {
34
39
export type DefaultSize = {
@@ -45,30 +50,6 @@ export namespace AlertProps {
45
50
description : NonNullable < ReactNode > ;
46
51
} ;
47
52
48
- export type NonClosable = {
49
- /** Default false */
50
- closable ?: false ;
51
- isClosed ?: never ;
52
- onClose ?: never ;
53
- } ;
54
-
55
- export type Closable = {
56
- /** Default false */
57
- closable : true ;
58
- } & ( Closable . Controlled | Closable . Uncontrolled ) ;
59
-
60
- export namespace Closable {
61
- export type Controlled = {
62
- isClosed : boolean ;
63
- onClose : ( ) => void ;
64
- } ;
65
-
66
- export type Uncontrolled = {
67
- isClosed ?: never ;
68
- onClose ?: ( ) => void ;
69
- } ;
70
- }
71
-
72
53
type ExtractSeverity < FrClassName > = FrClassName extends `fr-alert--${infer Severity } `
73
54
? Exclude < Severity , "sm" >
74
55
: never ;
@@ -89,7 +70,7 @@ export const Alert = memo(
89
70
small : isSmall ,
90
71
title,
91
72
description,
92
- closable : isClosable = false ,
73
+ closable : isClosableByUser = false ,
93
74
isClosed : props_isClosed ,
94
75
onClose,
95
76
...rest
@@ -145,7 +126,7 @@ export const Alert = memo(
145
126
onClose ?.( ) ;
146
127
} else {
147
128
//Controlled
148
- onClose ( ) ;
129
+ onClose ?. ( ) ;
149
130
}
150
131
} ) ;
151
132
@@ -174,7 +155,7 @@ export const Alert = memo(
174
155
</ HtmlTitleTag >
175
156
) }
176
157
< DescriptionTag className = { classes . description } > { description } </ DescriptionTag >
177
- { isClosable && (
158
+ { isClosableByUser && (
178
159
< button
179
160
ref = { setButtonElement }
180
161
className = { cx ( fr . cx ( "fr-link--close" , "fr-link" ) , classes . close ) }
0 commit comments