Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support link underline preference #3720

Merged
merged 21 commits into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
7f1a415
adds Prose component and stories
mperrotti Sep 6, 2023
a37f660
adds tests and makes some minor changes
mperrotti Sep 7, 2023
2c2af0b
Create happy-rivers-attend.md
mperrotti Sep 7, 2023
91dfef5
Merge branch 'main' into mp/prose-component
mperrotti Sep 7, 2023
5d8fd51
Merge branch 'main' into mp/prose-component
mperrotti Sep 8, 2023
ab51c47
handle link underline preferences
mperrotti Sep 12, 2023
605c3b5
Merge branch 'mp/prose-component' of github.com:primer/react into mp/…
mperrotti Sep 12, 2023
b3f6d01
adds visual regression testing
mperrotti Sep 14, 2023
9d1feb5
Merge branch 'main' into mp/prose-component
mperrotti Sep 14, 2023
dff1612
fixes storybook ID in Prose docs data
mperrotti Sep 14, 2023
1b8f086
Merge branch 'mp/prose-component' of github.com:primer/react into mp/…
mperrotti Sep 14, 2023
b805565
updates changeset with changed components data
mperrotti Sep 14, 2023
c131d81
Merge branch 'main' of github.com:primer/react into mp/prose-component
mperrotti Sep 28, 2023
0fed1ab
rm Prose component
mperrotti Sep 28, 2023
4413717
Merge branch 'main' into mp/prose-component
mperrotti Sep 29, 2023
0ae04e2
test(vrt): update snapshots
joshblack Oct 2, 2023
0736bde
test(e2e): separate storybook global args by semicolon instead of amp…
joshblack Oct 5, 2023
f19facf
test(vrt): update snapshots
joshblack Oct 5, 2023
443e575
Merge branch 'main' into mp/prose-component
mperrotti Oct 5, 2023
56c9391
Merge branch 'main' into mp/prose-component
mperrotti Oct 6, 2023
90d5f19
update snapshots
mperrotti Oct 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/happy-rivers-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": minor
---

Adds draft Prose component to support styling within text blocks
71 changes: 71 additions & 0 deletions e2e/components/Prose.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import {test, expect} from '@playwright/test'
import {visit} from '../test-helpers/storybook'
import {themes} from '../test-helpers/themes'

test.describe('Prose', () => {
test.describe('Default', () => {
for (const theme of themes) {
test.describe(theme, () => {
test('default @vrt', async ({page}) => {
await visit(page, {
id: 'drafts-components-prose--default',
globals: {
colorScheme: theme,
},
})

expect(await page.screenshot()).toMatchSnapshot(`Prose.Default.${theme}.png`)
})

test('axe @aat', async ({page}) => {
await visit(page, {
id: 'drafts-components-prose--default',
globals: {
colorScheme: theme,
},
})
await expect(page).toHaveNoViolations({
rules: {
'color-contrast': {
enabled: theme !== 'dark_dimmed',
},
},
})
})
})
}
})

test.describe('Full Width', () => {
for (const theme of themes) {
test.describe(theme, () => {
test('default @vrt', async ({page}) => {
await visit(page, {
id: 'drafts-components-prose-features--full-width',
globals: {
colorScheme: theme,
},
})

expect(await page.screenshot()).toMatchSnapshot(`Prose.FullWidth.${theme}.png`)
})

test('axe @aat', async ({page}) => {
await visit(page, {
id: 'drafts-components-prose--default',
globals: {
colorScheme: theme,
},
})
await expect(page).toHaveNoViolations({
rules: {
'color-contrast': {
enabled: theme !== 'dark_dimmed',
},
},
})
})
})
}
})
})
1 change: 1 addition & 0 deletions src/ActionList/LinkItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const LinkItem = React.forwardRef(({sx = {}, active, as: Component, ...pr

// inherit Item styles
color: 'inherit',
textDecoration: 'none',
'&:hover': {color: 'inherit', textDecoration: 'none'},
}

Expand Down
7 changes: 7 additions & 0 deletions src/BaseStyles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ const GlobalStyle = createGlobalStyle<{colorScheme?: 'light' | 'dark'}>`
details-dialog:focus:not(:focus-visible):not(.focus-visible) {
outline: none;
}

/* Used to fake conditional styles using a technique by Lea Verou: https://lea.verou.me/blog/2020/10/the-var-space-hack-to-toggle-multiple-values-with-one-custom-property/ */
/* We have to use a zero-width space character (\u200B) as the value instead of a regular whitespace character because styled-components strips out properties that just have a whitespace value. */
:root {--prefers-link-underlines: \u200B;}
[data-a11y-link-underlines='true'] {
--prefers-link-underlines: initial;
}
`

const Base = styled.div<SystemTypographyProps & SystemCommonProps>`
Expand Down
2 changes: 1 addition & 1 deletion src/BranchName/BranchName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const BranchName = styled.a<SxProp>`
color: ${get('colors.accent.fg')};
background-color: ${get('colors.accent.subtle')};
border-radius: ${get('radii.2')};
text-decoration: none;
text-decoration: var(--prefers-link-underlines, underline);

${sx};
`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ exports[`BranchName renders consistently 1`] = `
color: #0969da;
background-color: #ddf4ff;
border-radius: 6px;
-webkit-text-decoration: none;
text-decoration: none;
-webkit-text-decoration: var(--prefers-link-underlines,underline);
text-decoration: var(--prefers-link-underlines,underline);
}

<a
Expand Down
2 changes: 1 addition & 1 deletion src/Breadcrumbs/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const BreadcrumbsItem = styled.a.attrs<StyledBreadcrumbsItemProps>(props => ({
color: ${get('colors.accent.fg')};
display: inline-block;
font-size: ${get('fontSizes.1')};
text-decoration: none;
text-decoration: var(--prefers-link-underlines, underline);
&:hover {
text-decoration: underline;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ exports[`Breadcrumbs.Item adds activeClassName={SELECTED_CLASS} when it gets a "
color: #0969da;
display: inline-block;
font-size: 14px;
-webkit-text-decoration: none;
text-decoration: none;
-webkit-text-decoration: var(--prefers-link-underlines,underline);
text-decoration: var(--prefers-link-underlines,underline);
}

.c0:hover {
Expand All @@ -32,8 +32,8 @@ exports[`Breadcrumbs.Item renders consistently 1`] = `
color: #0969da;
display: inline-block;
font-size: 14px;
-webkit-text-decoration: none;
text-decoration: none;
-webkit-text-decoration: var(--prefers-link-underlines,underline);
text-decoration: var(--prefers-link-underlines,underline);
}

.c0:hover {
Expand All @@ -57,8 +57,8 @@ exports[`Breadcrumbs.Item respects the "selected" prop 1`] = `
color: #0969da;
display: inline-block;
font-size: 14px;
-webkit-text-decoration: none;
text-decoration: none;
-webkit-text-decoration: var(--prefers-link-underlines,underline);
text-decoration: var(--prefers-link-underlines,underline);
}

.c0:hover {
Expand Down
6 changes: 4 additions & 2 deletions src/Button/__tests__/__snapshots__/Button.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1511,11 +1511,13 @@ exports[`Button styles invisible button appropriately 1`] = `
display: -webkit-inline-flex;
display: -ms-inline-flexbox;
display: inline-flex;
-webkit-text-decoration: var(--prefers-link-underlines,underline);
text-decoration: var(--prefers-link-underlines,underline);
}

.c0[href]:hover {
-webkit-text-decoration: none;
text-decoration: none;
-webkit-text-decoration: var(--prefers-link-underlines,underline);
text-decoration: var(--prefers-link-underlines,underline);
}

.c0:hover {
Expand Down
6 changes: 6 additions & 0 deletions src/Button/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ export const getVariantStyles = (variant: VariantType = 'default', theme?: Theme
backgroundColor: 'transparent',
borderColor: 'transparent',
boxShadow: 'none',
'&[href]': {
textDecoration: 'var(--prefers-link-underlines, underline)',
'&:hover': {
textDecoration: 'var(--prefers-link-underlines, underline)',
},
},
'&:hover:not([disabled])': {
backgroundColor: 'btn.hoverBg',
},
Expand Down
1 change: 1 addition & 0 deletions src/Heading/Heading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const Heading = forwardRef(({as: Component = 'h2', ...props}, forwardedRef) => {
return (
<StyledHeading
as={Component}
className="pc-Heading"
{...props}
// @ts-ignore shh
ref={innerRef}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ exports[`Heading renders consistently 1`] = `
}

<h2
className="c0"
className="c0 pc-Heading"
/>
`;
4 changes: 2 additions & 2 deletions src/Link/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ const hoverColor = system({

const StyledLink = styled.a<StyledLinkProps>`
color: ${props => (props.muted ? get('colors.fg.muted')(props) : get('colors.accent.fg')(props))};
text-decoration: ${props => (props.underline ? 'underline' : 'none')};
text-decoration: ${props => (props.underline ? 'underline' : 'var(--prefers-link-underlines, underline)')};
&:hover {
text-decoration: ${props => (props.muted ? 'none' : 'underline')};
text-decoration: ${props => (props.muted ? 'var(--prefers-link-underlines, underline)' : 'underline')};
${props => (props.hoverColor ? hoverColor : props.muted ? `color: ${get('colors.accent.fg')(props)}` : '')};
}
&:is(button) {
Expand Down
32 changes: 16 additions & 16 deletions src/Link/__tests__/__snapshots__/Link.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
exports[`Link applies button styles when rendering a button element 1`] = `
.c0 {
color: #0969da;
-webkit-text-decoration: none;
text-decoration: none;
-webkit-text-decoration: var(--prefers-link-underlines,underline);
text-decoration: var(--prefers-link-underlines,underline);
}

.c0:hover {
Expand Down Expand Up @@ -37,8 +37,8 @@ exports[`Link applies button styles when rendering a button element 1`] = `
exports[`Link passes href down to link element 1`] = `
.c0 {
color: #0969da;
-webkit-text-decoration: none;
text-decoration: none;
-webkit-text-decoration: var(--prefers-link-underlines,underline);
text-decoration: var(--prefers-link-underlines,underline);
}

.c0:hover {
Expand Down Expand Up @@ -72,8 +72,8 @@ exports[`Link passes href down to link element 1`] = `
exports[`Link renders consistently 1`] = `
.c0 {
color: #0969da;
-webkit-text-decoration: none;
text-decoration: none;
-webkit-text-decoration: var(--prefers-link-underlines,underline);
text-decoration: var(--prefers-link-underlines,underline);
}

.c0:hover {
Expand Down Expand Up @@ -106,8 +106,8 @@ exports[`Link renders consistently 1`] = `
exports[`Link respects hoverColor prop 1`] = `
.c0 {
color: #0969da;
-webkit-text-decoration: none;
text-decoration: none;
-webkit-text-decoration: var(--prefers-link-underlines,underline);
text-decoration: var(--prefers-link-underlines,underline);
}

.c0:hover {
Expand Down Expand Up @@ -141,14 +141,14 @@ exports[`Link respects hoverColor prop 1`] = `
exports[`Link respects the "sx" prop when "muted" prop is also passed 1`] = `
.c0 {
color: #656d76;
-webkit-text-decoration: none;
text-decoration: none;
-webkit-text-decoration: var(--prefers-link-underlines,underline);
text-decoration: var(--prefers-link-underlines,underline);
color: #ffffff;
}

.c0:hover {
-webkit-text-decoration: none;
text-decoration: none;
-webkit-text-decoration: var(--prefers-link-underlines,underline);
text-decoration: var(--prefers-link-underlines,underline);
color: #0969da;
}

Expand Down Expand Up @@ -178,13 +178,13 @@ exports[`Link respects the "sx" prop when "muted" prop is also passed 1`] = `
exports[`Link respects the "muted" prop 1`] = `
.c0 {
color: #656d76;
-webkit-text-decoration: none;
text-decoration: none;
-webkit-text-decoration: var(--prefers-link-underlines,underline);
text-decoration: var(--prefers-link-underlines,underline);
}

.c0:hover {
-webkit-text-decoration: none;
text-decoration: none;
-webkit-text-decoration: var(--prefers-link-underlines,underline);
text-decoration: var(--prefers-link-underlines,underline);
color: #0969da;
}

Expand Down
24 changes: 16 additions & 8 deletions src/NavList/__snapshots__/NavList.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ exports[`NavList renders a simple list 1`] = `

.c3 {
color: #0969da;
-webkit-text-decoration: none;
text-decoration: none;
-webkit-text-decoration: var(--prefers-link-underlines,underline);
text-decoration: var(--prefers-link-underlines,underline);
padding-left: 8px;
padding-right: 8px;
padding-top: 6px;
Expand All @@ -212,6 +212,8 @@ exports[`NavList renders a simple list 1`] = `
flex-grow: 1;
border-radius: 6px;
color: inherit;
-webkit-text-decoration: none;
text-decoration: none;
}

.c3:hover {
Expand Down Expand Up @@ -601,8 +603,8 @@ exports[`NavList renders with groups 1`] = `

.c7 {
color: #0969da;
-webkit-text-decoration: none;
text-decoration: none;
-webkit-text-decoration: var(--prefers-link-underlines,underline);
text-decoration: var(--prefers-link-underlines,underline);
padding-left: 8px;
padding-right: 8px;
padding-top: 6px;
Expand All @@ -617,6 +619,8 @@ exports[`NavList renders with groups 1`] = `
flex-grow: 1;
border-radius: 6px;
color: inherit;
-webkit-text-decoration: none;
text-decoration: none;
}

.c7:hover {
Expand Down Expand Up @@ -1082,8 +1086,8 @@ exports[`NavList.Item with NavList.SubNav does not have active styles if SubNav

.c11 {
color: #0969da;
-webkit-text-decoration: none;
text-decoration: none;
-webkit-text-decoration: var(--prefers-link-underlines,underline);
text-decoration: var(--prefers-link-underlines,underline);
padding-left: 16px;
padding-right: 8px;
padding-top: 6px;
Expand All @@ -1098,6 +1102,8 @@ exports[`NavList.Item with NavList.SubNav does not have active styles if SubNav
flex-grow: 1;
border-radius: 6px;
color: inherit;
-webkit-text-decoration: none;
text-decoration: none;
font-size: 12px;
font-weight: 400;
}
Expand Down Expand Up @@ -1560,8 +1566,8 @@ exports[`NavList.Item with NavList.SubNav has active styles if SubNav contains t

.c11 {
color: #0969da;
-webkit-text-decoration: none;
text-decoration: none;
-webkit-text-decoration: var(--prefers-link-underlines,underline);
text-decoration: var(--prefers-link-underlines,underline);
padding-left: 16px;
padding-right: 8px;
padding-top: 6px;
Expand All @@ -1576,6 +1582,8 @@ exports[`NavList.Item with NavList.SubNav has active styles if SubNav contains t
flex-grow: 1;
border-radius: 6px;
color: inherit;
-webkit-text-decoration: none;
text-decoration: none;
font-size: 12px;
font-weight: 400;
}
Expand Down
Loading