UNPKG

@hitachivantara/uikit-react-utils

Version:
52 lines (51 loc) 1.61 kB
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const react = require("react"); const serialize = require("@emotion/serialize"); const utils = require("@emotion/utils"); const clsx = require("clsx"); const uikitReactShared = require("@hitachivantara/uikit-react-shared"); function getRef(args) { if (args.length !== 1) { return { args, ref: void 0 }; } const [arg] = args; if (!(arg instanceof Object)) { return { args, ref: void 0 }; } if (!("ref" in arg)) { return { args, ref: void 0 }; } const { ref, ...argCopy } = arg; return { args: [argCopy], ref }; } const cssFactory = /* @__PURE__ */ (() => { function merge(registered, css, className) { const registeredStyles = []; const rawClassName = utils.getRegisteredStyles( registered, registeredStyles, className ); if (registeredStyles.length < 2) { return className; } return rawClassName + css(registeredStyles); } function innerCssFactory(cache) { const css = (...styles) => { const { ref, args } = getRef(styles); const serialized = serialize.serializeStyles(args, cache.registered); utils.insertStyles(cache, serialized, false); return `${cache.key}-${serialized.name}${ref === void 0 ? "" : ` ${ref}`}`; }; const cx = (...args) => merge(cache.registered, css, clsx.clsx(args)); return { css, cx }; } return innerCssFactory; })(); function useCss() { const cache = uikitReactShared.useEmotionCache(); return react.useMemo(() => cssFactory(cache), [cache]); } exports.useCss = useCss;