Skip to content

Commit

Permalink
Added variant prop to SubNav.Link (#868)
Browse files Browse the repository at this point in the history
  • Loading branch information
rezrah authored Dec 18, 2024
1 parent 0401cc5 commit c0aa598
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/slimy-snakes-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react-brand': patch
---

`SubNav.Link` now supports `variant="default"` to help increase contrast and legibility on non-standard backgrounds.
9 changes: 5 additions & 4 deletions apps/docs/content/components/SubNav.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,11 @@ Submenus appear as a dropdown by default.

### SubNav.Link <Label>Required</Label>

| name | type | default | required | description |
| -------------- | -------- | ------- | -------- | ----------------------------------------------- |
| `aria-current` | `string` | | `true` | Required for indicating the current active link |
| `href` | `string` | | `true` | URL of the page the link goes to |
| name | type | default | required | description |
| -------------- | --------------------------------------------------------------- | ------- | -------- | ----------------------------------------------- |
| `aria-current` | `string` | | `true` | Required for indicating the current active link |
| `href` | `string` | | `true` | URL of the page the link goes to |
| `variant` | <PropTableValues values={['default', 'muted']} addLineBreaks /> | `muted` | `false` | Alternative idle text appearance |

### SubNav.Action

Expand Down
25 changes: 25 additions & 0 deletions packages/react/src/SubNav/SubNav.features.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,28 @@ NarrowAnchorNavVariantMenuOpen.play = async ({canvasElement}) => {
const firstLink = within(overlayMenu).getAllByRole('link')[0]
expect(firstLink).toHaveFocus()
}

export const AnchorNavDefaultLinkVariant = args => (
<SubNav {...args}>
<SubNav.Heading href="#">Heading</SubNav.Heading>
<SubNav.Link href="#" variant="default">
Link
</SubNav.Link>
<SubNav.Link href="#" variant="default">
Link
</SubNav.Link>
<SubNav.Link href="#" variant="default">
Link
</SubNav.Link>
<SubNav.Link href="#" variant="default">
Link
</SubNav.Link>
<SubNav.Link href="#" variant="default">
Link
</SubNav.Link>
<SubNav.Link href="#" variant="default">
Link
</SubNav.Link>
<SubNav.Action href="#">Primary CTA</SubNav.Action>
</SubNav>
)
15 changes: 8 additions & 7 deletions packages/react/src/SubNav/SubNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import React, {
type ReactNode,
type RefObject,
} from 'react'
import {Button, ButtonSizes, ButtonVariants, Text, ThemeProvider, useWindowSize} from '..'
import {Button, ButtonSizes, ButtonVariants, Text, TextProps, ThemeProvider, useWindowSize} from '..'

import {default as clsx} from 'clsx'
import {ChevronDownIcon, ChevronUpIcon} from '@primer/octicons-react'
Expand Down Expand Up @@ -341,13 +341,14 @@ const SubNavHeading = ({href, children, className, 'data-testid': testID, ...pro
type SubNavLinkProps = {
href: string
'data-testid'?: string
_variant?: SubMenuVariants
variant?: TextProps['variant']
_subMenuVariant?: SubMenuVariants
} & PropsWithChildren<React.HTMLProps<HTMLAnchorElement>> &
BaseProps<HTMLAnchorElement>

const SubNavLinkWithSubmenu = forwardRef<HTMLDivElement, SubNavLinkProps>(
(
{children, href, 'aria-current': ariaCurrent, 'data-testid': testId, className, _variant, ...props},
{children, href, 'aria-current': ariaCurrent, 'data-testid': testId, className, _subMenuVariant, variant, ...props},
forwardedRef,
) => {
const submenuId = useId()
Expand Down Expand Up @@ -393,7 +394,7 @@ const SubNavLinkWithSubmenu = forwardRef<HTMLDivElement, SubNavLinkProps>(
size="200"
weight="semibold"
className={styles['SubNav__link-label']}
variant={ariaCurrent === 'page' ? 'default' : 'muted'}
variant={ariaCurrent === 'page' || variant === 'default' ? 'default' : 'muted'}
>
{label}
</Text>
Expand Down Expand Up @@ -458,13 +459,13 @@ const SubNavLink = forwardRef<HTMLAnchorElement | HTMLDivElement, SubNavLinkProp
<SubNavLinkWithSubmenu
{...props}
ref={ref as RefObject<HTMLDivElement>}
_variant={isAnchorVariantSubMenu ? 'anchor' : undefined}
_subMenuVariant={isAnchorVariantSubMenu ? 'anchor' : undefined}
/>
</li>
)
}

const {children, href, 'aria-current': ariaCurrent, 'data-testid': testId, className, ...rest} = props
const {children, href, 'aria-current': ariaCurrent, 'data-testid': testId, variant, className, ...rest} = props

return (
<li>
Expand All @@ -486,7 +487,7 @@ const SubNavLink = forwardRef<HTMLAnchorElement | HTMLDivElement, SubNavLinkProp
size="100"
weight="semibold"
className={styles['SubNav__link-label']}
variant={ariaCurrent === 'page' ? 'default' : 'muted'}
variant={ariaCurrent === 'page' || variant === 'default' ? 'default' : 'muted'}
>
{children}
</Text>
Expand Down
8 changes: 8 additions & 0 deletions packages/react/src/SubNav/SubNav.visual.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,12 @@ test.describe('Visual Comparison: SubNav', () => {
expect(await page.screenshot({fullPage: true})).toMatchSnapshot()
})
})
test('SubNav / Anchor Nav Default Link Variant', async ({page}) => {
await page.goto(
'http://localhost:6006/iframe.html?args=&id=components-subnav-features--anchor-nav-default-link-variant&viewMode=story',
)

await page.waitForTimeout(500)
expect(await page.screenshot({fullPage: true})).toMatchSnapshot()
})
})
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions packages/react/src/Testimonial/Testimonial.visual.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ test.describe('Visual Comparison: Testimonial', () => {
expect(await page.screenshot({fullPage: true})).toMatchSnapshot()
})

test('Testimonial / Testimonial Variants', async ({page}) => {
test('Testimonial / Variants', async ({page}) => {
await page.goto(
'http://localhost:6006/iframe.html?args=&id=components-testimonial-features--testimonial-variants&viewMode=story',
'http://localhost:6006/iframe.html?args=&id=components-testimonial-features--variants&viewMode=story',
)

await page.waitForTimeout(500)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c0aa598

Please sign in to comment.