Skip to content

Commit

Permalink
feat: implemented separator form field
Browse files Browse the repository at this point in the history
Closes #480
  • Loading branch information
Skaiir committed Oct 16, 2023
1 parent 6506118 commit bf81fbc
Show file tree
Hide file tree
Showing 13 changed files with 138 additions and 7 deletions.
9 changes: 9 additions & 0 deletions packages/form-js-carbon-styles/test/spec/complex.json
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,15 @@
"suffixAdorner": "suffix"
}
},
{
"type": "separator",
"id": "Field_1a82jj4sdsd"
},
{
"type": "spacer",
"height": 30,
"id": "Field_1a82jjsdasd"
},
{
"action": "reset",
"label": "reset",
Expand Down
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 @@ -710,6 +710,10 @@
background: repeating-linear-gradient( 45deg, #ffffff, #ffffff 10px, #f5f5f5 10px, #f5f5f5 20px);
}

.fjs-editor-container .fjs-form-field-separator hr {
margin: 10px 2px;
}

/**
* Custom Dragula Styles
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const labelsByType = {
number: 'NUMBER',
radio: 'RADIO',
select: 'SELECT',
separator: 'SEPARATOR',
spacer: 'SPACER',
taglist: 'TAGLIST',
text: 'TEXT VIEW',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export default function GeneralGroup(field, editField, getService) {
...ReadonlyEntry({ field, editField })
];

if (entries.length === 0) {
return null;
}

return {
id: 'general',
label: 'General',
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(14);
expect(result.container.querySelectorAll('.fjs-palette-field')).to.have.length(PALETTE_ENTRIES.length);

expectEntries(result.container, PALETTE_ENTRIES);
});
Expand All @@ -56,7 +56,7 @@ describe('palette', function() {
const result = createPalette({ container });

// then
expect(result.container.querySelectorAll('.fjs-palette-group')).to.have.length(4);
expect(result.container.querySelectorAll('.fjs-palette-group')).to.have.length(PALETTE_GROUPS.length);

expectGroups(result.container, PALETTE_GROUPS);
});
Expand Down
3 changes: 3 additions & 0 deletions packages/form-js-playground/test/spec/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
"label": "Checkbox",
"key": "isGood"
},
{
"type": "separator"
},
{
"type": "select",
"label": "Select me",
Expand Down
9 changes: 9 additions & 0 deletions packages/form-js-viewer/assets/form-js-base.css
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,15 @@
justify-content: center;
}

.fjs-container hr {
border: none;
border-top: solid 2px var(--color-borders-group);
}

.fjs-container .fjs-form-field-separator hr {
margin: 7px 2px;
}

.fjs-container .fjs-input[type='text'],
.fjs-container .fjs-input[type='email'],
.fjs-container .fjs-input[type='tel'],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { formFieldClasses } from '../Util';

const type = 'separator';

export default function Separator() {

return (
<div class={ formFieldClasses(type) }>
<hr />
</div>
);
}

Separator.config = {
type,
keyed: false,
label: 'Separator',
group: 'presentation',
create: (options = {}) => ({
...options
})
};
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions packages/form-js-viewer/src/render/components/icons/Spacer.svg
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 SeparatorIcon from './Separator.svg';
import SpacerIcon from './Spacer.svg';
import TextIcon from './Text.svg';
import TextfieldIcon from './Textfield.svg';
Expand All @@ -27,6 +28,7 @@ export const iconsByType = (type) => {
number: NumberIcon,
radio: RadioIcon,
select: SelectIcon,
separator: SeparatorIcon,
spacer: SpacerIcon,
taglist: TaglistIcon,
text: TextIcon,
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 @@ -10,6 +10,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 Separator from './form-fields/Separator';
import Spacer from './form-fields/Spacer';
import Taglist from './form-fields/Taglist';
import Text from './form-fields/Text';
Expand All @@ -29,6 +30,7 @@ export {
Numberfield,
Radio,
Select,
Separator,
Spacer,
Taglist,
Text,
Expand All @@ -48,6 +50,7 @@ export const formFields = [
Radio,
Select,
Spacer,
Separator,
Taglist,
Text,
Textfield,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { render } from '@testing-library/preact/pure';

import Separator from '../../../../../src/render/components/form-fields/Separator';

import {
createFormContainer
} from '../../../../TestHelper';

import { WithFormContext } from './helper';

let container;


describe('Separator', function() {

beforeEach(function() {
container = createFormContainer();
});

afterEach(function() {
container.remove();
});

it('should render', function() {

// when
const { container } = createSeparator();

// then
const formField = container.querySelector('.fjs-form-field');

expect(formField).to.exist;
expect(formField.classList.contains('fjs-form-field-separator')).to.be.true;

const separator = formField.querySelector('hr');
expect(separator).to.exist;

});

});

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

const defaultField = {
type: 'separator'
};

function createSeparator(options = {}) {
const {
data = {},
initialData = {},
properties = {},
field = defaultField
} = options;

return render(WithFormContext(
<Separator field={ field }
/>,
{
...options,
properties,
initialData,
data
}
),
{
container: options.container || container.querySelector('.fjs-form')
});
}

0 comments on commit bf81fbc

Please sign in to comment.