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

@pmwcs/tabs

v1.1.0

Published

PMWCS tabs component

Downloads

3

Readme

Tabs

Tabs make it easy to explore and switch between different views.

  • Module @pmwcs/tabs
  • Import styles:
    • Using CSS Loader
      • import '@pmwcs/tabs/styles';
    • Or include stylesheets
      • '@material/tab-bar/dist/mdc.tab-bar.css'
      • '@material/tab/dist/mdc.tab.css'
      • '@material/tab-scroller/dist/mdc.tab-scroller.css'
      • '@material/tab-indicator/dist/mdc.tab-indicator.css'
      • '@material/ripple/dist/mdc.ripple.css'
      • '@pmwcs/icon/icon.css'
  • MDC Docs: https://material.io/develop/web/components/tabs/tab-bar/

Basic Usage

Tabs can be either controlled or uncontrolled just like inputs. Use the activeTabIndex and onActivate callback for controlled components.

<TabBar>
  <Tab>Cookies</Tab>
  <Tab>Pizza</Tab>
  <Tab>Icecream</Tab>
</TabBar>
function Example() {
  const [activeTab, setActiveTab] = React.useState(0);

  return (
    <TabBar
      activeTabIndex={activeTab}
      onActivate={evt => setActiveTab(evt.detail.index)}
    >
      <Tab>Cookies</Tab>
      <Tab>Pizza</Tab>
      <Tab>Icecream</Tab>
    </TabBar>
  );
}

Variants

<TabBar>
  <Tab>Cookies</Tab>
  <Tab>Pizza</Tab>
  <Tab>Icecream</Tab>
</TabBar>
<TabBar>
  <Tab icon="star_border" label="Cookies" />
  <Tab icon="favorite_border" label="Pizza" />
  <Tab icon="mood" label="Icecream" />
</TabBar>
<TabBar>
  <Tab icon="star_border" />
  <Tab icon="favorite_border" />
  <Tab icon="mood" />
</TabBar>
<TabBar>
  <Tab stacked icon="star_border" label="Cookies" />
  <Tab stacked icon="favorite_border" label="Pizza" />
  <Tab stacked icon="mood" label="Icecream" />
</TabBar>
<TabBar>
  <Tab stacked restrictIndicator icon="star_border" label="Cookies" />
  <Tab stacked restrictIndicator icon="favorite_border" label="Pizza" />
  <Tab stacked restrictIndicator icon="mood" label="Icecream" />
</TabBar>
<TabBar>
  {/* Tabs automatically scroll with lots of content. */}
  <Tab>Cookies</Tab>
  <Tab>Pizza</Tab>
  <Tab>Icecream</Tab>
  <Tab>Chocolate</Tab>
  <Tab>Fishsticks</Tab>
  <Tab>Ratatouille</Tab>
  <Tab>Bread</Tab>
  <Tab>Rolls</Tab>
  <Tab>Sushi</Tab>
  <Tab>Cupcake</Tab>
  <Tab>Cheesecake</Tab>
</TabBar>

Transitions

<TabBar>
  <Tab>Cookies</Tab>
  <Tab>Pizza</Tab>
  <Tab>Icecream</Tab>
</TabBar>

Icons as Indicators

material-components-web has some light support for using icons as indicators (it's buried in their docs but there are no working examples or demos). Support has been added to PMWCS, but your mileage may vary since it will require quite a bit of manual positioning and styling. By default, the icons appear full size at the center of the tab, effectively making them overlay images.

<TabBar>
  <Tab iconIndicator="star">Cookies</Tab>
  <Tab iconIndicator="favorite">Pizza</Tab>
  <Tab iconIndicator="mood">Icecream</Tab>
</TabBar>
function IconIndicatorExample() {
  const style = {
    transformOrigin: 'center center',
    transform: 'translateY(1rem) scale(0.45)'
  };

  return (
    <TabBar>
      <Tab
        label="Cookies"
        iconIndicator={{
          icon: 'star',
          style: style
        }}
      />
      <Tab
        label="Pizza"
        iconIndicator={{
          icon: 'favorite',
          style: style
        }}
      />
      <Tab
        label="Icecream"
        iconIndicator={{
          icon: 'mood',
          style: style
        }}
      />
    </TabBar>
  );
}

TabBar

The TabBar component

Props

| Name | Type | Description | |------|------|-------------| | activeTabIndex | undefined \| number | The index of the active tab. | | foundationRef | React.Ref<MDCTabBarFoundation \| null> | Advanced: A reference to the MDCFoundation. | | indicatorTransition | "slide" \| "fade" | Specifies whether the indicator should slide or fade. Defaults to slide. | | onActivate | undefined \| (evt: TabBarOnActivateEventT) => void | Callback when the active tab changes. Receives event as an argument with event.target.value set to the activeTabIndex. evt.detail = { index: number; } |

Tab

A Tab component

Props

| Name | Type | Description | |------|------|-------------| | children | React.ReactNode | The label for the tab, passed as children. | | foundationRef | React.Ref<MDCTabFoundation \| null> | Advanced: A reference to the MDCFoundation. | | icon | PMWCS.IconPropT | The icon to use for the tab. | | iconIndicator | PMWCS.IconPropT | Optionally use a custom icon for the active indicator, instead of the underline. | | label | any | A label for the tab. | | minWidth | undefined \| false \| true | Indicates that the tab should shrink in size to be as narrow as possible without causing text to wrap. | | onInteraction | undefined \| (evt: TabOnInteractionEventT) => void | Fires when a tab has been interacted with. This is captures both keyboard and click events. evt.detail = { tabId: string } | | restrictIndicator | undefined \| false \| true | Restricts the indicator to the content | | stacked | undefined \| false \| true | Stacks the icon on top of the text label |