feat: core components support simple locale switching (#4273)

* feat: core components support simple locale switching

* fix: test error

* fix: test error
This commit is contained in:
Vben
2024-08-29 22:31:49 +08:00
committed by GitHub
parent 98da0672e7
commit a77cc00e9f
18 changed files with 78 additions and 32 deletions

View File

@@ -44,8 +44,8 @@ describe('drawerApi', () => {
it('should initialize with default state', () => {
expect(drawerState.isOpen).toBe(false);
expect(drawerState.cancelText).toBe('取消');
expect(drawerState.confirmText).toBe('确定');
expect(drawerState.cancelText).toBe(undefined);
expect(drawerState.confirmText).toBe(undefined);
});
it('should open the drawer', () => {

View File

@@ -28,12 +28,10 @@ export class DrawerApi {
} = options;
const defaultState: DrawerState = {
cancelText: '取消',
closable: true,
closeOnClickModal: true,
closeOnPressEscape: true,
confirmLoading: false,
confirmText: '确定',
footer: true,
isOpen: false,
loading: false,

View File

@@ -3,7 +3,11 @@ import type { DrawerProps, ExtendedDrawerApi } from './drawer';
import { ref, watch } from 'vue';
import { useIsMobile, usePriorityValue } from '@vben-core/composables';
import {
useIsMobile,
usePriorityValue,
useSimpleLocale,
} from '@vben-core/composables';
import { Info, X } from '@vben-core/icons';
import {
Sheet,
@@ -34,7 +38,7 @@ const props = withDefaults(defineProps<Props>(), {
});
const wrapperRef = ref<HTMLElement>();
const { $t } = useSimpleLocale();
const { isMobile } = useIsMobile();
const state = props.drawerApi?.useStore?.();
@@ -165,7 +169,7 @@ function pointerDownOutside(e: Event) {
<slot name="footer">
<VbenButton variant="ghost" @click="() => drawerApi?.onCancel()">
<slot name="cancelText">
{{ cancelText }}
{{ cancelText || $t('cancel') }}
</slot>
</VbenButton>
<VbenButton
@@ -173,7 +177,7 @@ function pointerDownOutside(e: Event) {
@click="() => drawerApi?.onConfirm()"
>
<slot name="confirmText">
{{ confirmText }}
{{ confirmText || $t('confirm') }}
</slot>
</VbenButton>
</slot>

View File

@@ -44,8 +44,8 @@ describe('modalApi', () => {
it('should initialize with default state', () => {
expect(modalState.isOpen).toBe(false);
expect(modalState.cancelText).toBe('取消');
expect(modalState.confirmText).toBe('确定');
expect(modalState.cancelText).toBe(undefined);
expect(modalState.confirmText).toBe(undefined);
});
it('should open the modal', () => {

View File

@@ -28,12 +28,10 @@ export class ModalApi {
} = options;
const defaultState: ModalState = {
cancelText: '取消',
centered: false,
closeOnClickModal: true,
closeOnPressEscape: true,
confirmLoading: false,
confirmText: '确定',
draggable: false,
footer: true,
fullscreen: false,

View File

@@ -3,7 +3,11 @@ import type { ExtendedModalApi, ModalProps } from './modal';
import { computed, nextTick, ref, watch } from 'vue';
import { useIsMobile, usePriorityValue } from '@vben-core/composables';
import {
useIsMobile,
usePriorityValue,
useSimpleLocale,
} from '@vben-core/composables';
import { Expand, Info, Shrink } from '@vben-core/icons';
import {
Dialog,
@@ -44,6 +48,7 @@ const dialogRef = ref();
const headerRef = ref();
const footerRef = ref();
const { $t } = useSimpleLocale();
const { isMobile } = useIsMobile();
const state = props.modalApi?.useStore?.();
@@ -235,7 +240,7 @@ function pointerDownOutside(e: Event) {
<slot name="footer">
<VbenButton variant="ghost" @click="() => modalApi?.onCancel()">
<slot name="cancelText">
{{ cancelText }}
{{ cancelText || $t('cancel') }}
</slot>
</VbenButton>
<VbenButton
@@ -243,7 +248,7 @@ function pointerDownOutside(e: Event) {
@click="() => modalApi?.onConfirm()"
>
<slot name="confirmText">
{{ confirmText }}
{{ confirmText || $t('confirm') }}
</slot>
</VbenButton>
</slot>

View File

@@ -53,10 +53,7 @@ withDefaults(defineProps<Props>(), {
:width="logoSize"
class="relative rounded-none bg-transparent"
/>
<span
v-if="!collapsed"
class="text-primary dark:text-foreground truncate text-nowrap"
>
<span v-if="!collapsed" class="text-foreground truncate text-nowrap">
{{ text }}
</span>
</a>