Skip to content

Commit

Permalink
feat: added sticky function to controls container
Browse files Browse the repository at this point in the history
  • Loading branch information
markandrewkato authored and kevinchappell committed May 29, 2019
1 parent 49e84b2 commit b8ddfd3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
13 changes: 9 additions & 4 deletions src/js/components/controls/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ export class Controls {
* Methods to be called on initialization
* @param {Object} controlOptions
*/
init(controlOptions) {
init(controlOptions, sticky = false) {
this.applyOptions(controlOptions)
this.registerControls()
this.buildDOM()
this.buildDOM(sticky)
return this
}

Expand Down Expand Up @@ -265,7 +265,7 @@ export class Controls {
* Returns the markup for the form controls/fields
* @return {DOM}
*/
buildDOM() {
buildDOM(sticky) {
const _this = this
const groupedFields = this.groupElements()
const formActions = this.formActions()
Expand All @@ -276,8 +276,13 @@ export class Controls {
content: _this.panels.children,
})

let controlClass = 'formeo-controls'
if (sticky) {
controlClass += ' formeo-sticky'
}

const element = dom.create({
className: 'formeo-controls',
className: controlClass,
content: [groupsWrap, formActions],
})
const groups = element.getElementsByClassName('control-group')
Expand Down
1 change: 1 addition & 0 deletions src/js/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mi18n.addLanguage('en-US', EN_US)
export const defaults = {
get editor() {
return {
stickyControls: false,
allowEdit: true,
dataType: 'json',
debug: false,
Expand Down
2 changes: 1 addition & 1 deletion src/js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class FormeoEditor {
init() {
const _this = this
this.load(this.userFormData, _this.opts)
this.controls = Controls.init(_this.opts.controls)
this.controls = Controls.init(_this.opts.controls, _this.opts.stickyControls)
_this.formId = Components.get('id')
this.i18n = {
setLang: formeoLocale => {
Expand Down
6 changes: 6 additions & 0 deletions src/sass/components/_controls.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
width: 26%;
overflow: hidden;

&.formeo-sticky {
position: sticky;
top: 0;
align-self: flex-start;
}

&.pull-left {
.form-actions {
float: left;
Expand Down

0 comments on commit b8ddfd3

Please sign in to comment.