-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added TomsterPopper component to test keyboard event handling
- Loading branch information
1 parent
c597a69
commit 237218d
Showing
11 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<div id="tomster-popper" class={{if this.isVisible 'show' 'hide'}}> | ||
<div id="greeting"> | ||
{{t "general.greeting" name="Tomster"}} | ||
</div> | ||
<img | ||
src="/assets/images/teaching-tomster.png" | ||
alt={{t "general.teachingTomster"}} | ||
{{on-key 'ctrl+shift+KeyT' this.popToggle event='keyup'}} | ||
/> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import Component from '@glimmer/component'; | ||
import { tracked } from '@glimmer/tracking'; | ||
import { action } from '@ember/object'; | ||
|
||
export default class TomsterPopperComponent extends Component { | ||
@tracked isVisible = false; | ||
|
||
@action | ||
popToggle() { | ||
this.isVisible = !this.isVisible; | ||
|
||
console.log(`tomster says...${this.isVisible ? 'hello' : 'goodbye'}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#tomster-popper { | ||
bottom: -100vw; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
left: 50%; | ||
position: fixed; | ||
z-index: 10; | ||
} | ||
#tomster-popper.show { | ||
animation-duration: 500ms; | ||
animation-name: slidein; | ||
bottom: -70px; | ||
display: flex; | ||
} | ||
#tomster-popper.hide { | ||
animation-duration: 1s; | ||
animation-name: slideout; | ||
bottom: -100vw; | ||
display: flex; | ||
} | ||
#tomster-popper #greeting { | ||
background-color: #fff; | ||
border: 1px solid #000; | ||
border-radius: 5px; | ||
bottom: 5px; | ||
padding: 5px; | ||
position: relative; | ||
width: 140px; | ||
} | ||
#tomster-popper img { | ||
height: 200px; | ||
width: 200px; | ||
} | ||
|
||
@keyframes slidein { | ||
from { | ||
bottom: -100vw; | ||
translate: 0 10vw; | ||
scale: 50% 50%; | ||
} | ||
|
||
to { | ||
bottom: -70px; | ||
translate: 0 0; | ||
scale: 100% 1; | ||
} | ||
} | ||
|
||
@keyframes slideout { | ||
from { | ||
bottom: -70px; | ||
translate: 0 0; | ||
scale: 100% 1; | ||
} | ||
|
||
to { | ||
bottom: -100vw; | ||
translate: 0 10vw; | ||
scale: 50% 50%; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const intersection = (r1, r2) => { | ||
const xOverlap = Math.max(0, Math.min(r1.x + r1.w, r2.x + r2.w) - Math.max(r1.x, r2.x)); | ||
const yOverlap = Math.max(0, Math.min(r1.y + r1.h, r2.y + r2.h) - Math.max(r1.y, r2.y)); | ||
const overlapArea = xOverlap * yOverlap; | ||
|
||
return overlapArea; | ||
}; | ||
|
||
const percentInView = (div) => { | ||
const rect = div.getBoundingClientRect(); | ||
|
||
const dimension = { x: rect.x, y: rect.y, w: rect.width, h: rect.height }; | ||
const viewport = { x: 0, y: 0, w: window.innerWidth, h: window.innerHeight }; | ||
const divsize = dimension.w * dimension.h; | ||
const overlap = intersection(dimension, viewport); | ||
const percent = overlap / divsize; | ||
|
||
return percent; | ||
}; | ||
|
||
export function elementInView(elemId) { | ||
console.log( | ||
'elementInView?', | ||
percentInView(document.getElementById(elemId)), | ||
percentInView(document.getElementById(elemId)) > 0, | ||
); | ||
return percentInView(document.getElementById(elemId)) > 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupRenderingTest } from 'remember-stuff/tests/helpers'; | ||
import { render } from '@ember/test-helpers'; | ||
import { hbs } from 'ember-cli-htmlbars'; | ||
// import { elementInView } from '../../helpers/intersection-observing'; | ||
|
||
module('Integration | Component | tomster-popper', function (hooks) { | ||
setupRenderingTest(hooks); | ||
|
||
test('it renders', async function (assert) { | ||
await render(hbs`<TomsterPopper />`); | ||
|
||
assert.dom('#tomster-popper').exists(); | ||
|
||
// TODO | ||
// assert.false(elementInView('tomster-popper')); | ||
|
||
// let tomster = document.querySelector('#tomster-popper'); | ||
// tomster.classList.add('show'); | ||
|
||
// assert.true(elementInView('tomster-popper')); | ||
|
||
// tomster.classList.remove('show'); | ||
// tomster.classList.add('hide'); | ||
|
||
// assert.false(elementInView('tomster-popper')); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters