Skip to content

Commit da1adeb

Browse files
committed
add transparency
1 parent cc097d5 commit da1adeb

File tree

13 files changed

+111
-24
lines changed

13 files changed

+111
-24
lines changed

src/common/utils/colorUtils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
import { getLuminance } from "polished";
1+
import { darken, getLuminance, lighten } from "polished";
22

33
export function isLight(color: string): boolean {
44
return getLuminance(color) >= 0.5;
55
}
6+
7+
export function adjustLuminance(amount: number, color: string) {
8+
return isLight(color) ? darken(amount, color) : lighten(amount, color);
9+
}

src/common/utils/htmlHelpers.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { ForwardedRef } from "react";
2+
3+
export function setRef<T extends HTMLElement>(
4+
ref: ForwardedRef<T>,
5+
value: T | null,
6+
): void {
7+
if (typeof ref === "function") {
8+
ref(value);
9+
} else if (ref != null) {
10+
ref.current = value;
11+
}
12+
}

src/components/AppSideBar/AppSideBar.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { adjustLuminance } from "../../common/utils/colorUtils";
12
import useSystemSettings from "../../stores/systemSettingsStore";
23
import Button from "../Button";
34
import { StyledItemContainer, StyledSideBar } from "./styles";
@@ -27,7 +28,9 @@ function AppSideBar({ items }: AppSideBarProps) {
2728
group="vertical"
2829
onClick={item.onClick}
2930
color={fontColor}
30-
backgroundColor={buttonColor}
31+
backgroundColor={"transparent"}
32+
backgroundColorHover={adjustLuminance(0.1, buttonColor)}
33+
backgroundColorActive={adjustLuminance(0.2, buttonColor)}
3134
active={item.isActive ?? false}
3235
justifyContent="start"
3336
key={item.title}

src/components/BorderedApp/BorderedApp.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function BorderedApp<
7272
contentRef,
7373
}: React.PropsWithChildren<BorderedAppProps<T, E>>) {
7474
const winMan = useWindowManagerStore();
75-
const settings = useSystemSettings();
75+
const { mainColor, blur, opacity } = useSystemSettings();
7676

7777
// Listen for keyDown events and send them down to the content rendered inside the bordered app
7878
const handleKeyDown = (e: KeyboardEvent) =>
@@ -122,10 +122,12 @@ function BorderedApp<
122122
initialDimensions={initialDimensions}
123123
initialPosition={initialPosition}
124124
zIndex={zIndex}
125-
backgroundColor={settings.mainColor}
125+
backgroundColor={mainColor}
126126
display={hidden === true ? "none" : "grid"}
127127
tabIndex={0}
128128
onKeyDown={handleKeyDown}
129+
opacity={opacity}
130+
blur={blur}
129131
>
130132
<StyledCorner location="nw" ref={resizeHandleNW} />
131133
<StyledEdge location="n" ref={resizeHandleN} />

src/components/BorderedApp/styles.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import styled from "@emotion/styled";
22
import { Dimensions, Position } from "../../hooks/useDragToResize";
3+
import { transparentize } from "polished";
34

45
interface StyledBorderedAppProps {
56
initialDimensions: Dimensions;
67
initialPosition: Position;
78
zIndex: number | undefined;
89
backgroundColor: string;
910
display: "none" | "grid";
11+
opacity: number;
12+
blur: number;
1013
}
1114

1215
export const StyledBorderedApp = styled.div<StyledBorderedAppProps>`
@@ -26,7 +29,9 @@ export const StyledBorderedApp = styled.div<StyledBorderedAppProps>`
2629
width: ${(props) => props.initialDimensions.width}px;
2730
height: ${(props) => props.initialDimensions.height}px;
2831
z-index: ${(props) => props.zIndex};
29-
background-color: ${(props) => props.backgroundColor};
32+
background-color: ${(props) =>
33+
transparentize(props.opacity, props.backgroundColor)};
34+
backdrop-filter: ${(props) => props.blur && `blur(${props.blur}px)`};
3035
display: ${(props) => props.display};
3136
left: ${(props) => props.initialPosition.x}px;
3237
top: ${(props) => props.initialPosition.y}px;

src/components/BottomBar/BottomBar.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@ interface BottomBarProps {}
1212

1313
// eslint-disable-next-line no-empty-pattern
1414
function BottomBar({}: BottomBarProps) {
15-
const settings = useSystemSettings();
15+
const { mainColor, opacity, blur } = useSystemSettings();
1616
return (
1717
<StyledContainer id="bottom-bar__container">
18-
<StyledBottomBar id="bottom-bar" backgroundColor={settings.mainColor}>
18+
<StyledBottomBar
19+
id="bottom-bar"
20+
backgroundColor={mainColor}
21+
opacity={opacity}
22+
blur={blur}
23+
>
1924
<StyledContents id="bottom-bar__contents">
2025
<TextEditorLauncher />
2126
<CalculatorLauncher />

src/components/BottomBar/styles.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,20 @@ export const StyledContainer = styled.div`
1515
align-items: center;
1616
`;
1717

18-
export const StyledBottomBar = styled.div<{ backgroundColor: string }>`
18+
interface StyledBottomBarProps {
19+
backgroundColor: string;
20+
opacity: number;
21+
blur: number;
22+
}
23+
export const StyledBottomBar = styled.div<StyledBottomBarProps>`
1924
height: 100%;
2025
width: 100%;
2126
display: flex;
2227
background-color: var(--ui-color-primary);
2328
border-radius: 50px;
24-
background-color: ${(props) => transparentize(0.5, props.backgroundColor)};
25-
backdrop-filter: blur(5px);
29+
background-color: ${(props) =>
30+
transparentize(props.opacity, props.backgroundColor)};
31+
backdrop-filter: ${(props) => props.blur && `blur(${props.blur}px)`};
2632
box-shadow:
2733
0 -2px 10px 1px #11172b,
2834
0 -2px 3px #bebebe inset;

src/components/Button/Button.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { forwardRef, PropsWithChildren, useCallback } from "react";
22
import { StyledButton, StyledButtonProps } from "./styles";
3+
import { setRef } from "../../common/utils/htmlHelpers";
34

45
interface ButtonProps extends StyledButtonProps {
56
onClick?: () => void;
@@ -9,13 +10,7 @@ interface ButtonProps extends StyledButtonProps {
910
const Button = forwardRef<HTMLButtonElement, PropsWithChildren<ButtonProps>>(
1011
({ onClick, children, ...rest }, ref) => {
1112
const onRef = useCallback(
12-
(el: HTMLButtonElement | null) => {
13-
if (typeof ref === "function") {
14-
ref(el);
15-
} else if (ref != null) {
16-
ref.current = el;
17-
}
18-
},
13+
(el: HTMLButtonElement | null) => setRef(ref, el),
1914
[ref],
2015
);
2116
return (

src/components/TopBar/TopBar.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@ interface TopBarProps {}
1313

1414
// eslint-disable-next-line no-empty-pattern
1515
function TopBar({}: TopBarProps) {
16-
const settings = useSystemSettings();
16+
const { mainColor, opacity, blur } = useSystemSettings();
1717
return (
1818
<StyledTopBarContainer id="top-bar__container">
19-
<StyledTopBar id="top-bar" backgroundColor={settings.mainColor}>
19+
<StyledTopBar
20+
id="top-bar"
21+
backgroundColor={mainColor}
22+
opacity={opacity}
23+
blur={blur}
24+
>
2025
<StyledTopBarContents id="top-bar__contents">
2126
<FocusedWindowMenu />
2227
<ClockMenu />

src/components/TopBar/styles.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,21 @@ export const StyledTopBarContainer = styled.div`
1010
box-sizing: border-box;
1111
`;
1212

13-
export const StyledTopBar = styled.div<{ backgroundColor: string }>`
13+
interface StyledTopBarProps {
14+
backgroundColor: string;
15+
opacity: number;
16+
blur: number;
17+
}
18+
export const StyledTopBar = styled.div<StyledTopBarProps>`
1419
height: 100%;
1520
width: 100%;
1621
border-radius: 15px;
1722
box-shadow:
1823
0 -2px 10px 1px #11172b,
1924
0 -2px 3px #bebebe inset;
20-
background-color: ${(props) => transparentize(0.5, props.backgroundColor)};
21-
backdrop-filter: blur(5px);
25+
background-color: ${(props) =>
26+
transparentize(props.opacity, props.backgroundColor)};
27+
backdrop-filter: ${(props) => props.blur && `blur(${props.blur}px)`};
2228
`;
2329

2430
export const StyledTopBarContents = styled.div`

0 commit comments

Comments
 (0)