forked from SAP/machine-learning-lab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathButton.jsx
35 lines (30 loc) · 1.01 KB
/
Button.jsx
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
import React, { useState } from 'react';
import { useTranslation } from 'react-i18next';
import styled from 'styled-components';
// styled-components uses Tagged Templates syntax (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals ; https://styled-components.com/docs/basics)
const StyledButton = styled.button`
margin-top: 12px;
color: ${(props) => (props.isEnabled ? 'white' : 'black')};
background-color: ${(props) => (props.isEnabled ? 'blue' : 'orange')};
`;
function Button() {
const { t, i18n } = useTranslation();
const [isEnabled, setEnabled] = useState();
const click = () => {
if (isEnabled) {
i18n.changeLanguage('en');
} else {
i18n.changeLanguage('de');
}
setEnabled(!isEnabled);
};
const language = isEnabled ? 'Englisch' : 'German';
return (
<div>
<StyledButton type="button" onClick={click} isEnabled={isEnabled}>
{t('change-language', { language })}
</StyledButton>
</div>
);
}
export default Button;