-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
68 lines (63 loc) · 2.52 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { h as $, app } from "hyperapp";
import { SCREENS } from "./src/constants/AppConstant";
import Stack from './src/utils/Stack';
import './index.css';
import './toast.css';
const init = {
darkMode: true,
currentScreen: 0,
primaryColor: { h: 207, s: 70, l: 50 },
accentColor: { h: 155, s: 70, l: 50 },
grey: { h: 207, s: 10, l: 40 },
red: { h: 0, s: 70, l: 40 },
green: { h: 145, s: 55, l: 40 },
yellow: { h: 50, s: 90, l: 40 },
toast: { show: false, message: '' }
};
const primaryColorUndoStack = new Stack();
const accentColorUndoStack = new Stack();
const primaryColorRedoStack = new Stack();
const accentColorRedoStack = new Stack();
const initializeStack = () => {
primaryColorUndoStack.push(init.primaryColor.h);
accentColorUndoStack.push(init.accentColor.h);
}
const toggleDarkMode = (state) => ({ ...state, darkMode: !state.darkMode });
const gotoNextStep = state => ({ ...state, currentScreen: Math.min(++state.currentScreen, SCREENS.length - 1) });
const gotoPreviousStep = state => ({ ...state, currentScreen: Math.max(--state.currentScreen, 0) });
app({
init: [init, initializeStack()],
view: state => $('div', { class: { dark: state.darkMode } }, [
$(SCREENS[state.currentScreen], {
...state,
primaryColorUndoStack, accentColorUndoStack,
primaryColorRedoStack, accentColorRedoStack
}),
$('div', { class: 'topbar' }, [
$('a', { href: '#', title: "Toggle darkness!!!", onclick: toggleDarkMode }, [
$('i', { class: { fas: true, 'fa-moon': !state.darkMode, 'fa-sun': state.darkMode } })
]),
$('a', { href: 'https://github.com/tahins/refactoring-color', target: '_blank' }, [
$('i', { class: 'fab fa-github' })
]),
$('a', { href: 'https://twitter.com/tahins', target: '_blank' }, [
$('i', { class: 'fab fa-twitter' })
])
]),
$('div', { class: 'navigation' }, [
state.currentScreen > 0 && $('a', { href: '#', onclick: gotoPreviousStep }, [
$('i', { class: 'fas fa-angle-left' })
]),
state.currentScreen < SCREENS.length - 1 && $('a', { href: '#', onclick: gotoNextStep }, [
$('i', { class: 'fas fa-angle-right' })
])
]),
$('div', {
class: {
toast: true,
show: state.toast.show
}
}, state.toast.message)
]),
node: document.getElementById("app")
});