-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from LucasWerey/feat/15
feat(dslib): add ranking container
- Loading branch information
Showing
11 changed files
with
306 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,46 @@ | ||
<script setup lang="ts"> | ||
import './assets/index.css' | ||
import CertifContainer from './components/Containment/CertifContainer' | ||
import DeleteModal from './components/Indicators/DeleteModal' | ||
const handleUpdate = (value: string) => { | ||
console.log(value) | ||
} | ||
import RankingContainer from './components/Containment/RankingContainer' | ||
</script> | ||
|
||
<template> | ||
<div class="h-[100vh] w-[100vw] bg-basic-lightgrey p-2"> | ||
<DeleteModal | ||
description="Lorem ipsum dolor sit amet consectetur. Quis aliquet eget id quis lectus pellentesque. Porttitor." | ||
title="Voulez-vous vraiment supprimer cet élément ?" | ||
labelFirstButton="Annuler" | ||
labelSecondButton="Oui, Supprimer" | ||
<div class="flex h-[100vh] w-[100vw] flex-col gap-5 bg-basic-lightgrey p-2"> | ||
<RankingContainer title="Mots clés" :labels="['Yo', 'Suuuu']" /> | ||
<RankingContainer | ||
title="Transports utilisés" | ||
:labels="[ | ||
'Yo', | ||
'Suuuu', | ||
'Yo', | ||
'Yo', | ||
'Yo', | ||
'Yo', | ||
'Yo', | ||
'Yo', | ||
'Yo', | ||
'Yo', | ||
'Yo', | ||
'Yo', | ||
'Yo', | ||
'Yo', | ||
'Yo', | ||
'Yo', | ||
'Yo', | ||
'Yo', | ||
'Yo', | ||
'Yo', | ||
'Yo', | ||
'Yo', | ||
'Yo', | ||
'Yo', | ||
'Yo', | ||
'Yo', | ||
'Yo', | ||
'Yo' | ||
]" | ||
top-rank | ||
draggable | ||
/> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
src/components/Containment/RankingContainer/RankingContainer.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { mount } from '@vue/test-utils' | ||
import { it, describe, expect } from 'vitest' | ||
import RankingContainer from '.' | ||
|
||
describe('RankingContainer', () => { | ||
it('renders the correct title', () => { | ||
const wrapper = mount(RankingContainer, { | ||
props: { | ||
title: 'Test Title', | ||
labels: [], | ||
topRank: false, | ||
draggable: false | ||
} | ||
}) | ||
|
||
const titleElement = wrapper.find('[data-test="title"]') | ||
expect(titleElement.text()).toBe('Test Title') | ||
}) | ||
|
||
it('renders the correct labels', () => { | ||
const wrapper = mount(RankingContainer, { | ||
props: { | ||
title: 'Test Title', | ||
labels: ['Label 1', 'Label 2'], | ||
topRank: false, | ||
draggable: false | ||
} | ||
}) | ||
|
||
const labelsElements = wrapper.findAll('[data-test="label"]') | ||
expect(labelsElements[0].text()).toBe('Label 1') | ||
expect(labelsElements[1].text()).toBe('Label 2') | ||
}) | ||
|
||
it('applies the top rank class when topRank is true', () => { | ||
const wrapper = mount(RankingContainer, { | ||
props: { | ||
title: 'Test Title', | ||
labels: [], | ||
topRank: true, | ||
draggable: false | ||
} | ||
}) | ||
|
||
const containerElement = wrapper.find('[data-test="container"]') | ||
expect(containerElement.classes()).toContain('border-primary-moonstone') | ||
}) | ||
|
||
it('applies the draggable class when draggable is true', () => { | ||
const wrapper = mount(RankingContainer, { | ||
props: { | ||
title: 'Test Title', | ||
labels: [], | ||
topRank: false, | ||
draggable: true | ||
} | ||
}) | ||
|
||
const draggableIconElement = wrapper.find('[data-test="draggableIcon"]') | ||
expect(draggableIconElement.classes()).toContain('cursor-move') | ||
}) | ||
it('handles mouse down, move, and up events', async () => { | ||
const wrapper = mount(RankingContainer, { | ||
props: { | ||
title: 'Test Title', | ||
labels: [ | ||
'eazez', | ||
'eazez', | ||
'eazeza', | ||
'eazezaeza', | ||
'zaezaezaezaezae', | ||
'eazezaezaezae', | ||
'ezaezaezaezae', | ||
'ezaezaezaezae', | ||
'eazezaezaezae', | ||
'ezaezaezae', | ||
'ezaezaezaea', | ||
'eazezaeza' | ||
], | ||
topRank: false, | ||
draggable: true | ||
} | ||
}) | ||
|
||
const scrollContainer = wrapper.find('[data-test="scrollContainer"]') | ||
|
||
await scrollContainer.trigger('mousedown', { | ||
clientX: 100, | ||
clientY: 100 | ||
}) | ||
|
||
await scrollContainer.trigger('mousemove', { | ||
clientX: 200, | ||
clientY: 200 | ||
}) | ||
await scrollContainer.trigger('mouseup') | ||
}) | ||
}) |
52 changes: 52 additions & 0 deletions
52
src/components/Containment/RankingContainer/RankingContainer.story.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<template> | ||
<Story | ||
title="Ranking Container" | ||
group="containment" | ||
:layout="{ | ||
type: 'grid', | ||
width: '80%' | ||
}" | ||
> | ||
<template #controls> | ||
<ControlDescription> | ||
<HstInput v-model="controls.title" title="Title" /> | ||
</ControlDescription> | ||
<ControlDescription> | ||
<HstSelect v-model="controls.labels" :options="labelOptions" title="Labels" multiple /> | ||
</ControlDescription> | ||
<ControlDescription> | ||
<HstCheckbox v-model="controls.topRank" title="Top Rank" /> | ||
</ControlDescription> | ||
<ControlDescription> | ||
<HstCheckbox v-model="controls.draggable" title="Draggable" /> | ||
</ControlDescription> | ||
</template> | ||
|
||
<Variant title="Playground" auto-props-disabled> | ||
<RankingContainer | ||
:title="controls.title" | ||
:labels="controls.labels" | ||
:topRank="controls.topRank" | ||
:draggable="controls.draggable" | ||
/> | ||
</Variant> | ||
</Story> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
interface Controls { | ||
title: string | ||
labels: string[] | ||
topRank: boolean | ||
draggable: boolean | ||
} | ||
const controls = reactive<Controls>({ | ||
title: 'Ranking Container', | ||
labels: ['Label 1', 'Label 2', 'Label 3', 'Label 4', 'Label 5'], | ||
topRank: false, | ||
draggable: false | ||
}) | ||
const labelOptions = ['this is for testing the scroll container'] | ||
</script> |
110 changes: 110 additions & 0 deletions
110
src/components/Containment/RankingContainer/RankingContainer.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<template> | ||
<div class="h-10 w-full overflow-hidden"> | ||
<div | ||
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" | ||
> | ||
<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" | ||
:class="[topRankClassBorder, draggableClass]" | ||
data-test="draggableIcon" | ||
> | ||
<p class="rotate-90" :class="topRankClassSeparator">|||</p> | ||
</div> | ||
<div class="flex h-full w-fit min-w-0 flex-row items-center gap-1 sm:gap-5"> | ||
<div | ||
class="flex items-center font-eina1 text-1 font-semibold text-basic-black sm:whitespace-nowrap sm:text-4" | ||
data-test="title" | ||
> | ||
{{ title }} | ||
</div> | ||
<div class="flex items-center text-4" :class="topRankClassSeparator">|</div> | ||
<div | ||
class="scrollbar-hide flex min-w-0 cursor-grab select-none flex-row items-center gap-2 overflow-x-scroll pr-2" | ||
@mousedown="handleMouseDown" | ||
@mousemove="handleMouseMove" | ||
@mouseup="handleMouseUp" | ||
@mouseleave="handleMouseUp" | ||
ref="scrollContainer" | ||
data-test="scrollContainer" | ||
> | ||
<ChipContainer v-for="label in labels" :label="label" :key="label" data-test="label" /> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
const props = defineProps({ | ||
title: { | ||
type: String as PropType<string>, | ||
default: '', | ||
required: true | ||
}, | ||
labels: { | ||
type: Array as PropType<string[]>, | ||
default: () => [] | ||
}, | ||
topRank: { | ||
type: Boolean as PropType<boolean>, | ||
default: false | ||
}, | ||
draggable: { | ||
type: Boolean as PropType<boolean>, | ||
default: false | ||
} | ||
}) | ||
const title = computed(() => props.title) | ||
const labels = computed(() => props.labels) | ||
const topRank = computed(() => props.topRank) | ||
const draggable = computed(() => props.draggable) | ||
let isDragging = false | ||
let startX: number, scrollLeft: number | ||
const scrollContainer: Ref<HTMLElement | null> = ref(null) | ||
const topRankClassBorder = computed(() => | ||
topRank.value ? 'border-primary-moonstone' : 'border-basic-grey' | ||
) | ||
const topRankClassSeparator = computed(() => | ||
topRank.value ? 'text-primary-moonstone' : 'text-basic-grey' | ||
) | ||
const draggableClass = computed(() => (draggable.value ? 'cursor-move' : 'cursor-default')) | ||
const handleMouseDown = (e: MouseEvent) => { | ||
isDragging = true | ||
startX = e.pageX - (scrollContainer.value?.offsetLeft || 0) | ||
scrollLeft = scrollContainer.value?.scrollLeft || 0 | ||
} | ||
const handleMouseMove = (e: MouseEvent) => { | ||
if (!isDragging) return | ||
e.preventDefault() | ||
const x = e.pageX - (scrollContainer.value?.offsetLeft || 0) | ||
const walk = (x - startX) * 1.2 | ||
if (scrollContainer.value) { | ||
scrollContainer.value.scrollLeft = scrollLeft - walk | ||
} | ||
} | ||
const handleMouseUp = () => { | ||
isDragging = false | ||
} | ||
</script> | ||
|
||
<style scoped> | ||
.scrollbar-hide::-webkit-scrollbar { | ||
display: none; | ||
} | ||
.scrollbar-hide { | ||
-ms-overflow-style: none; | ||
scrollbar-width: none; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './RankingContainer.vue'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters