carbon-react
Version:
A library of reusable React components for easily building user interfaces.
2 lines (1 loc) • 669 B
JavaScript
import{jsx as e}from"react/jsx-runtime";import t from"react";import n from"./matching-text.style.js";function r(t,i){if(!i||!i.length||!t)return t;const l=t.toLowerCase(),o=i.toLowerCase(),c=l.indexOf(o);if(-1===c)return t;const s=t.slice(0,c),a=t.slice(c,c+i.length),h=t.slice(c+i.length,t.length);let f=h;return h.length>=i.length&&(f=r(h,i)),[e("span",{children:s},"preceding"),e(n,{"data-role":"matching-text",children:a},"match"),e("span",{children:f},"following")]}function i(e,n){if("string"==typeof e)return r(e,n);if(!t.isValidElement(e))return e;const l=t.Children.map(e.props.children,(e=>i(e,n)));return t.cloneElement(e,{children:l})}export{i as default};