2.0.1 • Published 2 years ago

@nozzlegear/react-win-pivot v2.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@nozzlegear/react-win-pivot

Screeshot of react-win-pivot

Installation

With Yarn:

yarn install @nozzlegear/react-win-pivot

Or from NPM:

npm install @nozzlegear/react-win-pivot --save

Importing

Import the component via ES6 import:

import { Pivot } from "@nozzlegear/react-win-pivot";
// or use default import
import Pivot from "@nozzlegear/react-win-pivot";

Example

import * as React from "react";
import { Pivot } from "../index";

type Tab = "First Tab" | "Second Tab" | "Third Tab";

const DEFAULT_TABS: Tab[] = [
    "First Tab",
    "Second Tab",
    "Third Tab",
]

function MyPivotComponent(): JSX.Element {
    const [selectedTab, setSelectedTab] = React.useState(DEFAULT_TABS[0]);

    return (
        <Pivot animate={true} tabs={DEFAULT_TABS} selectedTab={selectedTab} onChange={setSelectedTab}>
            <div>
                <h1>{`This is the ${selectedTab}.`}</h1>
            </div>
        </Pivot>
    )
}

Props

Note: This package has full TypeScript definitions! You should automatically receive intellisense for all of the props documented below:

NameTypeRequiredDescription
animatebooleanRequiredIndicates that the pivot should animate when it renders and each time the selected tab changes.
animationDuration?numberOptional, default 200The duration of the animation in milliseconds. Only used when animate is true.
tabsstring[]RequiredAn array of strings to be used as the name of the tabs, e.g. "Tab 1", "Tab 2".
selectedTabstringRequiredThe currently selected tab. Must be one of the string values from tabs.
onChange(newTab: string) => voidRequiredA function that's called when the user attempts to change the selected tab. Note that this is only a notification that the user wants to change the tab, it will not change itself.
childrenReact.ReactNodeRequiredContent to show in the Pivot's content area.

Styling

If you'd like to style the Pivot components yourself, you can change the following CSS variables with your own stylesheet:

NameDefault value
--pivot-tabs-font-familyinherit
--pivot-tabs-font-size24px
--pivot-tabs-font-colorrgba(0,0,0,.6)
--pivot-tabs-active-font-color#000
--pivot-tabs-padding20px 20px 20px 0
--pivot-tabs-column-gap20px
--pivot-tabs-border-width0 0 1px 0
--pivot-tabs-border-stylesolid
--pivot-tabs-border-color#ccc
--pivot-tabs-content-padding0
--pivot-tabs-slide-in-start-opacity0
--pivot-tabs-slide-in-end-opacity1
--pivot-tabs-slide-in-transitionall 0.1s ease-in-out
--pivot-tabs-slide-in-transformtranslate(0, 0)
--pivot-tabs-slide-in-from-left-transformtranslate(-100px, 0px)
--pivot-tabs-slide-in-from-right-transformtranslate(100px, 0px)
--pivot-tabs-slide-in-from-below-transformtranslate(0px, 100px)

Example:

.react-win-pivot {
    /* Change the padding of the tabs list */
    --pivot-tabs-padding: 40px 0;
    /* Change the css transition for animated tabs */
    --pivot-tabs-slide-in-transition: all 0.15s linear;
}