-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add VMediaViewer * feat(VMediaViewer): improved code * feat : css warnings * feat: add VCarouselProgress
- Loading branch information
Showing
15 changed files
with
725 additions
and
87 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"@type": "Document", | ||
"@id": "/api/documents/2", | ||
"mimeType": "image/jpeg", | ||
"imageWidth": "2043", | ||
"imageHeight": "3040", | ||
"mediaDuration": 0, | ||
"imageAverageColor": "#533c28", | ||
"alt": "img_test.jpg", | ||
"relativePath": "02.jpg", | ||
"processable": true, | ||
"type": "image", | ||
"copyright": "Sous licence protégée", | ||
"folders": [] | ||
} |
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
12 changes: 12 additions & 0 deletions
12
components/molecules/VCarouselProgress/Default.stories.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,12 @@ | ||
<script setup lang="ts"> | ||
const index = ref(0) | ||
</script> | ||
|
||
<template> | ||
<NuxtStory> | ||
<VCarouselProgress | ||
v-model:index="index" | ||
:snap-length="3" | ||
/> | ||
</NuxtStory> | ||
</template> |
94 changes: 94 additions & 0 deletions
94
components/molecules/VCarouselProgress/VCarouselProgress.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,94 @@ | ||
<script lang="ts" setup> | ||
import type { ThemeProps } from '~/composables/use-theme' | ||
const props = defineProps<{ | ||
index: number | ||
snapLength: number | ||
} & ThemeProps>() | ||
const { themeClass } = useTheme({ props }) | ||
const root = ref<HTMLElement | null>(null) | ||
const thumb = ref<HTMLElement | null>(null) | ||
onMounted(() => { | ||
setIndicatorWidth() | ||
setIndicatorPosition(props.index) | ||
}) | ||
watch(() => props.snapLength, () => { | ||
setIndicatorWidth() | ||
setIndicatorPosition(props.index) | ||
}, { flush: 'post' }) | ||
watch(() => props.index, (newIndex) => { | ||
setIndicatorPosition(newIndex) | ||
}) | ||
function setIndicatorWidth() { | ||
if (!root.value?.offsetWidth || !thumb.value) return // can be undefined in SSR | ||
const value = (root.value?.offsetWidth / Math.max(props.snapLength, 1) / root.value?.offsetWidth) * 100 | ||
thumb.value?.style.setProperty('--v-carousel-controls-thumb-width', value + '%') | ||
} | ||
function setIndicatorPosition(index: number) { | ||
if (!root.value || !thumb.value) return | ||
const percent = index / Math.max(props.snapLength - 1, 1) | ||
const translate = percent * (root.value?.offsetWidth - thumb.value?.getBoundingClientRect().width) | ||
thumb.value.style.translate = translate + 'px 0 ' | ||
} | ||
</script> | ||
|
||
<template> | ||
<div | ||
ref="root" | ||
:class="[$style.root, themeClass]" | ||
> | ||
<div | ||
ref="thumb" | ||
:class="$style.thumb" | ||
/> | ||
</div> | ||
</template> | ||
|
||
<style lang="scss" module> | ||
@use 'assets/scss/functions/rem' as *; | ||
@use 'assets/scss/mixins/include-media' as *; | ||
@use 'assets/scss/mixins/theme' as *; | ||
.root { | ||
position: relative; | ||
overflow: hidden; | ||
width: rem(48); | ||
height: rem(2); | ||
flex-shrink: 0; | ||
@include theme-variants('colors-control'); | ||
&::before { | ||
position: absolute; | ||
background-color: var(--theme-colors-control-content-disabled, #ccc); | ||
content: ''; | ||
inset: 0; | ||
} | ||
@include media('>=lg') { | ||
width: rem(64); | ||
} | ||
} | ||
.thumb { | ||
position: relative; | ||
width: clamp(#{rem(22)}, var(--v-carousel-controls-thumb-width), 100%); | ||
height: 100%; | ||
background-color: var(--theme-colors-control-content, currentColor); | ||
content: ''; | ||
transform-origin: left; | ||
transition: 0.2s linear, 0.5s; | ||
transition-property: translate, width; | ||
} | ||
</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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<script setup lang="ts"> | ||
import type { RoadizDocument } from '@roadiz/types' | ||
import { useMediaViewer } from '~/composables/use-media-viewer' | ||
import image from '~/assets/stories/fixtures/documents/image-01.json' | ||
import imagePortrait from '~/assets/stories/fixtures/documents/image-portrait.json' | ||
import video from '~/assets/stories/fixtures/documents/video-01.json' | ||
const documents = [image, imagePortrait, video, image, video, image] as RoadizDocument[] | ||
const { isOpen, open } = useMediaViewer() | ||
function onOpenClick() { | ||
open(documents, 0) | ||
} | ||
</script> | ||
|
||
<template> | ||
<NuxtStory> | ||
<VButton | ||
v-if="!isOpen" | ||
label="open" | ||
filled | ||
@click="onOpenClick" | ||
/> | ||
<Transition :name="$style['media-viewer']"> | ||
<VMediaViewer v-if="isOpen" /> | ||
</Transition> | ||
</NuxtStory> | ||
</template> | ||
|
||
<style lang="scss" module> | ||
.media-viewer { | ||
&:global(#{'-enter-active'}), | ||
&:global(#{'-leave-active'}) { | ||
transition: translate 1s ease(out-quart); | ||
} | ||
&:global(#{'-enter-from'}), | ||
&:global(#{'-leave-to'}) { | ||
translate: 0 100%; | ||
} | ||
} | ||
.controls { | ||
position: fixed; | ||
z-index: 2000; | ||
} | ||
</style> |
Oops, something went wrong.