logo

pleroma-fe

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

select_motion.vue (2946B)


  1. <template>
  2. <div
  3. class="SelectMotion btn-group"
  4. >
  5. <button
  6. class="btn button-default"
  7. :disabled="disabled"
  8. @click="add"
  9. >
  10. <FAIcon
  11. fixed-width
  12. icon="plus"
  13. />
  14. </button>
  15. <button
  16. class="btn button-default"
  17. :disabled="disabled || !moveUpValid"
  18. :class="{ disabled: disabled || !moveUpValid }"
  19. @click="moveUp"
  20. >
  21. <FAIcon
  22. fixed-width
  23. icon="chevron-up"
  24. />
  25. </button>
  26. <button
  27. class="btn button-default"
  28. :disabled="disabled || !moveDnValid"
  29. :class="{ disabled: disabled || !moveDnValid }"
  30. @click="moveDn"
  31. >
  32. <FAIcon
  33. fixed-width
  34. icon="chevron-down"
  35. />
  36. </button>
  37. <button
  38. class="btn button-default"
  39. :disabled="disabled || !present"
  40. :class="{ disabled: disabled || !present }"
  41. @click="del"
  42. >
  43. <FAIcon
  44. fixed-width
  45. icon="times"
  46. />
  47. </button>
  48. </div>
  49. </template>
  50. <script setup>
  51. import { computed, defineEmits, defineProps, nextTick } from 'vue'
  52. const props = defineProps({
  53. modelValue: {
  54. type: Array,
  55. required: true
  56. },
  57. selectedId: {
  58. type: Number,
  59. required: true
  60. },
  61. disabled: {
  62. type: Boolean,
  63. default: false
  64. },
  65. getAddValue: {
  66. type: Function,
  67. required: true
  68. }
  69. })
  70. const emit = defineEmits(['update:modelValue', 'update:selectedId'])
  71. const moveUpValid = computed(() => {
  72. return props.selectedId > 0
  73. })
  74. const present = computed(() => props.modelValue[props.selectedId] != null)
  75. const moveUp = async () => {
  76. const newModel = [...props.modelValue]
  77. const movable = newModel.splice(props.selectedId, 1)[0]
  78. newModel.splice(props.selectedId - 1, 0, movable)
  79. emit('update:modelValue', newModel)
  80. await nextTick()
  81. emit('update:selectedId', props.selectedId - 1)
  82. }
  83. const moveDnValid = computed(() => {
  84. return props.selectedId < props.modelValue.length - 1
  85. })
  86. const moveDn = async () => {
  87. const newModel = [...props.modelValue]
  88. const movable = newModel.splice(props.selectedId.value, 1)[0]
  89. newModel.splice(props.selectedId + 1, 0, movable)
  90. emit('update:modelValue', newModel)
  91. await nextTick()
  92. emit('update:selectedId', props.selectedId + 1)
  93. }
  94. const add = async () => {
  95. const newModel = [...props.modelValue, props.getAddValue()]
  96. emit('update:modelValue', newModel)
  97. await nextTick()
  98. emit('update:selectedId', Math.max(newModel.length - 1, 0))
  99. }
  100. const del = async () => {
  101. const newModel = [...props.modelValue]
  102. newModel.splice(props.selectedId, 1)
  103. emit('update:modelValue', newModel)
  104. await nextTick()
  105. emit('update:selectedId', newModel.length === 0 ? undefined : Math.max(props.selectedId - 1, 0))
  106. }
  107. </script>
  108. <style lang="scss">
  109. .SelectMotion {
  110. flex: 0 0 auto;
  111. display: grid;
  112. grid-auto-columns: 1fr;
  113. grid-auto-flow: column;
  114. margin-top: 0.25em;
  115. .button-default {
  116. margin: 0;
  117. padding: 0;
  118. }
  119. }
  120. </style>