logo

pleroma-fe

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

contrast_ratio.vue (3077B)


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