2019-11-23 11:25:36 -08:00
|
|
|
<!-- Normally "pressable" icons would be toggle buttons, but to avoid having the titles and labels mismatched
|
|
|
|
due to guidelines from http://w3c.github.io/aria-practices/#button , we just use normal buttons and change
|
|
|
|
the aria-label instead. See discussion in: https://github.com/nolanlawson/pinafore/issues/1633 -->
|
|
|
|
<button id={elementId}
|
|
|
|
type="button"
|
|
|
|
title={ariaLabel}
|
2019-11-17 21:23:32 -05:00
|
|
|
aria-label={ariaLabel}
|
2019-11-17 20:51:44 -05:00
|
|
|
aria-hidden={ariaHidden ? 'true' : undefined}
|
2019-11-23 11:25:36 -08:00
|
|
|
tabindex={ariaHidden ? '-1' : '0'}
|
2019-02-23 12:32:00 -08:00
|
|
|
class={computedClass}
|
|
|
|
{disabled}
|
|
|
|
ref:node
|
|
|
|
>
|
2019-03-02 19:02:06 -08:00
|
|
|
<SvgIcon className="icon-button-svg {svgClassName || ''}" ref:svg {href} />
|
2019-02-23 12:32:00 -08:00
|
|
|
</button>
|
2018-01-28 12:51:48 -08:00
|
|
|
<style>
|
2018-03-16 08:42:10 -07:00
|
|
|
.icon-button {
|
2018-01-28 12:51:48 -08:00
|
|
|
padding: 6px 10px;
|
|
|
|
background: none;
|
|
|
|
border: none;
|
2018-04-04 21:45:19 -07:00
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
2018-01-28 12:51:48 -08:00
|
|
|
}
|
|
|
|
|
2019-03-02 19:02:06 -08:00
|
|
|
:global(.icon-button-svg) {
|
2018-01-28 12:51:48 -08:00
|
|
|
width: 24px;
|
|
|
|
height: 24px;
|
|
|
|
fill: var(--action-button-fill-color);
|
2018-03-22 20:09:20 -07:00
|
|
|
pointer-events: none; /* hack for Edge */
|
2018-01-28 12:51:48 -08:00
|
|
|
}
|
|
|
|
|
2019-03-02 19:02:06 -08:00
|
|
|
:global(.icon-button.big-icon .icon-button-svg) {
|
2018-01-28 12:51:48 -08:00
|
|
|
width: 32px;
|
|
|
|
height: 32px;
|
|
|
|
}
|
|
|
|
|
2018-04-04 21:45:19 -07:00
|
|
|
/*
|
|
|
|
* regular styles
|
|
|
|
*/
|
|
|
|
|
2019-03-02 19:02:06 -08:00
|
|
|
:global(.icon-button:hover .icon-button-svg) {
|
2018-01-28 12:51:48 -08:00
|
|
|
fill: var(--action-button-fill-color-hover);
|
|
|
|
}
|
|
|
|
|
2019-03-02 19:02:06 -08:00
|
|
|
:global(.icon-button.not-pressable:active .icon-button-svg,
|
|
|
|
.icon-button.same-pressed:active .icon-button-svg) {
|
2018-01-28 12:51:48 -08:00
|
|
|
fill: var(--action-button-fill-color-active);
|
|
|
|
}
|
|
|
|
|
2019-03-02 19:02:06 -08:00
|
|
|
:global(.icon-button.pressed.not-same-pressed .icon-button-svg) {
|
2018-03-21 09:38:20 -07:00
|
|
|
fill: var(--action-button-fill-color-pressed);
|
2018-01-28 12:51:48 -08:00
|
|
|
}
|
|
|
|
|
2019-03-02 19:02:06 -08:00
|
|
|
:global(.icon-button.pressed.not-same-pressed:hover .icon-button-svg) {
|
2018-01-28 12:51:48 -08:00
|
|
|
fill: var(--action-button-fill-color-pressed-hover);
|
|
|
|
}
|
|
|
|
|
2019-03-02 19:02:06 -08:00
|
|
|
:global(.icon-button.pressed.not-same-pressed:active .icon-button-svg) {
|
2018-01-28 12:51:48 -08:00
|
|
|
fill: var(--action-button-fill-color-pressed-active);
|
|
|
|
}
|
2018-04-04 21:45:19 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* muted
|
|
|
|
*/
|
|
|
|
|
2019-03-02 19:02:06 -08:00
|
|
|
:global(.icon-button.muted-style .icon-button-svg) {
|
2018-04-04 21:45:19 -07:00
|
|
|
fill: var(--action-button-deemphasized-fill-color);
|
|
|
|
}
|
|
|
|
|
2019-03-02 19:02:06 -08:00
|
|
|
:global(.icon-button.muted-style:hover .icon-button-svg) {
|
2018-04-04 21:45:19 -07:00
|
|
|
fill: var(--action-button-deemphasized-fill-color-hover);
|
|
|
|
}
|
|
|
|
|
2019-03-02 19:02:06 -08:00
|
|
|
:global(.icon-button.muted-style.not-pressable:active .icon-button-svg,
|
|
|
|
.icon-button.muted-style.same-pressed:active .icon-button-svg) {
|
2018-04-04 21:45:19 -07:00
|
|
|
fill: var(--action-button-deemphasized-fill-color-active);
|
|
|
|
}
|
|
|
|
|
2019-03-02 19:02:06 -08:00
|
|
|
:global(.icon-button.muted-style.pressed.not-same-pressed .icon-button-svg) {
|
2018-04-04 21:45:19 -07:00
|
|
|
fill: var(--action-button-deemphasized-fill-color-pressed);
|
|
|
|
}
|
|
|
|
|
2019-03-02 19:02:06 -08:00
|
|
|
:global(.icon-button.muted-style.pressed.not-same-pressed:hover .icon-button-svg) {
|
2018-04-04 21:45:19 -07:00
|
|
|
fill: var(--action-button-deemphasized-fill-color-pressed-hover);
|
|
|
|
}
|
|
|
|
|
2019-03-02 19:02:06 -08:00
|
|
|
:global(.icon-button.muted-style.pressed.not-same-pressed:active .icon-button-svg) {
|
2018-04-04 21:45:19 -07:00
|
|
|
fill: var(--action-button-deemphasized-fill-color-pressed-active);
|
|
|
|
}
|
|
|
|
|
2018-02-24 14:49:28 -08:00
|
|
|
</style>
|
|
|
|
<script>
|
2018-03-14 18:52:33 -07:00
|
|
|
import { classname } from '../_utils/classname'
|
2018-03-22 20:23:00 -07:00
|
|
|
import { store } from '../_store/store'
|
2019-03-02 19:02:06 -08:00
|
|
|
import SvgIcon from './SvgIcon.html'
|
2018-03-14 18:52:33 -07:00
|
|
|
|
2018-02-24 14:49:28 -08:00
|
|
|
export default {
|
2019-02-23 12:32:00 -08:00
|
|
|
oncreate () {
|
2019-11-23 11:25:36 -08:00
|
|
|
const { clickListener } = this.get()
|
2019-02-23 12:32:00 -08:00
|
|
|
if (clickListener) {
|
|
|
|
this.onClick = this.onClick.bind(this)
|
|
|
|
this.refs.node.addEventListener('click', this.onClick)
|
|
|
|
}
|
2019-11-09 17:25:26 -05:00
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
|
|
const { pressable, pressedLabel, label } = this.get()
|
|
|
|
if (pressable && ((!pressedLabel || !label) || pressedLabel === label)) {
|
|
|
|
throw new Error('pressable buttons should have a label and a pressedLabel different from each other')
|
|
|
|
}
|
|
|
|
}
|
2019-02-23 12:32:00 -08:00
|
|
|
},
|
|
|
|
ondestroy () {
|
2019-08-03 13:49:37 -07:00
|
|
|
const { clickListener } = this.get()
|
2019-02-23 12:32:00 -08:00
|
|
|
if (clickListener) {
|
|
|
|
this.refs.node.removeEventListener('click', this.onClick)
|
|
|
|
}
|
|
|
|
},
|
2018-04-29 22:13:41 -07:00
|
|
|
data: () => ({
|
|
|
|
big: false,
|
|
|
|
muted: false,
|
|
|
|
disabled: false,
|
2019-08-19 19:08:59 -07:00
|
|
|
svgClassName: undefined,
|
2019-11-23 11:25:36 -08:00
|
|
|
elementId: '',
|
2018-04-29 22:13:41 -07:00
|
|
|
pressable: false,
|
|
|
|
pressed: false,
|
2019-11-09 17:25:26 -05:00
|
|
|
pressedLabel: undefined,
|
2019-08-19 19:08:59 -07:00
|
|
|
className: undefined,
|
2019-02-09 19:05:59 -08:00
|
|
|
sameColorWhenPressed: false,
|
2019-02-23 12:32:00 -08:00
|
|
|
ariaHidden: false,
|
2019-11-23 11:25:36 -08:00
|
|
|
clickListener: true
|
2018-04-29 22:13:41 -07:00
|
|
|
}),
|
2018-03-22 20:23:00 -07:00
|
|
|
store: () => store,
|
2018-02-24 14:49:28 -08:00
|
|
|
computed: {
|
2019-11-17 21:23:32 -05:00
|
|
|
computedClass: ({ pressable, pressed, big, muted, sameColorWhenPressed, className }) => (classname(
|
|
|
|
'icon-button',
|
|
|
|
!pressable && 'not-pressable',
|
|
|
|
pressed && 'pressed',
|
|
|
|
big && 'big-icon',
|
|
|
|
muted && 'muted-style',
|
|
|
|
sameColorWhenPressed ? 'same-pressed' : 'not-same-pressed',
|
|
|
|
className
|
|
|
|
)),
|
2019-11-23 11:25:36 -08:00
|
|
|
ariaLabel: ({ pressable, pressed, label, pressedLabel }) => ((pressable && pressed) ? pressedLabel : label)
|
2018-04-21 08:32:40 -07:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
animate (animation) {
|
2019-03-02 19:02:06 -08:00
|
|
|
this.refs.svg.animate(animation)
|
2019-02-23 12:32:00 -08:00
|
|
|
},
|
|
|
|
onClick (e) {
|
|
|
|
this.fire('click', e)
|
2018-04-21 08:32:40 -07:00
|
|
|
}
|
2019-03-02 19:02:06 -08:00
|
|
|
},
|
|
|
|
components: {
|
|
|
|
SvgIcon
|
2018-02-24 14:49:28 -08:00
|
|
|
}
|
|
|
|
}
|
2018-12-04 22:31:46 -08:00
|
|
|
</script>
|