logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git

contrast_ratio.vue (2511B)


  1. <template>
  2. <span
  3. v-if="contrast"
  4. class="contrast-ratio"
  5. >
  6. <span
  7. :title="hint"
  8. class="rating"
  9. >
  10. <span v-if="contrast.aaa">
  11. <FAIcon icon="thumbs-up" />
  12. </span>
  13. <span v-if="!contrast.aaa && contrast.aa">
  14. <FAIcon icon="adjust" />
  15. </span>
  16. <span v-if="!contrast.aaa && !contrast.aa">
  17. <FAIcon icon="exclamation-triangle" />
  18. </span>
  19. </span>
  20. <span
  21. v-if="contrast && large"
  22. class="rating"
  23. :title="hint_18pt"
  24. >
  25. <span v-if="contrast.laaa">
  26. <FAIcon icon="thumbs-up" />
  27. </span>
  28. <span v-if="!contrast.laaa && contrast.laa">
  29. <FAIcon icon="adjust" />
  30. </span>
  31. <span v-if="!contrast.laaa && !contrast.laa">
  32. <FAIcon icon="exclamation-triangle" />
  33. </span>
  34. </span>
  35. </span>
  36. </template>
  37. <script>
  38. import { library } from '@fortawesome/fontawesome-svg-core'
  39. import {
  40. faAdjust,
  41. faExclamationTriangle,
  42. faThumbsUp
  43. } from '@fortawesome/free-solid-svg-icons'
  44. library.add(
  45. faAdjust,
  46. faExclamationTriangle,
  47. faThumbsUp
  48. )
  49. export default {
  50. props: {
  51. large: {
  52. required: false,
  53. type: Boolean,
  54. default: false
  55. },
  56. // TODO: Make theme switcher compute theme initially so that contrast
  57. // component won't be called without contrast data
  58. contrast: {
  59. required: false,
  60. type: Object,
  61. default: () => ({})
  62. }
  63. },
  64. computed: {
  65. hint () {
  66. const levelVal = this.contrast.aaa ? 'aaa' : (this.contrast.aa ? 'aa' : 'bad')
  67. const level = this.$t(`settings.style.common.contrast.level.${levelVal}`)
  68. const context = this.$t('settings.style.common.contrast.context.text')
  69. const ratio = this.contrast.text
  70. return this.$t('settings.style.common.contrast.hint', { level, context, ratio })
  71. },
  72. hint_18pt () {
  73. const levelVal = this.contrast.laaa ? 'aaa' : (this.contrast.laa ? 'aa' : 'bad')
  74. const level = this.$t(`settings.style.common.contrast.level.${levelVal}`)
  75. const context = this.$t('settings.style.common.contrast.context.18pt')
  76. const ratio = this.contrast.text
  77. return this.$t('settings.style.common.contrast.hint', { level, context, ratio })
  78. }
  79. }
  80. }
  81. </script>
  82. <style lang="scss">
  83. .contrast-ratio {
  84. display: flex;
  85. justify-content: flex-end;
  86. margin-top: -4px;
  87. margin-bottom: 5px;
  88. .label {
  89. margin-right: 1em;
  90. }
  91. .rating {
  92. display: inline-block;
  93. text-align: center;
  94. margin-left: 0.5em;
  95. }
  96. }
  97. </style>