Skip to content

Commit

Permalink
feat(module: actionsheet): feat support locale (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
Guoyuanqiang authored and fisherspy committed Jan 9, 2019
1 parent 5a3ba5d commit 39870da
Show file tree
Hide file tree
Showing 17 changed files with 70 additions and 20 deletions.
1 change: 1 addition & 0 deletions components/action-sheet/action-sheet-options.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class ShareOption {
export class ShareActionSheetWithOptions extends ActionSheetOptions {
options: ShareOption[] | ShareOption[][];
cancelButtonText?: string = 'Cancel';
locale?;
}

@Injectable()
Expand Down
27 changes: 23 additions & 4 deletions components/action-sheet/action-sheet.component.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
import { Component, TemplateRef, ViewEncapsulation, HostListener } from '@angular/core';

import { Component, TemplateRef, ViewEncapsulation, HostListener, OnInit } from '@angular/core';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { LocaleProviderService } from '../locale-provider/locale-provider.service';
@Component({
selector: 'ActionSheet',
templateUrl: './action-sheet.component.html',
encapsulation: ViewEncapsulation.None
})
export class ActionSheetComponent {
export class ActionSheetComponent implements OnInit {
unsubscribe$ = new Subject<void>();
option: any;
constructor() {}
constructor(private localeProviderService: LocaleProviderService) {}

ngOnInit() {
this.localeProvider();
}

localeProvider() {
const self = this;
if (self.option.locale || self.option.locale !== undefined) {
self.localeProviderService.setLocale(self.option.locale);
}
self.localeProviderService.localeChange.pipe(takeUntil(self.unsubscribe$)).subscribe(_ => {
if (self.option.cancelButtonText) {
self.option.cancelButtonText = self.localeProviderService.getLocaleSubObj('ActionSheet')['dismissText'];
}
});
}

onPress(index: any, rowIndex = 0, event) {}
showShare(option) {
Expand Down
4 changes: 2 additions & 2 deletions components/action-sheet/action-sheet.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { NgZorroAntdMobilePipesModule } from '../pipes/ng-zorro-antd-mobile.pipe
import { ActionSheetComponent } from './action-sheet.component';
import { WingBlankModule } from '../wing-blank/wing-blank.module';
import { WhiteSpaceModule} from '../white-space/white-space.module';

import { LocaleProviderModule } from '../locale-provider/locale-provider.module';
@NgModule({
imports: [CommonModule, NgZorroAntdMobilePipesModule, ListModule, WhiteSpaceModule, WingBlankModule, CoreModule],
imports: [CommonModule, NgZorroAntdMobilePipesModule, ListModule, WhiteSpaceModule, WingBlankModule, CoreModule, LocaleProviderModule],
declarations: [
ActionSheetComponent
],
Expand Down
3 changes: 2 additions & 1 deletion components/action-sheet/action-sheet.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export class ActionSheet extends PopupService {
'className',
'transitionName',
'maskTransitionName',
'options'
'options',
'locale'
];
config = Object.assign(options, config, {
close: (): void => {
Expand Down
14 changes: 8 additions & 6 deletions components/action-sheet/demo/basic.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component } from '@angular/core';
import { ActionSheet, Toast } from 'ng-zorro-antd-mobile';

import { en_US, ru_RU, zh_CN, sv_SE, da_DK } from 'ng-zorro-antd-mobile';
@Component({
selector: 'demo-action-sheet-basic',
template: `
Expand Down Expand Up @@ -47,13 +47,14 @@ export class DemoActionSheetBasicComponent {
console.log(buttonIndex);
}
);
};
}

showShareActionSheet = () => {
ActionSheet.showShareActionSheetWithOptions(
{
options: this.dataList,
message: 'I am description, description, description'
message: 'I am description, description, description',
locale: zh_CN
},
buttonIndex => {
return new Promise(resolve => {
Expand All @@ -62,18 +63,19 @@ export class DemoActionSheetBasicComponent {
});
}
);
};
}

showShareActionSheetMulpitleLine = () => {
const data = [[...this.dataList, this.dataList[2]], [this.dataList[3], this.dataList[4]]];
ActionSheet.showShareActionSheetWithOptions(
{
options: data,
message: 'I am description, description, description'
message: 'I am description, description, description',
locale: en_US
},
(buttonIndex, rowIndex) => {
console.log(buttonIndex);
}
);
};
}
}
3 changes: 2 additions & 1 deletion components/action-sheet/doc/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ Display shareable action sheet. The `options` object must contain one or more of

- options (array of `{icon: TemplateRef | innerHTML, title: string}`) - a list of share buttons (required)
- It can be a two-dimensional array, can display multi-line buttons, e.g. `[[{icon,title},...],...]` means two rows and two columns. In this case there are two parameters on `callback`, the first for the `column` sequence, the second for the `line`.
- cancelButtonText (string) - the text of cancel button, default `取消`
- cancelButtonText (string) - the text of cancel button, default `Cancel`
- title (string) - a title to show above the action sheet
- message (string/React.element) - a message to show below the title
- maskClosable (bool) - Whether it's allowed to close when you click the mask (default true)
- locale - international, can override the configuration of the global `[LocaleProvider](https://ng.mobile.ant.design/components/locale-provider/en)` | Object: { dismissText}

The `callback` function support returns Promise

Expand Down
3 changes: 2 additions & 1 deletion components/action-sheet/doc/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ subtitle: 动作面板
- title (string) - 顶部标题
- message (string/React.element) - 顶部标题下的简要消息
- maskClosable (bool) - 点击蒙层是否允许关闭,默认允许
- locale - 国际化,可覆盖全局`[LocaleProvider](https://ng.mobile.ant.design/components/locale-provider/zh)`的配置 | Object: { dismissText }

`callback`函数支持返回 Promise
- `callback`函数支持返回 Promise

#### static showShareActionSheetWithOptions(options: Object, failureCallback: Function, successCallback: Function)

Expand Down
3 changes: 3 additions & 0 deletions components/action-sheet/locale/da_DK.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
dismissText: 'Annuller'
};
3 changes: 3 additions & 0 deletions components/action-sheet/locale/en_US.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
dismissText: 'Cancel'
};
3 changes: 3 additions & 0 deletions components/action-sheet/locale/ru_RU.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
dismissText: 'Отмена'
};
3 changes: 3 additions & 0 deletions components/action-sheet/locale/sv_SE.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
dismissText: 'Avbryt'
};
3 changes: 3 additions & 0 deletions components/action-sheet/locale/zh_CN.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
dismissText: '取消'
};
4 changes: 3 additions & 1 deletion components/locale-provider/languages/da_DK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import SearchBar from '../../search-bar/locale/da_DK';
import InputItem from '../../input-item/locale/da_DK';
import Pagination from '../../pagination/locale/da_DK';
import PullToRefresh from '../../pull-to-refresh/locale/da_DK';
import ActionSheet from '../../action-sheet/locale/da_DK';

export default {
locale: 'da_DK',
Expand All @@ -18,5 +19,6 @@ export default {
SearchBar,
InputItem,
Pagination,
PullToRefresh
PullToRefresh,
ActionSheet
};
4 changes: 3 additions & 1 deletion components/locale-provider/languages/en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import SearchBar from '../../search-bar/locale/en_US';
import InputItem from '../../input-item/locale/en_US';
import Pagination from '../../pagination/locale/en_US';
import PullToRefresh from '../../pull-to-refresh/locale/en_US';
import ActionSheet from '../../action-sheet/locale/en_US';

export default {
locale: 'en_US',
Expand All @@ -18,5 +19,6 @@ export default {
SearchBar,
InputItem,
Pagination,
PullToRefresh
PullToRefresh,
ActionSheet
};
4 changes: 3 additions & 1 deletion components/locale-provider/languages/ru_RU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import SearchBar from '../../search-bar/locale/ru_RU';
import InputItem from '../../input-item/locale/ru_RU';
import Pagination from '../../pagination/locale/ru_RU';
import PullToRefresh from '../../pull-to-refresh/locale/ru_RU';
import ActionSheet from '../../action-sheet/locale/ru_RU';

export default {
locale: 'ru_RU',
Expand All @@ -18,5 +19,6 @@ export default {
SearchBar,
InputItem,
Pagination,
PullToRefresh
PullToRefresh,
ActionSheet
};
4 changes: 3 additions & 1 deletion components/locale-provider/languages/sv_SE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import SearchBar from '../../search-bar/locale/sv_SE';
import InputItem from '../../input-item/locale/sv_SE';
import Pagination from '../../pagination/locale/sv_SE';
import PullToRefresh from '../../pull-to-refresh/locale/sv_SE';
import ActionSheet from '../../action-sheet/locale/sv_SE';

export default {
locale: 'sv_SE',
Expand All @@ -18,5 +19,6 @@ export default {
SearchBar,
InputItem,
Pagination,
PullToRefresh
PullToRefresh,
ActionSheet
};
4 changes: 3 additions & 1 deletion components/locale-provider/languages/zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import SearchBar from '../../search-bar/locale/zh_CN';
import InputItem from '../../input-item/locale/zh_CN';
import Pagination from '../../pagination/locale/zh_CN';
import PullToRefresh from '../../pull-to-refresh/locale/zh_CN';
import ActionSheet from '../../action-sheet/locale/zh_CN';

export default {
locale: 'zh_CN',
Expand All @@ -18,5 +19,6 @@ export default {
SearchBar,
InputItem,
Pagination,
PullToRefresh
PullToRefresh,
ActionSheet
};

0 comments on commit 39870da

Please sign in to comment.