use-classy
Version:
A utility for generating React [className] strings, with support for CSS modules and BEM expansions.
3 lines (2 loc) • 5.08 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react"),require("prop-types")):"function"==typeof define&&define.amd?define(["exports","react","prop-types"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).classy={},t.react,t.PropTypes)}(this,(function(t,e,r){"use strict";function n(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var o=n(r);function i(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function u(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?i(Object(r),!0).forEach((function(e){c(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):i(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function c(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function a(t){return function(t){if(Array.isArray(t))return f(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(!t)return;if("string"==typeof t)return f(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return f(t,e)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function f(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}var l="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},s="object"==typeof l&&l&&l.Object===Object&&l,p="object"==typeof self&&self&&self.Object===Object&&self,y=(s||p||Function("return this")()).Symbol,b=y,d=Object.prototype,v=d.hasOwnProperty,O=d.toString,g=b?b.toStringTag:void 0;var j=function(t){var e=v.call(t,g),r=t[g];try{t[g]=void 0;var n=!0}catch(t){}var o=O.call(t);return n&&(e?t[g]=r:delete t[g]),o},h=Object.prototype.toString;var m=j,S=function(t){return h.call(t)},P=y?y.toStringTag:void 0;var w=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":P&&P in Object(t)?m(t):S(t)};var A=function(t,e){return function(r){return t(e(r))}}(Object.getPrototypeOf,Object);var T=function(t){return null!=t&&"object"==typeof t},E=w,R=A,C=T,I=Function.prototype,_=Object.prototype,D=I.toString,x=_.hasOwnProperty,M=D.call(Object);var Y=function(t){if(!C(t)||"[object Object]"!=E(t))return!1;var e=R(t);if(null===e)return!0;var r=x.call(e,"constructor")&&e.constructor;return"function"==typeof r&&r instanceof r&&D.call(r)==M};var k=function(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t},q=w,F=T;var L=function(t){return F(t)&&"[object Arguments]"==q(t)},U=T,N=Object.prototype,$=N.hasOwnProperty,z=N.propertyIsEnumerable,B=L(function(){return arguments}())?L:function(t){return U(t)&&$.call(t,"callee")&&!z.call(t,"callee")},G=B,H=Array.isArray,J=G,K=H,Q=y?y.isConcatSpreadable:void 0;var V=k,W=function(t){return K(t)||J(t)||!!(Q&&t&&t[Q])};var X=function t(e,r,n,o,i){var u=-1,c=e.length;for(n||(n=W),i||(i=[]);++u<c;){var a=e[u];r>0&&n(a)?r>1?t(a,r-1,n,o,i):V(i,a):o||(i[i.length]=a)}return i},Z=X;var tt=function(t){return(null==t?0:t.length)?Z(t,Infinity):[]},et=["-","_"],rt=function(t){return tt(t.map((function(t){return"string"==typeof t?null==t?void 0:t.split(/[\s,.]/g):t})))},nt=function(t,e){return t&&e?"&"===t[0]?t.replace("&",e):et.includes(t[0])&&!t.includes("-scss")?"".concat(e).concat(t):t:t};function ot(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];if(this instanceof ot?this.constructor:void 0){var n,o;"string"==typeof e[0]?(o=e[0],n=e[1]):(n=e[0],o=e[1]);var i=n||{},c=i.bem,f=void 0===c?o:c,l=i.classes,s=void 0===l?{}:l;return function(){for(var t,e=arguments.length,r=new Array(e),o=0;o<e;o++)r[o]=arguments[o];var i=ot(u(u({bem:f},n),s),r);return i||(null===(t=n)||void 0===t?void 0:t[f])||f}}if(!e.length)return"";var p=e[0],y=e.slice(1);Y(p)||(y=[p].concat(a(y)),p={});var b=p||{},d=b.bem,v=void 0===d?"":d;return y=tt(y),(y=rt(y)).filter((function(t){return"string"==typeof t&&t})).map((function(t){return(t=nt(t,v))in p&&(t=p[t]),t})).join(" ")}ot.SEPARATORS=et;var it=o.default.oneOfType([o.default.string,o.default.arrayOf(o.default.oneOfType([o.default.string,o.default.array]))]);t.CLASSY_PROPTYPE=it,t.CLASSY_SEPARATORS=et,t.SEPARATORS=et,t.classy=ot,t.default=ot,t.useClassy=function(t,r){var n=e.useCallback((function(){return new ot(t,r)}),[t,r]);return e.useMemo((function(){return n.apply(void 0,arguments)}),[n])},Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=classy.js.map