Skip to content

Commit

Permalink
Modify branded-navbar and button to check for color-contrast
Browse files Browse the repository at this point in the history
  • Loading branch information
futa-ikeda committed Aug 1, 2023
1 parent e4c1f45 commit 2f9330c
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { tracked } from 'tracked-built-ins';

import { serviceLinks } from 'ember-osf-web/const/service-links';
import { layout, requiredAction } from 'ember-osf-web/decorators/component';
import BrandModel from 'ember-osf-web/models/brand';
import PreprintProviderModel from 'ember-osf-web/models/preprint-provider';
import ProviderModel from 'ember-osf-web/models/provider';
import Analytics from 'ember-osf-web/services/analytics';
Expand Down Expand Up @@ -53,6 +54,7 @@ export default class BrandedNavbar extends Component {

@alias('theme.provider') provider!: ProviderModel;
@alias('theme.provider.id') providerId!: string;
@alias('theme.provider.brand.primaryColor') brandPrimaryColor!: BrandModel;

@computed('intl.locale', 'theme.{providerType,provider.providerTitle}', 'translateKey')
get brandTitle(): string {
Expand All @@ -68,7 +70,7 @@ export default class BrandedNavbar extends Component {

@action
toggleSecondaryNavigation() {
this.toggleProperty('showNavLinks');
this.showNavLinks = !this.showNavLinks;
}

get isMobileOrTablet() {
Expand Down
23 changes: 22 additions & 1 deletion lib/app-components/addon/components/branded-navbar/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

.branded-nav-wrapper {
.branded-nav {
background-color: var(--primary-color);
z-index: 999;
}

Expand Down Expand Up @@ -93,3 +92,25 @@

}
}

// preprint-branded navbar uses brand relationship and not custom CSS
// !importants needed to override the default styles set in app/styles/_components.scss
// branded-navbar dark/light text only used for preprint providers, as collection providers currently use custom CSS
.preprint-branded-navbar {
background-color: var(--primary-color) !important;
background-image: none !important;

&.light-text {
a,
:global(.secondary-nav-dropdown) {
color: $color-text-white !important;
}
}

&.dark-text {
a,
:global(.secondary-nav-dropdown) {
color: $color-text-black !important;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<div local-class='branded-nav-wrapper'>
<nav
local-class='branded-nav'
local-class='branded-nav
{{if (eq this.theme.providerType 'preprint') 'preprint-branded-navbar'}}
{{if (sufficient-contrast this.brandPrimaryColor '#fff') 'light-text' 'dark-text'}}'
class='navbar navbar-inverse navbar-fixed-top'
id='navbarScope'
>
Expand Down
15 changes: 15 additions & 0 deletions lib/osf-components/addon/components/button/component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import Component from '@glimmer/component';
import { inject as service } from '@ember/service';

import Theme from 'ember-osf-web/services/theme';
import PreprintProviderModel from 'ember-osf-web/models/preprint-provider';

const layoutClasses = {
small: 'SmallButton',
Expand All @@ -23,6 +27,8 @@ interface Args {
}

export default class Button extends Component<Args> {
@service theme!: Theme;

get classList(): string {
const classes = [];
const { layout, type } = this.args;
Expand All @@ -41,4 +47,13 @@ export default class Button extends Component<Args> {

return classes.join(' ');
}

get primaryColor(): string {
if (!this.theme.provider) {
return '#337ab7'; // $color-osf-primary;
}
// Only preprint-providers will have brands that need to be checked for color contrast
const brand = (this.theme.provider as PreprintProviderModel).brand;
return brand ? brand.get('primaryColor') : '#337ab7';
}
}
6 changes: 6 additions & 0 deletions lib/osf-components/addon/components/button/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
}
}

// This should only be used in preprint branding as we move away from using custom CSS
// Please don't rely on this class for new brands
.DarkText {
color: $color-text-black;
}

.SecondaryButton {
background-color: $color-bg-white;
border: 1px solid $color-border-gray-light;
Expand Down
5 changes: 4 additions & 1 deletion lib/osf-components/addon/components/button/template.hbs
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>

0 comments on commit 2f9330c

Please sign in to comment.