Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-tabs-scrollable

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-tabs-scrollable

a simple react scrollable tabs with a lot of additional features and with fully supporting of RTL mode

  • 1.0.10
  • npm
  • Socket score

Version published
Weekly downloads
3.3K
decreased by-36.76%
Maintainers
1
Weekly downloads
 
Created
Source

react-tabs-scrollable

a simple react scrollable tabs with a lot of additional features and with fully supporting of RTL mode

NPM JavaScript Style Guide

Install

npm install --save react-tabs-scrollable
yarn add react-tabs-scrollable

Demo

Demo

Features

  • Easy to start with it takes you less than minute to start it up!
  • It has many features and so easy to customize
  • Fully support for RTL (actually the reason why I built this component is because RTL)
  • Fully accessible
  • You can control in literally everything inside it
  • Small size 8k and 3.1k gzipped
  • Great to use in navigation , menus and lists or any proper use for tabs
  • Easy to style , you have the css file so you can edit it as you would like
  • And much more ..

Usage

import React from 'react'
import { Tabs, Tab } from 'react-tabs-scrollable'
import 'react-tabs-scrollable/dist/rts.css'

const SimpleTabs = () => {
  // define state with initial value to let the tabs start with that value
  const [activeTab, setActiveTab] = React.useState(1)

  // define a onClick function to bind the value on tab click
  const onTabClick = (e, index) => {
    console.log(e)
    setActiveTab(index)
  }

  return (
    <Tabs activeTab={activeTab} onTabClick={onTabClick}>
      {/* generating an array to loop through it  */}
      {[...Array(20).keys()].map((item) => (
        <Tab key={item}>Tab {item}</Tab>
      ))}
    </Tabs>
  )
}

export default SimpleTabs

Full example with all features

<Tabs
  // the selected tab state which must be passed to the commponent
  activeTab={activeTab}
  // tab on click function
  // it has two props
  // first one is event object
  // second one is the index of the selected tab
  onTabClick={(val) => console.log(val)}
  // this prop returns a group of events to control the tabs such as onLeftBtnClick , onRightBtnClick to control the tabs
  // you should pass here a ref to get the required functionality
  action={tabRef}
  // sets if the direction of the page is RTL or not
  // default false
  isRTL={false}
  // sets if the tabs reached the end point of the tab container
  // function
  didReachEnd={(val) => console.log(val)}
  // sets if the tabs reached the start point container
  // function
  didReachStart={(val) => console.log(val)}
  // sets how many tabs you want to scroll on every move
  // default 3 tabs on each navigation button click
  tabsScrollAmount={3}
  // sets the general animation duration when you click on the navigation buttons and when you click out the tabs view
  // this option will disable navBtnCLickAnimationDuration and selectedAnimationDuration
  // default 300s
  animationDuration={300}
  // sets the animation of the scroll when you click on the navigation buttons
  // note : this will overwirte the animationDuration value
  // default 300s
  navBtnCLickAnimationDuration={300}
  // sets the animation of the scroll when you click on a tab that is out of the view
  // note : this will overwirte the animationDuration value
  // default 300s
  selectedAnimationDuration={300}
  // sets the right navitgation vutton icon
  // default feather arrow-right svg icon
  // you can pass jsx here or just a string
  rightBtnIcon={'>'}
  // sets the left navitgation button icon
  // default feather arrow-left svg icon
  // you can pass jsx here or just a string
  leftBtnIcon={'<'}
  //hides the navigantion button
  // default false
  hideNavBtns={false}
  // hides the navigation buttons on mobile devices
  // default true
  hideNavBtnsOnMobile={true}
  // shows the scroll of the tabs
  // default false
  showTabsScroll={false}
  // sets the color of navigation buttons if you dont want to use your own
  // it just changes the stroke color of the svg icon
  // you cant use this option if you used your own btns
  // or you can customize it using css
  navBtnsIconColor={'HEX'}
  // gets the coordinates of the selected tab
  // returns object of the width and the scrollLeft of the selected tab
  // be careful when you use state with this function it will be triggered on every scroll movement and when the app rerenders
  selectedTabCoordinates={(val) => console.log(val)}
>
  <Tab>item </Tab>
  {[...Array(20).keys()].map((tab) => (
    <Tab key={tab}>Tab {tab}</Tab>
  ))}
</Tabs>

API

NameDefaultTypeDescription
activeTab* -integerthe selected tab value which must be passed to the commponent
onTabClick*-function function(event, value) => void callback function fires on tab click. It has two props, the first on is the event object the second on is the selected tab value
action-refreact ref fired when the component mounts. It's useful if you want to some functionalities programmatically. It supports 4 function :
onLeftBtnClick ,onRightBtnClick, goToStart, goToEnd

onLeftBtnClick : to control the left btn click and use your own navigation button. you can call it by so ref.onLeftBtnClick()

onRightBtnClick : to control the right btn click and use your own navigation button. you can call it by so ref.onRightBtnClick()

goToStart : to control the tabs to go to the start of the tabs container. you can call it by so ref.goToStart()

goToEnd : to control the tabs to go to the end of the tabs container. you can call it by so ref.goToEnd()
isRTLfalseboolean sets if the direction of the tabs is RTL or not
didReachEnd-function sets if the tabs reached the end point of the container didReachEnd={(val) => console.log(val)}
didReachStart-function sets if the tabs reached the start point of the container didReachStart={(val) => console.log(val)}
tabsScrollAmount3string | integer sets how many tabs you want to scroll on every move tabsScrollAmount={3}
animationDuration300s integer sets the animation duration of the scroll when you click on the navigation buttons note : this will overwirte the animationDuration value animationDuration={300}
navBtnCLickAnimationDuration300s integer sets the animation of the scroll when you click on the navigation buttons note : this will overwirte the animationDuration value navBtnCLickAnimationDuration={300}
selectedAnimationDuration300s integer sets the animation of the scroll when you click on a tab that is out of the view note : this will overwirte the animationDuration value selectedAnimationDuration={300}
rightBtnIconfeather arrow-right svg icon string | jsx sets the right navitgation button icon rightBtnIcon={'>'}
leftBtnIconfeather arrow-left svg icon string | jsx sets the left navitgation button icon leftBtnIcon={'>'}
hideNavBtnsfalse boolean hides the navigantion button hideNavBtns={false}
hideNavBtnsOnMobiletrue boolean hides the navigation buttons on mobile devices
showTabsScrollfalse boolean shows the scroll of the tabsn
selectedTabCoordinates- function gets the coordinates of the selected tab returns object of the width and the scrollLeft of the selected tab be careful when you use state with this function it will be triggered on every scroll movement and when the app rerenders selectedTabCoordinates={(val) => console.log(val)}
// val returns {width : float , left : float}
// the left turns into right when isRTL={true}

you can see all the examples in the Demo

please let me see your reviews and if there're any features you want me to add to them

License

MIT © Mohammed Aliwi

Keywords

FAQs

Package last updated on 14 Jan 2023

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc