forked from bpmn-io/form-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added DirectionEntry to the AppearanceGroup
- Loading branch information
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
packages/form-js-editor/src/features/properties-panel/entries/DirectionEntry.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 GitHub Actions / Build (macos-latest, 20)
|
||
|
||
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 GitHub Actions / Build (macos-latest, 20)
|
||
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
11
packages/form-js-viewer/src/render/context/DirectionContext.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 GitHub Actions / Build (macos-latest, 20)
|
||
|
||
export const DirectionContext = createContext({ | ||
direction: 'ltr', | ||
setDirection: (direction) => {}, | ||
}); | ||
|
||
export function useDirection() { | ||
return useContext(DirectionContext); | ||
} |