File tree Expand file tree Collapse file tree 6 files changed +86
-16
lines changed
Expand file tree Collapse file tree 6 files changed +86
-16
lines changed Original file line number Diff line number Diff line change 1- import { PropsWithChildren } from "react" ;
1+ import { forwardRef , PropsWithChildren , useCallback } from "react" ;
22import { StyledButton , StyledButtonProps } from "./styles" ;
33
44interface ButtonProps extends StyledButtonProps {
55 onClick ?: ( ) => void ;
66 disabled ?: boolean ;
77}
88
9- function Button ( {
10- onClick,
11- children,
12- ...rest
13- } : PropsWithChildren < ButtonProps > ) {
14- return (
15- < StyledButton { ...rest } onClick = { onClick } >
16- { children }
17- </ StyledButton >
18- ) ;
19- }
9+ const Button = forwardRef < HTMLButtonElement , PropsWithChildren < ButtonProps > > (
10+ ( { onClick, children, ...rest } , ref ) => {
11+ 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+ } ,
19+ [ ref ] ,
20+ ) ;
21+ return (
22+ < StyledButton { ...rest } onClick = { onClick } ref = { onRef } >
23+ { children }
24+ </ StyledButton >
25+ ) ;
26+ } ,
27+ ) ;
28+
2029export default Button ;
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ export const StyledCalc = styled.div`
1212 /* padding: 5px; */
1313 border-radius: 10px;
1414 box-sizing: border-box;
15- gap: 10px ;
15+ gap: 5px ;
1616` ;
1717
1818export const StyledInputOutput = styled . div < {
@@ -38,6 +38,7 @@ export const StyledInputOutputContents = styled.div`
3838 text-shadow: 2px 2px 4px rgb(0, 0, 0, 0.5);
3939 overflow-x: auto;
4040 width: 100%;
41+ text-align: end;
4142` ;
4243
4344export const StyledButtons = styled . div `
Original file line number Diff line number Diff line change 11// import useCalendarEvents from "../hooks/useCalendarEvents";
2- import { StyledCalendarSidebar } from "./styles" ;
2+ import { useRef } from "react" ;
3+ import CalendarTimeSlot from "../CalendarTimeSlot/CalendarTimeSlot" ;
4+ import { StyledCalendarSidebar , StyledDayBreak } from "./styles" ;
5+ import useSystemSettings from "../../../stores/systemSettingsStore" ;
36
47interface CalendarSidebarProps {
58 date : Date ;
@@ -9,7 +12,16 @@ interface CalendarSidebarProps {
912
1013// eslint-disable-next-line no-empty-pattern
1114export default function CalendarSidebar ( { } : CalendarSidebarProps ) {
15+ const ref = useRef < HTMLDivElement > ( null ) ;
16+ const [ breakColor ] = useSystemSettings ( ( s ) => [ s . secondaryColor ] ) ;
1217 return (
13- < StyledCalendarSidebar className = "calendar__side-bar" > </ StyledCalendarSidebar >
18+ < StyledCalendarSidebar className = "calendar__side-bar" ref = { ref } >
19+ { Array . from ( { length : 25 } ) . map ( ( _ , i ) => (
20+ < >
21+ < CalendarTimeSlot hour = { i } />
22+ { i < 24 && < StyledDayBreak color = { breakColor } /> }
23+ </ >
24+ ) ) }
25+ </ StyledCalendarSidebar >
1426 ) ;
1527}
Original file line number Diff line number Diff line change @@ -3,7 +3,18 @@ import styled from "@emotion/styled";
33interface StyledCalendarSidebarProps { }
44export const StyledCalendarSidebar = styled . div < StyledCalendarSidebarProps > `
55 width: 100%;
6- max-width: 300px;
76 height: 100%;
87 grid-area: side;
8+ overflow: auto;
9+ padding-left: 6px;
10+ box-sizing: border-box;
11+ ` ;
12+
13+ interface StyledDayBreakProps {
14+ color : string ;
15+ }
16+ export const StyledDayBreak = styled . hr < StyledDayBreakProps > `
17+ width: 100%;
18+ margin: 0;
19+ background-color: ${ ( p ) => p . color } ;
920` ;
Original file line number Diff line number Diff line change 1+ import { useCallback , useRef } from "react" ;
2+ import useSystemSettings from "../../../stores/systemSettingsStore" ;
3+ import Button from "../../../components/Button" ;
4+
5+ interface CalendarTimeSlotProps {
6+ hour : number ;
7+ }
8+
9+ export default function CalendarTimeSlot ( { hour } : CalendarTimeSlotProps ) {
10+ const currentHour = useRef ( new Date ( ) . getHours ( ) ) ;
11+ const [ backgroundColor , fontColor ] = useSystemSettings ( ( s ) => [
12+ s . mainColor ,
13+ s . fontColor ,
14+ ] ) ;
15+
16+ const onRef = useCallback (
17+ ( el : null | HTMLButtonElement ) => {
18+ if ( el && hour === currentHour . current ) {
19+ el . scrollIntoView ( ) ;
20+ }
21+ } ,
22+ [ currentHour , hour ] ,
23+ ) ;
24+
25+ return (
26+ < Button
27+ borderRadius = { 0 }
28+ height = { 60 }
29+ backgroundColor = { backgroundColor }
30+ color = { fontColor }
31+ justifyContent = "start"
32+ ref = { onRef }
33+ >
34+ { hour . toString ( ) . padStart ( 2 , "0" ) } :00
35+ </ Button >
36+ ) ;
37+ }
You can’t perform that action at this time.
0 commit comments