npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-screen-assist

v1.0.0

Published

A React package for screen reader support and accessibility enhancements

Downloads

53

Readme

react-screen-assist

A React accessibility package for screen reading and content narration with advanced features for web applications, especially useful in e-commerce and interactive sites.

Installation

Install with npm, yarn, or pnpm:

npm install react-screen-assist

or

yarn add react-screen-assist

or

pnpm add react-screen-assist

Quick Start

1. Wrap Your Application with the ScreenReaderProvider

This provider enables screen reader functionality throughout your app.

import { ScreenReaderProvider } from 'react-screen-assist';

function App({ children }) {
    return (
        <ScreenReaderProvider>
            {children}
        </ScreenReaderProvider>
    );
}

2. Use AccessibleElement for Screen-Readable Content

This component allows you to wrap any content you want to be screen-readable, with optional priority settings.

import { AccessibleElement } from 'react-screen-assist';

function ProductCard({ product }) {
    return (
        <AccessibleElement
            description={`Product: ${product.name}, Price: ${product.price}`}
            priority="high"
        >
            {/*Your product card content*/}
        </AccessibleElement>
    );
}

3. Customize with the useScreenReader Hook

For more control, use the useScreenReader hook to access screen reader functions directly.

import { useScreenReader } from 'react-screen-assist';

function CustomComponent() {
    const { speak, isEnabled, toggleScreenReader } = useScreenReader();

    return (
        <div>
            <button onClick={() => speak("Hello, world!")}>
                Read This
            </button>
            <button onClick={toggleScreenReader}>
                {isEnabled ? 'Disable' : 'Enable'} Screen Reader
            </button>
        </div>
    );
}

Features

  • 🎯 Priority-Based Speech Queuing: Control priority of spoken content.
  • 🎛️ Adjustable Speech Rate and Pitch: Customize speech settings.
  • ⏯️ Pause, Resume, and Stop Controls: Manage speech playback.
  • 🔄 Automatic Focus Handling: Read content on focus or mouse events.
  • 🎨 Customizable Styles: Style elements as needed.
  • 📱 Mobile-Friendly: Accessible across devices.
  • 💻 TypeScript Support: Includes TypeScript types for seamless integration.

API Reference

<ScreenReaderProvider>

This provider wraps your application, enabling screen reader context across all child components.

<ScreenReaderProvider>
    <YourApp />
</ScreenReaderProvider>

useScreenReader Hook

The useScreenReader hook provides full access to screen reader functionalities.

const {
    isEnabled, // boolean indicating if screen reader is enabled
    toggleScreenReader, // Function to enable/disable screen reader
    speak, // Function to speak text with optional priority
    pause, // Function to pause speech
    resume, // Function to resume speech
    stop, // Function to stop speech
    rate, // Current speech rate
    setRate, // Function to set speech rate
    pitch, // Current pitch level
    setPitch // Function to set pitch level
} = useScreenReader();

<AccessibleElement>

An element wrapper that makes content accessible for screen readers. Automatically triggers speech on focus and hover.

Props

  • children: The content to render inside the element.
  • description (optional): The text to be read by the screen reader.
  • priority (optional): Determines the urgency of spoken content ('high', 'normal', 'low').
  • className (optional): Custom CSS classes.
<AccessibleElement
    description="This content will be read by the screen reader"
    priority="normal"
    className="custom-styles"
>
    {/*Your content*/}
</AccessibleElement>

Examples

Example 1: E-commerce Product Card

function ProductCard({ product }) {
    return (
        <AccessibleElement
            description={`${product.name}. Price: ${product.price} dollars. ${product.inStock ? 'In stock' : 'Out of stock'}`}
            priority="normal"
        >
            <div className="product-card">
                <img src={product.image} alt={product.name} />
                <h3>{product.name}</h3>
                <p>${product.price}</p>
            </div>
        </AccessibleElement>
    );
}

Example 2: Navigation Menu with Focus Triggers

function NavigationMenu() {
    const { speak } = useScreenReader();

    return (
        <nav>
            <AccessibleElement description="Main navigation menu">
                <ul>
                    {menuItems.map(item => (
                        <li key={item.id}>
                            <button
                                onFocus={() => speak(item.name, 'high')}
                                onMouseEnter={() => speak(item.name, 'low')}
                            >
                                {item.name}
                            </button>
                        </li>
                    ))}
                </ul>
            </AccessibleElement>
        </nav>
    );
}

Contributing

Contributions are welcome! Please read our contributing guidelines before submitting a pull request.

License

MIT © Idris Kulubi