Skip to content

Commit

Permalink
Merge branch 'feat/dark-mode'
Browse files Browse the repository at this point in the history
  • Loading branch information
paultibbetts committed Jun 28, 2020
2 parents a8f40d9 + e677c76 commit 38b319a
Show file tree
Hide file tree
Showing 18 changed files with 875 additions and 71 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
/node_modules

Expand Down
2 changes: 1 addition & 1 deletion .playroom/frame.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { MemoryRouter } from 'react-router-dom';
import '../src/index.css';
import '../src/styles.css';

export default (props) => {
const { children } = props;
Expand Down
1 change: 1 addition & 0 deletions .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
'@storybook/addon-actions',
'@storybook/addon-links',
'@storybook/addon-docs',
'@storybook/addon-viewport/register',
'storybook-addon-playroom',
],
};
7 changes: 5 additions & 2 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@

import '../src/index.css';
import { addDecorator, addParameters } from '@storybook/react';
import { withMemoryRouter } from './decorators/memoryRouter'
import { withPlayroom } from 'storybook-addon-playroom';
import { INITIAL_VIEWPORTS } from '@storybook/addon-viewport';
import '../src/styles.css';

addDecorator(withPlayroom);

addDecorator(withMemoryRouter);

addParameters({
playroom: {
url: process.env.NODE_ENV === 'production' ? '/playroom/' : undefined,
},
viewport: {
viewports: INITIAL_VIEWPORTS
}
});
20 changes: 20 additions & 0 deletions .stylelintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"extends": "stylelint-config-recommended",
"rules": {
"at-rule-no-unknown": [
true,
{
"ignoreAtRules": [
"tailwind",
"apply",
"variants",
"responsive",
"screen"
]
}
],
"block-no-empty": null,
"unit-whitelist": ["em", "rem", "s", "px"]
}
}

17 changes: 13 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,39 @@
"typescript": "^3.8.3"
},
"scripts": {
"prestart": "yarn run build:styles",
"start": "BROWSER=none react-scripts start",
"now-start": "serve --single ./build",
"now-start": "serve -s ./build",
"prebuild": "NODE_ENV=production yarn run build:styles",
"build": "react-scripts build",
"build:styles": "postcss src/tailwind.css -o src/styles.css",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"storybook:start": "start-storybook -p 9009 -s public",
"storybook": "concurrently \"yarn storybook:start\" \"yarn playroom\"",
"build-storybook": "build-storybook -s public",
"storybook:build": "build-storybook -s public",
"playroom": "playroom start",
"build-playroom": "playroom build"
"playroom:build": "playroom build"
},
"devDependencies": {
"@fullhuman/postcss-purgecss": "^2.1.0",
"@storybook/addon-actions": "^5.3.17",
"@storybook/addon-docs": "^5.3.18",
"@storybook/addon-links": "^5.3.17",
"@storybook/addon-viewport": "^5.3.18",
"@storybook/addons": "^5.3.17",
"@storybook/preset-create-react-app": "^2.1.1",
"@storybook/react": "^5.3.17",
"babel-loader": "^8.1.0",
"autoprefixer": "^9.7.5",
"concurrently": "^5.1.0",
"playroom": "^0.21.2",
"postcss-cli": "^7.1.0",
"react-docgen-typescript-loader": "^3.7.2",
"redux-devtools": "^3.5.0",
"storybook-addon-playroom": "^1.0.0",
"stylelint": "^13.3.0",
"stylelint-config-recommended": "^3.0.0",
"tailwindcss": "^1.2.0",
"ts-loader": "^6.2.2"
},
"browserslist": {
Expand Down
19 changes: 19 additions & 0 deletions postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const purgecss = require('@fullhuman/postcss-purgecss')({

content: [
'./src/**/*.tsx',
'./public/index.html',
],

defaultExtractor: content => content.match(/[A-Za-z0-9-_:/]+/g) || []
})

module.exports = {
plugins: [
require('tailwindcss'),
require('autoprefixer'),
...process.env.NODE_ENV === 'production'
? [purgecss]
: []
]
}
2 changes: 1 addition & 1 deletion src/components/About/About.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const About: React.FC = () => {
Yet another Hacker News clone
</p>
<p className="dark:text-white">
Featuring <a className="dark:hover:text-gray-700" href="https://reactjs.org/">React 16</a>, <a className="dark:hover:text-gray-700" href="https://reacttraining.com/react-router/">React Router 4</a>, <a className="dark:hover:text-gray-700" href="https://react-redux.js.org/">React Redux</a>, <a className="dark:hover:text-gray-700" href="https://github.com/gaearon/redux-thunk">Redux Thunk</a>, <a className="dark:hover:text-gray-700" href="https://github.com/cheeaun/node-hnapi/">HN API</a>, CSS variables, unread link highlighting, clickable links in comments, dark mode <a href="https://github.com/ptibbetts/reactHN/pull/2">(#2)</a>, TailwindCSS, Storybook <a href="https://github.com/ptibbetts/reactHN/pull/2/commits/22cd78ccdc9e1bf275913ad1d66898a2bd0e0e0f">(22cd78c)</a>and playroom <a href="https://github.com/ptibbetts/reactHN/pull/2/commits/ae522750b8c2921eb1dfe716078b4695ce3661c6">(ae52275)</a>.
Featuring <a className="dark:hover:text-gray-700" href="https://reactjs.org/">React 16</a>, <a className="dark:hover:text-gray-700" href="https://reacttraining.com/react-router/">React Router 4</a>, <a className="dark:hover:text-gray-700" href="https://react-redux.js.org/">React Redux</a>, <a className="dark:hover:text-gray-700" href="https://github.com/gaearon/redux-thunk">Redux Thunk</a>, <a className="dark:hover:text-gray-700" href="https://github.com/cheeaun/node-hnapi/">HN API</a>, unread link highlighting, clickable links in comments, dark mode <a className="dark:hover:text-gray-700" href="https://github.com/ptibbetts/reactHN/pull/2">(#2)</a>, TailwindCSS, Storybook <a className="dark:hover:text-gray-700" href="https://github.com/ptibbetts/reactHN/pull/2/commits/22cd78ccdc9e1bf275913ad1d66898a2bd0e0e0f">(22cd78c)</a>and playroom <a className="dark:hover:text-gray-700" href="https://github.com/ptibbetts/reactHN/pull/2/commits/ae522750b8c2921eb1dfe716078b4695ce3661c6">(ae52275)</a>.
</p>
<p className="dark:text-white">
View the source code on <a className="dark:hover:text-gray-700" href="https://github.com/ptibbetts/reactHN">GitHub</a>
Expand Down
10 changes: 10 additions & 0 deletions src/components/Collection/Collection.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,14 @@ export const Default = () => (
path=":page?"
page={1}
/>
)

export const IsFetching = () => (
<Collection
type='news'
collection={collectionData}
isFetching={true}
path=":page?"
page={1}
/>
)
19 changes: 19 additions & 0 deletions src/components/Collection/Collection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,19 @@ export const Collection = (props: Props) => {
const pageNumber: string = page.toString() || '1';

const renderList = (data: StoryModel[], perPage: number) => {
<<<<<<< HEAD
let classNames = "collection content";
if (isFetching) {
classNames = `${classNames} is-fetching`;
}
return (
<div className={classNames}>
<ol className="collection__list">
=======
return (
<div>
<ol>
>>>>>>> feat/dark-mode
{renderStories(data, perPage)}
</ol>
</div>
Expand Down Expand Up @@ -68,10 +74,19 @@ export const Collection = (props: Props) => {
return (
<div>
{renderList(content, content.length)}
<<<<<<< HEAD
<Pagination
page={pageNumber ? pageNumber : '1'}
type={type}
/>
=======
<div className="my-4">
<Pagination
page={pageNumber ? pageNumber : '1'}
type={type}
/>
</div>
>>>>>>> feat/dark-mode
</div>
);
}
Expand All @@ -89,7 +104,11 @@ export const Collection = (props: Props) => {
}

return (
<<<<<<< HEAD
<div className="container">
=======
<div>
>>>>>>> feat/dark-mode
{renderContent(collection)}
</div>
);
Expand Down
11 changes: 10 additions & 1 deletion src/components/Comment/Comment.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,13 @@ export const WithSubComments = () => (
<Comment
data={subCommentData}
/>
)
)

export const WithCodeBlock = () => (
<Comment
data={{
...commentData,
content: '<p><pre><code>echo "Hello World!!1"</code></pre></p>'
}}
/>
);
3 changes: 3 additions & 0 deletions src/components/Comment/Comment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ export const Comment = (props: ICommentProps): JSX.Element => {
dangerouslySetInnerHTML={renderMarkup(comment.content)}
/>
</div>
<<<<<<< HEAD
<div dangerouslySetInnerHTML={renderMarkup(comment.content)} />
=======
>>>>>>> feat/dark-mode
{comment.comments.length > 0
? <Comments data={comment.comments} />
: ''
Expand Down
10 changes: 7 additions & 3 deletions src/components/Item/Item.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default {

const itemData = {
...defaultStoryData,
content: '<p>Isolated components</p>',
content: '',
comments: defaultCommentsData,
comments_count: defaultCommentsData.length
}
Expand All @@ -35,9 +35,13 @@ const noContentItemData = {
...itemData,
content: ''
}
export const NoContent = () => (
export const WithContent = () => (
<Item
item={noContentItemData}
item={{
...itemData,
title: 'Show HN: Storybook',
content: '<p>Some example content</p>'
}}
isFetching={false}
/>
)
Expand Down
8 changes: 6 additions & 2 deletions src/components/Item/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ export const Item = (props: Props) => {
}
</div>
<div
<<<<<<< HEAD
className="item__content"
=======
className="mt-3"
>>>>>>> feat/dark-mode
dangerouslySetInnerHTML={renderMarkup(data.content)}
/>
</div>
Expand All @@ -73,7 +77,7 @@ export const Item = (props: Props) => {

const renderContents = (data: ItemModel) => {
return (
<div className={isFetching ? 'is-fetching' : ''}>
<div className={isFetching ? 'opacity-25' : ''}>
{ renderItem(data) }
{
data.comments && data.comments.length > 0
Expand All @@ -85,7 +89,7 @@ export const Item = (props: Props) => {
}

return (
<div className="container">
<div>
{renderContents(item)}
</div>
);
Expand Down
22 changes: 11 additions & 11 deletions src/components/Navigation/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,31 @@ const links: { dest: string, label: string }[] = [
}
];

const className = "navigation__link";
const activeClassName = `${className}--active`;
const navLinkClass = 'inline-block text-white p-2 hover:text-blue-500 border-transparent border-b-2';
const navLinkActiveClass = 'border-blue-500 text-blue-500';

export const Navigation: React.FC = () => (
<nav
className="navigation"
className="sticky top-0 bg-black-600"
onClick={() => scrollToTop()}
>
<div className="container">
<ul className="navigation__list">
<div className="max-w-screen-lg mx-auto">
<ul className="flex items-center">
{links.map((link, index) => (
<li className="navigation__listItem" key={index}>
<li key={index}>
<NavLink
to={link.dest}
className={className}
activeClassName={activeClassName}
className={navLinkClass}
activeClassName={navLinkActiveClass}
>
{link.label}
</NavLink>
</li>
))}
<li className="navigation__listItem navigation__listItem--about">
<li className="ml-auto">
<NavLink to="/about"
className={className}
activeClassName={activeClassName}
className={navLinkClass}
activeClassName={navLinkActiveClass}
>
about
</NavLink>
Expand Down
2 changes: 1 addition & 1 deletion src/components/User/User.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const User = (props: Props) => {
}

return (
<div className="container">
<div>
{props.isFetching
? <Loading />
: renderUser(props.user)
Expand Down
28 changes: 15 additions & 13 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import './styles.css';
import * as serviceWorker from './serviceWorker';

import { Provider } from 'react-redux';
Expand All @@ -27,18 +27,20 @@ const root: JSX.Element = (
<div>
<Navigation />
<main>
<Switch>
<Route exact path="/" component={DefaultFeature} />
<Route path="/item/:id" component={ItemFeature} />
<Route path="/user/:id" component={UserFeature} />
<Route path="/news/:page?" render={props => <CollectionFeature {...props} type='news' />} />
<Route path="/newest/:page?" render={props => <CollectionFeature {...props} type='newest' />} />
<Route path="/show/:page?" render={props => <CollectionFeature {...props} type='show' />} />
<Route path="/ask/:page?" render={props => <CollectionFeature {...props} type='ask' />} />
<Route path="/jobs/:page?" render={props => <CollectionFeature {...props} type='jobs' />} />
<Route exact path="/about" component={About} />
<Route component={NoMatch} />
</Switch>
<div className="max-w-screen-lg my-4 mx-auto">
<Switch>
<Route exact path="/" component={DefaultFeature} />
<Route path="/item/:id" component={ItemFeature} />
<Route path="/user/:id" component={UserFeature} />
<Route path="/news/:page?" render={props => <CollectionFeature {...props} type='news' />} />
<Route path="/newest/:page?" render={props => <CollectionFeature {...props} type='newest' />} />
<Route path="/show/:page?" render={props => <CollectionFeature {...props} type='show' />} />
<Route path="/ask/:page?" render={props => <CollectionFeature {...props} type='ask' />} />
<Route path="/jobs/:page?" render={props => <CollectionFeature {...props} type='jobs' />} />
<Route exact path="/about" component={About} />
<Route component={NoMatch} />
</Switch>
</div>
</main>
</div>
</Router>
Expand Down
Loading

0 comments on commit 38b319a

Please sign in to comment.