Skip to content

Commit

Permalink
feat(shape): Add MDC Shape with support for unelevated angled corners (
Browse files Browse the repository at this point in the history
  • Loading branch information
kfranqueiro committed Apr 9, 2018
1 parent e68b053 commit dc87f18
Show file tree
Hide file tree
Showing 15 changed files with 487 additions and 3 deletions.
5 changes: 4 additions & 1 deletion demos/common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,17 @@ fieldset {
text-decoration: none;
}

// Use full-opacity equivalent of rgba(0, 0, 0, .05) and expose for demos to reference
$hero-background-color: #f2f2f2;

.hero {
display: flex;
flex-flow: row nowrap;
align-items: center;
justify-content: center;
height: 360px;
min-height: 360px;
background-color: rgba(0, 0, 0, .05);
background-color: $hero-background-color;
}

// Default padding on all examples.
Expand Down
8 changes: 8 additions & 0 deletions demos/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@
</span>
</a>

<a href="shape.html" role="listitem" class="mdc-list-item">
<span class="demo-catalog-list-icon mdc-list-item__graphic"><img src="/images/ic_component_24px.svg" /></span>
<span class="mdc-list-item__text">
Shape
<span class="mdc-list-item__secondary-text">Mixins for angled corners on unelevated components</span>
</span>
</a>

<a href="slider.html" role="listitem" class="mdc-list-item">
<span class="demo-catalog-list-icon mdc-list-item__graphic"><img src="/images/slider.svg" /></span>
<span class="mdc-list-item__text">
Expand Down
121 changes: 121 additions & 0 deletions demos/shape.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<!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>
<head>
<meta charset="utf-8">
<title>Shape - Material Components Catalog</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/png" href="/images/logo_components_color_2x_web_48dp.png">
<link rel="stylesheet" href="/assets/shape.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto+Mono">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<script src="/ready.js"></script>
</head>
<body class="mdc-typography">
<header class="mdc-toolbar mdc-toolbar--fixed">
<div class="mdc-toolbar__row">
<section class="mdc-toolbar__section mdc-toolbar__section--align-start">
<a href="/" class="catalog-back mdc-toolbar__menu-icon"><i class="material-icons">&#xE5C4;</i></a>
<span class="mdc-toolbar__title catalog-title">Shape</span>
</section>
</div>
</header>

<main class="mdc-toolbar-fixed-adjust">
<section class="hero">
<div class="mdc-shape-container four-corner-container">
<button class="mdc-button mdc-button--unelevated">Filled Button</button>
<div class="mdc-shape-container__corner mdc-shape-container__corner--top-left"></div>
<div class="mdc-shape-container__corner mdc-shape-container__corner--top-right"></div>
<div class="mdc-shape-container__corner mdc-shape-container__corner--bottom-right"></div>
<div class="mdc-shape-container__corner mdc-shape-container__corner--bottom-left"></div>
</div>
<div class="mdc-shape-container four-corner-container four-corner-container--stroked">
<button class="mdc-button mdc-button--stroked">Stroked Button</button>
<div class="mdc-shape-container__corner mdc-shape-container__corner--top-left"></div>
<div class="mdc-shape-container__corner mdc-shape-container__corner--top-right"></div>
<div class="mdc-shape-container__corner mdc-shape-container__corner--bottom-right"></div>
<div class="mdc-shape-container__corner mdc-shape-container__corner--bottom-left"></div>
</div>
</section>

<section class="demo-wrapper">
<h1 class="mdc-typography--display2">Button</h1>

<h2 class="mdc-typography--display1">Filled</h2>
<div class="mdc-shape-container two-corner-container">
<button class="mdc-button mdc-button--unelevated">Skip</button>
<div class="mdc-shape-container__corner mdc-shape-container__corner--top-left"></div>
<div class="mdc-shape-container__corner mdc-shape-container__corner--bottom-right"></div>
</div>
<div class="mdc-shape-container four-corner-container">
<button class="mdc-button mdc-button--unelevated">Finish</button>
<div class="mdc-shape-container__corner mdc-shape-container__corner--top-left"></div>
<div class="mdc-shape-container__corner mdc-shape-container__corner--top-right"></div>
<div class="mdc-shape-container__corner mdc-shape-container__corner--bottom-right"></div>
<div class="mdc-shape-container__corner mdc-shape-container__corner--bottom-left"></div>
</div>

<h2 class="mdc-typography--display1">Stroked</h2>
<div class="mdc-shape-container two-corner-container two-corner-container--stroked">
<button class="mdc-button mdc-button--stroked">Skip</button>
<div class="mdc-shape-container__corner mdc-shape-container__corner--top-left"></div>
<div class="mdc-shape-container__corner mdc-shape-container__corner--bottom-right"></div>
</div>
<div class="mdc-shape-container four-corner-container four-corner-container--stroked">
<button class="mdc-button mdc-button--stroked">Finish</button>
<div class="mdc-shape-container__corner mdc-shape-container__corner--top-left"></div>
<div class="mdc-shape-container__corner mdc-shape-container__corner--top-right"></div>
<div class="mdc-shape-container__corner mdc-shape-container__corner--bottom-right"></div>
<div class="mdc-shape-container__corner mdc-shape-container__corner--bottom-left"></div>
</div>

<h1 class="mdc-typography--display2">Card</h1>

<div class="mdc-shape-container card-container">
<div class="mdc-card mdc-card--stroked demo-card">
<a class="mdc-card__primary-action demo-card__primary-action" href="#">
<div class="demo-card__row">
<div class="mdc-card__media mdc-card__media--square demo-card__media"></div>
<div class="demo-card__info">
<div class="mdc-typography--headline">Title</div>
<div class="mdc-typography--body1">Body text</div>
</div>
</div>
</a>
</div>
<div class="mdc-shape-container__corner mdc-shape-container__corner--top-left"></div>
<div class="mdc-shape-container__corner mdc-shape-container__corner--top-right"></div>
<div class="mdc-shape-container__corner mdc-shape-container__corner--bottom-right"></div>
<div class="mdc-shape-container__corner mdc-shape-container__corner--bottom-left"></div>
</div>
</section>
</main>

<script src="/assets/material-components-web.js" async></script>
<script src="/assets/common.js" async></script>
<script>
demoReady(function() {
// Attach ripples to demonstrate corner masking
[].forEach.call(document.querySelectorAll('.mdc-button, .mdc-card__primary-action'), function(surface) {
mdc.ripple.MDCRipple.attachTo(surface);
});
});
</script>
</body>
</html>
94 changes: 94 additions & 0 deletions demos/shape.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
//
// 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 "./common";
@import "../packages/mdc-button/mdc-button";
@import "../packages/mdc-button/mixins";
@import "../packages/mdc-button/variables";
@import "../packages/mdc-card/mdc-card";
@import "../packages/mdc-card/variables";
@import "../packages/mdc-shape/mdc-shape";
@import "../packages/mdc-shape/mixins";

.demo-wrapper {
margin: 24px;
}

// Demo buttons
// (TODO: padding, possibly through new button mixins)

.two-corner-container {
@include mdc-shape-angled-corner($mdc-theme-background, $mdc-button-height / 4, 0);
}

.four-corner-container {
margin: 0 8px;
@include mdc-shape-angled-corner($mdc-theme-background, $mdc-button-height / 4 + 1);
}

.two-corner-container--stroked,
.four-corner-container--stroked {
@include mdc-shape-angled-corner-stroke(2px, $mdc-theme-primary);
}

.hero {
// Override background mask color for buttons in hero section
@include mdc-shape-angled-corner-background($hero-background-color);

// For whatever reason, this aligns the shape borders better in Chrome on OS X,
// as opposed to having the buttons centered side by side. Other browsers don't seem to have an issue.
flex-direction: column;

.four-corner-container {
margin: 8px 0;
}
}

// Demo card

.card-container {
@include mdc-shape-angled-corner($mdc-theme-background, 24px, 4px);
@include mdc-shape-angled-corner-stroke($mdc-card-stroke-width, $mdc-card-stroke-color);
}

.demo-card {
@include mdc-card-corner-radius(24px 4px);

@include mdc-rtl {
@include mdc-card-corner-radius(4px 24px);
}
}

.demo-card__row {
display: flex;
}

.demo-card__media {
background-image: url("/images/1-1.jpg");
width: 110px;
border-top-left-radius: inherit;

@include mdc-rtl {
border-top-left-radius: 0;
border-top-right-radius: inherit;
}
}

.demo-card__info {
display: flex;
flex-direction: column;
padding: 8px 16px;
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
"rtl",
"select",
"selection-control",
"shape",
"slider",
"snackbar",
"switch",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
@import "@material/radio/mdc-radio";
@import "@material/ripple/mdc-ripple";
@import "@material/select/mdc-select";
@import "@material/shape/mdc-shape";
@import "@material/slider/mdc-slider";
@import "@material/snackbar/mdc-snackbar";
@import "@material/switch/mdc-switch";
Expand Down
1 change: 1 addition & 0 deletions packages/material-components-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@material/rtl": "^0.34.0",
"@material/select": "^0.34.1",
"@material/selection-control": "^0.34.1",
"@material/shape": "^0.0.0",
"@material/slider": "^0.34.0",
"@material/snackbar": "^0.34.0",
"@material/switch": "^0.34.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/mdc-card/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
@include mdc-theme-prop(background-color, $color);
}

@mixin mdc-card-stroke($color, $thickness: 1px) {
@mixin mdc-card-stroke($color, $thickness: $mdc-card-stroke-width) {
border: $thickness solid mdc-theme-prop-value($color);
}

Expand Down
18 changes: 18 additions & 0 deletions packages/mdc-card/_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-card-stroke-color: #dbdbdb;
$mdc-card-stroke-width: 1px;
3 changes: 2 additions & 1 deletion packages/mdc-card/mdc-card.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
@import "@material/ripple/mixins";
@import "@material/rtl/mixins";
@import "./mixins";
@import "./variables";

// postcss-bem-linter: define card

Expand All @@ -31,7 +32,7 @@

.mdc-card--stroked {
@include mdc-elevation(0);
@include mdc-card-stroke(#dbdbdb);
@include mdc-card-stroke($mdc-card-stroke-color);
}

//
Expand Down
Loading

0 comments on commit dc87f18

Please sign in to comment.