Skip to content

Commit 29c73a8

Browse files
committed
feat: add events for page transitions
1 parent 31c0a47 commit 29c73a8

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

custom-elements.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@
5454
"default": "\"\""
5555
}
5656
],
57+
"events": [
58+
{
59+
"name": "helium-start",
60+
"description": "Fires when the page transition starts"
61+
},
62+
{
63+
"name": "helium-end",
64+
"description": "Fires when the page transition ends"
65+
}
66+
],
5767
"slots": [
5868
{
5969
"name": "",

demo/components/property-demo.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ class PropertyDemo extends PageViewElement {
2323
If you don't use the <code>attrForSelected</code> property you can
2424
just set the numerical index of which element you wish to show.
2525
</p>
26+
<p>
27+
Note that we're using the <code>helium-start</code> and
28+
<code>helium-end</code> events to disable the input changing the
29+
slides while the animation is running
30+
</p>
2631
<p>
2732
<label for="select-index">Slide Index:</label>
2833
<input
@@ -40,6 +45,8 @@ class PropertyDemo extends PageViewElement {
4045
class="sample-pages"
4146
selected="${this._selectedIndex}"
4247
.animationClasses="${this._propAnimationClasses}"
48+
@helium-start="${this._toggleDisabledIndex}"
49+
@helium-end="${this._toggleDisabledIndex}"
4350
>
4451
<div>Slide index: 0</div>
4552
<div>Slide index: 1</div>
@@ -158,6 +165,8 @@ class PropertyDemo extends PageViewElement {
158165
<helium-animated-pages
159166
selected="\${this._selectedIndex}"
160167
.animationClasses="\${this._propAnimationClasses}"
168+
@helium-start="\${this._toggleDisabledIndex}"
169+
@helium-end="\${this._toggleDisabledIndex}"
161170
>
162171
<div>Slide index: 0</div>
163172
<div>Slide index: 1</div>
@@ -180,6 +189,10 @@ class PropertyDemo extends PageViewElement {
180189
this._selectedIndex = parseInt(e.target.value);
181190
}
182191
}
192+
_toggleDisabledIndex() {
193+
const input = this.shadowRoot.querySelector('#select-index');
194+
input.disabled = !input.disabled;
195+
}
183196
_nameChanged(e) {
184197
if (e.target.value) {
185198
this._selectedName = e.target.value;

src/HeliumAnimatedPages.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ const _isString = (next) => {
1313
*
1414
* @slot - The slot for the pages to animate
1515
*
16+
* @fires helium-start - Fires when the page transition starts
17+
* @fires helium-end - Fires when the page transition ends
18+
*
1619
* @cssprop --helium-children-visible - Whether this component should be visible if it's a children of another `helium-animated-pages`.
1720
*
1821
* @prop {Boolean} isAnimating - This property will get the state of the animation, whether it's currently in the middle of an animation or not.
@@ -242,12 +245,22 @@ export default class HeliumAnimatedPages extends LitElement {
242245
}
243246

244247
_changeActive(next, prev) {
248+
const startEvent = new CustomEvent('helium-start', {
249+
composed: true,
250+
bubbles: true,
251+
});
252+
this.dispatchEvent(startEvent);
245253
if (!this.animationClasses) {
246254
// this is a fallback just in case animationClasses wasn't set
247255
this._inPage.setAttribute('active', true);
248256
if (this._outPage) {
249257
this._outPage.removeAttribute('active');
250258
}
259+
const endEvent = new CustomEvent('helium-end', {
260+
composed: true,
261+
bubbles: true,
262+
});
263+
this.dispatchEvent(endEvent);
251264
} else {
252265
this._currentClasses = this._animationClasses(next, prev);
253266
this._beginAnimation();
@@ -309,6 +322,11 @@ export default class HeliumAnimatedPages extends LitElement {
309322
this._inPage = null;
310323
this._outPage = null;
311324
this._currentClasses = null;
325+
const endEvent = new CustomEvent('helium-end', {
326+
composed: true,
327+
bubbles: true,
328+
});
329+
this.dispatchEvent(endEvent);
312330
}
313331
}
314332
}

0 commit comments

Comments
 (0)