|
| 1 | +<template> |
| 2 | + |
| 3 | + <!-- At the time of writing, the KLabeledIcon component does not set |
| 4 | + the color of the label properly (issue #1102). When this is fixed, setting |
| 5 | + color on the button component should no longer be needed. --> |
| 6 | + <button |
| 7 | + class="community-library-status-button" |
| 8 | + :title="tooltip" |
| 9 | + @click="$emit('click')" |
| 10 | + > |
| 11 | + <KLabeledIcon |
| 12 | + :icon="icon" |
| 13 | + iconAfter="dropdown" |
| 14 | + :color="labelColor" |
| 15 | + :label="text" |
| 16 | + /> |
| 17 | + </button> |
| 18 | + |
| 19 | +</template> |
| 20 | + |
| 21 | + |
| 22 | +<script> |
| 23 | +
|
| 24 | + import { themePalette } from 'kolibri-design-system/lib/styles/theme'; |
| 25 | + import { computed, defineComponent } from 'vue'; |
| 26 | + import { CommunityLibraryStatus } from 'shared/constants'; |
| 27 | +
|
| 28 | + export default defineComponent({ |
| 29 | + name: 'ChannelCommunityLibraryStatusButton', |
| 30 | + setup(props) { |
| 31 | + const theme = themePalette(); |
| 32 | +
|
| 33 | + const configChoices = { |
| 34 | + [CommunityLibraryStatus.PENDING]: { |
| 35 | + text: 'Submitted', |
| 36 | + tooltip: 'Submission awaiting review', |
| 37 | + color: theme.yellow.v_100, |
| 38 | + darkColor: theme.yellow.v_200, |
| 39 | + labelColor: theme.orange.v_600, |
| 40 | + icon: 'schedule', |
| 41 | + }, |
| 42 | + [CommunityLibraryStatus.APPROVED]: { |
| 43 | + text: 'Approved', |
| 44 | + tooltip: 'Live in Community Library', |
| 45 | + color: theme.green.v_100, |
| 46 | + darkColor: theme.green.v_200, |
| 47 | + labelColor: theme.green.v_600, |
| 48 | + icon: 'circleCheckmark', |
| 49 | + }, |
| 50 | + [CommunityLibraryStatus.REJECTED]: { |
| 51 | + text: 'Flagged', |
| 52 | + tooltip: 'Review flagged submission', |
| 53 | + color: theme.red.v_100, |
| 54 | + darkColor: theme.red.v_200, |
| 55 | + labelColor: theme.red.v_600, |
| 56 | + icon: 'error', |
| 57 | + }, |
| 58 | + }; |
| 59 | +
|
| 60 | + // NOTE: Having the whole config object as a computed property and |
| 61 | + // then accessing its elements breaks tests (possibly because of quirks |
| 62 | + // of how vue-jest and vue-template-compiler handle computed properties |
| 63 | + // defined using the composition API). |
| 64 | + // Therefore, we define the individual attributes as separate |
| 65 | + // computed properties as a workaround. |
| 66 | + const text = computed(() => configChoices[props.status].text); |
| 67 | + const tooltip = computed(() => configChoices[props.status].tooltip); |
| 68 | + const color = computed(() => configChoices[props.status].color); |
| 69 | + const darkColor = computed(() => configChoices[props.status].darkColor); |
| 70 | + const labelColor = computed(() => configChoices[props.status].labelColor); |
| 71 | + const icon = computed(() => configChoices[props.status].icon); |
| 72 | +
|
| 73 | + return { |
| 74 | + text, |
| 75 | + tooltip, |
| 76 | + color, |
| 77 | + darkColor, |
| 78 | + labelColor, |
| 79 | + icon, |
| 80 | + }; |
| 81 | + }, |
| 82 | + // NOTE: Values of props declared in the setup method using `declareProps` cannot |
| 83 | + // be checked in tests, so we declare them using the options API for better testability. |
| 84 | + props: { |
| 85 | + status: { |
| 86 | + type: String, |
| 87 | + required: true, |
| 88 | + validator: value => |
| 89 | + [ |
| 90 | + CommunityLibraryStatus.PENDING, |
| 91 | + CommunityLibraryStatus.APPROVED, |
| 92 | + CommunityLibraryStatus.REJECTED, |
| 93 | + ].includes(value), |
| 94 | + }, |
| 95 | + }, |
| 96 | + }); |
| 97 | +
|
| 98 | +</script> |
| 99 | + |
| 100 | + |
| 101 | +<style lang="scss" scoped> |
| 102 | +
|
| 103 | + @import '~kolibri-design-system/lib/styles/definitions'; |
| 104 | +
|
| 105 | + .community-library-status-button { |
| 106 | + @extend %md-standard-func; |
| 107 | +
|
| 108 | + width: 9em; |
| 109 | + padding: 4px; |
| 110 | + color: v-bind('labelColor'); |
| 111 | + background-color: v-bind('color'); |
| 112 | + border-radius: 16px; |
| 113 | + transition: background-color $core-time; |
| 114 | + } |
| 115 | +
|
| 116 | + .community-library-status-button:hover { |
| 117 | + background-color: v-bind('darkColor'); |
| 118 | + } |
| 119 | +
|
| 120 | +</style> |
0 commit comments