Skip to content

Commit de75d8e

Browse files
[UnderlineNav2]: Add string type to the counter prop and display loading counter for all (#2449)
* string type for counters and fix loading issue * add changeset * improve docs * update animation details * Inverte the pulse effect Co-authored-by: Daniel Guillan <[email protected]> Co-authored-by: Daniel Guillan <[email protected]>
1 parent 4b276c7 commit de75d8e

File tree

6 files changed

+25
-12
lines changed

6 files changed

+25
-12
lines changed

.changeset/tough-peas-sort.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/react': patch
3+
---
4+
5+
UnderlineNav2: Add string type to the `counter` prop and display loading counter for all

docs/content/drafts/UnderlineNav2.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ const Navigation = () => {
152152
name="loadingCounters"
153153
type="boolean"
154154
defaultValue="false"
155-
description="Whether all of the counters are in loading state"
155+
description="Whether the navigation items are in loading state. Component waits for all the counters to finish loading to prevent multiple layout shifts."
156156
/>
157157
<PropsTableRow
158158
name="afterSelect"

src/UnderlineNav2/LoadingCounter.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import styled, {keyframes} from 'styled-components'
22
import {get} from '../constants'
33

44
const loading = keyframes`
5-
from { opacity: 0.4; }
6-
to { opacity: 0.8; }
5+
from { opacity: 1; }
6+
to { opacity: 0.2; }
77
`
88

99
export const LoadingCounter = styled.span`
10-
animation: ${loading} 1.2s linear infinite alternate;
11-
background-color: ${get('colors.neutral.emphasis')};
10+
animation: ${loading} 1.2s ease-in-out infinite alternate;
11+
background-color: ${get('colors.neutral.muted')};
1212
border-color: ${get('colors.border.default')};
1313
width: 1.5rem;
1414
height: 1rem; // 16px

src/UnderlineNav2/UnderlineNav.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,9 @@ export const UnderlineNav = forwardRef(
299299
{loadingCounters ? (
300300
<LoadingCounter />
301301
) : (
302-
<CounterLabel>{actionElementProps.counter}</CounterLabel>
302+
actionElementProps.counter !== undefined && (
303+
<CounterLabel>{actionElementProps.counter}</CounterLabel>
304+
)
303305
)}
304306
</Box>
305307
</ActionList.Item>

src/UnderlineNav2/UnderlineNavItem.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export type UnderlineNavItemProps = {
4242
/**
4343
* Counter
4444
*/
45-
counter?: number
45+
counter?: number | string
4646
} & SxProp &
4747
LinkProps
4848

@@ -172,10 +172,16 @@ export const UnderlineNavItem = forwardRef(
172172
{children}
173173
</Box>
174174
)}
175-
{counter && (
175+
{loadingCounters ? (
176176
<Box as="span" data-component="counter" sx={counterStyles}>
177-
{loadingCounters ? <LoadingCounter /> : <CounterLabel>{counter}</CounterLabel>}
177+
<LoadingCounter />
178178
</Box>
179+
) : (
180+
counter !== undefined && (
181+
<Box as="span" data-component="counter" sx={counterStyles}>
182+
<CounterLabel>{counter}</CounterLabel>
183+
</Box>
184+
)
179185
)}
180186
</Box>
181187
</Box>

src/UnderlineNav2/examples.stories.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ export const withCounterLabels = () => {
7272
)
7373
}
7474

75-
const items: {navigation: string; icon: React.FC<IconProps>; counter?: number}[] = [
75+
const items: {navigation: string; icon: React.FC<IconProps>; counter?: number | string}[] = [
7676
{navigation: 'Code', icon: CodeIcon},
77-
{navigation: 'Issues', icon: IssueOpenedIcon, counter: 120},
77+
{navigation: 'Issues', icon: IssueOpenedIcon, counter: '12K'},
7878
{navigation: 'Pull Requests', icon: GitPullRequestIcon, counter: 13},
7979
{navigation: 'Discussions', icon: CommentDiscussionIcon, counter: 5},
8080
{navigation: 'Actions', icon: PlayIcon, counter: 4},
8181
{navigation: 'Projects', icon: ProjectIcon, counter: 9},
82-
{navigation: 'Insights', icon: GraphIcon},
82+
{navigation: 'Insights', icon: GraphIcon, counter: '0'},
8383
{navigation: 'Settings', icon: GearIcon, counter: 10},
8484
{navigation: 'Security', icon: ShieldLockIcon}
8585
]

0 commit comments

Comments
 (0)