Skip to content

MDC Migration: Globally restyle mat-icon-button #6608

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 5 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions tensorboard/webapp/metrics/views/_common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ $metrics-min-card-height: 320px;
@mixin metrics-card-controls {
@include tb-theme-foreground-prop(color, secondary-text);
white-space: nowrap;

::ng-deep button[mat-icon-button] {
font-size: 16px;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unnecessary with my other suggestions. I think the 24px x 24px default is perfectly fine here.

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhere in the metrics code we (unsuccessfully) try to override the height of the pin icon to 18px (I see it in the css browser but it doesn't get applied). Can you remove that as part of this change?

I think it looks perfectly fine at 24px x 24px. The reason it might look odd to someone is because the two icons directly surrounding it are a bit squat - but that's not really the pin icon's problem.

}

@mixin metrics-empty-message {
Expand Down
27 changes: 27 additions & 0 deletions tensorboard/webapp/theme/_tb_theme.template.scss
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,33 @@ $tb-dark-theme: map_merge(
}
}

body,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To summarize various comments below:

  body,
  body.dark-mode {
    a[mat-icon-button].mat-mdc-icon-button,
    button[mat-icon-button].mat-mdc-icon-button {
      height: 40px;
      width: 40px;
      display: inline-flex;
      justify-content: center;
      align-items: center;

      .mat-mdc-button-touch-target {
        height: 100%;
        width: 100%;
      }

      mat-icon.mat-icon {
        flex-shrink: 0;
      }

      mat-icon.mat-icon,
      svg {
        height: 24px;
        width: 24px;
      }
    }
  }

body.dark-mode {
button[mat-icon-button].mat-mdc-icon-button {
width: unset;
height: unset;
display: inline-flex;
justify-content: center;
align-items: center;
flex-wrap: wrap;

.mat-mdc-button-touch-target {
height: 100%;
width: 100%;
}

mat-icon.mat-icon {
min-width: 1em;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what you're really looking for is:

flex-shrink: 0;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, that is cleaner

}

mat-icon.mat-icon,
svg {
width: 1em;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, the affect of setting width and height to "1em" is that we can now control svg size by using "font-size" property?

That's interesting but I also think it's counter intuitive and probably the wrong path to go down. Consider:

  • Angular defines its icon and button sizes in terms of pixels.
  • We load our icons in terms of pixels (they are all loaded as 24px).
  • The large majority of our icons are displayed as 24px x 24px and that has been perfectly fine.

We really should just put:
height: 24px;
width: 24px;
To be consistent with the defaults of the current UI.

If there is a component that wants to specify a smaller icon (say, for example, the icons in the runs table) then they can just also specify their overrides in terms of pixels.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you feel about meeting in the middle with a css variable?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, a css variable seems like a reasonable idea.

I don't have a lot of experience with them - is there a way to document the variable in a way that is discoverable and understandable by those who actually need to use it?

height: 1em;
}
}
}

// Cannot use `tb-dark-theme` as :host-context in the global stylesheet is
// meaningless.
body.dark-mode {
Expand Down
22 changes: 12 additions & 10 deletions tensorboard/webapp/widgets/data_table/header_cell_component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,6 @@ $_icon_size: 12px;
}
}

.sorting-icon-container,
.context-menu-container {
width: $_icon_size + 4px;
height: $_icon_size + 4px;
border-radius: 5px;
display: flex;
justify-content: center;
align-items: center;
}

.cell {
align-items: center;
display: flex;
Expand All @@ -60,6 +50,18 @@ $_icon_size: 12px;
line-height: 1;
}

button.sorting-icon-container,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  button[mat-icon-button].mat-mdc-icon-button {
    &.sorting-icon-container,
    &.context-menu-container {
      border-radius: 5px;
      font-size: 0;
      height: $_icon_size + 4px;
      padding: 0;
      width: $_icon_size + 4px;

      mat-icon, ::ng-deep svg {
        height: $_icon_size;
        line-height: 1;
        width: $_icon_size;
      }
    }

button.context-menu-container {
width: $_icon_size + 4px;
height: $_icon_size + 4px;
border-radius: 5px;
display: flex;
justify-content: center;
align-items: center;
font-size: 12px;
padding: 4px;
}

.sorting-icon-container {
::ng-deep path {
fill: unset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</g>
</svg>
<button
[class.extent-edit-button]="true"
class="extent-edit-button"
[class.extent-edit-menu-opened]="editMenuOpened"
mat-icon-button
#matMenuTrigger="matMenuTrigger"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,24 @@ text {
display: flex;
height: 100%;
width: 100%;

.extent-edit-button {
font-size: 16px;
height: 24px;
line-height: 24px;
position: absolute;
right: 5px;
top: 5px;
visibility: hidden;
width: 24px;
padding: 0;

mat-icon {
height: 16px;
width: 16px;
line-height: 16px;
}
}
}

.major,
Expand Down Expand Up @@ -112,24 +130,6 @@ text {
}
}

.extent-edit-button {
background-color: mat.get-color-from-palette(mat.$gray-palette, 200);
font-size: 0;
height: 24px;
line-height: 24px;
position: absolute;
right: 5px;
top: 5px;
visibility: hidden;
width: 24px;

mat-icon {
height: 16px;
width: 16px;
line-height: 16px;
}
}

.extent-edit-input {
align-items: center;
column-gap: 5px;
Expand Down