@applicaster/zapp-react-native-utils
Version:
Applicaster Zapp React Native utilities package
411 lines (378 loc) • 11.6 kB
JavaScript
const R = require("ramda");
const { ZAPPIFEST_FIELDS } = require("../keys");
const {
toSnakeCase,
isDefined,
getConditionalField,
} = require("../_internals");
const { spacingKey } = require("../containers");
function fontKey(label, defaults, conditionalField = null) {
const keyName = R.compose(toSnakeCase, R.toLower)(label);
const fields = [];
const enableField = getConditionalField(label, defaults);
const conditional_field =
conditionalField || enableField.conditionalField || {};
if (enableField.fields) {
fields.push(...enableField.fields);
}
fields.push({
type: ZAPPIFEST_FIELDS.color_picker,
label: `${label} font color`,
key: `${keyName}_font_color`,
initial_value: defaults.fontColor,
...conditional_field,
});
if (isDefined(defaults.focusedFontColor)) {
fields.push({
type: ZAPPIFEST_FIELDS.color_picker,
label: `${label} focused font color`,
key: `${keyName}_focused_font_color`,
initial_value: defaults.focusedFontColor,
...conditional_field,
});
}
fields.push(
...[
{
type: ZAPPIFEST_FIELDS.number_input,
label: `iOS ${label} font size`,
key: `${keyName}_ios_font_size`,
initial_value: defaults.fontSizeiOS,
...conditional_field,
},
{
type: ZAPPIFEST_FIELDS.number_input,
label: `Android ${label} font size`,
key: `${keyName}_android_font_size`,
initial_value: defaults.fontSizeAndroid,
...conditional_field,
},
{
type: ZAPPIFEST_FIELDS.font_selector.ios,
label: `iOS ${label} font family`,
key: `${keyName}_ios_font_family`,
initial_value: defaults.fontFamilyiOS,
...conditional_field,
},
{
type: ZAPPIFEST_FIELDS.font_selector.android,
label: `Android ${label} font family`,
key: `${keyName}_android_font_family`,
initial_value: defaults.fontFamilyAndroid,
...conditional_field,
},
{
type: ZAPPIFEST_FIELDS.number_input,
label: `iOS ${label} line height`,
key: `${keyName}_ios_line_height`,
initial_value: defaults.lineHeightiOS,
...conditional_field,
},
{
type: ZAPPIFEST_FIELDS.number_input,
label: `Android ${label} line height`,
key: `${keyName}_android_line_height`,
initial_value: defaults.lineHeightAndroid,
...conditional_field,
},
{
type: ZAPPIFEST_FIELDS.number_input,
label: `iOS ${label} letter spacing`,
key: `${keyName}_ios_letter_spacing`,
initial_value: defaults.letterSpacingiOS,
...conditional_field,
},
{
type: ZAPPIFEST_FIELDS.number_input,
label: `Android ${label} letter spacing`,
key: `${keyName}_android_letter_spacing`,
initial_value: defaults.letterSpacingAndroid,
...conditional_field,
},
{
type: ZAPPIFEST_FIELDS.select,
label: `${label} text transform`,
key: `${keyName}_text_transform`,
options: [
{
text: "Default",
value: "default",
},
{
text: "Uppercase",
value: "uppercase",
},
{
text: "Lowercase",
value: "lowercase",
},
{
text: "Capitalize",
value: "capitalize",
},
],
initial_value: defaults.textTransform,
...conditional_field,
},
]
);
if (isDefined(defaults.textAlignement)) {
fields.push({
type: ZAPPIFEST_FIELDS.select,
label: `${label} text alignment`,
key: `${keyName}_text_alignement`,
options: [
{ text: "center", value: "center" },
{ text: "left", value: "left" },
{ text: "right", value: "right" },
],
initial_value: defaults.textAlignement,
...conditional_field,
});
}
if (isDefined(defaults.numberOfLines)) {
fields.push({
type: ZAPPIFEST_FIELDS.number_input,
label: `${label} number of lines`,
key: `${keyName}_number_of_lines`,
initial_value: defaults.numberOfLines,
...conditional_field,
});
}
const spacingFields = spacingKey(label, defaults, conditional_field);
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,
...conditional_field,
});
}
if (isDefined(defaults.cornerRadius)) {
fields.push({
type: ZAPPIFEST_FIELDS.number_input,
label: `${label} corner radius`,
key: `${keyName}_corner_radius`,
initial_value: defaults.cornerRadius,
...conditional_field,
});
}
return fields;
}
function fontKeyTV(label, defaults, conditionalField = null) {
const keyName = R.compose(toSnakeCase, R.toLower)(label);
const fields = [];
const enableField = getConditionalField(label, defaults);
const conditional_field =
conditionalField || enableField.conditionalField || {};
if (enableField.fields) {
fields.push(...enableField.fields);
}
fields.push({
type: ZAPPIFEST_FIELDS.color_picker,
label: `${label} font color`,
key: `${keyName}_font_color`,
initial_value: defaults.fontColor,
...conditional_field,
});
if (isDefined(defaults.focusedFontColor)) {
fields.push({
type: ZAPPIFEST_FIELDS.color_picker,
label: `${label} focused font color`,
key: `${keyName}_focused_font_color`,
initial_value: defaults.focusedFontColor,
...conditional_field,
});
}
fields.push(
...[
{
type: ZAPPIFEST_FIELDS.number_input,
label: `TvOS ${label} font size`,
key: `${keyName}_tvos_font_size`,
initial_value: defaults.fontSizeTvOS,
...conditional_field,
},
{
type: ZAPPIFEST_FIELDS.number_input,
label: `Android ${label} font size`,
key: `${keyName}_android_font_size`,
initial_value: defaults.fontSizeAndroid,
...conditional_field,
},
{
type: ZAPPIFEST_FIELDS.number_input,
label: `Lg ${label} font size`,
key: `${keyName}_lg_font_size`,
initial_value: defaults.fontSizeLg,
...conditional_field,
},
{
type: ZAPPIFEST_FIELDS.number_input,
label: `Samsung ${label} font size`,
key: `${keyName}_samsung_font_size`,
initial_value: defaults.fontSizeSamsung,
...conditional_field,
},
{
type: ZAPPIFEST_FIELDS.font_selector.tvos,
label: `TvOS ${label} font family`,
key: `${keyName}_tvos_font_family`,
initial_value: defaults.fontFamilyTvOS,
...conditional_field,
},
{
type: ZAPPIFEST_FIELDS.font_selector.android,
label: `Android ${label} font family`,
key: `${keyName}_android_font_family`,
initial_value: defaults.fontFamilyAndroid,
...conditional_field,
},
{
type: ZAPPIFEST_FIELDS.font_selector.lg,
label: `Lg ${label} font family`,
key: `${keyName}_lg_font_family`,
initial_value: defaults.fontFamilyLg,
...conditional_field,
},
{
type: ZAPPIFEST_FIELDS.font_selector.samsung,
label: `Samsung ${label} font family`,
key: `${keyName}_samsung_font_family`,
initial_value: defaults.fontFamilySamsung,
...conditional_field,
},
{
type: ZAPPIFEST_FIELDS.number_input,
label: `TvOS ${label} line height`,
key: `${keyName}_tvos_line_height`,
initial_value: defaults.lineHeightTvOS,
...conditional_field,
},
{
type: ZAPPIFEST_FIELDS.number_input,
label: `Android ${label} line height`,
key: `${keyName}_android_line_height`,
initial_value: defaults.lineHeightAndroid,
...conditional_field,
},
{
type: ZAPPIFEST_FIELDS.number_input,
label: `Lg ${label} line height`,
key: `${keyName}_lg_line_height`,
initial_value: defaults.lineHeightLg,
...conditional_field,
},
{
type: ZAPPIFEST_FIELDS.number_input,
label: `Samsung ${label} line height`,
key: `${keyName}_samsung_line_height`,
initial_value: defaults.lineHeightSamsung,
...conditional_field,
},
{
type: ZAPPIFEST_FIELDS.number_input,
label: `TvOS ${label} letter spacing`,
key: `${keyName}_tvos_letter_spacing`,
initial_value: defaults.letterSpacingTvOS,
...conditional_field,
},
{
type: ZAPPIFEST_FIELDS.number_input,
label: `Android ${label} letter spacing`,
key: `${keyName}_android_letter_spacing`,
initial_value: defaults.letterSpacingAndroid,
...conditional_field,
},
{
type: ZAPPIFEST_FIELDS.number_input,
label: `Lg ${label} letter spacing`,
key: `${keyName}_lg_letter_spacing`,
initial_value: defaults.letterSpacingLg,
...conditional_field,
},
{
type: ZAPPIFEST_FIELDS.number_input,
label: `Samsung ${label} letter spacing`,
key: `${keyName}_samsung_letter_spacing`,
initial_value: defaults.letterSpacingSamsung,
...conditional_field,
},
{
type: ZAPPIFEST_FIELDS.select,
label: `${label} text transform`,
key: `${keyName}_text_transform`,
options: [
{
text: "Default",
value: "default",
},
{
text: "Uppercase",
value: "uppercase",
},
{
text: "Lowercase",
value: "lowercase",
},
{
text: "Capitalize",
value: "capitalize",
},
],
initial_value: defaults.textTransform,
...conditional_field,
},
]
);
if (isDefined(defaults.textAlignement)) {
fields.push({
type: ZAPPIFEST_FIELDS.select,
label: `${label} text alignment`,
key: `${keyName}_text_alignement`,
options: [
{ text: "center", value: "center" },
{ text: "left", value: "left" },
{ text: "right", value: "right" },
],
initial_value: defaults.textAlignement,
...conditional_field,
});
}
if (isDefined(defaults.numberOfLines)) {
fields.push({
type: ZAPPIFEST_FIELDS.number_input,
label: `${label} number of lines`,
key: `${keyName}_number_of_lines`,
initial_value: defaults.numberOfLines,
...conditional_field,
});
}
const spacingFields = spacingKey(label, defaults, conditional_field);
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,
...conditional_field,
});
}
if (isDefined(defaults.cornerRadius)) {
fields.push({
type: ZAPPIFEST_FIELDS.number_input,
label: `${label} corner radius`,
key: `${keyName}_corner_radius`,
initial_value: defaults.cornerRadius,
...conditional_field,
});
}
return fields;
}
module.exports = {
fontKey,
fontKeyTV,
};