Files
2025-03-07 19:22:02 +01:00

50 lines
2.0 KiB
JavaScript

import * as React from 'react';
/**
* Similar to `getSlots`, main difference is that it's compatible with new custom jsx pragma
*
* @internal
* This is an internal temporary method, this method will cease to exist eventually!
*
* * ❗️❗️ **DO NOT USE IT EXTERNALLY** ❗️❗️
*
* @deprecated use slot.always or slot.optional combined with assertSlots instead
*/ export function getSlotsNext(state) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
const slots = {};
const slotProps = {};
const slotNames = Object.keys(state.components);
for (const slotName of slotNames){
// eslint-disable-next-line @typescript-eslint/no-deprecated
const [slot, props] = getSlotNext(state, slotName);
// eslint-disable-next-line @typescript-eslint/no-deprecated
slots[slotName] = slot;
slotProps[slotName] = props;
}
// eslint-disable-next-line @typescript-eslint/no-deprecated
return {
slots,
slotProps: slotProps
};
}
/**
* @deprecated use slot.always or slot.optional combined with assertSlots instead
*/ function getSlotNext(state, slotName) {
var _state_components, _state_components1;
const props = state[slotName];
if (props === undefined) {
return [
null,
undefined
];
}
// TS Error: Property 'as' does not exist on type 'UnknownSlotProps | undefined'.ts(2339)
const { as: asProp, ...propsWithoutAs } = props;
const slot = ((_state_components = state.components) === null || _state_components === void 0 ? void 0 : _state_components[slotName]) === undefined || typeof state.components[slotName] === 'string' ? asProp || ((_state_components1 = state.components) === null || _state_components1 === void 0 ? void 0 : _state_components1[slotName]) || 'div' : state.components[slotName];
const shouldOmitAsProp = typeof slot === 'string' && asProp;
const slotProps = shouldOmitAsProp ? propsWithoutAs : props;
return [
slot,
slotProps
];
}