From 44b30a9bd8c01d0528356da65adf13323c66b609 Mon Sep 17 00:00:00 2001 From: IRBorisov <8611739+IRBorisov@users.noreply.github.com> Date: Fri, 15 Dec 2023 17:34:50 +0300 Subject: [PATCH] Refactoring: use clsx to clarify classNames --- README.md | 5 +- rsconcept/frontend/README.md | 21 ++++++ rsconcept/frontend/package-lock.json | 1 + rsconcept/frontend/package.json | 1 + rsconcept/frontend/src/App.tsx | 17 ++++- .../frontend/src/components/Common/Button.tsx | 41 ++++++---- .../src/components/Common/Checkbox.tsx | 57 +++++++------- .../src/components/Common/ConceptLoader.tsx | 20 +++-- .../src/components/Common/ConceptSearch.tsx | 16 ++-- .../src/components/Common/ConceptTab.tsx | 12 ++- .../src/components/Common/ConceptTooltip.tsx | 8 +- .../src/components/Common/Divider.tsx | 13 +++- .../src/components/Common/Dropdown.tsx | 34 +++++++-- .../src/components/Common/DropdownButton.tsx | 17 ++++- .../components/Common/DropdownCheckbox.tsx | 12 ++- .../src/components/Common/EmbedYoutube.tsx | 13 +++- .../src/components/Common/FileInput.tsx | 13 ++-- .../src/components/Common/GraphUI.tsx | 1 + .../frontend/src/components/Common/Label.tsx | 13 +++- .../{LabeledText.tsx => LabeledValue.tsx} | 8 +- .../src/components/Common/MiniButton.tsx | 16 +++- .../frontend/src/components/Common/Modal.tsx | 32 ++++++-- .../src/components/Common/Overlay.tsx | 2 +- .../src/components/Common/PDFViewer.tsx | 5 +- .../src/components/Common/PageControls.tsx | 8 +- .../src/components/Common/SelectorButton.tsx | 19 +++-- .../src/components/Common/SubmitButton.tsx | 13 +++- .../src/components/Common/SwitchButton.tsx | 12 ++- .../src/components/Common/TextArea.tsx | 29 +++++--- .../src/components/Common/TextInput.tsx | 35 ++++++--- .../src/components/Common/TextURL.tsx | 2 +- .../src/components/Common/Tristate.tsx | 30 ++++---- .../src/components/Common/commonInterfaces.ts | 2 +- .../src/components/ConceptToaster.tsx | 2 +- .../components/DataTable/PaginationTools.tsx | 17 +++-- .../src/components/DataTable/SortingIcon.tsx | 2 +- .../frontend/src/components/ErrorFallback.tsx | 4 +- .../src/components/ExpectedAnonymous.tsx | 4 +- rsconcept/frontend/src/components/Footer.tsx | 15 +++- .../src/components/Help/HelpButton.tsx | 4 +- rsconcept/frontend/src/components/Icons.tsx | 2 +- .../frontend/src/components/InfoError.tsx | 4 +- .../src/components/Navigation/Logo.tsx | 2 +- .../src/components/Navigation/Navigation.tsx | 23 ++++-- .../Navigation/NavigationButton.tsx | 15 +++- .../components/Navigation/ThemeSwitcher.tsx | 2 +- .../Navigation/ToggleNavigationButton.tsx | 25 +++++-- .../components/Navigation/UserDropdown.tsx | 2 +- .../src/components/Navigation/UserMenu.tsx | 2 +- .../src/components/RSInput/RSInput.tsx | 16 ++-- .../src/components/RSInput/textEditing.ts | 2 +- .../src/components/RSInput/tooltip.ts | 3 +- .../src/components/RefsInput/RefsInput.tsx | 74 +++++++------------ .../src/components/RefsInput/tooltip.ts | 3 +- .../frontend/src/components/RequireAuth.tsx | 2 +- .../components/Shared/ConstituentaBadge.tsx | 17 +++-- .../components/Shared/ConstituentaPicker.tsx | 10 +-- .../src/components/Shared/GrammemeBadge.tsx | 11 ++- .../components/Shared/InfoConstituenta.tsx | 2 +- .../src/components/Shared/InfoCstClass.tsx | 12 ++- .../src/components/Shared/InfoCstStatus.tsx | 18 +++-- .../frontend/src/context/AuthContext.tsx | 2 +- .../DlgConstituentaTemplate/ArgumentsTab.tsx | 50 +++++++++---- .../DlgConstituentaTemplate.tsx | 8 +- .../frontend/src/dialogs/DlgCreateCst.tsx | 6 +- .../dialogs/DlgDeleteCst/ConstituentsList.tsx | 10 ++- .../DlgEditReference/DlgEditReference.tsx | 10 +-- .../dialogs/DlgEditReference/EntityTab.tsx | 4 +- .../DlgEditReference/WordformButton.tsx | 11 ++- .../DlgEditWordForms/DlgEditWordForms.tsx | 23 ++++-- .../DlgEditWordForms/WordFormsTable.tsx | 2 +- .../frontend/src/dialogs/DlgRenameCst.tsx | 8 +- rsconcept/frontend/src/dialogs/DlgShowAST.tsx | 2 +- .../frontend/src/dialogs/DlgUploadRSForm.tsx | 2 +- rsconcept/frontend/src/index.css | 15 ++-- rsconcept/frontend/src/main.tsx | 2 +- .../frontend/src/models/languageAPI.test.ts | 2 +- .../frontend/src/models/libraryAPI.test.ts | 2 +- rsconcept/frontend/src/models/rsformAPI.ts | 6 +- .../frontend/src/pages/CreateRSFormPage.tsx | 8 +- rsconcept/frontend/src/pages/HomePage.tsx | 6 +- .../src/pages/LibraryPage/ItemIcons.tsx | 7 +- .../src/pages/LibraryPage/SearchPanel.tsx | 23 +++++- .../src/pages/LibraryPage/ViewLibrary.tsx | 8 +- rsconcept/frontend/src/pages/LoginPage.tsx | 8 +- .../src/pages/ManualsPage/TopicsList.tsx | 30 ++++++-- .../ConstituentaToolbar.tsx | 12 +-- .../EditorConstituenta/FormConstituenta.tsx | 6 +- .../EditorRSExpression/EditorRSExpression.tsx | 2 +- .../EditorRSExpression/ParsingResult.tsx | 2 +- .../EditorRSExpression/RSAnalyzer.tsx | 2 +- .../EditorRSExpression/StatusBar.tsx | 8 +- .../RSFormPage/EditorRSForm/RSFormStats.tsx | 32 ++++---- .../RSFormPage/EditorRSForm/RSFormToolbar.tsx | 10 +-- .../RSFormPage/EditorRSList/RSListToolbar.tsx | 12 +-- .../pages/RSFormPage/EditorRSList/RSTable.tsx | 2 +- .../EditorTermGraph/EditorTermGraph.tsx | 19 ++++- .../EditorTermGraph/GraphToolbar.tsx | 14 ++-- .../src/pages/RSFormPage/RSFormPage.tsx | 2 +- .../frontend/src/pages/RSFormPage/RSTabs.tsx | 32 +++++--- .../src/pages/RSFormPage/RSTabsMenu.tsx | 26 +++---- .../ViewConstituents/ConstituentsSearch.tsx | 14 +--- .../ViewConstituents/ConstituentsTable.tsx | 12 ++- rsconcept/frontend/src/pages/RegisterPage.tsx | 2 +- .../pages/UserProfilePage/EditorPassword.tsx | 9 ++- .../pages/UserProfilePage/EditorProfile.tsx | 5 +- .../src/pages/UserProfilePage/UserTabs.tsx | 4 +- .../UserProfilePage/ViewSubscriptions.tsx | 9 ++- rsconcept/frontend/src/utils/codemirror.ts | 44 ++++++++--- rsconcept/frontend/src/utils/constants.ts | 1 + 110 files changed, 899 insertions(+), 460 deletions(-) create mode 100644 rsconcept/frontend/README.md rename rsconcept/frontend/src/components/Common/{LabeledText.tsx => LabeledValue.tsx} (59%) diff --git a/README.md b/README.md index 1d5ce40f..d80e5085 100644 --- a/README.md +++ b/README.md @@ -12,17 +12,18 @@ This readme file is used mostly to document project dependencies npm install
   - axios
+  - clsx
   - react-router-dom 
   - react-toastify
   - react-loader-spinner
-  - js-file-download
   - react-tabs
   - react-intl
   - react-select
   - react-error-boundary
   - react-pdf
-  - reagraph
   - react-tooltip
+  - js-file-download
+  - reagraph
   - @tanstack/react-table
   - @uiw/react-codemirror
   - @uiw/codemirror-themes
diff --git a/rsconcept/frontend/README.md b/rsconcept/frontend/README.md
new file mode 100644
index 00000000..8cbcd381
--- /dev/null
+++ b/rsconcept/frontend/README.md
@@ -0,0 +1,21 @@
+# Frontend Developer guidelines
+
+Styling conventions
+- static > conditional static > props. All dynamic styling should go in styles props
+- dimensions = rectangle + outer layout
+
+
+clsx className groupind and order +
+  - layer: z-position
+  - outer layout: fixed bottom-1/2 left-0 -translate-x-1/2
+  - rectangle: mt-3 w-full min-w-10 h-fit
+  - inner layout: px-3 py-2 flex flex-col gap-3 justify-start items-center
+  - overflow behavior: overflow-auto
+  - border: borer-2 outline-none shadow-md
+  - colors: clr-controls
+  - text: text-start text-sm font-semibold whitespace-nowrap
+  - behavior modifiers: select-none disabled:cursor-not-allowed
+  - transitions: 
+  
+
\ No newline at end of file diff --git a/rsconcept/frontend/package-lock.json b/rsconcept/frontend/package-lock.json index 32144628..c758342c 100644 --- a/rsconcept/frontend/package-lock.json +++ b/rsconcept/frontend/package-lock.json @@ -13,6 +13,7 @@ "@uiw/codemirror-themes": "^4.21.21", "@uiw/react-codemirror": "^4.21.21", "axios": "^1.6.2", + "clsx": "^2.0.0", "js-file-download": "^0.4.12", "react": "^18.2.0", "react-dom": "^18.2.0", diff --git a/rsconcept/frontend/package.json b/rsconcept/frontend/package.json index a8cc4bb8..4cbe4713 100644 --- a/rsconcept/frontend/package.json +++ b/rsconcept/frontend/package.json @@ -17,6 +17,7 @@ "@uiw/codemirror-themes": "^4.21.21", "@uiw/react-codemirror": "^4.21.21", "axios": "^1.6.2", + "clsx": "^2.0.0", "js-file-download": "^0.4.12", "react": "^18.2.0", "react-dom": "^18.2.0", diff --git a/rsconcept/frontend/src/App.tsx b/rsconcept/frontend/src/App.tsx index 8a5abc9f..73feda82 100644 --- a/rsconcept/frontend/src/App.tsx +++ b/rsconcept/frontend/src/App.tsx @@ -1,3 +1,4 @@ +import clsx from 'clsx'; import { createBrowserRouter, Outlet, RouterProvider } from 'react-router-dom'; import ConceptToaster from './components/ConceptToaster'; @@ -21,7 +22,11 @@ function Root() { const { noNavigation, noFooter, viewportHeight, mainHeight, showScroll } = useConceptTheme(); return ( -
+
-
+
@@ -101,4 +112,4 @@ function App () { ); } -export default App; +export default App; \ No newline at end of file diff --git a/rsconcept/frontend/src/components/Common/Button.tsx b/rsconcept/frontend/src/components/Common/Button.tsx index 40e38e69..945f69c0 100644 --- a/rsconcept/frontend/src/components/Common/Button.tsx +++ b/rsconcept/frontend/src/components/Common/Button.tsx @@ -1,3 +1,5 @@ +import clsx from 'clsx'; + import { IColorsProps, IControlProps } from './commonInterfaces'; interface ButtonProps @@ -17,21 +19,30 @@ function Button({ loading, ...restProps }: ButtonProps) { - const borderClass = noBorder ? '' : 'border rounded'; - const padding = dense ? 'px-1' : 'px-3 py-2'; - const outlineClass = noOutline ? 'outline-none': 'clr-outline'; - const cursor = 'disabled:cursor-not-allowed ' + (loading ? 'cursor-progress ' : 'cursor-pointer '); return ( - - ); + ); } -export default Button; +export default Button; \ No newline at end of file diff --git a/rsconcept/frontend/src/components/Common/Checkbox.tsx b/rsconcept/frontend/src/components/Common/Checkbox.tsx index 74fa52d8..9646c26c 100644 --- a/rsconcept/frontend/src/components/Common/Checkbox.tsx +++ b/rsconcept/frontend/src/components/Common/Checkbox.tsx @@ -1,3 +1,4 @@ +import clsx from 'clsx'; import { useMemo } from 'react'; import { CheckboxCheckedIcon } from '../Icons'; @@ -25,14 +26,10 @@ function Checkbox({ } else if (setValue) { return 'cursor-pointer'; } else { - return '' + return ''; } }, [disabled, setValue]); - const bgColor = useMemo( - () => { - return value !== false ? 'clr-primary' : 'clr-app' - }, [value]); - + function handleClick(event: React.MouseEvent): void { event.preventDefault(); if (disabled || !setValue) { @@ -42,27 +39,31 @@ function Checkbox({ } return ( - - ); + ); } -export default Checkbox; +export default Checkbox; \ No newline at end of file diff --git a/rsconcept/frontend/src/components/Common/ConceptLoader.tsx b/rsconcept/frontend/src/components/Common/ConceptLoader.tsx index c19bec4a..9ad8b364 100644 --- a/rsconcept/frontend/src/components/Common/ConceptLoader.tsx +++ b/rsconcept/frontend/src/components/Common/ConceptLoader.tsx @@ -10,15 +10,13 @@ interface ConceptLoaderProps { export function ConceptLoader({size=10}: ConceptLoaderProps) { const {colors} = useConceptTheme(); - return ( -
- -
- ); -} +
+ +
); +} \ No newline at end of file diff --git a/rsconcept/frontend/src/components/Common/ConceptSearch.tsx b/rsconcept/frontend/src/components/Common/ConceptSearch.tsx index d7220225..bb6a03ba 100644 --- a/rsconcept/frontend/src/components/Common/ConceptSearch.tsx +++ b/rsconcept/frontend/src/components/Common/ConceptSearch.tsx @@ -5,31 +5,27 @@ import TextInput from './TextInput'; interface ConceptSearchProps { value: string onChange?: (newValue: string) => void - dense?: boolean noBorder?: boolean dimensions?: string } -function ConceptSearch({ value, onChange, noBorder, dimensions, dense }: ConceptSearchProps) { - const borderClass = dense && !noBorder ? 'border-t border-x': ''; +function ConceptSearch({ value, onChange, noBorder, dimensions }: ConceptSearchProps) { return (
(onChange ? onChange(event.target.value) : undefined)} />
); } -export default ConceptSearch; - - +export default ConceptSearch; \ No newline at end of file diff --git a/rsconcept/frontend/src/components/Common/ConceptTab.tsx b/rsconcept/frontend/src/components/Common/ConceptTab.tsx index 26a3bbb6..c7e67a63 100644 --- a/rsconcept/frontend/src/components/Common/ConceptTab.tsx +++ b/rsconcept/frontend/src/components/Common/ConceptTab.tsx @@ -1,3 +1,4 @@ +import clsx from 'clsx'; import type { TabProps } from 'react-tabs'; import { Tab } from 'react-tabs'; @@ -11,7 +12,14 @@ extends Omit { function ConceptTab({ label, tooltip, className, ...otherProps }: ConceptTabProps) { return ( @@ -21,4 +29,4 @@ function ConceptTab({ label, tooltip, className, ...otherProps }: ConceptTabProp ConceptTab.tabsRole = 'Tab'; -export default ConceptTab; +export default ConceptTab; \ No newline at end of file diff --git a/rsconcept/frontend/src/components/Common/ConceptTooltip.tsx b/rsconcept/frontend/src/components/Common/ConceptTooltip.tsx index d93cc884..b9dd2c6c 100644 --- a/rsconcept/frontend/src/components/Common/ConceptTooltip.tsx +++ b/rsconcept/frontend/src/components/Common/ConceptTooltip.tsx @@ -1,5 +1,6 @@ 'use client'; +import clsx from 'clsx'; import { createPortal } from 'react-dom'; import { ITooltip, Tooltip } from 'react-tooltip'; @@ -26,7 +27,12 @@ function ConceptTooltip({ - ); +
); } -export default Divider; +export default Divider; \ No newline at end of file diff --git a/rsconcept/frontend/src/components/Common/Dropdown.tsx b/rsconcept/frontend/src/components/Common/Dropdown.tsx index f2e9a239..17119d1d 100644 --- a/rsconcept/frontend/src/components/Common/Dropdown.tsx +++ b/rsconcept/frontend/src/components/Common/Dropdown.tsx @@ -1,16 +1,36 @@ +import clsx from 'clsx'; + +import Overlay from './Overlay'; + interface DropdownProps { - children: React.ReactNode stretchLeft?: boolean dimensions?: string + children: React.ReactNode } -function Dropdown({ children, dimensions = 'w-fit', stretchLeft }: DropdownProps) { +function Dropdown({ + dimensions = 'w-fit', + stretchLeft, + children +}: DropdownProps) { return ( -
-
+ {children} -
-
); + ); } -export default Dropdown; +export default Dropdown; \ No newline at end of file diff --git a/rsconcept/frontend/src/components/Common/DropdownButton.tsx b/rsconcept/frontend/src/components/Common/DropdownButton.tsx index 62f56f63..280e201e 100644 --- a/rsconcept/frontend/src/components/Common/DropdownButton.tsx +++ b/rsconcept/frontend/src/components/Common/DropdownButton.tsx @@ -1,3 +1,5 @@ +import clsx from 'clsx'; + interface DropdownButtonProps { tooltip?: string | undefined onClick?: () => void @@ -6,17 +8,24 @@ interface DropdownButtonProps { } function DropdownButton({ tooltip, onClick, disabled, children }: DropdownButtonProps) { - const behavior = onClick ? 'cursor-pointer disabled:cursor-not-allowed clr-hover' : 'cursor-default'; - const text = disabled ? 'text-controls' : ''; return ( ); } -export default DropdownButton; +export default DropdownButton; \ No newline at end of file diff --git a/rsconcept/frontend/src/components/Common/DropdownCheckbox.tsx b/rsconcept/frontend/src/components/Common/DropdownCheckbox.tsx index 404a8725..c4d08c88 100644 --- a/rsconcept/frontend/src/components/Common/DropdownCheckbox.tsx +++ b/rsconcept/frontend/src/components/Common/DropdownCheckbox.tsx @@ -1,3 +1,5 @@ +import clsx from 'clsx'; + import Checkbox from './Checkbox'; interface DropdownCheckboxProps { @@ -9,11 +11,15 @@ interface DropdownCheckboxProps { } function DropdownCheckbox({ tooltip, setValue, disabled, ...restProps }: DropdownCheckboxProps) { - const behavior = (setValue && !disabled) ? 'clr-hover' : ''; return (
); } -export default DropdownCheckbox; +export default DropdownCheckbox; \ No newline at end of file diff --git a/rsconcept/frontend/src/components/Common/EmbedYoutube.tsx b/rsconcept/frontend/src/components/Common/EmbedYoutube.tsx index 88fd20d7..db3734ce 100644 --- a/rsconcept/frontend/src/components/Common/EmbedYoutube.tsx +++ b/rsconcept/frontend/src/components/Common/EmbedYoutube.tsx @@ -11,13 +11,20 @@ function EmbedYoutube({ videoID, pxHeight, pxWidth }: EmbedYoutubeProps) { return (