Skip to content

Commit

Permalink
fix(toggle-switch-entry): crop descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme committed Oct 2, 2020
1 parent 032c385 commit 9de27e8
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 22 deletions.
4 changes: 2 additions & 2 deletions lib/factory/EntryFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ EntryFactory.collapsible = function(options) {
return collapsible(options);
};

EntryFactory.toggleSwitch = function(options) {
return toggleSwitch(options, setDefaultParameters(options));
EntryFactory.toggleSwitch = function(translate, options) {
return toggleSwitch(translate, options, setDefaultParameters(options));
};

module.exports = EntryFactory;
13 changes: 8 additions & 5 deletions lib/factory/ToggleSwitchEntryFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ var getBusinessObject = require('bpmn-js/lib/util/ModelUtil').getBusinessObject,

var entryFieldDescription = require('./EntryFieldDescription');

var domify = require('min-dom').domify;

var toggleSwitch = function(options, defaultParameters) {
var toggleSwitch = function(translate, options, defaultParameters) {
var resource = defaultParameters,
id = resource.id,
label = options.label || id,
Expand All @@ -18,7 +19,9 @@ var toggleSwitch = function(options, defaultParameters) {
labelOn = options.labelOn,
labelOff = options.labelOff;

resource.html = '<label for="' + escapeHTML(id) + '" ' +
resource.html = document.createDocumentFragment();

resource.html.appendChild(domify('<label for="' + escapeHTML(id) + '" ' +
(canBeHidden ? 'data-show="shouldShow"' : '') +
'>' + escapeHTML(label) + '</label>' +
'<div class="bpp-field-wrapper"' +
Expand All @@ -36,14 +39,14 @@ var toggleSwitch = function(options, defaultParameters) {
'<p class="bpp-toggle-switch__label" data-show="isOff">' +
escapeHTML(labelOff) +
'</p>' +
'</div>';
'</div>'));

if (descriptionOn) {
resource.html += entryFieldDescription(descriptionOn, { show: 'isOn' });
resource.html.appendChild(entryFieldDescription(descriptionOn, translate, { show: 'isOn' }));
}

if (descriptionOff) {
resource.html += entryFieldDescription(descriptionOff, { show: 'isOff' });
resource.html.appendChild(entryFieldDescription(descriptionOff, translate, { show: 'isOff' }));
}

resource.get = function(element) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ module.exports = function(group, element, elementTemplates, bpmnFactory, transla
}

// (5) add parameter toggle
parameterEntries.splice(templateProperty.description ? 2 : 1, 0, entryFactory.toggleSwitch({
parameterEntries.splice(templateProperty.description ? 2 : 1, 0, entryFactory.toggleSwitch(translate, {
id: id + '-assignment-toggle',
label: translate('Local Variable Assignment'),
modelProperty: 'isActive',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ module.exports = function(group, element, elementTemplates, bpmnFactory, transla
}

// (3) add parameter toggle
parameterEntries.splice(templateProperty.description ? 2 : 1, 0, entryFactory.toggleSwitch({
parameterEntries.splice(templateProperty.description ? 2 : 1, 0, entryFactory.toggleSwitch(translate, {
id: id + '-assignment-toggle',
label: translate('Process Variable Assignment'),
modelProperty: 'isActive',
Expand Down
41 changes: 28 additions & 13 deletions test/spec/factory/ToggleSwitchEntryFactorySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('factory/ToggleSwitchEntry', function() {
it('should render', function() {

// when
var html = ToggleSwitchEntry({
var html = ToggleSwitchEntry(translate, {
id: 'foo',
label: 'label',
labelOff: 'off',
Expand All @@ -19,21 +19,36 @@ describe('factory/ToggleSwitchEntry', function() {
modelProperty: 'toggle'
}).html;

var foo = document.createElement('div');

foo.appendChild(html);

// then
expect(html).to.eql('<label for="foo" >label</label>' +
'<div class="bpp-field-wrapper">' +
'<label class="bpp-toggle-switch__switcher">' +
'<input id="foo" type="checkbox" name="toggle" />' +
'<span class="bpp-toggle-switch__slider"></span>' +
'</label>'+
'<p class="bpp-toggle-switch__label" data-show="isOn">on</p>' +
'<p class="bpp-toggle-switch__label" data-show="isOff">off</p>' +
'</div>' +
'<div class="bpp-field-description"data-show="isOn">this is on</div>' +
'<div class="bpp-field-description"data-show="isOff">this is off</div>');
expect(foo.innerHTML).to.eql(
'<label for="foo">label</label>' +
'<div class="bpp-field-wrapper">' +
'<label class="bpp-toggle-switch__switcher">' +
'<input id="foo" type="checkbox" name="toggle">' +
'<span class="bpp-toggle-switch__slider"></span>' +
'</label>'+
'<p class="bpp-toggle-switch__label" data-show="isOn">on</p>' +
'<p class="bpp-toggle-switch__label" data-show="isOff">off</p>' +
'</div>' +
'<div class="bpp-field-description description description--expanded" data-show="isOn">' +
'<span class="description__text">this is on</span>' +
'</div>' +
'<div class="bpp-field-description description description--expanded" data-show="isOff">' +
'<span class="description__text">this is off</span>' +
'</div>'
);
});

});

});
});

// helpers //////////

function translate(string) {
return string;
}

0 comments on commit 9de27e8

Please sign in to comment.