-
Notifications
You must be signed in to change notification settings - Fork 142
RTL direction support via properties panel (revised) #1213
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
base: develop
Are you sure you want to change the base?
Changes from 4 commits
9120642
6520e02
79d38e9
53980fa
569c889
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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'; | ||
|
||
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; | ||
const { setDirection } = useDirection(); // Get the context | ||
merrime-n marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
const debounce = useService('debounce'); | ||
|
||
const path = ['direction']; | ||
|
||
const getValue = () => { | ||
const value = get(field, path, 'ltr'); | ||
return value; | ||
}; | ||
|
||
const setValue = (value) => { | ||
setDirection(value); // Update context | ||
merrime-n marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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, | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,3 +39,5 @@ export { RowCountEntry } from './RowCountEntry'; | |
export { HeadersSourceSelectEntry } from './HeadersSourceSelectEntry'; | ||
export { ColumnsExpressionEntry } from './ColumnsExpressionEntry'; | ||
export { StaticColumnsSourceEntry } from './StaticColumnsSourceEntry'; | ||
export { DirectionEntry } from './DirectionEntry'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you're using If you're using another software to code I'm not sure if they have support for it but either way both have CLIs, so you can use the CLI to fix things up. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✅ |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,25 @@ | ||
import { formFieldClasses } from '../Util'; | ||
import { useSingleLineTemplateEvaluation } from '../../hooks'; | ||
import { useSingleLineTemplateEvaluation, useService } from '../../hooks'; | ||
|
||
const type = 'button'; | ||
|
||
export function Button(props) { | ||
const { disabled, onFocus, onBlur, field } = props; | ||
|
||
const { action = 'submit' } = field; | ||
|
||
const evaluatedLabel = useSingleLineTemplateEvaluation(field.label || '', { debug: true }); | ||
|
||
const form = useService('form'); | ||
const { schema } = form._getState(); | ||
|
||
const direction = schema?.direction || 'ltr'; // Fetch the direction value from the form schema | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think, you should try and go for a single |
||
|
||
return ( | ||
<div class={formFieldClasses(type)}> | ||
<div | ||
class={formFieldClasses(type)} | ||
style={{ | ||
direction: direction, | ||
fontFamily: 'Vazirmatn, sans-serif', | ||
|
||
}}> | ||
<button | ||
class="fjs-button" | ||
type={action} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue here is that you're directly referencing the file across packages. See
DateTimeConstraintsEntry
for an example of how you can reference the viewer library (you have to ensure it is exported from the viewer).What I would do is, in the properties-panel hooks file, add an export referencing the viewer package, and then in this file reference the hook with useService
import { useService, useDirection } from '../hooks';
Just to keep things clean.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅