1
1
import { clsx } from 'clsx'
2
2
import type { To } from 'history'
3
3
import React from 'react'
4
- import styled from 'styled-components'
5
- import { get } from '../constants'
6
- import type { SxProp } from '../sx'
7
- import sx from '../sx'
8
4
import type { ComponentProps } from '../utils/types'
9
- import { toggleStyledComponent } from '../internal/utils/toggleStyledComponent'
10
- import { useFeatureFlag } from '../FeatureFlags'
11
5
12
6
import styles from './SubNav.module.css'
13
-
14
- const CSS_MODULES_FEATURE_FLAG = 'primer_react_css_modules_ga'
7
+ import { defaultSxProp } from '../utils/defaultSxProp'
8
+ import type { SxProp } from '../sx'
9
+ import Box from '../Box'
15
10
16
11
type StyledSubNavProps = React . ComponentProps < 'nav' > & {
17
12
actions ?: React . ReactNode
@@ -20,150 +15,90 @@ type StyledSubNavProps = React.ComponentProps<'nav'> & {
20
15
label ?: string
21
16
} & SxProp
22
17
type StyledSubNavLinksProps = React . ComponentProps < 'div' > & SxProp
23
- type StyledSubNavLinkProps = React . ComponentProps < 'a' > & SxProp & { to ?: To ; selected ?: boolean }
24
-
25
- // SubNav
26
-
27
- const StyledSubNav = toggleStyledComponent (
28
- CSS_MODULES_FEATURE_FLAG ,
29
- 'nav' ,
30
- styled . nav < SxProp > `
31
- display: flex;
32
- justify-content: space-between;
33
-
34
- .SubNav-body {
35
- display: flex;
36
- margin-bottom: -1px;
37
-
38
- > * {
39
- margin-left: ${ get ( 'space.2' ) } ;
40
- }
41
-
42
- > *:first-child {
43
- margin-left: 0;
44
- }
45
- }
46
-
47
- .SubNav-actions {
48
- align-self: center;
49
- }
50
-
51
- ${ sx } ;
52
- ` ,
53
- )
18
+ type StyledSubNavLinkProps = React . ComponentProps < 'a' > & { to ?: To ; selected ?: boolean } & SxProp
54
19
55
20
const SubNav = React . forwardRef < HTMLElement , StyledSubNavProps > ( function SubNav (
56
- { actions, className, children, label, ...rest } ,
21
+ { actions, className, children, label, sx : sxProp = defaultSxProp , ...rest } ,
57
22
forwardRef ,
58
23
) {
59
- const enabled = useFeatureFlag ( CSS_MODULES_FEATURE_FLAG )
24
+ if ( sxProp !== defaultSxProp ) {
25
+ return (
26
+ < Box
27
+ as = "nav"
28
+ ref = { forwardRef }
29
+ sx = { sxProp }
30
+ className = { clsx ( className , 'SubNav' , styles . SubNav ) }
31
+ aria-label = { label }
32
+ { ...rest }
33
+ >
34
+ < div className = { clsx ( 'SubNav-body' , styles . Body ) } > { children } </ div >
35
+ { actions && < div className = { clsx ( 'SubNav-actions' , styles . Actions ) } > { actions } </ div > }
36
+ </ Box >
37
+ )
38
+ }
60
39
return (
61
- < StyledSubNav
62
- ref = { forwardRef }
63
- className = { clsx ( className , 'SubNav' , { [ styles . SubNav ] : enabled } ) }
64
- aria-label = { label }
65
- { ...rest }
66
- >
67
- < div className = { clsx ( 'SubNav-body' , { [ styles . Body ] : enabled } ) } > { children } </ div >
68
- { actions && < div className = { clsx ( 'SubNav-actions' , { [ styles . Actions ] : enabled } ) } > { actions } </ div > }
69
- </ StyledSubNav >
40
+ < nav ref = { forwardRef } className = { clsx ( className , 'SubNav' , styles . SubNav ) } aria-label = { label } { ...rest } >
41
+ < div className = { clsx ( 'SubNav-body' , styles . Body ) } > { children } </ div >
42
+ { actions && < div className = { clsx ( 'SubNav-actions' , styles . Actions ) } > { actions } </ div > }
43
+ </ nav >
70
44
)
71
45
} )
72
46
SubNav . displayName = 'SubNav'
73
47
74
48
// SubNav.Links
75
49
76
- const StyledSubNavLinks = toggleStyledComponent (
77
- CSS_MODULES_FEATURE_FLAG ,
78
- 'div' ,
79
- styled . div < SubNavLinksProps > `
80
- display: flex;
81
- ${ sx } ;
82
- ` ,
50
+ const SubNavLinks = React . forwardRef < HTMLDivElement , StyledSubNavLinksProps > (
51
+ ( { children, className, sx : sxProp = defaultSxProp , ...rest } , forwardRef ) => {
52
+ if ( sxProp !== defaultSxProp ) {
53
+ return (
54
+ < Box as = "div" ref = { forwardRef } sx = { sxProp } className = { clsx ( className , styles . Links ) } { ...rest } >
55
+ { children }
56
+ </ Box >
57
+ )
58
+ }
59
+ return (
60
+ < div ref = { forwardRef } className = { clsx ( className , styles . Links ) } { ...rest } >
61
+ { children }
62
+ </ div >
63
+ )
64
+ } ,
83
65
)
84
-
85
- const SubNavLinks = React . forwardRef < HTMLElement , StyledSubNavLinksProps > ( function SubNavLink (
86
- { children, className, ...rest } ,
87
- forwardRef ,
88
- ) {
89
- const enabled = useFeatureFlag ( CSS_MODULES_FEATURE_FLAG )
90
- return (
91
- < StyledSubNavLinks ref = { forwardRef } className = { clsx ( className , enabled && styles . Links ) } { ...rest } >
92
- { children }
93
- </ StyledSubNavLinks >
94
- )
95
- } )
96
66
SubNavLinks . displayName = 'SubNav.Links'
97
67
98
68
// SubNav.Link
99
69
100
- const StyledSubNavLink = toggleStyledComponent (
101
- CSS_MODULES_FEATURE_FLAG ,
102
- 'a' ,
103
- styled . a . attrs < StyledSubNavLinkProps > ( props => ( {
104
- className : clsx ( 'SubNav-item' , props . selected && 'selected' , props . className ) ,
105
- } ) ) < StyledSubNavLinkProps > `
106
- padding-left: ${ get ( 'space.3' ) } ;
107
- padding-right: ${ get ( 'space.3' ) } ;
108
- font-weight: ${ get ( 'fontWeights.semibold' ) } ;
109
- font-size: ${ get ( 'fontSizes.1' ) } ;
110
- line-height: 20px; //custom value for SubNav
111
- min-height: 34px; //custom value for SubNav
112
- color: ${ get ( 'colors.fg.default' ) } ;
113
- text-align: center;
114
- text-decoration: none;
115
- border-top: 1px solid ${ get ( 'colors.border.default' ) } ;
116
- border-bottom: 1px solid ${ get ( 'colors.border.default' ) } ;
117
- border-right: 1px solid ${ get ( 'colors.border.default' ) } ;
118
- display: flex;
119
- align-items: center;
120
-
121
- &:first-of-type {
122
- border-top-left-radius: ${ get ( 'radii.2' ) } ;
123
- border-bottom-left-radius: ${ get ( 'radii.2' ) } ;
124
- border-left: 1px solid ${ get ( 'colors.border.default' ) } ;
125
- }
126
-
127
- &:last-of-type {
128
- border-top-right-radius: ${ get ( 'radii.2' ) } ;
129
- border-bottom-right-radius: ${ get ( 'radii.2' ) } ;
130
- }
131
-
132
- &:hover,
133
- &:focus {
134
- text-decoration: none;
135
- background-color: ${ get ( 'colors.canvas.subtle' ) } ;
136
- transition: background-color 0.2s ease;
70
+ const SubNavLink = React . forwardRef < HTMLAnchorElement , StyledSubNavLinkProps > (
71
+ ( { children, className, sx : sxProp = defaultSxProp , ...rest } , forwardRef ) => {
72
+ if ( sxProp !== defaultSxProp ) {
73
+ return (
74
+ < Box
75
+ as = "a"
76
+ ref = { forwardRef }
77
+ sx = { sxProp }
78
+ className = { clsx ( className , styles . Link ) }
79
+ data-selected = { rest . selected }
80
+ aria-current = { rest . selected }
81
+ { ...rest }
82
+ >
83
+ { children }
84
+ </ Box >
85
+ )
137
86
}
138
87
139
- &.selected {
140
- color: ${ get ( 'colors.fg.onEmphasis' ) } ;
141
- background-color: ${ get ( 'colors.accent.emphasis' ) } ;
142
- border-color: ${ get ( 'colors.accent.emphasis' ) } ;
143
- }
144
-
145
- ${ sx } ;
146
- ` ,
88
+ return (
89
+ < a
90
+ ref = { forwardRef }
91
+ className = { clsx ( className , styles . Link ) }
92
+ data-selected = { rest . selected }
93
+ aria-current = { rest . selected }
94
+ { ...rest }
95
+ >
96
+ { children }
97
+ </ a >
98
+ )
99
+ } ,
147
100
)
148
101
149
- const SubNavLink = React . forwardRef < HTMLElement , StyledSubNavLinkProps > ( function SubNavLink (
150
- { children, className, ...rest } ,
151
- forwardRef ,
152
- ) {
153
- const enabled = useFeatureFlag ( CSS_MODULES_FEATURE_FLAG )
154
- return (
155
- < StyledSubNavLink
156
- ref = { forwardRef }
157
- className = { clsx ( className , enabled && styles . Link ) }
158
- data-selected = { rest . selected }
159
- aria-current = { rest . selected }
160
- { ...rest }
161
- >
162
- { children }
163
- </ StyledSubNavLink >
164
- )
165
- } )
166
-
167
102
SubNavLink . displayName = 'SubNav.Link'
168
103
169
104
export type SubNavProps = ComponentProps < typeof SubNav >
0 commit comments