Newer
Older
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*Copyright (C) 2019 Centro de Computacao Cientifica e Software Livre
Departamento de Informatica - Universidade Federal do Parana
This file is part of Plataforma Integrada MEC.
Plataforma Integrada MEC is free software: you can redistribute it and/or modify
it under the terxs of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Plataforma Integrada MEC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Plataforma Integrada MEC. If not, see <http://www.gnu.org/licenses/>.*/
import React, { useEffect } from 'react';
import './ContrastBar.css';
import ContrastImageOn from '../../img/OnContrastIcon.png';
import ContrastImageOff from '../../img/OffContrastIcon.png';
import { Store } from '../../Store';
import Grid from "@material-ui/core/Grid"
import { Button } from '@material-ui/core';
import styled from 'styled-components';
/**
* Bar allowing for the toggle of the high contrast mode on the page.
*/
function ContrastBar() {
/* eslint-disable */
// Hook to set contrast context
const { state, dispatch } = React.useContext(Store);
const handleScrollTo = (location) => {
if (location === "Pesquisa_scroll")
dispatch({
type: 'HANDLE_SEARCH_BAR',
opened: !state.searchOpen
})
document.getElementById(location).scrollIntoView({ behavior: 'smooth' });
}
useEffect(() => {
const testContrast = localStorage.getItem('@portalmec/contrast');
if (testContrast) {
setContrastAction(testContrast);
} else {
setContrastAction('');
}
}, []);
const setContrastAction = (newContrast) => {
localStorage.setItem('@portalmec/contrast', newContrast)
return dispatch({
type: 'SET_CONTRAST',
payload: newContrast
})
}
const setFontSizeAction = (newFontSize) => {
return dispatch({
type: 'SET_FONT_SIZE',
payload: newFontSize
})
}
const toggleContrast = () => {
var status = (state.contrast === '' ? 'Contrast' : '')
setContrastAction(status)
}
const incrementFontSize = () => {
document.getElementsByTagName("body")[0].style.fontSize = (parseInt(state.fontSize, 10) + 1) + "px";
setFontSizeAction(parseInt(state.fontSize, 10) + 1);
}
const decrementFontSize = () => {
document.getElementsByTagName("body")[0].style.fontSize = (parseInt(state.fontSize, 10) - 1) + "px";
setFontSizeAction(parseInt(state.fontSize, 10) - 1);
}
const defaultFontSize = () => {
setFontSizeAction(15);
document.getElementsByTagName("body")[0].style.fontSize = "15px";
}
return (
<React.Fragment>
<StyledGrid contrast={state.contrast} xs={12}>
{
window.innerWidth > 750 ?
(
<>
<Grid xs={8}>
<StyledButton style={{justifyContent: "flex-start"}}>
<a href="/" accessKey="1" title="Ir para a página principal alt + 1">
<span className={`${state.contrast}text`}>Plataforma MEC de Recursos Educacionais Digitais</span>
</a>
</StyledButton>
</Grid>
<Grid xs={4} style={{display: "flex"}}>
<Grid xs={3}>
<StyledButton onClick={() => handleScrollTo("Conteudo_scroll")}>
<a className={`${state.contrast}text`} accessKey="2" title="Ir para o conteúdo alt + 2">
Conteúdo
</a>
</StyledButton>
</Grid>
<Grid xs={3}>
<StyledButton onClick={() => handleScrollTo("Pesquisa_scroll")}>
<a className={`${state.contrast}text`} accessKey="3" title="Ir para o menu e a barra de pesquisa alt + 3">
Menu
</a>
</StyledButton>
</Grid>
<Grid xs={3}>
<StyledButton onClick={() => handleScrollTo("Rodape_scroll")}>
<a className={`${state.contrast}text`} accessKey="4" title="Ir para o rodapé alt + 4">
Rodapé
</a>
</StyledButton>
</Grid>
<Grid xs={3}>
<StyledButton onClick={toggleContrast}>
<a className={`${state.contrast}text`} title={state.contrast === "" ? "Ativar alto contraste" : "Desativar alto contraste"}>
<img className='Constrasticon' src={state.contrast === "" ? ContrastImageOff : ContrastImageOn} style={{ paddingRight: "15px" }} alt="Ícone de contraste" />
</a>
</StyledButton>
</Grid>
</Grid>
</>
)
:
(
<>
<Grid xs={12} style={{display: "flex"}}>
<Grid xs={3}>
<StyledButton>
<a href="/" accessKey="1" title="Ir para a página principal alt + 1">
<span className={`${state.contrast}text`}>MEC RED</span>
</a>
</StyledButton>
</Grid>
<Grid xs={3}>
<StyledButton onClick={() => handleScrollTo("Conteudo_scroll")}>
<a className={`${state.contrast}text`} accessKey="2" title="Ir para o conteúdo alt + 2">
Conteúdo
</a>
</StyledButton>
</Grid>
<Grid xs={2}>
<StyledButton onClick={() => handleScrollTo("Pesquisa_scroll")}>
<a className={`${state.contrast}text`} accessKey="3" title="Ir para o menu e a barra de pesquisa alt + 3">
Menu
</a>
</StyledButton>
</Grid>
<Grid xs={3}>
<StyledButton onClick={() => handleScrollTo("Rodape_scroll")}>
<a className={`${state.contrast}text`} accessKey="4" title="Ir para o rodapé alt + 4">
Rodapé
</a>
</StyledButton>
</Grid>
<Grid xs={1}>
<StyledButton onClick={toggleContrast}>
<a className={`${state.contrast}text`} title={state.contrast === "" ? "Ativar alto contraste" : "Desativar alto contraste"}>
<img className='Constrasticon' src={state.contrast === "" ? ContrastImageOff : ContrastImageOn} style={{ paddingRight: "15px" }} alt="Ícone de contraste" />
</a>
</StyledButton>
</Grid>
</Grid>
</>
)
}
</StyledGrid>
</React.Fragment>
);
}
const StyledGrid = styled(Grid) `
display: flex;
padding-left: 15px;
padding-right: 15px;
background: ${props => props.contrast === "" ? "white" : "black"};
border-bottom: ${props => props.contrast === "" ? "1px solid #666" : "1px solid white"};
`
const StyledButton = styled(Button)`
width: 100%;
`
/*
<div>
<a className={`${state.contrast}text`} onClick={incrementFontSize} title="Aumentar tamanho da fonte">
A+
</a>
<a className={`${state.contrast}text`} onClick={decrementFontSize} title="Diminuir tamanho da fonte">
A-
</a>
<a className={`${state.contrast}text`} onClick={defaultFontSize} title="Restaurar tamanho da fonte">
A
</a>
</div>
*/
export default ContrastBar;