Skip to content

Commit 8f9bb3d

Browse files
introduce gap between items and remove 4px padding around
1 parent 7ca16c9 commit 8f9bb3d

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

src/UnderlineNav2/UnderlineNav.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import {
1919
ulStyles,
2020
scrollStyles,
2121
moreMenuStyles,
22-
menuItemStyles
22+
menuItemStyles,
23+
GAP
2324
} from './styles'
2425
import {ArrowButton} from './UnderlineNavArrowButton'
2526
import styled from 'styled-components'
@@ -146,7 +147,8 @@ const calculatePossibleItems = (childWidthArray: ChildWidthArray, navWidth: numb
146147
breakpoint = index - 1
147148
break
148149
} else {
149-
sumsOfChildWidth = sumsOfChildWidth + childWidth.width
150+
// The the gap between items into account when calculating the number of items possible
151+
sumsOfChildWidth = sumsOfChildWidth + childWidth.width + GAP
150152
}
151153
}
152154

src/UnderlineNav2/UnderlineNavItem.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,18 @@ export const UnderlineNavItem = forwardRef(
175175
{children}
176176
</Box>
177177
)}
178-
<Box as="span" data-component="counter" sx={counterStyles}>
179-
{loadingCounters ? <LoadingCounter /> : counter !== undefined && <CounterLabel>{counter}</CounterLabel>}
180-
</Box>
178+
179+
{loadingCounters ? (
180+
<Box as="span" data-component="counter" sx={counterStyles}>
181+
<LoadingCounter />
182+
</Box>
183+
) : (
184+
counter !== undefined && (
185+
<Box as="span" data-component="counter" sx={counterStyles}>
186+
<CounterLabel>{counter}</CounterLabel>
187+
</Box>
188+
)
189+
)}
181190
</Box>
182191
</Box>
183192
</Box>

src/UnderlineNav2/styles.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ import {Theme} from '../ThemeProvider'
22
import {BetterSystemStyleObject} from '../sx'
33
import {UnderlineNavProps} from './UnderlineNav'
44

5+
// The gap between the list items. It is a constant because the gap is used to calculate the possible number of items that can fit in the container.
6+
export const GAP = 8
7+
8+
const focusRing = (theme?: Theme): BetterSystemStyleObject => ({
9+
boxShadow: `inset 0 0 0 2px ${theme?.colors.accent.fg}`
10+
})
11+
512
export const iconWrapStyles = {
613
alignItems: 'center',
714
display: 'inline-flex',
@@ -48,7 +55,8 @@ export const ulStyles = {
4855
paddingX: 0,
4956
margin: '0',
5057
marginBottom: '-1px',
51-
alignItems: 'center'
58+
alignItems: 'center',
59+
gap: `${GAP}px`
5260
}
5361

5462
export const getDividerStyle = (theme?: Theme) => ({
@@ -106,15 +114,14 @@ export const getArrowBtnStyles = (theme?: Theme) => ({
106114
// To reset global focus styles because it doesn't support safari right now.
107115
'&:focus:not(:disabled)': {
108116
outline: 0,
109-
boxShadow: `inset 0 0 0 2px ${theme?.colors.accent.fg}`
117+
...focusRing(theme)
110118
},
111119
// where focus-visible is supported, remove the focus box-shadow
112120
'&:not(:focus-visible)': {
113121
boxShadow: 'none'
114122
},
115123
'&:focus-visible:not(:disabled)': {
116-
outline: 0,
117-
boxShadow: `inset 0 0 0 2px ${theme?.colors.accent.fg}`
124+
...focusRing(theme)
118125
}
119126
})
120127

@@ -129,7 +136,6 @@ export const getLinkStyles = (
129136
color: 'fg.default',
130137
textAlign: 'center',
131138
textDecoration: 'none',
132-
paddingX: 1,
133139
...(props?.variant === 'small' ? smallVariantLinkStyles : defaultVariantLinkStyles),
134140
'@media (hover:hover)': {
135141
'&:hover > div[data-component="wrapper"] ': {
@@ -140,15 +146,15 @@ export const getLinkStyles = (
140146
'&:focus': {
141147
outline: 0,
142148
'& > div[data-component="wrapper"]': {
143-
boxShadow: `inset 0 0 0 2px ${theme?.colors.accent.fg}`
149+
...focusRing(theme)
144150
},
145151
// where focus-visible is supported, remove the focus box-shadow
146152
'&:not(:focus-visible) > div[data-component="wrapper"]': {
147153
boxShadow: 'none'
148154
}
149155
},
150156
'&:focus-visible > div[data-component="wrapper"]': {
151-
boxShadow: `inset 0 0 0 2px ${theme?.colors.accent.fg}`
157+
...focusRing(theme)
152158
},
153159
// renders a visibly hidden "copy" of the label in bold, reserving box space for when label becomes bold on selected
154160
'& span[data-content]::before': {
@@ -164,7 +170,7 @@ export const getLinkStyles = (
164170
position: 'absolute',
165171
right: '50%',
166172
bottom: 0,
167-
width: `calc(100% - 8px)`,
173+
width: '100%',
168174
height: 2,
169175
content: '""',
170176
bg: selectedLink === ref ? theme?.colors.primer.border.active : 'transparent',

0 commit comments

Comments
 (0)