@@ -27,8 +27,13 @@ export type AlertProps = {
2727 as ?: `h${2 | 3 | 4 | 5 | 6 } `;
2828 classes ?: Partial < Record < "root" | "title" | "description" | "close" , string > > ;
2929 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 ) ;
3237
3338export namespace AlertProps {
3439 export type DefaultSize = {
@@ -45,30 +50,6 @@ export namespace AlertProps {
4550 description : NonNullable < ReactNode > ;
4651 } ;
4752
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-
7253 type ExtractSeverity < FrClassName > = FrClassName extends `fr-alert--${infer Severity } `
7354 ? Exclude < Severity , "sm" >
7455 : never ;
@@ -89,7 +70,7 @@ export const Alert = memo(
8970 small : isSmall ,
9071 title,
9172 description,
92- closable : isClosable = false ,
73+ closable : isClosableByUser = false ,
9374 isClosed : props_isClosed ,
9475 onClose,
9576 ...rest
@@ -145,7 +126,7 @@ export const Alert = memo(
145126 onClose ?.( ) ;
146127 } else {
147128 //Controlled
148- onClose ( ) ;
129+ onClose ?. ( ) ;
149130 }
150131 } ) ;
151132
@@ -174,7 +155,7 @@ export const Alert = memo(
174155 </ HtmlTitleTag >
175156 ) }
176157 < DescriptionTag className = { classes . description } > { description } </ DescriptionTag >
177- { isClosable && (
158+ { isClosableByUser && (
178159 < button
179160 ref = { setButtonElement }
180161 className = { cx ( fr . cx ( "fr-link--close" , "fr-link" ) , classes . close ) }
0 commit comments