-
Notifications
You must be signed in to change notification settings - Fork 637
Support link underline preference #3848
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@primer/react": minor | ||
--- | ||
|
||
Updates link styles to support underline link preferences. | ||
|
||
<!-- Changed components: ActionList, BranchName, Breadcrumbs, Button, Button2, Heading, Link --> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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;} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very cool hack! But we're only using this for one property: text-decoration so I'm not sure if we should prefer the explicit |
||
[data-a11y-link-underlines='true'] { | ||
--prefers-link-underlines: initial; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what do you think of using the off/on variables like Lea suggested in her blogpost for a clearer understanding of this variable assignment? |
||
} | ||
` | ||
|
||
const Base = styled.div<SystemTypographyProps & SystemCommonProps>` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,6 @@ exports[`Heading renders consistently 1`] = ` | |
} | ||
|
||
<h2 | ||
className="c0" | ||
className="c0 pc-Heading" | ||
/> | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)')}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assuming Instead of changing the default, should we keep that default and let folks change the default by switching-on text-decoration: props.underline ? 'underline' : 'var(--prefers-link-underlines, none)' If There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @joshblack @pksjce Does this sound right or am I missing the goal here? |
||
&: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) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
omg so clever!