64 lines
1.8 KiB
Plaintext
64 lines
1.8 KiB
Plaintext
// src/utils.ts
|
|
import { forwardRef as baseForwardRef } from "react";
|
|
function forwardRef(component) {
|
|
return baseForwardRef(component);
|
|
}
|
|
var toIterator = (obj) => {
|
|
return {
|
|
...obj,
|
|
[Symbol.iterator]: function() {
|
|
const keys = Object.keys(this);
|
|
let index = 0;
|
|
return {
|
|
next: () => {
|
|
if (index >= keys.length) {
|
|
return { done: true };
|
|
}
|
|
const key = keys[index];
|
|
const value = this[key];
|
|
index++;
|
|
return { value: { key, value }, done: false };
|
|
}
|
|
};
|
|
}
|
|
};
|
|
};
|
|
var mapPropsVariants = (props, variantKeys, removeVariantProps = true) => {
|
|
if (!variantKeys) {
|
|
return [props, {}];
|
|
}
|
|
const picked = variantKeys.reduce((acc, key) => {
|
|
if (key in props) {
|
|
return { ...acc, [key]: props[key] };
|
|
} else {
|
|
return acc;
|
|
}
|
|
}, {});
|
|
if (removeVariantProps) {
|
|
const omitted = Object.keys(props).filter((key) => !variantKeys.includes(key)).reduce((acc, key) => ({ ...acc, [key]: props[key] }), {});
|
|
return [omitted, picked];
|
|
} else {
|
|
return [props, picked];
|
|
}
|
|
};
|
|
var mapPropsVariantsWithCommon = (originalProps, variantKeys, commonKeys) => {
|
|
const props = Object.keys(originalProps).filter((key) => !variantKeys.includes(key) || (commonKeys == null ? void 0 : commonKeys.includes(key))).reduce((acc, key) => ({ ...acc, [key]: originalProps[key] }), {});
|
|
const variants = variantKeys.reduce(
|
|
(acc, key) => ({ ...acc, [key]: originalProps[key] }),
|
|
{}
|
|
);
|
|
return [props, variants];
|
|
};
|
|
var isHeroUIEl = (component) => {
|
|
var _a, _b, _c;
|
|
return !!((_c = (_b = (_a = component.type) == null ? void 0 : _a.render) == null ? void 0 : _b.displayName) == null ? void 0 : _c.includes("HeroUI"));
|
|
};
|
|
|
|
export {
|
|
forwardRef,
|
|
toIterator,
|
|
mapPropsVariants,
|
|
mapPropsVariantsWithCommon,
|
|
isHeroUIEl
|
|
};
|