This repository has been archived by the owner on Sep 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
140 lines (128 loc) · 4.19 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import * as React from 'react';
import ReactDOM from 'react-dom';
import { Sidebar } from './pages/components/Sidebar';
import Colours from './pages/Colors';
import ColourUse from './pages/ColorUse';
import ButtonColours from './pages/ButtonColours';
import Typography from './pages/Typography';
import Tables from './pages/Tables';
import Language from './pages/Language';
import { Buttons } from './pages/Buttons';
import ThemeBuilder from './pages/ThemeBuilder';
import * as styles from './index.css';
import { loadCSSFromTheme, themeActive, resetTheme } from './themeManager';
import IconsAndMedia from './pages/IconsAndMedia';
import Navigation from './pages/Navigation';
import Animation from './pages/Animation';
import CaseHeaders from './pages/CaseHeaders';
import Notifications from './pages/Notifications';
import ContentContainers from './pages/ContentContainers';
import FormElements from './pages/FormElements';
import BannerSVG from './pages/assets/banner.svg';
import { NavigationPage } from './pages/NavigationPages';
import { Links } from './pages/Links';
import { PageHeadings } from './pages/PageHeadings';
import { FastLinks } from './pages/FastLinks';
import { Microcopy } from './pages/Microcopy';
import { Badges } from './pages/Badges';
import { WidgetPages } from './pages/WidgetPages';
import { PageText } from './pages/PageText';
import { UXPrinciples } from './pages/UXPrinciples';
import { Breadcrumbs } from './pages/Breadcrumbs';
import { NavigationBar } from './pages/NavigationBar';
import { Tabs } from './pages/Tabs';
import { DeviceBreakpoints } from './pages/DeviceBreakpoints';
import { HomePage } from './pages/HomePage';
import { PageNotFound } from './pages/PageNotFound';
const PAGES = {
home: HomePage,
'/animation': Animation,
'/badges': Badges,
'/breadcrumbs': Breadcrumbs,
'/buttons': Buttons,
'/button-colours': ButtonColours,
'/case-headers': CaseHeaders,
'/colours': Colours,
'/colour-use': ColourUse,
'/content-containers': ContentContainers,
'/device-breakpoints': DeviceBreakpoints,
'/fast-links': FastLinks,
'/forms': FormElements,
'/icons_and_media': IconsAndMedia,
'/language': Language,
'/microcopy': Microcopy,
'/navigation': Navigation,
'/navigation-bar': NavigationBar,
'/navigation-pages': NavigationPage,
'/notifications': Notifications,
'/page-headings': PageHeadings,
'/page-text': PageText,
'/tabs': Tabs,
'/tables': Tables,
'/typography': Typography,
'/theme': ThemeBuilder,
'/ux-principles': UXPrinciples,
'/widget-pages': WidgetPages,
'/links': Links,
unknown: PageNotFound
};
const Banner = () => (
<div id={styles.banner}>
<BannerSVG />
</div>
);
class App extends React.Component {
constructor(props) {
super(props);
loadCSSFromTheme();
let path = window.location.pathname;
if (window.location.search && window.location.search !== '') {
path = location.search.replace('?p=', '');
}
this.state = { path };
this.handleClick = this.handleClick.bind(this);
window.onpopstate = e => {
if (e.state) {
this.setState({ path: e.state.path });
}
};
}
renderResetWarning() {
return (
<div className="alert alert-warning">
<button onClick={resetTheme}>Reset</button> There are theme
customisations active
</div>
);
}
handleClick(path) {
this.setState({ path });
const url = window.location.href.replace(/\/[^\/]*$/, path);
window.history.pushState({}, '', url);
}
render() {
const { path } = this.state;
let page = 'unknown';
if (['/', '', 'index.html', '/styleguide/'].includes(path) || !path) {
page = 'home';
} else if (Object.keys(PAGES).includes(path)) {
page = path;
}
const Page = PAGES[page];
return (
<React.Fragment>
{themeActive() ? this.renderResetWarning() : null}
<div className={styles.container}>
<div className={styles.sidebar}>
<Sidebar onClick={this.handleClick} />
</div>
<div className={styles.content}>
<Banner />
<Page onClick={this.handleClick} />
</div>
</div>
</React.Fragment>
);
}
}
ReactDOM.render(<App />, document.getElementById('content'));