-
Notifications
You must be signed in to change notification settings - Fork 633
/
ActivityButtonsGroup.vue
148 lines (132 loc) · 3.48 KB
/
ActivityButtonsGroup.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<template>
<div>
<h2 class="title">
{{ $tr('activities') }}
</h2>
<span
v-for="(key, activity) in learningActivitiesList"
:key="key"
alignment="center"
>
<KButton
appearance="flat-button"
:appearanceOverrides="isKeyActive(key)
? { ...activityStyles, ...activityActiveStyles }
: activityStyles"
:disabled="availableActivities &&
!availableActivities[key] &&
!isKeyActive(key)"
@click="$emit('input', key)"
>
<KIcon :icon="activityIcon(activity)" class="activity-icon" />
<p class="activity-button-text">
{{ coreString(camelCase(activity)) }}
</p>
</KButton>
</span>
</div>
</template>
<script>
import camelCase from 'lodash/camelCase';
import invert from 'lodash/invert';
import { LearningActivities } from 'kolibri.coreVue.vuex.constants';
import commonCoreStrings from 'kolibri.coreVue.mixins.commonCoreStrings';
import plugin_data from 'plugin_data';
const activitiesLookup = invert(LearningActivities);
const learningActivitiesShown = {};
if (process.env.NODE_ENV !== 'production') {
// TODO rtibbles: remove this condition
Object.assign(learningActivitiesShown, LearningActivities);
} else {
plugin_data.learningActivities.map(id => {
const key = activitiesLookup[id];
learningActivitiesShown[key] = id;
});
}
export default {
name: 'ActivityButtonsGroup',
mixins: [commonCoreStrings],
props: {
availableLabels: {
type: Object,
required: false,
default: null,
},
activeButtons: {
type: Object,
required: false,
default: null,
},
},
computed: {
learningActivitiesList() {
return learningActivitiesShown;
},
activityStyles() {
return {
color: this.$themeTokens.text,
width: '50%',
height: '100px',
border: '2px solid transparent',
textTransform: 'capitalize',
fontWeight: 'normal',
transition: 'none',
':hover': this.activityActiveStyles,
};
},
activityActiveStyles() {
return {
backgroundColor: this.$themeBrand.primary.v_50,
border: '2px',
borderColor: this.$themeTokens.primary,
borderStyle: 'solid',
borderRadius: '4px',
};
},
availableActivities() {
if (this.availableLabels) {
const activities = {};
for (let key of this.availableLabels.learning_activities) {
activities[key] = true;
}
return activities;
}
return null;
},
activeKeys() {
return Object.keys(this.activeButtons);
},
},
methods: {
camelCase(id) {
return camelCase(id);
},
activityIcon(activity) {
if (activity == 'EXPLORE') {
return 'interactShaded';
} else {
return `${camelCase(activity) + 'Shaded'}`;
}
},
isKeyActive(key) {
return key !== null && !!this.activeKeys.filter(k => k.includes(key)).length;
},
},
$trs: {
activities: {
message: 'Activities',
context: 'Section header label in the Library page sidebar.',
},
},
};
</script>
<style lang="scss" scoped>
.activity-icon {
width: 34px;
height: 34px;
}
.activity-button-text {
margin: auto;
margin-top: -12px;
}
</style>