Skip to content
This repository was archived by the owner on May 20, 2023. It is now read-only.

Commit 42cf9f4

Browse files
Googlernshahan
authored andcommitted
Add rangeFormatter input for material-date-range-picker component.
Our team used material-date-range-picker component for the app, but we have different date ranges format across it. This CL adds input to make it possible to customize range output with custom formatter function. PiperOrigin-RevId: 220048014
1 parent 76ca19c commit 42cf9f4

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

angular_components/lib/material_datepicker/material_date_range_picker.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ import 'package:angular_components/utils/angular/css/css.dart';
3434
import 'package:angular_components/utils/browser/dom_service/dom_service.dart';
3535
import 'package:angular_components/utils/disposer/disposer.dart';
3636

37+
/// Custom date range formatter interface.
38+
typedef RangeFormatter = String Function(DateRange range);
39+
3740
/// A material-design-styled date range picker.
3841
///
3942
/// Users can choose preset date ranges, type in custom date ranges, or select
@@ -305,6 +308,10 @@ class MaterialDateRangePickerComponent extends KeyboardHandlerMixin
305308
}
306309
}
307310

311+
/// Custom date range formatter function to apply to dropdown button text.
312+
@Input()
313+
RangeFormatter rangeFormatter = formatRange;
314+
308315
List<ComparisonOption> _comparisonOptions;
309316

310317
@ViewChild('focusOnClose')
@@ -548,14 +555,14 @@ class MaterialDateRangePickerComponent extends KeyboardHandlerMixin
548555
String _formattedRange;
549556
String get formattedRange => _formattedRange;
550557
String _getFormattedRange(DatepickerComparison value) =>
551-
value?.range != null ? formatRange(value.range) : placeHolderMsg;
558+
value?.range != null ? rangeFormatter(value.range) : placeHolderMsg;
552559

553560
bool get hasComparison => selection.value?.comparison != null;
554561

555562
String _formattedComparison;
556563
String get formattedComparison => _formattedComparison;
557564
String _getFormattedComparison(DatepickerComparison value) =>
558-
_compareMsg(formatRange(value?.comparison));
565+
_compareMsg(rangeFormatter(value?.comparison));
559566

560567
void _updateFormattedRanges(DatepickerComparison value) {
561568
_formattedRange = _getFormattedRange(value);

0 commit comments

Comments
 (0)