/
cv-header-global-action.vue
84 lines (82 loc) · 1.93 KB
/
cv-header-global-action.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<template>
<cv-icon-button
v-on="$listeners"
:class="[
`cv-header-global-action`,
`${carbonPrefix}--header__action`,
{ [`${carbonPrefix}--header__action--active`]: dataActive },
]"
type="button"
aria-haspopup="true"
:aria-controls="ariaControls"
:aria-expanded="active ? 'true' : 'false'"
@click="gaToggle"
@focusout="gaFocusout"
:id="uid"
:label="label"
:tipAlignment="tipAlignment"
:tipPosition="tipPosition"
>
<template slot="icon">
<slot />
</template>
</cv-icon-button>
</template>
<script>
import { uidMixin, carbonPrefixMixin } from '../../mixins';
import { CvIconButton } from '../cv-button';
export default {
components: { CvIconButton },
name: 'CvHeaderGlobalAction',
mixins: [uidMixin, carbonPrefixMixin],
props: {
active: Boolean,
ariaControls: String,
label: { type: String, default: undefined },
tipPosition: {
type: String,
default: 'bottom',
validator: val => ['top', 'left', 'bottom', 'right'.includes(val)],
},
tipAlignment: { type: String, default: 'center', validator: val => ['start', 'center', 'end'].includes(val) },
},
mounted() {
this.$parent.$emit('cv:panel-control-mounted', this);
},
beforeDestroy() {
this.$parent.$emit('cv:panel-control-beforeDestroy', this);
},
data() {
return {
dataActive: this.active,
};
},
watch: {
expanded() {
if (this.active !== this.dataActive) {
this.gaToggle();
}
},
},
computed: {
panelExpanded: {
get() {
return this.dataActive;
},
set(val) {
// do not emit 'cv:panel-control-toggle'
this.dataActive = val;
},
},
},
methods: {
gaToggle() {
this.$el.focus();
this.$parent.$emit('cv:panel-control-toggle', this);
},
gaFocusout(ev) {
this.$parent.$emit('cv:panel-control-focusout', this, ev);
},
},
};
</script>