UNPKG

@applicaster/zapp-react-native-utils

Version:

Applicaster Zapp React Native utilities package

115 lines (96 loc) 2.92 kB
const R = require("ramda"); const { SPACING_KEYS, ZAPPIFEST_FIELDS } = require("../keys"); const { toSnakeCase, toCamelCase, isDefined, getConditionalField, } = require("../_internals"); const { fontKey } = require("../fonts"); const { spacingKey } = require("../containers"); function buttonKey(label, defaults) { const keyName = R.compose(toSnakeCase, R.toLower)(label); const { fields, conditionalField } = getConditionalField(label, defaults); const fontsFieldsToSkip = [ "enable", ...SPACING_KEYS.map(R.compose(toCamelCase, toSnakeCase)), "backgroundColor", "focusedBackgroundColor", "cornerRadius", ]; const fontFields = fontKey( `${label} label`, R.omit(fontsFieldsToSkip, defaults), conditionalField ); fields.push(...fontFields); const spacingFields = spacingKey(label, defaults, conditionalField); fields.push(...spacingFields); if (isDefined(defaults.backgroundColor)) { fields.push({ type: ZAPPIFEST_FIELDS.color_picker, label: `${label} background color`, key: `${keyName}_background_color`, initial_value: defaults.backgroundColor, ...conditionalField, }); } if (isDefined(defaults.focusedBackgroundColor)) { fields.push({ type: ZAPPIFEST_FIELDS.color_picker, label: `${label} focused background color`, key: `${keyName}_focused_background_color`, initial_value: defaults.focusedBackgroundColor, ...conditionalField, }); } if (isDefined(defaults.cornerRadius)) { fields.push({ type: ZAPPIFEST_FIELDS.number_input, label: `${label} corner radius`, key: `${keyName}_corner_radius`, initial_value: defaults.cornerRadius, ...conditionalField, }); } if (isDefined(defaults.borderWidth)) { fields.push({ type: ZAPPIFEST_FIELDS.number_input, label: `${label} border width`, key: `${keyName}_border_width`, initial_value: defaults.borderWidth, ...conditionalField, }); } if (isDefined(defaults.borderColor)) { fields.push({ type: ZAPPIFEST_FIELDS.color_picker, label: `${label} border color`, key: `${keyName}_border_color`, initial_value: defaults.borderColor, ...conditionalField, }); } if (isDefined(defaults.focusedBorderColor)) { fields.push({ type: ZAPPIFEST_FIELDS.color_picker, label: `${label} focused border color`, key: `${keyName}_focused_border_color`, initial_value: defaults.focusedBorderColor, ...conditionalField, }); } if (isDefined(defaults.borderCornerRadius)) { fields.push({ type: ZAPPIFEST_FIELDS.number_input, label: `${label} border corner radius`, key: `${keyName}_border_corner_radius`, initial_value: defaults.borderCornerRadius, ...conditionalField, }); } return fields; } module.exports = { buttonKey, };