@blackblock/react-anchor-heading
Version:
A React heading component with id that automatically changes with textContent for anchoring.
2 lines (1 loc) • 815 B
JavaScript
import r from"react";function t(){return(t=Object.assign||function(r){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=e[n])}return r}).apply(this,arguments)}const e=r.forwardRef((function({as:e="div",children:n,...o},a){const c=e;return r.createElement(c,t({ref:a},o),n)})),n=r=>encodeURIComponent(r).toLowerCase();function o(){return(o=Object.assign||function(r){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=e[n])}return r}).apply(this,arguments)}const a=r.forwardRef((function({as:t="h1",children:a,...c},i){return r.createElement(e,o({ref:i,as:t,id:n(a)},c),a)}));function c({children:r,text:t}){return r({id:n(t),text:t})}export{a as Heading,c as HeadingPrimitive};