This commit is contained in:
2026-06-24 16:52:08 +02:00
commit 5abeb4fd48
53 changed files with 276551 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
'use client'
import { FormControl, FormErrorMessage, FormLabel, Input, InputProps } from '@chakra-ui/react'
import { useField } from 'formik'
type Props = React.InputHTMLAttributes<HTMLInputElement> & { name: string, label: string, isTextArea?: boolean } & InputProps
export const InputField: React.FC<Props> = ({size: _, isTextArea=false, ...props}) => {
const [field, { error }] = useField(props)
const { label, placeholder } = props
return (
<FormControl isInvalid={!!error}>
<FormLabel htmlFor={field.name}>{label}</FormLabel>
<Input {...field} {...props} id={field.name} placeholder={placeholder} />
{error ? <FormErrorMessage>{error}</FormErrorMessage> : null}
</FormControl>
)
}
+36
View File
@@ -0,0 +1,36 @@
'use client'
import { FormControl, FormErrorMessage, FormLabel, Textarea, TextareaProps } from '@chakra-ui/react'
import autosize from 'autosize'
import { useField } from 'formik'
import { useRef, useEffect } from 'react'
type Props = React.TextareaHTMLAttributes<HTMLTextAreaElement> & { name: string, label: string } & TextareaProps
export const TextareaField: React.FC<Props> = (props): JSX.Element => {
const [field, { error }] = useField(props)
const { label, placeholder } = props
// https://github.com/chakra-ui/chakra-ui/issues/670
const ref: any = useRef()
useEffect(() => {
const current = ref.current
autosize(current)
return () => {
autosize.destroy(current)
}
}, [])
return (
<FormControl isInvalid={!!error}>
<FormLabel htmlFor={field.name}>{label}</FormLabel>
<Textarea
{...field}
{...props}
ref={ref}
id={field.name}
placeholder={placeholder}
/>
{error ? <FormErrorMessage>{error}</FormErrorMessage> : null}
</FormControl>
)
}
+75
View File
@@ -0,0 +1,75 @@
'use client'
// ChatGPT-generated
import { Line } from 'react-chartjs-2'
import { Chart as ChartJS, TimeScale, LinearScale, PointElement, LineElement, Tooltip, Legend } from 'chart.js'
import 'chartjs-adapter-date-fns'
import { Entry } from '@/constants'
// Register required chart components
ChartJS.register(TimeScale, LinearScale, PointElement, LineElement, Tooltip, Legend)
export const TripCountChart = ({ data }: { data: Entry[] }) => {
const chartData = {
labels: data.map((entry) => entry.time),
datasets: [
{
label: 'Trip Count',
data: data.map((entry) => entry.trip_count),
fill: false,
borderColor: 'rgba(75,192,192,1)',
tension: 0.1,
segment: {
borderColor: (ctx: any) => {
const dataIndex = ctx.p0DataIndex // Starting index of the segment
const totalPoints = data.length
const threeQuarterIndex = Math.floor(totalPoints * 0.75)
// Use a different color after 3/4 of the x-axis
return dataIndex >= threeQuarterIndex
? 'rgba(255,99,132,1)' // Different color after 3/4
: 'rgba(75,192,192,1)' // Default color for the first 3/4
},
},
},
],
}
const options = {
scales: {
x: {
type: 'time',
time: {
unit: 'hour',
tooltipFormat: 'PPpp',
displayFormats: {
hour: 'MMM d, yyyy HH:mm',
},
},
title: {
display: true,
text: 'Time (Hour)',
},
},
y: {
beginAtZero: true,
title: {
display: true,
text: 'Trip Count',
},
},
},
plugins: {
tooltip: {
callbacks: {
label: function (context: any) {
return `Trip Count: ${context.raw}`
},
},
},
},
}
return <Line data={chartData} options={options as any} />
}
export default TripCountChart
+14
View File
@@ -0,0 +1,14 @@
import { Box } from '@chakra-ui/react'
interface Props {
children?: React.ReactNode
variant?: 'small' | 'regular'
}
export const Wrapper: React.FC<Props> = ({ children, variant = 'regular' }) => {
return (
<Box w='100%' maxW={variant == 'small' ? 400 : 800} mt={8} mx='auto'>
{children}
</Box>
)
}
+4
View File
@@ -0,0 +1,4 @@
export * from './Wrapper'
export * from './TripCountChart'
export * from './InputField'
export * from './TextareaField'