This repository has been archived by the owner on Nov 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #134 from jamesplease/card
Elevation
- Loading branch information
Showing
9 changed files
with
166 additions
and
7 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,11 @@ | ||
class ElevationExample extends Component { | ||
render() { | ||
return ( | ||
<Elevation depth={2} style={{ padding: '20px' }}> | ||
This is an elevation with some content | ||
</Elevation> | ||
); | ||
} | ||
} | ||
|
||
return <ElevationExample />; |
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,21 @@ | ||
## Usage | ||
|
||
```jsx | ||
import { Elevation } from 'materialish'; | ||
import 'materialish/elevation.css'; | ||
``` | ||
|
||
## Props | ||
|
||
| Prop Name | Default Value | Required | Description | | ||
| --------- | ------------- | -------- | ----------------------------------------------------------------------------- | | ||
| className | | No | Additional class name(s) to add to the Elevation | | ||
| depth | 1 | No | A value between 0 and 5 that determines the magnitude of the visual elevation | | ||
| ...rest | | No | Other props are placed on the root element of the Avatar | | ||
|
||
## CSS Variables | ||
|
||
| Variable | Default Value | Description | | ||
| ----------------- | ------------- | ------------------------------------- | | ||
| --mt-baseFontSize | 1rem | The size of text within the elevation | | ||
| --mt-fontFamily | 'Roboto' | The font family to use for text | |
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,33 @@ | ||
.mt-elevation { | ||
font-size: var(--mt-baseFontSize, 1rem); | ||
font-family: var(--mt-fontFamily, 'Roboto'); | ||
background: #fff; | ||
border-radius: 0.125em; | ||
display: inline-block; | ||
position: relative; | ||
transition: box-shadow 0.3s cubic-bezier(0.25, 0.8, 0.25, 1); | ||
} | ||
|
||
mt-elevation-0 { | ||
box-shadow: none; | ||
} | ||
|
||
.mt-elevation-1 { | ||
box-shadow: 0 3px 1px -2px rgba(0, 0, 0, .2), 0 2px 2px 0 rgba(0, 0, 0, .14), 0 1px 5px 0 rgba(0, 0, 0, .12); | ||
} | ||
|
||
.mt-elevation-2 { | ||
box-shadow: 0 4px 5px -2px rgba(0, 0, 0, .2), 0 7px 10px 1px rgba(0, 0, 0, .14), 0 2px 16px 1px rgba(0, 0, 0, .12); | ||
} | ||
|
||
.mt-elevation-3 { | ||
box-shadow: 0 7px 8px -4px rgba(0, 0, 0, .2), 0 12px 17px 2px rgba(0, 0, 0, .14), 0 5px 22px 4px rgba(0, 0, 0, .12); | ||
} | ||
|
||
.mt-elevation-4 { | ||
box-shadow: 0 9px 11px -5px rgba(0, 0, 0, .2), 0 18px 28px 2px rgba(0, 0, 0, .14), 0 7px 34px 6px rgba(0, 0, 0, .12); | ||
} | ||
|
||
.mt-elevation-5 { | ||
box-shadow: 0 11px 15px -7px rgba(0, 0, 0, .2), 0 24px 38px 3px rgba(0, 0, 0, .14), 0 9px 46px 8px rgba(0, 0, 0, .12); | ||
} |
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,29 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
function clamp(min, val, max) { | ||
return Math.min(Math.max(min, val), max); | ||
} | ||
|
||
class Elevation extends Component { | ||
render() { | ||
const { className = '', depth = 1, ...props } = this.props; | ||
|
||
const depthToUse = Number.isNaN(depth) ? 1 : depth; | ||
const clampedDepth = clamp(0, depthToUse, 5); | ||
|
||
return ( | ||
<div | ||
className={`mt-elevation mt-elevation-${clampedDepth} ${className}`} | ||
{...props} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
Elevation.propTypes = { | ||
className: PropTypes.string, | ||
depth: PropTypes.oneOf([1, 2, 3, 4, 5]), | ||
}; | ||
|
||
export default Elevation; |
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,54 @@ | ||
import React from 'react'; | ||
import { storiesOf } from '@storybook/react'; | ||
import { setOptions } from '@storybook/addon-options'; | ||
import '../src/elevation/elevation.css'; | ||
import { Elevation } from '../src/index'; | ||
|
||
setOptions({ | ||
name: 'Materialish', | ||
addonPanelInRight: true, | ||
}); | ||
|
||
storiesOf('Elevation', module) | ||
.add('Depth - 0', () => ( | ||
<Elevation | ||
depth={0} | ||
style={{ width: '200px', height: '200px', padding: '20px' }}> | ||
This is an elevation with some content | ||
</Elevation> | ||
)) | ||
.add('Depth - 1', () => ( | ||
<Elevation | ||
depth={1} | ||
style={{ width: '200px', height: '200px', padding: '20px' }}> | ||
This is an elevation with some content | ||
</Elevation> | ||
)) | ||
.add('Depth - 2', () => ( | ||
<Elevation | ||
depth={2} | ||
style={{ width: '200px', height: '200px', padding: '20px' }}> | ||
This is an elevation with some content | ||
</Elevation> | ||
)) | ||
.add('Depth - 3', () => ( | ||
<Elevation | ||
depth={3} | ||
style={{ width: '200px', height: '200px', padding: '20px' }}> | ||
This is an elevation with some content | ||
</Elevation> | ||
)) | ||
.add('Depth - 4', () => ( | ||
<Elevation | ||
depth={4} | ||
style={{ width: '200px', height: '200px', padding: '20px' }}> | ||
This is an elevation with some content | ||
</Elevation> | ||
)) | ||
.add('Depth - 5', () => ( | ||
<Elevation | ||
depth={5} | ||
style={{ width: '200px', height: '200px', padding: '20px' }}> | ||
This is an elevation with some content | ||
</Elevation> | ||
)); |