mirror of
https://github.com/IRBorisov/ConceptPortal.git
synced 2025-06-26 13:00:39 +03:00
Implement font switcher for RSInput
This commit is contained in:
parent
eee3788a8a
commit
6a41ecd88c
|
@ -11,6 +11,7 @@ import { forwardRef, useCallback, useMemo, useRef } from 'react';
|
||||||
import Label from '@/components/ui/Label';
|
import Label from '@/components/ui/Label';
|
||||||
import { useRSForm } from '@/context/RSFormContext';
|
import { useRSForm } from '@/context/RSFormContext';
|
||||||
import { useConceptTheme } from '@/context/ThemeContext';
|
import { useConceptTheme } from '@/context/ThemeContext';
|
||||||
|
import { getFontClassName } from '@/models/miscellaneousAPI';
|
||||||
import { generateAlias, getCstTypePrefix, guessCstType } from '@/models/rsformAPI';
|
import { generateAlias, getCstTypePrefix, guessCstType } from '@/models/rsformAPI';
|
||||||
import { extractGlobals } from '@/models/rslangAPI';
|
import { extractGlobals } from '@/models/rslangAPI';
|
||||||
|
|
||||||
|
@ -48,7 +49,7 @@ const RSInput = forwardRef<ReactCodeMirrorRef, RSInputProps>(
|
||||||
},
|
},
|
||||||
ref
|
ref
|
||||||
) => {
|
) => {
|
||||||
const { darkMode, colors } = useConceptTheme();
|
const { darkMode, colors, mathFont } = useConceptTheme();
|
||||||
const { schema } = useRSForm();
|
const { schema } = useRSForm();
|
||||||
|
|
||||||
const internalRef = useRef<ReactCodeMirrorRef>(null);
|
const internalRef = useRef<ReactCodeMirrorRef>(null);
|
||||||
|
@ -136,7 +137,7 @@ const RSInput = forwardRef<ReactCodeMirrorRef, RSInputProps>(
|
||||||
<div className={clsx('flex flex-col gap-2', className, cursor)} style={style}>
|
<div className={clsx('flex flex-col gap-2', className, cursor)} style={style}>
|
||||||
<Label text={label} />
|
<Label text={label} />
|
||||||
<CodeMirror
|
<CodeMirror
|
||||||
className='font-math'
|
className={getFontClassName(mathFont)}
|
||||||
id={id}
|
id={id}
|
||||||
ref={thisRef}
|
ref={thisRef}
|
||||||
basicSetup={editorSetup}
|
basicSetup={editorSetup}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import { createContext, useCallback, useContext, useLayoutEffect, useMemo, useSt
|
||||||
|
|
||||||
import Tooltip from '@/components/ui/Tooltip';
|
import Tooltip from '@/components/ui/Tooltip';
|
||||||
import useLocalStorage from '@/hooks/useLocalStorage';
|
import useLocalStorage from '@/hooks/useLocalStorage';
|
||||||
|
import { FontStyle } from '@/models/miscellaneous';
|
||||||
import { animationDuration } from '@/styling/animations';
|
import { animationDuration } from '@/styling/animations';
|
||||||
import { darkT, IColorTheme, lightT } from '@/styling/color';
|
import { darkT, IColorTheme, lightT } from '@/styling/color';
|
||||||
import { globalIDs } from '@/utils/constants';
|
import { globalIDs } from '@/utils/constants';
|
||||||
|
@ -18,6 +19,9 @@ interface IThemeContext {
|
||||||
darkMode: boolean;
|
darkMode: boolean;
|
||||||
toggleDarkMode: () => void;
|
toggleDarkMode: () => void;
|
||||||
|
|
||||||
|
mathFont: FontStyle;
|
||||||
|
setMathFont: (value: FontStyle) => void;
|
||||||
|
|
||||||
noNavigationAnimation: boolean;
|
noNavigationAnimation: boolean;
|
||||||
noNavigation: boolean;
|
noNavigation: boolean;
|
||||||
toggleNoNavigation: () => void;
|
toggleNoNavigation: () => void;
|
||||||
|
@ -46,6 +50,7 @@ interface ThemeStateProps {
|
||||||
|
|
||||||
export const ThemeState = ({ children }: ThemeStateProps) => {
|
export const ThemeState = ({ children }: ThemeStateProps) => {
|
||||||
const [darkMode, setDarkMode] = useLocalStorage('darkMode', false);
|
const [darkMode, setDarkMode] = useLocalStorage('darkMode', false);
|
||||||
|
const [mathFont, setMathFont] = useLocalStorage<FontStyle>('editor_font_math', 'math');
|
||||||
const [colors, setColors] = useState<IColorTheme>(lightT);
|
const [colors, setColors] = useState<IColorTheme>(lightT);
|
||||||
const [noNavigation, setNoNavigation] = useState(false);
|
const [noNavigation, setNoNavigation] = useState(false);
|
||||||
const [noNavigationAnimation, setNoNavigationAnimation] = useState(false);
|
const [noNavigationAnimation, setNoNavigationAnimation] = useState(false);
|
||||||
|
@ -106,6 +111,8 @@ export const ThemeState = ({ children }: ThemeStateProps) => {
|
||||||
value={{
|
value={{
|
||||||
darkMode,
|
darkMode,
|
||||||
colors,
|
colors,
|
||||||
|
mathFont,
|
||||||
|
setMathFont,
|
||||||
noNavigationAnimation,
|
noNavigationAnimation,
|
||||||
noNavigation,
|
noNavigation,
|
||||||
noFooter,
|
noFooter,
|
||||||
|
|
|
@ -28,6 +28,11 @@ export enum DependencyMode {
|
||||||
*/
|
*/
|
||||||
export type GraphColoringScheme = 'none' | 'status' | 'type';
|
export type GraphColoringScheme = 'none' | 'status' | 'type';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents font styles.
|
||||||
|
*/
|
||||||
|
export type FontStyle = 'controls' | 'main' | 'math' | 'math2';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents manuals topic.
|
* Represents manuals topic.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,9 +1,17 @@
|
||||||
/**
|
/**
|
||||||
* Module: API for miscellaneous frontend model types. Future targets for refactoring aimed at extracting modules.
|
* Module: API for miscellaneous frontend model types. Future targets for refactoring aimed at extracting modules.
|
||||||
*/
|
*/
|
||||||
import { DependencyMode, ILibraryFilter, LibraryFilterStrategy } from './miscellaneous';
|
import { DependencyMode, FontStyle, ILibraryFilter, LibraryFilterStrategy } from './miscellaneous';
|
||||||
import { IConstituenta, IRSForm } from './rsform';
|
import { IConstituenta, IRSForm } from './rsform';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create style name from {@link FontStyle}.
|
||||||
|
*/
|
||||||
|
export function getFontClassName(style: FontStyle): string {
|
||||||
|
console.log(style);
|
||||||
|
return `font-${style}`;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter list of {@link ILibraryItem} to a given graph query.
|
* Filter list of {@link ILibraryItem} to a given graph query.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
import { ReactCodeMirrorRef } from '@uiw/react-codemirror';
|
import { ReactCodeMirrorRef } from '@uiw/react-codemirror';
|
||||||
import { AnimatePresence } from 'framer-motion';
|
import { AnimatePresence } from 'framer-motion';
|
||||||
import { useCallback, useLayoutEffect, useRef, useState } from 'react';
|
import { useCallback, useLayoutEffect, useRef, useState } from 'react';
|
||||||
import { BiListUl } from 'react-icons/bi';
|
import { BiFontFamily, BiListUl } from 'react-icons/bi';
|
||||||
import { FaRegKeyboard } from 'react-icons/fa6';
|
import { FaRegKeyboard } from 'react-icons/fa6';
|
||||||
import { RiNodeTree } from 'react-icons/ri';
|
import { RiNodeTree } from 'react-icons/ri';
|
||||||
import { toast } from 'react-toastify';
|
import { toast } from 'react-toastify';
|
||||||
|
@ -14,6 +14,7 @@ import { RSTextWrapper } from '@/components/RSInput/textEditing';
|
||||||
import MiniButton from '@/components/ui/MiniButton';
|
import MiniButton from '@/components/ui/MiniButton';
|
||||||
import Overlay from '@/components/ui/Overlay';
|
import Overlay from '@/components/ui/Overlay';
|
||||||
import { useRSForm } from '@/context/RSFormContext';
|
import { useRSForm } from '@/context/RSFormContext';
|
||||||
|
import { useConceptTheme } from '@/context/ThemeContext';
|
||||||
import DlgShowAST from '@/dialogs/DlgShowAST';
|
import DlgShowAST from '@/dialogs/DlgShowAST';
|
||||||
import useCheckExpression from '@/hooks/useCheckExpression';
|
import useCheckExpression from '@/hooks/useCheckExpression';
|
||||||
import useLocalStorage from '@/hooks/useLocalStorage';
|
import useLocalStorage from '@/hooks/useLocalStorage';
|
||||||
|
@ -56,6 +57,7 @@ function EditorRSExpression({
|
||||||
...restProps
|
...restProps
|
||||||
}: EditorRSExpressionProps) {
|
}: EditorRSExpressionProps) {
|
||||||
const { schema } = useRSForm();
|
const { schema } = useRSForm();
|
||||||
|
const { mathFont, setMathFont } = useConceptTheme();
|
||||||
|
|
||||||
const [isModified, setIsModified] = useState(false);
|
const [isModified, setIsModified] = useState(false);
|
||||||
const { parseData, checkExpression, resetParse, loading } = useCheckExpression({ schema });
|
const { parseData, checkExpression, resetParse, loading } = useCheckExpression({ schema });
|
||||||
|
@ -145,6 +147,10 @@ function EditorRSExpression({
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toggleFont() {
|
||||||
|
setMathFont(mathFont === 'math' ? 'math2' : 'math');
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<AnimatePresence>
|
<AnimatePresence>
|
||||||
|
@ -155,6 +161,11 @@ function EditorRSExpression({
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<Overlay position='top-[-0.5rem] right-0 flex'>
|
<Overlay position='top-[-0.5rem] right-0 flex'>
|
||||||
|
<MiniButton
|
||||||
|
title='Изменить шрифт'
|
||||||
|
icon={<BiFontFamily size='1.25rem' className={mathFont === 'math' ? 'icon-primary' : ''} />}
|
||||||
|
onClick={toggleFont}
|
||||||
|
/>
|
||||||
<MiniButton
|
<MiniButton
|
||||||
noHover
|
noHover
|
||||||
title='Отображение специальной клавиатуры'
|
title='Отображение специальной клавиатуры'
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
--font-ui: 'Geologica', sans-serif;
|
--font-ui: 'Geologica', sans-serif;
|
||||||
--font-main: 'Rubik', 'Fira Code', 'Noto Sans Math', 'Noto Sans Symbols 2', 'Segoe UI Symbol', sans-serif;
|
--font-main: 'Rubik', 'Fira Code', 'Noto Sans Math', 'Noto Sans Symbols 2', 'Segoe UI Symbol', sans-serif;
|
||||||
--font-math: 'Fira Code', 'Noto Sans Math', 'Noto Sans Symbols 2', 'Rubik', 'Segoe UI Symbol', sans-serif;
|
--font-math: 'Fira Code', 'Noto Sans Math', 'Noto Sans Symbols 2', 'Rubik', 'Segoe UI Symbol', sans-serif;
|
||||||
|
--font-math2: 'Noto Sans Math', 'Noto Sans Symbols 2', 'Rubik', 'Segoe UI Symbol', sans-serif;
|
||||||
|
|
||||||
/* Light Theme */
|
/* Light Theme */
|
||||||
--cl-bg-120: hsl(000, 000%, 100%);
|
--cl-bg-120: hsl(000, 000%, 100%);
|
||||||
|
|
|
@ -8,6 +8,9 @@
|
||||||
@tailwind utilities;
|
@tailwind utilities;
|
||||||
|
|
||||||
@layer utilities {
|
@layer utilities {
|
||||||
|
.font-main {
|
||||||
|
font-family: var(--font-main);
|
||||||
|
}
|
||||||
.font-controls {
|
.font-controls {
|
||||||
font-family: var(--font-ui);
|
font-family: var(--font-ui);
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
|
@ -16,6 +19,9 @@
|
||||||
.font-math {
|
.font-math {
|
||||||
font-family: var(--font-math);
|
font-family: var(--font-math);
|
||||||
}
|
}
|
||||||
|
.font-math2 {
|
||||||
|
font-family: var(--font-math2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@layer components {
|
@layer components {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user