UNPKG

@nethesis/phone-island

Version:
3 lines (2 loc) 2.28 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react");require("../node_modules/@babel/runtime/helpers/defineProperty.js"),require("../node_modules/@babel/runtime/helpers/objectWithoutProperties.js"),require("../node_modules/@babel/runtime/helpers/typeof.js"),require("../node_modules/html-parse-stringify/dist/html-parse-stringify.js"),require("../node_modules/react-i18next/dist/es/context.js");var t=require("../node_modules/react-i18next/dist/es/useTranslation.js");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("../node_modules/@babel/runtime/helpers/slicedToArray.js");var n=r(e);exports.default=function(r){var i=r.text,a=t.useTranslation().t,l=e.useState(!1),s=l[0],u=l[1],o=e.useRef(null),c=e.useRef(null),p="unknown"===i?a("TextScroll.unknown"):i,d=e.useCallback((function(){if(o.current&&c.current){var e=c.current.scrollWidth-o.current.clientWidth>5;u(e||p.length>12)}else u(p.length>12)}),[p,12]);e.useLayoutEffect((function(){d()}),[p,d]),e.useEffect((function(){if("undefined"!=typeof ResizeObserver){var e=new ResizeObserver((function(){d()}));return o.current&&e.observe(o.current),c.current&&e.observe(c.current),function(){return e.disconnect()}}}),[p,d]);var f=e.useMemo((function(){return"".concat(Math.max(8,Math.ceil(p.length/2)),"s")}),[p]);return n.default.createElement("div",{ref:o,className:"pi-relative pi-block pi-w-full pi-max-w-full pi-overflow-hidden pi-whitespace-nowrap"},s?n.default.createElement(n.default.Fragment,null,n.default.createElement("div",{className:"pi-inline-flex pi-whitespace-nowrap",style:{animation:"scrollText ".concat(f," linear infinite")}},n.default.createElement("span",{className:"pi-pr-6"},p),n.default.createElement("span",{className:"pi-pr-6","aria-hidden":"true"},p)),n.default.createElement("div",{className:"pi-pointer-events-none pi-absolute pi-right-0 pi-top-0 pi-h-full pi-w-6 pi-bg-gradient-to-r pi-from-transparent pi-to-gray-50 dark:pi-to-gray-950"})):n.default.createElement("span",{className:"pi-block pi-max-w-full pi-truncate"},p),n.default.createElement("span",{ref:c,className:"pi-pointer-events-none pi-absolute pi-left-0 pi-top-0 pi-invisible pi-whitespace-nowrap","aria-hidden":"true"},p))}; //# sourceMappingURL=TextScroll.js.map