1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-31 00:16:47 +01:00

feat: configurable global font size (#9155)

This PR sets up the application to accept a value from a variant we
control to set the font size of the application on a global level. If it
fails, the value falls back to the previously set CSS value.
This commit is contained in:
Fredrik Strand Oseberg 2025-01-27 14:43:32 +01:00 committed by GitHub
parent 6363167b68
commit 378bbe5133
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 46 additions and 4 deletions

View File

@ -23,6 +23,7 @@ import { LicenseBanner } from './banners/internalBanners/LicenseBanner';
import { Demo } from './demo/Demo'; import { Demo } from './demo/Demo';
import { LoginRedirect } from './common/LoginRedirect/LoginRedirect'; import { LoginRedirect } from './common/LoginRedirect/LoginRedirect';
import { SecurityBanner } from './banners/internalBanners/SecurityBanner'; import { SecurityBanner } from './banners/internalBanners/SecurityBanner';
import { useUiFlag } from 'hooks/useUiFlag';
const StyledContainer = styled('div')(() => ({ const StyledContainer = styled('div')(() => ({
'& ul': { '& ul': {
@ -33,6 +34,7 @@ const StyledContainer = styled('div')(() => ({
export const App = () => { export const App = () => {
const { authDetails } = useAuthDetails(); const { authDetails } = useAuthDetails();
const { refetch: refetchUiConfig } = useUiConfig(); const { refetch: refetchUiConfig } = useUiConfig();
const uiGlobalFontSizeVariant = useUiFlag('uiGlobalFontSize');
const { user } = useAuthUser(); const { user } = useAuthUser();
const hasFetchedAuth = Boolean(authDetails || user); const hasFetchedAuth = Boolean(authDetails || user);
@ -43,6 +45,33 @@ export const App = () => {
? routes.filter((route) => !route.enterprise) ? routes.filter((route) => !route.enterprise)
: routes; : routes;
useEffect(() => {
let style: HTMLStyleElement | null = null;
if (!uiGlobalFontSizeVariant) return;
if (!uiGlobalFontSizeVariant.enabled) return;
try {
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = `
html {
font-size: ${uiGlobalFontSizeVariant?.payload?.value}px;
height: 100%;
overflow: auto;
overflow-y: scroll;
}
`;
document.head.appendChild(style);
} catch (err) {
console.error('Error setting global font size', err);
}
return () => {
if (!style) return;
document.head.removeChild(style);
};
}, [JSON.stringify(uiGlobalFontSizeVariant)]);
useEffect(() => { useEffect(() => {
if (hasFetchedAuth && Boolean(user?.id)) { if (hasFetchedAuth && Boolean(user?.id)) {
refetchUiConfig(); refetchUiConfig();

View File

@ -95,6 +95,7 @@ export type UiFlags = {
lifecycleImprovements?: boolean; lifecycleImprovements?: boolean;
frontendHeaderRedesign?: boolean; frontendHeaderRedesign?: boolean;
dataUsageMultiMonthView?: boolean; dataUsageMultiMonthView?: boolean;
uiGlobalFontSize?: Variant;
}; };
export interface IVersionInfo { export interface IVersionInfo {

View File

@ -63,7 +63,8 @@ export type IFlagKey =
| 'sortProjectRoles' | 'sortProjectRoles'
| 'lifecycleImprovements' | 'lifecycleImprovements'
| 'frontendHeaderRedesign' | 'frontendHeaderRedesign'
| 'dataUsageMultiMonthView'; | 'dataUsageMultiMonthView'
| 'uiGlobalFontSize';
export type IFlags = Partial<{ [key in IFlagKey]: boolean | Variant }>; export type IFlags = Partial<{ [key in IFlagKey]: boolean | Variant }>;
@ -304,6 +305,17 @@ const flags: IFlags = {
process.env.UNLEASH_EXPERIMENTAL_DATA_USAGE_MULTI_MONTH_VIEW, process.env.UNLEASH_EXPERIMENTAL_DATA_USAGE_MULTI_MONTH_VIEW,
false, false,
), ),
uiGlobalFontSize: {
name: 'uiGlobalFontSize',
enabled: parseEnvVarBoolean(
process.env.EXPERIMENTAL_UI_GLOBAL_FONT_SIZE_NAME,
false,
),
payload: {
type: PayloadType.JSON,
value: '14',
},
},
}; };
export const defaultExperimentalOptions: IExperimentalOptions = { export const defaultExperimentalOptions: IExperimentalOptions = {