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-material-tabs

v0.0.8

Published

A simple React package that provides the Material Design tab component.

Downloads

10

Readme

forked from oliverfencott/material-tabs, only change so far is compatibility with react 16

material-tabs

What is it?

A simple React package that provides the Material Design tab component.

This is what they look like:

demo

Gifs, because open source, because Internet.

Get started

npm install --save material-tabs

Example

The code in the above example looks like:


import {TabGroup, Tab} from 'material-tabs';

const tabs = [
  {linkTo: 'dashboard', label: 'Dashboard'},
  {linkTo: 'downloads', label: 'Downloads'},
  {linkTo: 'uploads', label: 'Uploads'},
  {linkTo: 'totalStats', label: 'Stats'},
  {linkTo: 'account', label: 'Account'}
];

const Layout = React.createClass({
  render: function() {
    return (
      <div>
        <div style={{backgroundColor: '#212121'}}>
          <div style={{width: 700}}>
            <TabGroup style={{indicator: {color: '#2196f3'}}}>
              {this.renderTabs()}
            </TabGroup>
          </div>
        </div>

      // Rest of layout

      </div>
    );
  },

  renderTabs: function() {
    return tabs.map((tab, index) => {
      return (
        <UnstyledLink to={tab.linkTo} key={index}>
          <Tab>
            {tab.label}
          </Tab>
        </UnstyledLink>
      );
    });
  }
});

Components

The package provides 2 components: Tab and TabGroup, used together like so:

import {Tab, TabGroup} from 'material-tabs';

const NavigationTabs = React.createClass({
  render: function() {
    return (
      <TabGroup>
        <Tab>
          One
        </Tab>
        <Tab>
          Two
        </Tab>
      </TabGroup>
    );
  }
)};

The following aspects are determined as a result of the number of children TabGroup has:

  • The position of the indicator (underline), highlighting which tab was clicked and
  • The width of each Tab.

Meaning each Tab will always be identical in width.

TabGroup

By default, the following styles are applied:

  • TabGroup is 100% width of it's parent,
  • The indicator is #FFFFFF (white).
  • Background colors are default (inherit).

TabGroup accepts the following style prop:

style={{ indicator: { color: '#FF5722' } }}

TabGroup accepts an onChangeTab prop which passes the index of the newly selected Tab back up, used like so:

render: function() {
  return (
    <TabGroup onChangeTab={this.handleChange}>
      <Tab>
        One
      </Tab>
      <Tab>
        Two
      </Tab>
    </TabGroup>
  );
},

handleChange: function(index) {
  console.log(index); // 1
}

It also accepts a defaultSelectedTab prop, which should be the index of the tab to be selected on initial render, which by default is of course 0. This would be used to make sure the correct tab is selected when arriving from an external link.

Because the TabGroup component only cares about how many children it has (as opposed to what the children are), it's very easy to use the Tabs nested inside links (such as when using the very excellent and highly recommended React-router). For example:

render: function() {
  return (
    <TabGroup>
      <Link to='home'>
        <Tab>
          Home
        </Tab>
      </Link>
      <Link to='favourites'>
        <Tab>
          Favourites
        </Tab>
      </Link>
    </TabGroup>
  );
}

will render exactly the same without links (save for default link styling).

Tab

By default, the following styles are applied:

  • The currently selected Tab text color is #FFFFFF (white),
  • Unselected Tabs are the same color, with an opacity of 0.7 applied,
  • Background colors are default (inherit).

All other styles follow the spec, such as text styling, spacing, heights, and animation.

Tab accepts the following style prop:

style={{ color: '#FF5722' }}

Tab accepts a regular onClick prop as you would expect.

Todo