-
Notifications
You must be signed in to change notification settings - Fork 56
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
[No ticket] Preprint branding rework #1913
Merged
futa-ikeda
merged 10 commits into
CenterForOpenScience:feature/search-improvements
from
futa-ikeda:preprint-navbar-rework
Aug 8, 2023
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ecee178
Allow editing secondary-color in dev tool
futa-ikeda 04050d2
Use preprints brand for navbar color and hero background
futa-ikeda 6554004
Ensure navbar logo overwrite only when appropriate
futa-ikeda 6e3649a
Add helper for detecting color-contrast
futa-ikeda 285f3d5
Add some error handling to sufficient-contrast helper
futa-ikeda 90e4595
Modify branded-navbar and button to check for color-contrast
futa-ikeda caf7789
Add special-case for biohackrxiv
futa-ikeda b928ca5
Add additional providers to mirage
futa-ikeda 2cda0d1
Move sufficient-contrast helper to osf-components
futa-ikeda b4d5daf
Better error handling for button primary color
futa-ikeda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
{{page-title this.theme.provider.providerTitle replace=true}} | ||
<ThemeStyles /> | ||
<BrandedNavbar | ||
@translateKey='collections.general.brand' | ||
@brandRoute='preprints.discover' | ||
@addLinkKey='collections.navbar.add' | ||
/> | ||
{{outlet}} | ||
<div {{with-branding (get-model this.theme.provider.brand)}}> | ||
<ThemeStyles /> | ||
<BrandedNavbar | ||
@translateKey='collections.general.brand' | ||
@brandRoute='preprints.discover' | ||
@addLinkKey='collections.navbar.add' | ||
/> | ||
{{outlet}} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
lib/app-components/addon/components/branded-navbar/template.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 5 additions & 3 deletions
8
lib/app-components/addon/components/theme-styles/template.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
{{!-- template-lint-disable no-bare-strings --}} | ||
<style> | ||
.navbar-image { | ||
background-image: url('{{this.assets.square_color_transparent}}'); | ||
} | ||
{{#if this.assets.square_color_transparent}} | ||
.navbar-image { | ||
background-image: url('{{this.assets.square_color_transparent}}'); | ||
} | ||
{{/if}} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 11 additions & 3 deletions
14
lib/osf-components/addon/components/brand-color-inputs/template.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
<label>{{t 'app_components.brand_color_inputs.primary_label'}}</label> | ||
<Input @value={{this.primaryColor}} /> | ||
<Button {{on 'click' this.setPrimaryColor}}>{{t 'app_components.brand_color_inputs.primary_set'}}</Button> | ||
<label> | ||
{{t 'app_components.brand_color_inputs.primary_label'}} | ||
<Input @value={{this.primaryColor}} /> | ||
</label> | ||
<Button {{on 'click' this.setPrimaryColor}}>{{t 'app_components.brand_color_inputs.primary_set'}}</Button> | ||
<br> | ||
<label> | ||
{{t 'app_components.brand_color_inputs.secondary_label'}} | ||
<Input @value={{this.secondaryColor}} /> | ||
</label> | ||
<Button {{on 'click' this.setSecondaryColor}}>{{t 'app_components.brand_color_inputs.secondary_set'}}</Button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
<button type='button' local-class='Button {{this.classList}}' ...attributes> | ||
<button type='button' local-class='Button {{this.classList}} | ||
{{if (sufficient-contrast this.primaryColor '#ffffff') '' 'DarkText'}}' | ||
...attributes | ||
> | ||
{{yield}} | ||
</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { helper } from '@ember/component/helper'; | ||
|
||
/** | ||
* Criteria is based on WCAG 2.0 Guidelines. | ||
* https://www.w3.org/WAI/WCAG21/quickref/?versions=2.0#qr-visual-audio-contrast-contrast | ||
* | ||
* Relative Luminance is calculated using the formula from WCAG 2.0 Guidelines. | ||
* https://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef | ||
* | ||
* @param {Array} backgroundColor The background color in hex format | ||
* @param {Array} foregroundColor The foreground color in hex format | ||
* @param {Object} options {largeText: true if text is at least 18 point if not bold and at least 14 point if bold} | ||
* @return {Boolean} Whether the contrast between the two colors is sufficient | ||
*/ | ||
|
||
const wcagAA = { | ||
normalText: 4.5, | ||
largeText: 3, | ||
}; | ||
const wcagAAA = { | ||
normalText: 7, | ||
largeText: 4.5, | ||
}; | ||
|
||
function threeDigitHexToSixDigit(hex: string): string { | ||
if (hex.length === 3) { | ||
return hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]; | ||
} | ||
return hex; | ||
} | ||
|
||
export function sufficientContrast( | ||
[backgroundColor, foregroundColor]: [string, string], { largeText = false, useAAA = false }, | ||
): boolean { | ||
const standard = useAAA ? wcagAAA : wcagAA; | ||
const threshold = largeText ? standard.largeText : standard.normalText; | ||
|
||
if (!backgroundColor || !foregroundColor) { | ||
return false; | ||
} | ||
|
||
let bg = backgroundColor.replace('#', ''); | ||
let fg = foregroundColor.replace('#', ''); | ||
bg = bg.length === 3 ? threeDigitHexToSixDigit(bg) : bg; | ||
fg = fg.length === 3 ? threeDigitHexToSixDigit(fg) : fg; | ||
|
||
// convert background and foreground color hex to sRGB | ||
const bgSRGB = { | ||
r: parseInt('0x' + bg.substring(0, 2), 16) / 255, | ||
g: parseInt('0x' + bg.substring(2, 4), 16) / 255, | ||
b: parseInt('0x' + bg.substring(4, 6), 16) / 255, | ||
}; | ||
const fgSRGB = { | ||
r: parseInt('0x' + fg.substring(0, 2), 16) / 255, | ||
g: parseInt('0x' + fg.substring(2, 4), 16) / 255, | ||
b: parseInt('0x' + fg.substring(4, 6), 16) / 255, | ||
}; | ||
|
||
const bgRGBLuminance = { | ||
r: bgSRGB.r <= 0.03928 ? bgSRGB.r / 12.92 : Math.pow((bgSRGB.r + 0.055) / 1.055, 2.4), | ||
g: bgSRGB.g <= 0.03928 ? bgSRGB.g / 12.92 : Math.pow((bgSRGB.g + 0.055) / 1.055, 2.4), | ||
b: bgSRGB.b <= 0.03928 ? bgSRGB.b / 12.92 : Math.pow((bgSRGB.b + 0.055) / 1.055, 2.4), | ||
}; | ||
const fgRGBLuminance = { | ||
r: fgSRGB.r <= 0.03928 ? fgSRGB.r / 12.92 : Math.pow((fgSRGB.r + 0.055) / 1.055, 2.4), | ||
g: fgSRGB.g <= 0.03928 ? fgSRGB.g / 12.92 : Math.pow((fgSRGB.g + 0.055) / 1.055, 2.4), | ||
b: fgSRGB.b <= 0.03928 ? fgSRGB.b / 12.92 : Math.pow((fgSRGB.b + 0.055) / 1.055, 2.4), | ||
}; | ||
|
||
// calculate relative luminance | ||
const bgLuminance = 0.2126 * bgRGBLuminance.r + 0.7152 * bgRGBLuminance.g + 0.0722 * bgRGBLuminance.b; | ||
const fgLuminance = 0.2126 * fgRGBLuminance.r + 0.7152 * fgRGBLuminance.g + 0.0722 * fgRGBLuminance.b; | ||
|
||
// calculate contrast ratio | ||
const contrastRatio = (Math.max(bgLuminance, fgLuminance) + 0.05) / (Math.min(bgLuminance, fgLuminance) + 0.05); | ||
return contrastRatio >= threshold; | ||
} | ||
|
||
export default helper(sufficientContrast); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from 'osf-components/helpers/sufficient-contrast'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🌚