UPD: Animate drag

This commit is contained in:
Robert Kossessa
2024-02-07 02:13:16 +01:00
parent dd472742dd
commit 364b4578cb
6 changed files with 118 additions and 28 deletions

View File

@@ -3,7 +3,7 @@
class="flex-1 flex flex-col items-center rounded-lg p-2 gap-2 font-heading transition-all border"
:class="{'text-black bg-zinc-300 hover:bg-zinc-200 border-zinc-100': selected,
'hover:bg-zinc-800 text-muted-foreground border-transparent' : !selected}"
@click="$emit('select'); $refs.title.scramble()">
@click="$emit('select'); $refs.title?.scramble()">
<slot v-if="$slots['replace']" name="replace" />
<template v-else>
<img

View File

@@ -6,8 +6,8 @@
v-model="configPage"
:options="configPages"
class="p-2 border solid border-b">
<template v-for="(page, key) in configPages" #[key]>
{{ $t(page.titleKey) }}
<template v-for="(page, key) in configPages" #[key] :key="key">
<ScrambleText ref="title" :text="$t(page.titleKey)" />
</template>
</TabSelect>
<div class="grow overflow-y-auto">

View File

@@ -41,7 +41,7 @@
<script setup>
import { AudioLines, AudioWaveform, GaugeCircle } from 'lucide-vue-next'
import ConfigSection from '@/components/common/ConfigSection.vue'
import Color from 'color'
import { Separator } from '@/components/ui/separator'
import { ref } from 'vue'
import TabSelect from '@/components/common/TabSelect.vue'
import FdIcon from '@/assets/icons/iconFineDetents.svg'

View File

@@ -48,6 +48,7 @@ import CdIcon from '@/assets/icons/iconCoarseDetents.svg'
import VfIcon from '@/assets/icons/iconViscousRotation.svg'
import RcIcon from '@/assets/icons/iconReturnToCenter.svg'
import SteppedSlider from '@/components/common/SteppedSlider.vue'
import { Separator } from '@/components/ui/separator'
const feedbackType = ref('fineDetents') // TODO: replace with actual value

View File

@@ -0,0 +1,76 @@
<script setup lang="ts">
import draggable from 'vuedraggable'
import { ref } from 'vue'
const message = [
'vue.draggable',
'draggable',
'component',
'for',
'vue.js 2.0',
'based',
'on',
'Sortablejs',
]
const list = ref(
message.map((name, index) => {
return { name, order: index + 1 }
}),
)
const dragOptions = ref({
animation: 200,
group: 'description',
disabled: false,
ghostClass: 'ghost',
})
const drag = ref(false)
const sort = () => {
console.log('here')
list.value = list.value.sort((a, b) => a.order - b.order)
}
</script>
<template>
<div class="row">
<div class="col-2 flex">
<button class="btn btn-secondary button" @click="sort">
To original order
</button>
</div>
<div class="col-6 flex-col">
<h3>Transition</h3>
<transition-group>
<draggable
key="dragggable"
item-key="name"
:list="list"
v-bind="dragOptions"
@start="drag = true"
@end="drag = false"
>
<template #item="{ element }">
<li :key="element.name">
{{ element.name }}
</li>
</template>
</draggable>
</transition-group>
</div>
</div>
</template>
<style scoped>
.button {
margin-top: 35px;
}
.ghost {
opacity: 0.5;
background: #c8ebfb;
}
</style>

View File

@@ -50,30 +50,32 @@
}})</span>
</CollapsibleTrigger>
<CollapsibleContent>
<draggable
:list="category.profiles"
group="profiles"
item-key="name"
:animation="150"
direction="vertical"
@start="drag = true"
@end="drag = false"
@change="(event)=>onProfileDrop(event, categoryIndex)">
<template v-if="category.profiles.length === 0" #header>
<div class="flex h-12 justify-center items-center hideable-header">
<MoreHorizontal class="w-4 text-zinc-600" />
</div>
</template>
<template #item="{ element }">
<ProfileButton
:key="element.id"
:profile="element"
:selected="store.selectedProfile?.id === element.id"
@select="store.selectProfile(element.id); showProfileConfig=true"
@duplicate="store.duplicateProfile(element.id)"
@delete="store.removeProfile(element.id)" />
</template>
</draggable>
<TransitionGroup>
<draggable
key="draggable"
item-key="id"
:list="category.profiles"
v-bind="dragOptions"
@start="drag = true"
@end="drag = false"
@change="(event)=>onProfileDrop(event, categoryIndex)">
<template v-if="category.profiles.length === 0" #header>
<div class="flex h-12 justify-center items-center hideable-header">
<MoreHorizontal class="w-4 text-zinc-600" />
</div>
</template>
<template #item="{ element }">
<div :key="element.name">
<ProfileButton
:profile="element"
:selected="store.selectedProfile?.id === element.id"
@select="store.selectProfile(element.id); showProfileConfig=true"
@duplicate="store.duplicateProfile(element.id)"
@delete="store.removeProfile(element.id)" />
</div>
</template>
</draggable>
</TransitionGroup>
</CollapsibleContent>
</Collapsible>
</div>
@@ -104,6 +106,13 @@ defineProps({
},
})
const dragOptions = ref({
group: 'profiles',
ghostClass: 'ghost',
animation: 150,
direction: 'vertical',
})
const maxProfiles = 32
const store = useStore()
@@ -198,6 +207,10 @@ const onProfileDrop = (event, categoryIndex) => {
opacity: 0;
}
.sortable-drag {
opacity: 0;
}
.hideable-header:not(:only-child) {
display: none;
}