Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

feat(fab): Enable padding customization #2959

Merged
merged 14 commits into from
Jun 22, 2018
Merged
Show file tree
Hide file tree
Changes from 8 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
27 changes: 24 additions & 3 deletions demos/fab.html
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,36 @@
<legend>Extended FAB</legend>
<div class="demo-fabs">
<figure class="demo-figure-fab-extended">
<button class="mdc-fab mdc-fab--extended demo-fab-extended-fluid" aria-label="Favorite">
<span class="material-icons mdc-fab__icon">shopping_cart</span>
<span class="mdc-fab__label">Add to cart</span>
<button class="mdc-fab mdc-fab--extended demo-fab-extended-fluid" aria-label="Create">
<span class="material-icons mdc-fab__icon">add</span>
<span class="mdc-fab__label">Create</span>
</button>
<figcaption>
<div>Auto width extended FAB (Responsive)</div>
</figcaption>
</figure>
</div>
<div class="demo-fabs">
<figure class="demo-figure-fab-extended">
<button class="mdc-fab mdc-fab--extended demo-fab-extended-fluid" aria-label="Create">
<span class="mdc-fab__label">Create</span>
<span class="material-icons mdc-fab__icon">add</span>
</button>
<figcaption>
<div>Auto width extended FAB (Text label followed by Icon)</div>
</figcaption>
</figure>
</div>
<div class="demo-fabs">
<figure class="demo-figure-fab-extended">
<button class="mdc-fab mdc-fab--extended demo-fab-extended-without-icon" aria-label="Create">
<span class="mdc-fab__label">Create</span>
</button>
<figcaption>
<div>Extended FAB (without Icon)</div>
</figcaption>
</figure>
</div>
</section>

<section>
Expand Down
2 changes: 2 additions & 0 deletions packages/mdc-fab/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ Mixin | Description
`mdc-fab-container-color($color)` | Sets the container color to the given color
`mdc-fab-icon-size($width, $height)` | Sets the icon `width`, `height`, and `font-size` properties to the specified `width` and `height`. `$height` is optional and will default to `$width` if omitted. The `font-size` will be set to the provided `$width` value.
`mdc-fab-ink-color($color)` | Sets the ink color to the given color
`mdc-fab-extended-padding($icon-padding, $label-padding)` | Sets the padding of icon sides (Left side and gutter space) and label side for Extended FAB. The left & right padding of the icon are equal.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm suggesting some rephrasings for each of these, to try to simplify and clarify when to use each.

"Sets the padding on both sides of the icon, and between the label and the edge of the FAB. In cases where there is no icon, $label-padding will apply to both sides."

`mdc-fab-extended-label-padding($label-padding)` | Sets the label side padding for Extended FAB. This padding size will be applied to both sides when Extended FAB is rendered without icon.
Copy link
Contributor

Choose a reason for hiding this comment

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

Change the second sentence to "Useful in lieu of mdc-fab-extended-padding when styling an Extended FAB with no icon."


The ripple effect for the FAB component is styled using [MDC Ripple](../mdc-ripple) mixins.

Expand Down
31 changes: 29 additions & 2 deletions packages/mdc-fab/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
@import "@material/ripple/variables";
@import "@material/theme/functions";
@import "@material/theme/mixins";
@import "@material/rtl/mixins";
@import "./variables";

@mixin mdc-fab-accessible($container-color) {
$fill-tone: mdc-theme-tone($container-color);
Expand Down Expand Up @@ -54,6 +56,30 @@
width: 100%;
}

@mixin mdc-fab-extended-padding($icon-padding, $label-padding) {
@include mdc-fab-extended-label-padding($label-padding);

// Offsets the outer label padding by deducting it from icon padding.
.mdc-fab__icon {
@include mdc-rtl-reflexive-property(
margin,
$mdc-fab-extended-icon-padding - $mdc-fab-extended-label-padding,
Copy link
Contributor

Choose a reason for hiding this comment

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

The variable names throughout these mixins need to be updated to reference the mixin parameters, otherwise they will never actually customize anything.

We should ideally have an additional screenshot test page under mdc-fab/mixins to test these.

$mdc-fab-extended-icon-padding);
}

// For Extended FAB with text label followed by icon.
.mdc-fab__label + .mdc-fab__icon {
@include mdc-rtl-reflexive-property(
margin,
$mdc-fab-extended-icon-padding,
$mdc-fab-extended-icon-padding - $mdc-fab-extended-label-padding);
}
}

@mixin mdc-fab-extended-label-padding($label-padding) {
padding: 0 $mdc-fab-extended-label-padding;
Copy link
Contributor

Choose a reason for hiding this comment

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

$label-padding

}

$mdc-fab-icon-enter-delay_: 90ms;
$mdc-fab-icon-enter-duration_: 180ms;
$mdc-fab-extended-height_: 48px;
Expand Down Expand Up @@ -129,11 +155,13 @@ $mdc-fab-extended-height_: 48px;

@mixin mdc-fab--extended_ {
@include mdc-typography(button);
@include mdc-fab-extended-padding(
$mdc-fab-extended-icon-padding,
$mdc-fab-extended-label-padding);

width: auto;
max-width: 100%;
height: $mdc-fab-extended-height_;
padding: 0 20px 0 16px;
border-radius: $mdc-fab-extended-height_ / 2;
}

Expand All @@ -145,7 +173,6 @@ $mdc-fab-extended-height_: 48px;

@mixin mdc-fab__label_ {
justify-content: flex-start;
padding-left: 8px;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
Expand Down
18 changes: 18 additions & 0 deletions packages/mdc-fab/_variables.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// Copyright 2018 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

$mdc-fab-extended-icon-padding: 12px;
$mdc-fab-extended-label-padding: 20px;
3 changes: 2 additions & 1 deletion packages/mdc-fab/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@material/elevation": "^0.36.1",
"@material/ripple": "^0.36.0",
"@material/theme": "^0.35.0",
"@material/typography": "^0.35.0"
"@material/typography": "^0.35.0",
"@material/rtl": "^0.36.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: put rtl after ripple

}
}
10 changes: 5 additions & 5 deletions test/screenshot/golden.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@
}
},
"mdc-fab/classes/extended.html": {
"publicUrl": "https://storage.googleapis.com/mdc-web-screenshot-tests/abhiomkar/2018/06/08/15_24_10_920/e995ab9c/mdc-fab/classes/extended.html",
"publicUrl": "https://storage.googleapis.com/mdc-web-screenshot-tests/abhiomkar/2018/06/19/19_52_01_078/mdc-fab/classes/extended.html",
"screenshots": {
"desktop_windows_chrome@latest": "https://storage.googleapis.com/mdc-web-screenshot-tests/abhiomkar/2018/06/08/15_24_10_920/e995ab9c/mdc-fab/classes/extended.html.win10_chrome66x64.png",
"desktop_windows_edge@latest": "https://storage.googleapis.com/mdc-web-screenshot-tests/abhiomkar/2018/06/08/15_24_10_920/e995ab9c/mdc-fab/classes/extended.html.win10_edge17.png",
"desktop_windows_firefox@latest": "https://storage.googleapis.com/mdc-web-screenshot-tests/abhiomkar/2018/06/08/15_24_10_920/e995ab9c/mdc-fab/classes/extended.html.win10_ff59x64.png",
"desktop_windows_ie@11": "https://storage.googleapis.com/mdc-web-screenshot-tests/abhiomkar/2018/06/08/15_24_10_920/e995ab9c/mdc-fab/classes/extended.html.win10_ie11.png"
"desktop_windows_chrome@latest": "https://storage.googleapis.com/mdc-web-screenshot-tests/abhiomkar/2018/06/19/19_52_01_078/mdc-fab/classes/extended.html.win10_chrome66x64.png",
"desktop_windows_edge@latest": "https://storage.googleapis.com/mdc-web-screenshot-tests/abhiomkar/2018/06/19/19_52_01_078/mdc-fab/classes/extended.html.win10_edge17.png",
"desktop_windows_firefox@latest": "https://storage.googleapis.com/mdc-web-screenshot-tests/abhiomkar/2018/06/19/19_52_01_078/mdc-fab/classes/extended.html.win10_ff59x64.png",
"desktop_windows_ie@11": "https://storage.googleapis.com/mdc-web-screenshot-tests/abhiomkar/2018/06/19/19_52_01_078/mdc-fab/classes/extended.html.win10_ie11.png"
}
},
"mdc-fab/classes/mini.html": {
Expand Down
17 changes: 14 additions & 3 deletions test/screenshot/mdc-fab/classes/extended.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,20 @@
<main class="test-main test-main--fab">
<div class="test-grid">
<div class="test-cell test-cell--extended">
<button class="mdc-fab mdc-fab--extended" aria-label="Add to cart">
<span class="material-icons mdc-fab__icon">shopping_cart</span>
<span class="mdc-fab__label">Add to cart</span>
<button class="mdc-fab mdc-fab--extended" aria-label="Create">
<span class="material-icons mdc-fab__icon">add</span>
<span class="mdc-fab__label">Create</span>
</button>
</div>
<div class="test-cell test-cell--extended">
<button class="mdc-fab mdc-fab--extended" aria-label="Create">
<span class="mdc-fab__label">Create</span>
<span class="material-icons mdc-fab__icon">add</span>
</button>
</div>
<div class="test-cell test-cell--extended">
<button class="mdc-fab mdc-fab--extended" aria-label="Create">
<span class="mdc-fab__label">Create</span>
</button>
</div>
</div>
Expand Down