Skip to content

Commit

Permalink
docs(demo): add interactive demo
Browse files Browse the repository at this point in the history
  • Loading branch information
cahilfoley committed Jun 9, 2019
1 parent 7c49bd2 commit 470f427
Show file tree
Hide file tree
Showing 15 changed files with 544 additions and 75 deletions.
2 changes: 1 addition & 1 deletion demo/.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
REACT_APP_PACKAGE_NAME=$npm_package_name
REACT_APP_PACKAGE_NAME=@cahil/snowfall
REACT_APP_GITHUB_URL=$npm_package_homepage
432 changes: 393 additions & 39 deletions demo/package-lock.json

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions demo/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
{
"name": "@cahil/snowfall",
"name": "@cahil/snowfall-demo",
"version": "1.0.0",
"private": true,
"homepage": "https://github.com/cahilfoley/snowfall",
"dependencies": {
"@cahil/snowfall": "latest",
"@material-ui/core": "^4.0.2",
"@material-ui/lab": "^4.0.0-alpha.15",
"@types/jest": "^24.0.13",
"@types/node": "^12.0.7",
"@types/react": "^16.8.19",
"@types/react-dom": "^16.8.4",
"gh-pages": "^2.0.1",
"react": "^16.8.6",
"react-color": "^2.17.3",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1",
"typescript": "^3.5.1"
Expand All @@ -31,5 +34,8 @@
"not dead",
"not ie <= 11",
"not op_mini all"
]
],
"devDependencies": {
"@types/react-color": "^3.0.1"
}
}
12 changes: 3 additions & 9 deletions demo/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,11 @@
<head>
<meta charset="utf-8" />
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<link
href="https://fonts.googleapis.com/css?family=Montserrat:400,600"
rel="stylesheet"
/>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<link href="https://fonts.googleapis.com/css?family=Montserrat|Work+Sans&display=swap" rel="stylesheet" />
<meta name="theme-color" content="#000000" />
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<title>Snowfall Demo | @cahil/snowfall</title>
<title>Snowfall Demo | %REACT_APP_PACKAGE_NAME%</title>
</head>
<body>
<noscript> You need to enable JavaScript to run this app. </noscript>
Expand Down
7 changes: 4 additions & 3 deletions demo/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ body {
.app {
position: relative;
background-color: #282c34;
background-image: url(./128.jpg);
background-image: url(./assets/128.jpg);
background-size: cover;
background-position: center center;
min-height: 100vh;
Expand All @@ -33,11 +33,12 @@ body {

h1 {
font-weight: 600;
font-size: 6rem;
font-size: 5rem;
margin: 16px;
}

a {
color: rgba(33, 150, 243, 0.87);
color: inherit;
text-decoration: none;
font-size: 2rem;
}
42 changes: 29 additions & 13 deletions demo/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
import React, { Component } from 'react'
import React, { useContext } from 'react'
import Snowfall from '@cahil/snowfall'
import GithubLink from './GithubLink'
import GithubLink from './components/GithubLink/GithubLink'
import Settings from './components/Settings'
import { SettingsContext, StateProvider } from './context/settings'
import './App.css'

const githubURL = process.env.REACT_APP_GITHUB_URL as string
const packageName = process.env.REACT_APP_PACKAGE_NAME as string

class App extends Component {
render() {
return (
<div className="app">
<GithubLink url={githubURL} />
<Snowfall snowflakeCount={200} />
<h1>snowfall</h1>
<a href={githubURL}>{packageName}</a>
</div>
)
}
const Demo = () => {
const settings = useContext(SettingsContext)

return <Snowfall color={settings.color} snowflakeCount={settings.snowflakeCount} />
}

const Title = () => {
const settings = useContext(SettingsContext)

return (
<a href={githubURL} style={{ color: settings.color }}>
<h1>{packageName}</h1>
</a>
)
}

const App = () => (
<StateProvider>
<div className="app">
<GithubLink url={githubURL} />
<Title />
<Demo />
<Settings />
</div>
</StateProvider>
)

export default App
File renamed without changes
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions demo/src/components/Settings/Settings.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.settings-container {
background-color: rgba(66, 66, 66, 0.7) !important;
width: 100%;
max-width: 400px;
padding: 32px;
}
61 changes: 61 additions & 0 deletions demo/src/components/Settings/Settings.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import React, { useContext } from 'react'
import { CirclePicker } from 'react-color'
import Box from '@material-ui/core/Box'
import Paper from '@material-ui/core/Paper'
import Typography from '@material-ui/core/Typography'
import Slider from '@material-ui/lab/Slider'
import { SettingsContext, SnowfallSettings } from 'context/settings'
import { ThemeProvider } from './theme'

import './Settings.css'

const colors = [
'#dee4fd',
'#e91e63',
'#9c27b0',
'#673ab7',
'#3f51b5',
'#2196f3',
'#03a9f4',
'#00bcd4',
'#009688',
'#4caf50',
'#8bc34a',
'#cddc39',
'#ffeb3b',
'#ffc107',
'#ff9800',
'#ff5722',
'#795548',
'#607d8b',
]

const Settings = () => {
const settings = useContext(SettingsContext) as SnowfallSettings

return (
<ThemeProvider>
<Paper className="settings-container">
<Typography gutterBottom>Snowflake Count - {settings.snowflakeCount}</Typography>
<Slider
value={settings.snowflakeCount}
min={0}
max={750}
step={1}
onChange={(_, value) => settings.setSnowflakeCount(value)}
/>
<Box my={2}>
<Typography gutterBottom>Color - {settings.color}</Typography>
<CirclePicker
colors={colors}
width="100%"
color={settings.color}
onChangeComplete={value => settings.setColor(value.hex)}
/>
</Box>
</Paper>
</ThemeProvider>
)
}

export default Settings
1 change: 1 addition & 0 deletions demo/src/components/Settings/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './Settings'
15 changes: 15 additions & 0 deletions demo/src/components/Settings/theme.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as React from 'react'
import { createMuiTheme, MuiThemeProvider } from '@material-ui/core/styles'

export const theme = createMuiTheme({
palette: {
type: 'dark',
primary: {
main: 'rgba(33, 150, 243, 0.87)',
},
},
})

export const ThemeProvider: React.FC = ({ children }) => {
return <MuiThemeProvider theme={theme}>{children}</MuiThemeProvider>
}
20 changes: 20 additions & 0 deletions demo/src/context/settings.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React, { createContext, useState, FC } from 'react'
import { SnowfallProps } from '@cahil/snowfall'

export interface SnowfallSettings extends SnowfallProps {
setColor: (color: string) => void
setSnowflakeCount: (count: number) => void
}

export const SettingsContext = createContext<Partial<SnowfallSettings>>({})

export const StateProvider: FC = ({ children }) => {
const [color, setColor] = useState('#dee4fd')
const [snowflakeCount, setSnowflakeCount] = useState(200)

return (
<SettingsContext.Provider value={{ color, setColor, snowflakeCount, setSnowflakeCount }}>
{children}
</SettingsContext.Provider>
)
}
11 changes: 3 additions & 8 deletions demo/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,14 @@
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"baseUrl": "src",
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve",
"lib": [
"dom",
"dom.iterable",
"esnext"
]
"lib": ["dom", "dom.iterable", "esnext"]
},
"include": [
"src"
]
"include": ["src"]
}

0 comments on commit 470f427

Please sign in to comment.