Skip to content

Further enhance the optional DocumentationHero background #421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/components/DocumentationTopic.vue
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,10 @@ export default {
type: Boolean,
default: false,
},
disableHeroBackground: {
type: Boolean,
default: false,
},
},
provide() {
// NOTE: this is not reactive: if this.references change, the provided value
Expand Down Expand Up @@ -334,7 +338,18 @@ export default {
shouldShowLanguageSwitcher: ({ objcPath, swiftPath, isTargetIDE }) => (
!!(objcPath && swiftPath && isTargetIDE)
),
enhanceBackground: ({ symbolKind }) => (symbolKind ? (symbolKind === 'module') : true),
enhanceBackground: ({ symbolKind, disableHeroBackground, topicSectionsStyle }) => {
if (
// if the hero bg is forcefully disabled
disableHeroBackground
// or the topicSectionsStyle is a `grid` type
|| topicSectionsStyle === TopicSectionsStyle.compactGrid
|| topicSectionsStyle === TopicSectionsStyle.detailedGrid
) {
return false;
}
return symbolKind ? (symbolKind === 'module') : true;
},
shortHero: ({
roleHeading,
abstract,
Expand Down
18 changes: 17 additions & 1 deletion tests/unit/components/DocumentationTopic.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,22 @@ describe('DocumentationTopic', () => {
});
});

it('renders a `DocumentationHero`, disabled, if `disableHeroBackground` prop is `true`', () => {
const hero = wrapper.find(DocumentationHero);
expect(hero.props('enhanceBackground')).toBe(true);
wrapper.setProps({ disableHeroBackground: true });
expect(hero.props('enhanceBackground')).toBe(false);
});

it('renders a `DocumentationHero`, disabled, if the `topicSectionsStyle` is a grid type', () => {
const hero = wrapper.find(DocumentationHero);
expect(hero.props('enhanceBackground')).toBe(true);
wrapper.setProps({ topicSectionsStyle: TopicSectionsStyle.detailedGrid });
expect(hero.props('enhanceBackground')).toBe(false);
wrapper.setProps({ topicSectionsStyle: TopicSectionsStyle.compactGrid });
expect(hero.props('enhanceBackground')).toBe(false);
});

it('renders a `Title`', () => {
const hero = wrapper.find(DocumentationHero);

Expand Down Expand Up @@ -463,7 +479,7 @@ describe('DocumentationTopic', () => {
});
});

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

const topicSections = [
Expand Down
1 change: 1 addition & 0 deletions tests/unit/views/DocumentationTopic.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ describe('DocumentationTopic', () => {
},
enableOnThisPageNav: false,
topicSectionsStyle: TopicSectionsStyle.list, // default value
disableHeroBackground: false,
});
});

Expand Down