Skip to content

Commit

Permalink
Use css variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecao committed Aug 6, 2020
1 parent 5d4ff5c commit a5930f1
Show file tree
Hide file tree
Showing 29 changed files with 131 additions and 85 deletions.
4 changes: 2 additions & 2 deletions components/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import classNames from 'classnames';
import Icon from './Icon';
import styles from './Button.module.css';

export default function Button({ icon, children, className, onClick }) {
export default function Button({ icon, type = 'button', children, className, onClick = () => {} }) {
return (
<button type="button" className={classNames(styles.button, className)} onClick={onClick}>
<button type={type} className={classNames(styles.button, className)} onClick={onClick}>
{icon && <Icon icon={icon} />}
{children}
</button>
Expand Down
9 changes: 1 addition & 8 deletions components/Button.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
justify-content: center;
align-items: center;
background: #f5f5f5;
padding: 4px 8px;
padding: 8px 16px;
border-radius: 4px;
border: 0;
outline: none;
Expand All @@ -13,10 +13,3 @@
.button:hover {
background: #eaeaea;
}

.button svg {
display: block;
width: 16px;
height: 16px;
margin-right: 8px;
}
2 changes: 1 addition & 1 deletion components/Dropdown.module.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.dropdown {
position: relative;
font-size: 14px;
font-size: var(--font-size-small);
min-width: 140px;
}

Expand Down
4 changes: 2 additions & 2 deletions components/Header.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}

.title {
font-size: 30px;
font-size: var(--font-size-large);
}

.nav {
Expand All @@ -19,7 +19,7 @@
}

.nav > * {
font-size: 14px;
font-size: var(--font-size-normal);
font-weight: 600;
margin-left: 40px;
}
6 changes: 4 additions & 2 deletions components/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React, { useState } from 'react';
import { Formik, Form, Field, ErrorMessage } from 'formik';
import Router from 'next/router';
import { post } from 'lib/web';
import Button from './Button';
import styles from './Login.module.css';

const validate = ({ username, password }) => {
const errors = {};
Expand Down Expand Up @@ -39,7 +41,7 @@ export default function Login() {
onSubmit={handleSubmit}
>
{() => (
<Form>
<Form className={styles.form}>
<h3>{message}</h3>
<div>
<label htmlFor="username">Username</label>
Expand All @@ -51,7 +53,7 @@ export default function Login() {
<Field name="password" type="password" />
<ErrorMessage name="password" />
</div>
<button type="submit">Submit</button>
<Button type="submit">Submit</Button>
</Form>
)}
</Formik>
Expand Down
6 changes: 6 additions & 0 deletions components/Login.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.form {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
4 changes: 2 additions & 2 deletions components/MetricCard.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
}

.value {
font-size: 36px;
font-size: var(--font-size-xlarge);
line-height: 40px;
min-height: 40px;
font-weight: 600;
}

.label {
font-size: 16px;
font-size: var(--font-size-normal);
}
6 changes: 6 additions & 0 deletions components/Page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from 'react';
import styles from './Page.module.css';

export default function Page({ children }) {
return <div className={styles.container}>{children}</div>;
}
8 changes: 8 additions & 0 deletions components/Page.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.container {
flex: 1;
display: flex;
flex-direction: column;
padding: 0 30px;
background: var(--gray50);
height: 100%;
}
8 changes: 4 additions & 4 deletions components/PageviewsChart.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@
flex-direction: column;
justify-content: center;
align-items: center;
color: #fff;
color: var(--gray50);
text-align: center;
}

.title {
font-size: 12px;
font-size: var(--font-size-xsmall);
font-weight: 600;
}

.metric {
display: flex;
justify-content: center;
align-items: center;
font-size: 14px;
font-size: var(--font-size-small);
font-weight: 600;
}

Expand All @@ -34,7 +34,7 @@
overflow: hidden;
border-radius: 100%;
margin-right: 8px;
background: #fff;
background: var(--gray50);
}

.color {
Expand Down
2 changes: 1 addition & 1 deletion components/QuickButtons.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function QuickButtons({ value, onChange }) {
{Object.keys(options).map(key => (
<Button
key={key}
className={classNames({ [styles.active]: value === key })}
className={classNames(styles.button, { [styles.active]: value === key })}
onClick={() => handleClick(key)}
>
{options[key]}
Expand Down
5 changes: 5 additions & 0 deletions components/QuickButtons.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
margin-left: 10px;
}

.button {
font-size: var(--font-size-xsmall);
padding: 4px 8px;
}

.active {
font-weight: 600;
}
Expand Down
18 changes: 12 additions & 6 deletions components/RankingsChart.module.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.container {
position: relative;
min-height: 430px;
font-size: 14px;
font-size: var(--font-size-small);
padding: 20px 0;
display: flex;
flex-direction: column;
Expand All @@ -15,11 +15,11 @@
.title {
flex: 1;
font-weight: 600;
font-size: 16px;
font-size: var(--font-size-normal);
}

.heading {
font-size: 14px;
font-size: var(--font-size-small);
text-align: center;
width: 100px;
}
Expand Down Expand Up @@ -61,7 +61,7 @@
position: relative;
width: 50px;
color: #6e6e6e;
border-left: 1px solid #8e8e8e;
border-left: 1px solid var(--gray600);
padding-left: 10px;
z-index: 1;
}
Expand All @@ -72,7 +72,7 @@
left: 0;
height: 30px;
opacity: 0.1;
background: #2680eb;
background: var(--primary400);
z-index: -1;
}

Expand All @@ -83,9 +83,15 @@

.body:empty:before {
content: 'No data available';
color: #b3b3b3;
color: var(--gray500);
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}

@media only screen and (max-width: 992px) {
.container {
min-height: auto;
}
}
5 changes: 3 additions & 2 deletions components/Settings.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React from 'react';
import Page from './Page';

export default function Settings() {
return (
<div>
<Page>
<h2>Settings</h2>
</div>
</Page>
);
}
2 changes: 1 addition & 1 deletion components/StickyHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default function StickyHeader({
ref={ref}
data-sticky={sticky}
className={classNames(className, { [stickyClassName]: sticky })}
{...(sticky && { style: stickyStyle })}
style={sticky ? { ...stickyStyle, width: ref?.current?.clientWidth } : null}
>
{children}
</div>
Expand Down
6 changes: 2 additions & 4 deletions components/WebsiteChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export default function WebsiteChart({
const [data, setData] = useState();
const [dateRange, setDateRange] = useState(getDateRange(defaultDateRange));
const { startDate, endDate, unit, value } = dateRange;
const container = useRef();

const [pageviews, uniques] = useMemo(() => {
if (data) {
Expand Down Expand Up @@ -54,11 +53,10 @@ export default function WebsiteChart({
}, [websiteId, startDate, endDate, unit]);

return (
<div ref={container}>
<>
<StickyHeader
className={classNames(styles.header, 'row')}
stickyClassName={styles.sticky}
stickyStyle={{ width: container?.current?.clientWidth }}
enabled={stickyHeader}
>
<MetricsBar
Expand Down Expand Up @@ -87,6 +85,6 @@ export default function WebsiteChart({
)}
</CheckVisible>
</div>
</div>
</>
);
}
6 changes: 3 additions & 3 deletions components/WebsiteChart.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
}

.title {
font-size: 24px;
font-size: var(--font-size-large);
line-height: 60px;
font-weight: 600;
}
Expand All @@ -20,7 +20,7 @@
position: fixed;
top: 0;
margin: auto;
background: #fff;
border-bottom: 1px solid #e1e1e1;
background: var(--gray50);
border-bottom: 1px solid var(--gray300);
z-index: 2;
}
5 changes: 3 additions & 2 deletions components/WebsiteDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import classNames from 'classnames';
import WebsiteChart from './WebsiteChart';
import RankingsChart from './RankingsChart';
import WorldMap from './WorldMap';
import Page from './Page';
import { getDateRange } from 'lib/date';
import { get } from 'lib/web';
import { browserFilter, urlFilter, refFilter, deviceFilter, countryFilter } from 'lib/filters';
Expand Down Expand Up @@ -41,7 +42,7 @@ export default function WebsiteDetails({ websiteId, defaultDateRange = '7day' })
}

return (
<div className={styles.container}>
<Page>
<div className="row">
<div className={classNames(styles.chart, 'col')}>
<h2>{data.label}</h2>
Expand Down Expand Up @@ -132,6 +133,6 @@ export default function WebsiteDetails({ websiteId, defaultDateRange = '7day' })
</div>
</>
)}
</div>
</Page>
);
}
13 changes: 4 additions & 9 deletions components/WebsiteDetails.module.css
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
.container {
background: #fff;
padding: 0 30px;
}

.chart {
margin-bottom: 30px;
}

.row {
border-top: 1px solid #e1e1e1;
border-top: 1px solid var(--gray300);
min-height: 430px;
}

.row > [class*='col-'] {
border-left: 1px solid #e1e1e1;
border-left: 1px solid var(--gray300);
padding: 0 20px;
}

Expand All @@ -26,13 +21,13 @@
padding-right: 0;
}

@media only screen and (max-width: 1000px) {
@media only screen and (max-width: 992px) {
.row {
border: 0;
}

.row > [class*='col-'] {
border-top: 1px solid #e1e1e1;
border-top: 1px solid var(--gray300);
border-left: 0;
padding: 0;
}
Expand Down
5 changes: 3 additions & 2 deletions components/WebsiteList.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useState, useEffect } from 'react';
import Link from './Link';
import WebsiteChart from './WebsiteChart';
import Page from './Page';
import Icon from './Icon';
import { get } from 'lib/web';
import Arrow from 'assets/arrow-right.svg';
Expand All @@ -18,7 +19,7 @@ export default function WebsiteList() {
}, []);

return (
<div className={styles.container}>
<Page>
{data &&
data.websites.map(({ website_id, label }) => (
<div key={website_id} className={styles.website}>
Expand All @@ -43,6 +44,6 @@ export default function WebsiteList() {
<WebsiteChart key={website_id} title={label} websiteId={website_id} />
</div>
))}
</div>
</Page>
);
}
Loading

0 comments on commit a5930f1

Please sign in to comment.