-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
97 additions
and
215 deletions.
There are no files selected for viewing
218 changes: 71 additions & 147 deletions
218
frontend/src/components/Profile/ThemeColor.container.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,147 +1,71 @@ | ||
// import React from "react"; | ||
// import { useEffect, useState } from "react"; | ||
// import { TwitterPicker } from "react-color"; | ||
// import styled from "styled-components"; | ||
// import ThemeColor from "./ThemeColor"; | ||
|
||
// const ThemeColorContainer: React.FC<{ | ||
// showColorPicker: boolean; | ||
// setShowColorPicker: React.Dispatch<React.SetStateAction<boolean>>; | ||
// }> = ({ showColorPicker, setShowColorPicker }) => { | ||
// const savedColor = localStorage.getItem("mainColor"); | ||
// const [mainColor, setMainColor] = useState<string>( | ||
// savedColor ? savedColor : "#9747ff" | ||
// ); | ||
|
||
// const root: HTMLElement = document.documentElement; | ||
|
||
// const handleChange = (mainColor: { hex: string }) => { | ||
// const selectedColor: string = mainColor.hex; | ||
// setMainColor(selectedColor); | ||
// }; | ||
|
||
// const handleReset = () => { | ||
// const defaultColor = "#9747ff"; | ||
// setMainColor(defaultColor); | ||
// root.style.setProperty("--main-color", defaultColor); | ||
// root.style.setProperty("--lightpurple-color", "#b18cff"); | ||
// localStorage.setItem("mainColor", defaultColor); | ||
// }; | ||
|
||
// const handleSave = () => { | ||
// localStorage.setItem("mainColor", mainColor); | ||
// root.style.setProperty("--main-color", mainColor); | ||
// toggleColorPicker(true); | ||
// }; | ||
|
||
// const handleCancel = () => { | ||
// const savedColor = localStorage.getItem("mainColor"); | ||
// root.style.setProperty("--main-color", savedColor); | ||
// toggleColorPicker(true); | ||
// }; | ||
|
||
// const toggleColorPicker = (isChange: boolean) => { | ||
// if (isChange) setShowColorPicker(!showColorPicker); | ||
// }; | ||
|
||
// const confirmBeforeUnload = (e: BeforeUnloadEvent) => { | ||
// if (mainColor !== localStorage.getItem("mainColor")) { | ||
// e.returnValue = | ||
// "변경된 색상이 저장되지 않을 수 있습니다. 계속하시겠습니까?"; | ||
// } | ||
// }; | ||
|
||
// useEffect(() => { | ||
// root.style.setProperty("--main-color", mainColor); | ||
// window.addEventListener("beforeunload", confirmBeforeUnload); | ||
// return () => { | ||
// window.removeEventListener("beforeunload", confirmBeforeUnload); | ||
// }; | ||
// }, [mainColor]); | ||
|
||
// return ( | ||
// <ThemeColor | ||
// handleSave={handleSave} | ||
// handleCancel={handleCancel} | ||
// handleReset={handleReset} | ||
// handleChange={handleChange} | ||
// toggleColorPicker={toggleColorPicker} | ||
// /> | ||
// ); | ||
// }; | ||
|
||
// const ThemeColorStyled = styled.div` | ||
// width: 350px; | ||
// height: 215px; | ||
// background-color: var(--lightgary-color); | ||
// border-radius: 10px; | ||
// padding: 30px; | ||
// `; | ||
|
||
// const TableTitleStyled = styled.div` | ||
// font-size: 18px; | ||
// font-weight: bold; | ||
// `; | ||
|
||
// const TableTopStyled = styled.div` | ||
// display: flex; | ||
// align-items: center; | ||
// justify-content: space-between; | ||
// margin-bottom: 20px; | ||
// `; | ||
|
||
// const BtnWrapStyled = styled.div` | ||
// display: flex; | ||
// `; | ||
|
||
// const ResetBtnStyled = styled.div` | ||
// width: 54px; | ||
// height: 23px; | ||
// background-color: white; | ||
// border-radius: 4px; | ||
// color: var(--gray-color); | ||
// font-size: 12px; | ||
// display: flex; | ||
// align-items: center; | ||
// justify-content: center; | ||
// `; | ||
|
||
// const SaveBtnStyled = styled.div` | ||
// width: 54px; | ||
// height: 23px; | ||
// background-color: var(--main-color); | ||
// border-radius: 4px; | ||
// color: white; | ||
// font-size: 12px; | ||
// display: flex; | ||
// align-items: center; | ||
// justify-content: center; | ||
// margin-right: 15px; | ||
// `; | ||
|
||
// const MainColorButtonStyled = styled.button` | ||
// width: 28px; | ||
// height: 28px; | ||
// background-color: var(--main-color); | ||
// border-radius: 8px; | ||
// `; | ||
|
||
// const ColorSelectStyled = styled.div` | ||
// padding: 20px; | ||
// width: 100%; | ||
// display: flex; | ||
// align-items: center; | ||
// justify-content: space-between; | ||
// `; | ||
|
||
// const TableBodyStyled = styled.div` | ||
// background-color: white; | ||
// width: 290px; | ||
// height: 120px; | ||
// border-radius: 8px; | ||
// display: flex; | ||
// flex-direction: column; | ||
// align-items: center; | ||
// `; | ||
|
||
// export default ThemeColorContainer; | ||
import { useEffect, useState } from "react"; | ||
import ThemeColor from "./ThemeColor"; | ||
|
||
const ThemeColorContainer: React.FC<{ | ||
showColorPicker: boolean; | ||
setShowColorPicker: React.Dispatch<React.SetStateAction<boolean>>; | ||
}> = ({ showColorPicker, setShowColorPicker }) => { | ||
const savedColor = localStorage.getItem("mainColor"); | ||
const defaultColor = "#9747ff"; | ||
const [mainColor, setMainColor] = useState<string>( | ||
savedColor ? savedColor : defaultColor | ||
); | ||
const root: HTMLElement = document.documentElement; | ||
|
||
const handleChange = (mainColor: { hex: string }) => { | ||
const selectedColor: string = mainColor.hex; | ||
setMainColor(selectedColor); | ||
}; | ||
|
||
const handleReset = () => { | ||
setMainColor(defaultColor); | ||
root.style.setProperty("--main-color", defaultColor); | ||
root.style.setProperty("--lightpurple-color", "#b18cff"); | ||
localStorage.setItem("mainColor", defaultColor); | ||
}; | ||
|
||
const handleSave = () => { | ||
localStorage.setItem("mainColor", mainColor); | ||
root.style.setProperty("--main-color", mainColor); | ||
toggleColorPicker(true); | ||
}; | ||
|
||
const handleCancel = () => { | ||
const savedColor = localStorage.getItem("mainColor"); | ||
root.style.setProperty("--main-color", savedColor); | ||
toggleColorPicker(true); | ||
}; | ||
|
||
const toggleColorPicker = (isChange: boolean) => { | ||
if (isChange) setShowColorPicker(!showColorPicker); | ||
}; | ||
|
||
const confirmBeforeUnload = (e: BeforeUnloadEvent) => { | ||
if (mainColor !== localStorage.getItem("mainColor")) { | ||
e.returnValue = | ||
"변경된 색상이 저장되지 않을 수 있습니다. 계속하시겠습니까?"; | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
root.style.setProperty("--main-color", mainColor); | ||
window.addEventListener("beforeunload", confirmBeforeUnload); | ||
return () => { | ||
window.removeEventListener("beforeunload", confirmBeforeUnload); | ||
}; | ||
}, [mainColor]); | ||
|
||
return ( | ||
<ThemeColor | ||
showColorPicker={showColorPicker} | ||
setShowColorPicker={setShowColorPicker} | ||
handleChange={handleChange} | ||
handleReset={handleReset} | ||
handleSave={handleSave} | ||
handleCancel={handleCancel} | ||
mainColor={mainColor} | ||
/> | ||
); | ||
}; | ||
|
||
export default ThemeColorContainer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters