Skip to content

Commit

Permalink
Added DirectionEntry to the AppearanceGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
okaeiz committed Jun 18, 2024
1 parent 6520e02 commit 79d38e9
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { get } from 'min-dash';
import { useService } from '../hooks';
import { SelectEntry, isSelectEntryEdited } from '@bpmn-io/properties-panel';
import { useDirection } from '../../../../../form-js-viewer/src/render/context/DirectionContext';

Check failure on line 4 in packages/form-js-editor/src/features/properties-panel/entries/DirectionEntry.js

View workflow job for this annotation

GitHub Actions / Build (macos-latest, 20)

Unexpected path "../../../../../form-js-viewer/src/render/context/DirectionContext" imported in restricted zone

Check failure on line 4 in packages/form-js-editor/src/features/properties-panel/entries/DirectionEntry.js

View workflow job for this annotation

GitHub Actions / Build (ubuntu-20.04, 20)

Unexpected path "../../../../../form-js-viewer/src/render/context/DirectionContext" imported in restricted zone

export function DirectionEntry(props) {
const { editField, field } = props;

const entries = [
{
id: 'direction',
component: Direction,
editField,
field,
isEdited: isSelectEntryEdited,
isDefaultVisible: (field) => field.type === 'default',
},
];

return entries;
}

function Direction(props) {
const { editField, field, id } = props;

Check failure on line 24 in packages/form-js-editor/src/features/properties-panel/entries/DirectionEntry.js

View workflow job for this annotation

GitHub Actions / Build (macos-latest, 20)

'id' is assigned a value but never used. Allowed unused vars must match /^_/u

Check failure on line 24 in packages/form-js-editor/src/features/properties-panel/entries/DirectionEntry.js

View workflow job for this annotation

GitHub Actions / Build (ubuntu-20.04, 20)

'id' is assigned a value but never used. Allowed unused vars must match /^_/u
const { setDirection } = useDirection(); // Get the context

const debounce = useService('debounce');

const path = ['direction'];

const getValue = () => {
const value = get(field, path, 'ltr');
return value;
};

const setValue = (value) => {
setDirection(value); // Update context
return editField(field, path, value || 'ltr');
};

const getOptions = () => [
{
label: 'Left to Right',
value: 'ltr',
},
{
label: 'Right to Left',
value: 'rtl',
},
];

return SelectEntry({
debounce,
element: field,
getValue,
id: 'direction',
label: 'Direction',
setValue,
getOptions,
});
}
11 changes: 11 additions & 0 deletions packages/form-js-viewer/src/render/context/DirectionContext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { createContext } from 'preact';
import { useState, useContext } from 'preact/hooks';

Check failure on line 2 in packages/form-js-viewer/src/render/context/DirectionContext.js

View workflow job for this annotation

GitHub Actions / Build (macos-latest, 20)

'useState' is defined but never used. Allowed unused vars must match /^_/u

Check failure on line 2 in packages/form-js-viewer/src/render/context/DirectionContext.js

View workflow job for this annotation

GitHub Actions / Build (ubuntu-20.04, 20)

'useState' is defined but never used. Allowed unused vars must match /^_/u

export const DirectionContext = createContext({
direction: 'ltr',
setDirection: (direction) => {},
});

export function useDirection() {
return useContext(DirectionContext);
}

0 comments on commit 79d38e9

Please sign in to comment.