1.0.0 • Published 11 months ago

@element-public/react-tabs v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
11 months ago

TabBar

Description

Tabs organize content across different screens, data sets, and other interactions. The Tab Bar contains the Tab Scroller and Tab components.

See live demos on storybook

Storybook TabBar Demos

Install bundle from npm-e

npm i @element-public/react-components @element-public/themes

Optional: install the component individually

npm i @element-public/react-tabs @element-public/themes

Open ~/.npmrc in an editor and add the following line to enable the @element-public scope:

@element-public:registry=https://npm.platforms.engineering

Troubleshooting

See below if you have never installed a package from Bayer's npm-enterprise or run into the following error:

npm ERR! code E401
npm ERR! Unable to authenticate, your authentication token seems to be invalid.
npm ERR! To correct this please trying logging in again with:
npm ERR!     npm login

Setup an access token

See the devtools npm-e guide to learn how to create an access token if this is the first time you are using a npm-e package at Bayer or you do not have a line that starts with the following in your ~/.npmrc file:

//npm.platforms.engineering/:_authToken=

Notes

Scroller Alignment

The align modifier classes are only applicable when the contents do not meet or exceed the width of the Tab Scroller and Tab Bar (i.e., most commonly, when minWidth is used on each tab).

Indicator Types and Transitions

The Tab Indicator may be represented in one of two ways:

  • Underline, indicated by underline
  • Icon, indicated by the presence of an icon

NOTE: One of these classes must be applied to the Tab Indicator's content element.

The Tab Indicator may transition in one of two ways:

  • Slide, the default behavior
  • Fade, indicated by the fade prop

When set to "fade" the tab indicator will fade in on activation and fade out on deactivation.

Indicator Size

By default the Tab Indicator will span the entire tab. Alternatively, the tab indicator can be set up to span only the content of the tab if it is instead placed within the mdc-tab__content element of mdc-tab. This behavior is controlled by Tab or another parent component.

Tab Bar Props

NameTypeDefaultRequiredDescription
activeTabIndexnumber0falseIndex of the currently active tab.
classNamestringundefinedfalseThe css class name to be passed through to the component markup.
clusterAlignstring'start'falseClustered tabs can be aligned to 'start', 'center', or 'end'. Requires one or more tabs to have clustered set to true.Accepted Values: start, center, end
clusteredbooleanfalsefalseIndicates that tabs should shrink in size to be as narrow as possible without causing text to wrap.
elevatedbooleanfalsefalseApply elevated styles to raise the tab-bar above standard content.
stackedbooleanfalsefalseIndicates that the tab icon and label should flow vertically instead of horizontally.
variantstring'surface'falseBackground theme color. Accepts one of 'primary', 'secondary', or 'surface'.Accepted Values: primary, secondary, surface

Tab Bar Deprecated Props

NameTypeDefaultRequiredDeprecatedDescription
raisedbooleanundefinedfalsePlease use elevated instead.Apply a raised style.
scrollablebooleanundefinedfalseDeprecated, containers will scroll when necessary.Create a fixed height scrollable container.

Tab Bar Render Props

NameTypeDefaultRequiredDescription
childrenReact.ReactNodenullfalseAccepts one or more Tab components.

Tab Bar Events

NameDefaultRequiredParamsDescription
onTabActivatedundefinedfalseFires when switching to a different tab.

Tab Props

NameTypeDefaultRequiredDescription
activebooleanundefinedfalseIndicates that the tab is active.
badgestring|function|React.ReactNodeundefinedfalseThe custom tab notification badge to be rendered.
classNamestringundefinedfalseThe css class name to be passed through to the component markup.
clusteredbooleanfalsefalseIndicates that the tab should shrink in size to be as narrow as possible without causing text to wrap.
indicatorIconstringnullfalseAn icon to be used as the tab indicator. Accepts the name of any valid material icon (see Icon component documentation for a list of valid icons). If no icon is provided the tab-indicator will use an underline.
indicatorSizestring'full'falseThe tab-indicator will span the entire tab with 'full' or only the content of the tab with 'content'.Accepted Values: full, content
indicatorTransitionstring'slide'falseThe tab-indicator will use a 'slide' or 'fade' transition between tabs.Accepted Values: slide, fade
stackedbooleanfalsefalseIndicates that the tab icon and label should flow vertically instead of horizontally. If stacked is true the tab will not show a badge. You can place the badge on the leading icon.

Tab Render Props

NameTypeDefaultRequiredDescription
childrenReact.ReactNodenullfalseThe displayed content. Expects a valid string, though will accept any valid components or markup. If label and children are both set, label will take priority.
iconReact.ReactNodeundefinedfalseAdd a leading icon to the tab.
labelReact.ReactNodenullfalseThe displayed text. Expects a valid string. If label and children are both set, label will take priority.

Tab Indicator Props

NameTypeDefaultRequiredDescription
activebooleanfalsefalseVisually activates the indicator.
iconstringnullfalseThe tab-indicator will use an underline if no icon is provided.
transitionstring'slide'falseThe Tab Indicator will use a 'slide' or 'fade' transition between tabs.

Tab Scroller Props

NameTypeDefaultRequiredDescription
alignstring'start'falseClustered tabs can be aligned to 'start', 'center', or 'end'.Accepted Values: start, center, end

Tab Scroller Render Props

NameTypeDefaultRequiredDescription
childrenReact.ReactNodenullfalseAccepts Tab components.