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

@asphalt-react/content-switcher

v2.0.0-rc.4

Published

Content switcher

Downloads

155

Readme

ContentSwitcher

npm

Component to switch between alternate views of a content within the same page or screen. Only one view is visible at a time. For instance, use ContentSwticher to switch between tabular view and graphical view of a dataset. It's a controlled component where you control which content view should be visible.

ContentSwitcher exports another component named Switch. Switch creates the tabs for each view. Switches come in 2 sizes: small and medium (default). Each Switch has three types of caption:

  • text only
  • text with an icon; icon adds more context to the text
  • icon only

Switch accepts most of the button element's attributes such as id & name and supports data-* attributes.

Accessibility

  1. ContentSwitcher has a role="tablist" and the Switches have role="tab".
  2. The selected Switch has "aria-selected" set to true.
  3. The Switches are focusable using tab.
  4. ContentSwitcher accepts aria-* attributes for role="tablist".
  5. Switch accepts aria-* attributes for role="tab".

Accessibility must-haves

  1. Add role="tabpanel" to the content section.
  2. Add an id to a Switch. Pass the "id"'s value to aria-labelledby attribute to the element of the content section.
  3. Add an id to the view section element. Pass the "id"'s value to aria-controls attribute of its Switch.
  4. Add aria-label or aria-labelledby in Switch with icon as caption.

Check examples to see these in action.

Usage

import React, { useState } from "react"
import { ContentSwitcher, Switch } from "@asphalt-react/content-switcher"

function App() {
  const [active, setActive] = useState(0)
  const clickHandler = ({ value }) => setActive(value)
  return (
    <main>
      <ContentSwitcher active={active} onAction={clickHandler}>
        <Switch value={0}>First</Switch>
        <Switch value={1}>Second</Switch>
      </ContentSwitcher>
      <div>
        {active === 0 && (<div>First Section</div)}
        {active === 1 && (<div>Second Section</div>)}
      </div>
    </main>
  )
}

export default App

Props

children

Switch components.

| type | required | default | | ---- | -------- | ------- | | node | true | N/A |

active

Index of the active Switch.

| type | required | default | | ------ | -------- | ------- | | number | true | N/A |

onAction

Function called on clicking a Switch.

The function accepts an object as argument with the keys:

  • value: value of the Switch clicked
  • event: React synthetic event

| type | required | default | | ---- | -------- | ------- | | func | false | N/A |

size

Size of the Switches. Accepts one of "s" or "m" for small & medium.

| type | required | default | | ---- | -------- | ------- | | enum | false | "m" |

Switch

Props

children

Switch caption.

| type | required | default | | ---- | -------- | ------- | | node | true | N/A |

value

Index of the Switch.

| type | required | default | | ------ | -------- | ------- | | number | true | N/A |

icon

Renders icon as caption.

| type | required | default | | ---- | -------- | ------- | | bool | false | false |

qualifier

Icons to add more context to the textual caption.

Accepts SVG or SVG wrapped React component. Checkout @asphalt-react/iconpack for SVG wrapped React components.

⚠️ Do not use qualifier to render a Switch with icon as caption; use icon prop instead.

| type | required | default | | ------- | -------- | ------- | | element | false | N/A |

qualifierEnd

Appends qualifier to the text in caption. Switch prepends the qualifier by default.

| type | required | default | | ---- | -------- | ------- | | bool | false | false |