Skip to content
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

Merged
merged 96 commits into from
May 8, 2018
Merged

feat: rtl support #343

merged 96 commits into from
May 8, 2018

Conversation

yggg
Copy link
Contributor

@yggg yggg commented Apr 3, 2018

Please read and mark the following check list before creating a pull request:

Short description of what this resolves:

@yggg yggg self-assigned this Apr 3, 2018
@yggg yggg requested a review from nnixaa April 3, 2018 07:42
@@ -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)
Copy link
Collaborator

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.
Copy link
Collaborator

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';
Copy link
Collaborator

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');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NB_LAYOUT_DIRECTION

@@ -55,7 +56,8 @@ export class NbThemeModule {
*/
static forRoot(nbThemeOptions: NbThemeOptions,
nbJSThemes?: NbJSThemeOptions[],
nbMediaBreakpoints?: NbMediaBreakpoint[]): ModuleWithProviders {
nbMediaBreakpoints?: NbMediaBreakpoint[],
layoutDirection?: Direction): ModuleWithProviders {
Copy link
Collaborator

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?

@nnixaa nnixaa added the WIP label Apr 5, 2018
@nnixaa nnixaa requested a review from Tibing April 5, 2018 20:22
@nnixaa
Copy link
Collaborator

nnixaa commented Apr 5, 2018

@Tibing please review the popover changes. The changes are intended to RTL support.

Tibing
Tibing previously requested changes Apr 5, 2018
private document: NbDocument,
@Optional() @Inject(NB_LAYOUT_DIRECTION) private dir = NbLayoutDirection.LTR,
) {
this.dir = dir;
Copy link
Member

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 {
Copy link
Member

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;
Copy link
Member

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 }) {
Copy link
Member

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 {
Copy link
Member

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;
Copy link
Member

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;
Copy link
Member

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?

yggg added 23 commits April 9, 2018 12:46
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
Copy link
Collaborator

@nnixaa nnixaa left a 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

Copy link
Collaborator

@nnixaa nnixaa left a 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

@@ -0,0 +1,53 @@
All Nebular components were updated to support RTL out of the box.
Copy link
Collaborator

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.

@@ -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.
Copy link
Collaborator

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'.

<div class="note note-info">
<div class="note-title">Note</div>
<div class="note-body">
1. Works only in layout component
Copy link
Collaborator

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.

<div class="note note-info">
<div class="note-title">Note</div>
<div class="note-body">
1. Listen only to changes made through service itself
Copy link
Collaborator

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

<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`.
Copy link
Collaborator

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.

nnixaa
nnixaa previously approved these changes May 8, 2018
@nnixaa nnixaa merged commit 0326c1c into akveo:master May 8, 2018
@yggg yggg removed the WIP label May 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants