mirror of
https://github.com/muerwre/markdown-home-tab.git
synced 2025-05-08 23:36:41 +07:00
added fonts and icons
This commit is contained in:
parent
1377d25403
commit
d7a09b2729
20 changed files with 694 additions and 18 deletions
src
assets/images
components/buttons/IconButton
main.tsxmodules
layout
components/GridLayoutItemWrapper
editor/containers/MarkdownEditorContainer
theme
styles
3
src/assets/images/delete.svg
Normal file
3
src/assets/images/delete.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" height="48" viewBox="0 96 960 960" width="48">
|
||||
<path d="m249 849-42-42 231-231-231-231 42-42 231 231 231-231 42 42-231 231 231 231-42 42-231-231-231 231Z" />
|
||||
</svg>
|
After (image error) Size: 206 B |
3
src/assets/images/split-horizontal.svg
Normal file
3
src/assets/images/split-horizontal.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" height="48" viewBox="0 96 960 960" width="48">
|
||||
<path d="M220 486h520V236H220v250Zm0 60q-24 0-42-18t-18-42V236q0-24 18-42t42-18h520q24 0 42 18t18 42v250q0 24-18 42t-42 18H220Zm0 370h520V666H220v250Zm0 60q-24 0-42-18t-18-42V666q0-24 18-42t42-18h520q24 0 42 18t18 42v250q0 24-18 42t-42 18H220Zm0-490V236v250Zm0 430V666v250Z" />
|
||||
</svg>
|
After (image error) Size: 373 B |
3
src/assets/images/split-vertical.svg
Normal file
3
src/assets/images/split-vertical.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" height="48" viewBox="0 96 960 960" width="48">
|
||||
<path d="M570 936q-24 0-42-18t-18-42V276q0-24 18-42t42-18h210q24 0 42 18t18 42v600q0 24-18 42t-42 18H570Zm0-660v600h210V276H570ZM180 936q-24 0-42-18t-18-42V276q0-24 18-42t42-18h210q24 0 42 18t18 42v600q0 24-18 42t-42 18H180Zm0-660v600h210V276H180Zm600 0H570h210Zm-390 0H180h210Z" />
|
||||
</svg>
|
After (image error) Size: 378 B |
17
src/components/buttons/IconButton/index.tsx
Normal file
17
src/components/buttons/IconButton/index.tsx
Normal file
|
@ -0,0 +1,17 @@
|
|||
import classNames from "classnames";
|
||||
import { FC } from "react";
|
||||
|
||||
import styles from "./styles.module.scss";
|
||||
|
||||
type IconButtonProps = React.DetailedHTMLProps<
|
||||
React.ButtonHTMLAttributes<HTMLButtonElement>,
|
||||
HTMLButtonElement
|
||||
>;
|
||||
|
||||
const IconButton: FC<IconButtonProps> = ({ children, className, ...props }) => (
|
||||
<button {...props} className={classNames(styles.button, className)}>
|
||||
{children}
|
||||
</button>
|
||||
);
|
||||
|
||||
export { IconButton };
|
8
src/components/buttons/IconButton/styles.module.scss
Normal file
8
src/components/buttons/IconButton/styles.module.scss
Normal file
|
@ -0,0 +1,8 @@
|
|||
.button {
|
||||
background: none;
|
||||
border: none;
|
||||
color: var(--color-text);
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
|
@ -3,9 +3,12 @@ import ReactDOM from "react-dom/client";
|
|||
import { Editor } from "~/pages/editor";
|
||||
|
||||
import "./styles/main.scss";
|
||||
import { ThemeProvider } from "./modules/theme/containers/ThemeProvider";
|
||||
|
||||
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
|
||||
<React.StrictMode>
|
||||
<Editor />
|
||||
<ThemeProvider>
|
||||
<Editor />
|
||||
</ThemeProvider>
|
||||
</React.StrictMode>
|
||||
);
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
import { FC, PropsWithChildren } from "react";
|
||||
import styles from "./styles.module.scss";
|
||||
import { IconButton } from "~/components/buttons/IconButton";
|
||||
|
||||
import DeleteIcon from "~/assets/images/delete.svg";
|
||||
import SplitVertical from "~/assets/images/split-vertical.svg";
|
||||
import SplitHorizontal from "~/assets/images/split-horizontal.svg";
|
||||
|
||||
console.log(DeleteIcon);
|
||||
|
||||
type GridLayoutItemWrapperProps = PropsWithChildren & {
|
||||
splitVertical: () => void;
|
||||
|
@ -15,15 +22,23 @@ const GridLayoutItemWrapper: FC<GridLayoutItemWrapperProps> = ({
|
|||
}) => (
|
||||
<div className={styles.wrapper}>
|
||||
<div className={styles.menu}>
|
||||
<button onClick={splitVertical} role="button">
|
||||
v
|
||||
</button>
|
||||
<button onClick={splitHorizontal} role="button">
|
||||
h
|
||||
</button>
|
||||
<button onClick={remove} role="button">
|
||||
d
|
||||
</button>
|
||||
<IconButton
|
||||
onClick={splitVertical}
|
||||
role="button"
|
||||
className={styles.button}
|
||||
>
|
||||
<SplitVertical />
|
||||
</IconButton>
|
||||
<IconButton
|
||||
onClick={splitHorizontal}
|
||||
role="button"
|
||||
className={styles.button}
|
||||
>
|
||||
<SplitHorizontal />
|
||||
</IconButton>
|
||||
<IconButton onClick={remove} role="button" className={styles.button}>
|
||||
<DeleteIcon />
|
||||
</IconButton>
|
||||
</div>
|
||||
|
||||
{children}
|
||||
|
|
|
@ -9,3 +9,20 @@
|
|||
top: 0;
|
||||
right: 0;
|
||||
}
|
||||
|
||||
.button {
|
||||
opacity: 0.3;
|
||||
cursor: pointer;
|
||||
padding: 4px 2px;
|
||||
transition: opacity 0.25s;
|
||||
|
||||
&:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
svg {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
fill: currentColor;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
import { useEffect, useState } from "react";
|
||||
|
||||
const prefix = "VALUE__";
|
||||
|
||||
const safelyGetStringValue = (key: string) => {
|
||||
try {
|
||||
return localStorage.getItem(key) ?? "";
|
||||
|
@ -19,7 +17,8 @@ const safelySetStringValue = (key: string, value: string) => {
|
|||
};
|
||||
|
||||
export const usePersistedValue = (
|
||||
id: string
|
||||
id: string,
|
||||
prefix: string
|
||||
): [string, (val: string) => void] => {
|
||||
const key = `${prefix}${id}`;
|
||||
const [value, setValue] = useState(safelyGetStringValue(key));
|
||||
|
|
|
@ -11,7 +11,7 @@ interface MarkdownEditorContainerProps {
|
|||
export const MarkdownEditorContainer: FC<MarkdownEditorContainerProps> = ({
|
||||
id,
|
||||
}) => {
|
||||
const [value, setValue] = usePersistedValue(id);
|
||||
const [value, setValue] = usePersistedValue(id, "MarkdownEditorContainer");
|
||||
|
||||
return (
|
||||
<div className={styles.editor}>
|
||||
|
|
3
src/modules/theme/constants/fonts.ts
Normal file
3
src/modules/theme/constants/fonts.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
export enum FontFamily {
|
||||
Inter = "inter",
|
||||
}
|
3
src/modules/theme/constants/theme.ts
Normal file
3
src/modules/theme/constants/theme.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
export enum Theme {
|
||||
Dark = "dark",
|
||||
}
|
24
src/modules/theme/containers/ThemeProvider/index.tsx
Normal file
24
src/modules/theme/containers/ThemeProvider/index.tsx
Normal file
|
@ -0,0 +1,24 @@
|
|||
import { FC, PropsWithChildren, useEffect, useState } from "react";
|
||||
import { ThemeContext, defaultTheme } from "../../context/ThemeContext";
|
||||
|
||||
type ThemeProviderProps = PropsWithChildren;
|
||||
|
||||
const ThemeProvider: FC<ThemeProviderProps> = ({ children }) => {
|
||||
const [theme] = useState(defaultTheme);
|
||||
|
||||
useEffect(() => {
|
||||
document.body.classList.add(`font-family-${theme.font}`);
|
||||
return () => document.body.classList.remove(`font-family-${theme.font}`);
|
||||
}, [theme.font]);
|
||||
|
||||
useEffect(() => {
|
||||
document.body.classList.add(`theme-${theme.theme}`);
|
||||
return () => document.body.classList.remove(`theme-${theme.theme}`);
|
||||
}, [theme.theme]);
|
||||
|
||||
return (
|
||||
<ThemeContext.Provider value={theme}>{children}</ThemeContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export { ThemeProvider };
|
12
src/modules/theme/context/ThemeContext/index.ts
Normal file
12
src/modules/theme/context/ThemeContext/index.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
import { createContext, useContext } from "react";
|
||||
import { Theme } from "../../constants/theme";
|
||||
import { FontFamily } from "../../constants/fonts";
|
||||
|
||||
export const defaultTheme = {
|
||||
theme: Theme.Dark,
|
||||
font: FontFamily.Inter,
|
||||
};
|
||||
|
||||
export const ThemeContext = createContext(defaultTheme);
|
||||
|
||||
export const useTheme = () => useContext(ThemeContext);
|
|
@ -2,4 +2,5 @@
|
|||
--color-border: #333333;
|
||||
--color-background: #111111;
|
||||
--color-text: #ffffff;
|
||||
--color-link: #25bfe6;
|
||||
}
|
||||
|
|
4
src/styles/_fonts.scss
Normal file
4
src/styles/_fonts.scss
Normal file
|
@ -0,0 +1,4 @@
|
|||
body.font-family-inter {
|
||||
@import url("https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700;800;900&display=swap");
|
||||
font-family: "Inter", sans-serif;
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
@import "dockview/dist/styles/dockview.css";
|
||||
@import "reset.scss";
|
||||
@import "fonts.scss";
|
||||
@import "dark.scss";
|
||||
|
||||
html,
|
||||
|
@ -14,3 +15,13 @@ body {
|
|||
height: 100vh;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
a {
|
||||
color: var(--color-link);
|
||||
}
|
||||
|
||||
ul {
|
||||
li p {
|
||||
margin: 0.5em 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue