Skip to content

refactor(datepicker): remove MatIconModule dependency #9499

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/lib/datepicker/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ ng_module(
module_name = "@angular/material/datepicker",
assets = [
":datepicker_content_css",
":datepicker_toggle_css",
":calendar_body_css",
":calendar_css",
],
deps = [
"//src/lib/core",
"//src/lib/button",
"//src/lib/dialog",
"//src/lib/icon",
"//src/lib/input",
"//src/cdk/a11y",
"//src/cdk/bidi",
Expand All @@ -35,6 +35,12 @@ sass_binary(
deps = ["//src/lib/core:core_scss_lib"],
)

sass_binary(
name = "datepicker_toggle_scss",
src = "datepicker-toggle.scss",
deps = ["//src/lib/core:core_scss_lib"],
)

sass_binary(
name = "calendar_scss",
src = "calendar.scss",
Expand All @@ -56,6 +62,15 @@ genrule(
cmd = "cat $(locations :datepicker_content_scss) > $@",
)

# TODO(jelbourn): remove this when sass_binary supports specifying an output filename and dir.
# Copy the output of the sass_binary such that the filename and path match what we expect.
genrule(
name = "datepicker_toggle_css",
srcs = [":datepicker_toggle_scss"],
outs = ["datepicker-toggle.css"],
cmd = "cat $(locations :datepicker_toggle_scss) > $@",
)

# TODO(jelbourn): remove this when sass_binary supports specifying an output filename and dir.
# Copy the output of the sass_binary such that the filename and path match what we expect.
genrule(
Expand Down
2 changes: 0 additions & 2 deletions src/lib/datepicker/datepicker-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {CommonModule} from '@angular/common';
import {NgModule} from '@angular/core';
import {MatButtonModule} from '@angular/material/button';
import {MatDialogModule} from '@angular/material/dialog';
import {MatIconModule} from '@angular/material/icon';
import {MatCalendar} from './calendar';
import {MatCalendarBody} from './calendar-body';
import {
Expand All @@ -33,7 +32,6 @@ import {MatYearView} from './year-view';
CommonModule,
MatButtonModule,
MatDialogModule,
MatIconModule,
OverlayModule,
A11yModule,
],
Expand Down
19 changes: 12 additions & 7 deletions src/lib/datepicker/datepicker-toggle.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
<button mat-icon-button type="button" [attr.aria-label]="_intl.openCalendarLabel"
[disabled]="disabled" (click)="_open($event)">
<mat-icon *ngIf="!_customIcon">
<svg viewBox="0 0 24 24" width="100%" height="100%" fill="currentColor"
style="vertical-align: top" focusable="false">
<path d="M0 0h24v24H0z" fill="none"/>
<path d="M19 3h-1V1h-2v2H8V1H6v2H5c-1.11 0-1.99.9-1.99 2L3 19c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H5V8h14v11zM7 10h5v5H7z"/>
</svg>
</mat-icon>

<svg
*ngIf="!_customIcon"
class="mat-datepicker-toggle-default-icon"
viewBox="0 0 24 24"
width="24px"
height="24px"
fill="currentColor"
focusable="false">
<path d="M0 0h24v24H0z" fill="none"/>
<path d="M19 3h-1V1h-2v2H8V1H6v2H5c-1.11 0-1.99.9-1.99 2L3 19c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H5V8h14v11zM7 10h5v5H7z"/>
</svg>

<ng-content select="[matDatepickerToggleIcon]"></ng-content>
</button>
6 changes: 6 additions & 0 deletions src/lib/datepicker/datepicker-toggle.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.mat-datepicker-toggle-default-icon {
.mat-form-field-prefix &,
.mat-form-field-suffix & {
width: 1em;
}
}
1 change: 1 addition & 0 deletions src/lib/datepicker/datepicker-toggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export class MatDatepickerToggleIcon {}
moduleId: module.id,
selector: 'mat-datepicker-toggle',
templateUrl: 'datepicker-toggle.html',
styleUrls: ['datepicker-toggle.css'],
host: {
'class': 'mat-datepicker-toggle',
'[class.mat-datepicker-toggle-active]': 'datepicker && datepicker.opened',
Expand Down