how to swap between RTL and LTR SCSS file
when I use LTR I should use part of SCSS and when I use RTL I should use different part of SCSS
in style.angular.scss using LTR
// Angular vendors
@import "~socicon/css/socicon.css";
@import "~@fortawesome/fontawesome-free/css/all.min.css";
@import "~line-awesome/dist/line-awesome/css/line-awesome.css";
@import "~prism-themes/themes/prism-shades-of-purple.css";
@import "~bootstrap-icons/font/bootstrap-icons.css";
@import "~animate.css/animate.css";
@import "./core/vendors/plugins/prismjs";
@import "./core/vendors/plugins/formvalidation";
in style.angular.scss using RTL without last two row from LTR the default
// Angular vendors
@import "~socicon/css/socicon.css";
@import "~@fortawesome/fontawesome-free/css/all.min.css";
@import "~line-awesome/dist/line-awesome/css/line-awesome.css";
@import "~prism-themes/themes/prism-shades-of-purple.css";
@import "~bootstrap-icons/font/bootstrap-icons.css";
@import "~animate.css/animate.css";
//@import "./core/vendors/plugins/prismjs";
//@import "./core/vendors/plugins/formvalidation";
and the same things in styles.scss file in RTL should i use last two rows and in the opposite way should i use different imports !
/* You can add global styles to this file, and also import other style files */
/*@import "./assets/sass/style.scss";*/
// Replace above style with this css file to enable RTL styles
// @import './assets/sass/plugins.scss';
@import "./assets/css/style.rtl.css";
@import "./assets/sass/style.angular.scss";
So how to reflect between this SCSS changes when i do change on the direction ??
Hi,
Currently, Angular does not provide built-in support for dynamically changing the CSS file based on the direction (LTR or RTL). In the provided styles.scss file, the LTR and RTL CSS files are included as hardcoded imports.
To handle dynamic direction changes, you would need to implement a custom solution. One possible approach is to create separate CSS files for LTR and RTL styles, and then conditionally load the appropriate file based on the direction.
Here's an example of how you can achieve this:
1. Create two separate SCSS files: style.ltr.scss
and style.rtl.scss
. Place the specific styles for each direction in their respective files.
2. In your component or application, define a class variable to keep track of the current direction. For example:
direction: string = "ltr"; // Default direction is LTR
<!-- Replace the default style import with conditional imports -->
<ng-container [ngSwitch]="direction">
<ng-container *ngSwitchCase=""ltr"">
<!-- Load LTR styles -->
<link rel="stylesheet" href="./assets/css/style.ltr.css">
<link rel="stylesheet" href="./assets/sass/style.angular.scss">
</ng-container>
<ng-container *ngSwitchCase=""rtl"">
<!-- Load RTL styles -->
<link rel="stylesheet" href="./assets/css/style.rtl.css">
<link rel="stylesheet" href="./assets/sass/style.angular.scss">
</ng-container>
</ng-container>
direction
variable based on user input or application logic. For example:toggleDirection() {
this.direction = this.direction === "ltr" ? "rtl" : "ltr";
}
direction
variable is changed to `'ltr'`, the LTR styles will be loaded, and when it is changed to `'rtl'`, the RTL styles will be loaded. The corresponding SCSS files will be applied accordingly.styles.scss
file, including style.angular.scss
, which contains the common styles for both directions.