Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement spacer component #732

Merged
merged 3 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions packages/form-js-editor/assets/form-js-editor-base.css
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,10 @@
margin-right: 2px;
}

.fjs-editor-container .fjs-form-field-spacer {
min-height: 30px;
}

/**
* Custom Dragula Styles
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const labelsByType = {
number: 'NUMBER',
radio: 'RADIO',
select: 'SELECT',
spacer: 'SPACER',
taglist: 'TAGLIST',
text: 'TEXT VIEW',
textfield: 'TEXT FIELD',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { NumberFieldEntry, isNumberFieldEntryEdited } from '@bpmn-io/properties-panel';

import { get } from 'min-dash';
import { useService } from '../hooks';

export default function SpacerEntry(props) {
const {
editField,
field,
id
} = props;

const {
type
} = field;

if (type !== 'spacer') {
return [];
}

const entries = [];

entries.push({
id: id + '-height',
component: SpacerHeight,
isEdited: isNumberFieldEntryEdited,
editField,
field
});

return entries;
}

function SpacerHeight(props) {

const {
editField,
field,
id
} = props;

const debounce = useService('debounce');

const getValue = (e) => get(field, [ 'height' ]);

const setValue = (value, error) => {
if (error) {
return;
}

editField(field, [ 'height' ], value);
};

return NumberFieldEntry({
debounce,
label: 'Height',
element: field,
id,
getValue,
setValue,
validate: (value) => {
if (value === undefined || value === null) return;
if (value < 1) return 'Should be greater than zero.';
if (!Number.isInteger(value)) return 'Should be an integer.';
}
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export { default as KeyEntry } from './KeyEntry';
export { default as LabelEntry } from './LabelEntry';
export { default as ImageSourceEntry } from './ImageSourceEntry';
export { default as TextEntry } from './TextEntry';
export { default as SpacerEntry } from './SpacerEntry';
export { default as NumberEntries } from './NumberEntries';
export { default as NumberSerializationEntry } from './NumberSerializationEntry';
export { default as DateTimeEntry } from './DateTimeEntry';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
ReadonlyEntry,
SelectEntries,
TextEntry,
SpacerEntry,
NumberEntries,
DateTimeEntry
} from '../entries';
Expand All @@ -27,6 +28,7 @@ export default function GeneralGroup(field, editField, getService) {
...ActionEntry({ field, editField }),
...DateTimeEntry({ field, editField }),
...TextEntry({ field, editField, getService }),
...SpacerEntry({ field, editField }),
...NumberEntries({ field, editField }),
...ImageSourceEntry({ field, editField }),
...AltTextEntry({ field, editField }),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Spacer } from '@bpmn-io/form-js-viewer';
import { editorFormFieldClasses } from '../Util';
import { iconsByType } from '../icons';

const type = 'spacer';

export default function EditorSpacer(props) {
const { field } = props;
const { height = 50 } = field;
const SpacerIcon = iconsByType(type);

return (
<div class={ editorFormFieldClasses(type) } style={ { height } }>
<SpacerIcon viewBox="0 0 54 54" />
</div>
);
}

EditorSpacer.config = Spacer.config;
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import EditorText from './EditorText';
import EditorSpacer from './EditorSpacer';

export const editorFormFields = [
EditorText
EditorText,
EditorSpacer
];
12 changes: 6 additions & 6 deletions packages/form-js-editor/test/spec/FormEditor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('FormEditor', function() {
});

// then
expect(formEditor.get('formFieldRegistry').getAll()).to.have.length(16);
expect(formEditor.get('formFieldRegistry').getAll()).to.have.length(17);
Skaiir marked this conversation as resolved.
Show resolved Hide resolved
});


Expand Down Expand Up @@ -114,7 +114,7 @@ describe('FormEditor', function() {
});

// then
expect(formEditor.get('formFieldRegistry').getAll()).to.have.length(16);
expect(formEditor.get('formFieldRegistry').getAll()).to.have.length(17);
});


Expand All @@ -137,7 +137,7 @@ describe('FormEditor', function() {
container.querySelector('.fjs-container').classList.add('fjs-no-theme');

// then
expect(formEditor.get('formFieldRegistry').getAll()).to.have.length(16);
expect(formEditor.get('formFieldRegistry').getAll()).to.have.length(17);
});


Expand Down Expand Up @@ -192,7 +192,7 @@ describe('FormEditor', function() {
await formEditor.importSchema(schema);

// then
expect(formEditor.get('formFieldRegistry').getAll()).to.have.length(16);
expect(formEditor.get('formFieldRegistry').getAll()).to.have.length(17);
});


Expand Down Expand Up @@ -929,15 +929,15 @@ describe('FormEditor', function() {
// assume
const formFieldRegistry = formEditor.get('formFieldRegistry');

expect(formFieldRegistry.getAll()).to.have.length(16);
expect(formFieldRegistry.getAll()).to.have.length(17);

// when
startDragging(container);
moveDragging(container);
endDragging(container);

// then
expect(formFieldRegistry.getAll()).to.have.length(17);
expect(formFieldRegistry.getAll()).to.have.length(18);

const selection = formEditor.get('selection');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('palette', function() {
const result = createPalette({ container });

// then
expect(result.container.querySelectorAll('.fjs-palette-field')).to.have.length(12);
expect(result.container.querySelectorAll('.fjs-palette-field')).to.have.length(13);

expectEntries(result.container, PALETTE_ENTRIES);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2370,6 +2370,35 @@ describe('properties panel', function() {
});


describe('spacer', function() {

it('entries', function() {

// given
const field = schema.components.find(({ type }) => type === 'spacer');

const result = createPropertiesPanel({
container,
field
});

// then
expectGroups(result.container, [
'General',
'Condition',
'Layout',
'Custom properties'
]);

expectGroupEntries(result.container, 'General', [
'Height'
]);

});

});


describe('textfield', function() {

it('entries', function() {
Expand Down
5 changes: 5 additions & 0 deletions packages/form-js-editor/test/spec/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@
"alt": "The bpmn.io logo",
"type": "image"
},
{
"id": "Spacer_1",
"type": "spacer",
"height":60
},
{
"id": "Button_1",
"action": "submit",
Expand Down
4 changes: 2 additions & 2 deletions packages/form-js-editor/test/spec/import/Importer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('Importer', function() {
// then
expect(warnings).to.be.empty;

expect(formFieldRegistry.getAll()).to.have.length(16);
expect(formFieldRegistry.getAll()).to.have.length(17);
}));


Expand All @@ -40,7 +40,7 @@ describe('Importer', function() {
await formEditor.importSchema(schema);

// assume
expect(formFieldRegistry.getAll()).to.have.length(16);
expect(formFieldRegistry.getAll()).to.have.length(17);

// when
const result = await formEditor.importSchema(other);
Expand Down
7 changes: 7 additions & 0 deletions packages/form-js-viewer/assets/form-js-base.css
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,13 @@
margin: auto;
}

.fjs-container .fjs-form-field-spacer {
background-color: transparent;
display: flex;
align-items: center;
justify-content: center;
}

.fjs-container .fjs-input[type='text'],
.fjs-container .fjs-input[type='email'],
.fjs-container .fjs-input[type='tel'],
Expand Down
2 changes: 1 addition & 1 deletion packages/form-js-viewer/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export * from './render';
export * from './util';
export * from './features';

const schemaVersion = 9;
const schemaVersion = 10;

export {
Form,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { formFieldClasses } from '../Util';

const type = 'spacer';

export default function Spacer(props) {
const { field } = props;
const { height = 60 } = field;

return (
<div class={ formFieldClasses(type) } style={ { height: height } } />
);
}

Spacer.config = {
type,
keyed: false,
label: 'Spacer',
group: 'presentation',
create: (options = {}) => ({
height: 60,
...options
})
};
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions packages/form-js-viewer/src/render/components/icons/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ColumnsIcon from './Group.svg';
import NumberIcon from './Number.svg';
import RadioIcon from './Radio.svg';
import SelectIcon from './Select.svg';
import SpacerIcon from './Spacer.svg';
import TextIcon from './Text.svg';
import TextfieldIcon from './Textfield.svg';
import TextareaIcon from './Textarea.svg';
Expand All @@ -24,6 +25,7 @@ export const iconsByType = (type) => {
number: NumberIcon,
radio: RadioIcon,
select: SelectIcon,
spacer: SpacerIcon,
taglist: TaglistIcon,
text: TextIcon,
textfield: TextfieldIcon,
Expand Down
3 changes: 3 additions & 0 deletions packages/form-js-viewer/src/render/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Image from './form-fields/Image';
import Numberfield from './form-fields/Number';
import Radio from './form-fields/Radio';
import Select from './form-fields/Select';
import Spacer from './form-fields/Spacer';
import Taglist from './form-fields/Taglist';
import Text from './form-fields/Text';
import Textfield from './form-fields/Textfield';
Expand All @@ -24,6 +25,7 @@ export {
Numberfield,
Radio,
Select,
Spacer,
Taglist,
Text,
Textfield,
Expand All @@ -40,6 +42,7 @@ export const formFields = [
Datetime,
Radio,
Select,
Spacer,
Taglist,
Text,
Textfield,
Expand Down
Loading
Loading