Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit be87cca

Browse files
feat(#41): add a slot "info" to the code template
1 parent fe1239c commit be87cca

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

src/components/slides/deckdeckgo-slide-code/deckdeckgo-slide-code.scss

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ div.deckgo-slide {
44
flex-direction: column;
55
align-items: flex-start;
66
justify-content: flex-start;
7+
8+
position: relative;
79
}
810

911
div.deckgo-slide-code-container {
@@ -21,6 +23,31 @@ div.deckgo-slide-code-container {
2123
transition: opacity 0.5s ease-in;
2224
}
2325

26+
27+
::slotted([slot="info"]) {
28+
display: none;
29+
30+
pointer-events: none;
31+
}
32+
33+
::slotted([slot="info"].deckgo-show-info) {
34+
position: absolute;
35+
top: 0;
36+
left: 0;
37+
38+
width: 100%;
39+
height: 100%;
40+
41+
display: flex;
42+
align-items: center;
43+
justify-content: center;
44+
flex-direction: column;
45+
46+
background: var(--deckgo-show-info-background);
47+
48+
pointer-events: initial;
49+
}
50+
2451
@media print {
2552
div.deckgo-slide {
2653
height: 100%;

src/components/slides/deckdeckgo-slide-code/deckdeckgo-slide-code.tsx

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ export class DeckdeckgoSlideCode implements DeckdeckgoSlide {
4444
this.slideDidLoad.emit();
4545

4646
await this.moveSlots();
47+
48+
await this.showInfo();
4749
}
4850

4951
private moveSlots(): Promise<void> {
@@ -60,6 +62,40 @@ export class DeckdeckgoSlideCode implements DeckdeckgoSlide {
6062
});
6163
}
6264

65+
private showInfo(): Promise<void> {
66+
return new Promise<void>((resolve) => {
67+
// Only on mobile devices
68+
if (DeckdeckgoUtils.isMobile()) {
69+
const info: HTMLElement = this.el.querySelector('[slot=\'info\']');
70+
71+
if (info) {
72+
info.classList.add('deckgo-show-info');
73+
}
74+
}
75+
76+
resolve();
77+
});
78+
}
79+
80+
private hideInfo(): Promise<boolean> {
81+
return new Promise<boolean>((resolve) => {
82+
// Only on mobile devices
83+
if (DeckdeckgoUtils.isMobile()) {
84+
const info: HTMLElement = this.el.querySelector('[slot=\'info\']');
85+
86+
if (info && info.classList.contains('deckgo-show-info')) {
87+
info.classList.remove('deckgo-show-info');
88+
info.style.setProperty('pointer-events', 'none');
89+
90+
resolve(true);
91+
return;
92+
}
93+
}
94+
95+
resolve(false);
96+
});
97+
}
98+
6399
@Method()
64100
beforeSwipe(_enter: boolean): Promise<boolean> {
65101
return new Promise<boolean>(async (resolve) => {
@@ -130,13 +166,20 @@ export class DeckdeckgoSlideCode implements DeckdeckgoSlide {
130166
}
131167

132168
private switchAction(): Promise<void> {
133-
return new Promise<void>((resolve) => {
169+
return new Promise<void>(async (resolve) => {
134170
if (!this.mobile) {
135171
// Scrolling is allowed on not mobile devices
136172
resolve();
137173
return;
138174
}
139175

176+
const infoRemoved: boolean = await this.hideInfo();
177+
if (infoRemoved) {
178+
// On the first click, we just want to hide the info
179+
resolve();
180+
return;
181+
}
182+
140183
this.action = this.action === DeckdeckgoSlideCodeAction.SWIPE ? DeckdeckgoSlideCodeAction.SCROLL : DeckdeckgoSlideCodeAction.SWIPE;
141184

142185
this.scrolling.emit(this.action === DeckdeckgoSlideCodeAction.SCROLL);
@@ -176,6 +219,7 @@ export class DeckdeckgoSlideCode implements DeckdeckgoSlide {
176219
<deckgo-highlight-code src={this.src} anchor={this.anchor} anchorZoom={this.anchorZoom} hideAnchor={this.hideAnchor} language={this.language}></deckgo-highlight-code>
177220
</div>
178221
<slot name="code"></slot>
222+
<slot name="info"></slot>
179223
<slot name="notes"></slot>
180224
</div>;
181225
}

0 commit comments

Comments
 (0)