Skip to content

Commit

Permalink
Merge pull request #46 from LucasWerey/fix/19
Browse files Browse the repository at this point in the history
Fix/19
  • Loading branch information
LucasWerey authored Jan 20, 2024
2 parents 59bd950 + f7f476a commit cf53040
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lucaswerey/dslib-pfe",
"version": "0.0.65",
"version": "0.0.66",
"private": false,
"main": "./lib/index.umd.js",
"module": "./lib/index.mjs",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('RankingContainer', () => {
title: 'Test Title',
labels: [],
topRank: false,
draggable: false
isDraggable: false
}
})

Expand All @@ -23,7 +23,7 @@ describe('RankingContainer', () => {
title: 'Test Title',
labels: ['Label 1', 'Label 2'],
topRank: false,
draggable: false
isDraggable: false
}
})

Expand All @@ -38,7 +38,7 @@ describe('RankingContainer', () => {
title: 'Test Title',
labels: [],
topRank: true,
draggable: false
isDraggable: false
}
})

Expand All @@ -52,7 +52,7 @@ describe('RankingContainer', () => {
title: 'Test Title',
labels: [],
topRank: false,
draggable: true
isDraggable: true
}
})

Expand All @@ -78,7 +78,7 @@ describe('RankingContainer', () => {
'eazezaeza'
],
topRank: false,
draggable: true
isDraggable: true
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
>
<template #controls>
<ControlDescription>
<HstInput v-model="controls.title" title="Title" />
<HstText v-model="controls.title" title="Title" />
</ControlDescription>
<ControlDescription>
<HstSelect v-model="controls.labels" :options="labelOptions" title="Labels" multiple />
Expand All @@ -28,8 +28,28 @@
:labels="controls.labels"
:topRank="controls.topRank"
:draggable="controls.draggable"
:is-draggable="controls.draggable"
@dragstart="event => console.log('dragstart', event)"

Check failure on line 32 in src/components/Containment/RankingContainer/RankingContainer.story.vue

View workflow job for this annotation

GitHub Actions / build

Parameter 'event' implicitly has an 'any' type.
@dragover="event => console.log('dragover', event)"

Check failure on line 33 in src/components/Containment/RankingContainer/RankingContainer.story.vue

View workflow job for this annotation

GitHub Actions / build

Parameter 'event' implicitly has an 'any' type.
@drop="event => console.log('drop', event)"

Check failure on line 34 in src/components/Containment/RankingContainer/RankingContainer.story.vue

View workflow job for this annotation

GitHub Actions / build

Parameter 'event' implicitly has an 'any' type.
/>
</Variant>
<Variant title="MultipleContainers" auto-props-disabled>
<div class="space-y-4">
<RankingContainer
v-for="(container, index) in controls2.values()"
:key="index"
:title="container.title"
:labels="container.labels"
:topRank="container.topRank"
draggable="true"
isDraggable
@dragstart="event => handleDragStart(event, index)"

Check failure on line 47 in src/components/Containment/RankingContainer/RankingContainer.story.vue

View workflow job for this annotation

GitHub Actions / build

Parameter 'event' implicitly has an 'any' type.
@dragover="handleDragOver"
@drop="event => handleDrop(event, index)"

Check failure on line 49 in src/components/Containment/RankingContainer/RankingContainer.story.vue

View workflow job for this annotation

GitHub Actions / build

Parameter 'event' implicitly has an 'any' type.
/>
</div>
</Variant>
</Story>
</template>

Expand All @@ -48,5 +68,45 @@ const controls = reactive<Controls>({
draggable: false
})
const controls2 = ref([
{ title: 'Container 1', labels: ['Label 1'], topRank: false, draggable: true },
{ title: 'Container 2', labels: ['Label 2'], topRank: false, draggable: true },
{ title: 'Container 3', labels: ['Label 3'], topRank: false, draggable: true }
])
const labelOptions = ['this is for testing the scroll container']
let draggedItem: Ref<number | null> = ref(null)
const handleDragStart = async (event: any, index: number) => {
event.stopPropagation()
await new Promise(resolve => setTimeout(resolve, 0))
draggedItem.value = index
console.log(`Drag started from position: ${index}`)
}
const handleDragOver = (event: any) => {
event.preventDefault()
event.stopPropagation()
}
const handleDrop = (event: any, index: number) => {
event.stopPropagation()
if (draggedItem.value !== null) {
const controlsCopy = [...controls2.value]
const draggedContainer = controlsCopy[draggedItem.value]
controlsCopy.splice(draggedItem.value, 1)
controlsCopy.splice(index, 0, draggedContainer)
controlsCopy[0].topRank = index === 0
for (let i = 1; i < controlsCopy.length; i++) {
controlsCopy[i].topRank = false
}
controls2.value = controlsCopy
console.log(`Dropped at position: ${index}`)
console.log(
'New order of items:',
controls2.value.map((item, index) => `Position ${index}: ${item.title}`)
)
}
}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
class="flex h-full w-full shrink-0 flex-row items-center gap-3 rounded-[4px] border border-basic-grey bg-basic-white"
:class="topRankClassBorder"
data-test="container"
@dragstart="$emit('dragstart', $event)"
@dragover="$emit('dragover', $event)"
@drop="$emit('drop', $event)"
>
<div
class="flex h-full w-fit select-none items-center justify-center border-r border-basic-grey px-3 align-middle text-basic-grey"
Expand Down Expand Up @@ -51,7 +54,7 @@ const props = defineProps({
type: Boolean as PropType<boolean>,
default: false
},
draggable: {
isDraggable: {
type: Boolean as PropType<boolean>,
default: false
}
Expand All @@ -60,7 +63,7 @@ const props = defineProps({
const title = computed(() => props.title)
const labels = computed(() => props.labels)
const topRank = computed(() => props.topRank)
const draggable = computed(() => props.draggable)
const draggable = computed(() => props.isDraggable)
let isDragging = false
let startX: number, scrollLeft: number
Expand Down

0 comments on commit cf53040

Please sign in to comment.