Skip to content

Commit

Permalink
introduce gap between items and remove 4px padding around
Browse files Browse the repository at this point in the history
  • Loading branch information
broccolinisoup committed Oct 17, 2022
1 parent 7ca16c9 commit 8f9bb3d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
6 changes: 4 additions & 2 deletions src/UnderlineNav2/UnderlineNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import {
ulStyles,
scrollStyles,
moreMenuStyles,
menuItemStyles
menuItemStyles,
GAP
} from './styles'
import {ArrowButton} from './UnderlineNavArrowButton'
import styled from 'styled-components'
Expand Down Expand Up @@ -146,7 +147,8 @@ const calculatePossibleItems = (childWidthArray: ChildWidthArray, navWidth: numb
breakpoint = index - 1
break
} else {
sumsOfChildWidth = sumsOfChildWidth + childWidth.width
// The the gap between items into account when calculating the number of items possible
sumsOfChildWidth = sumsOfChildWidth + childWidth.width + GAP
}
}

Expand Down
15 changes: 12 additions & 3 deletions src/UnderlineNav2/UnderlineNavItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,18 @@ export const UnderlineNavItem = forwardRef(
{children}
</Box>
)}
<Box as="span" data-component="counter" sx={counterStyles}>
{loadingCounters ? <LoadingCounter /> : counter !== undefined && <CounterLabel>{counter}</CounterLabel>}
</Box>

{loadingCounters ? (
<Box as="span" data-component="counter" sx={counterStyles}>
<LoadingCounter />
</Box>
) : (
counter !== undefined && (
<Box as="span" data-component="counter" sx={counterStyles}>
<CounterLabel>{counter}</CounterLabel>
</Box>
)
)}
</Box>
</Box>
</Box>
Expand Down
22 changes: 14 additions & 8 deletions src/UnderlineNav2/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import {Theme} from '../ThemeProvider'
import {BetterSystemStyleObject} from '../sx'
import {UnderlineNavProps} from './UnderlineNav'

// 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.
export const GAP = 8

const focusRing = (theme?: Theme): BetterSystemStyleObject => ({
boxShadow: `inset 0 0 0 2px ${theme?.colors.accent.fg}`
})

export const iconWrapStyles = {
alignItems: 'center',
display: 'inline-flex',
Expand Down Expand Up @@ -48,7 +55,8 @@ export const ulStyles = {
paddingX: 0,
margin: '0',
marginBottom: '-1px',
alignItems: 'center'
alignItems: 'center',
gap: `${GAP}px`
}

export const getDividerStyle = (theme?: Theme) => ({
Expand Down Expand Up @@ -106,15 +114,14 @@ export const getArrowBtnStyles = (theme?: Theme) => ({
// To reset global focus styles because it doesn't support safari right now.
'&:focus:not(:disabled)': {
outline: 0,
boxShadow: `inset 0 0 0 2px ${theme?.colors.accent.fg}`
...focusRing(theme)
},
// where focus-visible is supported, remove the focus box-shadow
'&:not(:focus-visible)': {
boxShadow: 'none'
},
'&:focus-visible:not(:disabled)': {
outline: 0,
boxShadow: `inset 0 0 0 2px ${theme?.colors.accent.fg}`
...focusRing(theme)
}
})

Expand All @@ -129,7 +136,6 @@ export const getLinkStyles = (
color: 'fg.default',
textAlign: 'center',
textDecoration: 'none',
paddingX: 1,
...(props?.variant === 'small' ? smallVariantLinkStyles : defaultVariantLinkStyles),
'@media (hover:hover)': {
'&:hover > div[data-component="wrapper"] ': {
Expand All @@ -140,15 +146,15 @@ export const getLinkStyles = (
'&:focus': {
outline: 0,
'& > div[data-component="wrapper"]': {
boxShadow: `inset 0 0 0 2px ${theme?.colors.accent.fg}`
...focusRing(theme)
},
// where focus-visible is supported, remove the focus box-shadow
'&:not(:focus-visible) > div[data-component="wrapper"]': {
boxShadow: 'none'
}
},
'&:focus-visible > div[data-component="wrapper"]': {
boxShadow: `inset 0 0 0 2px ${theme?.colors.accent.fg}`
...focusRing(theme)
},
// renders a visibly hidden "copy" of the label in bold, reserving box space for when label becomes bold on selected
'& span[data-content]::before': {
Expand All @@ -164,7 +170,7 @@ export const getLinkStyles = (
position: 'absolute',
right: '50%',
bottom: 0,
width: `calc(100% - 8px)`,
width: '100%',
height: 2,
content: '""',
bg: selectedLink === ref ? theme?.colors.primer.border.active : 'transparent',
Expand Down

0 comments on commit 8f9bb3d

Please sign in to comment.