Skip to content

Commit

Permalink
Deduplicate floating button code (#340)
Browse files Browse the repository at this point in the history
Rename minor to major and inverse the logic.
  • Loading branch information
XhmikosR authored Oct 13, 2021
1 parent 967c86d commit 68c6574
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 63 deletions.
1 change: 0 additions & 1 deletion src/css/_components.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
@import 'components/settings';
@import 'components/material-switch';
@import 'components/toolbar';
@import 'components/minor-floating-action-button';
@import 'components/floating-action-button';
@import 'components/spinner';
@import 'components/toasts';
Expand Down
4 changes: 2 additions & 2 deletions src/css/_main-layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
.minor-action-container {
display: flex;

.minor-floating-action-button {
.floating-action-button {
margin-right: 10px;
}
}
Expand All @@ -68,7 +68,7 @@
bottom: 58px;
right: 8px;

.minor-floating-action-button {
.floating-action-button {
margin-bottom: 10px;
margin-right: 0;
}
Expand Down
47 changes: 32 additions & 15 deletions src/css/components/_floating-action-button.scss
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
.floating-action-button {
width: 56px;
height: 56px;
border-radius: 28px;
background-color: #00bcd4;
width: 40px;
height: 40px;
border-radius: 20px;
background-color: #fff;
box-shadow: 0 2px 3px rgba(0, 0, 0, 0.25);
position: relative;
cursor: pointer;
overflow: hidden;
z-index: 0; // Is this really needed?
display: flex;
align-items: center;
justify-content: center;
transition: transform 0.1s ease-out, box-shadow 0.1s ease-out;

@media (min-width: 640px) {
box-shadow: 0 4px 11px rgba(0, 0, 0, 0.3);
}

transition: transform 0.1s ease-out, box-shadow 0.1s ease-out;

&:hover,
&.key-focused {
transform: scale(1.15);
Expand All @@ -29,20 +31,35 @@
display: block;
width: 24px;
height: 24px;
fill: #fff;
fill: #000;
z-index: 1;
}

.spinner {
position: absolute;
top: 0;
left: 0;
.ripple {
background-color: #00bcd4;
}

&.major-floating-action-button {
width: 56px;
height: 56px;
border-color: #fff;
}
border-radius: 28px;
background-color: #00bcd4;

.ripple {
background-color: #fff;
.icon {
fill: #fff;
}

.spinner {
position: absolute;
top: 0;
left: 0;
width: 56px;
height: 56px;
border-color: #fff;
}

.ripple {
background-color: #fff;
}
}
}
41 changes: 0 additions & 41 deletions src/css/components/_minor-floating-action-button.scss

This file was deleted.

11 changes: 7 additions & 4 deletions src/js/page/ui/floating-action-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,27 @@ import { strToEl } from '../utils';
import Ripple from './ripple';

export default class FloatingActionButton {
constructor({ title, href, iconSvg, classList, major = false }) {
constructor({ title, href, iconSvg, major = false }) {
this.container = strToEl(
(href ? '<a>' : '<div role="button" tabindex="0">') +
iconSvg +
(href ? '</a>' : '</div>') +
'');

const classes = ['floating-action-button'];

if (href) {
this.container.href = href;
}
if (title) {
this.container.setAttribute('title', title);
}
this.container.classList.add(major ? 'floating-action-button' : 'minor-floating-action-button');
if (classList) {
classList.forEach((className) => { this.container.classList.add(className); });
if (major) {
classes.push('major-floating-action-button');
}

this.container.classList.add(...classes);

this._ripple = new Ripple();
this.container.appendChild(this._ripple.container);
this.container.addEventListener('click', () => this.onClick());
Expand Down

0 comments on commit 68c6574

Please sign in to comment.