Skip to content
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(theme): add support for light theme #130

Merged
merged 4 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions commitlint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const Configuration: UserConfig = {
'build', // Build scripts or configuration
'ci', // Continuous integration
'release', // Release related changes
'theme', // Theme changes
'other', // Other changes
],
],
Expand Down
8 changes: 4 additions & 4 deletions src/components/project/NewProject/NewProject.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@

[class*='ant-radio-button-checked'] {
border: solid 1px transparent;
background-image: linear-gradient(rgb(20, 20, 20), rgb(20, 20, 20)),
var(--primary-gradient);
background-origin: border-box;
background-clip: content-box, border-box;
background: var(--primary);
border-radius: var(--border-radius);

&::before {
Expand All @@ -72,6 +69,9 @@
background: #000;
z-index: -1;
border-radius: inherit;
[data-theme='light'] & {
background: var(--primary);
}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/components/shared/LogView/LogView.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,10 @@
display: inline-block;
margin-left: 0.5rem;
}
[class*='xterm-cursor-outline'] {
outline-color: var(--text-color) !important;
}
[class*='xterm-cursor-bar'] {
box-shadow: 1px 0 0 var(--text-color) inset !important;
}
}
2 changes: 1 addition & 1 deletion src/components/shared/LogView/LogView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const LogView: FC<Props> = ({ filter }) => {
grey: '\x1b[38;5;243m',
success: '\x1b[38;5;40m',
error: '\x1b[38;5;196m',
warning: '\x1b[38;5;226m',
warning: '\x1b[38;5;214m',
info: '\x1b[38;5;33m',
reset: '\x1b[0m',
};
Expand Down
74 changes: 74 additions & 0 deletions src/components/shared/ThemeProvider/ThemeProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { ConfigProvider, theme as antdTheme } from 'antd';
import {
ReactNode,
createContext,
useContext,
useEffect,
useState,
} from 'react';

type Theme = 'light' | 'dark';

interface ThemeContextProps {
theme: Theme;
toggleTheme: () => void;
}

export const ThemeContext = createContext<ThemeContextProps | undefined>(
undefined,
);

export const useTheme = () => {
const context = useContext(ThemeContext);
if (!context) {
throw new Error('useTheme must be used within a ThemeProvider');
}
return context;
};

export const ThemeProvider = ({ children }: { children: ReactNode }) => {
// Initialize theme based on local storage or system preference
const [theme, setTheme] = useState<Theme>(() => {
if (typeof window === 'undefined') {
return 'dark';
}
const savedTheme = localStorage.getItem('theme');
if (savedTheme) {
return savedTheme as Theme;
}
const prefersDark = window.matchMedia(
'(prefers-color-scheme: dark)',
).matches;
return prefersDark ? 'dark' : 'light';
});

// Apply the theme to the HTML element and save it in localStorage
useEffect(() => {
document.documentElement.setAttribute('data-theme', theme);
localStorage.setItem('theme', theme);
}, [theme]);

const toggleTheme = () => {
setTheme((prevTheme) => (prevTheme === 'light' ? 'dark' : 'light'));
};

// Ant Design's theme configuration
const antdConfig = {
token: {
colorPrimary: '#0098ea',
colorError: '#C84075',
fontFamily: 'var(--font-body)',
borderRadius: 4,
},
algorithm:
theme === 'dark' ? antdTheme.darkAlgorithm : antdTheme.defaultAlgorithm,
};

return (
<ThemeContext.Provider value={{ theme, toggleTheme }}>
<ConfigProvider theme={antdConfig}>{children}</ConfigProvider>
</ThemeContext.Provider>
);
};

export default ThemeProvider;
1 change: 1 addition & 0 deletions src/components/shared/ThemeProvider/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { ThemeContext, default, useTheme } from './ThemeProvider';
1 change: 1 addition & 0 deletions src/components/shared/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { default as Layout } from './Layout';
export { default as LogView } from './LogView';
export { default as ThemeProvider } from './ThemeProvider';
9 changes: 7 additions & 2 deletions src/components/template/ProjectTemplate/ProjectTemplate.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable react/no-children-prop */
import { NewProject } from '@/components/project';
import { useTheme } from '@/components/shared/ThemeProvider';
import AppIcon from '@/components/ui/icon';
import { AppConfig } from '@/config/AppConfig';
import { projectExamples } from '@/constant/projectExamples';
Expand All @@ -9,7 +10,10 @@ import Link from 'next/link';
import { FC, useEffect, useState } from 'react';
import Markdown from 'react-markdown';
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
import { oneDark as darkTheme } from 'react-syntax-highlighter/dist/cjs/styles/prism';
import {
oneDark as darkTheme,
oneLight as lightTheme,
} from 'react-syntax-highlighter/dist/cjs/styles/prism';
import s from './ProjectTemplate.module.scss';

function LinkRenderer({
Expand All @@ -35,6 +39,7 @@ const ProjectTemplate: FC = () => {
contract: string;
content: string;
}>({ contract: '', content: '' });
const { theme } = useTheme();

const getContent = async () => {
const link = examples[currentExample].link;
Expand Down Expand Up @@ -166,7 +171,7 @@ const ProjectTemplate: FC = () => {
PreTag="div"
children={String(children).replace(/\n$/, '')}
language={match[1]}
style={darkTheme}
style={theme === 'dark' ? darkTheme : lightTheme}
/>
) : (
<code {...rest} className={className}>
Expand Down
8 changes: 6 additions & 2 deletions src/components/ui/icon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { BsShare } from 'react-icons/bs';

import { BsFillPlayFill } from 'react-icons/bs';
import { FaRegClone } from 'react-icons/fa';
import { FaMoon, FaRegClone, FaSun } from 'react-icons/fa';
import { FiEdit2, FiEye } from 'react-icons/fi';
import { GoTriangleDown, GoTriangleRight, GoTriangleUp } from 'react-icons/go';
import { GrClear } from 'react-icons/gr';
Expand Down Expand Up @@ -69,7 +69,9 @@ export type AppIconType =
| 'Import'
| 'Reload'
| 'Share'
| 'Save';
| 'Save'
| 'Moon'
| 'Sun';

export interface AppIconInterface {
name: AppIconType;
Expand Down Expand Up @@ -110,6 +112,8 @@ const Components = {
Reload: AiOutlineReload,
Share: BsShare,
Save: AiOutlineSave,
Moon: FaMoon,
Sun: FaSun,
};

const AppIcon: FC<AppIconInterface> = ({ name, className = '' }) => {
Expand Down
34 changes: 28 additions & 6 deletions src/components/workspace/ABIUi/ABIUi.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
height: 1px;
margin: 0 auto;
background-color: #373636;
[data-theme='light'] & {
background-color: #e0e0e0;
}
}
&.tact {
display: flex;
Expand All @@ -30,6 +33,9 @@
background: rgba(14, 14, 16, 0.9);
border-radius: 5px;
padding: 5px;
[data-theme='light'] & {
background: rgba(255, 255, 255, 0.9);
}

> div {
border-left: 0 !important;
Expand Down Expand Up @@ -62,27 +68,40 @@
border: 0;
box-shadow: none;
background: #232222;
[data-theme='light'] & {
background: #d6d6d6;
}
&:hover {
color: var(--text-color);
background-color: var(--grey--50);
}
}
}
&.Setter {
.btnAction {
border: solid 1px transparent;
background-image: linear-gradient(rgb(20, 20, 20), rgb(20, 20, 20)),
var(--primary-gradient);
background-origin: border-box;
background-clip: content-box, border-box;
background: var(--primary);
box-shadow: none;
z-index: 0;

&:hover {
border-color: transparent;
color: #fff;
color: var(--text-color);

&:before {
background: #101010;
[data-theme='light'] & {
background: var(--btn-primary-hover);
}
}
}
& span,
&:hover span [data-theme='light'] & {
color: #fff;
}
&:disabled {
opacity: 0.5;
color: #fff;
color: var(--text-color);
}

&:before {
Expand All @@ -95,6 +114,9 @@
background: #000;
z-index: -1;
border-radius: inherit;
[data-theme='light'] & {
background: var(--primary);
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/workspace/BottomPanel/BottomPanel.module.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.root {
background-color: #181717;
background-color: var(--dark-800);
height: 100%;
z-index: 1000;
position: relative;
Expand Down Expand Up @@ -43,11 +43,11 @@
justify-content: center;
.icon {
path {
stroke: #fff;
stroke: var(--text-color);
}
}
&:hover {
background-color: var(--grey);
background-color: var(--grey--70);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
height: 100vh;
overflow-y: auto;
.heading {
color: #ccc;
color: var(--color-light);
text-align: center;
display: block;
font-size: 0.875rem;
Expand All @@ -28,6 +28,9 @@
background: rgba(14, 14, 16, 0.9);
border-radius: 5px;
padding: 2px;
[data-theme='light'] & {
background: rgba(255, 255, 255, 0.9);
}
> div {
border-left: 0 !important;
}
Expand All @@ -42,11 +45,11 @@
}
.connectedWallet {
font-size: 0.8rem;
color: #ccc;
color: var(--color-light);
margin-top: 1rem;
span {
font-size: 0.9rem;
color: #fff;
color: var(--text-color);
}
}
.contractAddress {
Expand Down
3 changes: 3 additions & 0 deletions src/components/workspace/Editor/Editor.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
justify-content: space-between;
font-size: 0.8rem;
padding: 0.2rem 1rem;
[data-theme='light'] & {
background-color: rgba(255, 255, 255, 0.7);
}
.vimStatuBar {
font-family: monospace;
}
Expand Down
4 changes: 3 additions & 1 deletion src/components/workspace/Editor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import EditorDefault, { loader } from '@monaco-editor/react';
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
import { FC, useEffect, useRef, useState } from 'react';
// import { useLatest } from 'react-use';
import { useTheme } from '@/components/shared/ThemeProvider';
import { useFile, useFileTab } from '@/hooks';
import { useProject } from '@/hooks/projectV2.hooks';
import { useLatest } from 'react-use';
Expand All @@ -23,6 +24,7 @@ const Editor: FC<Props> = ({ className = '' }) => {
const { activeProject } = useProject();
const { getFile, saveFile: storeFileContent } = useFile();
const { fileTab, updateFileDirty } = useFileTab();
const { theme } = useTheme();

const { isFormatOnSave, getSettingStateByKey } = useSettingAction();

Expand Down Expand Up @@ -249,7 +251,7 @@ const Editor: FC<Props> = ({ className = '' }) => {
<EditorDefault
className={s.editor}
path={fileTab.active ?? ''}
theme="vs-theme-dark"
theme={theme === 'dark' ? 'vs-theme-dark' : 'light'}
// height="90vh"
defaultLanguage={fileTypeFromFileName(fileTab.active ?? '')}
// defaultLanguage={`func`}
Expand Down
7 changes: 5 additions & 2 deletions src/components/workspace/Tabs/Tabs.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

&.isActive {
background: var(--black-500);
color: #ffffff;
color: var(--text-color);
.close {
visibility: visible;
}
Expand All @@ -76,6 +76,9 @@

&:hover {
background-color: #403d3d;
[data-theme='light'] & {
background-color: #f7f7f7;
}
}
&.isDirty {
.closeIcon {
Expand All @@ -92,7 +95,7 @@
width: 8px;
height: 8px;
border-radius: 50%;
background: #fff;
background: var(--text-color);
margin-right: 5px;
position: absolute;
left: 0;
Expand Down
Loading
Loading