Skip to content

Commit

Permalink
fix(Progress): handle horizontal animation in RTL mode (#2723)
Browse files Browse the repository at this point in the history
  • Loading branch information
malik-jouda authored Nov 21, 2024
1 parent b140dbf commit 0baa3a0
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 44 deletions.
19 changes: 17 additions & 2 deletions src/runtime/components/Progress.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export type ProgressSlots = {
import { computed } from 'vue'
import { ProgressIndicator, ProgressRoot, useForwardPropsEmits } from 'radix-vue'
import { reactivePick } from '@vueuse/core'
import { useLocale } from '../composables/useLocale'

const props = withDefaults(defineProps<ProgressProps>(), {
inverted: false,
Expand All @@ -59,6 +60,8 @@ const props = withDefaults(defineProps<ProgressProps>(), {
const emits = defineEmits<ProgressEmits>()
defineSlots<ProgressSlots>()

const { dir } = useLocale()

const rootProps = useForwardPropsEmits(reactivePick(props, 'as', 'getValueLabel', 'modelValue'), emits)

const isIndeterminate = computed(() => rootProps.value.modelValue === null)
Expand Down Expand Up @@ -93,8 +96,20 @@ const indicatorStyle = computed(() => {
return
}

return {
transform: `translate${props.orientation === 'vertical' ? 'Y' : 'X'}(${props.inverted ? '' : '-'}${100 - percent.value}%)`
if (props.orientation === 'vertical') {
return {
transform: `translateY(${props.inverted ? '' : '-'}${100 - percent.value}%)`
}
} else {
if (dir.value === 'rtl') {
return {
transform: `translateX(${props.inverted ? '-' : ''}${100 - percent.value}%)`
}
} else {
return {
transform: `translateX(${props.inverted ? '' : '-'}${100 - percent.value}%)`
}
}
}
})

Expand Down
34 changes: 34 additions & 0 deletions src/runtime/keyframes.css
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,24 @@
}
}


@keyframes carousel-rtl {

0%,
100% {
width: 50%
}

0% {
transform: translateX(100%)
}

100% {
transform: translateX(-200%)
}
}


@keyframes carousel-vertical {

0%,
Expand Down Expand Up @@ -394,6 +412,22 @@
}
}

@keyframes carousel-inverse-rtl {

0%,
100% {
width: 50%
}

0% {
transform: translateX(-200%)
}

100% {
transform: translateX(100%)
}
}

@keyframes carousel-inverse-vertical {

0%,
Expand Down
4 changes: 2 additions & 2 deletions src/theme/progress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export default (options: Required<ModuleOptions>) => ({
orientation: 'horizontal',
animation: 'carousel',
class: {
indicator: 'data-[state=indeterminate]:animate-[carousel_2s_ease-in-out_infinite]'
indicator: 'data-[state=indeterminate]:animate-[carousel_2s_ease-in-out_infinite] data-[state=indeterminate]:rtl:animate-[carousel-rtl_2s_ease-in-out_infinite]'
}
}, {
orientation: 'vertical',
Expand All @@ -174,7 +174,7 @@ export default (options: Required<ModuleOptions>) => ({
orientation: 'horizontal',
animation: 'carousel-inverse',
class: {
indicator: 'data-[state=indeterminate]:animate-[carousel-inverse_2s_ease-in-out_infinite]'
indicator: 'data-[state=indeterminate]:animate-[carousel-inverse_2s_ease-in-out_infinite] data-[state=indeterminate]:rtl:animate-[carousel-inverse-rtl_2s_ease-in-out_infinite]'
}
}, {
orientation: 'vertical',
Expand Down
Loading

0 comments on commit 0baa3a0

Please sign in to comment.