2019-02-23 20:32:00 +00:00
|
|
|
<button type="button"
|
|
|
|
title={label}
|
|
|
|
aria-label={label}
|
|
|
|
aria-pressed={pressable ? !!pressed : void 0}
|
|
|
|
aria-hidden={ariaHidden}
|
|
|
|
class={computedClass}
|
|
|
|
{disabled}
|
|
|
|
ref:node
|
|
|
|
>
|
|
|
|
<svg class="icon-button-svg {svgClassName || ''}" ref:svg>
|
|
|
|
<use xlink:href={href} />
|
|
|
|
</svg>
|
|
|
|
</button>
|
2018-01-28 20:51:48 +00:00
|
|
|
<style>
|
2018-03-16 15:42:10 +00:00
|
|
|
.icon-button {
|
2018-01-28 20:51:48 +00:00
|
|
|
padding: 6px 10px;
|
|
|
|
background: none;
|
|
|
|
border: none;
|
2018-04-05 04:45:19 +00:00
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
2018-01-28 20:51:48 +00:00
|
|
|
}
|
|
|
|
|
2018-03-16 15:42:10 +00:00
|
|
|
.icon-button-svg {
|
2018-01-28 20:51:48 +00:00
|
|
|
width: 24px;
|
|
|
|
height: 24px;
|
|
|
|
fill: var(--action-button-fill-color);
|
2018-03-23 03:09:20 +00:00
|
|
|
pointer-events: none; /* hack for Edge */
|
2018-01-28 20:51:48 +00:00
|
|
|
}
|
|
|
|
|
2018-03-16 15:42:10 +00:00
|
|
|
.icon-button.big-icon .icon-button-svg {
|
2018-01-28 20:51:48 +00:00
|
|
|
width: 32px;
|
|
|
|
height: 32px;
|
|
|
|
}
|
|
|
|
|
2018-04-05 04:45:19 +00:00
|
|
|
/*
|
|
|
|
* regular styles
|
|
|
|
*/
|
|
|
|
|
2018-03-16 15:42:10 +00:00
|
|
|
.icon-button:hover .icon-button-svg {
|
2018-01-28 20:51:48 +00:00
|
|
|
fill: var(--action-button-fill-color-hover);
|
|
|
|
}
|
|
|
|
|
2019-02-03 19:10:52 +00:00
|
|
|
.icon-button.not-pressable:active .icon-button-svg,
|
|
|
|
.icon-button.same-pressed:active .icon-button-svg {
|
2018-01-28 20:51:48 +00:00
|
|
|
fill: var(--action-button-fill-color-active);
|
|
|
|
}
|
|
|
|
|
2019-02-03 19:10:52 +00:00
|
|
|
.icon-button.pressed.not-same-pressed .icon-button-svg {
|
2018-03-21 16:38:20 +00:00
|
|
|
fill: var(--action-button-fill-color-pressed);
|
2018-01-28 20:51:48 +00:00
|
|
|
}
|
|
|
|
|
2019-02-03 19:10:52 +00:00
|
|
|
.icon-button.pressed.not-same-pressed:hover .icon-button-svg {
|
2018-01-28 20:51:48 +00:00
|
|
|
fill: var(--action-button-fill-color-pressed-hover);
|
|
|
|
}
|
|
|
|
|
2019-02-03 19:10:52 +00:00
|
|
|
.icon-button.pressed.not-same-pressed:active .icon-button-svg {
|
2018-01-28 20:51:48 +00:00
|
|
|
fill: var(--action-button-fill-color-pressed-active);
|
|
|
|
}
|
2018-04-05 04:45:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* muted
|
|
|
|
*/
|
|
|
|
|
|
|
|
.icon-button.muted-style .icon-button-svg {
|
|
|
|
fill: var(--action-button-deemphasized-fill-color);
|
|
|
|
}
|
|
|
|
|
|
|
|
.icon-button.muted-style:hover .icon-button-svg {
|
|
|
|
fill: var(--action-button-deemphasized-fill-color-hover);
|
|
|
|
}
|
|
|
|
|
2019-02-03 19:10:52 +00:00
|
|
|
.icon-button.muted-style.not-pressable:active .icon-button-svg,
|
|
|
|
.icon-button.muted-style.same-pressed:active .icon-button-svg {
|
2018-04-05 04:45:19 +00:00
|
|
|
fill: var(--action-button-deemphasized-fill-color-active);
|
|
|
|
}
|
|
|
|
|
2019-02-03 19:10:52 +00:00
|
|
|
.icon-button.muted-style.pressed.not-same-pressed .icon-button-svg {
|
2018-04-05 04:45:19 +00:00
|
|
|
fill: var(--action-button-deemphasized-fill-color-pressed);
|
|
|
|
}
|
|
|
|
|
2019-02-03 19:10:52 +00:00
|
|
|
.icon-button.muted-style.pressed.not-same-pressed:hover .icon-button-svg {
|
2018-04-05 04:45:19 +00:00
|
|
|
fill: var(--action-button-deemphasized-fill-color-pressed-hover);
|
|
|
|
}
|
|
|
|
|
2019-02-03 19:10:52 +00:00
|
|
|
.icon-button.muted-style.pressed.not-same-pressed:active .icon-button-svg {
|
2018-04-05 04:45:19 +00:00
|
|
|
fill: var(--action-button-deemphasized-fill-color-pressed-active);
|
|
|
|
}
|
|
|
|
|
2018-02-24 22:49:28 +00:00
|
|
|
</style>
|
|
|
|
<script>
|
2018-03-15 01:52:33 +00:00
|
|
|
import { classname } from '../_utils/classname'
|
2018-03-23 03:23:00 +00:00
|
|
|
import { store } from '../_store/store'
|
2019-02-18 19:47:02 +00:00
|
|
|
import { animate } from '../_utils/animate'
|
2018-03-15 01:52:33 +00:00
|
|
|
|
2018-02-24 22:49:28 +00:00
|
|
|
export default {
|
2019-02-23 20:32:00 +00:00
|
|
|
oncreate () {
|
|
|
|
let { clickListener, elementId } = this.get()
|
|
|
|
if (clickListener) {
|
|
|
|
this.onClick = this.onClick.bind(this)
|
|
|
|
this.refs.node.addEventListener('click', this.onClick)
|
|
|
|
}
|
|
|
|
if (elementId) {
|
|
|
|
this.refs.node.setAttribute('id', elementId)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
ondestroy () {
|
|
|
|
let { clickListener } = this.get()
|
|
|
|
if (clickListener) {
|
|
|
|
this.refs.node.removeEventListener('click', this.onClick)
|
|
|
|
}
|
|
|
|
},
|
2018-04-30 05:13:41 +00:00
|
|
|
data: () => ({
|
|
|
|
big: false,
|
|
|
|
muted: false,
|
|
|
|
disabled: false,
|
|
|
|
svgClassName: void 0,
|
2019-02-23 20:32:00 +00:00
|
|
|
elementId: void 0,
|
2018-04-30 05:13:41 +00:00
|
|
|
pressable: false,
|
|
|
|
pressed: false,
|
|
|
|
className: void 0,
|
2019-02-10 03:05:59 +00:00
|
|
|
sameColorWhenPressed: false,
|
2019-02-23 20:32:00 +00:00
|
|
|
ariaHidden: false,
|
|
|
|
clickListener: true
|
2018-04-30 05:13:41 +00:00
|
|
|
}),
|
2018-03-23 03:23:00 +00:00
|
|
|
store: () => store,
|
2018-02-24 22:49:28 +00:00
|
|
|
computed: {
|
2019-02-03 19:10:52 +00:00
|
|
|
computedClass: ({ pressable, pressed, big, muted, sameColorWhenPressed, className }) => {
|
2018-03-15 01:52:33 +00:00
|
|
|
return classname(
|
2018-02-24 22:49:28 +00:00
|
|
|
'icon-button',
|
|
|
|
!pressable && 'not-pressable',
|
|
|
|
pressed && 'pressed',
|
|
|
|
big && 'big-icon',
|
2018-04-05 04:45:19 +00:00
|
|
|
muted && 'muted-style',
|
2019-02-03 19:10:52 +00:00
|
|
|
sameColorWhenPressed ? 'same-pressed' : 'not-same-pressed',
|
2018-03-03 05:55:04 +00:00
|
|
|
className
|
2018-03-15 01:52:33 +00:00
|
|
|
)
|
2018-02-24 22:49:28 +00:00
|
|
|
}
|
2018-04-21 15:32:40 +00:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
animate (animation) {
|
|
|
|
let { reduceMotion } = this.store.get()
|
|
|
|
if (!animation || reduceMotion) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
let svg = this.refs.svg
|
2019-02-18 19:47:02 +00:00
|
|
|
animate(svg, animation)
|
2019-02-23 20:32:00 +00:00
|
|
|
},
|
|
|
|
onClick (e) {
|
|
|
|
this.fire('click', e)
|
2018-04-21 15:32:40 +00:00
|
|
|
}
|
2018-02-24 22:49:28 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-05 06:31:46 +00:00
|
|
|
</script>
|