Skip to content

Commit c264299

Browse files
author
Dobromir Hristov
committed
refactor: disable DocumentationHero background when topicSectionsStyle is a grid, or via a prop from DocumentationTopic
1 parent a5da0f4 commit c264299

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

src/components/DocumentationTopic.vue

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,10 @@ export default {
296296
type: Boolean,
297297
default: false,
298298
},
299+
disableHeroBackground: {
300+
type: Boolean,
301+
default: false,
302+
},
299303
},
300304
provide() {
301305
// NOTE: this is not reactive: if this.references change, the provided value
@@ -334,7 +338,18 @@ export default {
334338
shouldShowLanguageSwitcher: ({ objcPath, swiftPath, isTargetIDE }) => (
335339
!!(objcPath && swiftPath && isTargetIDE)
336340
),
337-
enhanceBackground: ({ symbolKind }) => (symbolKind ? (symbolKind === 'module') : true),
341+
enhanceBackground: ({ symbolKind, disableHeroBackground, topicSectionsStyle }) => {
342+
if (
343+
// if the hero bg is forcefully disabled
344+
disableHeroBackground
345+
// or the topicSectionsStyle is a `grid` type
346+
|| topicSectionsStyle === TopicSectionsStyle.compactGrid
347+
|| topicSectionsStyle === TopicSectionsStyle.detailedGrid
348+
) {
349+
return false;
350+
}
351+
return symbolKind ? (symbolKind === 'module') : true;
352+
},
338353
shortHero: ({
339354
roleHeading,
340355
abstract,

tests/unit/components/DocumentationTopic.spec.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,22 @@ describe('DocumentationTopic', () => {
293293
});
294294
});
295295

296+
it('renders a `DocumentationHero`, disabled, if `disableHeroBackground` prop is `true`', () => {
297+
const hero = wrapper.find(DocumentationHero);
298+
expect(hero.props('enhanceBackground')).toBe(true);
299+
wrapper.setProps({ disableHeroBackground: true });
300+
expect(hero.props('enhanceBackground')).toBe(false);
301+
});
302+
303+
it('renders a `DocumentationHero`, disabled, if the `topicSectionsStyle` is a grid type', () => {
304+
const hero = wrapper.find(DocumentationHero);
305+
expect(hero.props('enhanceBackground')).toBe(true);
306+
wrapper.setProps({ topicSectionsStyle: TopicSectionsStyle.detailedGrid });
307+
expect(hero.props('enhanceBackground')).toBe(false);
308+
wrapper.setProps({ topicSectionsStyle: TopicSectionsStyle.compactGrid });
309+
expect(hero.props('enhanceBackground')).toBe(false);
310+
});
311+
296312
it('renders a `Title`', () => {
297313
const hero = wrapper.find(DocumentationHero);
298314

@@ -463,7 +479,7 @@ describe('DocumentationTopic', () => {
463479
});
464480
});
465481

466-
it('renders `Topics` if there are topic sections, passing the `topicSectionStyles` over', () => {
482+
it('renders `Topics` if there are topic sections, passing the `topicSectionsStyle` over', () => {
467483
expect(wrapper.contains(Topics)).toBe(false);
468484

469485
const topicSections = [

tests/unit/views/DocumentationTopic.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ describe('DocumentationTopic', () => {
543543
},
544544
enableOnThisPageNav: false,
545545
topicSectionsStyle: TopicSectionsStyle.list, // default value
546+
disableHeroBackground: false,
546547
});
547548
});
548549

0 commit comments

Comments
 (0)