UNPKG

@applicaster/zapp-react-native-utils

Version:

Applicaster Zapp React Native utilities package

51 lines (41 loc) 1.14 kB
const R = require("ramda"); const { SPACING_KEYS, ZAPPIFEST_FIELDS, ABSOLUTE_POSITION_FIELDS, } = require("../keys"); const { toSnakeCase, toCamelCase, isDefined, generateFieldsFromDefaults, } = require("../_internals"); const { fieldsGroup } = require("../utils"); function spacingKey(label, defaults, conditionalField = {}) { const keyName = R.compose(toSnakeCase, R.toLower)(label); return SPACING_KEYS.reduce((fields, spacing) => { const snakedSpacing = toSnakeCase(spacing); const spacingProp = toCamelCase(snakedSpacing); if (isDefined(defaults[spacingProp])) { fields.push({ type: ZAPPIFEST_FIELDS.number_input, label: `${label} ${spacing}`, key: `${keyName}_${snakedSpacing}`, initial_value: defaults[spacingProp], ...conditionalField, }); } return fields; }, []); } function absolutePositionElement(label, description, defaults) { return fieldsGroup( label, description, generateFieldsFromDefaults(label, defaults, ABSOLUTE_POSITION_FIELDS) ); } module.exports = { spacingKey, absolutePositionElement, };