This repository has been archived by the owner on Jan 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(fab): Move all FAB styles to mixins (#1166)
Partially resolves #1143. New `mdc-fab-theme` mixin uses a config object. This makes it easy to extend somebody else's theme values, overriding only specific properties or sub-properties.
- Loading branch information
Showing
3 changed files
with
176 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
// Copyright 2016 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 "@material/animation/functions"; | ||
@import "@material/animation/variables"; | ||
@import "@material/elevation/mixins"; | ||
@import "@material/ripple/mixins"; | ||
@import "@material/theme/mixins"; | ||
|
||
@mixin mdc-fab-base_ { | ||
@include mdc-ripple-base; | ||
|
||
display: inline-flex; | ||
position: relative; | ||
justify-content: center; | ||
width: 56px; | ||
height: 56px; | ||
padding: 0; | ||
transition: box-shadow 280ms $mdc-animation-standard-curve-timing-function; | ||
border: none; | ||
border-radius: 50%; | ||
cursor: pointer; | ||
user-select: none; | ||
box-sizing: border-box; | ||
fill: currentColor; | ||
-moz-appearance: none; | ||
-webkit-appearance: none; | ||
overflow: hidden; | ||
|
||
@include mdc-elevation(6); | ||
|
||
&:active { | ||
@include mdc-elevation(12); | ||
} | ||
|
||
&:active, | ||
&:focus { | ||
// TODO(acdvorak): Should this be paired with states and/or ripple? We don't want to disable outline | ||
// (an accessibility/usability feature) unless we're confident that there is also a visual indication that the | ||
// element has focus. If the client has customized the DOM in some unexpected way, and is certain that another | ||
// element will receive focus instead, they can always override this property manually in their CSS. | ||
outline: none; | ||
} | ||
|
||
&:hover { | ||
cursor: pointer; | ||
} | ||
|
||
&::-moz-focus-inner { | ||
padding: 0; | ||
border: 0; | ||
} | ||
|
||
// This allows for using SVGs within them to align properly in all browsers. | ||
// Can remove once: https://bugzilla.mozilla.org/show_bug.cgi?id=1294515 is resolved. | ||
|
||
// stylelint-disable selector-max-type | ||
// postcss-bem-linter: ignore | ||
> svg { | ||
width: 100%; | ||
} | ||
// stylelint-enable selector-max-type | ||
} | ||
|
||
@mixin mdc-fab--mini_ { | ||
width: 40px; | ||
height: 40px; | ||
} | ||
|
||
@mixin mdc-fab--disabled_ { | ||
cursor: default; | ||
pointer-events: none; | ||
} | ||
|
||
@mixin mdc-fab-theme($config) { | ||
$bg-color: map-get($config, bg-color); | ||
$fg-color: map-get($config, fg-color); | ||
$ripple-config: map-get($config, ripple-config); | ||
$tap-highlight-color: map-get($config, tap-highlight-color); | ||
|
||
@if $ripple-config { | ||
@include mdc-ripple-bg(map-merge((pseudo: "::before"), $ripple-config)); | ||
@include mdc-ripple-fg(map-merge((pseudo: "::after"), $ripple-config)); | ||
} | ||
|
||
@if $tap-highlight-color { | ||
@if $ripple-config { | ||
&:not(.mdc-ripple-upgraded) { | ||
@include mdc-theme-prop(-webkit-tap-highlight-color, $tap-highlight-color); | ||
} | ||
} | ||
|
||
@else { | ||
@include mdc-theme-prop(-webkit-tap-highlight-color, $tap-highlight-color); | ||
} | ||
} | ||
|
||
@if $bg-color { | ||
@include mdc-theme-prop(background-color, $bg-color); | ||
} | ||
|
||
@if $fg-color { | ||
@include mdc-theme-prop(color, $fg-color); | ||
} | ||
} | ||
|
||
@mixin mdc-fab__icon_ { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
width: 100%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters