commit a57ad5087aae11796356c12d9f5efff7ef64c747 Author: cupcakearmy Date: Sun Mar 3 16:13:57 2019 +0100 redesign diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..08c9401 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +node_modules +public + +.idea +.vscode \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..9010afd --- /dev/null +++ b/README.md @@ -0,0 +1,38 @@ +# React Typescript Stylus Webpack Boilerplate 👨‍🍳 + +This is the starting point for any react-typescript-stylus-webpack-hipsterframeworkxyz boilerplate to get up and running quickly. + +## Getting Started 🚀 + +```bash +git clone https://github.com/CupCakeArmy/react-boilerplate.git +npm i +npm run dev + +# Or +wget https://github.com/CupCakeArmy/react-boilerplate/archive/master.zip +unzip master +``` + +## Usage 📖 + +### Build 🛠 + +```bash +# Dev +npm run build:dev + +# Prod +npm run build:prod +``` + +### Dev 👀 + +Compiles on files changed + +```bash +npm run dev + +# Go to +http://localhost:8080 +``` diff --git a/package.json b/package.json new file mode 100755 index 0000000..76b8ea9 --- /dev/null +++ b/package.json @@ -0,0 +1,30 @@ +{ + "private": true, + "scripts": { + "build:dev": "webpack -d", + "build:prod": "webpack -p", + "dev": "webpack-dev-server -d" + }, + "dependencies": { + "animejs": "^3.0.1", + "react": "^16.8", + "react-dom": "^16.8" + }, + "devDependencies": { + "@types/animejs": "^2.0.1", + "@types/react": "^16.8", + "@types/react-dom": "^16.8", + "awesome-typescript-loader": "^5", + "css-loader": "^2", + "file-loader": "^3", + "html-webpack-plugin": "^3", + "mini-css-extract-plugin": "^0.5.0", + "style-loader": "^0", + "stylus": "^0", + "stylus-loader": "^3", + "typescript": "^3.3.3", + "webpack": "^4", + "webpack-cli": "^3", + "webpack-dev-server": "^3.1.14" + } +} diff --git a/src/App.tsx b/src/App.tsx new file mode 100644 index 0000000..480b782 --- /dev/null +++ b/src/App.tsx @@ -0,0 +1,38 @@ +import React from 'react' +import AnimatedBackground from './Components/AnimatedBackground' +import Cursor from './Components/Cursor' +import Letters from './Screens/Letters' +import { useMousePosition } from './util' + +export const Duration = 4000 + +const App: React.FC = () => { + + const mouse = useMousePosition() + + const convertToDeg = (current: number, factor: number) => `${(.5 - current) * factor}deg` + + return
+
+

+ +

+
+ +
+ +
+ + + + +
+} + +export default App \ No newline at end of file diff --git a/src/Components/AnimatedBackground.tsx b/src/Components/AnimatedBackground.tsx new file mode 100644 index 0000000..5bf9be9 --- /dev/null +++ b/src/Components/AnimatedBackground.tsx @@ -0,0 +1,38 @@ +import React, { useEffect, useState } from 'react' +import { Duration } from '../App' +import { GoldenRatio, Rand } from '../util' + +type Color = [number, number, number] + +const getRandomColor = () => [Rand(0, 255), Rand(70, 90), Rand(80, 90)] as Color +const colorToString = ([h, s, l]: Color) => `hsl(${h}, ${s}%, ${l}%)` as string +const valuesToGradient = (dir: number, from: Color, to: Color) => `linear-gradient(${dir}deg, ${colorToString(from)}, ${colorToString(to)})` as string + +const AnimatedBackground: React.FC = () => { + + const [start, setStart] = useState([255, 255, 255]) + const [end, setEnd] = useState([255, 255, 255]) + const [direction, setDirection] = useState(0) + + const update = () => { + const from = getRandomColor() + // Calculate cojugate color based on the golden ratio + const to: Color = [Math.floor(from[0] + (255 * GoldenRatio * 2)) % 255, from[1], from[2]] + + setStart(from) + setEnd(to) + setDirection(Rand(0, 360)) + } + + useEffect(() => { + update() + const interval = setInterval(update, Duration) + return () => clearInterval(interval) + }, []) + + return
+} + +export default AnimatedBackground \ No newline at end of file diff --git a/src/Components/Cursor.tsx b/src/Components/Cursor.tsx new file mode 100644 index 0000000..33fd657 --- /dev/null +++ b/src/Components/Cursor.tsx @@ -0,0 +1,22 @@ +import React from 'react' +import { useIsMousePresent, useMousePosition } from '../util' + +const Cursor: React.FC = () => { + const mouse = useMousePosition() + const present = useIsMousePresent() + + return present + ? + : null +} + +export default Cursor \ No newline at end of file diff --git a/src/Components/LetterAnimation.tsx b/src/Components/LetterAnimation.tsx new file mode 100644 index 0000000..60b2fe6 --- /dev/null +++ b/src/Components/LetterAnimation.tsx @@ -0,0 +1,43 @@ +import anime from 'animejs' +import React, { useEffect, useRef } from 'react' +import { Duration } from '../App' + +export type LettersProps = { + text: string + delay?: number +} + +const LetterAnimation: React.FC = React.memo(({ text, delay }) => { + + const letters = useRef(null) + + const animate = () => { + if (!letters || !letters.current) return + + const wrapper = letters.current + wrapper.innerHTML = wrapper.innerText.replace( + /./g, + l => `${l}`, + ) + + anime({ + targets: wrapper.querySelectorAll(`.letter`), + translateX: [40, 0], + rotateY: [-20, 0], + opacity: [0, 1], + // color: () => getRandomColor(), + easing: 'easeOutExpo', + duration: Duration / 3, + delay: (el, i) => (delay || 0) + 250 + 25 * i, + }) + + } + + useEffect(animate) + + return + {text} + +}) + +export default LetterAnimation \ No newline at end of file diff --git a/src/Screens/Letters.tsx b/src/Screens/Letters.tsx new file mode 100644 index 0000000..3e45099 --- /dev/null +++ b/src/Screens/Letters.tsx @@ -0,0 +1,33 @@ +import React, { useEffect, useRef, useState } from 'react' +import LetterAnimation from '../Components/LetterAnimation' + +type Pair = [string, string] + +const pairs: Pair[] = [ + ['visualize', 'create'], + ['invision', 'build'], + ['ideate', 'deploy'], +] + +export const Duration = 4000 + +const Letters: React.FC = React.memo(() => { + + const [index, setIndex] = useState(0) + const wrapper = useRef(null) + + + useEffect(() => { + setTimeout( + () => setIndex((index < pairs.length - 1) ? index + 1 : 0), + Duration, + ) + }, [index]) + + return + + + +}) + +export default Letters \ No newline at end of file diff --git a/src/index.html b/src/index.html new file mode 100755 index 0000000..452e015 --- /dev/null +++ b/src/index.html @@ -0,0 +1,14 @@ + + + + + Template + + + + + +
+ + + \ No newline at end of file diff --git a/src/index.styl b/src/index.styl new file mode 100644 index 0000000..406d76f --- /dev/null +++ b/src/index.styl @@ -0,0 +1 @@ +@require './styles/*' \ No newline at end of file diff --git a/src/index.tsx b/src/index.tsx new file mode 100755 index 0000000..834172c --- /dev/null +++ b/src/index.tsx @@ -0,0 +1,7 @@ +import React from 'react' +import ReactDOM from 'react-dom' +import App from './App' + +import './index.styl' + +ReactDOM.render(, document.getElementById('root')) \ No newline at end of file diff --git a/src/styles/AnimatedBackground.styl b/src/styles/AnimatedBackground.styl new file mode 100644 index 0000000..0125459 --- /dev/null +++ b/src/styles/AnimatedBackground.styl @@ -0,0 +1,4 @@ +.animated-background + height 100% + width 100% + animation all 1s linear \ No newline at end of file diff --git a/src/styles/App.styl b/src/styles/App.styl new file mode 100644 index 0000000..3349204 --- /dev/null +++ b/src/styles/App.styl @@ -0,0 +1,33 @@ +@require './Breakpoints.styl' + +#App + height 100vh + width 100vw + display flex + align-items center + justify-content center + perspective 1em + + #bg + position absolute + left 0 + top 0 + width 100vw + height 100vh + z-index -1 + + #letters-wrapper + display inline-block + text-align center + font-size 1em + font-weight bold + +is-phone() + font-size 2.5em + +is-tablet() + font-size 3em + +is-netbook() + font-size 3.5em + +is-laptop() + font-size 4em + +is-desktop() + font-size 4.5em \ No newline at end of file diff --git a/src/styles/Breakpoints.styl b/src/styles/Breakpoints.styl new file mode 100644 index 0000000..1629d11 --- /dev/null +++ b/src/styles/Breakpoints.styl @@ -0,0 +1,20 @@ +is-phone() + @media (max-width: 599px) + {block} + +is-tablet() + @media (min-width: 600px) { + block + } + +is-netbook() + @media (min-width: 900px) + {block} + +is-laptop() + @media (min-width: 1200px) + {block} + +is-desktop() + @media (min-width: 1800px) + {block} \ No newline at end of file diff --git a/src/styles/Footer.styl b/src/styles/Footer.styl new file mode 100644 index 0000000..a402088 --- /dev/null +++ b/src/styles/Footer.styl @@ -0,0 +1,18 @@ +footer + font-family 'Inconsolata', monospace + display flex + align-items center + justify-content center + flex-direction column + font-size 1.2em + position absolute + bottom 0 + left 0 + text-align center + width 100vw + padding 1em + + a + text-decoration inherit + color inherit + font-weight bold diff --git a/src/styles/Letters.styl b/src/styles/Letters.styl new file mode 100644 index 0000000..9c6b581 --- /dev/null +++ b/src/styles/Letters.styl @@ -0,0 +1,9 @@ +.letters + display inline-block + position relative + letter-spacing .05em + +.letter + display inline-block + transform-origin 0 0 + line-height 1em \ No newline at end of file diff --git a/src/styles/global.styl b/src/styles/global.styl new file mode 100644 index 0000000..79ec44b --- /dev/null +++ b/src/styles/global.styl @@ -0,0 +1,16 @@ +@import url('https://fonts.googleapis.com/css?family=Raleway') +@import url('https://fonts.googleapis.com/css?family=Merriweather:300,400,700') +@import url('https://fonts.googleapis.com/css?family=Inconsolata:400,700') + +* + box-sizing border-box + cursor none + +html, +body, +#root + margin 0 + border 0 + font-family 'Merriweather', serif + font-size 1em + overflow hidden \ No newline at end of file diff --git a/src/util.ts b/src/util.ts new file mode 100644 index 0000000..137a639 --- /dev/null +++ b/src/util.ts @@ -0,0 +1,56 @@ +import { useEffect, useState } from 'react' + +const getSize = () => { + const { innerHeight, innerWidth, outerHeight, outerWidth } = window + return { innerHeight, innerWidth, outerHeight, outerWidth } +} + +export const useIsMousePresent = ()=> { + let [present, setPresent] = useState(true) + + useEffect(() => { + const enter = ()=> setPresent(true) + const leave = ()=> setPresent(false) + window.document.addEventListener('mouseenter', enter) + window.document.addEventListener('mouseleave', leave) + return () => { + window.document.removeEventListener('mouseenter', enter) + window.document.removeEventListener('mouseleave', leave) + } + }, []) + + return present +} + +export const useMousePosition = () => { + let [position, setPosition] = useState({ absolute: { x: 0, y: 0 }, relative: { x: 0, y: 0 } }) + + const handle = (e: MouseEvent) => { + setPosition({ + absolute: { + x: e.pageX, + y: e.pageY, + }, + relative: { + x: e.pageX / window.innerWidth, + y: e.pageY / window.innerHeight, + }, + }) + } + + useEffect(() => { + window.addEventListener('mousemove', handle) + return () => { + window.removeEventListener('mousemove', handle) + } + }, []) + + return position +} + +export const Rand = (from: number = 0, to: number = 1, float: boolean = false) => { + const rand = (Math.random() * (to - from)) + from + return float ? rand : rand | 0 +} + +export const GoldenRatio: number = (1 + Math.sqrt(5)) / 2 diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..4d6e7d8 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,60 @@ +{ + "compilerOptions": { + /* Basic Options */ + "target": "esnext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */ + "module": "esnext", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ + // "lib": [], /* Specify library files to be included in the compilation. */ + // "allowJs": true, /* Allow javascript files to be compiled. */ + // "checkJs": true, /* Report errors in .js files. */ + "jsx": "react", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ + // "declaration": true, /* Generates corresponding '.d.ts' file. */ + // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ + // "sourceMap": true, /* Generates corresponding '.map' file. */ + // "outFile": "./", /* Concatenate and emit output to single file. */ + // "outDir": "./", /* Redirect output structure to the directory. */ + "rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ + // "composite": true, /* Enable project compilation */ + "removeComments": true, /* Do not emit comments to output. */ + // "noEmit": true, /* Do not emit outputs. */ + // "importHelpers": true, /* Import emit helpers from 'tslib'. */ + // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ + // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ + + /* Strict Type-Checking Options */ + "strict": true, /* Enable all strict type-checking options. */ + "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ + "strictNullChecks": true, /* Enable strict null checks. */ + "strictFunctionTypes": true, /* Enable strict checking of function types. */ + "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ + "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ + "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ + "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ + + /* Additional Checks */ + // "noUnusedLocals": true, /* Report errors on unused locals. */ + // "noUnusedParameters": true, /* Report errors on unused parameters. */ + // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ + // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ + + /* Module Resolution Options */ + "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ + // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ + // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ + // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ + // "typeRoots": [], /* List of folders to include type definitions from. */ + // "types": [], /* Type declaration files to be included in compilation. */ + // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ + // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ + + /* Source Map Options */ + // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ + // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ + + /* Experimental Options */ + // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ + // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + } +} \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.js new file mode 100755 index 0000000..1d822ae --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,65 @@ +const path = require('path') + +const HtmlWebpackPlugin = require('html-webpack-plugin') +const MiniCssExtractPlugin = require('mini-css-extract-plugin') + +module.exports = { + entry: [ + './index.tsx' + ], + output: { + filename: 'bundle.js', + path: path.resolve(__dirname, 'public') + }, + resolve: { + extensions: ['.js', '.jsx', '.ts', '.tsx'] + }, + context: path.resolve(__dirname, 'src'), + devServer: { + contentBase: path.resolve(__dirname, 'public/assets'), + open: true, + }, + plugins: [ + new HtmlWebpackPlugin({ + template: 'index.html' + }), + new MiniCssExtractPlugin({ + filename: 'bundle.css' + }) + ], + stats: { + assets: true, + assetsSort: 'size', + all: false, + errors: true, + colors: true, + performance: true, + timings: true, + }, + module: { + rules: [{ + test: /\.tsx?$/, + loader: 'awesome-typescript-loader', + }, + // { + // test: /\.html$/, + // use: ['html-loader'] + // }, + { + test: /\.css$/, + use: [MiniCssExtractPlugin.loader, 'css-loader'] + }, { + test: /\.styl$/, + use: [MiniCssExtractPlugin.loader, 'css-loader', 'stylus-loader'], + }, { + test: /\.(jpg|png|gif|svg|woff2?|ttf|eot|svg|otf)$/, + use: [{ + loader: 'file-loader', + options: { + name: '[name].[ext]', + outputPath: './assets/', + }, + }], + }] + } +} \ No newline at end of file