UNPKG

@hex2r/react-announcer

Version:

Accessible announcer component for React apps using the Context API. Renders live-region messages for screen readers and provides a simple hook for dispatching announcements from anywhere in your component tree.

33 lines (26 loc) 963 B
import React from 'react'; type AnnouncerEvent = { message: string; assertive?: boolean; }; type PropsWithId = { id: string; }; type Announcement = PropsWithId & AnnouncerEvent; type AnnounceFn = (e: AnnouncerEvent) => void; type AnnouncerContextType = { announce: AnnounceFn; }; declare const AnnouncerContext: React.Context<AnnouncerContextType | undefined>; type AnnouncerProvider = { children: (announcements: Announcement[]) => React.ReactNode; }; declare const AnnouncerProvider: ({ children }: AnnouncerProvider) => React.JSX.Element; declare const useAnnouncer: () => AnnouncerContextType; type AnnouncementRegionProps = { announcements: Announcement[]; srOnlySupported?: boolean; stackLimit?: number; }; declare function AnnouncementRegion({ announcements, srOnlySupported, stackLimit, }: AnnouncementRegionProps): React.JSX.Element; export { AnnouncementRegion, AnnouncerContext, AnnouncerProvider, useAnnouncer };