Skip to content

Commit

Permalink
[TASK] refactor, add CTA fields (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmh authored Apr 11, 2024
1 parent 9bb819d commit 6da4454
Show file tree
Hide file tree
Showing 12 changed files with 269 additions and 220 deletions.
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import {
richtext,
url,
video,
embed
embed,
cta
} from './lib/content-tab-fields.js'

/**
Expand All @@ -50,7 +51,8 @@ const moduleFields = {
border,
textalignment,
video,
embed
embed,
cta
}
/**
* #### Theme fields entry point
Expand Down
25 changes: 24 additions & 1 deletion lib/content-tab-fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,27 @@ function embed (label, name, fields) {
return { ...contentOptions, ...otherOptions }
}

export { text, link, richtext, url, video, embed }
/**
* #### CTA fields allow the user to select a call-to-action from the HubSpot CTA tool.
* `only_content_tab`
*
* Some parameters have `default` values, `OMIT` such parameters if you don't want to override them.
* @example
* fi.cta('label', 'name', {...options if needed})
* @memberof Fields
* @param {string} label The text the content creator sees describing the field. May contain spaces.
* @param {string} name Field/HubL variable name, which you'll reference when incorporating the field and its values in the module or theme. `Cannot contain spaces or special characters!`
* @param {Object} [fields]
* @param {EDITOR_OPTIONS} [fields.editor_options] Editor options group.
* @param {DISPLAY_CONDITIONS} [fields.display_conditions] Display conditions group.
* @param {REPEATER_OPTIONS} [fields.repeater_options] Repeater options. Keep `occurrence` object empty to just enable a feature. `repeater_options: {occurrence: {}}`
* @param {REPEATER_OPTIONS_DEFAULT} [fields.repeater_options_default] Repeater options with predefined repeated fields and `default` values for each field.
* @returns {COMMON_FIELDS}
*/
function cta (label, name, fields) {
const contentOptions = {}
const otherOptions = initField(label, name, 'cta', fields)
return { ...contentOptions, ...otherOptions }
}

export { text, link, richtext, url, video, embed, cta }
4 changes: 2 additions & 2 deletions lib/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function image (label, name, fields) {
* @param {string} label The text the content creator sees describing the field. May contain spaces.
* @param {string} name Field/HubL variable name, which you'll reference when incorporating the field and its values in the module or theme. `Cannot contain spaces or special characters!`
* @param {Object} [fields]
* @param {'fontawesome-5.14.0'|'fontawesome-5.0.10'} [fields.icon_set='fontawesome-5.14.0'] `fontawesome-5.14.0` The FontAwesome icon set to use.
* @param {'fontawesome-5.14.0'|'fontawesome-5.0.10'|'fontawesome-6.4.2'} [fields.icon_set='fontawesome-6.4.2'] `fontawesome-6.4.2` The FontAwesome icon set to use.
* @param {Object} [fields.default] Defaout icon object --> It's generally a good idea to skip setting the `default` object, as it should be configured by the editor, not the developer
* @param {string} [fields.default.name] The name of the icon
* @param {string} [fields.default.unicode] The unicode of the icon
Expand All @@ -146,7 +146,7 @@ function image (label, name, fields) {
*/
function icon (label, name, fields) {
const contentOptions = {}
contentOptions.icon_set = fields?.icon_set ?? 'fontawesome-5.14.0'
contentOptions.icon_set = fields?.icon_set ?? 'fontawesome-6.4.2'
contentOptions.default = fields?.default ?? {}

const otherOptions = initField(label, name, 'icon', fields)
Expand Down
26 changes: 25 additions & 1 deletion lib/style-tab-fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,32 @@ function alignment (label, name, fields) {
* @param {string} name Field/HubL variable name, which you'll reference when incorporating the field and its values in the module or theme. `Cannot contain spaces or special characters!`
* @param {Object} [fields]
* @param {Object} [fields.limits] Sets the guidelines for min and max amount of spacing.
* @param {Object} [fields.limits.padding] Padding limits object
* @param {Object} [fields.limits.margin] Margin limits object
* @param {Object} [fields.limits.margin.top] Default top margin object
* @param {?number} [fields.limits.margin.top.min] min top margin value
* @param {?number} [fields.limits.margin.top.max] max top margin value
* @param {null|Array<'%'|'ch'|'em'|'ex'|'in'|'lh'|'pc'|'pt'|'px'|'Q'|'rem'|'vh'|'vmax'|'vmin'|'vw'>} [fields.limits.margin.top.units] top margin units
* @param {Object} [fields.limits.margin.bottom] Default bottom margin object
* @param {?number} [fields.limits.margin.bottom.min] min bottom margin value
* @param {?number} [fields.limits.margin.bottom.max] max bottom margin value
* @param {null|Array<'%'|'ch'|'em'|'ex'|'in'|'lh'|'pc'|'pt'|'px'|'Q'|'rem'|'vh'|'vmax'|'vmin'|'vw'>} [fields.limits.margin.bottom.units] top margin units
* @param {Object} [fields.limits.padding] Padding limits object
* @param {Object} [fields.limits.padding.top] Default top padding object
* @param {?number} [fields.limits.padding.top.min] min top padding value
* @param {?number} [fields.limits.padding.top.max] max top padding value
* @param {null|Array<'%'|'ch'|'em'|'ex'|'in'|'lh'|'pc'|'pt'|'px'|'Q'|'rem'|'vh'|'vmax'|'vmin'|'vw'>} [fields.limits.padding.top.units] top padding units
* @param {Object} [fields.limits.padding.bottom] Default top padding object
* @param {?number} [fields.limits.padding.bottom.min] min top padding value
* @param {?number} [fields.limits.padding.bottom.max] max top padding value
* @param {null|Array<'%'|'ch'|'em'|'ex'|'in'|'lh'|'pc'|'pt'|'px'|'Q'|'rem'|'vh'|'vmax'|'vmin'|'vw'>} [fields.limits.padding.bottom.units] top padding units
* @param {Object} [fields.limits.padding.left] Default top padding object
* @param {?number} [fields.limits.padding.left.min] min top padding value
* @param {?number} [fields.limits.padding.left.max] max top padding value
* @param {null|Array<'%'|'ch'|'em'|'ex'|'in'|'lh'|'pc'|'pt'|'px'|'Q'|'rem'|'vh'|'vmax'|'vmin'|'vw'>} [fields.limits.padding.left.units] top padding units
* @param {Object} [fields.limits.padding.right] Default top padding object
* @param {?number} [fields.limits.padding.right.min] min top padding value
* @param {?number} [fields.limits.padding.right.max] max top padding value
* @param {null|Array<'%'|'ch'|'em'|'ex'|'in'|'lh'|'pc'|'pt'|'px'|'Q'|'rem'|'vh'|'vmax'|'vmin'|'vw'>} [fields.limits.padding.right.units] top padding units
* @param {Object} [fields.default] Default spacing object --> It's generally a good idea to skip setting the `default` object, as it should be configured by the editor, not the developer
* @param {Object} [fields.default.margin] Default margin object
* @param {Object} [fields.default.margin.top] Default top margin object
Expand Down
2 changes: 1 addition & 1 deletion lib/types/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @property {string} [help_text] Text that displays in the editor within a tooltip on hover to assist the content creator (limit 300 characters). Best used for information that is supplementary but not required to use the field. You can include the following HTML tags (other tags will be ignored on render): a, b, br, em, i, p, small, strong, span.
* @property {string} [inline_help_text] Text that displays inline below field's label (limit 400 characters). Best used for information required to use the field. You can include the following HTML tags (other tags will be ignored on render): a, b, br, em, i, p, small, strong, span.
* @property {null|'half_width'} [display_width=full_width] `full_width` By default, fields are full-width in the editor.
* @property {Object} [inherited_value]
* @property {?Object} [inherited_value]
* @property {INHERITED_VALUES} [inherited_value.property_value_paths]
*/

Expand Down
2 changes: 1 addition & 1 deletion lib/utils/common-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function EditorOptions (fields) {
if ('inline_help_text' in fields) {
this.inline_help_text = fields.inline_help_text
}
this.inherited_value = fields?.inherited_value ?? {}
this.inherited_value = fields?.inherited_value ?? null
return this
}

Expand Down
24 changes: 12 additions & 12 deletions test/1content-js-simple.module/fields.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"display_width": null,
"required": false,
"locked": false,
"inherited_value": {}
"inherited_value": null
},
{
"multiple": false,
Expand All @@ -32,7 +32,7 @@
"display_width": null,
"required": false,
"locked": false,
"inherited_value": {}
"inherited_value": null
},
{
"default": {
Expand All @@ -46,7 +46,7 @@
"display_width": null,
"required": false,
"locked": false,
"inherited_value": {}
"inherited_value": null
},
{
"load_external_fonts": true,
Expand All @@ -58,10 +58,10 @@
"display_width": null,
"required": false,
"locked": false,
"inherited_value": {}
"inherited_value": null
},
{
"icon_set": "fontawesome-5.14.0",
"icon_set": "fontawesome-6.4.2",
"default": {},
"id": "",
"name": "icon_field",
Expand All @@ -70,7 +70,7 @@
"display_width": null,
"required": false,
"locked": false,
"inherited_value": {}
"inherited_value": null
},
{
"responsive": true,
Expand All @@ -89,7 +89,7 @@
"display_width": null,
"required": false,
"locked": false,
"inherited_value": {}
"inherited_value": null
},
{
"show_advanced_rel_options": false,
Expand Down Expand Up @@ -119,7 +119,7 @@
"display_width": null,
"required": false,
"locked": false,
"inherited_value": {}
"inherited_value": null
},
{
"display": "text",
Expand All @@ -131,7 +131,7 @@
"display_width": null,
"required": false,
"locked": false,
"inherited_value": {}
"inherited_value": null
},
{
"id": "",
Expand All @@ -141,7 +141,7 @@
"display_width": null,
"required": false,
"locked": false,
"inherited_value": {}
"inherited_value": null
},
{
"allow_new_line": false,
Expand All @@ -154,7 +154,7 @@
"display_width": null,
"required": false,
"locked": false,
"inherited_value": {}
"inherited_value": null
},
{
"supported_types": [
Expand All @@ -179,6 +179,6 @@
"display_width": null,
"required": false,
"locked": false,
"inherited_value": {}
"inherited_value": null
}
]
24 changes: 12 additions & 12 deletions test/1content-js.module/fields.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"required": true,
"locked": false,
"help_text": "tooltip",
"inherited_value": {}
"inherited_value": null
},
{
"multiple": false,
Expand All @@ -35,7 +35,7 @@
"required": false,
"locked": true,
"inline_help_text": "Inline",
"inherited_value": {}
"inherited_value": null
},
{
"show_opacity": false,
Expand All @@ -50,7 +50,7 @@
"display_width": null,
"required": false,
"locked": false,
"inherited_value": {},
"inherited_value": null,
"visibility": {
"controlling_field_path": "boolean_field",
"operator": "EQUAL",
Expand All @@ -75,10 +75,10 @@
"display_width": null,
"required": false,
"locked": false,
"inherited_value": {}
"inherited_value": null
},
{
"icon_set": "fontawesome-5.14.0",
"icon_set": "fontawesome-6.4.2",
"default": {},
"id": "",
"name": "icon_field",
Expand All @@ -87,7 +87,7 @@
"display_width": null,
"required": false,
"locked": false,
"inherited_value": {}
"inherited_value": null
},
{
"responsive": true,
Expand All @@ -106,7 +106,7 @@
"display_width": null,
"required": false,
"locked": false,
"inherited_value": {},
"inherited_value": null,
"occurrence": {
"max": 10,
"min": null
Expand Down Expand Up @@ -140,7 +140,7 @@
"display_width": null,
"required": true,
"locked": false,
"inherited_value": {},
"inherited_value": null,
"occurrence": {
"min": null,
"max": null
Expand All @@ -158,7 +158,7 @@
"display_width": null,
"required": false,
"locked": false,
"inherited_value": {},
"inherited_value": null,
"occurrence": {
"min": 2,
"default": 4,
Expand All @@ -175,7 +175,7 @@
"display_width": null,
"required": false,
"locked": false,
"inherited_value": {}
"inherited_value": null
},
{
"allow_new_line": false,
Expand All @@ -196,7 +196,7 @@
"display_width": null,
"required": false,
"locked": false,
"inherited_value": {},
"inherited_value": null,
"occurrence": {
"default": 5,
"min": null,
Expand Down Expand Up @@ -226,6 +226,6 @@
"display_width": null,
"required": false,
"locked": false,
"inherited_value": {}
"inherited_value": null
}
]
8 changes: 4 additions & 4 deletions test/1contentgroup-js-simple.module/fields.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"display_width": null,
"required": false,
"locked": false,
"inherited_value": {}
"inherited_value": null
},
{
"type": "group",
Expand All @@ -35,20 +35,20 @@
"display_width": null,
"required": false,
"locked": false,
"inherited_value": {}
"inherited_value": null
}
],
"expanded": false,
"display_width": null,
"required": false,
"locked": false,
"inherited_value": {}
"inherited_value": null
}
],
"expanded": false,
"display_width": null,
"required": false,
"locked": false,
"inherited_value": {}
"inherited_value": null
}
]
Loading

0 comments on commit 6da4454

Please sign in to comment.