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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
f0a461a
feat(rtl): add rtl properties mixins
yggg Mar 30, 2018
08dcdfa
feat(rlt): support in actions component
yggg Mar 30, 2018
9e083db
feat(rtl): support on flip card
yggg Mar 30, 2018
1f151ea
feat(rtl): add direction service
yggg Apr 2, 2018
aa0a26e
style(checkbox-component): fix typo
yggg Apr 2, 2018
18d955f
feat(rtl): checkbox support
yggg Apr 2, 2018
f26549b
feat(rtl): add rtl only mixin
yggg Apr 2, 2018
bc1702f
feat(rlt): add support in context-menu
yggg Apr 2, 2018
e515c32
style(contenxt-menu): change import
yggg Apr 2, 2018
dfba68d
feat(rtl): badge support
yggg Apr 2, 2018
11f00f9
fix(direction-service): remove type from constructor parameter
yggg Apr 2, 2018
4a8df51
feat(rtl): add styles for search close button
yggg Apr 2, 2018
f1708d8
refactor(badge): add host pseudo class to isolate styles
yggg Apr 2, 2018
6e94e91
feat(rtl): add rtl styles for user component
yggg Apr 2, 2018
d941631
feat(user-component): align text right for rtl layout
yggg Apr 3, 2018
63e0b33
feat(rtl): add sidebar rtl styles
yggg Apr 3, 2018
e011923
feat(rtl): align menu item text to right in rtl layout
yggg Apr 3, 2018
d9c05b8
feat(rtl): add mirroring styles for sidebar
yggg Apr 3, 2018
723873a
refactor(rtl): use 'auto' to reset position properties
yggg Apr 4, 2018
3aa1897
fix(popover): set initial top, left position
yggg Apr 4, 2018
14091f5
style: prefix public variables with 'Nb'
yggg Apr 4, 2018
c2f6138
style: simplify provider entry
yggg Apr 5, 2018
29a8243
style: rename service, use enum instead of type
yggg Apr 5, 2018
3a202da
feat(layout-direction-service): add helper properties
yggg Apr 5, 2018
2493320
refactor(layout-direction-service): create property in constructor
yggg Apr 5, 2018
90179fa
feat(rtl): add start, end options for popover component
yggg Apr 5, 2018
5b7928f
refactor(badge): revert badge api changes
yggg Apr 5, 2018
5382901
refactor(badge): revert badge api changes
yggg Apr 5, 2018
e69f44d
feat(rtl): add logical position properties for badge component
yggg Apr 5, 2018
f9a5848
style: use destructuring assignment
yggg Apr 5, 2018
b241f00
refactor(lauout-column): change column position property to logical
yggg Apr 5, 2018
1186ac6
docs(direction-service): add service documentation
yggg Apr 5, 2018
0538330
style(direction-service): add types, remove unnecessary cast
yggg Apr 5, 2018
5786eca
feat(docs): include directions service docs entry
yggg Apr 5, 2018
6b337a7
feat(rtl): mirror horizontal paddings for menu items
yggg Apr 5, 2018
5506186
style(direction-service): rename dir to direction
yggg Apr 6, 2018
ba88751
refactor(direction-service): change helpers to be methods
yggg Apr 6, 2018
db87aad
feat(rtl): add position helper for popover component
yggg Apr 6, 2018
3d788bb
refactorting(sidebar): add physical position properties back
yggg Apr 6, 2018
a147db6
refactor(layout-column): add physical position properties back
yggg Apr 6, 2018
b8999d6
refactoring(direction-service): set rtl attribute on body
yggg Apr 6, 2018
d1a709c
feat(rtl): add posibility to prefix :host-context selector
yggg Apr 6, 2018
4bb74dd
style: use single quotes
yggg Apr 6, 2018
bc478ec
refactor(rtl): mirror ohrizontl margins for menu icons
yggg Apr 6, 2018
daad88e
fix: resolve merge conflict
yggg Apr 9, 2018
7005da1
fix(layout): update e2e tests to match new flex order
yggg Apr 9, 2018
5bf7d82
style(badge): remove unsused import
yggg Apr 11, 2018
33a1ab2
feat(layout): align text right in rtl
yggg Apr 11, 2018
c06f59f
refactor(rtl): add ability to append selector to dir attr
yggg Apr 11, 2018
634cf91
feat(rtl): mirror padding on form control description
yggg Apr 11, 2018
993f990
Merge branch 'master' into feature/rtl-support
nnixaa Apr 12, 2018
25b5ef6
feat(rtl): context menu add padding mirroring for icons
yggg Apr 12, 2018
8a32536
feat(rtl): mirror blockquotes
yggg Apr 12, 2018
9607103
feat(rtl): mirror lists padding
yggg Apr 12, 2018
b196c18
feat(rtl): move close toast button to the right
yggg Apr 12, 2018
c0b14a4
feat(rtl): mirror sort icons position in smart table
yggg Apr 12, 2018
6be5394
feat(rtl): mirror smart table pager styles
yggg Apr 12, 2018
2524167
feat(rtl): mirror buttons with icons styles
yggg Apr 12, 2018
5f2e323
feat(rtl): mirror form text styles
yggg Apr 12, 2018
e5696eb
feat(rtl): mirror btn divided group styles
yggg Apr 12, 2018
6b03613
fix(rtl): add missing ltr only mixin
yggg Apr 12, 2018
8a908b5
feat(rtl): add dropdown mirrored styles
yggg Apr 12, 2018
ff2856b
style(overrides): remove nonexistent in bootstrap class
yggg Apr 12, 2018
c288556
feat(dropdown): align dropdown menu automatically
yggg Apr 12, 2018
c444551
feat(rtl): add input, button groups rtl styles
yggg Apr 12, 2018
15d0ff2
feat(rtl): add rtl toggle component into test app
yggg Apr 12, 2018
5ea5863
refactor(rtl-mixins): remove append flag
yggg Apr 13, 2018
9739bb4
feat(rtl): reverse header elements in rtl
yggg Apr 13, 2018
da7040c
feat(rtl): mirror controls on toasts
yggg Apr 13, 2018
4cada3f
fix(rtl): keep border radius on single inputs
yggg Apr 13, 2018
ad98a2d
style: update layout direction service description
yggg Apr 13, 2018
5ad47ec
feat(rtl): mirror horizontal and vertical menu items padding
yggg Apr 13, 2018
7095eed
refactor(rtl): decrease menu item padding
yggg Apr 13, 2018
9151f9a
feat(rtl): decrease menu item margin
yggg Apr 13, 2018
51215b3
Merge branch 'master' into feature/rtl-support
nnixaa Apr 19, 2018
789449a
refactor(rtl-mixins): simplify rtl mixins
yggg Apr 20, 2018
6bb6b13
refactor(theming): use :host instead of :host-context
yggg Apr 20, 2018
521b2f1
style: remove unused parameter
yggg Apr 25, 2018
9ee3b24
refactor: rewrite in one-line selector and add comments
yggg Apr 25, 2018
45e52ab
refactor(direction-service): set dir attribute on document
yggg Apr 25, 2018
260bd7d
Merge branch 'feature/rtl-support' of https://github.com/yggg/nebular…
yggg Apr 25, 2018
29a80a0
test(layout-component): add direction setting test
yggg Apr 25, 2018
b2afe4d
Merge branch 'master' into feature/rtl-support
nnixaa Apr 25, 2018
7ad6bc9
Merge branch 'master' into feature/rtl-support
nnixaa Apr 26, 2018
f67ac5c
Merge branch 'master' into feature/rtl-support
nnixaa Apr 26, 2018
b92c056
docs(rtl): add bidi support entry in dev docs
yggg Apr 28, 2018
386c627
style: add bidirectionality implemetation longread
yggg Apr 28, 2018
b5b29eb
Merge branch 'feature/rtl-support' of https://github.com/yggg/nebular…
yggg Apr 28, 2018
c997398
docs(rtl): add rtl system overview
yggg May 7, 2018
22699ff
docs(direction-service): update onDirectionChange description
yggg May 7, 2018
213fb58
docs(rtl): merge rtl and direction service pages in one
yggg May 7, 2018
2ee07de
docs(rtl): remove temporary notes
yggg May 7, 2018
01a86dc
docs(rtl): fix direction service docs
yggg May 7, 2018
243a7b6
docs(rtl): use code snippets syntax
yggg May 7, 2018
c476b78
style: fix typo
yggg May 8, 2018
78c0487
docs(rtl): remove duplicate service entry
yggg May 8, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DEV_DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- for the override styles - registered in a list of overrides
- component *.theme registered in a list of component themes
- looks great on all default themes
- supports bidirectionality
- requires approval from several core team contributors

# Objectives
Expand Down
48 changes: 48 additions & 0 deletions docs/articles/rtl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
All Nebular components support RTL out of the box.

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:

```html
<nb-sidebar start></nb-sidebar>
```

Document direction could be set through the `NbThemeModule.forRoot` call. Supported values are `ltr` and `rtl`.

```typescript
@NgModule({
imports: [
NbThemeModule.forRoot(nbThemeOptions, nbJSThemes, nbMediaBreakpoints, 'rtl')
]
})
```
Default value is `ltr`.

<div class="note note-info">
<div class="note-title">Note</div>
<div class="note-body">
Components must be placed inside of the `<nb-layout></nb-layout>` component to correctly support language direction.
</div>
</div>

To help you add RTL support to your custom components, Nebular provides you with two scss mixins: `nb-lrt` and `nb-rtl`. You can use them to alter values of css properties, which don't support logical values, like paddings, margins, etc. You can pass single property and value as arguments, pass multiple statements as a content of mixin or both. For example:
```scss
:host {
nb-ltr(padding-left, 1em);
nb-rtl(padding-right, 1em);
}
```
```scss
:host {
nb-ltr() {
padding-left: 1em;
};
nb-rtl() {
padding-right: 1em;
};
}
```

Please note, the mixins are only available within component `:host` selector or `nb-install-component()` mixin if used.

If you need to change direction dynamically, get current value or listen to changes of direction, Nebular provides `NbLayoutDirectionService`.
22 changes: 22 additions & 0 deletions docs/structure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -637,4 +637,26 @@ export const STRUCTURE = [
},
],
},
{
type: 'section',
name: 'Usability',
children: [
{
type: 'page',
name: 'Right-to-left (RTL)',
children: [
{
type: 'block',
block: 'markdown',
source: 'rtl.md',
},
{
type: 'block',
block: 'component',
source: 'NbLayoutDirectionService',
},
],
},
],
},
];
18 changes: 12 additions & 6 deletions e2e/layout.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('nb-layout', () => {
});
});

it('should render left with order: 1', () => {
it('should render left with order: 0', () => {
element
.all(
by.css(`#layout-fluid >
Expand All @@ -54,7 +54,7 @@ describe('nb-layout', () => {
.get(0)
.getCssValue('order')
.then(value => {
expect(value).toMatch('1');
expect(value).toMatch('0');
});
});

Expand All @@ -71,7 +71,7 @@ describe('nb-layout', () => {
});
});

it('should render center with order: 2', () => {
it('should render center with order: 1', () => {
element
.all(
by.css(`#layout-fluid >
Expand All @@ -80,7 +80,7 @@ describe('nb-layout', () => {
.get(1)
.getCssValue('order')
.then(value => {
expect(value).toMatch('2');
expect(value).toMatch('1');
});
});

Expand All @@ -97,7 +97,7 @@ describe('nb-layout', () => {
});
});

it('should render right with order: 2', () => {
it('should render right with order: 1', () => {
element
.all(
by.css(`#layout-fluid >
Expand All @@ -106,7 +106,7 @@ describe('nb-layout', () => {
.get(2)
.getCssValue('order')
.then(value => {
expect(value).toMatch('2');
expect(value).toMatch('1');
});
});

Expand Down Expand Up @@ -155,4 +155,10 @@ describe('nb-layout', () => {
})
});
});

it('should set default document direction', () => {
browser.executeScript('return document.dir').then(function (direction) {
expect(direction).toBe('ltr');
});
});
});
5 changes: 4 additions & 1 deletion src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import 'style-loader!./app.themes.scss';

@Component({
selector: 'nb-app-root',
template: `<router-outlet></router-outlet>`,
template: `
<nb-layout-direction-toggle></nb-layout-direction-toggle>
<router-outlet></router-outlet>
`,
})
export class NbAppComponent {
}
2 changes: 2 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ import { AuthGuard } from './auth-guard.service';
import { RoleProvider } from './role.provider';
import { NbDynamicToAddComponent } from './dynamic.component';
import { NbPlaygroundModule } from '../playground/playground.module';
import { NbLayoutDirectionToggleComponent } from './layout-direction-toggle/layout-direction-toggle.component';

const NB_TEST_COMPONENTS = [
NbAppComponent,
Expand Down Expand Up @@ -226,6 +227,7 @@ const NB_TEST_COMPONENTS = [
],
declarations: [
...NB_TEST_COMPONENTS,
NbLayoutDirectionToggleComponent,
],
entryComponents: [
NbDynamicToAddComponent,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
:host {
display: block;
padding: 0.5em;

label {
margin: 0;
}

span {
vertical-align: middle;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Component } from '@angular/core';
import { NbLayoutDirectionService, NbLayoutDirection } from '@nebular/theme';

@Component({
selector: 'nb-layout-direction-toggle',
styleUrls: [ './layout-direction-toggle.component.scss' ],
template: `
<label dir="ltr">
<input type="checkbox" value="isRtl" (click)="toggleFlow()" />
<span>RTL</span>
</label>
`,
})
export class NbLayoutDirectionToggleComponent {
constructor(private directionService: NbLayoutDirectionService) {}

get isRtl() {
return this.directionService.isRtl();
}

toggleFlow() {
const oppositeDirection = this.isRtl
? NbLayoutDirection.LTR
: NbLayoutDirection.RTL;
this.directionService.setDirection(oppositeDirection);
}
}
11 changes: 11 additions & 0 deletions src/app/user-test/user-test.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ import { NbBadgeComponent } from 'framework/theme/components/badge/badge.compone
<nb-user
[picture]="'data:image/png;base64,aaa'"></nb-user>
</div>
<div class="test-row">
<nb-user inverse
size="large"
picture="https://lorempixel.com/400/200/animals/"
name="Dmitry Nehaychik"
title="Worker"
badgeText="29"
[badgeStatus]="badge.STATUS_DANGER"
[badgePosition]="badge.TOP_START">
</nb-user>
</div>
</nb-layout-column>
</nb-layout>
`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
height: nb-theme(actions-size-small);
padding: 0 nb-theme(actions-padding);

&:first-child {
@include nb-ltr(border-left, none!important);
@include nb-rtl(border-right, none!important);
}

a.icon-container {
&:hover, &:focus {
text-decoration: none;
Expand All @@ -25,7 +30,10 @@
color: nb-theme(actions-fg);
font-size: nb-theme(actions-size-small);
}
border-left: 1px solid nb-theme(actions-separator);

@include nb-ltr(border-left, 1px solid nb-theme(actions-separator));
@include nb-rtl(border-right, 1px solid nb-theme(actions-separator));

background: transparent;
}

Expand All @@ -34,7 +42,9 @@
i.control-icon {
color: nb-theme(actions-bg);
}
border-left: 1px solid nb-theme(actions-separator);

@include nb-ltr(border-left, 1px solid nb-theme(actions-separator));
@include nb-rtl(border-right, 1px solid nb-theme(actions-separator));
}
}

Expand Down
4 changes: 0 additions & 4 deletions src/framework/theme/components/actions/actions.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
align-items: center;
position: relative;

&:first-child {
border-left: none!important;
}

i.control-icon {
&:hover {
cursor: pointer;
Expand Down
3 changes: 2 additions & 1 deletion src/framework/theme/components/actions/actions.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ export class NbActionComponent {
/**
* Badge position.
* Can be set to any class or to one of predefined positions:
* 'top left', 'top right', 'bottom left', 'bottom right'
* 'top left', 'top right', 'bottom left', 'bottom right',
* 'top start', 'top end', 'bottom start', 'bottom end'
* @type string
*/
@Input() badgePosition: string;
Expand Down
2 changes: 1 addition & 1 deletion src/framework/theme/components/badge/badge.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*/

.nb-badge {
:host .nb-badge {
position: absolute;
padding: 0.25em 0.4em;
font-size: 75%;
Expand Down
31 changes: 24 additions & 7 deletions src/framework/theme/components/badge/badge.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import { Component, Input } from '@angular/core';
import { NbLayoutDirectionService } from '../../services/direction.service';

/**
* Badge is a simple labeling component.
Expand Down Expand Up @@ -51,13 +52,17 @@ export class NbBadgeComponent {
static readonly BOTTOM_LEFT = 'bottom left';
static readonly BOTTOM_RIGHT = 'bottom right';

static readonly TOP_START = 'top start';
static readonly TOP_END = 'top end';
static readonly BOTTOM_START = 'bottom start';
static readonly BOTTOM_END = 'bottom end';

static readonly STATUS_PRIMARY = 'primary';
static readonly STATUS_INFO = 'info';
static readonly STATUS_SUCCESS = 'success';
static readonly STATUS_WARNING = 'warning';
static readonly STATUS_DANGER = 'danger';

positionClass: string = NbBadgeComponent.TOP_RIGHT;
colorClass: string = NbBadgeComponent.STATUS_PRIMARY;

/**
Expand All @@ -70,14 +75,11 @@ export class NbBadgeComponent {
* Badge position
*
* Can be set to any class or to one of predefined positions:
* 'top left', 'top right', 'bottom left', 'bottom right'
* 'top left', 'top right', 'bottom left', 'bottom right',
* 'top start', 'top end', 'bottom start', 'bottom end'
* @type string
*/
@Input() set position(value) {
if (value) {
this.positionClass = value;
}
}
@Input() position: string;

/**
* Badge status (adds specific styles):
Expand All @@ -90,4 +92,19 @@ export class NbBadgeComponent {
this.colorClass = value;
}
}

get positionClass() {
if (!this.position) {
return NbBadgeComponent.TOP_RIGHT;
}

const isLtr = this.layoutDirectionService.isLtr();
const startValue = isLtr ? 'left' : 'right';
const endValue = isLtr ? 'right' : 'left';
return this.position
.replace(/\bstart\b/, startValue)
.replace(/\bend\b/, endValue);
}

constructor(private layoutDirectionService: NbLayoutDirectionService) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@
margin-bottom: nb-theme(card-margin);
padding: nb-theme(card-padding);
}

.flipcard-body .front-container {
@include nb-ltr(margin-right, -100%);
@include nb-rtl(margin-left, -100%);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@
}
}

.front-container {
margin-right: -100%;
}

.back-container {
transform: rotateY(180deg);
}
Expand Down
Loading