Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit bd4dc66

Browse files
committed
feat(datepicker): add docs with usage for $mdDateLocale
1 parent 4211d21 commit bd4dc66

7 files changed

+80
-49
lines changed

src/components/datepicker/calendar.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
* @ngInject @constructor
7777
*/
7878
function CalendarCtrl($element, $attrs, $scope, $animate, $q, $mdConstant,
79-
$mdTheming, $$mdDateUtil, $$mdDateLocale, $mdInkRipple, $mdUtil) {
79+
$mdTheming, $$mdDateUtil, $mdDateLocale, $mdInkRipple, $mdUtil) {
8080
$mdTheming($element);
8181
/**
8282
* Dummy array-like object for virtual-repeat to iterate over. The length is the total
@@ -104,7 +104,7 @@
104104
this.dateUtil = $$mdDateUtil;
105105

106106
/** @final */
107-
this.dateLocale = $$mdDateLocale;
107+
this.dateLocale = $mdDateLocale;
108108

109109
/** @final {!angular.JQLite} */
110110
this.$element = $element;

src/components/datepicker/calendar.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ describe('md-calendar', function() {
9898
$compile = $injector.get('$compile');
9999
$rootScope = $injector.get('$rootScope');
100100
$$rAF = $injector.get('$$rAF');
101-
dateLocale = $injector.get('$$mdDateLocale');
101+
dateLocale = $injector.get('$mdDateLocale');
102102
dateUtil = $injector.get('$$mdDateUtil');
103103
$mdUtil = $injector.get('$mdUtil');
104104
keyCodes = $injector.get('$mdConstant').KEY_CODE;
@@ -136,7 +136,7 @@ describe('md-calendar', function() {
136136
expect(extractRowText(header)).toEqual(['S', 'M', 'T', 'W', 'T', 'F' ,'S']);
137137
});
138138

139-
it('should use $$mdDateLocale.shortDays as weeks header values', function() {
139+
it('should use $mdDateLocale.shortDays as weeks header values', function() {
140140
var oldShortDays = dateLocale.shortDays;
141141
dateLocale.shortDays = ['SZ', 'MZ', 'TZ', 'WZ', 'TZ', 'FZ', 'SZ'];
142142

src/components/datepicker/calendarMonth.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848
* Controller for a single calendar month.
4949
* @ngInject @constructor
5050
*/
51-
function CalendarMonthCtrl($element, $$mdDateUtil, $$mdDateLocale) {
51+
function CalendarMonthCtrl($element, $$mdDateUtil, $mdDateLocale) {
5252
this.dateUtil = $$mdDateUtil;
53-
this.dateLocale = $$mdDateLocale;
53+
this.dateLocale = $mdDateLocale;
5454
this.$element = $element;
5555
this.calendarCtrl = null;
5656

@@ -108,7 +108,7 @@
108108
selectionIndicator.textContent = this.dateLocale.dates[opt_date.getDate()];
109109

110110
cell.setAttribute('tabindex', '-1');
111-
cell.setAttribute('aria-label', this.dateLocale.longAnnounceFormatter(opt_date));
111+
cell.setAttribute('aria-label', this.dateLocale.longDateFormatter(opt_date));
112112
cell.id = calendarCtrl.getDateId(opt_date);
113113
cell.addEventListener('click', calendarCtrl.cellClickHandler);
114114

src/components/datepicker/dateLocale.spec.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
describe('$$mdDateLocale', function() {
2+
describe('$mdDateLocale', function() {
33
var dateLocale, dateUtil;
44

55
// Fake $locale with made-up days and months.
@@ -19,8 +19,8 @@ describe('$$mdDateLocale', function() {
1919
$provide.value('$locale', $localeFake);
2020
}));
2121

22-
beforeEach(inject(function($$mdDateLocale, $$mdDateUtil) {
23-
dateLocale = $$mdDateLocale;
22+
beforeEach(inject(function($mdDateLocale, $$mdDateUtil) {
23+
dateLocale = $mdDateLocale;
2424
dateUtil = $$mdDateUtil;
2525
}));
2626

@@ -55,23 +55,23 @@ describe('$$mdDateLocale', function() {
5555
'X12', 'X13', 'X14', 'X15', 'X16', 'X17', 'X18', 'X19', 'X20', 'X21', 'X22', 'X23', 'X24',
5656
'X25', 'X26', 'X27', 'X28', 'X29', 'X30', 'X31'];
5757

58-
beforeEach(module(function($$mdDateLocaleProvider) {
59-
$$mdDateLocaleProvider.months = fakeMonths;
60-
$$mdDateLocaleProvider.shortMonths = fakeshortMonths;
61-
$$mdDateLocaleProvider.days = fakeDays;
62-
$$mdDateLocaleProvider.shortDays = fakeShortDays;
63-
$$mdDateLocaleProvider.dates = fakeDates;
64-
$$mdDateLocaleProvider.formatDate = function() {
58+
beforeEach(module(function($mdDateLocaleProvider) {
59+
$mdDateLocaleProvider.months = fakeMonths;
60+
$mdDateLocaleProvider.shortMonths = fakeshortMonths;
61+
$mdDateLocaleProvider.days = fakeDays;
62+
$mdDateLocaleProvider.shortDays = fakeShortDays;
63+
$mdDateLocaleProvider.dates = fakeDates;
64+
$mdDateLocaleProvider.formatDate = function() {
6565
return 'Your birthday!'
6666
};
67-
$$mdDateLocaleProvider.parseDate = function() {
67+
$mdDateLocaleProvider.parseDate = function() {
6868
return new Date(1969, 6, 16);
6969
};
7070
}));
7171

7272

73-
beforeEach(inject(function($$mdDateLocale, $$mdDateUtil) {
74-
dateLocale = $$mdDateLocale;
73+
beforeEach(inject(function($mdDateLocale, $$mdDateUtil) {
74+
dateLocale = $mdDateLocale;
7575
dateUtil = $$mdDateUtil;
7676
}));
7777

src/components/datepicker/dateLocaleProvider.js

+54-25
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,53 @@
55
* Provider that allows the user to specify messages, formatters, and parsers for date
66
* internationalization.
77
*/
8+
9+
10+
/**
11+
* @ngdoc service
12+
* @name $mdDateLocaleProvider
13+
* @module material.components.datepicker
14+
*
15+
* @description
16+
* The `$mdDateLocaleProvider` is the provider that creates the `$mdDateLocale` service.
17+
* This provider that allows the user to specify messages, formatters, and parsers for date
18+
* internationalization. The `$mdDateLocale` service itself is consumed by Angular Material
19+
* components that that deal with dates.
20+
*
21+
* @usage
22+
* <hljs lang="js">
23+
* myAppModule.config(function($mdDateLocaleProvider) {
24+
*
25+
* // Example of a French localization.
26+
* $mdDateLocaleProvider.months = ['Janvier', 'Février', 'Mars', ...];
27+
* $mdDateLocaleProvider.shortMonths = ['Janv', 'Févr', 'Mars', ...];
28+
* $mdDateLocaleProvider.days = ['Lundi', 'Mardi', 'Mercredi', ...];
29+
* $mdDateLocaleProvider.shortDays = ['L', 'M', 'M', ...];
30+
* $mdDateLocaleProvider.dates = [1, 2, 3, 4, 5, 6, ...];
31+
*
32+
* // Example uses moment.js to parse and format dates.
33+
* $mdDateLocaleProvider.formatDate = function(date) {
34+
* return moment(date).format
35+
* };
36+
* $mdDateLocaleProvider.parseDate = function(dateString) {
37+
* return moment(dateString).toDate('L');
38+
* };
39+
*
40+
* $mdDateLocaleProvider.monthHeaderFormatter = function(date) {
41+
* $mdDateLocale.shortMonths[date.getMonth()] + ' ' + date.getFullYear();
42+
* };
43+
*
44+
* $mdDateLocaleProvider.weekNumberFormatter = function(weekNumber) {
45+
* return 'Semaine ' + weekNumber;
46+
* };
47+
*
48+
* $mdDateLocaleProvider.msgCalendar = 'Calendrier';
49+
* $mdDateLocaleProvider.msgOpenCalendar = 'Ouvrir le calendrier';
50+
*
51+
* });
52+
* </hljs>
53+
*
54+
*/
855
angular.module('material.components.datepicker').config(function($provide) {
956
// TODO(jelbourn): Assert provided values are correctly formatted. Need assertions.
1057

@@ -50,18 +97,11 @@
5097
this.weekNumberFormatter = null;
5198

5299
/**
53-
* Function that formats a date into a short aria-live announcement that is read when
54-
* the focused date changes within the same month.
55-
* @type {function(Date): string}
56-
*/
57-
this.shortAnnounceFormatter = null;
58-
59-
/**
60-
* Function that formats a date into a long aria-live announcement that is read when
61-
* the focused date changes to a date in a different month.
100+
* Function that formats a date into a long aria-label that is read
101+
* when the focused date changes.
62102
* @type {function(Date): string}
63103
*/
64-
this.longAnnounceFormatter = null;
104+
this.longDateFormatter = null;
65105

66106
/**
67107
* ARIA label for the calendar "dialog" used in the datepicker.
@@ -120,21 +160,11 @@
120160
}
121161

122162
/**
123-
* Default formatter for short aria-live announcements.
124-
* @param {!Date} date
125-
* @returns {string}
126-
*/
127-
function defaultShortAnnounceFormatter(date) {
128-
// Example: 'Tuesday 12'
129-
return service.days[date.getDay()] + ' ' + service.dates[date.getDate()];
130-
}
131-
132-
/**
133-
* Default formatter for long aria-live announcements.
163+
* Default formatter for date cell aria-labels.
134164
* @param {!Date} date
135165
* @returns {string}
136166
*/
137-
function defaultLongAnnounceFormatter(date) {
167+
function defaultLongDateFormatter(date) {
138168
// Example: 'Thursday June 18 2015'
139169
return [
140170
service.days[date.getDay()],
@@ -170,15 +200,14 @@
170200
parseDate: this.parseDate || defaultParseDate,
171201
monthHeaderFormatter: this.monthHeaderFormatter || defaultMonthHeaderFormatter,
172202
weekNumberFormatter: this.weekNumberFormatter || defaultWeekNumberFormatter,
173-
shortAnnounceFormatter: this.shortAnnounceFormatter || defaultShortAnnounceFormatter,
174-
longAnnounceFormatter: this.longAnnounceFormatter || defaultLongAnnounceFormatter,
203+
longDateFormatter: this.longDateFormatter || defaultLongDateFormatter,
175204
msgCalendar: this.msgCalendar || defaultMsgCalendar,
176205
msgOpenCalendar: this.msgOpenCalendar || defaultMsgOpenCalendar
177206
});
178207

179208
return service;
180209
};
181210

182-
$provide.provider('$$mdDateLocale', new DateLocaleProvider());
211+
$provide.provider('$mdDateLocale', new DateLocaleProvider());
183212
});
184213
})();

src/components/datepicker/datePicker.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
*
3030
* @description
3131
* `<md-datepicker>` is a component used to select a single date.
32+
* For information on how to configure internationalization for the date piicker,
33+
* see `$mdDateLocaleProvider`.
3234
*
3335
* @usage
3436
* <hljs lang="html">
@@ -45,7 +47,7 @@
4547
'<md-button class="md-datepicker-button md-icon-button" type="button" ' +
4648
'tabindex="-1" aria-hidden="true" ' +
4749
'ng-click="ctrl.openCalendarPane($event)">' +
48-
'<md-icon class="md-datepicker-calendar-icon" md-svg-icon="md-calendar"></md-icon>' +
50+
'<md-icon class="md-datepicker-calendar-icon" md-svg-icon="md-calendar"></md-icon>' +
4951
'</md-button>' +
5052
'<div class="md-datepicker-input-container">' +
5153
'<input class="md-datepicker-input" aria-haspopup="true">' +
@@ -90,15 +92,15 @@
9092
* @ngInject @constructor
9193
*/
9294
function DatePickerCtrl($scope, $element, $attrs, $compile, $timeout, $mdConstant, $mdTheming,
93-
$mdUtil, $$mdDateLocale, $$mdDateUtil, $$rAF) {
95+
$mdUtil, $mdDateLocale, $$mdDateUtil, $$rAF) {
9496
/** @final */
9597
this.$compile = $compile;
9698

9799
/** @final */
98100
this.$timeout = $timeout;
99101

100102
/** @final */
101-
this.dateLocale = $$mdDateLocale;
103+
this.dateLocale = $mdDateLocale;
102104

103105
/** @final */
104106
this.dateUtil = $$mdDateUtil;

src/components/datepicker/datePicker.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('md-date-picker', function() {
1616
$$rAF = $injector.get('$$rAF');
1717
$animate = $injector.get('$animate');
1818
dateUtil = $injector.get('$$mdDateUtil');
19-
dateLocale = $injector.get('$$mdDateLocale');
19+
dateLocale = $injector.get('$mdDateLocale');
2020
$timeout = $injector.get('$timeout');
2121
keyCodes = $injector.get('$mdConstant').KEY_CODE;
2222

0 commit comments

Comments
 (0)