-
-
Notifications
You must be signed in to change notification settings - Fork 252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨ feat: add light/dark theme switch #68
base: main
Are you sure you want to change the base?
Changes from 2 commits
34b65a7
4f5a923
ebe1d21
3ee8e02
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ import { Reorder } from 'framer-motion'; | |
import { | ||
Trash as TrashIcon, | ||
Check as CheckIcon, | ||
Moon as MoonIcon, | ||
Sun as SunIcon, | ||
X as CloseIcon, | ||
} from '@styled-icons/feather'; | ||
|
||
|
@@ -24,7 +26,7 @@ import { CanvasErrorFallback } from './error'; | |
|
||
const Canvas = () => { | ||
const { extensions } = useExtensions(); | ||
const { sections, currentSection, previewMode } = useCanvas(); | ||
const { sections, currentSection, previewMode, lightTheme } = useCanvas(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here, that logic with be moved to the pages/_app.tsx const { theme } = useTheme();
const curTheme = themes[theme]
return (
<ThemeProvider theme={curTheme }>
...
) |
||
const [hasError, setHasError] = useState(false); | ||
|
||
const sectionIds = sections.map(section => section.id); | ||
|
@@ -41,9 +43,26 @@ const Canvas = () => { | |
<S.Container | ||
onContextMenu={handleOpenContextMenu} | ||
fullHeight={hasError || !hasSection} | ||
isLightTheme={lightTheme} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It can be removed |
||
> | ||
<S.Wrapper isLeftAligned={false}> | ||
<Tooltip | ||
position="right" | ||
content={`Preview: ${lightTheme ? 'dark' : 'light'} mode`} | ||
variant="info" | ||
> | ||
<S.Button | ||
aria-label={`Preview: ${lightTheme ? 'dark' : 'light'} mode`} | ||
onClick={() => events.canvas.switchTheme(lightTheme)} | ||
variant="success" | ||
> | ||
{lightTheme ? <MoonIcon size={16} /> : <SunIcon size={16} />} | ||
</S.Button> | ||
</Tooltip> | ||
</S.Wrapper> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
{hasSection && !previewMode && ( | ||
<S.Wrapper> | ||
<S.Wrapper isLeftAligned={true}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It can be removed |
||
<Tooltip position="left" content="Clear canvas" variant="danger"> | ||
<S.Button | ||
aria-label="Clear canvas" | ||
|
@@ -61,7 +80,7 @@ const Canvas = () => { | |
onChange={setHasError} | ||
> | ||
{previewMode && ( | ||
<S.Wrapper> | ||
<S.Wrapper isLeftAligned={true}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It can be removed |
||
<Tooltip position="left" content="Use template" variant="success"> | ||
<S.Button | ||
aria-label="Use template" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All changes in this file can be reverted because we will use the theme feature of the styled-components to make the theme change. |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The theme switch logic needs to be separated into another react context, which can be called ThemeContext |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ export enum Events { | |
CANVAS_REORDER_SECTIONS = 'canvas.section.reorder', | ||
CANVAS_DUPLICATE_SECTION = 'canvas.section.duplicate', | ||
CANVAS_CLEAR_SECTIONS = 'canvas.clear', | ||
CANVAS_SWITCH_THEME = 'canvas.switchTheme', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change the event name to APP_SET_THEME = "app.set.theme" |
||
|
||
TEMPLATE_USE = 'template.use', | ||
TEMPLATE_PREVIEW = 'template.preview', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move it to the app handle (the file need to be created)
Then, include it in the index handles