33 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44'use client' ;
55
6- import { Localized } from '@fluent/react' ;
6+ import { useLocalization } from '@fluent/react' ;
77import classNames from 'classnames' ;
88import * as Dialog from '@radix-ui/react-dialog' ;
9+ import * as VisuallyHidden from "@radix-ui/react-visually-hidden" ;
910import Image from 'next/image' ;
1011import checkLogo from '@fxa/shared/assets/images/check.svg' ;
1112import closeIcon from '@fxa/shared/assets/images/close.svg' ;
12- import { useEffect , useState } from 'react' ;
13+ import { useState } from 'react' ;
1314
1415export enum AlertBarVariant {
1516 ERROR ,
@@ -19,58 +20,52 @@ export enum AlertBarVariant {
1920export type AlertBarProps = {
2021 checked ?: boolean ;
2122 children : React . ReactNode ;
22- ariaId ?: string ;
2323 variant ?: AlertBarVariant ;
24- onClick ?: ( ) => any ;
2524 containerRef ?: HTMLElement | null ;
2625} ;
2726
2827export const AlertBar = ( {
2928 checked,
3029 children,
3130 variant = AlertBarVariant . ERROR ,
32- ariaId,
33- onClick,
3431 containerRef = null ,
3532} : AlertBarProps ) => {
36- const [ container , setContainer ] = useState < HTMLElement | null > ( null ) ;
33+ const [ openDialog , setOpenDialog ] = useState ( true ) ;
3734
38- useEffect ( ( ) => {
39- if ( ! containerRef ) {
40- setContainer ( document . getElementById ( 'header' ) ) ;
41- }
42- } , [ ] ) ;
35+ const { l10n } = useLocalization ( ) ;
4336
4437 let alertTypeStyle ;
4538 switch ( variant ) {
4639 case AlertBarVariant . ERROR :
47- alertTypeStyle = 'bg-red-600 text-white ' ;
40+ alertTypeStyle = 'bg-red-100 error ' ;
4841 break ;
4942
5043 case AlertBarVariant . SUCCESS :
51- alertTypeStyle = 'bg-grey-700 text-white ' ;
44+ alertTypeStyle = 'bg-green-200 success ' ;
5245 break ;
5346 }
5447
5548 return (
5649 < >
57- < Dialog . Root open = { true } modal = { false } >
58- < Dialog . Portal container = { container } >
50+ < Dialog . Root open = { openDialog } modal = { false } >
51+ < Dialog . Portal container = { containerRef } >
5952 < Dialog . Content
60- className = {
61- 'left-0 w-full absolute flex font-medium items-center justify-center pt-32 tablet:pt-40'
62- }
53+ className = "flex absolute justify-center mx-2 mt-2 right-0 left-0 top-16 tablet:top-20 z-10"
6354 >
55+ < VisuallyHidden . Root asChild >
56+ < Dialog . Title
57+ >
58+ { l10n . getString ( 'alert-dialog-title' , null , 'Alert dialog' ) }
59+ </ Dialog . Title >
60+ </ VisuallyHidden . Root >
6461 < div
65- aria-labelledby = { ariaId }
6662 className = { classNames (
67- 'w-2/3 tablet:w-[640px] flex font-medium items-center justify-center min-h-[32px] my-1 mx-auto p-2 relative rounded-md text-sm tablet:max-w-[640px] ' ,
63+ 'max-w-full tablet:max-w-2xl w-full desktop: min-w-sm flex shadow-md rounded-sm text-sm font-medium text-grey-700 border border-transparent outline-none ' ,
6864 alertTypeStyle
6965 ) }
7066 data-testid = "alert-container"
71- role = "dialog"
7267 >
73- < div className = "text-center w-[80%] " >
68+ < div className = "flex-1 py-2 px-8 text-center outline-none " >
7469 { checked && (
7570 < Image
7671 src = { checkLogo }
@@ -80,19 +75,22 @@ export const AlertBar = ({
8075 ) }
8176 { children }
8277 </ div >
83- { onClick && (
84- < Localized id = "close-aria" >
85- < span
86- data-testid = "clear-success-alert"
87- className = "grid"
88- aria-label = "Close modal"
89- onClick = { ( ) => onClick ( ) }
90- role = "button"
91- >
92- < Image src = { closeIcon } alt = "" className = "w-4 h-4" />
93- </ span >
94- </ Localized >
95- ) }
78+ < Dialog . Close asChild >
79+ < button
80+ className = {
81+ classNames (
82+ 'shrink-0 items-stretch justify-center py-2 px-3 focus-visible:rounded-sm focus-visible-default outline-none' ,
83+ alertTypeStyle
84+ )
85+ }
86+ onClick = { ( ) => setOpenDialog ( false ) }
87+ >
88+ < Image
89+ src = { closeIcon }
90+ alt = { l10n . getString ( 'dialog-close' , null , 'Close dialog' ) }
91+ />
92+ </ button >
93+ </ Dialog . Close >
9694 </ div >
9795 </ Dialog . Content >
9896 </ Dialog . Portal >
0 commit comments