-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from harshmangalam/revert-79-main
Revert "enhance alert box accessbility #52 issue"
- Loading branch information
Showing
1 changed file
with
3 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,14 @@ | ||
import { component$, useStore } from "@builder.io/qwik"; | ||
import { component$ } from "@builder.io/qwik"; | ||
|
||
type Props = { | ||
text: string; | ||
status: "alert-info" | "alert-success" | "alert-warning" | "alert-error"; | ||
onClose?: () => void; | ||
}; | ||
|
||
export const Alert = component$((props: Props) => { | ||
const { text, status = "alert-info", onClose } = props; | ||
const store = useStore({ isVisible: true }); | ||
|
||
const handleClose = () => { | ||
store.isVisible = false; | ||
if (onClose) { | ||
onClose(); | ||
} | ||
}; | ||
|
||
if (!store.isVisible) return null; | ||
|
||
const { text, status = "alert-info" } = props; | ||
return ( | ||
<div | ||
role="alert" | ||
aria-live="assertive" | ||
aria-atomic="true" | ||
class={["alert", status]} | ||
aria-label="Alert" | ||
> | ||
<div class={["alert", status]}> | ||
<span>{text}</span> | ||
{onClose && ( | ||
<button | ||
onClick={handleClose} | ||
aria-label="Close alert" | ||
class="close-button" | ||
> | ||
× {/* Close icon */} | ||
</button> | ||
)} | ||
</div> | ||
); | ||
}); |