Skip to content

Commit

Permalink
New: Add block horizontal alignment option (fixes adaptlearning#393)
Browse files Browse the repository at this point in the history
  • Loading branch information
swashbuck authored Mar 6, 2023
1 parent e4409e9 commit 501adcb
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
3 changes: 2 additions & 1 deletion example.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@
"_isDividerBlock": false,
"_paddingTop": "",
"_paddingBottom": "",
"_componentVerticalAlignment": ""
"_componentVerticalAlignment": "",
"_componentHorizontalAlignment": ""
}

// components.json
Expand Down
7 changes: 7 additions & 0 deletions js/themeBlockView.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default class ThemeBlockView extends ThemeView {
this.setPaddingTop();
this.setPaddingBottom();
this.setComponentVerticalAlignment();
this.setComponentHorizontalAlignment();
}

setPaddingTop() {
Expand All @@ -30,6 +31,12 @@ export default class ThemeBlockView extends ThemeView {
this.$el.addClass(`align-vert-${componentVerticalAlignment}`);
}

setComponentHorizontalAlignment() {
const componentHorizontalAlignment = this.model.get('_componentHorizontalAlignment');
if (!componentHorizontalAlignment) return;
this.$el.addClass(`align-horz-${componentHorizontalAlignment}`);
}

onRemove() {}

}
6 changes: 6 additions & 0 deletions less/core/block.less
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,10 @@

// Aligns child components to the bottom of the parent block on the vertical axis
&.align-vert-bottom .component__container {align-items: flex-end; }

// Aligns child components centrally on the horizontal axis
&.align-horz-center .component__container { justify-content: center; }

// Aligns child components to the right of the parent block on the horizontal axis
&.align-horz-right .component__container { justify-content: flex-end; }
}
8 changes: 8 additions & 0 deletions properties.schema
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,14 @@
"inputType": {"type":"Select", "options":["top","center","bottom"]},
"title": "Set the vertical alignment of the child component(s)",
"help": "Defines the vertical alignment of the child component(s) in relation to the block. Top: Aligns descendents to the top of the block. Center: Aligns descendents to the center of the block. Bottom: Aligns descendents to the bottom of the block. The default alignment is `top`."
},
"_componentHorizontalAlignment": {
"type": "string",
"required": false,
"default": "left",
"inputType": {"type":"Select", "options":["left","center","right"]},
"title": "Set the horizontal alignment of the child component(s)",
"help": "Defines the horizontal alignment of the child component(s) in relation to the block. The default alignment is `left`."
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions schema/block.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,18 @@
"bottom"
],
"_backboneForms": "Select"
},
"_componentHorizontalAlignment": {
"type": "string",
"title": "Set the horizontal alignment of the child component(s)",
"description": "Defines the horizontal alignment of the child component(s) in relation to the block. The default alignment is `left`.",
"default": "left",
"enum": [
"left",
"center",
"right"
],
"_backboneForms": "Select"
}
}
}
Expand Down

0 comments on commit 501adcb

Please sign in to comment.