- Install the required dependencies:
npm install date-fns react-dnd react-dnd-html5-backend react-dnd-touch-backend- Create new file use-mobile.ts at
@/hooks:
import { useState, useEffect } from "react"
const MOBILE_BREAKPOINT = 768
export function useIsMobile(breakpoint: number = MOBILE_BREAKPOINT) {
const [isMobile, setIsMobile] = useState<boolean | undefined>(undefined)
useEffect(() => {
const mql = window.matchMedia(`(max-width: ${breakpoint - 1}px)`)
const onChange = () => {
setIsMobile(window.innerWidth < breakpoint)
}
mql.addEventListener("change", onChange)
setIsMobile(window.innerWidth < breakpoint)
return () => mql.removeEventListener("change", onChange)
}, []);
return !!isMobile
}- Copy and paste the following code into your project calendar-timeline.tsx
The following Shadcn UI components are required:
import {
useTimeline,
TimelineProvider,
TimelineControl,
TimelineContent,
TimelineHeader,
TimelineRows
} from '@/components/calendar-timeline';
function Component() {
const timeline = useTimeline({
// configuration here...
});
return (
<TimelineProvider context={timeline}>
<TimelineControl>
{/* your action controls */}
</TimelineControl>
<TimelineContent className='max-h-[30rem]'>
<TimelineHeader />
<TimelineRows />
</TimelineContent>
</TimelineProvider>
)
}This project is licensed under the MIT License. See the LICENSE file for details.