Skip to content

Commit

Permalink
Allow making default navigation accent color configurable
Browse files Browse the repository at this point in the history
REDMINE-20704
  • Loading branch information
tf committed May 7, 2024
1 parent e633839 commit ad7d15b
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
de:
pageflow:
editor:
widgets:
attributes:
defaultNavigation:
accentColor:
label: "Akzentfarbe"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
en:
pageflow:
editor:
widgets:
attributes:
defaultNavigation:
accentColor:
label: "Accent color"
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react';

import {DefaultNavigation} from 'widgets/defaultNavigation/DefaultNavigation';

import {renderInEntry} from 'pageflow-scrolled/testHelpers';
import '@testing-library/jest-dom/extend-expect';

describe('DefaultNavigation', () => {
it('does not have style attribute on header by default', async () => {
const {container} = renderInEntry(
<DefaultNavigation configuration={{}} />
);

expect(container.querySelector('header')).not.toHaveAttribute('style');
});

it('supports overriding accent color', async () => {
const {container} = renderInEntry(
<DefaultNavigation configuration={{accentColor: 'brand-blue'}} />
);

expect(container.querySelector('header')).toHaveStyle(
{'--theme-accent-color': 'var(--theme-palette-color-brand-blue)'
});
});
});
14 changes: 14 additions & 0 deletions entry_types/scrolled/package/src/editor/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {SideBarController} from './controllers/SideBarController';

import {browser} from 'pageflow/frontend';
import {CheckBoxInputView, ConfigurationEditorView} from 'pageflow/ui';
import {ColorSelectInputView} from './views/inputs/ColorSelectInputView';
import {BrowserNotSupportedView} from './views/BrowserNotSupportedView';

editor.registerEntryType('scrolled', {
Expand Down Expand Up @@ -53,7 +54,20 @@ editor.widgetTypes.registerRole('header', {
editor.widgetTypes.register('defaultNavigation', {
configurationEditorView: ConfigurationEditorView.extend({
configure: function() {
const [values, texts] = this.options.entry.getPaletteColors({name: 'accentColors'});

this.tab('defaultNavigation', function() {
if (values.length) {
this.input('accentColor', ColorSelectInputView, {
includeBlank: true,
blankTranslationKey: 'pageflow_scrolled.editor.' +
'common_content_element_attributes.' +
'palette_color.blank',
values,
texts,
});
}

this.input('hideToggleMuteButton', CheckBoxInputView);
this.input('hideSharingButton', CheckBoxInputView);
this.input('fixedOnDesktop', CheckBoxInputView);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import classNames from 'classnames';

import {
Widget,
paletteColor,
useScrollPosition,
useChapters,
useCurrentChapter,
Expand Down Expand Up @@ -125,7 +126,7 @@ export function DefaultNavigation({configuration}) {
!mobileNavHidden
),
[styles.hasChapters]: hasChapters
})}>
})} style={{'--theme-accent-color': paletteColor(configuration.accentColor)}}>
<div className={styles.navigationBarContentWrapper}>
{hasChapters && <HamburgerIcon onClick={handleBurgerMenuClick}
mobileNavHidden={mobileNavHidden}/>}
Expand Down

0 comments on commit ad7d15b

Please sign in to comment.