1
- import type { ForwardRefComponent as PolymorphicForwardRefComponent } from '../utils/polymorphic'
2
1
import { clsx } from 'clsx'
3
2
import type { To } from 'history'
4
3
import React , { useRef , useState } from 'react'
5
- import styled from 'styled-components'
6
- import { get } from '../constants'
7
4
import { FocusKeys , useFocusZone } from '../hooks/useFocusZone'
8
5
import type { SxProp } from '../sx'
9
- import sx from '../sx'
10
6
import type { ComponentProps } from '../utils/types'
11
- import getGlobalFocusStyles from '../internal/utils/getGlobalFocusStyles'
12
7
13
- const ITEM_CLASS = 'TabNav-item'
14
- const SELECTED_CLASS = 'selected'
15
-
16
- const TabNavBase = styled . div < SxProp > `
17
- ${ sx }
18
- `
19
-
20
- const TabNavTabList = styled . div `
21
- display: flex;
22
- margin-bottom: -1px;
23
- overflow: auto;
24
- `
25
-
26
- const TabNavNav = styled . nav `
27
- margin-top: 0;
28
- border-bottom: 1px solid ${ get ( 'colors.border.default' ) } ;
29
- `
8
+ import styles from './TabNav.module.css'
9
+ import { BoxWithFallback } from '../internal/components/BoxWithFallback'
30
10
31
11
/**
32
12
* @deprecated
33
13
*/
34
- export type TabNavProps = ComponentProps < typeof TabNavBase >
14
+ export type TabNavProps = ComponentProps < typeof BoxWithFallback >
35
15
36
16
/**
37
17
* @deprecated
@@ -73,11 +53,13 @@ function TabNav({children, 'aria-label': ariaLabel, ...rest}: TabNavProps) {
73
53
)
74
54
75
55
return (
76
- < TabNavBase { ...rest } ref = { navRef as React . RefObject < HTMLDivElement > } >
77
- < TabNavNav aria-label = { ariaLabel } >
78
- < TabNavTabList role = "tablist" > { children } </ TabNavTabList >
79
- </ TabNavNav >
80
- </ TabNavBase >
56
+ < BoxWithFallback { ...rest } ref = { navRef as React . RefObject < HTMLDivElement > } >
57
+ < nav aria-label = { ariaLabel } className = { styles . TabNavNav } >
58
+ < div role = "tablist" className = { styles . TabNavTabList } >
59
+ { children }
60
+ </ div >
61
+ </ nav >
62
+ </ BoxWithFallback >
81
63
)
82
64
}
83
65
@@ -88,44 +70,30 @@ export type TabNavLinkProps = React.DetailedHTMLProps<React.HTMLAttributes<HTMLA
88
70
to ?: To
89
71
selected ?: boolean
90
72
href ?: string
73
+ className ?: string
74
+ as ?: React . ElementType | 'a' | 'button' | 'div'
75
+ disabled ?: boolean
91
76
} & SxProp
92
77
93
78
/**
94
79
* @deprecated
95
80
*/
96
- const TabNavLink = styled . a . attrs < TabNavLinkProps > ( props => ( {
97
- className : clsx ( ITEM_CLASS , props . selected && SELECTED_CLASS , props . className ) ,
98
- role : 'tab' ,
99
- 'aria-selected' : ! ! props . selected ,
100
- tabIndex : - 1 ,
101
- } ) ) < TabNavLinkProps > `
102
- padding: 8px 12px;
103
- font-size: ${ get ( 'fontSizes.1' ) } ;
104
- line-height: 20px;
105
- color: ${ get ( 'colors.fg.default' ) } ;
106
- text-decoration: none;
107
- background-color: transparent;
108
- border: 1px solid transparent;
109
- border-bottom: 0;
110
-
111
- ${ getGlobalFocusStyles ( '-6px' ) } ;
112
-
113
- &:hover,
114
- &:focus {
115
- color: ${ get ( 'colors.fg.default' ) } ;
116
- text-decoration: none;
117
- }
118
-
119
- &.selected {
120
- color: ${ get ( 'colors.fg.default' ) } ;
121
- border-color: ${ get ( 'colors.border.default' ) } ;
122
- border-top-right-radius: ${ get ( 'radii.2' ) } ;
123
- border-top-left-radius: ${ get ( 'radii.2' ) } ;
124
- background-color: ${ get ( 'colors.canvas.default' ) } ;
125
- }
126
-
127
- ${ sx } ;
128
- ` as PolymorphicForwardRefComponent < 'a' , TabNavLinkProps >
81
+ const TabNavLink = React . forwardRef < HTMLAnchorElement , TabNavLinkProps > ( function TabNavLink (
82
+ { selected, className, as = 'a' , ...rest } : TabNavLinkProps ,
83
+ ref ,
84
+ ) {
85
+ return (
86
+ < BoxWithFallback
87
+ as = { as }
88
+ ref = { ref }
89
+ role = "tab"
90
+ tabIndex = { - 1 }
91
+ aria-selected = { selected ? true : undefined }
92
+ className = { clsx ( 'TabNav-item' , styles . TabNavLink , selected && 'selected' , selected && styles . Selected , className ) }
93
+ { ...rest }
94
+ />
95
+ )
96
+ } )
129
97
130
98
TabNavLink . displayName = 'TabNav.Link'
131
99
0 commit comments