-
Notifications
You must be signed in to change notification settings - Fork 37
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
Add anti-aliasing to Text and other components #884
base: main
Are you sure you want to change the base?
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,9 @@ | ||
--- | ||
'@primer/react-brand': minor | ||
--- | ||
|
||
Anti-aliasing is now applied automatically to all `Text` instances _except_ under these conditions: | ||
|
||
- When explicitly disabled via `antialiasing={false}` | ||
- When font weight is `light` or `extralight` AND size is `'100'` or `'200'` | ||
- When size is `100` (regardless of weight) |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -67,6 +67,10 @@ export type TextProps = { | |||||||||||||||||||||||
* Note: Only applies to block elements. | ||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||
align?: 'start' | 'center' | 'end' | ||||||||||||||||||||||||
/** | ||||||||||||||||||||||||
* Toggle antialiasing on or off | ||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||
antialiasing?: boolean | ||||||||||||||||||||||||
} & TextTags | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
export function Text({ | ||||||||||||||||||||||||
|
@@ -80,6 +84,7 @@ export function Text({ | |||||||||||||||||||||||
variant = defaultTextVariant, | ||||||||||||||||||||||||
weight, | ||||||||||||||||||||||||
style, | ||||||||||||||||||||||||
antialiasing = true, | ||||||||||||||||||||||||
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. Minor thing, but I wonder if this would be clearer if it were named wdyt? |
||||||||||||||||||||||||
...rest | ||||||||||||||||||||||||
}: PropsWithChildren<TextProps>) { | ||||||||||||||||||||||||
const {classes: animationClasses, styles: animationInlineStyles} = useAnimation(animate) | ||||||||||||||||||||||||
|
@@ -96,12 +101,22 @@ export function Text({ | |||||||||||||||||||||||
.join(' ') | ||||||||||||||||||||||||
}, [weight]) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
const dontApplyAA = Boolean( | ||||||||||||||||||||||||
// When explicitly disabled | ||||||||||||||||||||||||
!antialiasing || | ||||||||||||||||||||||||
// When selected font weight is not suitable for anti-aliasing | ||||||||||||||||||||||||
(weight && ['light', 'extralight'].includes(weight as TextWeightVariants) && ['100', '200'].includes(size)) || | ||||||||||||||||||||||||
// When size is too small | ||||||||||||||||||||||||
size === '100', | ||||||||||||||||||||||||
) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
Comment on lines
+104
to
+112
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. This logic could be simplified slightly by bringing the Just a matter of opinion, but also extracting the font-weight check into a variable could do away for the need for explicit comments too. Up to you though
Suggested change
|
||||||||||||||||||||||||
const textClassName = clsx( | ||||||||||||||||||||||||
animationClasses, | ||||||||||||||||||||||||
styles.Text, | ||||||||||||||||||||||||
styles[`Text-font--${font}`], | ||||||||||||||||||||||||
styles[`Text--${variant}`], | ||||||||||||||||||||||||
styles[`Text--${size}`], | ||||||||||||||||||||||||
!dontApplyAA && styles['Text--antialiased'], | ||||||||||||||||||||||||
weight && weightClass, | ||||||||||||||||||||||||
align && styles[`Text-align--${align}`], | ||||||||||||||||||||||||
className, | ||||||||||||||||||||||||
|
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.
Is there a reason that this uses
subpixel-antialiased
where others just userantialiased
?