Skip to content

Commit def6875

Browse files
committed
Basic test fixed, add actual SideNav files, force rem replaced with px
1 parent b4cc405 commit def6875

17 files changed

+373
-67
lines changed

example/index.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,38 @@
11
import React from 'react'
22
import ReactDOM from 'react-dom'
33

4+
import SVG_MATERIAL_FAVORITE from 'svg-icon/dist/svg/material/favorite.svg'
5+
import SVG_MATERIAL_REFRESH from 'svg-icon/dist/svg/material/refresh.svg'
6+
7+
import _ from 'underscore'
8+
9+
10+
const items = [
11+
{
12+
label: 'Some Label',
13+
id: 'some',
14+
icon: SVG_MATERIAL_FAVORITE,
15+
Component: <div>SOme label</div>,
16+
},
17+
{
18+
label: 'The Fuck',
19+
id: 'the_fuck',
20+
icon: SVG_MATERIAL_REFRESH,
21+
Component: <div>The fuck</div>,
22+
},
23+
]
24+
25+
const ids = _.pluck(items, 'id')
26+
427
import OverwatchSideNav from '../lib'
528

629

730
ReactDOM.render(
8-
<OverwatchSideNav />,
31+
<div>
32+
<OverwatchSideNav
33+
items={items}
34+
ids={ids}
35+
/>
36+
</div>,
937
document.getElementById('app')
1038
)

example/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"devDependencies": {
88
"babel-core": "^6.24.1",
99
"babel-loader": "^7.0.0",
10+
"raw-loader": "^0.5.1",
1011
"react": "16.2.0",
1112
"react-dom": "16.2.0",
1213
"source-map-loader": "^0.2.3",
@@ -16,5 +17,9 @@
1617
"peerDependencies": {
1718
"react": ">=15.4.2",
1819
"react-dom": ">=15.4.2"
20+
},
21+
"dependencies": {
22+
"svg-icon": "^0.8.2",
23+
"underscore": "^1.8.3"
1924
}
2025
}

example/webpack.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ const config = {
2929
'source-map-loader',
3030
],
3131
},
32+
{
33+
test: /\.(svg)$/,
34+
use: ['raw-loader'],
35+
// exclude: /(node_modules)/,
36+
}
3237
]
3338

3439
},

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"README.md"
2929
],
3030
"dependencies": {
31+
"@likethemammal/general-components": "^0.1.12",
3132
"underscore": "^1.8.3"
3233
},
3334
"devDependencies": {

src/__tests__/components/CheckboxWithLabel.test.js

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/__tests__/components/SideNav.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React from 'react';
2+
import {shallow} from 'enzyme';
3+
4+
import general from '@likethemammal/general-components'
5+
6+
const shared = general.__tests__._shared.tests
7+
8+
import SideNav from '../../components/'
9+
import _ from 'underscore'
10+
11+
const items = [
12+
{
13+
label: 'Label',
14+
id: 'some_id',
15+
icon: [],
16+
Component: <div>test</div>,
17+
},
18+
{
19+
label: 'Test',
20+
id: 'slug',
21+
icon: [],
22+
Component: <div>The fuck</div>,
23+
},
24+
]
25+
26+
const ids = _.pluck(items, 'id')
27+
28+
describe('SideNav', () => {
29+
// Render a checkbox with label in the document
30+
const component = shallow(
31+
<SideNav
32+
items={items}
33+
id={ids}
34+
/>
35+
)
36+
37+
shared.SNAPSHOTS_SHOULD_MATCH([
38+
component
39+
])
40+
41+
})
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`CheckboxWithLabel Snapshot 0 should match 1`] = `undefined`;
3+
exports[`SideNav Snapshot 0 should match 1`] = `undefined`;

src/actions/example.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/components/Item.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import React, { Component } from 'react'
2+
3+
import css from './Item.less'
4+
5+
import general from '../../../../general-components/'
6+
7+
const { SVG } = general.components
8+
9+
class Item extends Component {
10+
static defaultProps = {
11+
className: css.container,
12+
defaultColor: '#323c50',
13+
textColor: 'white',
14+
activeColor: '#00c3ff'
15+
}
16+
17+
state = {
18+
hovered: false,
19+
}
20+
21+
onClick = () => {
22+
const { id, onHashChange } = this.props
23+
24+
onHashChange(`#${id}`)
25+
}
26+
27+
onMouseEnter = () => {
28+
this.setState({
29+
hovered: true,
30+
})
31+
}
32+
33+
onMouseLeave = () => {
34+
this.setState({
35+
hovered: false,
36+
})
37+
}
38+
39+
render() {
40+
41+
const {
42+
className,
43+
id,
44+
label,
45+
icon,
46+
hash,
47+
defaultColor,
48+
textColor,
49+
activeColor,
50+
} = this.props
51+
52+
const {
53+
hovered
54+
} = this.state
55+
56+
const active = hash === `#${id}`
57+
const colorStyle = {
58+
backgroundColor: active || hovered ? activeColor : defaultColor,
59+
color: textColor,
60+
}
61+
62+
const iconStyle = {
63+
fill: textColor,
64+
}
65+
66+
return <a
67+
href={`/#${id}`}
68+
className={className}
69+
onClick={this.onClick}
70+
>
71+
<div
72+
style={colorStyle}
73+
className={css.inner}
74+
onMouseEnter={this.onMouseEnter}
75+
onMouseLeave={this.onMouseLeave}
76+
>
77+
<div className={css.icon_container}>
78+
<SVG
79+
raw={icon}
80+
className={css.icon}
81+
style={iconStyle}
82+
/>
83+
</div>
84+
<div className={css.label}>
85+
{label}
86+
</div>
87+
</div>
88+
</a>
89+
}
90+
}
91+
92+
export default Item

src/components/Item.less

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
@import "../colors.less";
2+
3+
@item_height: 4.0rem;
4+
@icon_width: 4.3rem;
5+
@hover_padding_size: 1rem;
6+
7+
.container {
8+
composes: cf from '../../../../general-components/bin/general.css';
9+
position: relative;
10+
right: -100%;
11+
display: block;
12+
margin-left: -@icon_width - @hover_padding_size;
13+
padding-left: @hover_padding_size;
14+
padding-bottom: @hover_padding_size - 0.7rem;
15+
color: inherit;
16+
17+
transition: right 275ms ease;
18+
19+
&:hover {
20+
right: 0;
21+
}
22+
23+
box-sizing: border-box;
24+
}
25+
26+
.container * {
27+
box-sizing: border-box;
28+
}
29+
30+
.inner {
31+
text-align: center;
32+
border-radius: 5px 0 0 5px;
33+
34+
transition: 100ms linear;
35+
}
36+
37+
.icon_container {
38+
float: left;
39+
}
40+
41+
.icon {
42+
height: @item_height;
43+
width: @icon_width;
44+
padding: 0 0.8rem;
45+
background: rgba(0,0,0,0.1);
46+
border-radius: 3px 0 0 3px;
47+
composes: container from '../../../../general-components/bin/components/SVG.css';
48+
}
49+
50+
.label {
51+
display: inline-block;
52+
line-height: @item_height;
53+
padding-right: 13px;
54+
padding-left: 13px;
55+
font-size: 2rem;
56+
text-transform: uppercase;
57+
text-align: center;
58+
composes: _font_general from '../../../../general-components/bin/general.css';
59+
}

src/components/Root.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)