Skip to content

Commit 09302d4

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

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
@@ -281,6 +281,10 @@ export default {
281281
type: Array,
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 === TopicSectionsStyle.compactGrid
335+
|| topicSectionsStyle === TopicSectionsStyle.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
@@ -291,6 +291,22 @@ describe('DocumentationTopic', () => {
291291
});
292292
});
293293

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

@@ -461,7 +477,7 @@ describe('DocumentationTopic', () => {
461477
});
462478
});
463479

464-
it('renders `Topics` if there are topic sections, passing the `topicSectionStyles` over', () => {
480+
it('renders `Topics` if there are topic sections, passing the `topicSectionsStyle` over', () => {
465481
expect(wrapper.contains(Topics)).toBe(false);
466482

467483
const topicSections = [

tests/unit/views/DocumentationTopic.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ describe('DocumentationTopic', () => {
542542
swift: ['documentation/swift'],
543543
},
544544
topicSectionsStyle: TopicSectionsStyle.list, // default value
545+
disableHeroBackground: false,
545546
});
546547
});
547548

0 commit comments

Comments
 (0)