Last active
July 26, 2022 22:22
-
-
Save semanticpixel/580aa502e0d3dabb8a148156daaf324f to your computer and use it in GitHub Desktop.
Badge-in-element
This file contains hidden or 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
import Component from '@glimmer/component'; | |
import STEPS from '../steps'; | |
export default class extends Component { | |
get destinationElement() { | |
return document.getElementById('badge-outlet'); | |
} | |
get styles() { | |
const newDestinationElement = document.getElementById(`${STEPS[this.args.step]}-2`); | |
const rect = newDestinationElement.getBoundingClientRect(); | |
// console.log('Nav Jobs Rectangle: ', rect); | |
// 8 is sizeOfBadge / 2 | |
// return `top: ${rect.top - 8}px; left: ${rect.right - 8}px`; | |
// 24 is sizeOfBadge / 2 + margin of page (8 + 16) | |
// return `transform: translate(${rect.right - 8}px,${rect.top - 8}px)`; | |
return `transform: translate(${(rect.x + rect.width) - 8}px,${rect.y - 8}px)`; | |
} | |
} |
This file contains hidden or 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
import Component from '@glimmer/component'; | |
import { action } from '@ember/object'; | |
import STEPS from '../steps'; | |
export default class extends Component { | |
get destinationElement() { | |
return document.getElementById(STEPS[this.args.step]); | |
} | |
get styles() { | |
const rect = this.destinationElement.getBoundingClientRect(); | |
// console.log(rect, rect.top, rect.right, rect.bottom, rect.left); | |
// 8 is sizeOfBadge / 2 | |
// return `top: ${-8}px; right: ${-8}px`; | |
return `transform: translate(${rect.width - 8}px,${-8}px)`; | |
} | |
@action | |
animationEnd(e) { | |
console.log('Animation Ended'); | |
const element = e.target; | |
element.classList.remove('badge--animated-focus'); | |
element.classList.remove('badge--animated'); | |
setInterval(() => { | |
element.classList.add('badge--animated'); | |
}, 0); | |
} | |
} |
This file contains hidden or 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
import Controller from '@ember/controller'; | |
import { action } from '@ember/object'; | |
import { tracked } from '@glimmer/tracking'; | |
import STEPS from '../steps'; | |
export default class ApplicationController extends Controller { | |
appName = 'Ember Twiddle'; | |
@tracked stepV1 = 0; | |
@tracked stepV2 = 0; | |
@action onClickV1() { | |
this.stepV1 = (this.stepV1 + 1) % STEPS.length; | |
} | |
@action onClickV2() { | |
this.stepV2 = (this.stepV2 + 1) % STEPS.length; | |
} | |
} |
This file contains hidden or 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
const STEPS = [ | |
'global-nav-home', | |
'global-nav-messaging', | |
'global-nav-jobs', | |
'global-nav-profile', | |
'global-nav-notifications', | |
]; | |
export default STEPS; |
This file contains hidden or 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
body { | |
margin: 12px 16px; | |
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
font-size: 65%; | |
} | |
.global-nav { | |
margin-left: auto; | |
min-height: 52px; | |
} | |
.global-nav__items { | |
display: flex; | |
flex-wrap: nowrap; | |
list-style-type: none; | |
} | |
.global-nav__item { | |
align-items: center; | |
cursor: pointer; | |
display: flex; | |
flex-direction: column; | |
font-size: 1.2rem; | |
font-weight: 400; | |
justify-content: center; | |
line-height: 1.5; | |
min-height: 52px; | |
min-width: 80px; | |
position: relative; | |
text-decoration: none; | |
background-color: #fafafa; | |
border: 1px solid rgba(0,0,0,0.4); | |
} | |
.global-nav__icon { | |
width: 24px; | |
height: 24px; | |
background-color: #ddd; | |
} | |
.global-nav__label { | |
font-size: 1.2rem; | |
color: #666; | |
} | |
.badge { | |
position: absolute; | |
width: 16px; | |
height: 16px; | |
background-color: purple; | |
border-radius: 50%; | |
z-index: 1; | |
} | |
.badge { | |
top: 0; | |
left: 0; | |
} | |
.badge--animated-focus { | |
animation: focus 1s cubic-bezier(0,0,0.32,1); | |
} | |
.badge--animated { | |
animation: pulse 3s linear 2s; | |
} | |
.badge--animated-v2 { | |
animation: pulse 3s linear 3s infinite; | |
} | |
.badge--outlet { | |
background-color: pink; | |
} | |
.badge__container { | |
/* position: fixed; */ | |
position: absolute; | |
width: 16px; | |
height: 16px; | |
top: 0; | |
left: 0; | |
z-index: 1; | |
/* transition: transform 1000ms cubic-bezier(0,0,0.32,1); */ | |
} | |
@keyframes focus { | |
0% { | |
transform: scale(0); | |
opacity: 0; | |
border: 0; | |
background-color: transparent; | |
} | |
50% { | |
transform: scale(3); | |
opacity: 1; | |
border: 2px solid; | |
background-color: transparent; | |
} | |
100% { | |
transform: scale(1); | |
opacity: 1; | |
} | |
} | |
@keyframes pulse { | |
0% { | |
transform: scale(1); | |
} | |
/* 40% { | |
transform: scale(1); | |
} */ | |
10% { | |
transform: scale(1.5); | |
} | |
90% { | |
transform: scale(1.5); | |
} | |
100% { | |
transform: scale(1); | |
} | |
} | |
@keyframes pulse-v2 { | |
0%, 50%, { | |
transform: scale(1); | |
} | |
51% { | |
transform: scale(1.5); | |
} | |
70%, 100% { | |
transform: scale(1); | |
} | |
} | |
@keyframes pulse-v3 { | |
0% { | |
transform: scale(1); | |
} | |
20%, { | |
transform: scale(1.5); | |
} | |
100% { | |
transform: scale(1.5); | |
} | |
} |
This file contains hidden or 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
{ | |
"version": "0.17.1", | |
"EmberENV": { | |
"FEATURES": {}, | |
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false, | |
"_APPLICATION_TEMPLATE_WRAPPER": true, | |
"_JQUERY_INTEGRATION": true | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js", | |
"ember": "3.18.1", | |
"ember-template-compiler": "3.18.1", | |
"ember-testing": "3.18.1" | |
}, | |
"addons": { | |
"@glimmer/component": "1.0.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment