-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathcontext.js
More file actions
85 lines (73 loc) · 2.24 KB
/
context.js
File metadata and controls
85 lines (73 loc) · 2.24 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { useTranslation } from 'next-i18next'
import React, { useContext } from 'react'
export const AppContext = React.createContext()
import { colors, fontSizes, fonts } from './constants'
export const AppProvider = ({ children }) => {
const { i18n } = useTranslation('common')
const changeLanguage = () => {
console.log(i18n.language === 'en')
if (i18n.language === 'en') {
i18n.changeLanguage('tr')
} else {
i18n.changeLanguage('en')
}
}
const handleColor = e => {
if (e.target.classList.contains('btn')) {
const newColor = colors[e.target.dataset.label]
var r = document.querySelector(':root')
r.style.setProperty('--color-primary', newColor)
var titles2 = document.querySelectorAll('.title--2')
var titles3 = document.querySelectorAll('.title--3')
;[...titles2, ...titles3].forEach(t => {
t.style.color = newColor
})
var svgs = document.querySelectorAll('svg')
svgs.forEach(svg => {
svg.style.color = newColor
})
}
}
const handleFont = (e, idx) => {
const newFont = fonts[idx]
var r = document.querySelector(':root')
r.style.setProperty('--font', newFont)
const allp = document.querySelectorAll('p')
console.log(allp)
allp.forEach(p => {
p.style.fontFamily = newFont
})
}
const handleFontSize = (e, idx) => {
const allp = document.querySelectorAll('p')
const allptitle2 = document.querySelectorAll('p.title--2')
const allptitle3 = document.querySelectorAll('p.title--3')
const pheader = document.querySelector('.main__header-name')
const smalls = [1.25, 1.4, 1.8, 2, 2.25]
const mids = [1.55, 1.8, 2, 2.25, 2.5]
const bigs = [5, 6, 7, 8, 9]
allp.forEach(p => {
p.style.fontSize = `${smalls[idx]}rem`
})
;[...allptitle2, ...allptitle3].forEach(p => {
p.style.fontSize = `${mids[idx]}rem`
})
pheader.style.fontSize = `${bigs[idx]}rem`
}
return (
<AppContext.Provider
value={{
language: i18n.language,
changeLanguage,
handleColor,
handleFont,
handleFontSize,
}}
>
{children}
</AppContext.Provider>
)
}
export const useGlobalContext = () => {
return useContext(AppContext)
}