Skip to content

Commit 7ea4722

Browse files
committed
feat: Tabs - Add links variant
- add variant="links" with larger padding and no background - use a 2px bottom shadow for hover and active states - expose tabsInnerClassName for scroll inner styling - mark active tab with class for links-variant styles
1 parent dada074 commit 7ea4722

3 files changed

Lines changed: 47 additions & 9 deletions

File tree

src/components/Tabs/Tabs.styl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,32 @@ div .inactive
1616
.tab
1717
flex-shrink 0
1818
white-space nowrap
19+
20+
.variant-links
21+
& > button
22+
&:not(:first-child)
23+
margin-left 0
24+
border-radius inherit
25+
&:not(:last-child)
26+
border-radius inherit
27+
28+
.tab
29+
padding var(--p-3) var(--p-5)
30+
background-color transparent !important
31+
box-shadow none
32+
33+
&:hover
34+
&:focus
35+
background-color transparent !important
36+
box-shadow 0 2px 0 0 var(--active-color-alpha-100)
37+
38+
.tab.active
39+
color inherit
40+
background-color transparent !important
41+
box-shadow 0 2px 0 0 var(--active-color)
42+
43+
&:hover
44+
&:focus
45+
color inherit
46+
background-color transparent !important
47+
box-shadow 0 2px 0 0 var(--active-color)

src/components/Tabs/Tabs.tsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
import { useCallback, useEffect, useRef, useState } from 'react';
1+
import * as T from './Tabs.types';
22

3-
import cn from 'classnames';
3+
import { useCallback, useEffect, useRef, useState } from 'react';
44

5-
import { Scroll } from '../Scroll/Scroll';
65
import { Button } from '../Button/Button';
76
import { ButtonGroup } from '../ButtonGroup/ButtonGroup';
8-
9-
import * as T from './Tabs.types';
107
import S from './Tabs.styl';
8+
import { Scroll } from '../Scroll/Scroll';
9+
import cn from 'classnames';
1110

1211
const isId = id => ['string', 'number'].includes(typeof id);
1312

1413
export function Tabs(props: T.Props) {
1514
const {
1615
size = 'm',
16+
variant = 'default',
1717
className,
1818
tabsWrapperClassName,
19+
tabsInnerClassName,
1920
tabsClassName,
2021
contentClassName,
2122
items,
@@ -87,7 +88,7 @@ export function Tabs(props: T.Props) {
8788
return (
8889
<Button
8990
{...rest}
90-
className={cn(S.tab, rest.className)}
91+
className={cn(S.tab, isActive && S.active, rest.className)}
9192
size={size}
9293
key={id}
9394
onClick={e => onTabClick(e, params)}
@@ -104,12 +105,18 @@ export function Tabs(props: T.Props) {
104105
x
105106
offset={{ x: { before: 10, after: 10 } }}
106107
className={tabsWrapperClassName}
107-
innerClassName={cn(S.tabsScroll, S[`size-${size}`])}
108+
innerClassName={cn(S.tabsScroll, S[`size-${size}`], tabsInnerClassName)}
108109
autoHide
109110
fadeSize={size}
110111
size={size}
111112
>
112-
<ButtonGroup className={tabsClassName} {...rest}>
113+
<ButtonGroup
114+
className={cn(
115+
variant === 'links' && S['variant-links'],
116+
tabsClassName
117+
)}
118+
{...rest}
119+
>
113120
{tabsButtons}
114121
</ButtonGroup>
115122
</Scroll>

src/components/Tabs/Tabs.types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Size } from 'uilib/types';
21
import { ButtonProps } from '../Button/Button';
32
import { ReactNode } from 'react';
3+
import { Size } from 'uilib/types';
44

55
type ID = string | number;
66

@@ -21,8 +21,10 @@ export type RenderProps = {
2121

2222
export type Props = {
2323
size?: Size;
24+
variant?: 'default' | 'links';
2425
className?: string;
2526
tabsWrapperClassName?: string;
27+
tabsInnerClassName?: string;
2628
tabsClassName?: string;
2729
contentClassName?: string;
2830
items: Item[];

0 commit comments

Comments
 (0)