-
Notifications
You must be signed in to change notification settings - Fork 773
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copy bidi module from angular material cdk so there's not a new dependency.
- Loading branch information
1 parent
843a68d
commit 7699957
Showing
14 changed files
with
458 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/demo-app/app/docs-layout/layoutRowWithDirection.demo.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import {Component} from '@angular/core'; | ||
|
||
@Component({ | ||
moduleId: module.id, | ||
selector: 'demo-layout-row-direction', | ||
template: ` | ||
<mat-card class="card-demo"> | ||
<mat-card-title>Direction support for RTL</mat-card-title> | ||
<mat-card-subtitle> | ||
Simple row using layout gap and flex offset to demonstrate changes | ||
in layout direction between rtl and ltr. | ||
</mat-card-subtitle> | ||
<mat-card-content fxLayout="column" fxLayoutGap="8px"> | ||
<div> | ||
<button (click)="toggleDirection()" mat-raised-button> | ||
Toggle direction | ||
</button> | ||
</div> | ||
<div class="containerX"> | ||
<div fxLayout="row" class="colored box" fxLayoutGap="20px" | ||
[dir]="direction" fxFlex> | ||
<div fxFlexOffset="20px">item 1</div> | ||
<div>item 2</div> | ||
<div>item 3</div> | ||
</div> | ||
</div> | ||
</mat-card-content> | ||
<mat-card-footer> | ||
<div class="hint"> | ||
<div dir="{{ direction }}" fxLayoutGap="20px"> | ||
</div> | ||
</mat-card-footer> | ||
</mat-card> | ||
` | ||
}) | ||
export class DemoLayoutRowDirection { | ||
direction = 'ltr'; | ||
|
||
toggleDirection() { | ||
this.direction = this.direction === 'ltr' ? 'rtl' : 'ltr'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {NgModule} from '@angular/core'; | ||
import {DOCUMENT} from '@angular/common'; | ||
import {Dir} from './dir'; | ||
import {DIR_DOCUMENT, Directionality} from './directionality'; | ||
|
||
|
||
@NgModule({ | ||
exports: [Dir], | ||
declarations: [Dir], | ||
providers: [ | ||
{provide: DIR_DOCUMENT, useExisting: DOCUMENT}, | ||
Directionality, | ||
] | ||
}) | ||
export class BidiModule { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
The `bidi` package provides a common system for components to get and respond to change in the | ||
application's LTR/RTL layout direction. This directory was copied straight from | ||
https://github.com/angular/material2/blob/master/src/cdk/bidi/ | ||
|
||
### Directionality | ||
|
||
When including the CDK's `BidiModule`, components can inject `Directionality` to get the current | ||
text direction (RTL or LTR); | ||
|
||
#### Example | ||
```ts | ||
@Component({ ... }) | ||
export class MyWidget implements OnDestroy { | ||
|
||
/** Whether the widget is in RTL mode or not. */ | ||
private isRtl: boolean; | ||
|
||
/** Subscription to the Directionality change EventEmitter. */ | ||
private _dirChangeSubscription = Subscription.EMPTY; | ||
|
||
constructor(dir: Directionality) { | ||
this.isRtl = dir.value === 'rtl'; | ||
|
||
_dirChangeSubscription = dir.change.subscribe(() => { | ||
this.flipDirection(); | ||
}); | ||
} | ||
|
||
ngOnDestroy() { | ||
this._dirChangeSubscription.unsubscribe(); | ||
} | ||
} | ||
``` | ||
|
||
### The `Dir` directive | ||
The `BidiModule` also includes a directive that matches any elements with a `dir` attribute. This | ||
directive has the same API as Directionality and provides itself _as_ `Directionality`. By doing | ||
this, any component that injects `Directionality` will get the closest ancestor layout direction | ||
context. |
Oops, something went wrong.