Skip to content

Commit 352541d

Browse files
authored
Merge branch 'master' into slider
2 parents ff6dbdb + 26a5948 commit 352541d

File tree

5 files changed

+46
-9
lines changed

5 files changed

+46
-9
lines changed

src/i18n/en.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@
123123
"BUTTON_ARIA_LEFT": "Go to the previous tab",
124124
"BUTTON_ARIA_RIGHT": "Go to the next tab"
125125
},
126+
"TOGGLE": {
127+
"OFF": "Off",
128+
"ON": "On"
129+
},
126130
"TOPNAV": {
127131
"SKIP_TO_MAIN": "Skip to main content",
128132
"HAMBURGER": {

src/table/table.component.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ import { I18n } from "./../i18n/i18n.module";
199199
<button
200200
class="bx--table-sort-v2"
201201
*ngIf="this.sort.observers.length > 0 && column.sortable"
202+
[attr.aria-label]="(column.sorted && column.ascending ? sortDescendingLabel : sortAscendingLabel)"
202203
[ngClass]="{
203204
'bx--table-sort-v2--active': column.sorted,
204205
'bx--table-sort-v2--ascending': column.ascending
@@ -210,10 +211,7 @@ import { I18n } from "./../i18n/i18n.module";
210211
</ng-template>
211212
<svg
212213
class="bx--table-sort-v2__icon"
213-
width="10" height="5" viewBox="0 0 10 5"
214-
[attr.aria-label]="(column.sorted && column.ascending ? sortDescendingLabel : sortAscendingLabel)"
215-
[attr.alt]="(column.sorted && column.ascending ? sortDescendingLabel : sortAscendingLabel)">
216-
<title>{{(column.sorted && column.ascending ? sortDescendingLabel : sortAscendingLabel)}}</title>
214+
width="10" height="5" viewBox="0 0 10 5">
217215
<path d="M0 0l5 4.998L10 0z" fill-rule="evenodd" />
218216
</svg>
219217
</button>

src/toggle/toggle.component.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ComponentFixture, TestBed, fakeAsync, tick, async } from "@angular/core
33
import { By } from "@angular/platform-browser";
44
import { StaticIconModule } from "../icon/static-icon.module";
55

6+
import { I18nModule } from "../i18n/i18n.module";
67
import { Toggle, ToggleChange } from "./toggle.component";
78

89
describe("Toggle", () => {
@@ -14,7 +15,7 @@ describe("Toggle", () => {
1415
beforeEach(() => {
1516
TestBed.configureTestingModule({
1617
declarations: [Toggle],
17-
imports: [BrowserAnimationsModule, StaticIconModule],
18+
imports: [BrowserAnimationsModule, StaticIconModule, I18nModule],
1819
providers: []
1920
});
2021

src/toggle/toggle.component.ts

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
} from "@angular/core";
99
import { NG_VALUE_ACCESSOR } from "@angular/forms";
1010

11+
import { I18n } from "../i18n/i18n.module";
1112

1213
/**
1314
* Defines the set of states for a toggle component.
@@ -76,9 +77,9 @@ export class ToggleChange {
7677
[ngClass]="{
7778
'bx--skeleton': skeleton
7879
}">
79-
<span class="bx--toggle__text--left">{{ !skeleton ? "Off" : null }}</span>
80+
<span class="bx--toggle__text--left">{{(!skeleton ? offText : null) | async }}</span>
8081
<span class="bx--toggle__appearance"></span>
81-
<span class="bx--toggle__text--right">{{ !skeleton ? "On" : null }}</span>
82+
<span class="bx--toggle__text--right">{{(!skeleton ? onText : null) | async}}</span>
8283
</label>
8384
8485
<label
@@ -112,6 +113,35 @@ export class Toggle extends Checkbox {
112113
*/
113114
static toggleCount = 0;
114115

116+
/**
117+
* Text that is set on the left side of the toggle.
118+
* @type {(string)}
119+
* @memberof Toggle
120+
*/
121+
@Input()
122+
set offText(value) {
123+
this._offText.next(value);
124+
}
125+
126+
get offText() {
127+
return this._offText;
128+
}
129+
130+
/**
131+
* Text that is set on the right side of the toggle.
132+
* @type {(string)}
133+
* @memberof Toggle
134+
*/
135+
@Input()
136+
set onText(value) {
137+
this._onText.next(value);
138+
}
139+
140+
get onText() {
141+
return this._onText;
142+
}
143+
144+
115145
/**
116146
* Size of the toggle component.
117147
* @type {("sm" | "md" | "default")}
@@ -138,12 +168,14 @@ export class Toggle extends Checkbox {
138168
*/
139169
@Output() change = new EventEmitter<ToggleChange>();
140170

171+
protected _offText = this.i18n.get("TOGGLE.OFF");
172+
protected _onText = this.i18n.get("TOGGLE.ON");
141173
/**
142174
* Creates an instance of Toggle.
143175
* @param {ChangeDetectorRef} changeDetectorRef
144176
* @memberof Toggle
145177
*/
146-
constructor(protected changeDetectorRef: ChangeDetectorRef) {
178+
constructor(protected changeDetectorRef: ChangeDetectorRef, protected i18n: I18n) {
147179
super(changeDetectorRef);
148180
Toggle.toggleCount++;
149181
}

src/toggle/toggle.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { FormsModule } from "@angular/forms";
44
import { CommonModule } from "@angular/common";
55

66
// imports
7+
import { I18nModule } from "../i18n/i18n.module";
78
import { Toggle } from "../toggle/toggle.component";
89

910
// exports
@@ -18,7 +19,8 @@ export { Toggle } from "../toggle/toggle.component";
1819
],
1920
imports: [
2021
CommonModule,
21-
FormsModule
22+
FormsModule,
23+
I18nModule
2224
]
2325
})
2426
export class ToggleModule { }

0 commit comments

Comments
 (0)