Skip to content

Commit 950d13e

Browse files
committed
calendar tweaks
1 parent 47609b2 commit 950d13e

File tree

9 files changed

+111
-23
lines changed

9 files changed

+111
-23
lines changed

src/common/utils/dateUtils.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
const MS_PER_DAY = 24 * 60 * 60 * 1000;
22

3+
const ordinalSuffixes = {
4+
one: "st",
5+
two: "nd",
6+
few: "rd",
7+
other: "th",
8+
many: "th",
9+
zero: "th",
10+
} as const satisfies Record<Intl.LDMLPluralRule, string>;
11+
312
export function getMonthName(
413
monthIndex: number,
514
locale = "en-US",
@@ -12,14 +21,43 @@ export function getMonthName(
1221

1322
export function getDayName(
1423
dayIndex: number,
24+
locale?: "en-US",
25+
format?: "long" | "short",
26+
): string;
27+
export function getDayName(
28+
dayIndex: Date,
29+
locale?: "en-US",
30+
format?: "long" | "short",
31+
): string;
32+
export function getDayName(
33+
d: number | Date,
1534
locale = "en-US",
1635
format: "long" | "short" = "short",
1736
) {
37+
const dayIndex = typeof d === "number" ? d : d.getDay();
1838
return new Intl.DateTimeFormat(locale, { weekday: format }).format(
1939
new Date(2021, 0, dayIndex + 3),
2040
);
2141
}
2242

43+
export function getDateOrdinal(
44+
dateOfMonth: number,
45+
locale?: Intl.UnicodeBCP47LocaleIdentifier,
46+
): string;
47+
export function getDateOrdinal(
48+
date: Date,
49+
locale?: Intl.UnicodeBCP47LocaleIdentifier,
50+
): string;
51+
export function getDateOrdinal(
52+
date: Date | number,
53+
locale: Intl.UnicodeBCP47LocaleIdentifier = "en-US",
54+
): string {
55+
const ordinalPlurals = new Intl.PluralRules(locale, { type: "ordinal" });
56+
57+
const d = typeof date === "number" ? date : date.getDate();
58+
return `${d}${ordinalSuffixes[ordinalPlurals.select(d)]}`;
59+
}
60+
2361
export function isToday(
2462
year: number,
2563
month: number,

src/components/BottomBar/styles.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import styled from "@emotion/styled";
2+
import { transparentize } from "polished";
23

34
export const StyledContainer = styled.div`
45
min-height: 0;
@@ -20,9 +21,11 @@ export const StyledBottomBar = styled.div<{ backgroundColor: string }>`
2021
display: flex;
2122
background-color: var(--ui-color-primary);
2223
border-radius: 50px;
23-
background-color: #2e3440;
24-
box-shadow: 0 -2px 10px 1px #11172b, 0 -2px 3px #bebebe inset;
25-
background-color: ${(props) => props.backgroundColor};
24+
background-color: ${(props) => transparentize(0.5, props.backgroundColor)};
25+
backdrop-filter: blur(5px);
26+
box-shadow:
27+
0 -2px 10px 1px #11172b,
28+
0 -2px 3px #bebebe inset;
2629
`;
2730

2831
export const StyledContents = styled.div`

src/components/TopBar/styles.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import styled from "@emotion/styled";
2+
import { transparentize } from "polished";
23

34
export const StyledTopBarContainer = styled.div`
45
grid-area: top-bar;
@@ -13,8 +14,11 @@ export const StyledTopBar = styled.div<{ backgroundColor: string }>`
1314
height: 100%;
1415
width: 100%;
1516
border-radius: 15px;
16-
box-shadow: 0 -2px 10px 1px #11172b, 0 -2px 3px #bebebe inset;
17-
background-color: ${(props) => props.backgroundColor};
17+
box-shadow:
18+
0 -2px 10px 1px #11172b,
19+
0 -2px 3px #bebebe inset;
20+
background-color: ${(props) => transparentize(0.5, props.backgroundColor)};
21+
backdrop-filter: blur(5px);
1822
`;
1923

2024
export const StyledTopBarContents = styled.div`

src/programs/Calendar/Calendar.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,19 @@ const Calendar = forwardRef<CalendarHandles, CalendarProps>((_props, ref) => {
3434
className="calendar"
3535
>
3636
<CalendarNavigation
37-
month={calendar.cursor.getMonth()}
38-
year={calendar.cursor.getFullYear()}
37+
date={calendar.cursor}
38+
onClickNextDay={calendar.nextDay}
39+
onClickPrevDay={calendar.prevDay}
3940
onClickNextMonth={calendar.nextMonth}
4041
onClickNextYear={calendar.nextYear}
4142
onClickPrevMonth={calendar.prevMonth}
4243
onClickPrevYear={calendar.prevYear}
4344
/>
44-
<CalendarSidebar date={calendar.cursor} />
45+
<CalendarSidebar
46+
date={calendar.cursor}
47+
nextDay={calendar.nextDay}
48+
prevDay={calendar.prevDay}
49+
/>
4550
<StyledCalendarDaysFrame frameColor={accentColor}>
4651
<StyledCalendarDays
4752
borderColor={accentColor}

src/programs/Calendar/CalendarNavigation/CalendarNavigation.tsx

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { getMonthName } from "../../../common/utils/dateUtils";
1+
import {
2+
getDateOrdinal,
3+
getDayName,
4+
getMonthName,
5+
} from "../../../common/utils/dateUtils";
26
import Button from "../../../components/Button";
37
import useSystemSettings from "../../../stores/systemSettingsStore";
48
import {
@@ -7,16 +11,18 @@ import {
711
} from "./styles";
812

913
interface StyledNavigationProps {
10-
month: number;
11-
year: number;
14+
date: Date;
15+
onClickPrevDay(): void;
16+
onClickNextDay(): void;
1217
onClickPrevMonth(): void;
1318
onClickNextMonth(): void;
1419
onClickPrevYear(): void;
1520
onClickNextYear(): void;
1621
}
1722
export default function CalendarNavigation({
18-
month,
19-
year,
23+
date,
24+
onClickNextDay,
25+
onClickPrevDay,
2026
onClickNextMonth,
2127
onClickNextYear,
2228
onClickPrevMonth,
@@ -26,6 +32,9 @@ export default function CalendarNavigation({
2632
s.fontColor,
2733
s.mainColor,
2834
]);
35+
const day = date.getDate();
36+
const month = date.getMonth();
37+
const year = date.getFullYear();
2938
return (
3039
<StyledCalendarNavigation className="calendar__nav">
3140
<StyledCalendarNavigationSection className="calendar__nav-section">
@@ -71,6 +80,28 @@ export default function CalendarNavigation({
7180
group="horizontal"
7281
>{`>`}</Button>
7382
</StyledCalendarNavigationSection>
83+
84+
<StyledCalendarNavigationSection className="calendar__nav-section">
85+
<Button
86+
backgroundColor={buttonColor}
87+
color={fontColor}
88+
onClick={onClickPrevDay}
89+
group="horizontal"
90+
>{`<`}</Button>
91+
<Button
92+
backgroundColor={buttonColor}
93+
color={fontColor}
94+
group="horizontal"
95+
>
96+
{`${getDayName(date)} ${getDateOrdinal(day)}`}
97+
</Button>
98+
<Button
99+
backgroundColor={buttonColor}
100+
color={fontColor}
101+
onClick={onClickNextDay}
102+
group="horizontal"
103+
>{`>`}</Button>
104+
</StyledCalendarNavigationSection>
74105
</StyledCalendarNavigation>
75106
);
76107
}

src/programs/Calendar/CalendarNavigation/styles.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ interface StyledCalendarNavigationProps {}
66
export const StyledCalendarNavigation = styled.div<StyledCalendarNavigationProps>`
77
width: 100%;
88
display: grid;
9-
grid-template-columns: 1fr 1fr;
9+
grid-template-columns: 1fr 1fr 1fr;
1010
gap: 20px;
1111
grid-area: nav;
12-
padding: 6px 0;
12+
padding-bottom: 5px;
1313
`;
1414

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

src/programs/Calendar/CalendarSidebar/CalendarSidebar.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ import { StyledCalendarSidebar } from "./styles";
33

44
interface CalendarSidebarProps {
55
date: Date;
6+
prevDay(): void;
7+
nextDay(): void;
68
}
79

8-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
9-
export default function CalendarSidebar({ date }: CalendarSidebarProps) {
10-
// const events = useCalendarEvents({ date });
10+
// eslint-disable-next-line no-empty-pattern
11+
export default function CalendarSidebar({}: CalendarSidebarProps) {
1112
return (
12-
<StyledCalendarSidebar className="calendar__side-bar">
13-
{date.toISOString()}
14-
</StyledCalendarSidebar>
13+
<StyledCalendarSidebar className="calendar__side-bar"></StyledCalendarSidebar>
1514
);
1615
}

src/programs/Calendar/hooks/useCalendar.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ interface CalendarDay {
1010
export function useCalendar() {
1111
const [cursor, setCursor] = useState(startOfDay(new Date()));
1212

13+
const nextDay = () =>
14+
setCursor((d) => new Date(d.getFullYear(), d.getMonth(), d.getDate() + 1));
15+
16+
const prevDay = () =>
17+
setCursor((d) => new Date(d.getFullYear(), d.getMonth(), d.getDate() - 1));
18+
1319
const nextMonth = () =>
1420
setCursor((d) => new Date(d.getFullYear(), d.getMonth() + 1, d.getDate()));
1521

@@ -50,6 +56,8 @@ export function useCalendar() {
5056
useEffect(() => setDays(getCalendarDays), [cursor, getCalendarDays]);
5157

5258
return {
59+
prevDay,
60+
nextDay,
5361
prevMonth,
5462
nextMonth,
5563
prevYear,

src/programs/Calendar/styles.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ export const StyledCalendarLayout = styled.div<StyledCalendarLayoutProps>`
1212
/* flex-direction: column; */
1313
box-sizing: border-box;
1414
grid-template-areas:
15-
"nav nav side"
15+
"nav nav nav"
1616
"days days side"
1717
"days days side";
18-
grid-template-rows: 50px 1fr 1fr;
18+
grid-template-rows: 40px 1fr 1fr;
1919
grid-template-columns: 1fr 1fr minmax(150px, 1fr);
2020
`;
2121

0 commit comments

Comments
 (0)