5180 fichiers 38.5 Mo 0 téléchargements 350 vues mis à jour il y a 7 heures ui
chatTextSize.ts 1.3 Ko Télécharger le fichier
export type ChatTextSize = 's' | 'm' | 'l' | 'xl' | 'xxl';

export const CHAT_TEXT_SIZE_STORAGE_KEY = 'nitro.chat.text_size';
export const CHAT_TEXT_SIZE_EVENT = 'octane-chat-text-size-change';
export const CHAT_TEXT_SIZES: ChatTextSize[] = ['s', 'm', 'l', 'xl', 'xxl'];

const CHAT_TEXT_SIZE_LABELS: Record<ChatTextSize, string> = {
    s: 'S',
    m: 'M',
    l: 'L',
    xl: 'XL',
    xxl: 'XXL'
};

export const CHAT_TEXT_SIZE_PIXELS: Record<ChatTextSize, number> = {
    s: 11,
    m: 14,
    l: 18,
    xl: 22,
    xxl: 25
};

export const isChatTextSize = (value: string): value is ChatTextSize => CHAT_TEXT_SIZES.includes(value as ChatTextSize);

export const getChatTextSizeLabel = (size: ChatTextSize): string => CHAT_TEXT_SIZE_LABELS[size];

export const getStoredChatTextSize = (): ChatTextSize => {
    if (typeof window === 'undefined') return 'm';

    const stored = window.localStorage.getItem(CHAT_TEXT_SIZE_STORAGE_KEY);

    return stored && isChatTextSize(stored) ? stored : 'm';
};

export const setStoredChatTextSize = (size: ChatTextSize) => {
    if (typeof window === 'undefined') return;

    window.localStorage.setItem(CHAT_TEXT_SIZE_STORAGE_KEY, size);
    window.dispatchEvent(new CustomEvent<ChatTextSize>(CHAT_TEXT_SIZE_EVENT, { detail: size }));
};
15Sujets
1Dépôts
20Membres
3En ligne
Profile
Inscrit
Dernière visite
Messages
0
Votes positifs
0
Votes négatifs
0

Nous utilisons des cookies pour assurer le bon fonctionnement du site et améliorer votre expérience. en savoir plus

Autoriser