Skip to content

Commit 560e475

Browse files
authored
Merge pull request #5 from Codebrahma/card
Card
2 parents 9b8f0f8 + b30e7b0 commit 560e475

File tree

9 files changed

+194
-96
lines changed

9 files changed

+194
-96
lines changed

.babelrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"presets": ["env", "react"]
2+
"presets": ["env", "react", "es2015", "es2017", "babel-preset-stage-3"]
33
}

package-lock.json

Lines changed: 46 additions & 91 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"devDependencies": {
2020
"babel-core": "^6.26.0",
2121
"babel-loader": "^7.1.4",
22+
"babel-plugin-transform-object-rest-spread": "^6.26.0",
2223
"babel-preset-env": "^1.6.1",
2324
"babel-preset-react": "^6.24.1",
2425
"css-loader": "^0.28.11",
@@ -42,7 +43,12 @@
4243
},
4344
"dependencies": {
4445
"babel-eslint": "^8.2.3",
46+
"babel-preset-es2015": "^6.24.1",
47+
"babel-preset-es2017": "^6.24.1",
48+
"babel-preset-stage-3": "^6.24.1",
49+
"classnames": "^2.2.6",
4550
"react": "^16.3.2",
51+
"react-css-themr": "^2.1.2",
4652
"react-dom": "^16.3.2"
4753
}
4854
}

src/card/defaultTheme.scss

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
:local(.card) {
2+
background: #FFFFFF;
3+
border-radius: 3px;
4+
padding: 10px;
5+
min-width: 300px;
6+
}
7+
8+
:local(.noPadding) {
9+
padding: 0;
10+
}
11+
12+
:local(.wrapContent) {
13+
display: inline-block;
14+
}
15+
16+
:local(.elevation-low) {
17+
box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14),
18+
0 3px 1px -2px rgba(0, 0, 0, 0.2),
19+
0 1px 5px 0 rgba(0, 0, 0, 0.12);
20+
}
21+
22+
:local(.elevation-medium) {
23+
box-shadow: 0 4px 5px 0 rgba(0, 0, 0, 0.14),
24+
0 1px 10px 0 rgba(0, 0, 0, 0.12),
25+
0 2px 4px -1px rgba(0, 0, 0, 0.2);
26+
}
27+
28+
:local(.elevation-high) {
29+
box-shadow: 0 16px 24px 2px rgba(0, 0, 0, 0.14),
30+
0 6px 30px 5px rgba(0, 0, 0, 0.12),
31+
0 8px 10px -5px rgba(0, 0, 0, 0.2);
32+
}
33+
34+
:local(.cardHeader) {
35+
font-weight: bold;
36+
font-size: 18px;
37+
padding: 5px 0;
38+
}

src/card/index.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import { themr } from 'react-css-themr';
4+
import classnames from 'classnames';
5+
import defaultTheme from './defaultTheme.scss';
6+
7+
const Card = ({
8+
children,
9+
className,
10+
theme,
11+
wrapContent,
12+
elevation,
13+
noPadding,
14+
header, ...other
15+
}) => {
16+
const classes = classnames(theme.card, theme[`elevation-${elevation}`],{
17+
[theme.wrapContent]: wrapContent,
18+
[theme.noPadding]: noPadding,
19+
}, className);
20+
const headerClass = classnames(theme.cardHeader);
21+
let cardHeader;
22+
if (typeof header === 'string') {
23+
cardHeader = (<div className={headerClass}>
24+
<span>{header}</span>
25+
</div>)
26+
} else if(typeof header === 'function') {
27+
cardHeader = header();
28+
}
29+
30+
return (
31+
<div data-react-toolbox="card" className={classes} {...other}>
32+
{cardHeader}
33+
{children}
34+
</div>
35+
);
36+
};
37+
38+
Card.prototype = {
39+
theme: PropTypes.object,
40+
wrapContent: PropTypes.bool,
41+
noPadding: PropTypes.bool,
42+
elevation: PropTypes.oneOf(['low', 'medium', 'high']),
43+
header: PropTypes.oneOf([PropTypes.string, PropTypes.func]),
44+
}
45+
46+
Card.defaultProps = {
47+
elevation: 'low',
48+
}
49+
50+
export default themr('CBCard', defaultTheme)(Card);

src/card/readMe.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## Card
2+
3+
The base card component.
4+
5+
### Properties
6+
| Name | Type | Default | Description |
7+
|:-----|:-----|:-----|:-----|
8+
| `children` | `Any` | | All child component to be rendered inside a cardview |
9+
| `className` | `String` | | Additional class(es) for custom styling. These classes will be added along with library specific styles |
10+
| `wrapContent` | `Boolean` | `false` | If `true` sets the width of the parent card to width of its content else sets width to maximum available width inside its parent |
11+
| `elevation` | `String` | `low` | This set elevation/depth of shadow of the card. The possible values are `low`, `medium`,`high` |
12+
| `noPadding` | `Boolean` | `false` | If `true` card container will not give padding by default |
13+
| `header` | `String`/`Component` | | If a string is supplied, it will set as title of card with library specific styling. If a React component is supplied that component will be renderd as a header |
14+
15+
### Theme
16+
17+
| Name | Description|
18+
|:---------|:-----------|
19+
| `card` | Class used for the root element.|
20+
| `cardHeader` | Class used for header component if card renders header by itself |
21+
22+
### Usage
23+
```
24+
<Card
25+
header='Card String header'
26+
wrapContent
27+
noPadding
28+
theme={customTheme}>
29+
<span>Card Content</span>
30+
<span>Card Content</span>
31+
<span>Card Content</span>
32+
</Card>
33+
```

src/customcard.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
:local(.card) {
2+
border-radius: 4px;
3+
}
4+
5+
:local(.cardHeader) {
6+
color: gray;
7+
}

src/index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
3+
import Card from './card';
4+
import customTheme from './customcard.scss';
35

46
const Index = () => (
57
<div>
6-
Hello React!
8+
<Card
9+
header='Card String header'
10+
wrapContent
11+
theme={customTheme}>
12+
<span>Card Content</span>
13+
<span>Card Content</span>
14+
<span>Card Content</span>
15+
</Card>
716
</div>
817
);
918

webpack.common.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const path = require('path');
22
const HtmlWebPackPlugin = require('html-webpack-plugin');
33
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
44
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
5-
5+
const path = require('path');
66
const devMode = process.env.NODE_ENV !== 'production';
77
const htmlWebpackPlugin = new HtmlWebPackPlugin({
88
template: './src/index.html',
@@ -35,7 +35,7 @@ module.exports = {
3535
},
3636
{
3737
test: /\.scss$/,
38-
include: path.resolve(__dirname, 'docs'),
38+
include: path.resolve(__dirname, './src'),
3939
use: [
4040
'style-loader',
4141
'css-loader',
@@ -46,7 +46,7 @@ module.exports = {
4646
},
4747
plugins: [
4848
htmlWebpackPlugin,
49-
new BundleAnalyzerPlugin(),
49+
// new BundleAnalyzerPlugin(),
5050
new MiniCssExtractPlugin({
5151
filename: devMode ? '[name].css' : '[name].[hash].css',
5252
chunkFilename: devMode ? '[id].css' : '[id].[hash].css',

0 commit comments

Comments
 (0)