1.16.0 • Published 5 months ago

@asphalt-react/content-switcher v1.16.0

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
5 months ago

Contentswitcher

Component to switch between 2 or more blocks of content, only one block of content is displayed at a time. Contentswitcher does not maintain any internal state, so to switch between content, state should be managed by parent. It is useful when you need to switch between content in more than one places in a single page.

Note: You can have maximum 3 Switchers in ContentSwitcher.

Usage

import React, { useState } from "react"
import ContentSwitcher, { Switch } from "@asphalt-react/content-switcher"

function App() {
  const [active, setActive] = useState(0)
  const clickHandler = (event, active) => setActive(active)
  return (
    <main>
      <ContentSwitcher active={active} onAction={clickHandler}>
        <Switch value={0}>First</Switch>
        <Switch value={1}>Second</Switch>
      </ContentSwitcher>
      <div>
        {active === 0 ? <div>First Section</div> : <div>Second Section</div>}
      </div>
    </main>
  )
}

export default App

Props

children

Blocks of contents to switch between

typerequireddefault
nodetrueN/A

active

Index of the active Switch

typerequireddefault
enumfalse0

onAction

Function to be called when active Switch changes

typerequireddefault
funcfalseN/A

Switch

Props

children

Label of content to switch between

typerequireddefault
stringtrueN/A

value

Index of the Switch

typerequireddefault
enumtrueN/A