@etsoo/react
Version:
TypeScript ReactJs UI Independent Framework
44 lines (43 loc) • 1.18 kB
JavaScript
import { DomUtils } from "@etsoo/shared";
/**
* Grid size calculation
* @param size Size
* @param input Input
*/
export const GridSizeGet = (size, input) => {
if (typeof size === "function")
return size(input);
return size;
};
/**
* Grid data get with format
* @param data Data
* @param template Template
* @param keepSource Keep source data
* @returns Json data
*/
export function GridDataGet(props, template, keepSource) {
// Destruct
const { data, ...rest } = props;
// DomUtils.dataAs(data, template);
return { ...GridDataGetData(data, template, keepSource), ...rest };
}
/**
* Grid data get with format
* @param data Data
* @param template Template
* @param keepSource Keep source data
* @returns Json data
*/
export function GridDataGetData(data, template, keepSource) {
// Clear form empty value
if (data instanceof FormData) {
DomUtils.clearFormData(data);
}
// Conditions
// Set keepSource to true to hold form data, even they are invisible from the conditions
const conditions = data == null
? {}
: DomUtils.dataAs(data, template, keepSource);
return conditions;
}