Skip to content

Commit a86166c

Browse files
committed
add separators grouped buttons
1 parent eb5d4c4 commit a86166c

File tree

9 files changed

+62
-22
lines changed

9 files changed

+62
-22
lines changed

src/components/AppSideBar/AppSideBar.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,15 @@ interface SideBarItem {
1111

1212
interface AppSideBarProps {
1313
items: Array<SideBarItem>;
14+
itemSeparators?: boolean;
15+
itemSeparatorColor?: string;
1416
}
1517

16-
function AppSideBar({ items }: AppSideBarProps) {
18+
function AppSideBar({
19+
items,
20+
itemSeparators,
21+
itemSeparatorColor,
22+
}: AppSideBarProps) {
1723
const [fontColor, buttonColor] = useSystemSettings((s) => [
1824
s.fontColor,
1925
s.mainColor,
@@ -34,6 +40,8 @@ function AppSideBar({ items }: AppSideBarProps) {
3440
active={item.isActive ?? false}
3541
justifyContent="start"
3642
key={item.title}
43+
separators={itemSeparators}
44+
separatorColor={itemSeparatorColor}
3745
>
3846
{item.title}
3947
</Button>

src/components/Button/Button.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { forwardRef, PropsWithChildren, useCallback } from "react";
22
import { StyledButton, StyledButtonProps } from "./styles";
33
import { setRef } from "../../common/utils/htmlHelpers";
4+
import { adjustLuminance } from "../../common/utils/colorUtils";
45

56
interface ButtonProps extends StyledButtonProps {
67
onClick?: () => void;
@@ -13,8 +14,19 @@ const Button = forwardRef<HTMLButtonElement, PropsWithChildren<ButtonProps>>(
1314
(el: HTMLButtonElement | null) => setRef(ref, el),
1415
[ref],
1516
);
17+
const separatorColor =
18+
rest.separatorColor ??
19+
rest.backgroundColorHover ??
20+
(rest.backgroundColor && adjustLuminance(0.2, rest.backgroundColor)) ??
21+
"white";
22+
1623
return (
17-
<StyledButton {...rest} onClick={onClick} ref={onRef}>
24+
<StyledButton
25+
{...rest}
26+
onClick={onClick}
27+
ref={onRef}
28+
separatorColor={separatorColor}
29+
>
1830
{children}
1931
</StyledButton>
2032
);

src/components/Button/styles.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export interface StyledButtonProps {
1818
group?: "horizontal" | "vertical";
1919
padding?: CSSObject["padding"];
2020
justifyContent?: CSSProperties["justifyContent"];
21+
separators?: boolean;
22+
separatorColor?: string;
2123
}
2224

2325
export const StyledButton = styled.button<StyledButtonProps>`
@@ -30,7 +32,8 @@ function buildStyledButton({
3032
justifyContent = "center",
3133
...props
3234
}: StyledButtonProps): CSSObject {
33-
return {
35+
const styles: CSSObject = {
36+
position: "relative",
3437
...props,
3538
width: typeof width === "string" ? width : `${width}px`,
3639
height:
@@ -54,6 +57,31 @@ function buildStyledButton({
5457
},
5558
...radiusStyles({ borderRadius, group: props.group }), // this breaks the return type somehow. Something funky when spreading the emotion type
5659
} as CSSObject;
60+
61+
if (props.group && props.separators) {
62+
let width: string;
63+
let height: string;
64+
switch (props.group) {
65+
case "horizontal":
66+
width = "1px";
67+
height = "100%";
68+
break;
69+
case "vertical":
70+
width = "100%";
71+
height = "1px";
72+
break;
73+
}
74+
styles["&:not(:first-of-type)::before"] = {
75+
content: "''",
76+
position: "absolute",
77+
top: 0,
78+
left: 0,
79+
width,
80+
height,
81+
background: props.separatorColor ?? props.color,
82+
};
83+
}
84+
return styles;
5785
}
5886

5987
function getBackgroundColorActive(props: StyledButtonProps) {

src/programs/Calendar/CalendarNavigation/styles.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export const StyledCalendarNavigation = styled.div<StyledCalendarNavigationProps
99
grid-template-columns: 1fr 1fr 1fr;
1010
gap: 20px;
1111
grid-area: nav;
12-
padding-bottom: 5px;
1312
`;
1413

1514
export const StyledCalendarNavigationSection = styled.div<StyledCalendarNavigationSectionProps>`

src/programs/Calendar/CalendarSidebar/CalendarSidebar.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// import useCalendarEvents from "../hooks/useCalendarEvents";
22
import { useRef } from "react";
33
import CalendarTimeSlot from "../CalendarTimeSlot/CalendarTimeSlot";
4-
import { StyledCalendarSidebar, StyledDayBreak } from "./styles";
4+
import { StyledCalendarSidebar } from "./styles";
55
import useSystemSettings from "../../../stores/systemSettingsStore";
66

77
interface CalendarSidebarProps {
@@ -13,10 +13,7 @@ interface CalendarSidebarProps {
1313
// eslint-disable-next-line no-empty-pattern
1414
export default function CalendarSidebar({}: CalendarSidebarProps) {
1515
const ref = useRef<HTMLDivElement>(null);
16-
const [breakColor, scrollbarColor] = useSystemSettings((s) => [
17-
s.secondaryColor,
18-
s.iconColor,
19-
]);
16+
const [scrollbarColor] = useSystemSettings((s) => [s.iconColor]);
2017
return (
2118
<StyledCalendarSidebar
2219
scrollbarColor={scrollbarColor}
@@ -26,7 +23,6 @@ export default function CalendarSidebar({}: CalendarSidebarProps) {
2623
{Array.from({ length: 25 }).map((_, i) => (
2724
<>
2825
<CalendarTimeSlot hour={i} />
29-
{i < 24 && <StyledDayBreak color={breakColor} />}
3026
</>
3127
))}
3228
</StyledCalendarSidebar>

src/programs/Calendar/CalendarSidebar/styles.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,8 @@ export const StyledCalendarSidebar = styled.div<StyledCalendarSidebarProps>`
99
grid-area: side;
1010
overflow-y: auto;
1111
overflow-x: hidden; // getting a tiny amount of overflow, I think because of flex gap's sub-pixel rounding
12-
padding-left: 6px;
12+
/* padding-left: 6px; */
1313
box-sizing: border-box;
1414
scrollbar-color: ${(p) => p.scrollbarColor} transparent;
15-
`;
16-
17-
interface StyledDayBreakProps {
18-
color: string;
19-
}
20-
export const StyledDayBreak = styled.hr<StyledDayBreakProps>`
21-
width: 100%;
22-
margin: 0;
23-
background-color: ${(p) => p.color};
15+
border-radius: 10px;
2416
`;

src/programs/Calendar/CalendarTimeSlot/CalendarTimeSlot.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ export default function CalendarTimeSlot({ hour }: CalendarTimeSlotProps) {
2424

2525
return (
2626
<Button
27-
borderRadius={0}
28-
height={60}
27+
height={"12%"}
2928
backgroundColor={backgroundColor}
3029
color={fontColor}
3130
justifyContent="start"
3231
ref={onRef}
32+
group="vertical"
33+
separators
3334
>
3435
{hour.toString().padStart(2, "0")}:00
3536
</Button>

src/programs/Calendar/styles.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const StyledCalendarLayout = styled.div<StyledCalendarLayoutProps>`
1515
"nav nav nav"
1616
"days days side"
1717
"days days side";
18+
gap: 6px;
1819
grid-template-rows: 40px 1fr 1fr;
1920
grid-template-columns: 1fr 1fr minmax(150px, 1fr);
2021
`;

src/programs/FileBrowser/FileBrowser.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ function TopBar({
6262
color={fontColor}
6363
group="horizontal"
6464
borderRadius={6}
65+
separators
6566
>
6667
{"<"}
6768
</Button>
@@ -73,6 +74,7 @@ function TopBar({
7374
color={fontColor}
7475
group="horizontal"
7576
borderRadius={6}
77+
separators
7678
>
7779
{">"}
7880
</Button>
@@ -129,6 +131,7 @@ const FileBrowser = forwardRef<FileBrowserHandles, FileBrowserProps>(
129131
/>
130132

131133
<AppSideBar
134+
itemSeparators
132135
items={fs.favorites.map((fav) => ({
133136
title: fs.getNameFromPath(fav) ?? "",
134137
isActive: fav === fs.currentDirectory.path,

0 commit comments

Comments
 (0)