šŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →
Socket
Sign inDemoInstall
Socket

@rmwc/tabs

Package Overview
Dependencies
Maintainers
0
Versions
173
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rmwc/tabs

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

14.3.5
latest
Source
npm
Version published
Maintainers
0
Created
Source

Tabs

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

  • Module @rmwc/tabs
  • Import styles:
    • Using CSS Loader
      • import '@rmwc/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'
      • '@rmwc/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 RMWC, 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

NameTypeDescription
activeTabIndexnumberThe index of the active tab.
foundationRefRef<null | MDCTabBarFoundation<>>Advanced: A reference to the MDCFoundation.
indicatorTransition"slide" | "fade"Specifies whether the indicator should slide or fade. Defaults to slide.
onActivate(evt: TabBarOnActivateEventT) => voidCallback 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

NameTypeDescription
childrenReactNodeThe label for the tab, passed as children.
focusOnActivatebooleanFocuses the tab when activated. Defaults to true.
foundationRefRef<null | MDCTabFoundation<>>Advanced: A reference to the MDCFoundation.
iconIconPropTThe icon to use for the tab.
iconIndicatorIconPropTOptionally use a custom icon for the active indicator, instead of the underline.
labelanyA label for the tab.
minWidthbooleanIndicates that the tab should shrink in size to be as narrow as possible without causing text to wrap.
onInteraction(evt: TabOnInteractionEventT) => voidFires when a tab has been interacted with. This is captures both keyboard and click events. evt.detail = { tabId: string }
restrictIndicatorbooleanRestricts the indicator to the content
stackedbooleanStacks the icon on top of the text label

Keywords

rmwc

FAQs

Package last updated on 24 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts