logo

pleroma-fe

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

palette_editor.vue (3959B)


  1. <template>
  2. <div
  3. class="PaletteEditor"
  4. :class="{ '-compact': compact, '-apply': apply }"
  5. >
  6. <ColorInput
  7. v-for="key in paletteKeys"
  8. :key="key"
  9. :name="key"
  10. :model-value="props.modelValue[key]"
  11. :fallback="fallback(key)"
  12. :label="$t('settings.style.themes3.palette.' + key)"
  13. @update:modelValue="value => updatePalette(key, value)"
  14. />
  15. <button
  16. class="btn button-default palette-import-button"
  17. @click="importPalette"
  18. >
  19. <FAIcon icon="file-import" />
  20. {{ $t('settings.style.themes3.palette.import') }}
  21. </button>
  22. <button
  23. class="btn button-default palette-export-button"
  24. @click="exportPalette"
  25. >
  26. <FAIcon icon="file-export" />
  27. {{ $t('settings.style.themes3.palette.export') }}
  28. </button>
  29. <button
  30. v-if="apply"
  31. class="btn button-default palette-apply-button"
  32. :disabled="disabled"
  33. :class="{ disabled }"
  34. @click="applyPalette"
  35. >
  36. {{ $t('settings.style.themes3.palette.apply') }}
  37. </button>
  38. </div>
  39. </template>
  40. <script setup>
  41. import ColorInput from 'src/components/color_input/color_input.vue'
  42. import {
  43. newImporter,
  44. newExporter
  45. } from 'src/services/export_import/export_import.js'
  46. import { library } from '@fortawesome/fontawesome-svg-core'
  47. import {
  48. faFileImport,
  49. faFileExport
  50. } from '@fortawesome/free-solid-svg-icons'
  51. library.add(
  52. faFileImport,
  53. faFileExport
  54. )
  55. const paletteKeys = [
  56. 'bg',
  57. 'fg',
  58. 'text',
  59. 'link',
  60. 'accent',
  61. 'cRed',
  62. 'cBlue',
  63. 'cGreen',
  64. 'cOrange',
  65. 'wallpaper'
  66. ]
  67. const props = defineProps(['modelValue', 'compact', 'apply', 'disabled'])
  68. const emit = defineEmits(['update:modelValue', 'applyPalette'])
  69. const getExportedObject = () => paletteKeys.reduce((acc, key) => {
  70. const value = props.modelValue[key]
  71. if (value == null) {
  72. return acc
  73. } else {
  74. return { ...acc, [key]: props.modelValue[key] }
  75. }
  76. }, {})
  77. const paletteExporter = newExporter({
  78. filename: 'pleroma_palette',
  79. extension: 'json',
  80. getExportedObject
  81. })
  82. const paletteImporter = newImporter({
  83. accept: '.json',
  84. onImport (parsed, filename) {
  85. emit('update:modelValue', parsed)
  86. }
  87. })
  88. const exportPalette = () => {
  89. paletteExporter.exportData()
  90. }
  91. const importPalette = () => {
  92. paletteImporter.importData()
  93. }
  94. const applyPalette = (data) => {
  95. emit('applyPalette', getExportedObject())
  96. }
  97. const fallback = (key) => {
  98. if (key === 'accent') {
  99. return props.modelValue.link
  100. }
  101. if (key === 'link') {
  102. return props.modelValue.accent
  103. }
  104. if (key.startsWith('extra')) {
  105. return '#FF00FF'
  106. }
  107. if (key.startsWith('wallpaper')) {
  108. return '#008080'
  109. }
  110. }
  111. const updatePalette = (paletteKey, value) => {
  112. emit('update:modelValue', {
  113. ...props.modelValue,
  114. [paletteKey]: value
  115. })
  116. }
  117. </script>
  118. <style lang="scss">
  119. .PaletteEditor {
  120. display: grid;
  121. justify-content: space-around;
  122. grid-template-columns: repeat(4, 1fr);
  123. grid-template-rows: repeat(5, 1fr) auto;
  124. grid-gap: 0.5em;
  125. align-items: baseline;
  126. .palette-import-button {
  127. grid-column: 1 / span 2;
  128. }
  129. .palette-export-button {
  130. grid-column: 3 / span 2;
  131. }
  132. .palette-apply-button {
  133. grid-column: 1 / span 2;
  134. }
  135. .color-input.style-control {
  136. margin: 0;
  137. }
  138. &.-compact {
  139. grid-template-columns: repeat(2, 1fr);
  140. grid-template-rows: repeat(5, 1fr) auto;
  141. .palette-import-button {
  142. grid-column: 1;
  143. }
  144. .palette-export-button {
  145. grid-column: 2;
  146. }
  147. &.-apply {
  148. grid-template-rows: repeat(5, 1fr) auto auto;
  149. .palette-apply-button {
  150. grid-column: 1 / span 2;
  151. }
  152. }
  153. .-mobile & {
  154. grid-template-columns: 1fr;
  155. grid-template-rows: repeat(10, 1fr) auto;
  156. .palette-import-button {
  157. grid-column: 1;
  158. }
  159. .palette-export-button {
  160. grid-column: 1;
  161. }
  162. &.-apply {
  163. .palette-apply-button {
  164. grid-column: 1;
  165. }
  166. }
  167. }
  168. }
  169. }
  170. </style>