Skip to content

Commit 65c7cd6

Browse files
authored
Add HTML data attributes to background and hero elements (swiftlang#940)
* Add HTML data attributes We want to add HTML data attributes [1] to background and hero elements to be able to recognize them. We are only interested in hero that have an enhance background, so in the case that it doesn't have it, the data attribute won't be rendered. [1] https://developer.mozilla.org/en-US/docs/Web/HTML/How_to/Use_data_attributes * Fix tutorial background Add a default background-color for tutorials. Also, we want to remove any padding or margin of tutorial background for IDEs. Fixes rdar://149293880
1 parent 6c715fe commit 65c7cd6

File tree

10 files changed

+31
-5
lines changed

10 files changed

+31
-5
lines changed

src/components/DocumentationTopic/Hero/DocumentationHero.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
'documentation-hero--disabled': !enhanceBackground,
1515
}]"
1616
:style="styles"
17+
:data-hero="enhanceBackground"
1718
>
1819
<div class="icon">
1920
<TopicTypeIcon

src/components/Tutorial.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
-->
1010

1111
<template>
12-
<div class="tutorial">
12+
<div class="tutorial" data-background>
1313
<NavigationBar
1414
v-if="!isTargetIDE"
1515
:technology="metadata.category"

src/components/Tutorial/Hero.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
:title="sectionTitle"
1515
class="tutorial-hero"
1616
>
17-
<div class="hero dark">
17+
<div class="hero dark" data-hero>
1818
<div v-if="backgroundImageUrl" class="bg" :style="bgStyle" />
1919
<slot name="above-title" />
2020
<Row>

src/components/TutorialsOverview.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
{{ title }}
1919
</Nav>
2020
<main id="app-main" tabindex="0" class="main">
21-
<div class="radial-gradient">
21+
<div class="radial-gradient" data-hero>
2222
<slot name="above-hero" />
2323
<Hero
2424
v-if="heroSection"
@@ -129,13 +129,19 @@ export default {
129129
margin-top: -$nav-height;
130130
padding-top: $nav-height;
131131
132+
@include inTargetIde() {
133+
margin-top: 0;
134+
padding-top: 0;
135+
}
136+
132137
@include breakpoint(small) {
133138
margin-top: -$nav-height-small;
134139
padding-top: $nav-height-small;
135140
}
136141
137142
background: var(--color-tutorials-overview-fill-secondary,
138143
var(--color-tutorials-overview-background));
144+
background-color: var(--color-tutorials-overview-background-color);
139145
}
140146
141147
// HACK - remove the gradient for firefox only

src/components/TutorialsOverview/LearningPath.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
-->
1010

1111
<template>
12-
<div class="learning-path" :class="classes">
12+
<div class="learning-path" :class="classes" data-background>
1313
<div class="main-container">
1414
<div v-if="!isTargetIDE" class="secondary-content-container">
1515
<TutorialsNavigation :sections="sections" :aria-label="$t('sections.on-this-page')" />

src/styles/core/colors/_light.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@
183183
--color-tutorial-navbar-dropdown-background: var(--color-fill);
184184
--color-tutorial-navbar-dropdown-border: var(--color-fill-gray);
185185
--color-tutorial-quiz-border-active: var(--color-figure-blue);
186-
--color-tutorials-overview-background: #{dark-color(fill-secondary)};
186+
--color-tutorials-overview-background-color: #{dark-color(fill-secondary)};
187+
--color-tutorials-overview-background: var(--color-tutorials-overview-background-color);
187188
--color-tutorials-overview-content: #{dark-color(figure-gray)};
188189
--color-tutorials-overview-content-alt: #{dark-color(figure-gray)};
189190
--color-tutorials-overview-eyebrow: #{dark-color(figure-gray-secondary)};

tests/unit/components/DocumentationTopic/Hero/DocumentationHero.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ describe('DocumentationHero', () => {
4141
const withBackground = createWrapper();
4242
expect(withBackground.classes('documentation-hero')).toBe(true);
4343
expect(withBackground.classes('documentation-hero--disabled')).toBe(false);
44+
// exposes a data-hero HTML data attribute
45+
expect(withBackground.attributes('data-hero')).toBeDefined();
4446

4547
const withoutBackground = createWrapper({
4648
propsData: {
@@ -49,6 +51,8 @@ describe('DocumentationHero', () => {
4951
});
5052
expect(withoutBackground.classes('documentation-hero')).toBe(true);
5153
expect(withoutBackground.classes('documentation-hero--disabled')).toBe(true);
54+
// does not expose a data-hero HTML data attribute if there is no background
55+
expect(withoutBackground.attributes('data-hero')).not.toBeDefined();
5256
});
5357

5458
it('renders the DocumentationHero, enabled', () => {

tests/unit/components/Tutorial.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ describe('Tutorial', () => {
189189
expect(wrapper.is('div.tutorial')).toBe(true);
190190
});
191191

192+
it('exposes a data-background in its background element', () => {
193+
expect(wrapper.attributes('data-background')).toBeDefined();
194+
});
195+
192196
it('renders a `NavigationBar`', () => {
193197
const nav = wrapper.find(NavigationBar);
194198
expect(nav.exists()).toBe(true);

tests/unit/components/TutorialsOverview.spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ describe('TutorialsOverview', () => {
9494
expect(wrapper.contains(Nav)).toBe(false);
9595
});
9696

97+
it('exposes a data-hero HTML data attribute in the radial gradient', () => {
98+
const radialGradient = wrapper.find('.radial-gradient');
99+
expect(radialGradient.exists()).toBe(true);
100+
expect(radialGradient.attributes('data-hero')).toBeDefined();
101+
});
102+
97103
it('renders a `Hero`', () => {
98104
const hero = wrapper.find(Hero);
99105
expect(hero.exists()).toBe(true);

tests/unit/components/TutorialsOverview/LearningPath.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ describe('LearningPath', () => {
5353
expect(wrapper.is('.learning-path')).toBe(true);
5454
});
5555

56+
it('exposes a data-background in its background element', () => {
57+
expect(wrapper.attributes('data-background')).toBeDefined();
58+
});
59+
5660
it('renders a TutorialsNavigation if in Web mode', () => {
5761
const navigation = wrapper.find(TutorialsNavigation);
5862
expect(navigation.exists()).toBe(true);

0 commit comments

Comments
 (0)