mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-08-26 06:09:23 +00:00

# Description of Changes This PR refactors the frontend icon system to remove reliance on @mui/icons-material and the Google Material Symbols webfont. 🔄 Changes Introduced a new LocalIcon component powered by Iconify. Added scripts/generate-icons.js to: Scan the codebase for used icons. Extract only required Material Symbols from @iconify-json/material-symbols. Generate a minimized JSON bundle and TypeScript types. Updated .gitignore to exclude generated icon files. Replaced all <span className="material-symbols-rounded"> and MUI icon imports with <LocalIcon> usage. Removed material-symbols CSS import and related font dependency. Updated tsconfig.json to support JSON imports. Added prebuild/predev hooks to auto-generate the icons. ✅ Benefits No more 5MB+ Google webfont download → reduces initial page load size. Smaller install footprint → no giant @mui/icons-material dependency. Only ships the icons we actually use, cutting bundle size further. Type-safe icons via auto-generated MaterialSymbolIcon union type. Note most MUI not included in this update since they are low priority due to small SVG sizing (don't grab whole bundle) --- ## Checklist ### General - [ ] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md) (if applicable) - [ ] I have performed a self-review of my own code - [ ] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md#6-testing) for more details. --------- Co-authored-by: a <a>
221 lines
7.9 KiB
TypeScript
221 lines
7.9 KiB
TypeScript
import React, { useState, useRef, forwardRef, useEffect } from "react";
|
|
import { ActionIcon, Stack, Divider } from "@mantine/core";
|
|
import { useTranslation } from 'react-i18next';
|
|
import LocalIcon from './LocalIcon';
|
|
import { useRainbowThemeContext } from "./RainbowThemeProvider";
|
|
import AppConfigModal from './AppConfigModal';
|
|
import { useIsOverflowing } from '../../hooks/useIsOverflowing';
|
|
import { useFilesModalContext } from '../../contexts/FilesModalContext';
|
|
import { useToolWorkflow } from '../../contexts/ToolWorkflowContext';
|
|
import { ButtonConfig } from '../../types/sidebar';
|
|
import './quickAccessBar/QuickAccessBar.css';
|
|
import AllToolsNavButton from './AllToolsNavButton';
|
|
import ActiveToolButton from "./quickAccessBar/ActiveToolButton";
|
|
import {
|
|
isNavButtonActive,
|
|
getNavButtonStyle,
|
|
getActiveNavButton,
|
|
} from './quickAccessBar/QuickAccessBar';
|
|
|
|
const QuickAccessBar = forwardRef<HTMLDivElement>(({
|
|
}, ref) => {
|
|
const { t } = useTranslation();
|
|
const { isRainbowMode } = useRainbowThemeContext();
|
|
const { openFilesModal, isFilesModalOpen } = useFilesModalContext();
|
|
const { handleReaderToggle, handleBackToTools, handleToolSelect, selectedToolKey, leftPanelView, toolRegistry, readerMode } = useToolWorkflow();
|
|
const [configModalOpen, setConfigModalOpen] = useState(false);
|
|
const [activeButton, setActiveButton] = useState<string>('tools');
|
|
const scrollableRef = useRef<HTMLDivElement>(null);
|
|
const isOverflow = useIsOverflowing(scrollableRef);
|
|
|
|
useEffect(() => {
|
|
const next = getActiveNavButton(selectedToolKey, readerMode);
|
|
setActiveButton(next);
|
|
}, [leftPanelView, selectedToolKey, toolRegistry, readerMode]);
|
|
|
|
const handleFilesButtonClick = () => {
|
|
openFilesModal();
|
|
};
|
|
|
|
|
|
const buttonConfigs: ButtonConfig[] = [
|
|
{
|
|
id: 'read',
|
|
name: t("quickAccess.read", "Read"),
|
|
icon: <LocalIcon icon="menu-book-rounded" width="1.5rem" height="1.5rem" />,
|
|
size: 'lg',
|
|
isRound: false,
|
|
type: 'navigation',
|
|
onClick: () => {
|
|
setActiveButton('read');
|
|
handleBackToTools();
|
|
handleReaderToggle();
|
|
}
|
|
},
|
|
// TODO: Add sign
|
|
//{
|
|
// id: 'sign',
|
|
// name: t("quickAccess.sign", "Sign"),
|
|
// icon: <LocalIcon icon="signature-rounded" width="1.25rem" height="1.25rem" />,
|
|
// size: 'lg',
|
|
// isRound: false,
|
|
// type: 'navigation',
|
|
// onClick: () => {
|
|
// setActiveButton('sign');
|
|
// handleToolSelect('sign');
|
|
// }
|
|
//},
|
|
{
|
|
id: 'automate',
|
|
name: t("quickAccess.automate", "Automate"),
|
|
icon: <LocalIcon icon="automation-outline" width="1.25rem" height="1.25rem" />,
|
|
size: 'lg',
|
|
isRound: false,
|
|
type: 'navigation',
|
|
onClick: () => {
|
|
setActiveButton('automate');
|
|
handleToolSelect('automate');
|
|
}
|
|
},
|
|
{
|
|
id: 'files',
|
|
name: t("quickAccess.files", "Files"),
|
|
icon: <LocalIcon icon="folder-rounded" width="1.25rem" height="1.25rem" />,
|
|
isRound: true,
|
|
size: 'lg',
|
|
type: 'modal',
|
|
onClick: handleFilesButtonClick
|
|
},
|
|
//TODO: Activity
|
|
//{
|
|
// id: 'activity',
|
|
// name: t("quickAccess.activity", "Activity"),
|
|
// icon: <LocalIcon icon="vital-signs-rounded" width="1.25rem" height="1.25rem" />,
|
|
// isRound: true,
|
|
// size: 'lg',
|
|
// type: 'navigation',
|
|
// onClick: () => setActiveButton('activity')
|
|
//},
|
|
{
|
|
id: 'config',
|
|
name: t("quickAccess.config", "Config"),
|
|
icon: <LocalIcon icon="settings-rounded" width="1.25rem" height="1.25rem" />,
|
|
size: 'lg',
|
|
type: 'modal',
|
|
onClick: () => {
|
|
setConfigModalOpen(true);
|
|
}
|
|
}
|
|
];
|
|
|
|
|
|
|
|
return (
|
|
<div
|
|
ref={ref}
|
|
data-sidebar="quick-access"
|
|
className={`h-screen flex flex-col w-20 quick-access-bar-main ${isRainbowMode ? 'rainbow-mode' : ''}`}
|
|
style={{
|
|
borderRight: '1px solid var(--border-default)'
|
|
}}
|
|
>
|
|
{/* Fixed header outside scrollable area */}
|
|
<div className="quick-access-header">
|
|
<ActiveToolButton activeButton={activeButton} setActiveButton={setActiveButton} />
|
|
<AllToolsNavButton activeButton={activeButton} setActiveButton={setActiveButton} />
|
|
|
|
</div>
|
|
|
|
{/* Conditional divider when overflowing */}
|
|
{isOverflow && (
|
|
<Divider
|
|
size="xs"
|
|
className="overflow-divider"
|
|
/>
|
|
)}
|
|
|
|
{/* Scrollable content area */}
|
|
<div
|
|
ref={scrollableRef}
|
|
className="quick-access-bar flex-1"
|
|
onWheel={(e) => {
|
|
// Prevent the wheel event from bubbling up to parent containers
|
|
e.stopPropagation();
|
|
}}
|
|
>
|
|
<div className="scrollable-content">
|
|
{/* Top section with main buttons */}
|
|
<Stack gap="lg" align="center">
|
|
{buttonConfigs.slice(0, -1).map((config, index) => (
|
|
<React.Fragment key={config.id}>
|
|
|
|
<div className="flex flex-col items-center gap-1" style={{ marginTop: index === 0 ? '0.5rem' : "0rem" }}>
|
|
<ActionIcon
|
|
size={isNavButtonActive(config, activeButton, isFilesModalOpen, configModalOpen, selectedToolKey, leftPanelView) ? (config.size || 'xl') : 'lg'}
|
|
variant="subtle"
|
|
onClick={() => {
|
|
config.onClick();
|
|
}}
|
|
style={getNavButtonStyle(config, activeButton, isFilesModalOpen, configModalOpen, selectedToolKey, leftPanelView)}
|
|
className={isNavButtonActive(config, activeButton, isFilesModalOpen, configModalOpen, selectedToolKey, leftPanelView) ? 'activeIconScale' : ''}
|
|
data-testid={`${config.id}-button`}
|
|
>
|
|
<span className="iconContainer">
|
|
{config.icon}
|
|
</span>
|
|
</ActionIcon>
|
|
<span className={`button-text ${isNavButtonActive(config, activeButton, isFilesModalOpen, configModalOpen, selectedToolKey, leftPanelView) ? 'active' : 'inactive'}`}>
|
|
{config.name}
|
|
</span>
|
|
</div>
|
|
|
|
|
|
{/* Add divider after Automate button (index 1) and Files button (index 2) */}
|
|
{index === 1 && (
|
|
<Divider
|
|
size="xs"
|
|
className="content-divider"
|
|
/>
|
|
)}
|
|
</React.Fragment>
|
|
))}
|
|
</Stack>
|
|
|
|
{/* Spacer to push Config button to bottom */}
|
|
<div className="spacer" />
|
|
|
|
{/* Config button at the bottom */}
|
|
{buttonConfigs
|
|
.filter(config => config.id === 'config')
|
|
.map(config => (
|
|
<div className="flex flex-col items-center gap-1">
|
|
<ActionIcon
|
|
size={config.size || 'lg'}
|
|
variant="subtle"
|
|
onClick={config.onClick}
|
|
style={getNavButtonStyle(config, activeButton, isFilesModalOpen, configModalOpen, selectedToolKey, leftPanelView)}
|
|
className={isNavButtonActive(config, activeButton, isFilesModalOpen, configModalOpen, selectedToolKey, leftPanelView) ? 'activeIconScale' : ''}
|
|
data-testid={`${config.id}-button`}
|
|
>
|
|
<span className="iconContainer">
|
|
{config.icon}
|
|
</span>
|
|
</ActionIcon>
|
|
<span className={`button-text ${isNavButtonActive(config, activeButton, isFilesModalOpen, configModalOpen, selectedToolKey, leftPanelView) ? 'active' : 'inactive'}`}>
|
|
{config.name}
|
|
</span>
|
|
</div>
|
|
))}
|
|
</div>
|
|
</div>
|
|
|
|
<AppConfigModal
|
|
opened={configModalOpen}
|
|
onClose={() => setConfigModalOpen(false)}
|
|
/>
|
|
</div>
|
|
);
|
|
});
|
|
|
|
export default QuickAccessBar;
|