mue/src/features/navbar/components/Maximise.jsx

91 lines
2.4 KiB
React
Raw Normal View History

import variables from 'config/variables';
import { PureComponent } from 'react';
2023-03-16 11:11:18 +00:00
import { MdCropFree } from 'react-icons/md';
2021-01-17 18:07:26 +00:00
import { Tooltip } from 'components/Elements';
2023-03-16 11:11:18 +00:00
class Maximise extends PureComponent {
2021-03-23 13:10:34 +00:00
constructor() {
super();
this.state = {
hidden: false,
};
}
2020-09-14 19:48:58 +00:00
setAttribute(blur, brightness, filter) {
// don't attempt to modify the background if it isn't an image
const backgroundType = localStorage.getItem('backgroundType');
if (
backgroundType === 'colour' ||
backgroundType === 'random_colour' ||
backgroundType === 'random_gradient'
) {
return;
}
2021-04-21 18:35:33 +00:00
const element = document.getElementById('backgroundImage');
let backgroundFilter;
if (filter === true) {
const filterData = localStorage.getItem('backgroundFilter');
if (filterData !== 'none') {
backgroundFilter = filterData;
}
}
2021-04-21 18:35:33 +00:00
element.setAttribute(
'style',
`background-image: url(${element.style.backgroundImage
.replace('url("', '')
.replace('")', '')}); -webkit-filter: blur(${blur}px) brightness(${brightness}%) ${
backgroundFilter
? backgroundFilter + '(' + localStorage.getItem('backgroundFilterAmount') + '%)'
: ''
};`,
);
}
2020-09-14 19:48:58 +00:00
maximise = () => {
// hide widgets
const widgets = document.getElementById('widgets');
this.state.hidden === false
? (widgets.style.display = 'none')
: (widgets.style.display = 'flex');
if (this.state.hidden === false) {
this.setState({
hidden: true,
});
this.setAttribute(0, 100);
2021-09-28 22:04:04 +00:00
variables.stats.postEvent('feature', 'Background maximise');
} else {
this.setState({
hidden: false,
});
this.setAttribute(localStorage.getItem('blur'), localStorage.getItem('brightness'), true);
2021-09-28 22:04:04 +00:00
variables.stats.postEvent('feature', 'Background unmaximise');
}
};
2020-09-14 19:48:58 +00:00
render() {
return (
<Tooltip
title={variables.getMessage('modals.main.settings.sections.background.buttons.view')}
>
<button
2024-03-19 21:45:17 +00:00
className="navbarButton"
style={{ fontSize: this.props.fontSize }}
onClick={this.maximise}
aria-label={variables.getMessage('modals.main.settings.sections.background.buttons.view')}
>
2022-09-07 15:04:06 +00:00
<MdCropFree className="topicons" />
</button>
2021-04-08 18:52:17 +00:00
</Tooltip>
);
}
}
2023-03-16 11:11:18 +00:00
export { Maximise as default, Maximise };