Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(shape): Added new Shape APIs #3541

Merged
merged 27 commits into from
Sep 20, 2018
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
789e631
feat(shape): added shape APIs and updated README.
abhiomkar Aug 31, 2018
645a644
feat(shape): Updated shape API to accept component height instead of …
abhiomkar Aug 31, 2018
93758b9
feat(shape): Removed old shape demos from here
abhiomkar Aug 31, 2018
fdba967
feat(shape): Updated shape categories
abhiomkar Aug 31, 2018
e15d2cc
feat(shape): Updated shape pill resolve functions
abhiomkar Aug 31, 2018
3a1de82
feat(shape): Remove height info from shapes
abhiomkar Aug 31, 2018
98dafb4
feat(shape): Updated README and mixins
abhiomkar Sep 10, 2018
d2f8495
feat(shape): Use prop-value function when validating radius
abhiomkar Sep 10, 2018
2b8e864
feat(shape): Simplified shape mixin & functions
abhiomkar Sep 10, 2018
dc4be29
feat(shape): Updates to README
abhiomkar Sep 10, 2018
4585758
feat(shape): Added docs for functions.scss
abhiomkar Sep 10, 2018
9f3a6dd
feat(shape): Minor doc updates
abhiomkar Sep 10, 2018
d68700d
feat(shape): Updates to shape category value
abhiomkar Sep 10, 2018
82acafe
Merge branch 'feat/shape' into feat/shape_api
abhiomkar Sep 11, 2018
68b4794
feat(shape): Updated travis yml to include shape feat branch
abhiomkar Sep 11, 2018
2047412
feat(shape): Updated README for functions
abhiomkar Sep 12, 2018
71c1e50
feat(shape): Added support for percentage
abhiomkar Sep 12, 2018
2c9d160
feat(shape): Updated docs for percentage radius changes
abhiomkar Sep 12, 2018
d100ff1
feat(shape): Updated is-valid radius function for percentage radius
abhiomkar Sep 12, 2018
f85d500
feat(shape): Updated README to mention it supports only rounded
abhiomkar Sep 12, 2018
637fa38
feat(shape): Renamed global variables to include *-surface-* term
abhiomkar Sep 12, 2018
faa032c
feat(shape): Reorganized README
abhiomkar Sep 13, 2018
3a3afc6
feat(shape): Code comment for extracting number from percentage
abhiomkar Sep 14, 2018
b3067cd
feat(list): Changes for review comments
abhiomkar Sep 17, 2018
b5dc384
feat(shape): Made prop-value mixin private
abhiomkar Sep 17, 2018
6241ada
fix(shape): changes for review comments
abhiomkar Sep 18, 2018
b55ee00
fix(shape): changes for review comments
abhiomkar Sep 20, 2018
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ branches:
# This prevents excessive resource usage and CI slowness.
only:
- master
- feat/shape

before_install:
# Source the scripts to export their env vars. See https://superuser.com/a/176788/62792
Expand Down
127 changes: 0 additions & 127 deletions demos/shape.html

This file was deleted.

100 changes: 0 additions & 100 deletions demos/shape.scss

This file was deleted.

100 changes: 49 additions & 51 deletions packages/mdc-shape/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ path: /catalog/shape/

Shapes direct attention, identify components, communicate state, and express brand.

Many MDC Web components include direct support for rounded corners; this package provides additional support for
applying angled corners to unelevated surfaces.
> Currently shape system for web only supports rounded corners.

## Design & API Documentation

Expand All @@ -38,72 +37,71 @@ npm install @material/shape

## Basic Usage

### HTML
### Styles

The markup for angled corners involves a container element, and one element per angled corner.
```scss
@import "@material/shape/mixins";
@import "@material/shape/functions";
```

The following example demonstrates angled corners applied to a MDC Button, but this technique may be applied to any
unelevated component.
## Style Customization

```html
<div class="mdc-shape-container my-shape-container">
<button class="mdc-button mdc-button--unelevated">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>
```
### Sass Variables

> **Note:** Each angled corner should have its own `<div>` element. Any corner that will not be cut (i.e. its size is 0)
> does not need a dedicated element.
Components are categorized as small, medium and large in shape system. Overriding below sass variables applies shape (rounded) to respective categories. For example, overriding `$mdc-shape-medium-radius` variable would apply shape to all components that belong to medium category.

### Styles
Variable | Description
--- | ---
`$mdc-shape-small-surface-radius` | Rounded shape radius size for small surface components. Default value `4px`.
`$mdc-shape-medium-surface-radius` | Rounded shape radius size for medium surface components. Default value `8px`.
`$mdc-shape-large-surface-radius` | Rounded shape radius size for large surface components. Default value `0`.

```scss
@import "@material/shape/mdc-shape"; // The base shape styles need to be imported once in the page or application
@import "@material/shape/mixins";
Please refer [Material Design guidelines: Shape](https://material.io/go/design-shape) to learn about how components are categorized.

.my-shape-container {
@include mdc-shape-angled-corner(#fff, 10px);
}
```
### Sass Mixins

Mixin | Description
--- | ---
`mdc-shape-radius($radius, $rtl-reflexive)` | Shape API used by all other components to apply radius to appropriate corners. `$radius` can be single value or list of up to 4 radius corner values. Set `$rtl-reflexive` to true to flip the radius in RTL case, `false` by default.

## Variants
> Use `mdc-shape-resolve-percentage-radius` sass function to resolve percentage unit value to absolute radius value.

### Outlined Angled Corners
### Sass Functions

Outlined angled corners involve the same markup and styles/imports as above, with the addition of including a mixin for
outline:
Function | Description
--- | ---
`mdc-shape-flip-radius($radius)` | Flips the radius values in RTL context. $radius is list of 2-4 corner values.
abhiomkar marked this conversation as resolved.
Show resolved Hide resolved
`mdc-shape-resolve-percentage-radius($component-height, $radius)` | Calculates the absolute radius value based on its component height. Use this for fixed height components only.
`mdc-shape-mask-top-radius($radius)` | Accepts radius number or list of 2 radius values and returns 4 value list with top-left value, top-right value, bottom-right 0, bottom-left 0. Throws error when length of radius is more than 2.
abhiomkar marked this conversation as resolved.
Show resolved Hide resolved

### Additional Information

#### Shapes for fixed height components

Styles for applying shape to a fixed height component such as button looks like this:

```scss
.my-shape-container {
@include mdc-shape-angled-corner(#fff, 10px);
@include mdc-shape-angled-corner-outline(2px, blue);
}
@include mdc-shape-radius(mdc-shape-resolve-percentage-radius($mdc-button-height, $radius));
```

## Style Customization
Where, `$mdc-button-height` is the height of standard button and `$radius` is the size of shape. `mdc-shape-resolve-percentage-radius` function is used to resolve percentage unit value to absolute `$radius` value based on component height.

### CSS Classes
#### Shapes for dynamic height components

CSS Class | Description
--- | ---
`mdc-shape-container` | Mandatory. Parent element containing the component to be masked.
`mdc-shape-container__corner` | Mandatory. Element for masking a specific corner; there may be up to 4.
`mdc-shape-container__corner--bottom-left` | Element for masking the bottom left corner of the component.
`mdc-shape-container__corner--bottom-right` | Element for masking the bottom right corner of the component.
`mdc-shape-container__corner--top-left` | Element for masking the top left corner of the component.
`mdc-shape-container__corner--top-right` | Element for masking the top right corner of the component.
Styles for applying shapes to dynamic height component such as card looks like this:

### Sass Mixins
```scss
@include mdc-shape-radius($radius);
```

Mixin | Description
--- | ---
`mdc-shape-angled-corner($background-color, $top-left-size[, $top-right-size, $bottom-right-size, $bottom-left-size])` | Applies styles for masking angled corners, using the given background color and corner sizes. If fewer than 4 corner sizes are specified, the mixin automatically determines the other corners similarly to CSS `border-radius`.
`mdc-shape-angled-corner-background($background-color)` | Sets the background color used to mask angled corners. Useful for styling a subset of components in a section with a different background color.
`mdc-shape-angled-corner-outline($outline-width, $outline-color[, $outline-style])` | Applies outline styles to angled corners. `$outline-style` defaults to `solid`.
Where, `$radius` is absolute value only.

#### Shapes for components on specific corners

> **Note:** When mentioned above, "background color" specifically refers to the color of the background behind the surface (_not_ the fill color of the surface). These mixins operate by masking the corners of the surface to match the background.
Styles for applying shapes for specific corners such as drawer looks like this:

```scss
@include mdc-shape-radius((0, $radius, $radius, 0), $rtl-reflexive: true);
abhiomkar marked this conversation as resolved.
Show resolved Hide resolved
```

> **Note:** These mixins should be included in the context of the container element (or an ancestor) in order to apply styles to the corner elements.
Where, only top-right & bottom-right corners are customizable and it automatically flips radius values based on RTL context when `$rtl-reflexive` is set to true.
Loading