-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
feat: rtl support #343
feat: rtl support #343
Conversation
@@ -47,7 +47,7 @@ export class NbSidebarFooterComponent { | |||
/** | |||
* Layout sidebar component. | |||
* | |||
* Sidebar can be place on the left or the right side of the layout, can be fixed (shown above the content) | |||
* Sidebar can be place on the start or the end side of the layout, can be fixed (shown above the content) |
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.
start/end side of the layout - this sounds strange...
@@ -63,10 +63,10 @@ export class NbSidebarFooterComponent { | |||
* </nb-sidebar> | |||
* ``` | |||
* | |||
* @example Example of fixed sidebar located on the left side, initially collapsed. | |||
* @example Example of fixed sidebar located on the start side, initially collapsed. |
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.
start/end side of the layout - this sounds strange...
import { InjectionToken, Optional, Inject, Injectable } from '@angular/core'; | ||
import { NbDocument } from '../theme.options'; | ||
|
||
export type Direction = 'ltr' | 'rtl'; |
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.
Let's call it as NbDirection
|
||
export type Direction = 'ltr' | 'rtl'; | ||
|
||
export const LAYOUT_DIRECTION = new InjectionToken<Direction>('Flow direction'); |
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.
NB_LAYOUT_DIRECTION
src/framework/theme/theme.module.ts
Outdated
@@ -55,7 +56,8 @@ export class NbThemeModule { | |||
*/ | |||
static forRoot(nbThemeOptions: NbThemeOptions, | |||
nbJSThemes?: NbJSThemeOptions[], | |||
nbMediaBreakpoints?: NbMediaBreakpoint[]): ModuleWithProviders { | |||
nbMediaBreakpoints?: NbMediaBreakpoint[], | |||
layoutDirection?: Direction): ModuleWithProviders { |
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.
should we pass it as part of nbThemeOptions
?
@Tibing please review the popover changes. The changes are intended to RTL support. |
private document: NbDocument, | ||
@Optional() @Inject(NB_LAYOUT_DIRECTION) private dir = NbLayoutDirection.LTR, | ||
) { | ||
this.dir = dir; |
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.
Do we really have to call this variable dir? I know that it called dir in Document but it completely unclear to me. When I see dir I think about directory 😄
* Returns current layout direction. | ||
* @returns NbLayoutDirection. | ||
* */ | ||
getDirection(): NbLayoutDirection { |
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.
Also, if we call direction like dir, why do we call getter like getDirection instead of getDir?
* Maps logical position to physical according to current layout direction. | ||
* */ | ||
private get physicalPlacement(): NbPopoverPlacement { | ||
const { isLtr } = this.layoutDirectionService; |
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.
Maybe we can write
const isLtr = this.layoutDirectionService();
?
This syntax is great but it's really not obvious why we destructuring service and I have to check the service implementation to find out what's going on.
@@ -287,7 +295,7 @@ export class NbPopoverDirective implements OnInit, OnDestroy { | |||
/* | |||
* Set container position. | |||
* */ | |||
private patchPopoverPosition({ top: top, left: left }) { | |||
private patchPopoverPosition({ top, left }) { |
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.
Do we really need this changes? 😸
/* | ||
* Maps logical position to physical according to current layout direction. | ||
* */ | ||
private get physicalPlacement(): NbPopoverPlacement { |
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.
I think it's quite complicated solution for rtl support. Maybe we can add START and END in NbPopoverPlacement instead of creating separate enum. And then extend NbPositioningHelper with calculators which can choose between left and right calculators based on the NbLayoutDirectionService.
I think it'll simply and will require fewer changes.
What do you think about this solution?
@@ -43,15 +43,15 @@ import { NbWindow, NbDocument } from '../../theme.options'; | |||
}) | |||
export class NbLayoutColumnComponent { | |||
|
|||
@HostBinding('class.left') leftValue: boolean; | |||
@HostBinding('class.start') startValue: boolean; |
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.
Could you please also update comment above this component?
@@ -121,8 +121,8 @@ export class NbSidebarComponent implements OnInit, OnDestroy { | |||
private alive = true; | |||
|
|||
@HostBinding('class.fixed') fixedValue: boolean = false; | |||
@HostBinding('class.right') rightValue: boolean = false; | |||
@HostBinding('class.left') leftValue: boolean = true; | |||
@HostBinding('class.start') startValue: boolean = true; |
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.
What should I do If I want to have the sidebar on the left side all the time? I completely agree this is a rare situation but how will I solve it?
It's not possible to use @Inject with type. See angular/angular#15640
BREAKING CHANGE: change physical left, right properties to logical start, end respectively
'unset' value isn't supported by IE11
In rtl layout, popover positioned outside of viewport if 'left' set to 'auto'. In such case, content could shrink, so we'll calculate position based on dimentions, that would differ from those, that we'll have when it rendered inside a viewport. With 'left' equals to '0' popover should always feet viewport and dimentions will not change. Details: https://www.w3.org/TR/CSS2/visuren.html#propdef-left https://www.w3.org/TR/CSS2/visudet.html#abs-non-replaced-width
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.
let's add a checklist item to DEV_DOCS
To be able use rtl mixins in nebular and ngx-admin in .component.scss and .theme.scss. We cann't nest multiple host selectors due to big amount of bugs.
…into feature/rtl-support
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.
let's add a test to ensure that dir=ltr is set
…into feature/rtl-support
docs/articles/rtl.md
Outdated
@@ -0,0 +1,53 @@ | |||
All Nebular components were updated to support RTL out of the box. |
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.
All Nebular components support RTL out of the box.
docs/articles/rtl.md
Outdated
@@ -0,0 +1,53 @@ | |||
All Nebular components were updated to support RTL out of the box. | |||
|
|||
Now every component, that previously could be positioned via some setting, besides old `left` and `right` options, also support logical `start` and `end` properties, similar to flexbox. Value of `start` and `end` depends on current layout direction. For LTR it's left, for RTL - right. |
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 components that accept a position as a setting now also support logical start
and end
values, similar to flexbox. Value of start
and end
depends on current layout direction. For LTR it's left and for RTL - right.
For instance, if we need the sidebar to be positioned logically depending on a language direction, then instead of setting it to left
we can set its position to start
:
<nb-sidebar start></nb-sidebar>
Document direction could be set through the NbThemeModule.forRoot
call. Supported values are 'ltr' and 'rtl'.
docs/articles/rtl.md
Outdated
<div class="note note-info"> | ||
<div class="note-title">Note</div> | ||
<div class="note-body"> | ||
1. Works only in layout component |
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.
Components must be placed inside of the <nb-layoyt></nb-layout>
component to correctly support language direction.
docs/articles/rtl.md
Outdated
<div class="note note-info"> | ||
<div class="note-title">Note</div> | ||
<div class="note-body"> | ||
1. Listen only to changes made through service itself |
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.
we probably don't need this note
docs/articles/rtl.md
Outdated
<div class="note note-info"> | ||
<div class="note-title">Note</div> | ||
<div class="note-body"> | ||
One thing to note, mixins should be called only inside of `:host` mixin or `nb-install-component`. |
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.
Please note, the mixins are only available within component :host
selector or nb-install-component()
mixin if used.
Please read and mark the following check list before creating a pull request:
Short description of what this resolves: