feat: RTL布局支持 — close动画方向自动适配语言方向
This commit is contained in:
+4
-3
@@ -9,7 +9,7 @@ import { generateId, escapeHTML } from './utils.js';
|
|||||||
import { DEFAULTS, ICONS, TYPE_COLORS, THEMES } from './constants.js';
|
import { DEFAULTS, ICONS, TYPE_COLORS, THEMES } from './constants.js';
|
||||||
import { injectStyles } from './styles.js';
|
import { injectStyles } from './styles.js';
|
||||||
import { getTheme, applyTheme } from './themes.js';
|
import { getTheme, applyTheme } from './themes.js';
|
||||||
import { t as i18nT, setCurrentLocale } from './i18n.js';
|
import { t as i18nT, setCurrentLocale, getLocaleDirection, getCurrentLocale } from './i18n.js';
|
||||||
|
|
||||||
// 模块级共享容器缓存,所有 Toast 实例共用
|
// 模块级共享容器缓存,所有 Toast 实例共用
|
||||||
// 使用 Map 而非 WeakMap:document.body 在页面存活期间永不被 GC,
|
// 使用 Map 而非 WeakMap:document.body 在页面存活期间永不被 GC,
|
||||||
@@ -493,10 +493,11 @@ class Toast {
|
|||||||
el.classList.remove('met-show');
|
el.classList.remove('met-show');
|
||||||
|
|
||||||
const pos = this.config.position || 'top-right';
|
const pos = this.config.position || 'top-right';
|
||||||
|
const isRTL = getLocaleDirection(getCurrentLocale()) === 'rtl';
|
||||||
let transform = 'scale(.96)';
|
let transform = 'scale(.96)';
|
||||||
|
|
||||||
if (pos.includes('right')) transform = 'translateX(120%)';
|
if (pos.includes('right')) transform = isRTL ? 'translateX(-120%)' : 'translateX(120%)';
|
||||||
else if (pos.includes('left')) transform = 'translateX(-120%)';
|
else if (pos.includes('left')) transform = isRTL ? 'translateX(120%)' : 'translateX(-120%)';
|
||||||
else if (pos.startsWith('top')) transform = 'translateY(-20px)';
|
else if (pos.startsWith('top')) transform = 'translateY(-20px)';
|
||||||
else transform = 'translateY(20px)';
|
else transform = 'translateY(20px)';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user