Skip to content

Commit 37de1e5

Browse files
authored
Merge pull request #2176 from tf/nav-logo-prop
Allow overriding navigation bar logo settings via prop
2 parents 16cef60 + 26ec85f commit 37de1e5

File tree

3 files changed

+59
-8
lines changed

3 files changed

+59
-8
lines changed

entry_types/scrolled/package/spec/widgets/defaultNavigation/Defaultnavigation-spec.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,53 @@ describe('DefaultNavigation', () => {
3232
});
3333
});
3434

35+
it('uses theme logo by default', () => {
36+
const {getByRole} = renderInEntry(
37+
<DefaultNavigation configuration={{}} />,
38+
{
39+
seed: {
40+
themeAssets: {
41+
logoDesktop: 'logo-desktop.png'
42+
},
43+
themeOptions: {
44+
logoUrl: 'https://example.com',
45+
logoAltText: 'My logo'
46+
}
47+
}
48+
}
49+
);
50+
51+
expect(getByRole('link', {name: 'My logo'})).toBeInTheDocument();
52+
expect(getByRole('link', {name: 'My logo'})).toHaveAttribute('href', 'https://example.com');
53+
expect(getByRole('img', {name: 'My logo'})).toHaveAttribute('src', 'logo-desktop.png');
54+
});
55+
56+
it('takes logo props', () => {
57+
const {getByRole} = renderInEntry(
58+
<DefaultNavigation configuration={{}}
59+
logo={{
60+
srcDesktop: "other-logo.png",
61+
url: "https://other.example.com",
62+
altText: "Other logo"
63+
}} />,
64+
{
65+
seed: {
66+
themeAssets: {
67+
logoDesktop: 'logo.png'
68+
},
69+
themeOptions: {
70+
logoUrl: 'https://exmaple.com',
71+
logoAltText: 'My logo'
72+
}
73+
}
74+
}
75+
);
76+
77+
expect(getByRole('link', {name: 'Other logo'})).toBeInTheDocument();
78+
expect(getByRole('link', {name: 'Other logo'})).toHaveAttribute('href', 'https://other.example.com');
79+
expect(getByRole('img', {name: 'Other logo'})).toHaveAttribute('src', 'other-logo.png');
80+
});
81+
3582
it('supports extra buttons component', () => {
3683
const ExtraButtons = () => <button>Extra</button>;
3784
const {queryByRole} = renderInEntry(

entry_types/scrolled/package/src/widgets/defaultNavigation/DefaultNavigation.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ import {Scroller} from './Scroller';
2626

2727
import styles from './DefaultNavigation.module.css';
2828

29-
export function DefaultNavigation({configuration, ExtraButtons, MobileMenu}) {
29+
export function DefaultNavigation({
30+
configuration,
31+
ExtraButtons, MobileMenu,
32+
logo
33+
}) {
3034
const [navExpanded, setNavExpanded] = useState(true);
3135
const [mobileNavHidden, setMobileNavHidden] = useState(true);
3236
const [readingProgress, setReadingProgress] = useState(0);
@@ -132,7 +136,7 @@ export function DefaultNavigation({configuration, ExtraButtons, MobileMenu}) {
132136
mobileNavHidden={mobileNavHidden}/>}
133137

134138
<SkipLinks />
135-
<Logo />
139+
<Logo {...logo} />
136140

137141
{renderNav()}
138142
{MobileMenu && <MobileMenu configuration={configuration}

entry_types/scrolled/package/src/widgets/defaultNavigation/Logo.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@ import {useTheme} from 'pageflow-scrolled/frontend';
55

66
import styles from './DefaultNavigation.module.css';
77

8-
export function Logo() {
8+
export function Logo({srcMobile, srcDesktop, url, altText}) {
99
const theme = useTheme();
1010
return (
1111
<a target="_blank"
1212
rel="noopener noreferrer"
13-
href={theme.options.logoUrl}
13+
href={url || theme.options.logoUrl}
1414
className={classNames(
1515
styles.logo,
1616
{[styles.centerMobileLogo]:
1717
theme.options.defaultNavigationMobileLogoPosition === 'center'}
1818
)}>
1919
<picture>
20-
<source media="(max-width: 780px)" srcSet={theme.assets.logoMobile} />
21-
<source media="(min-width: 781px)" srcSet={theme.assets.logoDesktop} />
22-
<img src={theme.assets.logoDesktop}
23-
alt={theme.options.logoAltText} />
20+
<source media="(max-width: 780px)" srcSet={srcMobile || theme.assets.logoMobile} />
21+
<source media="(min-width: 781px)" srcSet={srcDesktop || theme.assets.logoDesktop} />
22+
<img src={srcDesktop || theme.assets.logoDesktop}
23+
alt={altText || theme.options.logoAltText} />
2424
</picture>
2525
</a>
2626
);

0 commit comments

Comments
 (0)