5180 fichiers 38.5 Mo 0 téléchargements 206 vues mis à jour il y a 5 heures ui
nitro-v36-with-renderer-v36 / src / common / native-text / nativeTextChildren.tsx
nativeTextChildren.tsx 983 o Télécharger le fichier
import { ReactNode } from 'react';
import { NativeLabel } from './NativeLabel';
import { isNativeTextEnabled } from './nativeTextEnabled';

const isEmpty = (part: unknown) => part === null || part === undefined || part === false || part === true;

/**
 * Children that are only text (strings and numbers, with the false / null of conditional parts) become one NativeLabel; anything
 * with elements in it is returned as it is, so mixed inline markup keeps the browser's layout.
 */
export const nativeTextChildren = (children: ReactNode, stateKey?: unknown): ReactNode => {
    if (!isNativeTextEnabled()) return children;

    const parts = Array.isArray(children) ? children : [children];

    if (!parts.every((part) => isEmpty(part) || typeof part === 'string' || typeof part === 'number')) return children;

    const text = parts.filter((part) => !isEmpty(part)).join('');

    if (!text.trim()) return children;

    return <NativeLabel stateKey={stateKey} text={text} />;
};
15Sujets
1Dépôts
20Membres
2En 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