mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-08-23 20:59:23 +00:00
simplify QuickAccessBar and use rem values in FitText
This commit is contained in:
parent
14a3d9a778
commit
808aae186e
@ -63,7 +63,8 @@ const FitText: React.FC<FitTextProps> = ({
|
|||||||
wordBreak: lines > 1 ? ('keep-all' as any) : ('normal' as any),
|
wordBreak: lines > 1 ? ('keep-all' as any) : ('normal' as any),
|
||||||
overflowWrap: 'normal',
|
overflowWrap: 'normal',
|
||||||
hyphens: 'manual',
|
hyphens: 'manual',
|
||||||
fontSize: fontSize ? `${fontSize}px` : undefined,
|
// fontSize expects rem values (e.g., 1.2, 0.9) to scale with global font size
|
||||||
|
fontSize: fontSize ? `${fontSize}rem` : undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -16,7 +16,7 @@ import TopToolIndicator from './quickAccessBar/TopToolIndicator';
|
|||||||
import {
|
import {
|
||||||
isNavButtonActive,
|
isNavButtonActive,
|
||||||
getNavButtonStyle,
|
getNavButtonStyle,
|
||||||
getTargetNavButton
|
getActiveNavButton
|
||||||
} from './quickAccessBar/QuickAccessBar';
|
} from './quickAccessBar/QuickAccessBar';
|
||||||
|
|
||||||
const QuickAccessBar = forwardRef<HTMLDivElement>(({
|
const QuickAccessBar = forwardRef<HTMLDivElement>(({
|
||||||
@ -24,36 +24,21 @@ const QuickAccessBar = forwardRef<HTMLDivElement>(({
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { isRainbowMode } = useRainbowThemeContext();
|
const { isRainbowMode } = useRainbowThemeContext();
|
||||||
const { openFilesModal, isFilesModalOpen } = useFilesModalContext();
|
const { openFilesModal, isFilesModalOpen } = useFilesModalContext();
|
||||||
const { handleReaderToggle, selectedTool, selectedToolKey, leftPanelView } = useToolWorkflow();
|
const { handleReaderToggle, handleBackToTools, selectedTool, selectedToolKey, leftPanelView } = useToolWorkflow();
|
||||||
const [configModalOpen, setConfigModalOpen] = useState(false);
|
const [configModalOpen, setConfigModalOpen] = useState(false);
|
||||||
const [activeButton, setActiveButton] = useState<string>('tools');
|
const [activeButton, setActiveButton] = useState<string>('tools');
|
||||||
const scrollableRef = useRef<HTMLDivElement>(null);
|
const scrollableRef = useRef<HTMLDivElement>(null);
|
||||||
const isOverflow = useIsOverflowing(scrollableRef);
|
const isOverflow = useIsOverflowing(scrollableRef);
|
||||||
|
|
||||||
// Sync left nav highlight with selected tool when appropriate
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (leftPanelView === 'toolContent' && selectedTool) {
|
setActiveButton(getActiveNavButton(leftPanelView, selectedTool, selectedToolKey));
|
||||||
const target = getTargetNavButton(selectedTool, selectedToolKey);
|
|
||||||
|
|
||||||
if (target && activeButton !== target) {
|
|
||||||
setActiveButton(target);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// If tool doesn't map to a nav button, clear the highlight
|
|
||||||
if (!target && activeButton !== 'tools') {
|
|
||||||
setActiveButton('tools');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Revert highlight when no specific mapping applies
|
|
||||||
if (leftPanelView !== 'toolContent') {
|
|
||||||
setActiveButton('tools');
|
|
||||||
}
|
|
||||||
}, [leftPanelView, selectedTool, selectedToolKey]);
|
}, [leftPanelView, selectedTool, selectedToolKey]);
|
||||||
|
|
||||||
const handleFilesButtonClick = () => {
|
const handleFilesButtonClick = () => {
|
||||||
openFilesModal();
|
openFilesModal();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const buttonConfigs: ButtonConfig[] = [
|
const buttonConfigs: ButtonConfig[] = [
|
||||||
{
|
{
|
||||||
id: 'read',
|
id: 'read',
|
||||||
@ -64,6 +49,9 @@ const QuickAccessBar = forwardRef<HTMLDivElement>(({
|
|||||||
type: 'navigation',
|
type: 'navigation',
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
setActiveButton('read');
|
setActiveButton('read');
|
||||||
|
// Clear any selected tool and return to picker so the top tool indicator hides
|
||||||
|
handleBackToTools();
|
||||||
|
// Then enter reader mode
|
||||||
handleReaderToggle();
|
handleReaderToggle();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -77,7 +65,11 @@ const QuickAccessBar = forwardRef<HTMLDivElement>(({
|
|||||||
size: 'lg',
|
size: 'lg',
|
||||||
isRound: false,
|
isRound: false,
|
||||||
type: 'navigation',
|
type: 'navigation',
|
||||||
onClick: () => setActiveButton('sign')
|
onClick: () => {
|
||||||
|
setActiveButton('sign');
|
||||||
|
// Ensure any previously selected tool is cleared so indicator hides
|
||||||
|
handleBackToTools();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'automate',
|
id: 'automate',
|
||||||
@ -89,7 +81,11 @@ const QuickAccessBar = forwardRef<HTMLDivElement>(({
|
|||||||
size: 'lg',
|
size: 'lg',
|
||||||
isRound: false,
|
isRound: false,
|
||||||
type: 'navigation',
|
type: 'navigation',
|
||||||
onClick: () => setActiveButton('automate')
|
onClick: () => {
|
||||||
|
setActiveButton('automate');
|
||||||
|
// Ensure any previously selected tool is cleared so indicator hides
|
||||||
|
handleBackToTools();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'files',
|
id: 'files',
|
||||||
|
@ -34,7 +34,7 @@ export function CardTitle({ title }: { title: string }) {
|
|||||||
| Prop | Type | Default | Description |
|
| Prop | Type | Default | Description |
|
||||||
|------|------|---------|-------------|
|
|------|------|---------|-------------|
|
||||||
| `text` | `string` | — | The string to render and fit |
|
| `text` | `string` | — | The string to render and fit |
|
||||||
| `fontSize` | `number` | computed | Maximum starting font size in px |
|
| `fontSize` | `number` | computed | Maximum starting font size in rem (e.g., 1.2, 0.9) |
|
||||||
| `minimumFontScale` | `number` | `0.8` | Smallest scale relative to the max (0..1) |
|
| `minimumFontScale` | `number` | `0.8` | Smallest scale relative to the max (0..1) |
|
||||||
| `lines` | `number` | `1` | Maximum number of lines to display and fit |
|
| `lines` | `number` | `1` | Maximum number of lines to display and fit |
|
||||||
| `className` | `string` | — | Optional class on the rendered element |
|
| `className` | `string` | — | Optional class on the rendered element |
|
||||||
@ -67,7 +67,7 @@ Notes:
|
|||||||
### Explicit starting size
|
### Explicit starting size
|
||||||
|
|
||||||
```tsx
|
```tsx
|
||||||
<FitText text="Starts at 18px, scales down if needed" fontSize={18} />
|
<FitText text="Starts at 1.2rem, scales down if needed" fontSize={1.2} />
|
||||||
```
|
```
|
||||||
|
|
||||||
### Render as a div
|
### Render as a div
|
||||||
@ -107,5 +107,6 @@ export function CustomFit() {
|
|||||||
- For predictable measurements, ensure the container has a fixed width (or stable layout) when fitting occurs.
|
- For predictable measurements, ensure the container has a fixed width (or stable layout) when fitting occurs.
|
||||||
- Avoid animating width while fitting; update after animation completes for best results.
|
- Avoid animating width while fitting; update after animation completes for best results.
|
||||||
- When you need more control of typography, pass `fontSize` to define the starting ceiling.
|
- When you need more control of typography, pass `fontSize` to define the starting ceiling.
|
||||||
|
- **Important**: The `fontSize` prop expects `rem` values (e.g., 1.2, 0.9) to ensure text scales with global font size changes.
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,15 +1,9 @@
|
|||||||
import { ButtonConfig } from '../../../types/sidebar';
|
import { ButtonConfig } from '../../../types/sidebar';
|
||||||
|
import { useFlatToolRegistry } from '../../../data/toolRegistry';
|
||||||
|
|
||||||
// Border radius constants
|
// Border radius constants
|
||||||
export const ROUND_BORDER_RADIUS = '0.5rem';
|
export const ROUND_BORDER_RADIUS = '0.5rem';
|
||||||
|
|
||||||
/**
|
|
||||||
* Get border radius for a button based on its configuration
|
|
||||||
*/
|
|
||||||
export const getNavButtonBorderRadius = (config: ButtonConfig): string => {
|
|
||||||
return config.isRound ? ROUND_BORDER_RADIUS : ROUND_BORDER_RADIUS;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a navigation button is currently active
|
* Check if a navigation button is currently active
|
||||||
*/
|
*/
|
||||||
@ -42,7 +36,7 @@ export const getNavButtonStyle = (
|
|||||||
backgroundColor: `var(--icon-${config.id}-bg)`,
|
backgroundColor: `var(--icon-${config.id}-bg)`,
|
||||||
color: `var(--icon-${config.id}-color)`,
|
color: `var(--icon-${config.id}-color)`,
|
||||||
border: 'none',
|
border: 'none',
|
||||||
borderRadius: getNavButtonBorderRadius(config),
|
borderRadius: ROUND_BORDER_RADIUS,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,23 +45,38 @@ export const getNavButtonStyle = (
|
|||||||
backgroundColor: 'var(--icon-inactive-bg)',
|
backgroundColor: 'var(--icon-inactive-bg)',
|
||||||
color: 'var(--icon-inactive-color)',
|
color: 'var(--icon-inactive-color)',
|
||||||
border: 'none',
|
border: 'none',
|
||||||
borderRadius: getNavButtonBorderRadius(config),
|
borderRadius: ROUND_BORDER_RADIUS,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine which nav button should be highlighted based on selected tool
|
* Determine which nav button should be highlighted based on the tool registry.
|
||||||
|
* Uses the tool's `view` property to map to the nav button id.
|
||||||
*/
|
*/
|
||||||
export const getTargetNavButton = (selectedTool: any, selectedToolKey: string | null): string | null => {
|
export const getTargetNavButton = (
|
||||||
if (!selectedTool || !selectedToolKey) return null;
|
selectedToolKey: string | null,
|
||||||
|
registry: ReturnType<typeof useFlatToolRegistry>
|
||||||
// Map specific tool keys to nav button ids
|
): string | null => {
|
||||||
if (selectedToolKey === 'sign') return 'sign';
|
if (!selectedToolKey) return null;
|
||||||
if (selectedToolKey === 'read') return 'read';
|
|
||||||
if (selectedToolKey === 'automate') return 'automate';
|
const toolEntry = registry[selectedToolKey];
|
||||||
|
if (!toolEntry) return null;
|
||||||
// Fallback: use subcategory for automation tools
|
|
||||||
if (selectedTool.subcategory === 'Automation') return 'automate';
|
// Use the tool's view as the nav button id
|
||||||
|
return toolEntry.view || null;
|
||||||
return null;
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine the active nav button based on current tool state and registry
|
||||||
|
*/
|
||||||
|
export const getActiveNavButton = (
|
||||||
|
leftPanelView: 'toolPicker' | 'toolContent',
|
||||||
|
selectedToolKey: string | null,
|
||||||
|
registry: ReturnType<typeof useFlatToolRegistry>
|
||||||
|
): string => {
|
||||||
|
if (leftPanelView !== 'toolContent' || !selectedToolKey) {
|
||||||
|
return 'tools';
|
||||||
|
}
|
||||||
|
|
||||||
|
return getTargetNavButton(selectedToolKey, registry) || 'tools';
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user