Skip to content

Commit

Permalink
Add HeadRoom, BackToTop, edit footer & theme color
Browse files Browse the repository at this point in the history
  • Loading branch information
juliencrn committed Apr 21, 2020
1 parent 66b7004 commit 56e0764
Show file tree
Hide file tree
Showing 13 changed files with 295 additions and 135 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"source.fixAll": true
},
"cSpell.words": [
"fira",
"frontmatter",
"okaidia",
"prismjs"
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2020 junscuzzy
Copyright (c) 2020 Julien CARON

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
145 changes: 41 additions & 104 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,117 +1,54 @@
# Gatsby's Typescript + Material-ui starter
# Usehooks.ts

[![Netlify Status](https://api.netlify.com/api/v1/badges/1b625068-4ac6-42d5-87fb-902d9077bbef/deploy-status)](https://app.netlify.com/sites/gatsby-material-typescript-starter/deploys)
This is the repository for [usehooks.ts](https://usehooks.ts), a [Gatsby](https://www.gatsbyjs.org) powered blog that publishes easy to understand React Hook code snippets.

Kick off your project with this [Material-ui](https://material-ui.com/) boilerplate. This starter ships with the main Gatsby configuration files you might need to get up and running blazing fast with the blazing fast app generator for React.
It includes support for Typescript in front-side and node-side and uses Eslint & Prettier.
UseHooks.ts has been strongly inspired by [usehooks.com](https://usehooks.com), thanks to him. My objective here is to publish my hooks in Typescript in order to find them quickly

This starter don't have any source or style supports, it's your choice.
If you'd like to submit new post ideas, improve existing posts, or change anything about the website feel free to submit an issue or pull-request.

_Have another more specific idea? You may want to check out our vibrant collection of [official and community-created starters](https://www.gatsbyjs.org/docs/gatsby-starters/)._
To run locally, `yarn`, then `yarn dev`, then open [localhost:8000](https://localhost:8000).

## 🚀 Quick start
## Summary

1. **Create a Gatsby site.**
- [useLocalStorage](https://gist.github.com/Junscuzzy/59598636c81071fd8c66af092fb02a09)

Use the Gatsby CLI to create a new site, specifying the default starter.
### Todo

```shell
# create a new Gatsby site using the starter
gatsby new gatsby-material-typescript-starter https://github.com/Junscuzzy/gatsby-material-typescript-starter
```
> TODO: Look in all my projects witch hooks I have used
1. **Start developing.**
- [useScrollPosition](https://github.com/n8tb1t/use-scroll-position)
- useDebounce
- useHover
- useWindowSize
- useOnClickOutside

Navigate into your new site’s directory and start it up.

```shell
cd gatsby-material-typescript-starter/
yarn develop
```
### Ideas from useHooks.com

1. **Open the source code and start editing!**
[useMemoCompare](https://usehooks.com/useMemoCompare/)<br/>
[useAsync](https://usehooks.com/useAsync/)<br/>
[useRequireAuth](https://usehooks.com/useRequireAuth/)<br/>
[useRouter](https://usehooks.com/useRouter/)<br/>
[useAuth](https://usehooks.com/useAuth/)<br/>
[useEventListener](https://usehooks.com/useEventListener/)<br/>
[useWhyDidYouUpdate](https://usehooks.com/useWhyDidYouUpdate/)<br/>
[useDarkMode](https://usehooks.com/useDarkMode/)<br/>
[useMedia](https://usehooks.com/useMedia/)<br/>
[useLockBodyScroll](https://usehooks.com/useLockBodyScroll/)<br/>
[useTheme](https://usehooks.com/useTheme/)<br/>
[useSpring](https://usehooks.com/useSpring/)<br/>
[useHistory](https://usehooks.com/useHistory/)<br/>
[useScript](https://usehooks.com/useScript/)<br/>
[useKeyPress](https://usehooks.com/useKeyPress/)<br/>
[useMemo](https://usehooks.com/useMemo/)<br/>
[useDebounce](https://usehooks.com/useDebounce/)<br/>
[useOnScreen](https://usehooks.com/useOnScreen/)<br/>
[usePrevious](https://usehooks.com/usePrevious/)<br/>
[useOnClickOutside](https://usehooks.com/useOnClickOutside/)<br/>
[useAnimation](https://usehooks.com/useAnimation/)<br/>
[useWindowSize](https://usehooks.com/useWindowSize/)<br/>
[useHover](https://usehooks.com/useHover/)<br/>

Your site is now running at `http://localhost:8000`!

_Note: You'll also see a second link: _`http://localhost:8000/___graphql`_. This is a tool you can use to experiment with querying your data. Learn more about using this tool in the [Gatsby tutorial](https://www.gatsbyjs.org/tutorial/part-five/#introducing-graphiql)._
Open the `gatsby-material-typescript-starter` directory in your code editor of choice and edit `src/pages/index.tsx`. Save your changes and the browser will update in real time!
1. **Bonus**: Check all linters using
```shell
yarn lint
```
Will execute Prettier, Eslint and Typescript checking
All the commands are in your `package.json > scripts`.
## 🧐 What's inside?

A quick look at the top-level files and directories you'll see in a Gatsby project.
.
├── .vscode/
├── node_modules/
├── src/
├── static/
├── .editorconfig
├── .eslintrc
├── .gitignore
├── .prettierrc
├── gatsby-browser.js
├── gatsby-config.js
├── gatsby-node.js
├── gatsby-ssr.js
├── LICENSE
├── package.json
├── README.md
├── tsconfig.json
└── yarn.lock
1. **`/.vscode`**: VSCode projects settings.
1. **`/node_modules`**: This directory contains all of the modules of code that your project depends on (npm packages) are automatically installed.
1. **`/src`**: This directory will contain all of the code related to what you will see on the front-end of your site (what you see in the browser) such as your site header or a page template. `src` is a convention for “source code”.
1. **`/static`**: Static files like `robots.txt` or `favicon.ico`.
1. **`.editorconfig`**: EditorConfig helps maintain consistent coding styles for multiple developers working on the same project across various editors and IDEs.
1. **`.eslintrc`**: This is a configuration file for [Eslint](https://eslint.org/). Find and fix problems in your JavaScript code
1. **`.gitignore`**: This file tells git which files it should not track / not maintain a version history for.
1. **`.prettierrc`**: This is a configuration file for [Prettier](https://prettier.io/). Prettier is a tool to help keep the formatting of your code consistent.
1. **`gatsby-browser.js`**: This file is where Gatsby expects to find any usage of the [Gatsby browser APIs](https://www.gatsbyjs.org/docs/browser-apis/) (if any). These allow customization/extension of default Gatsby settings affecting the browser.
1. **`gatsby-config.js`**: This is the main configuration file for a Gatsby site. This is where you can specify information about your site (metadata) like the site title and description, which Gatsby plugins you’d like to include, etc. (Check out the [config docs](https://www.gatsbyjs.org/docs/gatsby-config/) for more detail).
1. **`gatsby-node.js`**: This file is where Gatsby expects to find any usage of the [Gatsby Node APIs](https://www.gatsbyjs.org/docs/node-apis/) (if any). These allow customization/extension of default Gatsby settings affecting pieces of the site build process.
1. **`gatsby-ssr.js`**: This file is where Gatsby expects to find any usage of the [Gatsby server-side rendering APIs](https://www.gatsbyjs.org/docs/ssr-apis/) (if any). These allow customization of default Gatsby settings affecting server-side rendering.
1. **`LICENSE`**: Gatsby is licensed under the MIT license.
1. **`package.json`**: A manifest file for Node.js projects, which includes things like metadata (the project’s name, author, etc). This manifest is how npm knows which packages to install for your project.
1. **`README.md`**: A text file containing useful reference information about your project.
1. **`tsconfig.json`**: This is a configuration file for [Typescript](https://www.typescriptlang.org/). TypeScript is a typed superset of JavaScript that compiles to plain JavaScript.
1. **`yarn.lock`** (See `package.json` below, first). This is an automatically generated file based on the exact versions of your npm dependencies that were installed for your project. **(You won’t change this file directly).**
## 🎓 Learning Gatsby
Looking for more guidance? Full documentation for Gatsby lives [on the website](https://www.gatsbyjs.org/). Here are some places to start:
- **For most developers, we recommend starting with our [in-depth tutorial for creating a site with Gatsby](https://www.gatsbyjs.org/tutorial/).** It starts with zero assumptions about your level of ability and walks through every step of the process.
- **To dive straight into code samples, head [to our documentation](https://www.gatsbyjs.org/docs/).** In particular, check out the _Guides_, _API Reference_, and _Advanced Tutorials_ sections in the sidebar.
## 💫 Deploy
As a static generated website, you can deploy it on [Netlify](https://www.netlify.com), [Github Page](https://pages.github.com/) or [ZEIT Now](https://zeit.co/)
<p align="center">
<a href="./LICENSE"><strong>Unlicense</strong></a> &mdash; public domain
</p>
2 changes: 0 additions & 2 deletions content/posts/useLocalStorage.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,3 @@ const [state, dispatch] = useLocalStorage('uniqKey', initialValue)
// Or with real data
const [theme, setTheme] = useLocalStorage('theme', 'light')
```


8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
},
"dependencies": {
"@material-ui/core": "latest",
"@material-ui/icons": "^4.9.1",
"@material-ui/styles": "latest",
"@mdx-js/mdx": "^1.5.8",
"@mdx-js/react": "^1.5.8",
"@n8tb1t/use-scroll-position": "^1.0.43",
"deepmerge": "^4.2.2",
"gatsby": "latest",
"gatsby-plugin-catch-links": "^2.2.3",
Expand All @@ -44,14 +46,18 @@
"prism-react-renderer": "^1.0.2",
"react": "latest",
"react-dom": "latest",
"react-helmet": "^6.0.0"
"react-headroom": "^3.0.0",
"react-helmet": "^6.0.0",
"react-scroll": "^1.7.16"
},
"devDependencies": {
"@types/mdx-js__react": "^1.5.1",
"@types/node": "latest",
"@types/react": "latest",
"@types/react-dom": "latest",
"@types/react-headroom": "^2.2.1",
"@types/react-helmet": "^5.0.15",
"@types/react-scroll": "^1.5.4",
"@typescript-eslint/eslint-plugin": "^2.28.0",
"@typescript-eslint/parser": "^2.28.0",
"eslint": "^6.8.0",
Expand Down
52 changes: 52 additions & 0 deletions src/components/backToTop.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React, { FC, useState } from 'react'
import { makeStyles, Theme, createStyles } from '@material-ui/core/styles'
import Fab from '@material-ui/core/Fab'
import KeyboardArrowUpIcon from '@material-ui/icons/KeyboardArrowUp'
import { useScrollPosition } from '@n8tb1t/use-scroll-position'
import { Link } from 'react-scroll'

const useStyles = makeStyles((theme: Theme) =>
createStyles({
root: {
position: 'fixed',
bottom: theme.spacing(2),
right: theme.spacing(2),
zIndex: 1000,
transition: `opacity 200ms`,
},
}),
)

const BackToTop: FC = () => {
const classes = useStyles()
const [isVisible, setVisible] = useState(false)

useScrollPosition(
({ currPos }) => {
const shouldBeVisible = currPos.y > 500
if (isVisible !== shouldBeVisible) {
setVisible(shouldBeVisible)
}
},
undefined,
undefined,
true,
200,
)

return (
<Link
to="___gatsby"
smooth
isDynamic
className={classes.root}
style={{ opacity: Number(isVisible) }}
>
<Fab color="primary" size="small" aria-label="scroll back to top">
<KeyboardArrowUpIcon />
</Fab>
</Link>
)
}

export default BackToTop
3 changes: 2 additions & 1 deletion src/components/code.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React from 'react'
import { makeStyles } from '@material-ui/styles'
import Highlight, { defaultProps, Language } from 'prism-react-renderer'
import theme from 'prism-react-renderer/themes/vsDark'
import { Theme, Typography } from '@material-ui/core'

import theme from '../libs/prismjs-theme-dracula'

const useStyles = makeStyles((theme: Theme) => ({
pre: {
textAlign: 'left',
Expand Down
22 changes: 18 additions & 4 deletions src/layout/footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import React, { FC } from 'react'
import { makeStyles } from '@material-ui/styles'
import { Container, Typography, Theme, Link } from '@material-ui/core'

import useSiteMetadata from '../hooks/useSiteMetadata'

const useStyles = makeStyles((theme: Theme) => ({
footer: {
padding: theme.spacing(3, 2),
Expand All @@ -13,25 +15,37 @@ const useStyles = makeStyles((theme: Theme) => ({

const Footer: FC = () => {
const classes = useStyles()
const { author, social } = useSiteMetadata()

return (
<footer className={classes.footer}>
<Container maxWidth="md">
<Typography variant="body1" color="textSecondary">
© {new Date().getFullYear()}, Built with
{` `}
<Link href="https://www.gatsbyjs.org" color="inherit">
<Link href="https://www.gatsbyjs.org" target="_blank">
Gatsby
</Link>
,{` `}
<Link href="https://www.typescriptlang.org" color="inherit">
<Link href="https://www.typescriptlang.org" target="_blank">
Typescript
</Link>{' '}
and
{` `}
<Link href="https://material-ui.com/" color="inherit">
<Link href="https://material-ui.com/" target="_blank">
@Material-ui
</Link>
,
, written by
{` `}
<Link href={social.github} target="_blank">
{author.name}
</Link>{' '}
and hosted on
{` `}
<Link href="https://www.netlify.com/" target="_blank">
Netlify
</Link>
.
</Typography>
</Container>
</footer>
Expand Down
Loading

0 comments on commit 56e0764

Please sign in to comment.