@nitrogenbuilder/client-react
Version:
Nitrogen Builder React Client
41 lines (35 loc) • 894 B
text/typescript
import type { Prop } from '@nitrogenbuilder/types';
export function getDefault(prop: any, propV: Prop) {
const def = propV.default ?? '';
if (def === undefined || def === null || def === '') {
return prop;
}
if (prop === undefined || prop === null) {
return def;
}
if (typeof prop === 'object') {
if (typeof def === 'object') {
if (propV.responsive) {
if ('mobile' in prop) {
return { ...prop };
}
let returnObject: any = {};
if ('mobile' in def) {
returnObject.mobile = def.mobile;
}
if ('tablet' in prop) {
return { ...returnObject, ...prop };
}
if ('tablet' in def) {
returnObject.tablet = def.tablet;
}
if ('laptop' in prop) {
return { ...returnObject, ...prop };
}
}
return { ...def, ...prop };
}
throw new Error("Default value should be responsive, but it ain't bruh");
}
return prop;
}