Skip to content

Commit 14ab26b

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

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/components/DocumentationTopic.vue

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,10 @@ export default {
281281
type: String,
282282
required: false,
283283
},
284+
disableHeroBackground: {
285+
type: Boolean,
286+
default: false,
287+
},
284288
},
285289
provide() {
286290
// NOTE: this is not reactive: if this.references change, the provided value
@@ -322,7 +326,18 @@ export default {
322326
shouldShowLanguageSwitcher: ({ objcPath, swiftPath, isTargetIDE }) => (
323327
!!(objcPath && swiftPath && isTargetIDE)
324328
),
325-
enhanceBackground: ({ symbolKind }) => (symbolKind ? (symbolKind === 'module') : true),
329+
enhanceBackground: ({ symbolKind, disableHeroBackground, topicSectionsStyle }) => {
330+
if (
331+
// if the hero bg is forcefully disabled
332+
disableHeroBackground
333+
// or the topicSectionsStyle is a `grid` type
334+
|| topicSectionsStyle === TopicStyles.compactGrid
335+
|| topicSectionsStyle === TopicStyles.detailedGrid
336+
) {
337+
return false;
338+
}
339+
return symbolKind ? (symbolKind === 'module') : true;
340+
},
326341
shortHero: ({
327342
roleHeading,
328343
abstract,

tests/unit/components/DocumentationTopic.spec.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,22 @@ describe('DocumentationTopic', () => {
276276
});
277277
});
278278

279+
it('renders a `DocumentationHero`, disabled, if `disableHeroBackground` prop is `true`', () => {
280+
const hero = wrapper.find(DocumentationHero);
281+
expect(hero.props('enhanceBackground')).toBe(true);
282+
wrapper.setProps({ disableHeroBackground: true });
283+
expect(hero.props('enhanceBackground')).toBe(false);
284+
});
285+
286+
it('renders a `DocumentationHero`, disabled, if the `topicSectionsStyle` is a grid type', () => {
287+
const hero = wrapper.find(DocumentationHero);
288+
expect(hero.props('enhanceBackground')).toBe(true);
289+
wrapper.setProps({ topicSectionsStyle: TopicStyles.detailedGrid });
290+
expect(hero.props('enhanceBackground')).toBe(false);
291+
wrapper.setProps({ topicSectionsStyle: TopicStyles.compactGrid });
292+
expect(hero.props('enhanceBackground')).toBe(false);
293+
});
294+
279295
it('renders a `Title`', () => {
280296
const hero = wrapper.find(DocumentationHero);
281297

@@ -446,7 +462,7 @@ describe('DocumentationTopic', () => {
446462
});
447463
});
448464

449-
it('renders `Topics` if there are topic sections, passing the `topicSectionStyles` over', () => {
465+
it('renders `Topics` if there are topic sections, passing the `topicSectionsStyle` over', () => {
450466
expect(wrapper.contains(Topics)).toBe(false);
451467

452468
const topicSections = [

0 commit comments

Comments
 (0)