Design React Kit

repository·main·Indexed 41 days ago

https://github.com/italia/design-react-kit

A toolkit for creating web applications with React based on Bootstrap Italia. It implements styles from the Design UI Kit and provides a set of React components, including Autocomplete, BottomNavItem, Card, and Collapse. Version 5.10.0 requires bootstrap-italia and specific typefaces (Titillium Web, Roboto Mono, and Lora) for correct styling.

Tokens
58.5K
Snippets
195
Records
292
Agent score
51%

What's inside Design React Kit

  1. Overview of Design React Kit

    main

    Design React Kit provides React components designed for Public Administration services.

    Key resources:

    • GitHub Repository: For detailed usage instructions and contribution guidelines.
    • Playground Project: A small application built with the kit to demonstrate its capabilities.
    • License: Distributed under the BSD-3 license, which allows for modification and redistribution, including in closed-source software.
  2. Use Upload components for file selection

    main

    The Upload components provide various graphical and functional variants for HTML file input fields, allowing users to upload one or more files via form submission.

    Key variants include:

    • File List: A list of files where each item can exist in one of three states: loading (uploading), success (uploaded correctly), or error (upload failed).
    • Image Preview: Replaces standard SVG file icons with thumbnails of the uploaded images. The component optimizes non-square images, but lightweight images are recommended.
    • Avatar Upload: Combines an Avatar display with a file input for updating profile images. It is designed for a single file upload (no multiple attribute).
    • Gallery: A specialized view for managing a series of photos with thumbnail previews.
    • Drag & Drop: Allows users to drag files from their device directly onto the upload icon.
  3. How Megamenu works within a Navbar

    main

    A Megamenu is a variation of the Dropdown component used within a Navbar.

    Key implementation details:

    • The Navbar must include the class has-megamenu.
    • The Collapse component (used for mobile responsiveness) must include the megamenu prop.
    • Content is organized using MegamenuItem, which holds the specific menu content (links, images, or CTAs).
    <Navbar expand='lg' className='has-megamenu'>
      <NavbarBrand />
      <NavbarToggler ... />
      <Collapse isOpen={openNav} navbar header megamenu>
        <Nav className='mt-0' navbar>
          <MegamenuItem itemName='Menu Name'>
            {/* Content */}
          </MegamenuItem>
        </Nav>
      </Collapse>
    </Navbar>
  4. Add badges and alerts to BottomNavItem

    main

    You can enhance BottomNavItem with visual indicators:

    • Badge: Use the badge attribute to display numerical indicators (e.g., unread message counts).
    • Alert: Use the alert attribute to highlight a section that requires attention or contains new content.

    Accessibility Note: Both badges and alerts are hidden from screen readers by default. To ensure accessibility, you must provide an explanatory text using the srText attribute.

    <BottomNav>
      {/* Item with a badge and accessibility text */}
      <BottomNavItem 
        label="Messages" 
        href="/messages" 
        badge={5} 
        srText="5 unread messages" 
      />
    
      {/* Item with an alert and accessibility text */}
      <BottomNavItem 
        label="Notifications" 
        href="/notifications" 
        alert 
        srText="New notifications available" 
      />
    </BottomNav>
  5. Accessibility best practices for Tables

    main

    When using tables, follow these accessibility guidelines:

    1. Use <caption>: A <caption> element acts as a header for the table. It helps screen reader users identify the table's purpose and decide whether to read it.
    2. Don't rely solely on color: Using color to convey meaning (e.g., a red row for an error) is only a visual cue. Ensure that the information is also available via text content or through alternative means like the .visually-hidden class for screen readers.
  6. Accessibility best practices for Badges

    main

    When using badges, especially for counters, consider the following accessibility requirements:

    1. Meaningful Context: Color alone does not convey meaning to screen reader users. Ensure that information conveyed by color is also available via text or alternative means.
    2. Hidden Text: If a badge (like a number) might be confusing without context (e.g., a '4' appearing at the end of a sentence), use a visually hidden text element with the .visually-hidden class to provide context for assistive technologies.

    Example of providing context for a counter:

    <button>
      Notifiche
      <Badge>
        <span className="visually-hidden">4 notifiche non lette</span>
        4
      </Badge>
    </button>
  7. How to use Dropdown components

    main

    The Dropdown system in the Design React Kit is used to toggle contextual overlays (like link lists) via <button/> or <a/> elements.

    Core Components

    • Dropdown: The root container for the dropdown logic.
    • DropdownToggle: The trigger element. It uses the Button component internally and accepts all standard Button attributes. It can also be used as an anchor link.
    • DropdownMenu: The container for the menu items.
    • LinkListItem: The individual items within the menu (should be contained within a LinkList inside the menu).

    Accessibility Note

    Unlike strict WAI-ARIA role="menu" widgets which are limited to specific menu items, these dropdowns are designed to be generic. They can contain complex markup like search inputs or forms. While they include built-in keyboard support (arrow keys to navigate, ESC to close), you should manually add specific ARIA roles/attributes if you require strict WAI-ARIA compliance for application-style menus.

  8. How ThumbNav and ThumbNavItem work together

    main

    The ThumbNav component acts as a container for multiple ThumbNavItem elements. Each ThumbNavItem represents a single link or thumbnail in the navigation.

    Key behaviors:

    • Aspect Ratio: Each ThumbNavItem includes a resizer to maintain a consistent 3:2 aspect ratio regardless of the source image dimensions.
    • Active State: To highlight the currently selected item, apply the active attribute to the corresponding ThumbNavItem.
    • Accessibility: For accessibility compliance, ensure the alt attribute of the thumbnail image describes the action associated with the link.

    Use ThumbNav as the parent and populate it with ThumbNavItem children.

  9. Configure Upload Gallery mode

    main

    To manage the uploading of a series of photos and display them as a gallery with thumbnails, use the UploadList component and set the tipologia prop to 'gallery'.

    Note: While the component optimizes the display of non-square images, it is recommended to use lightweight images for better performance.

    // Example configuration for gallery mode
    <UploadList tipologia='gallery' ... />