akkoma-fe/src/components/contrast_ratio/contrast_ratio.vue

105 lines
2.5 KiB
Vue
Raw Normal View History

2018-10-09 21:07:28 +00:00
<template>
2019-07-05 07:17:44 +00:00
<span
v-if="contrast"
class="contrast-ratio"
>
<span
:title="hint"
class="rating"
>
<span v-if="contrast.aaa">
2020-10-20 18:03:46 +00:00
<FAIcon icon="thumbs-up" />
2019-07-05 07:17:44 +00:00
</span>
<span v-if="!contrast.aaa && contrast.aa">
2020-10-20 18:03:46 +00:00
<FAIcon icon="adjust" />
2019-07-05 07:17:44 +00:00
</span>
<span v-if="!contrast.aaa && !contrast.aa">
2020-10-20 18:03:46 +00:00
<FAIcon icon="exclamation-triangle" />
2019-07-05 07:17:44 +00:00
</span>
2018-11-13 13:30:01 +00:00
</span>
2019-07-05 07:17:44 +00:00
<span
v-if="contrast && large"
class="rating"
:title="hint_18pt"
>
<span v-if="contrast.laaa">
2020-10-20 18:03:46 +00:00
<FAIcon icon="thumbs-up" />
2019-07-05 07:17:44 +00:00
</span>
<span v-if="!contrast.laaa && contrast.laa">
2020-10-20 18:03:46 +00:00
<FAIcon icon="adjust" />
2019-07-05 07:17:44 +00:00
</span>
<span v-if="!contrast.laaa && !contrast.laa">
2020-10-20 18:03:46 +00:00
<FAIcon icon="exclamation-triangle" />
2019-07-05 07:17:44 +00:00
</span>
2018-10-09 21:07:28 +00:00
</span>
</span>
</template>
<script>
2020-10-20 18:03:46 +00:00
import { library } from '@fortawesome/fontawesome-svg-core'
import {
faAdjust,
faExclamationTriangle,
faThumbsUp
} from '@fortawesome/free-solid-svg-icons'
library.add(
faAdjust,
faExclamationTriangle,
faThumbsUp
)
2018-10-09 21:07:28 +00:00
export default {
props: {
large: {
2020-09-08 07:44:08 +00:00
required: false,
type: Boolean,
default: false
},
2020-01-19 22:37:45 +00:00
// TODO: Make theme switcher compute theme initially so that contrast
// component won't be called without contrast data
contrast: {
2020-01-19 22:37:45 +00:00
required: false,
2020-09-08 07:44:08 +00:00
type: Object,
default: () => ({})
}
},
2018-11-21 17:18:49 +00:00
computed: {
hint () {
const levelVal = this.contrast.aaa ? 'aaa' : (this.contrast.aa ? 'aa' : 'bad')
const level = this.$t(`settings.style.common.contrast.level.${levelVal}`)
const context = this.$t('settings.style.common.contrast.context.text')
const ratio = this.contrast.text
return this.$t('settings.style.common.contrast.hint', { level, context, ratio })
},
hint_18pt () {
const levelVal = this.contrast.laaa ? 'aaa' : (this.contrast.laa ? 'aa' : 'bad')
const level = this.$t(`settings.style.common.contrast.level.${levelVal}`)
const context = this.$t('settings.style.common.contrast.context.18pt')
const ratio = this.contrast.text
return this.$t('settings.style.common.contrast.hint', { level, context, ratio })
}
}
2018-10-09 21:07:28 +00:00
}
</script>
<style lang="scss">
.contrast-ratio {
display: flex;
2018-11-14 19:20:42 +00:00
justify-content: flex-end;
2018-10-09 21:07:28 +00:00
2018-11-21 19:01:34 +00:00
margin-top: -4px;
margin-bottom: 5px;
2018-10-09 21:07:28 +00:00
.label {
margin-right: 1em;
}
.rating {
display: inline-block;
text-align: center;
2020-10-20 18:03:46 +00:00
margin-left: 0.5em;
2018-10-09 21:07:28 +00:00
}
}
</style>