Skip to content

Commit

Permalink
Switching theme feature
Browse files Browse the repository at this point in the history
  • Loading branch information
UFxx committed Apr 26, 2024
1 parent 0cd3de6 commit 976f821
Show file tree
Hide file tree
Showing 24 changed files with 174 additions and 160 deletions.
15 changes: 0 additions & 15 deletions build/asset-manifest.json

This file was deleted.

1 change: 0 additions & 1 deletion build/index.html

This file was deleted.

2 changes: 0 additions & 2 deletions build/static/css/main.4ee3783a.css

This file was deleted.

1 change: 0 additions & 1 deletion build/static/css/main.4ee3783a.css.map

This file was deleted.

3 changes: 0 additions & 3 deletions build/static/js/main.e02ad37a.js

This file was deleted.

72 changes: 0 additions & 72 deletions build/static/js/main.e02ad37a.js.LICENSE.txt

This file was deleted.

1 change: 0 additions & 1 deletion build/static/js/main.e02ad37a.js.map

This file was deleted.

66 changes: 43 additions & 23 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import React, { useState } from "react";

import OpenSettingsIcon from "./assets/open-settings-icon.png";
import OpenSettingsIconDark from "./assets/open-settings-icon-dark-theme.png";
import OpenSettingsIconLight from "./assets/open-settings-icon-light-theme.png";

import Settings from "./components/Settings/Settings";
import Buttons from "./components/Buttons/Buttons";
import Charts from "./components/Charts/Charts";
import Donwload from "./components/Donwload/Donwload";
import ThemeChanger from "./components/ThemeChanger/ThemeChanger";

function App() {
const [theme, setTheme] = useState(true);

const [labels, setLabels] = useState(["label1", "label2", "label3"]);
const [values, setValues] = useState([100, 200, 300]);

Expand All @@ -27,32 +31,48 @@ function App() {
setSettingsOpen(!settingsOpen);
}

function changeValue(e) {
function changeRadioValue(e) {
setRadioValue(e.target.value);
}

return (
<div className="content">
<div className="chart-container">
{/* ValueState - which radio button is clicked */}
<Charts valueState={radioValue} data={data} />
</div>
<Settings
open={settingsOpen}
changeSettingsOpen={changeSettingsOpen}
data={data}
setLabels={setLabels}
setValues={setValues}
/>
<img
src={OpenSettingsIcon}
alt="open settings icon"
className="settings-open-button"
onClick={changeSettingsOpen}
/>
<Donwload />
<div className="choose-chart-type">
<Buttons changeValue={changeValue} valueState={radioValue} />
<div className={`container-${theme ? "dark" : "light"}`}>
<ThemeChanger setTheme={setTheme} theme={theme} />
<div className={`content-${theme ? "dark" : "light"}`}>
<div className={`chart-container-${theme ? "dark" : "light"}`}>
{/* ValueState - which radio button is clicked */}
<Charts valueState={radioValue} data={data} />
</div>
<Settings
open={settingsOpen}
changeSettingsOpen={changeSettingsOpen}
data={data}
setLabels={setLabels}
setValues={setValues}
theme={theme}
/>
{theme ? (
<img
src={OpenSettingsIconDark}
alt="open settings icon"
className="settings-open-button"
onClick={changeSettingsOpen}
/>
) : (
<img
src={OpenSettingsIconLight}
alt="open settings icon"
className="settings-open-button"
onClick={changeSettingsOpen}
/>
)}
<Donwload theme={theme} />
<div className="choose-chart-type">
<Buttons
changeRadioValue={changeRadioValue}
valueState={radioValue}
/>
</div>
</div>
</div>
);
Expand Down
Binary file added src/assets/close-settings-icon-light-theme.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed src/assets/close-settings-icon.png
Binary file not shown.
Binary file modified src/assets/donwload-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/open-settings-icon-light-theme.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed src/assets/open-settings-icon.png
Binary file not shown.
16 changes: 8 additions & 8 deletions src/components/Buttons/Buttons.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,49 @@ function Buttons(props) {
<>
{/* The name of the chart must begin with a small letter (name i mean chart type) */}
<RadioButton
changeValue={props.changeValue}
changeRadioValue={props.changeRadioValue}
valueState={props.valueState}
name="pie"
value="1"
/>
<RadioButton
changeValue={props.changeValue}
changeRadioValue={props.changeRadioValue}
valueState={props.valueState}
name="bar"
value="2"
/>
<RadioButton
changeValue={props.changeValue}
changeRadioValue={props.changeRadioValue}
valueState={props.valueState}
name="doughnut"
value="3"
/>
<RadioButton
changeValue={props.changeValue}
changeRadioValue={props.changeRadioValue}
valueState={props.valueState}
name="line"
value="4"
/>
<RadioButton
changeValue={props.changeValue}
changeRadioValue={props.changeRadioValue}
valueState={props.valueState}
name="bubble"
value="5"
/>
<RadioButton
changeValue={props.changeValue}
changeRadioValue={props.changeRadioValue}
valueState={props.valueState}
name="polararea"
value="6"
/>
<RadioButton
changeValue={props.changeValue}
changeRadioValue={props.changeRadioValue}
valueState={props.valueState}
name="radar"
value="7"
/>
<RadioButton
changeValue={props.changeValue}
changeRadioValue={props.changeRadioValue}
valueState={props.valueState}
name="scatter"
value="8"
Expand Down
2 changes: 1 addition & 1 deletion src/components/Buttons/RadioButton/RadioButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function RadioButton(props) {
id={`radio-${props.name}`}
value={props.value}
checked={props.valueState === props.value ? true : false}
onChange={props.changeValue}
onChange={props.changeRadioValue}
/>
<label htmlFor={`radio-${props.name}`}>{props.name}</label>
</>
Expand Down
6 changes: 4 additions & 2 deletions src/components/Donwload/Donwload.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import html2canvas from "html2canvas";
import DonwloadIcon from "../../assets/donwload-icon.png";

function Donwload() {
function Donwload(props) {
function capture() {
const captureElem = document.querySelector(".chart-container");
const captureElem = document.querySelector(
`.chart-container-${props.theme ? "dark" : "light"}`
);
html2canvas(captureElem)
.then((canvas) => {
canvas.style.display = "none";
Expand Down
26 changes: 18 additions & 8 deletions src/components/Settings/Settings.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from "react";

import CloseSettingsIcon from "../../assets/close-settings-icon.png";
import CloseSettingsIconDark from "../../assets/close-settings-icon-dark-theme.png";
import CloseSettingsIconLight from "../../assets/close-settings-icon-light-theme.png";

import LabelsForm from "./LabelsForm/LabelsForm";
import ValuesForm from "./ValuesForm/ValuesForm";
Expand All @@ -9,14 +10,23 @@ function Settings(props) {
return (
<div className={`chart-settings__${props.open ? "open" : "hidden"}`}>
<div className="settings-content">
<img
src={CloseSettingsIcon}
alt="close settings icon"
className="settings-close-button"
onClick={props.changeSettingsOpen}
/>
{props.theme ? (
<img
src={CloseSettingsIconDark}
alt="close settings icon"
className="settings-close-button"
onClick={props.changeSettingsOpen}
/>
) : (
<img
src={CloseSettingsIconLight}
alt="close settings icon"
className="settings-close-button"
onClick={props.changeSettingsOpen}
/>
)}
<LabelsForm setLabels={props.setLabels} />
<ValuesForm setValues = {props.setValues} />
<ValuesForm setValues={props.setValues} />
</div>
</div>
);
Expand Down
13 changes: 13 additions & 0 deletions src/components/ThemeChanger/ThemeChanger.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function ThemeChanger(props) {
function changeTheme() {
props.setTheme(!props.theme);
}
return (
<div className="theme-changer" onClick={changeTheme}>
<div
className={`theme-switcher theme-${props.theme ? "dark" : "light"}`}
></div>
</div>
);
}
export default ThemeChanger;
3 changes: 2 additions & 1 deletion src/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
// COMPONENTS
@import './scss/components/Settings';
@import './scss/components/Buttons';
@import './scss/components/Donwload';
@import './scss/components/Donwload';
@import './scss/components/ThemeChanger';
43 changes: 21 additions & 22 deletions src/scss/common/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,36 @@
"Lucida Sans", Arial, sans-serif;
}

body {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100svh;
.container-dark {
@extend %container;
background-color: black;
}

.container-light {
@extend %container;
background-color: white;
}

a {
text-decoration: none;
}

.content {
position: relative;
width: 700px;
height: 400px;
.content-dark {
@extend %content;
background-color: black;
box-shadow: 0 0 10px 2px rgba(255, 255, 255, 0.3);
border-radius: 30px;
padding: 30px;
overflow: hidden;
.chart-container {
.chart-container-dark {
@extend %chart-container;
background-color: #171717;
width: 100%;
height: 100%;
border-radius: 20px;
padding: 30px;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
}

.content-light {
@extend %content;
background-color: #9e9e9e;
box-shadow: 0 0 10px 2px rgba(40, 40, 40, 0.3);
.chart-container-light {
@extend %chart-container;
background-color: white;
}
}
Loading

0 comments on commit 976f821

Please sign in to comment.