feat(accessibility): implement centralized screen reader layout system (#8155)

This commit is contained in:
Victor Tsaran
2025-09-23 11:04:49 -07:00
committed by GitHub
parent f46e50b271
commit bfd904bfc8
10 changed files with 348 additions and 64 deletions
@@ -0,0 +1,32 @@
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { useUIState } from '../contexts/UIStateContext.js';
import { useConfig } from '../contexts/ConfigContext.js';
import { useSettings } from '../contexts/SettingsContext.js';
export const useFooterProps = () => {
const uiState = useUIState();
const config = useConfig();
const settings = useSettings();
return {
model: config.getModel(),
targetDir: config.getTargetDir(),
debugMode: config.getDebugMode(),
branchName: uiState.branchName,
debugMessage: uiState.debugMessage,
corgiMode: uiState.corgiMode,
errorCount: uiState.errorCount,
showErrorDetails: uiState.showErrorDetails,
showMemoryUsage:
config.getDebugMode() || settings.merged.ui?.showMemoryUsage || false,
promptTokenCount: uiState.sessionStats.lastPromptTokenCount,
nightly: uiState.nightly,
isTrustedFolder: uiState.isTrustedFolder,
vimMode: undefined,
};
};
@@ -0,0 +1,38 @@
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { useIsScreenReaderEnabled } from 'ink';
export interface LayoutConfig {
shouldUseStatic: boolean;
shouldShowFooterInComposer: boolean;
mode: 'default' | 'screenReader';
allowStaticToggle?: boolean;
}
export interface LayoutConfigOptions {
forceStaticMode?: boolean;
allowToggle?: boolean;
}
export const useLayoutConfig = (
options?: LayoutConfigOptions,
): LayoutConfig => {
const isScreenReader = useIsScreenReaderEnabled();
// Allow overriding static behavior when toggle is enabled
const shouldUseStatic =
options?.forceStaticMode !== undefined
? options.forceStaticMode
: !isScreenReader;
return {
shouldUseStatic,
shouldShowFooterInComposer: !isScreenReader,
mode: isScreenReader ? 'screenReader' : 'default',
allowStaticToggle: options?.allowToggle ?? false,
};
};