11'use client'
22
3- import styled from '@emotion/styled'
43import type {
54 ComponentProps ,
65 ElementType ,
@@ -15,96 +14,14 @@ import { Badge } from '../Badge'
1514import { Stack } from '../Stack'
1615import { Text } from '../Text'
1716import { Tooltip } from '../Tooltip'
17+ import {
18+ tabsBadge ,
19+ tabsBadgeContainer ,
20+ tabsButton ,
21+ tabsTextSelected ,
22+ } from './styles.css'
1823import { useTabsContext } from './TabsContext'
1924
20- const StyledBadge = styled ( Badge ) `
21- padding: 0 ${ ( { theme } ) => theme . space [ '1' ] } ;
22- margin-left: ${ ( { theme } ) => theme . space [ '1' ] } ;
23- `
24-
25- const StyledText = styled ( Text ) ``
26-
27- const StyledTooltip = styled ( Tooltip ) ``
28-
29- const BadgeContainer = styled . span `
30- margin-left: ${ ( { theme } ) => theme . space [ '1' ] } ;
31- display: flex;
32- `
33-
34- export const StyledTabButton = styled ( 'button' ) `
35- display: flex;
36- flex-direction: row;
37- padding: ${ ( { theme } ) => `${ theme . space [ '1' ] } ${ theme . space [ '2' ] } ` } ;
38- cursor: pointer;
39- justify-content: center;
40- align-items: baseline;
41- white-space: nowrap;
42- color: ${ ( { theme } ) => theme . colors . neutral . text } ;
43- text-decoration: none;
44- user-select: none;
45- touch-action: manipulation;
46- transition: color 0.2s;
47- border: none;
48- background: none;
49- border-bottom-width: 2px;
50- border-bottom-style: solid;
51- border-bottom-color: ${ ( { theme } ) => theme . colors . neutral . border } ;
52- outline: none;
53-
54- font-size: ${ ( { theme } ) => theme . typography . bodyStrong . fontSize } ;
55- font-family: ${ ( { theme } ) => theme . typography . bodyStrong . fontFamily } ;
56- font-weight: ${ ( { theme } ) => theme . typography . bodyStrong . weight } ;
57- letter-spacing: ${ ( { theme } ) => theme . typography . bodyStrong . letterSpacing } ;
58- line-height: ${ ( { theme } ) => theme . typography . bodyStrong . lineHeight } ;
59-
60- &:hover,
61- &:active,
62- &:focus {
63- text-decoration: none;
64- outline: none;
65- }
66-
67- &:focus-visible {
68- outline: auto;
69- }
70-
71- &[aria-selected='true'] {
72- color: ${ ( { theme } ) => theme . colors . primary . text } ;
73- border-bottom-color: ${ ( { theme } ) => theme . colors . primary . border } ;
74-
75- ${ StyledText } {
76- color: ${ ( { theme } ) => theme . colors . primary . text } ;
77- }
78- }
79-
80- &[aria-disabled='false']:not(:disabled) {
81- &:hover,
82- &:focus,
83- &:active {
84- outline: none;
85- color: ${ ( { theme } ) => theme . colors . primary . text } ;
86- border-bottom-color: ${ ( { theme } ) => theme . colors . primary . border } ;
87-
88- &[data-is-selected='false'] {
89- ${ StyledBadge } {
90- background-color: ${ ( { theme } ) => theme . colors . primary . background } ;
91- border-color: ${ ( { theme } ) => theme . colors . primary . background } ;
92- color: ${ ( { theme } ) => theme . colors . primary . text } ;
93- }
94- ${ StyledText } {
95- color: ${ ( { theme } ) => theme . colors . primary . text } ;
96- }
97- }
98- }
99- }
100-
101- &[aria-disabled='true'],
102- &:disabled {
103- cursor: not-allowed;
104- filter: grayscale(1) opacity(50%);
105- }
106- `
107-
10825type TabProps < T extends ElementType = 'button' > = {
10926 as ?: T
11027 badge ?: ReactNode
@@ -150,19 +67,19 @@ export const Tab = forwardRef(
15067 ) => {
15168 const { selected, onChange } = useTabsContext ( )
15269 const computedAs = as ?? 'button'
70+ const ComputedComponent = as ?? 'button'
15371 const isSelected = useMemo (
15472 ( ) => value !== undefined && selected === value ,
15573 [ value , selected ] ,
15674 )
15775
15876 return (
159- < StyledTooltip text = { tooltip } >
160- < StyledTabButton
77+ < Tooltip text = { tooltip } >
78+ < ComputedComponent
16179 aria-disabled = { disabled }
16280 aria-label = { value ? `${ value } ` : undefined }
16381 aria-selected = { isSelected }
164- as = { computedAs }
165- className = { className }
82+ className = { `${ className ? `${ className } ` : '' } ${ tabsButton } ` }
16683 data-is-selected = { isSelected }
16784 disabled = { computedAs === 'button' ? disabled : undefined }
16885 onClick = { event => {
@@ -186,31 +103,37 @@ export const Tab = forwardRef(
186103 < Stack alignItems = "center" direction = "row" >
187104 { children }
188105 { typeof counter === 'number' || typeof counter === 'string' ? (
189- < StyledBadge
106+ < Badge
107+ className = { tabsBadge }
190108 prominence = { isSelected ? 'strong' : 'default' }
191109 sentiment = { isSelected ? 'primary' : 'neutral' }
192110 size = "medium"
193111 >
194112 { counter }
195- </ StyledBadge >
113+ </ Badge >
114+ ) : null }
115+ { badge ? (
116+ < span className = { tabsBadgeContainer } > { badge } </ span >
196117 ) : null }
197- { badge ? < BadgeContainer > { badge } </ BadgeContainer > : null }
198118 </ Stack >
199119 { subtitle ? (
200120 < Stack direction = "row" >
201- < StyledText
121+ < Text
202122 as = "span"
123+ className = {
124+ tabsTextSelected [ isSelected ? 'selected' : 'default' ]
125+ }
203126 prominence = "weak"
204127 sentiment = "neutral"
205128 variant = "bodySmall"
206129 >
207130 { subtitle }
208- </ StyledText >
131+ </ Text >
209132 </ Stack >
210133 ) : null }
211134 </ Stack >
212- </ StyledTabButton >
213- </ StyledTooltip >
135+ </ ComputedComponent >
136+ </ Tooltip >
214137 )
215138 } ,
216139)
0 commit comments