Skip to content

Commit

Permalink
pkp/pkp-lib#9527 Same source of the truth for dir rtl/ltr
Browse files Browse the repository at this point in the history
  • Loading branch information
jardakotesovec committed Dec 19, 2023
1 parent 3246c77 commit e026f1b
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 16 deletions.
6 changes: 3 additions & 3 deletions .storybook/modes.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export const allModes = {
desktop: {
viewport: 'large',
theme: 'LTR',
theme: 'ltr',
},
'desktop RTL': {
'desktop rtl': {
viewport: 'large',
theme: 'RTL',
theme: 'rtl',
},
// for snapshotting scrollable areas with all content, like modals
desktopLargeHeight: {
Expand Down
23 changes: 15 additions & 8 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/** @type { import('@storybook/vue3').Preview } */

import {withThemeByDataAttribute} from '@storybook/addon-themes';

import {DirectionProvider} from '../DirectionProvider';
import {setup} from '@storybook/vue3';

import {addons, useParameter} from '@storybook/preview-api';
import {onUpdated, onMounted, ref, watch} from 'vue';
import GlobalMixins from '@/mixins/global.js';
import emitter from 'tiny-emitter/instance';

Expand Down Expand Up @@ -97,13 +98,19 @@ const preview = {
decorators: [
withThemeByDataAttribute({
themes: {
LTR: 'ltr',
RTL: 'RTL',
ltr: 'ltr',
rtl: 'rtl',
},
defaultTheme: 'LTR',
attributeName: 'dir',
parentSelector: 'body',
defaultTheme: 'ltr',
}),
(story, {globals}) => {
/** withThemebyDataAttribute decorator applies attribute after render, which
* is too late fort tinyMCE which needs to detect it on first render correctly
*
*/
document.body.setAttribute('dir', globals.theme);
return story();
},
(story) => ({
components: {story},
template: '<div style="padding: 10px;"><story /></div>',
Expand Down Expand Up @@ -162,7 +169,7 @@ const preview = {
chromatic: {
modes: {
desktop: allModes['desktop'],
'desktop RTL': allModes['desktop RTL'],
'desktop rtl': allModes['desktop rtl'],
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions src/components/Form/Form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -647,11 +647,11 @@ export default {
}
.pkpFormPage {
position: absolute;
left: -9999px;
display: none;
}
.pkpFormPage--current {
display: block;
position: relative;
left: auto;
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/Form/fields/FieldBaseAutosuggest.vue
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@ export default {
* Is this field in a right-to-left language
*/
isRTL() {
return $.pkp.app.rtlLocales.includes(this.localeKey);
var direction = document.body.getAttribute('dir');
return direction === 'rtl';
},
},
methods: {
Expand Down
3 changes: 2 additions & 1 deletion src/components/Form/fields/FieldRichTextarea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ export default {
* Is this field for language in a RTL language?
*/
isRTL() {
return $.pkp.app.rtlLocales.includes(this.localeKey);
const direction = document.body.getAttribute('dir');
return direction === 'rtl';
},
},
watch: {
Expand Down
6 changes: 5 additions & 1 deletion src/components/Form/fields/FieldText.vue
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export default {
*/
classes() {
let classes = ['pkpFormField--size' + this.size];
if ($.pkp.app.rtlLocales.includes(this.localeKey)) {
if (this.isRTL()) {
classes.push('pkpFormField--text--rtl');
}
return classes;
Expand Down Expand Up @@ -207,6 +207,10 @@ export default {
setFocus() {
this.$refs.input.focus();
},
isRTL() {
var direction = document.body.getAttribute('dir');
return direction === 'rtl';
},
},
};
</script>
Expand Down

0 comments on commit e026f1b

Please sign in to comment.