@zuzjs/ui 0.2.4 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/index.js +214 -15
- package/package.json +4 -2
- package/src/actions/addForm.tsx +0 -0
- package/src/actions/index.tsx +29 -0
- package/src/actions/redo.tsx +1 -0
- package/src/actions/reset.tsx +1 -0
- package/src/actions/undo.tsx +1 -0
- package/src/comps/app.tsx +34 -0
- package/src/comps/box.tsx +23 -0
- package/src/comps/button.tsx +45 -0
- package/src/comps/checkbox.tsx +74 -0
- package/src/comps/component.tsx +32 -0
- package/src/comps/contextmenu.tsx +43 -0
- package/src/comps/cover.tsx +34 -0
- package/src/comps/form.tsx +89 -0
- package/src/comps/heading.tsx +31 -0
- package/src/comps/icon.tsx +36 -0
- package/src/comps/image.tsx +26 -0
- package/src/comps/input.tsx +80 -0
- package/src/comps/masonry.tsx +192 -0
- package/src/comps/placeholder.tsx +58 -0
- package/src/comps/root.tsx +32 -0
- package/src/comps/select.tsx +63 -0
- package/src/comps/spacer.tsx +20 -0
- package/src/comps/spinner.tsx +36 -0
- package/src/comps/text.tsx +27 -0
- package/src/comps/toaster.tsx +115 -0
- package/src/comps/tweet.tsx +48 -0
- package/src/context/AppContext.tsx +3 -0
- package/src/context/AppProvider.tsx +101 -0
- package/src/context/_AppProvider.tsx +116 -0
- package/src/context/combineReducers.tsx +47 -0
- package/src/context/combineState.tsx +14 -0
- package/src/context/createSlice.tsx +40 -0
- package/src/context/index.tsx +6 -0
- package/src/context/reduceReducers.tsx +6 -0
- package/src/context/store/appbase.tsx +19 -0
- package/src/context/store/theme.tsx +53 -0
- package/src/core/defaultTheme.ts +89 -0
- package/src/core/extractCurrentDesignState.tsx +0 -0
- package/src/core/index.ts +285 -0
- package/src/core/router.ts +86 -0
- package/src/core/styles.ts +361 -0
- package/src/hooks/index.tsx +8 -0
- package/src/hooks/useAppReducer.tsx +40 -0
- package/src/hooks/useChooseEffect.tsx +6 -0
- package/src/hooks/useDevice.tsx +164 -0
- package/src/hooks/useDispatch.tsx +37 -0
- package/src/hooks/useImage.tsx +58 -0
- package/src/hooks/useResizeObserver.tsx +84 -0
- package/src/hooks/useRouter.tsx +45 -0
- package/src/hooks/useSelector.tsx +9 -0
- package/src/hooks/useStore.tsx +27 -0
- package/src/hooks/useTheme.tsx +9 -0
- package/src/hooks/useToast.tsx +11 -0
- package/src/index.tsx +33 -0
- package/src/kit/Builder.tsx +18 -0
- package/src/kit/Component.tsx +32 -0
- package/src/kit/Header.tsx +21 -0
- package/src/redux/slices/app.js +26 -0
- package/src/redux/slices/form.js +46 -0
- package/src/redux/store.js +33 -0
- package/src/scss/constants.scss +4 -0
- package/src/scss/mixins.scss +3 -0
- package/src/scss/props.scss +60 -0
- package/src/scss/style.scss +106 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { nanoid } from 'nanoid'
|
|
2
|
+
|
|
3
|
+
class Toaster {
|
|
4
|
+
|
|
5
|
+
#container : any;
|
|
6
|
+
#startTop : number
|
|
7
|
+
#tout : null
|
|
8
|
+
#defaultTimeLeft : number
|
|
9
|
+
|
|
10
|
+
constructor(config?: {
|
|
11
|
+
root : string,
|
|
12
|
+
duration: number
|
|
13
|
+
}){
|
|
14
|
+
this.#startTop = 20
|
|
15
|
+
this.#defaultTimeLeft = 4
|
|
16
|
+
const rootID = config?.root || `toast-container`;
|
|
17
|
+
if(document.querySelector(`#${rootID}`)) return;
|
|
18
|
+
var self = this;
|
|
19
|
+
var root = document.createElement('div');
|
|
20
|
+
root.id = rootID;
|
|
21
|
+
document.body.appendChild(root);
|
|
22
|
+
this.#container = document.querySelector(`#${rootID}`)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
show = (
|
|
26
|
+
message: string | null,
|
|
27
|
+
duration?: number
|
|
28
|
+
) => {
|
|
29
|
+
let self = this;
|
|
30
|
+
self.toast({
|
|
31
|
+
message: message,
|
|
32
|
+
duration: duration
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
dismiss(ID: string){
|
|
37
|
+
let self = this
|
|
38
|
+
self.#tout && clearTimeout(self.#tout);
|
|
39
|
+
setTimeout(()=>{
|
|
40
|
+
let tost = document.querySelector(`#${ID}`);
|
|
41
|
+
tost && tost.classList.remove("visible");
|
|
42
|
+
// tost && tost.classList.add("hidden");
|
|
43
|
+
setTimeout(()=>{
|
|
44
|
+
try{
|
|
45
|
+
document.getElementById(ID).parentNode.removeChild(document.getElementById(ID));
|
|
46
|
+
}catch(e){}
|
|
47
|
+
self.arrangeToasts();
|
|
48
|
+
}, 200);
|
|
49
|
+
}, 200);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
toast(config?: {
|
|
53
|
+
message: string | null,
|
|
54
|
+
duration: number
|
|
55
|
+
}){
|
|
56
|
+
|
|
57
|
+
var self = this;
|
|
58
|
+
var tout = null,
|
|
59
|
+
ID = 'toast-' + nanoid(),
|
|
60
|
+
toast = document.createElement('div'),
|
|
61
|
+
toastBG = document.createElement('div');
|
|
62
|
+
|
|
63
|
+
toast.id = ID;
|
|
64
|
+
toast.style.backgroundColor = `#111`
|
|
65
|
+
toast.style.color = `#fff`
|
|
66
|
+
toast.style.transform = `translate(-50%, -300px) scale(0.5)`;
|
|
67
|
+
toast.style.position = `fixed`
|
|
68
|
+
toast.style.padding = `6px 12px`
|
|
69
|
+
toast.style.fontSize = `14px`
|
|
70
|
+
toast.style.left = `50%`
|
|
71
|
+
toast.style.maxWidth = `95%`
|
|
72
|
+
toast.style.zIndex = `2147483647`
|
|
73
|
+
toast.classList.add( 'zuz-toast' );
|
|
74
|
+
toast.classList.add( 'fixed' );
|
|
75
|
+
toast.classList.add( 'f' );
|
|
76
|
+
|
|
77
|
+
toast.innerHTML = config.message || `You haven't passed "message" in this toast`;
|
|
78
|
+
|
|
79
|
+
self.#container.appendChild(toast);
|
|
80
|
+
|
|
81
|
+
self.arrangeToasts()
|
|
82
|
+
.then(() => {
|
|
83
|
+
setTimeout(()=>{
|
|
84
|
+
let tost = document.querySelector("#"+ID);
|
|
85
|
+
tost.classList.add("showing");
|
|
86
|
+
tout = setTimeout(() => self.dismiss(ID), (config?.duration == undefined ? self.#defaultTimeLeft : config?.duration == -1 ? 86400 : config?.duration) * 1000);
|
|
87
|
+
setTimeout(()=>{
|
|
88
|
+
let tost = document.querySelector("#"+ID);
|
|
89
|
+
tost.classList.remove("showing");
|
|
90
|
+
tost.classList.add("visible");
|
|
91
|
+
}, 200)
|
|
92
|
+
|
|
93
|
+
}, 10)
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
arrangeToasts(){
|
|
98
|
+
var self = this, top = self.#startTop;
|
|
99
|
+
return new Promise((resolve, reject) => {
|
|
100
|
+
var toasts = document.querySelectorAll(".zuz-toast"),
|
|
101
|
+
i = toasts.length;
|
|
102
|
+
while(i--){
|
|
103
|
+
toasts[i]['style'].top = `${top}px`
|
|
104
|
+
top += parseInt(getComputedStyle(toasts[i]).height.replace('px', '')) + 6;
|
|
105
|
+
}
|
|
106
|
+
resolve(null);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export default Toaster;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
+
// import PropTypes from `prop-types`
|
|
3
|
+
import Box from './box'
|
|
4
|
+
import { addScript } from '../core';
|
|
5
|
+
|
|
6
|
+
const Tweet = (props) => {
|
|
7
|
+
|
|
8
|
+
const [rand, setRand] = useState(Math.random())
|
|
9
|
+
const _tweet = useRef()
|
|
10
|
+
|
|
11
|
+
const renderTweet = () => {
|
|
12
|
+
const twttr = window['twttr']
|
|
13
|
+
twttr.ready().then(({ widgets }) => {
|
|
14
|
+
const { options, onTweetLoadSuccess, onTweetLoadError } = props
|
|
15
|
+
widgets
|
|
16
|
+
.createTweetEmbed(props.id, _tweet.current, options || {})
|
|
17
|
+
.then((twitterWidgetElement) => {
|
|
18
|
+
// this.setState({
|
|
19
|
+
// isLoading: false
|
|
20
|
+
// })
|
|
21
|
+
// onTweetLoadSuccess && onTweetLoadSuccess(twitterWidgetElement)
|
|
22
|
+
})
|
|
23
|
+
.catch(() => {})
|
|
24
|
+
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
const twttr = window['twttr']
|
|
30
|
+
if (!(twttr && twttr.ready)){
|
|
31
|
+
addScript(`https://platform.twitter.com/widgets.js`, renderTweet)
|
|
32
|
+
}else{
|
|
33
|
+
renderTweet()
|
|
34
|
+
}
|
|
35
|
+
}, [])
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
|
|
39
|
+
}, [rand])
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<Box as={`tweet`} weight={1} bref={_tweet}></Box>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
export default Tweet;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
useCallback,
|
|
3
|
+
useEffect,
|
|
4
|
+
useMemo,
|
|
5
|
+
useReducer
|
|
6
|
+
} from 'react'
|
|
7
|
+
import PropTypes from 'prop-types'
|
|
8
|
+
import AppContext from './AppContext'
|
|
9
|
+
import AppTheme from './store/theme'
|
|
10
|
+
|
|
11
|
+
let isMounted = true;
|
|
12
|
+
export const STORE_KEY = `__zuzjs`
|
|
13
|
+
export const STORE_FORM_KEY = `${STORE_KEY}forms`
|
|
14
|
+
export const STORE_DEFAUTLS = [`${STORE_KEY}base`, `${STORE_KEY}forms`]
|
|
15
|
+
|
|
16
|
+
const defaultState = {
|
|
17
|
+
[`${STORE_KEY}base`] : {
|
|
18
|
+
debug: true,
|
|
19
|
+
loading: false,
|
|
20
|
+
_tmp: Math.random()
|
|
21
|
+
},
|
|
22
|
+
[STORE_FORM_KEY] : {
|
|
23
|
+
forms: {}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const rootReducer = (state, action ) => ({
|
|
28
|
+
...state,
|
|
29
|
+
...action.payload
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
const AppProvider = ({
|
|
33
|
+
children,
|
|
34
|
+
initialState = {},
|
|
35
|
+
theme = {}
|
|
36
|
+
}) => {
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
isMounted = true;
|
|
41
|
+
return () => {
|
|
42
|
+
isMounted = false;
|
|
43
|
+
}
|
|
44
|
+
}, [])
|
|
45
|
+
|
|
46
|
+
const rootState = useMemo(() => ({
|
|
47
|
+
...defaultState,
|
|
48
|
+
...initialState,
|
|
49
|
+
theme: new AppTheme({ theme }).get()
|
|
50
|
+
}), [initialState])
|
|
51
|
+
|
|
52
|
+
const [state, _dispatch] = useReducer(rootReducer, rootState);
|
|
53
|
+
|
|
54
|
+
const dispatch = useCallback((args) => {
|
|
55
|
+
if (isMounted) {
|
|
56
|
+
_dispatch({ ...args });
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
[_dispatch],
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
// const dispatch = useCallback((payload = {}, _key = 'base') => {
|
|
63
|
+
// if(isMounted){
|
|
64
|
+
// const key = STORE_DEFAUTLS.indexOf(`${STORE_KEY}${_key}`) > -1 ? `${STORE_KEY}${_key}` : _key;
|
|
65
|
+
// const _state = { ...state[key] }
|
|
66
|
+
// console.log('key', key)
|
|
67
|
+
// console.log('state', _state)
|
|
68
|
+
// _dispatch({
|
|
69
|
+
// type: 'any',
|
|
70
|
+
// payload: {
|
|
71
|
+
// payload
|
|
72
|
+
// }
|
|
73
|
+
// })
|
|
74
|
+
// }
|
|
75
|
+
// }, [_dispatch]);
|
|
76
|
+
|
|
77
|
+
const providedValue = useMemo(
|
|
78
|
+
() => ({
|
|
79
|
+
...state,
|
|
80
|
+
dispatch
|
|
81
|
+
}),
|
|
82
|
+
[state]
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
return <AppContext.Provider value={providedValue}>{children}</AppContext.Provider>
|
|
87
|
+
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
AppProvider.defaultProps = {
|
|
91
|
+
theme: {},
|
|
92
|
+
initialState : {},
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
AppProvider.propTypes = {
|
|
96
|
+
children: PropTypes.node.isRequired,
|
|
97
|
+
initialState: PropTypes.instanceOf(Object),
|
|
98
|
+
theme: PropTypes.instanceOf(Object)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export default AppProvider
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
useCallback,
|
|
3
|
+
useEffect,
|
|
4
|
+
useMemo,
|
|
5
|
+
useReducer
|
|
6
|
+
} from 'react'
|
|
7
|
+
import PropTypes from 'prop-types'
|
|
8
|
+
import AppContext from './AppContext'
|
|
9
|
+
// import useAppReducer from '../hooks/useAppReducer'
|
|
10
|
+
import AppTheme from './store/theme'
|
|
11
|
+
let isMounted = true;
|
|
12
|
+
import appSlice from './store/appbase'
|
|
13
|
+
import combineReducers, { combineState } from './combineReducers'
|
|
14
|
+
import reduceReducers from './reduceReducers'
|
|
15
|
+
// const rootReducer = (state, action ) => ({
|
|
16
|
+
// ...state,
|
|
17
|
+
// ...action.payload
|
|
18
|
+
// })
|
|
19
|
+
|
|
20
|
+
// const rootReducer = combineReducers()
|
|
21
|
+
|
|
22
|
+
const AppProvider = ({
|
|
23
|
+
children,
|
|
24
|
+
// initialState = {},
|
|
25
|
+
reducers = {},
|
|
26
|
+
theme = {}
|
|
27
|
+
}) => {
|
|
28
|
+
|
|
29
|
+
const _dynamiceState = useMemo(() => {
|
|
30
|
+
const __ = {}
|
|
31
|
+
Object.keys(reducers).map(k => {
|
|
32
|
+
__[reducers[k].name] = [reducers[k].reducer, reducers[k].state]
|
|
33
|
+
})
|
|
34
|
+
return __
|
|
35
|
+
}, [reducers])
|
|
36
|
+
|
|
37
|
+
const _dynamiceReducers = useMemo(() => {
|
|
38
|
+
const __ = {}
|
|
39
|
+
Object.keys(reducers).map(k => {
|
|
40
|
+
__[reducers[k].name] = reduceReducers(reducers[k].reducer)
|
|
41
|
+
})
|
|
42
|
+
return __
|
|
43
|
+
}, [reducers])
|
|
44
|
+
|
|
45
|
+
const themeReducer = useCallback(() => {
|
|
46
|
+
(state, action) => ({
|
|
47
|
+
...state,
|
|
48
|
+
...action.payload
|
|
49
|
+
})
|
|
50
|
+
}, [])
|
|
51
|
+
|
|
52
|
+
// const [rootReducer, rootState] = useMemo(() => combineReducers({
|
|
53
|
+
// theme: [themeReducer, new AppTheme({ theme }).get()],
|
|
54
|
+
// [appSlice.name] : [appSlice.reducer, appSlice.state],
|
|
55
|
+
// ..._dynamiceReducers
|
|
56
|
+
// }), [reducers]);
|
|
57
|
+
|
|
58
|
+
const [_, rootState] = combineState({
|
|
59
|
+
theme: [themeReducer, new AppTheme({ theme }).get()],
|
|
60
|
+
[appSlice.name] : [appSlice.reducer, appSlice.state],
|
|
61
|
+
..._dynamiceState
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
const rootReducer = combineReducers({
|
|
65
|
+
theme: reduceReducers(themeReducer),
|
|
66
|
+
[appSlice.name] : reduceReducers(appSlice.reducer),
|
|
67
|
+
..._dynamiceReducers
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
console.log(rootState)
|
|
71
|
+
|
|
72
|
+
const [state, dispatch] = useReducer(
|
|
73
|
+
rootReducer,
|
|
74
|
+
rootState
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
isMounted = true;
|
|
79
|
+
return () => {
|
|
80
|
+
isMounted = false;
|
|
81
|
+
}
|
|
82
|
+
}, [])
|
|
83
|
+
|
|
84
|
+
// const dispatch = useCallback(() => {
|
|
85
|
+
// if(isMounted){
|
|
86
|
+
// // let ags = { ...args, action: }
|
|
87
|
+
// _dispatch();
|
|
88
|
+
// // _dispatch({ action: action, payload: payload })
|
|
89
|
+
// }
|
|
90
|
+
// }, [_dispatch]);
|
|
91
|
+
|
|
92
|
+
const providedValue = useMemo(
|
|
93
|
+
() => ({
|
|
94
|
+
...rootState,
|
|
95
|
+
// defaultState,
|
|
96
|
+
dispatch
|
|
97
|
+
}),
|
|
98
|
+
[state]
|
|
99
|
+
// [defaultState, state]
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
return <AppContext.Provider value={providedValue}>{children}</AppContext.Provider>
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
AppProvider.defaultProps = {
|
|
106
|
+
reducers: {}
|
|
107
|
+
// initialState : {},
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
AppProvider.propTypes = {
|
|
111
|
+
children: PropTypes.node.isRequired,
|
|
112
|
+
// initialState: PropTypes.instanceOf(Object)
|
|
113
|
+
reducers: PropTypes.instanceOf(Object)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export default AppProvider
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export const combineState = reducers => {
|
|
2
|
+
const reducerKeys = Object.keys(reducers);
|
|
3
|
+
const reducerValues = Object.values(reducers);
|
|
4
|
+
|
|
5
|
+
let globalState
|
|
6
|
+
reducerKeys.forEach((k, i) => globalState = { ...globalState, [k]: reducerValues[i][1] } )
|
|
7
|
+
|
|
8
|
+
let finalReducers = {}
|
|
9
|
+
reducerValues.forEach((v, i) => finalReducers = { ...finalReducers, [reducerKeys[i]] : v[0] });
|
|
10
|
+
|
|
11
|
+
return [
|
|
12
|
+
(state, action) => {
|
|
13
|
+
console.log('state', state)
|
|
14
|
+
console.log('action', action)
|
|
15
|
+
let hasStateChanged = false
|
|
16
|
+
const newState = {}
|
|
17
|
+
let nextStateForCurrentKey = {}
|
|
18
|
+
for(let i = 0; i < reducerKeys.length; i++){
|
|
19
|
+
const currentKey = reducerKeys[i]
|
|
20
|
+
const currentReducer = finalReducers[currentKey]
|
|
21
|
+
const prevStateForCurrentKey = state[currentKey]
|
|
22
|
+
nextStateForCurrentKey = currentReducer(
|
|
23
|
+
prevStateForCurrentKey,
|
|
24
|
+
action
|
|
25
|
+
)
|
|
26
|
+
hasStateChanged = hasStateChanged || nextStateForCurrentKey !== prevStateForCurrentKey
|
|
27
|
+
newState[currentKey] = nextStateForCurrentKey
|
|
28
|
+
}
|
|
29
|
+
return hasStateChanged ? newState : state
|
|
30
|
+
},
|
|
31
|
+
globalState
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const combineReducers = slices => {
|
|
37
|
+
return (state, action) =>
|
|
38
|
+
Object.keys(slices).reduce(
|
|
39
|
+
(acc, prop) => ({
|
|
40
|
+
...acc,
|
|
41
|
+
[prop]: slices[prop](acc[prop], action)
|
|
42
|
+
}),
|
|
43
|
+
state
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export default combineReducers;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const combineState = (state) => {
|
|
2
|
+
// const reducerKeys = Object.keys(state);
|
|
3
|
+
// const stateValues = Object.values(state);
|
|
4
|
+
|
|
5
|
+
// let globalState
|
|
6
|
+
|
|
7
|
+
// reducerKeys.forEach((k, i) => globalState = { ...globalState, [k]: reducerValues[i][1] } )
|
|
8
|
+
|
|
9
|
+
// console.log(globalState)
|
|
10
|
+
|
|
11
|
+
return state;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default combineState
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import React, { useReducer, useMemo } from 'react'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
import combineReducers from './combineReducers'
|
|
4
|
+
|
|
5
|
+
const createSlice = ({
|
|
6
|
+
name,
|
|
7
|
+
initialState,
|
|
8
|
+
reducers
|
|
9
|
+
}) => {
|
|
10
|
+
|
|
11
|
+
// const _dynamiceReducers = {}
|
|
12
|
+
// Object.keys(reducers).map(k => {
|
|
13
|
+
// _dynamiceReducers[reducers[k].name] = [reducers[k].reducer, initialState]
|
|
14
|
+
// })
|
|
15
|
+
|
|
16
|
+
// const _keys = Object.keys(reducers);
|
|
17
|
+
// const [reducer, state] = combineReducers(_dynamiceReducers);
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
name,
|
|
21
|
+
reducer: reducers,
|
|
22
|
+
actions: reducers,
|
|
23
|
+
state: initialState
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
createSlice.defaultProps = {
|
|
29
|
+
name: `app`,
|
|
30
|
+
initialState: {},
|
|
31
|
+
reducers: {}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
createSlice.propTypes = {
|
|
35
|
+
name: PropTypes.string.isRequired,
|
|
36
|
+
initialState: PropTypes.instanceOf(Object).isRequired,
|
|
37
|
+
reducers: PropTypes.instanceOf(Object).isRequired
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export default createSlice;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import createSlice from '../createSlice'
|
|
2
|
+
|
|
3
|
+
const appSlice = createSlice({
|
|
4
|
+
name: 'app',
|
|
5
|
+
initialState: {
|
|
6
|
+
debug: true,
|
|
7
|
+
version: 1.2,
|
|
8
|
+
loading: false
|
|
9
|
+
},
|
|
10
|
+
reducers: {
|
|
11
|
+
setCVersion: (state, action) => state.version = action.payload
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export const {
|
|
16
|
+
setLoading
|
|
17
|
+
} = appSlice.actions
|
|
18
|
+
|
|
19
|
+
export default appSlice;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
class AppTheme {
|
|
2
|
+
|
|
3
|
+
#mode;
|
|
4
|
+
#listen;
|
|
5
|
+
#lightTheme;
|
|
6
|
+
#darkTheme;
|
|
7
|
+
|
|
8
|
+
constructor(_conf){
|
|
9
|
+
const conf = _conf || {}
|
|
10
|
+
this.#listen = "listen" in conf ? conf.listen : (mod) => { console.log(`Theme switched to ${mod}`); };
|
|
11
|
+
this.#mode = conf.mode || "auto";
|
|
12
|
+
this.#lightTheme = {
|
|
13
|
+
//CORE
|
|
14
|
+
tag: "light",
|
|
15
|
+
dark: false,
|
|
16
|
+
primary: '#edeef5',
|
|
17
|
+
secondary: '#f9f9f9',
|
|
18
|
+
textColor: '#111111',
|
|
19
|
+
...( "theme" in conf && "light" in conf.theme ? {...conf.theme.light} : {})
|
|
20
|
+
};
|
|
21
|
+
this.#darkTheme = {
|
|
22
|
+
//CORE
|
|
23
|
+
tag: "dark",
|
|
24
|
+
dark: true,
|
|
25
|
+
primary: '#21222d',
|
|
26
|
+
secondary: '#282a37',
|
|
27
|
+
textColor: '#f9f9f9',
|
|
28
|
+
...( "theme" in conf && "dark" in conf.theme ? {...conf.theme.dark} : {})
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
get = () => {
|
|
33
|
+
let self = this;
|
|
34
|
+
// if(self.#mode === "auto"){
|
|
35
|
+
// window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => {
|
|
36
|
+
// self.#mode = event.matches ? "dark" : "light";
|
|
37
|
+
// self.#listen(self.#mode);
|
|
38
|
+
// });
|
|
39
|
+
// return window.matchMedia &&
|
|
40
|
+
// window.matchMedia('(prefers-color-scheme: dark)').matches ?
|
|
41
|
+
// self.#darkTheme : self.#lightTheme;
|
|
42
|
+
// }else
|
|
43
|
+
if(self.#mode === "light"){
|
|
44
|
+
return self.#lightTheme;
|
|
45
|
+
}else if(self.#mode === "dark"){
|
|
46
|
+
return self.#darkTheme;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export default AppTheme
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
class AppTheme {
|
|
2
|
+
|
|
3
|
+
#mode;
|
|
4
|
+
#listen;
|
|
5
|
+
#lightTheme;
|
|
6
|
+
#darkTheme;
|
|
7
|
+
|
|
8
|
+
constructor(_conf){
|
|
9
|
+
const conf = _conf || {}
|
|
10
|
+
this.#listen = "listen" in conf ? conf.listen : (mod) => { console.log(`Theme switched to ${mod}`); };
|
|
11
|
+
this.#mode = conf.mode || "auto";
|
|
12
|
+
this.#lightTheme = {
|
|
13
|
+
//CORE
|
|
14
|
+
tag: "light",
|
|
15
|
+
dark: false,
|
|
16
|
+
color: "#3a43ac",
|
|
17
|
+
primary: '#edeef5',
|
|
18
|
+
secondary: '#e8e9f0',
|
|
19
|
+
textColor: '#111111',
|
|
20
|
+
borderColor: '#dcdce1',
|
|
21
|
+
//APP
|
|
22
|
+
app: {
|
|
23
|
+
action: 'rgba(0,0,0,0.1)',
|
|
24
|
+
actionHover: 'rgba(255,255,255,0.1)',
|
|
25
|
+
actionActive: 'rgba(0,0,0,0.8)',
|
|
26
|
+
actionDisabled: 'rgba(255,255,255,0.01)',
|
|
27
|
+
shimmerBG: '#383a48',
|
|
28
|
+
shimmerFrom: '#383a48',
|
|
29
|
+
shimmerTo: '#4a4c5b',
|
|
30
|
+
iconBG: '#4a4c5b',
|
|
31
|
+
icon: '#111111',
|
|
32
|
+
sidebarHover: 'rgba(255,255,255,0.2)',
|
|
33
|
+
sidebarActive: 'rgba(255,255,255,1)',
|
|
34
|
+
toolbar: '#d5d6dc',
|
|
35
|
+
tool: 'transparent',
|
|
36
|
+
toolActive: 'rgba(255,255,255,0.75)',
|
|
37
|
+
toolHover: 'rgba(255,255,255,0.5)',
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
this.#darkTheme = {
|
|
41
|
+
//CORE
|
|
42
|
+
tag: "dark",
|
|
43
|
+
dark: true,
|
|
44
|
+
color: "#3a43ac",
|
|
45
|
+
primary: '#21222d',
|
|
46
|
+
secondary: '#282a37',
|
|
47
|
+
textColor: '#f9f9f9',
|
|
48
|
+
borderColor: '#353640',
|
|
49
|
+
//APP
|
|
50
|
+
app: {
|
|
51
|
+
action: 'rgba(255,255,255,0.05)',
|
|
52
|
+
actionHover: 'rgba(255,255,255,0.1)',
|
|
53
|
+
actionActive: 'rgba(255,255,255,0.2)',
|
|
54
|
+
actionDisabled: 'rgba(255,255,255,0.01)',
|
|
55
|
+
shimmerBG: '#383a48',
|
|
56
|
+
shimmerFrom: '#383a48',
|
|
57
|
+
shimmerTo: '#4a4c5b',
|
|
58
|
+
iconBG: '#4a4c5b',
|
|
59
|
+
icon: '#ffffff',
|
|
60
|
+
toolbar: '#21222d',
|
|
61
|
+
tool: 'transparent',
|
|
62
|
+
toolHover: '#2f3144',
|
|
63
|
+
toolActive: '#2f3144',
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
get = () => {
|
|
69
|
+
let self = this;
|
|
70
|
+
// if(self.#mode === "auto"){
|
|
71
|
+
// window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => {
|
|
72
|
+
// self.#mode = event.matches ? "dark" : "light";
|
|
73
|
+
// self.#listen(self.mode);
|
|
74
|
+
// });
|
|
75
|
+
// return window.matchMedia &&
|
|
76
|
+
// window.matchMedia('(prefers-color-scheme: dark)').matches ?
|
|
77
|
+
// self.#darkTheme : self.#lightTheme;
|
|
78
|
+
// }else
|
|
79
|
+
if(self.#mode === "light"){
|
|
80
|
+
return self.#lightTheme;
|
|
81
|
+
}else if(self.#mode === "dark"){
|
|
82
|
+
return self.#darkTheme;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export default AppTheme
|
|
File without changes
|