/
kaws
/
ui-kit-ce
Обзор
Документация
Войти
/
kaws
/
ui-kit-ce
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
packages/typography/src/utils/getFinalChildren.ts
33 строки
865 B
Denis Svyatovets
style: добавлен плагин eslint для jsDoc
27 янв 2025, 17:06
27 янв 2025, 17:06
6287359
Код
Авторство
О чём код?
import React from 'react' /** * */ export function getFinalChildren( originalChildren: React.ReactNode, truncatedText: string ): React.ReactNode { let currentTextIndex = 0 const processChildren = (child: React.ReactNode): React.ReactNode => { if (typeof child === 'string') { const textToInsert = truncatedText.slice( currentTextIndex, currentTextIndex + child.length ) currentTextIndex += child.length return textToInsert } else if (React.isValidElement(child) && child.props) { return React.cloneElement(child, { ...child.props, // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access children: React.Children.map(child.props.children, processChildren), }) } return child } return React.Children.map(originalChildren, processChildren) }