Start sharing components as a team!Share components as a team!Join Bit to build your applications faster.Get Started Free

tabbar

v1.0.4arrow_drop_down
v1.0.4
v1.0.2
v1.0.1
v1.0.0
STATUS
Passing
DOWNLOADS
69
LICENSE
MIT
VISIBILITY
Public
PUBLISHED
A year ago
SIZE
21 KB
Styled tabs component
1 contributor
Install tabbar as a package?
Copied
npm i @bit/sanzhardanybayev.ui-components.tabbar
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.dev
TabBar.jsx
87 Lines(63 sloc)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import React, {useState} from 'react';
import PropTypes from 'prop-types'
import styled from 'styled-components'


const TabsContainer = styled.ul`
    overflow: unset;
    border: 1px solid #c4cdd7;
    border-radius: 25px;
    padding: 5px 4px;
    
    list-style-type: none;
    display: block;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    
    font-family: Roboto, sans-serif;
    
`
const Tab = styled.li`
    min-width: 120px;
    text-align: center;
    position: relative;
    
    z-index: 1;
    margin: 0;
    border: unset;
    border-radius: 25px;
    padding: 6px 15px;
    font-size: 14px;
    line-height: 2;
    color: #c4cdd7;
    text-transform: initial;
    background-color: unset;
    transition: color 0.4s;
    display: inline-block;
    
    &:hover{
        color: #F42958 !important;
        cursor: pointer;
    }
    
    &.active{
        box-shadow: 0px 15px 39px rgba(0, 0, 0, 0.2);
        background-color: #ffffff; 
        color: #F42958;
    }
`

/**
 * @description Styled tabs component
 * @property firstTab - First tab's text
 * @property secondTab - Second tab's text
 * @property activeIndex - returns active tab's index
 * @returns {*}
 * @constructor
 */

const TabBar = ({firstTab, secondTab, activeIndex}) => {

    const [tabIndex, toggle] = useState(0);

    return (
        <TabsContainer>
            <Tab className={!tabIndex ? 'active' : ''} onClick={() => toggle(0) && activeIndex(0)}>
                {firstTab}
            </Tab>
            <Tab className={tabIndex ? 'active' : ''} onClick={() => toggle(1) && activeIndex(1)}>
                {secondTab}
            </Tab>
        </TabsContainer>
    );
};

TabBar.defaultProps = {
    firstTab: 'Отправителям',
    secondTab: 'Курьерам'
}

TabBar.propTypes = {
    firstTab: PropTypes.string.isRequired,
    secondTab: PropTypes.string.isRequired,
    activeIndex: PropTypes.func
};


export default TabBar;