11import { Box , safelySpreadBoxProps } from "@twilio-paste/box" ;
22import type { BoxProps , BoxStyleProps } from "@twilio-paste/box" ;
3+ import { Button } from "@twilio-paste/button" ;
4+ import { CloseIcon } from "@twilio-paste/icons/esm/CloseIcon" ;
35import { ErrorIcon } from "@twilio-paste/icons/esm/ErrorIcon" ;
46import { NeutralIcon } from "@twilio-paste/icons/esm/NeutralIcon" ;
57import { NewIcon } from "@twilio-paste/icons/esm/NewIcon" ;
@@ -43,33 +45,48 @@ export interface CalloutProps extends HTMLPasteProps<"div"> {
4345 * @memberof CalloutProps
4446 */
4547 marginY ?: BoxStyleProps [ "marginY" ] ;
48+ /**
49+ * Function to run on dismiss of the Callout. Adds a close button.
50+ *
51+ * @default null
52+ * @memberof CalloutProps
53+ */
54+ onDismiss ?: ( ) => void ;
55+ /**
56+ * Title for dismiss label. Only necessary when using onDismiss.
57+ *
58+ * @default 'Dismiss callout'
59+ * @memberof CalloutProps
60+ * @type {string }
61+ */
62+ i18nDismissLabel ?: string ;
4663}
4764
4865const variantStyles : Record < CalloutVariants , BoxStyleProps > = {
4966 success : {
50- backgroundColor : "colorBackgroundSuccessWeakest " ,
67+ backgroundColor : "colorBackgroundWeak " ,
5168 color : "colorTextSuccess" ,
52- borderColor : "colorBorderSuccessWeaker " ,
69+ borderColor : "colorBorderSuccessWeak " ,
5370 } ,
5471 error : {
5572 backgroundColor : "colorBackgroundErrorWeakest" ,
5673 color : "colorTextError" ,
57- borderColor : "colorBorderErrorWeaker " ,
74+ borderColor : "colorBorderErrorWeak " ,
5875 } ,
5976 warning : {
60- backgroundColor : "colorBackgroundWarningWeakest " ,
77+ backgroundColor : "colorBackgroundWeak " ,
6178 color : "colorTextWarningStrong" ,
62- borderColor : "colorBorderWarningWeaker " ,
79+ borderColor : "colorBorderWarningWeak " ,
6380 } ,
6481 new : {
65- backgroundColor : "colorBackgroundNewWeakest " ,
82+ backgroundColor : "colorBackgroundWeak " ,
6683 color : "colorTextNew" ,
67- borderColor : "colorBorderNewWeaker " ,
84+ borderColor : "colorBorderNewWeak " ,
6885 } ,
6986 neutral : {
70- backgroundColor : "colorBackgroundNeutralWeakest " ,
87+ backgroundColor : "colorBackgroundWeak " ,
7188 color : "colorTextNeutral" ,
72- borderColor : "colorBorderNeutralWeaker " ,
89+ borderColor : "colorBorderNeutralWeak " ,
7390 } ,
7491} ;
7592
@@ -90,7 +107,19 @@ const defaultIconLabels: Record<CalloutVariants, string> = {
90107} ;
91108
92109export const Callout = React . forwardRef < HTMLDivElement , CalloutProps > (
93- ( { children, variant, element = "CALLOUT" , i18nLabel, marginY, ...props } , ref ) => {
110+ (
111+ {
112+ children,
113+ variant,
114+ element = "CALLOUT" ,
115+ i18nLabel,
116+ marginY,
117+ onDismiss,
118+ i18nDismissLabel = "Dismiss callout" ,
119+ ...props
120+ } ,
121+ ref ,
122+ ) => {
94123 const IconComponent = variantIcons [ variant ] ;
95124 const iconLabel = i18nLabel ? i18nLabel : defaultIconLabels [ variant ] ;
96125
@@ -100,19 +129,31 @@ export const Callout = React.forwardRef<HTMLDivElement, CalloutProps>(
100129 ref = { ref }
101130 element = { element }
102131 display = "flex"
132+ flexDirection = "column"
103133 marginY = { marginY }
104- padding = "space60"
105- borderStyle = "solid"
106- borderWidth = "borderWidth10"
107- borderRadius = "borderRadius30"
134+ rowGap = "space50"
135+ paddingTop = "space70"
136+ paddingLeft = "space70"
137+ paddingRight = "space70"
138+ paddingBottom = "space90"
139+ borderLeftStyle = "solid"
140+ borderLeftWidth = "borderWidth20"
108141 variant = { variant }
109142 { ...variantStyles [ variant ] }
110143 >
111- < Box marginRight = "space60" paddingTop = "space10" element = { `${ element } _ICON` } >
112- { IconComponent }
113- < ScreenReaderOnly > { iconLabel } </ ScreenReaderOnly >
144+ < Box display = "flex" justifyContent = "space-between" >
145+ < Box element = { `${ element } _ICON` } >
146+ { IconComponent }
147+ < ScreenReaderOnly > { iconLabel } </ ScreenReaderOnly >
148+ </ Box >
149+ { onDismiss && typeof onDismiss === "function" && (
150+ < Button onClick = { onDismiss } variant = "secondary_icon" size = "reset" element = { `${ element } _DISMISS_BUTTON` } >
151+ < CloseIcon element = { `${ element } _DISMISS_ICON` } decorative size = "sizeIcon20" />
152+ < ScreenReaderOnly > { i18nDismissLabel } </ ScreenReaderOnly >
153+ </ Button >
154+ ) }
114155 </ Box >
115- < Box display = "flex" flexDirection = "column" rowGap = "space50 " flex = "1" >
156+ < Box display = "flex" flexDirection = "column" rowGap = "space30 " flex = "1" >
116157 { children }
117158 </ Box >
118159 </ Box >
0 commit comments