-
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.
Merge pull request #1 from aouerfelli/develop
Merged changes for v1.1.0
- Loading branch information
Showing
17 changed files
with
574 additions
and
416 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,13 @@ | ||
# http://EditorConfig.org | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
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 @@ | ||
{ | ||
"root": true, | ||
"extends": "airbnb-base", | ||
"env": { | ||
"browser": true, | ||
"node": true | ||
}, | ||
"rules": { | ||
"import/extensions": 0, | ||
"import/no-extraneous-dependencies": 0, | ||
"import/no-unresolved": [2, { "ignore": ["electron"] }], | ||
"no-param-reassign": ["error", { "props": false }] | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
dist | ||
node_modules | ||
npm-debug.log | ||
debug.log | ||
*.log | ||
.DS_Store | ||
dist |
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,92 @@ | ||
<template id="action-button-template"> | ||
<style> | ||
/* This is the only workaround I could think of (besides having a duplicate copy of the needed styles) */ | ||
@import url('../styles/base.css'); | ||
|
||
.container { | ||
display: inline-flex; | ||
flex-direction: column-reverse; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
|
||
.button { | ||
position: relative; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
padding: 0.375rem; | ||
margin: 0.75rem; | ||
margin-top: 0; | ||
outline: none; | ||
border: none; | ||
background-color: transparent; | ||
} | ||
|
||
.button::before { | ||
content: ''; | ||
position: absolute; | ||
z-index: -1; | ||
width: 0; | ||
height: 0; | ||
border-radius: 50%; | ||
background-color: var(--color-grey); | ||
opacity: 0; | ||
transition: all 0.3s var(--curve-standard); | ||
transition-property: width, height, opacity; | ||
will-change: width, height, opacity; | ||
} | ||
|
||
.button:active::before { | ||
width: 3rem; | ||
height: 3rem; | ||
opacity: 0.3; | ||
} | ||
|
||
.button .icon-container { | ||
width: 2.25rem; | ||
height: 2.25rem; | ||
fill: var(--color-grey); | ||
transition: fill 0.3s var(--curve-standard); | ||
will-change: fill; | ||
} | ||
|
||
.button:focus .icon-container { | ||
fill: var(--color-primary-light); | ||
} | ||
|
||
.button:hover .icon-container { | ||
fill: var(--color-primary); | ||
} | ||
|
||
.button:active .icon-container { | ||
fill: var(--color-primary-dark); | ||
} | ||
|
||
.label { | ||
display: inline-block; | ||
padding: 0.25rem 0.5rem; | ||
font-size: 0.8em; | ||
border-radius: var(--corner-radius); | ||
color: var(--font-color-light); | ||
background-color: var(--font-color-dark); | ||
opacity: 0; | ||
transition: opacity 0.3s var(--curve-sharp); | ||
} | ||
|
||
.button:hover ~ .label { | ||
opacity: 0.7; | ||
} | ||
</style> | ||
|
||
<div class="container"> | ||
<button class="button"> | ||
<svg class="icon-container" viewBox="0 0 24 24"> | ||
<path class="icon" d="" /> | ||
</svg> | ||
</button> | ||
<p class="label"></p> | ||
</div> | ||
</template> | ||
|
||
<script src="action-button.js"></script> |
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,105 @@ | ||
/* eslint-disable no-underscore-dangle */ | ||
|
||
class ActionButton extends HTMLElement { | ||
|
||
static get observedAttributes() { | ||
return ['label', 'icon']; | ||
} | ||
|
||
constructor() { | ||
super(); | ||
|
||
const ownerDocument = document.currentScript.ownerDocument; | ||
const template = ownerDocument.querySelector('#action-button-template'); | ||
const shadowRoot = this.attachShadow({ mode: 'open' }); | ||
shadowRoot.appendChild(template.content.cloneNode(true)); | ||
|
||
this._components = { | ||
container: shadowRoot.querySelector('.container'), | ||
button: shadowRoot.querySelector('.button'), | ||
label: shadowRoot.querySelector('.label'), | ||
icon: shadowRoot.querySelector('.icon'), | ||
}; | ||
this._action = undefined; | ||
} | ||
|
||
getAttributeValue(attributeName) { | ||
return this.hasAttribute(attributeName) ? this.getAttribute(attributeName) : ''; | ||
} | ||
|
||
get label() { | ||
return this.getAttributeValue(this._components.label.className); | ||
} | ||
|
||
set label(label) { | ||
if (!label) { | ||
return; | ||
} | ||
|
||
this._components.label.textContent = label; | ||
} | ||
|
||
get icon() { | ||
return this.getAttributeValue(this._components.icon.className); | ||
} | ||
|
||
set icon(icon) { | ||
if (!icon) { | ||
return; | ||
} | ||
|
||
this._components.icon.setAttribute('d', icon); | ||
} | ||
|
||
connectedCallback() { | ||
// Action is a noop function by default | ||
this.setAction(() => {}); | ||
} | ||
|
||
disconnectedCallback() { | ||
// Remove action from element on callback | ||
this.removeAction(); | ||
} | ||
|
||
attributeChangedCallback(attributeName, oldValue, newValue) { | ||
if (attributeName === this._components.label.className) { | ||
this.label = newValue; | ||
// Must check with baseVal property for icon because the className is a SVGAnimatedString object | ||
} else if (attributeName === this._components.icon.className.baseVal) { | ||
this.icon = newValue; | ||
} | ||
} | ||
|
||
setAction(action) { | ||
if (typeof action !== 'function') { | ||
return; | ||
} | ||
|
||
// Remove the current action and replace it with the new one | ||
this.removeAction(); | ||
this._action = action; | ||
this._components.button.addEventListener('click', this._action); | ||
} | ||
|
||
removeAction() { | ||
this._components.button.removeEventListener('click', this._action); | ||
} | ||
|
||
hideButton() { | ||
this.setHidden(true); | ||
} | ||
|
||
showButton() { | ||
this.setHidden(false); | ||
} | ||
|
||
setHidden(hidden) { | ||
if (typeof hidden !== 'boolean') { | ||
return; | ||
} | ||
|
||
this._components.container.style.display = hidden ? 'none' : ''; | ||
} | ||
} | ||
|
||
window.customElements.define('action-button', ActionButton); |
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
Oops, something went wrong.