Skip to content

Commit b82551c

Browse files
committed
1 parent d32bfb8 commit b82551c

35 files changed

+1245
-19
lines changed

src/app.tsx

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,32 @@
1-
// auto create app container if missing
2-
let appContainer = document.getElementById('app-container');
3-
if (appContainer == null) {
4-
appContainer = document.createElement('div');
5-
appContainer.id = 'app-container';
6-
document.body.appendChild(appContainer);
7-
}
81
// lib imports
92
import * as React from 'react';
103
import * as ReactDOM from 'react-dom';
11-
// components imports
12-
import { Main } from './components/main';
13-
import { AppStore, UserData } from './stores/app-store';
4+
import { Provider } from 'react-redux';
5+
import { Router, Route, hashHistory } from 'react-router';
6+
import { syncHistoryWithStore } from 'react-router-redux';
7+
// app imports
8+
import { MainLayout } from './layouts/main-layout';
9+
import { HomeContainer } from './containers/home-container/index';
10+
import { AboutContainer } from './containers/about-container/index';
11+
import CurrencyConverterContainer from './containers/currency-converter-container/index';
1412

15-
const message = 'React / Redux / TypeScript - starter-kit';
16-
const appStore = new AppStore(new UserData('Piotr', 32));
17-
export var app: any = ReactDOM.render(<Main welcomeMessage={message} appStore={appStore} />, appContainer);
13+
import { store } from './store';
14+
const history = syncHistoryWithStore(hashHistory, store) as any;
1815

19-
// here you can customize hot-module-reload hook
20-
// you could also copy to other modules
21-
export function __reload(prev) {
22-
if (prev.app.state)
23-
app.setState(prev.app.state);
16+
function App() {
17+
return (
18+
<Provider store={store}>
19+
<Router history={history}>
20+
<Route component={MainLayout}>
21+
<Route path="/" component={HomeContainer}/>
22+
<Route path="/about" component={AboutContainer}/>
23+
<Route path="/currency-converter" component={CurrencyConverterContainer}/>
24+
</Route>
25+
</Router>
26+
</Provider>
27+
);
2428
}
29+
30+
export const app = ReactDOM.render(
31+
<App />, document.getElementById('app-container')
32+
);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import * as React from 'react';
2+
import classNames from 'classnames';
3+
import csjs from 'csjs';
4+
import insertCss from 'insert-css';
5+
6+
const styles = csjs`
7+
.outerStyle {
8+
border-bottom: 1px solid #e7e7e7;
9+
background-color: #f7f7f7;
10+
}
11+
.innerStyle {
12+
color: 'green';
13+
}
14+
`;
15+
insertCss(csjs.getCss(styles));
16+
17+
export function PageHeader({className = '', children = undefined}) {
18+
19+
const componentClass = classNames(
20+
className,
21+
styles.outerStyle.className
22+
);
23+
24+
return (
25+
<div className={componentClass}>
26+
<h3 className={styles.innerStyle}>{children}</h3>
27+
</div>
28+
);
29+
}

src/components/page-header.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as React from 'react';
2+
import classNames from 'classnames';
3+
4+
// const inlineStyles = {};
5+
6+
export function PageHeader({className = '', children = undefined}) {
7+
8+
const parentClass = classNames(
9+
className,
10+
'c-heading c-heading--medium',
11+
'u-centered'
12+
);
13+
14+
return (
15+
<header className={parentClass}>{children}</header>
16+
);
17+
}

src/components/page-hero.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import * as React from 'react';
2+
import classNames from 'classnames';
3+
4+
// const inlineStyles = {};
5+
6+
export function PageHero({className = '', children = undefined,
7+
title = '', subtitle = ''}) {
8+
9+
const parentClass = classNames(
10+
className,
11+
'c-hero',
12+
'u-letter-box--super u-centered'
13+
);
14+
15+
return (
16+
<section className={parentClass}>
17+
<header className="c-heading c-heading--xlarge u-window-box--none">
18+
{title}
19+
</header>
20+
<header className="c-heading c-heading--small u-window-box--none">
21+
{subtitle}
22+
</header>
23+
<div>
24+
{children}
25+
</div>
26+
</section>
27+
);
28+
}

src/components/page-section.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as React from 'react';
2+
import classNames from 'classnames';
3+
4+
const inlineStyles = {
5+
minHeight: { minHeight: '200px' }
6+
};
7+
8+
export function PageSection({className = '', children = undefined}) {
9+
10+
const parentClass = classNames(
11+
className,
12+
'o-grid'
13+
);
14+
const cellClass = classNames(
15+
'o-grid__cell'
16+
);
17+
18+
return (
19+
<section className={parentClass}>
20+
<div className={cellClass}>{children}</div>
21+
</section>
22+
);
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as React from 'react';
2+
import { PageSection } from '../../components/page-section';
3+
import { PageHeader } from '../../components/page-header';
4+
5+
export function AboutContainer() {
6+
return (
7+
<article>
8+
<PageHeader>About</PageHeader>
9+
<PageSection>
10+
<p>
11+
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
12+
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
13+
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
14+
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
15+
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
16+
non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
17+
</p>
18+
</PageSection>
19+
<br />
20+
<br />
21+
</article>
22+
);
23+
};
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// lib imports
2+
import * as React from 'react';
3+
4+
import { CurrencySelect } from './currency-select';
5+
import { CurrencyInput } from './currency-input';
6+
7+
interface LocalProps {
8+
currencies: Object;
9+
baseCurrency: string;
10+
targetCurrency: string;
11+
baseValue: string;
12+
targetValue: string;
13+
onBaseCurrencyChange: (newCurrency: string) => void;
14+
onTargetCurrencyChange: (newCurrency: string) => void;
15+
onBaseValueChange: (newCurrency: string) => void;
16+
onTargetValueChange: (newCurrency: string) => void;
17+
}
18+
19+
interface LocalState {
20+
}
21+
22+
export class CurrencyConverter extends React.Component<LocalProps, LocalState> {
23+
render(): JSX.Element {
24+
const {
25+
currencies,
26+
baseCurrency,
27+
targetCurrency,
28+
baseValue,
29+
targetValue,
30+
onBaseCurrencyChange,
31+
onTargetCurrencyChange,
32+
onBaseValueChange,
33+
onTargetValueChange,
34+
} = this.props;
35+
36+
return (
37+
<div className="o-grid o-grid--small-full o-grid--medium-full">
38+
<div className="o-grid__cell">
39+
<CurrencySelect
40+
currencies={currencies}
41+
selectedCurrency={baseCurrency}
42+
onChange={onBaseCurrencyChange}
43+
/>
44+
<CurrencyInput
45+
value={baseValue}
46+
onChange={onBaseValueChange}
47+
/>
48+
</div>
49+
<div className="o-grid__cell">
50+
<CurrencySelect
51+
currencies={currencies}
52+
selectedCurrency={targetCurrency}
53+
onChange={onTargetCurrencyChange}
54+
/>
55+
<CurrencyInput
56+
value={targetValue}
57+
onChange={onTargetValueChange}
58+
/>
59+
</div>
60+
</div>
61+
);
62+
}
63+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import * as React from 'react';
2+
3+
export function CurrencyInput({value, onChange}) {
4+
return (
5+
<div className="u-letter-box--medium">
6+
<input
7+
className="c-field c-field--xlarge"
8+
type="text"
9+
value={value}
10+
onChange={onChange}
11+
onBlur={onChange}
12+
/>
13+
</div>
14+
);
15+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import * as React from 'react';
2+
3+
export function CurrencySelect({currencies, selectedCurrency, onChange}) {
4+
return (
5+
<select className="c-choice c-choice--padded"
6+
value={selectedCurrency} onChange={onChange}>
7+
{currencies.map(currency =>
8+
<option key={currency}>{currency}</option>
9+
)}
10+
</select>
11+
);
12+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import * as React from 'react';
2+
import { CurrencyValuationHeaderSelect } from './currency-valuation-header-select';
3+
import { CurrencyValuationHeaderCalendar } from './currency-valuation-header-calendar';
4+
5+
const DEFAULT_DATE = (new Date()).toISOString();
6+
7+
export function CurrencyValuationChange({changeValue, changePercent,
8+
type = 'Select', fromCurrency, toCurrency,
9+
onChange = null, onCalendarStartDateChange = null, onCalendaEndDateChange = null,
10+
selectedPeriod = '60', selectedStartDate = DEFAULT_DATE, selectedEndDate = DEFAULT_DATE }) {
11+
12+
const positive = parseFloat(changeValue) >= 0;
13+
const signClass = positive ? 'c-link--success' : 'c-link--error';
14+
const signedValue = positive ? '+' + changeValue : changeValue;
15+
16+
const positivePercent = parseFloat(changePercent) >= 0;
17+
const signClassPercent = positivePercent ? 'c-link--success' : 'c-link--error';
18+
const signedValuePercent = positivePercent ? '+' + changePercent : changePercent;
19+
20+
return (
21+
<div className="c-card--high">
22+
<div className="c-card__item u-letter-box--medium">
23+
{type === 'Select'
24+
? <CurrencyValuationHeaderSelect fromCurrency={fromCurrency} toCurrency={toCurrency}
25+
selectedPeriod={selectedPeriod} onChange={onChange} />
26+
: <CurrencyValuationHeaderCalendar fromCurrency={fromCurrency} toCurrency={toCurrency}
27+
selectedStartDate={selectedStartDate} selectedEndDate={selectedEndDate} onCalendarStartDateChange={onCalendarStartDateChange}
28+
onCalendaEndDateChange={onCalendaEndDateChange} />
29+
}
30+
</div>
31+
<div className="c-card__item u-pillar-box--super">
32+
Change:
33+
<span className={`c-link c-link--right ${signClass}`}>
34+
{signedValue}
35+
</span>
36+
</div>
37+
<div className="c-card__item u-pillar-box--super">
38+
Change%:
39+
<span className={`c-link c-link--right ${signClassPercent}`}>
40+
{signedValuePercent}%
41+
</span>
42+
</div>
43+
</div>
44+
);
45+
}

0 commit comments

Comments
 (0)