Skip to content

Commit c694c14

Browse files
Added option to display gradient on background only
1 parent 8c568bd commit c694c14

5 files changed

Lines changed: 61 additions & 15 deletions

File tree

index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,13 @@
8585
href="./public/res/apple/apple-touch-icon-180x180.png"
8686
/>
8787
</head>
88-
<body id="appBody">
88+
<body id="appBody">
8989
<script>
9090
window.global ||= window;
9191
</script>
9292
<div id="root"></div>
9393
<div id="portalContainer"></div>
9494
<script type="module" src="./src/index.tsx"></script>
95+
<div id="gradientLayer"></div>
9596
</body>
9697
</html>

src/app/features/settings/general/General.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ function Appearance() {
367367
const [twitterEmoji, setTwitterEmoji] = useSetting(settingsAtom, 'twitterEmoji');
368368

369369
const [customBackgroundEnabled, setCustomBackgroundEnabled] = useSetting(settingsAtom, 'customBackgroundEnabled');
370+
const [customBackgroundOnly, setCustomBackgroundOnly] = useSetting(settingsAtom, 'customBackgroundOnly');
370371
const [transparency, setTransparency] = useSetting(settingsAtom, 'transparency');
371372
const [customBgColor1, setCustomBgColor1] = useSetting(settingsAtom, 'customBgColor1');
372373
const [customBgColor2, setCustomBgColor2] = useSetting(settingsAtom, 'customBgColor2');
@@ -448,6 +449,19 @@ function Appearance() {
448449
</Box>
449450
</SequenceCard>
450451

452+
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
453+
<SettingTile
454+
title="Background only"
455+
after={
456+
<Switch
457+
variant="Primary"
458+
value={customBackgroundOnly}
459+
onChange={setCustomBackgroundOnly}
460+
/>
461+
}
462+
/>
463+
</SequenceCard>
464+
451465
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
452466
<SettingTile title="Transparency" after={<TransparencyInput/>}/>
453467
</SequenceCard>

src/app/pages/ThemeManager.tsx

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { ReactNode, useEffect } from 'react';
2-
import { configClass, varsClass } from 'folds';
2+
import { config, configClass, varsClass } from 'folds';
33
import {
44
DarkTheme,
55
LightTheme,
@@ -55,6 +55,7 @@ export function AuthRouteThemeManager({ children }: { children: ReactNode }) {
5555

5656
export function CustomThemeManager() {
5757
const [customBackgroundEnabled] = useSetting(settingsAtom, 'customBackgroundEnabled');
58+
const [customBackgroundOnly] = useSetting(settingsAtom, 'customBackgroundOnly');
5859
const [customBgColor1] = useSetting(settingsAtom, 'customBgColor1');
5960
const [customBgColor2] = useSetting(settingsAtom, 'customBgColor2');
6061
const [customBgColor3] = useSetting(settingsAtom, 'customBgColor3');
@@ -63,33 +64,52 @@ export function CustomThemeManager() {
6364
const [transparency] = useSetting(settingsAtom, 'transparency');
6465
const [angle] = useSetting(settingsAtom, 'angle');
6566
const [blur] = useSetting(settingsAtom, 'blur');
66-
6767
const [monochromeMode] = useSetting(settingsAtom, 'monochromeMode');
6868

6969
useEffect(() => {
70+
const gradientLayer = document.getElementById('gradientLayer');
71+
if (!gradientLayer) return;
72+
73+
gradientLayer.style.setProperty('z-index', customBackgroundOnly ? config.zIndex.Z100 : config.zIndex.Max);
74+
7075
if (!customBackgroundEnabled) {
71-
document.body.style.background = 'none';
72-
document.body.style.opacity = '1';
73-
document.body.style.backdropFilter = 'none';
76+
gradientLayer.style.background = 'none';
77+
gradientLayer.style.opacity = '0';
78+
gradientLayer.style.backdropFilter = 'none';
7479
return;
7580
}
7681

7782
const colors = [customBgColor1, customBgColor2, customBgColor3, customBgColor4, customBgColor5]
7883
.filter(Boolean)
79-
.map(c => (monochromeMode ? hexToGrayscale(c) : c))
84+
.map((c) => (monochromeMode ? hexToGrayscale(c) : c))
8085
.join(', ');
81-
82-
const gradient = `linear-gradient(${angle}deg, ${colors})`;
83-
document.body.style.background = gradient;
84-
86+
87+
gradientLayer.style.background = `linear-gradient(${angle}deg, ${colors})`;
88+
8589
if (blur && blur > 0) {
86-
document.body.style.backdropFilter = `blur(${blur}px)`;
90+
gradientLayer.style.backdropFilter = `blur(${blur}px)`;
91+
} else {
92+
gradientLayer.style.backdropFilter = 'none';
8793
}
88-
94+
8995
if (transparency !== undefined) {
90-
document.body.style.opacity = `${1 - transparency / 100}`;
96+
gradientLayer.style.opacity = `${transparency / 100}`;
97+
} else {
98+
gradientLayer.style.opacity = '0';
9199
}
92-
}, [customBackgroundEnabled, customBgColor1, customBgColor2, customBgColor3, customBgColor4, customBgColor5, transparency, angle, blur, monochromeMode]);
100+
}, [
101+
customBackgroundEnabled,
102+
customBackgroundOnly,
103+
customBgColor1,
104+
customBgColor2,
105+
customBgColor3,
106+
customBgColor4,
107+
customBgColor5,
108+
transparency,
109+
angle,
110+
blur,
111+
monochromeMode,
112+
]);
93113

94114
return null;
95115
}

src/app/state/settings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface Settings {
1616
darkThemeId?: string;
1717
monochromeMode?: boolean;
1818
customBackgroundEnabled: boolean;
19+
customBackgroundOnly: boolean;
1920
transparency: number;
2021
blur: number;
2122
angle: number;
@@ -59,6 +60,7 @@ const defaultSettings: Settings = {
5960
darkThemeId: undefined,
6061
monochromeMode: false,
6162
customBackgroundEnabled: false,
63+
customBackgroundOnly: false,
6264
transparency: 15,
6365
blur: 0,
6466
angle: 45,

src/index.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ body {
6262
flex-direction: column;
6363
}
6464

65+
#gradientLayer {
66+
position: fixed;
67+
inset: 0;
68+
pointer-events: none;
69+
opacity: 0;
70+
background: none;
71+
backdrop-filter: none;
72+
}
73+
6574
*,
6675
*::before,
6776
*::after {

0 commit comments

Comments
 (0)