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

Commit

Permalink
feat(fab): Enable padding customization (#2959)
Browse files Browse the repository at this point in the history
- This change enables users to customize Extended FAB icon & label padding using new mixins.
- Updated the paddings as per updated design spec. 
- Updated styles to support text label followed by icon Extended FAB.
- Added screenshot tests for mixins.
  • Loading branch information
abhiomkar authored Jun 22, 2018
1 parent 153e737 commit 1f5fd1f
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 13 deletions.
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 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. Useful 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,
$icon-padding - $label-padding,
$icon-padding);
}

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

@mixin mdc-fab-extended-label-padding($label-padding) {
padding: 0 $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;
1 change: 1 addition & 0 deletions packages/mdc-fab/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@material/animation": "^0.34.0",
"@material/elevation": "^0.36.1",
"@material/ripple": "^0.36.0",
"@material/rtl": "^0.36.0",
"@material/theme": "^0.35.0",
"@material/typography": "^0.35.0"
}
Expand Down
19 changes: 14 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 All @@ -125,6 +125,15 @@
"desktop_windows_ie@11": "https://storage.googleapis.com/mdc-web-screenshot-tests/kfranqueiro/2018/05/25/21_14_58_299/6b0f3e00/mdc-fab/classes/mini.html.win10_ie11.png"
}
},
"mdc-fab/mixins/mdc-fab-extended-label-padding.html": {
"publicUrl": "https://storage.googleapis.com/mdc-web-screenshot-tests/abhiomkar/2018/06/22/19_14_56_425/mdc-fab/mixins/mdc-fab-extended-label-padding.html",
"screenshots": {
"desktop_windows_chrome@latest": "https://storage.googleapis.com/mdc-web-screenshot-tests/abhiomkar/2018/06/22/19_14_56_425/mdc-fab/mixins/mdc-fab-extended-label-padding.html.win10_chrome66x64.png",
"desktop_windows_edge@latest": "https://storage.googleapis.com/mdc-web-screenshot-tests/abhiomkar/2018/06/22/19_14_56_425/mdc-fab/mixins/mdc-fab-extended-label-padding.html.win10_edge17.png",
"desktop_windows_firefox@latest": "https://storage.googleapis.com/mdc-web-screenshot-tests/abhiomkar/2018/06/22/19_14_56_425/mdc-fab/mixins/mdc-fab-extended-label-padding.html.win10_ff59x64.png",
"desktop_windows_ie@11": "https://storage.googleapis.com/mdc-web-screenshot-tests/abhiomkar/2018/06/22/19_14_56_425/mdc-fab/mixins/mdc-fab-extended-label-padding.html.win10_ie11.png"
}
},
"mdc-icon-button/classes/baseline.html": {
"publicUrl": "https://storage.googleapis.com/mdc-web-screenshot-tests/williamernest/2018/05/30/14_38_21_131/4dc98079/mdc-icon-button/classes/baseline.html",
"screenshots": {
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
30 changes: 30 additions & 0 deletions test/screenshot/mdc-fab/custom.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// 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.
//

@import "../../../packages/mdc-fab/mixins";

.custom-fab-extended-padding-and-icon-size {
@include mdc-fab-extended-padding(12px, 24px);
@include mdc-fab-icon-size(32px);
}

.custom-fab-extended-padding {
@include mdc-fab-extended-padding(16px, 24px);
}

.custom-fab-extended-label-padding {
@include mdc-fab-extended-label-padding(24px);
}
51 changes: 51 additions & 0 deletions test/screenshot/mdc-fab/mixins/mdc-fab-extended-label-padding.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!DOCTYPE html>
<!--
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
https://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
-->
<html lang="en">
<head>
<meta charset="utf-8">
<title>Extended FAB (Floating Action Button) - MDC Web Screenshot Test</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../../out/fixture.css">
<link rel="stylesheet" href="../../out/mdc.fab.css">
<link rel="stylesheet" href="../../out/mdc-fab/fixture.css">
<link rel="stylesheet" href="../../out/mdc-fab/custom.css">
</head>

<body class="test-body">
<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 custom-fab-extended-padding-and-icon-size" 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 custom-fab-extended-padding" 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 custom-fab-extended-label-padding" aria-label="Create">
<span class="mdc-fab__label">Create</span>
</button>
</div>
</div>
</main>
</body>
</html>

0 comments on commit 1f5fd1f

Please sign in to comment.