All files / src/components/modal ViewerActionRail.vue

100% Statements 14/14
100% Branches 0/0
100% Functions 7/7
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143                                                                                                                  9x   9x   9x       9x       9x           9x 153x     17x                                                                                                                       1x      
<template>
  <ActionRail
    :actions="viewActions"
    :menu-props="menuProps"
    :menu-on="menuOn"
    :menu-activator-props="menuActivatorProps"
  >
    <template #visible="{ action }">
      <Component
        v-bind="action.props"
        :is="action.component"
        :view="view"
        variant="button"
        @update:modal="onActionModal"
      />
    </template>
    <template #hidden="{ action }">
      <Component
        v-bind="action.props"
        :is="action.component"
        :view="view"
        variant="menu-item"
        @update:modal="onActionModal"
      />
    </template>
  </ActionRail>
</template>
 
<script setup lang="ts">
import { computed } from 'vue';
import { ScanView } from '@3cr/types-ts';
import FlipVerticalAction from '@/components/modal/actions/FlipVerticalAction.vue';
import FlipHorizontalAction from '@/components/modal/actions/FlipHorizontalAction.vue';
import FullscreenAction from '@/components/modal/actions/FullscreenAction.vue';
import PanAction from '@/components/modal/actions/PanAction.vue';
import ResetViewAction from '@/components/modal/actions/ResetViewAction.vue';
import Rotate2dAction from '@/components/modal/actions/Rotate2dAction.vue';
import Slice3dAction from '@/components/modal/actions/Slice3dAction.vue';
import ZoomAction from '@/components/modal/actions/ZoomAction.vue';
import LengthAction from '@/components/modal/actions/LengthAction.vue';
 
interface Props {
  view: ScanView;
  target?: EventTarget;
}
 
type Emits = {
  modal: [boolean];
};
 
type ActionItem = {
  component: any;
  width: number;
  condition: boolean;
  props: Record<string, any>;
};
 
const props = defineProps<Props>();
 
const emit = defineEmits<Emits>();
 
const menuProps = computed(() => ({
  closeOnContentClick: false,
}));
 
const menuOn = computed(() => ({
  'update:modelValue': onActionModal,
}));
 
const menuActivatorProps = computed(() => ({
  icon: 'more_vert',
  variant: 'text',
  color: 'white',
}));
 
const viewActions = computed(() => {
  return actions.value.filter((action) => action.condition);
});
 
const actions = computed<ActionItem[]>(() => [
  {
    component: FullscreenAction,
    width: 52,
    condition: true,
    props: {},
  },
  {
    component: ResetViewAction,
    width: 52,
    condition: true,
    props: {},
  },
  {
    component: PanAction,
    width: 52,
    condition: true,
    props: {},
  },
  {
    component: ZoomAction,
    width: 52,
    condition: true,
    props: {
      target: props.target,
    },
  },
  {
    component: Slice3dAction,
    width: 52,
    condition: props.view === ScanView.Volume,
    props: {},
  },
  {
    component: LengthAction,
    width: 52,
    condition: props.view !== ScanView.Volume,
    props: {},
  },
  {
    component: Rotate2dAction,
    width: 52,
    condition: props.view !== ScanView.Volume,
    props: {},
  },
  {
    component: FlipHorizontalAction,
    width: 52,
    condition: props.view !== ScanView.Volume,
    props: {},
  },
  {
    component: FlipVerticalAction,
    width: 52,
    condition: props.view !== ScanView.Volume,
    props: {},
  },
]);
 
async function onActionModal(value: boolean): Promise<void> {
  emit('modal', value);
}
</script>