Skip to content

Commit

Permalink
Merge branch 'main' into danielguillan/add-pillar-image-support
Browse files Browse the repository at this point in the history
  • Loading branch information
danielguillan authored Dec 19, 2024
2 parents 257e59c + c0aa598 commit 230f59d
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 11 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.

0 comments on commit 230f59d

Please sign in to comment.