-
Notifications
You must be signed in to change notification settings - Fork 112
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
RTL direction support via properties panel (revised) #1213
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 | ||
okaeiz marked this conversation as resolved.
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 | ||
okaeiz marked this conversation as resolved.
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 { 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', | ||
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. We have a css variable that defines fontFamily, so you can set it across the entire application rather easily (in general you'll find we don't use inline styles much, except for alignment). So if we're implementing it within the form-js, we should do it in one place only (somewhere in the form root). For now, because I still need to understand a little bit more about the font stuff, please just remove it. We'll get back to it when everything else is done. PS: the comments on this file apply across the board. 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. ✅ 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 removed the font; but I kindly ask you to reconsider this decision. The font makes no difference to English and the languages that have a similar alphabet to English. But in Persian, it is one of the main (if not the main) reasons why people decide not to use a software. If you take a look at Github, you'll find out that Github is also using Vazirmatn for its Persian strings. It is highly admired among open-source community. |
||
}}> | ||
<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.
✅