11import { type HTMLAttributes , type ReactNode , type Ref , useEffect , useRef , useCallback , useState } from 'react' ;
22import { CloseButton } from '../CloseButton' ;
3+ import { ErrorIcon , InfoIcon , SuccessIcon , WarningIcon } from '../../icons' ;
4+ import type { NotificationPopupLabels } from '../../labels' ;
5+ import { useComponentLibraryStrings } from '../../providers' ;
36import styles from './NotificationPopup.module.scss' ;
47
58export type NotificationVariant = 'info' | 'success' | 'warning' | 'error' ;
69
10+ const DEFAULT_NOTIFICATION_LABELS : Required < NotificationPopupLabels > = {
11+ dismissAriaLabel : 'Dismiss notification' ,
12+ } ;
13+
714export interface NotificationPopupProps extends HTMLAttributes < HTMLDivElement > {
815 /** Ref forwarded to the container. */
916 ref ?: Ref < HTMLDivElement > ;
@@ -26,6 +33,11 @@ export interface NotificationPopupProps extends HTMLAttributes<HTMLDivElement> {
2633 /** Called after the exit animation finishes and the element is removed from the DOM.
2734 * Use this in list/stack patterns to remove the item from state only after it has animated out. */
2835 onExited ?: ( ) => void ;
36+ /**
37+ * Override individual translatable strings inside the notification.
38+ * Values set here take priority over any `<ComponentLibraryProvider strings>` defaults.
39+ */
40+ labels ?: NotificationPopupLabels ;
2941}
3042
3143const ANIMATION_DURATION = 250 ;
@@ -62,8 +74,12 @@ export function NotificationPopup({
6274 onExited,
6375 className,
6476 ref,
77+ labels,
6578 ...rest
6679} : NotificationPopupProps ) {
80+ const ctx = useComponentLibraryStrings ( ) ;
81+ const l = { ...DEFAULT_NOTIFICATION_LABELS , ...ctx . notificationPopup , ...labels } ;
82+
6783 const timerRef = useRef < ReturnType < typeof setTimeout > | null > ( null ) ;
6884 const pausedRef = useRef ( false ) ;
6985 const prevVisibleRef = useRef ( visible ) ;
@@ -138,26 +154,10 @@ export function NotificationPopup({
138154 if ( ! mounted ) return null ;
139155
140156 const variantIcons : Record < NotificationVariant , ReactNode > = {
141- info : (
142- < svg viewBox = "0 0 16 16" width = "16" height = "16" fill = "currentColor" >
143- < path d = "M8 1.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13zM0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8zm9 3a1 1 0 1 1-2 0 1 1 0 0 1 2 0zm-.25-6.25a.75.75 0 0 0-1.5 0v3.5a.75.75 0 0 0 1.5 0v-3.5z" />
144- </ svg >
145- ) ,
146- success : (
147- < svg viewBox = "0 0 16 16" width = "16" height = "16" fill = "currentColor" >
148- < path d = "M8 1.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13zM0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8zm11.78-2.28a.75.75 0 0 0-1.06-1.06L7 8.37 5.28 6.65a.75.75 0 0 0-1.06 1.06l2.25 2.25a.75.75 0 0 0 1.06 0l4.25-4.24z" />
149- </ svg >
150- ) ,
151- warning : (
152- < svg viewBox = "0 0 16 16" width = "16" height = "16" fill = "currentColor" >
153- < path d = "M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368L8.22 1.754zM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0zm-.25-5.25a.75.75 0 0 0-1.5 0v2.5a.75.75 0 0 0 1.5 0v-2.5z" />
154- </ svg >
155- ) ,
156- error : (
157- < svg viewBox = "0 0 16 16" width = "16" height = "16" fill = "currentColor" >
158- < path d = "M2.343 13.657A8 8 0 1 1 13.657 2.343 8 8 0 0 1 2.343 13.657zm1.06-1.06A6.5 6.5 0 1 0 12.596 3.404 6.5 6.5 0 0 0 3.404 12.596zM6.22 4.97a.75.75 0 0 0-1.06 1.06L6.94 8l-1.78 1.97a.75.75 0 1 0 1.06 1.06L8 9.06l1.97 1.97a.75.75 0 1 0 1.06-1.06L9.06 8l1.97-1.97a.75.75 0 0 0-1.06-1.06L8 6.94 6.22 4.97z" />
159- </ svg >
160- ) ,
157+ info : < InfoIcon /> ,
158+ success : < SuccessIcon /> ,
159+ warning : < WarningIcon /> ,
160+ error : < ErrorIcon /> ,
161161 } ;
162162
163163 const isUrgent = URGENT_VARIANTS . has ( variant ) ;
@@ -187,7 +187,7 @@ export function NotificationPopup({
187187 </ div >
188188 < CloseButton
189189 size = "sm"
190- aria-label = "Dismiss notification"
190+ aria-label = { l . dismissAriaLabel }
191191 onClick = { onDismiss }
192192 className = { styles . dismiss }
193193 />
0 commit comments