mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-19 14:31:47 +01:00
fix(Breadcrumb/Carousel/Pagination): handle icons in RTL mode (#2633)
This commit is contained in:
@@ -76,8 +76,10 @@ extendDevtoolsMeta({
|
||||
</script>
|
||||
|
||||
<script setup lang="ts" generic="T extends BreadcrumbItem">
|
||||
import { computed } from 'vue'
|
||||
import { Primitive } from 'radix-vue'
|
||||
import { useAppConfig } from '#imports'
|
||||
import { useLocale } from '../composables/useLocale'
|
||||
import { get } from '../utils'
|
||||
import { pickLinkProps } from '../utils/link'
|
||||
import UIcon from './Icon.vue'
|
||||
@@ -89,9 +91,11 @@ const props = withDefaults(defineProps<BreadcrumbProps<T>>(), {
|
||||
labelKey: 'label'
|
||||
})
|
||||
const slots = defineSlots<BreadcrumbSlots<T>>()
|
||||
|
||||
const { dir } = useLocale()
|
||||
const appConfig = useAppConfig()
|
||||
|
||||
const separatorIcon = computed(() => props.separatorIcon || (dir.value === 'rtl' ? appConfig.ui.icons.chevronLeft : appConfig.ui.icons.chevronRight))
|
||||
|
||||
// eslint-disable-next-line vue/no-dupe-keys
|
||||
const ui = breadcrumb()
|
||||
</script>
|
||||
@@ -123,7 +127,7 @@ const ui = breadcrumb()
|
||||
|
||||
<li v-if="index < items!.length - 1" role="presentation" :class="ui.separator({ class: props.ui?.separator })">
|
||||
<slot name="separator">
|
||||
<UIcon :name="separatorIcon || appConfig.ui.icons.chevronRight" :class="ui.separatorIcon({ class: props.ui?.separatorIcon })" />
|
||||
<UIcon :name="separatorIcon" :class="ui.separatorIcon({ class: props.ui?.separatorIcon })" />
|
||||
</slot>
|
||||
</li>
|
||||
</template>
|
||||
|
||||
@@ -135,9 +135,12 @@ const props = withDefaults(defineProps<CarouselProps<T>>(), {
|
||||
defineSlots<CarouselSlots<T>>()
|
||||
|
||||
const appConfig = useAppConfig()
|
||||
const { t } = useLocale()
|
||||
const { dir, t } = useLocale()
|
||||
const rootProps = useForwardProps(reactivePick(props, 'active', 'align', 'breakpoints', 'containScroll', 'dragFree', 'dragThreshold', 'duration', 'inViewThreshold', 'loop', 'skipSnaps', 'slidesToScroll', 'startIndex', 'watchDrag', 'watchResize', 'watchSlides', 'watchFocus'))
|
||||
|
||||
const prevIcon = computed(() => props.prevIcon || (dir.value === 'rtl' ? appConfig.ui.icons.arrowRight : appConfig.ui.icons.arrowLeft))
|
||||
const nextIcon = computed(() => props.nextIcon || (dir.value === 'rtl' ? appConfig.ui.icons.arrowLeft : appConfig.ui.icons.arrowRight))
|
||||
|
||||
const ui = computed(() => carousel({
|
||||
orientation: props.orientation
|
||||
}))
|
||||
@@ -277,7 +280,7 @@ defineExpose({
|
||||
<div v-if="arrows" :class="ui.arrows({ class: props.ui?.arrows })">
|
||||
<UButton
|
||||
:disabled="!canScrollPrev"
|
||||
:icon="prevIcon || appConfig.ui.icons.arrowLeft"
|
||||
:icon="prevIcon"
|
||||
size="md"
|
||||
color="neutral"
|
||||
variant="outline"
|
||||
@@ -288,7 +291,7 @@ defineExpose({
|
||||
/>
|
||||
<UButton
|
||||
:disabled="!canScrollNext"
|
||||
:icon="nextIcon || appConfig.ui.icons.arrowRight"
|
||||
:icon="nextIcon"
|
||||
size="md"
|
||||
color="neutral"
|
||||
variant="outline"
|
||||
|
||||
@@ -103,9 +103,11 @@ extendDevtoolsMeta({ defaultProps: { total: 50 } })
|
||||
</script>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { PaginationRoot, PaginationList, PaginationListItem, PaginationFirst, PaginationPrev, PaginationEllipsis, PaginationNext, PaginationLast, useForwardPropsEmits } from 'radix-vue'
|
||||
import { reactivePick } from '@vueuse/core'
|
||||
import { useAppConfig } from '#imports'
|
||||
import { useLocale } from '../composables/useLocale'
|
||||
import UButton from './Button.vue'
|
||||
|
||||
const props = withDefaults(defineProps<PaginationProps>(), {
|
||||
@@ -124,9 +126,14 @@ const emits = defineEmits<PaginationEmits>()
|
||||
const slots = defineSlots<PaginationSlots>()
|
||||
|
||||
const appConfig = useAppConfig()
|
||||
|
||||
const { dir } = useLocale()
|
||||
const rootProps = useForwardPropsEmits(reactivePick(props, 'as', 'defaultPage', 'disabled', 'itemsPerPage', 'page', 'showEdges', 'siblingCount', 'total'), emits)
|
||||
|
||||
const firstIcon = computed(() => props.firstIcon || (dir.value === 'rtl' ? appConfig.ui.icons.chevronDoubleRight : appConfig.ui.icons.chevronDoubleLeft))
|
||||
const prevIcon = computed(() => props.prevIcon || (dir.value === 'rtl' ? appConfig.ui.icons.chevronRight : appConfig.ui.icons.chevronLeft))
|
||||
const nextIcon = computed(() => props.nextIcon || (dir.value === 'rtl' ? appConfig.ui.icons.chevronLeft : appConfig.ui.icons.chevronRight))
|
||||
const lastIcon = computed(() => props.lastIcon || (dir.value === 'rtl' ? appConfig.ui.icons.chevronDoubleLeft : appConfig.ui.icons.chevronDoubleRight))
|
||||
|
||||
// eslint-disable-next-line vue/no-dupe-keys
|
||||
const ui = pagination()
|
||||
</script>
|
||||
@@ -136,12 +143,12 @@ const ui = pagination()
|
||||
<PaginationList v-slot="{ items }" :class="ui.list({ class: props.ui?.list })">
|
||||
<PaginationFirst v-if="showControls || !!slots.first" as-child>
|
||||
<slot name="first">
|
||||
<UButton :color="color" :variant="variant" :size="size" :icon="firstIcon || appConfig.ui.icons.chevronDoubleLeft" :to="to?.(1)" />
|
||||
<UButton :color="color" :variant="variant" :size="size" :icon="firstIcon" :to="to?.(1)" />
|
||||
</slot>
|
||||
</PaginationFirst>
|
||||
<PaginationPrev v-if="showControls || !!slots.prev" as-child>
|
||||
<slot name="prev">
|
||||
<UButton :color="color" :variant="variant" :size="size" :icon="prevIcon || appConfig.ui.icons.chevronLeft" :to="page > 1 ? to?.(page - 1) : undefined" />
|
||||
<UButton :color="color" :variant="variant" :size="size" :icon="prevIcon" :to="page > 1 ? to?.(page - 1) : undefined" />
|
||||
</slot>
|
||||
</PaginationPrev>
|
||||
|
||||
@@ -169,12 +176,12 @@ const ui = pagination()
|
||||
|
||||
<PaginationNext v-if="showControls || !!slots.next" as-child>
|
||||
<slot name="next">
|
||||
<UButton :color="color" :variant="variant" :size="size" :icon="nextIcon || appConfig.ui.icons.chevronRight" :to="page < pageCount ? to?.(pageCount) : undefined" />
|
||||
<UButton :color="color" :variant="variant" :size="size" :icon="nextIcon" :to="page < pageCount ? to?.(pageCount) : undefined" />
|
||||
</slot>
|
||||
</PaginationNext>
|
||||
<PaginationLast v-if="showControls || !!slots.last" as-child>
|
||||
<slot name="last">
|
||||
<UButton :color="color" :variant="variant" :size="size" :icon="lastIcon || appConfig.ui.icons.chevronDoubleRight" :to=" to?.(pageCount)" />
|
||||
<UButton :color="color" :variant="variant" :size="size" :icon="lastIcon" :to=" to?.(pageCount)" />
|
||||
</slot>
|
||||
</PaginationLast>
|
||||
</PaginationList>
|
||||
|
||||
@@ -30,7 +30,7 @@ export function translate(path: string, option: undefined | TranslatorOption, lo
|
||||
export function buildLocaleContext(locale: MaybeRef<Locale>): LocaleContext {
|
||||
const lang = computed(() => unref(locale).name)
|
||||
const code = computed(() => unref(locale).code)
|
||||
const dir = computed(() => unref(locale).dir)
|
||||
const dir = computed(() => unref(locale).dir.toLowerCase())
|
||||
const localeRef = isRef(locale) ? locale : ref(locale)
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user