forked from bulwark-crypto/bulwark-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
226 additions
and
0 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,44 @@ | ||
import Chart from 'chart.js' | ||
import PropTypes from 'prop-types' | ||
import React from 'react' | ||
import ReactChartKick, {LineChart} from 'react-chartkick' | ||
import {pickRest} from '../lib/utils' | ||
|
||
ReactChartKick.addAdapter(Chart) | ||
|
||
export const ChartLine = (props) => { | ||
const [mods, {data, links, subtitle, title, ...rest}] = pickRest(props, []) | ||
|
||
return ( | ||
<div block='chart' mods={mods} {...rest}> | ||
<div block='chart' elem='head'> | ||
<div block='chart__head' elem='title'>{title}</div> | ||
{!!subtitle && <div block='chart__head' elem='subtitle'>{subtitle}</div>} | ||
<div block='chart__head' elem='flex' /> | ||
{Array.isArray(links) && | ||
<div block='chart__head' elem='links'> | ||
{links.map(l => ( | ||
<a className={l.active ? 'active' : ''} key={l.text} onClick={l.onClick}>{l.text}</a> | ||
))} | ||
</div> | ||
} | ||
</div> | ||
<div block='chart' elem='body'> | ||
<LineChart data={data} {...rest} /> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
ChartLine.propTypes = { | ||
data: PropTypes.object.isRequired, | ||
links: PropTypes.arrayOf(PropTypes.shape({ | ||
active: PropTypes.bool, | ||
onClick: PropTypes.func.isRequired, | ||
text: PropTypes.string.isRequired | ||
})), | ||
subtitle: PropTypes.string, | ||
title: PropTypes.string.isRequired | ||
} | ||
|
||
export default {ChartLine} |
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,52 @@ | ||
|
||
.chart { | ||
background-color: $black; | ||
border-radius: 10px; | ||
box-shadow: 0 0 5px 0 rgba(0, 0, 0, 0.25); | ||
color: $white; | ||
|
||
&__body { | ||
padding: 0 24px 24px 24px; | ||
text-align: center; | ||
} | ||
|
||
&__head { | ||
display: flex; | ||
flex-direction: row; | ||
padding: 32px 24px; | ||
|
||
* { display: inline-block; } | ||
|
||
&__flex { flex: 1; } | ||
|
||
&__links { | ||
a { | ||
color: $secondary; | ||
cursor: pointer; | ||
font-size: 14px; | ||
font-weight: 500; | ||
line-height: 19px; | ||
margin-right: 56px; | ||
|
||
&:last-child { margin-right: 0; } | ||
|
||
&.active { color: $white; } | ||
} | ||
} | ||
|
||
&__subtitle { | ||
font-size: 14px; | ||
line-height: 19px; | ||
padding-top: 11px; | ||
} | ||
|
||
&__title { | ||
font-family: $font-secondary; | ||
font-size: 24px; | ||
font-weight: bold; | ||
letter-spacing: -1px; | ||
line-height: 35px; | ||
margin-right: 10px; | ||
} | ||
} | ||
} |
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,31 @@ | ||
/* global describe, it */ | ||
import React from 'react' | ||
import expect from 'must' | ||
import { shallow } from 'enzyme' | ||
import {ChartLine} from '../react/Chart' | ||
|
||
const data = {} | ||
const keys = [1.1, 1.2301, 1.32, 1.30, 1.4, 1.5, 1.6] | ||
keys.forEach((k, i) => { data[i] = k }) | ||
|
||
describe('<ChartLine />', () => { | ||
const links = [ | ||
{active: true, onClick: () => {}, text: 'One'}, | ||
{onClick: () => {}, text: 'Two'} | ||
] | ||
const wrapper = shallow( | ||
<ChartLine data={data} links={links} subtitle='Sub' title='Test' /> | ||
) | ||
|
||
it('renders as a div', () => { | ||
expect(wrapper.is('div')).to.be.true() | ||
}) | ||
|
||
it('renders body, links, subtitle, and title', () => { | ||
expect(wrapper.find('.chart__body')).to.have.length(1) | ||
expect(wrapper.find('.chart__head')).to.have.length(1) | ||
expect(wrapper.childAt(0).find('.chart__head__title')).to.have.length(1) | ||
expect(wrapper.childAt(0).find('.chart__head__subtitle')).to.have.length(1) | ||
expect(wrapper.childAt(0).find('.chart__head__links')).to.have.length(1) | ||
}) | ||
}) |
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,52 @@ | ||
import React from 'react' | ||
|
||
import {ChartLine} from '../../react/Chart' | ||
|
||
const data = {} | ||
const keys = [1.1, 1.2301, 1.32, 1.30, 1.4, 1.5, 1.6] | ||
keys.forEach((k, i) => { data[i] = k }) | ||
|
||
const ButtonDemo = () => ( | ||
<div> | ||
<h3>Chart</h3> | ||
<ChartLine | ||
data={data} | ||
colors={['#ffffff']} | ||
legend={false} | ||
library={{ | ||
scales: { | ||
xAxes: [{gridLines: {display: false}, ticks: {display: false}}], | ||
yAxes: [{gridLines: {display: false}}] | ||
}, | ||
tooltips: { | ||
backgroundColor: '#ffffff', | ||
bodyFontColor: '#252525', | ||
bodyFontFamily: "'Roboto', sans-serif", | ||
bodyFontSize: 14, | ||
bodySpacing: 2, | ||
caretPadding: 9, | ||
cornerRadius: 5, | ||
footerFontSize: 0, | ||
titleFontSize: 0, | ||
titleMarginBottom: 0, | ||
titleSpacing: 0, | ||
xPadding: 20, | ||
yPadding: 6 | ||
} | ||
}} | ||
links={[ | ||
{active: true, onClick: f => f, text: '1 Day'}, | ||
{onClick: f => f, text: '1 Week'}, | ||
{onClick: f => f, text: '1 Month'} | ||
]} | ||
max={1.6} | ||
messages={{empty: 'No data'}} | ||
min={1.1} | ||
prefix='$' | ||
subtitle='Data courtesy of CoinMarketCap' | ||
thousands=',' | ||
title='Bulwark Price' /> | ||
</div> | ||
) | ||
|
||
export default ButtonDemo |
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