@nex-ui/system
Version:
A lightweight and performant styling library based on Emotion, focusing on component architecture and developer experience.
29 lines (26 loc) • 1.06 kB
JavaScript
import { __DEV__, isArray } from '@nex-ui/utils';
import { createRuntimeFn } from './createRuntimeFn.mjs';
import { mergeRecipeConfigs } from '../utils.mjs';
function defineSlotRecipe(config) {
if (__DEV__) {
if (config.compoundVariants && !isArray(config.compoundVariants)) {
throw new TypeError(`[Nex UI] system: The "compoundVariants" prop must be an array. Received: ${typeof config.compoundVariants}`);
}
}
// eslint-disable-next-line prefer-const
let { extend, ...other } = config;
if (extend && extend?.__slotRecipe === true && extend?.__config) {
other = mergeRecipeConfigs(extend.__config, other);
}
const { slots, ...o } = other;
const runtimeFn = createRuntimeFn({
mainStyles: slots,
...o
});
runtimeFn.__slotRecipe = true;
runtimeFn.__config = other;
runtimeFn.variants = other.variants ? Object.keys(other.variants) : [];
runtimeFn.slots = other.slots ? Object.keys(other.slots) : [];
return runtimeFn;
}
export { defineSlotRecipe };