MCPcopy Create free account
hub / github.com/Codehagen/Badget / ChartAreaInteractive

Function ChartAreaInteractive

src/components/chart-area-interactive.tsx:143–292  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

141} satisfies ChartConfig
142
143export function ChartAreaInteractive() {
144 const isMobile = useIsMobile()
145 const [timeRange, setTimeRange] = React.useState("90d")
146
147 React.useEffect(() => {
148 if (isMobile) {
149 setTimeRange("7d")
150 }
151 }, [isMobile])
152
153 const filteredData = chartData.filter((item) => {
154 const date = new Date(item.date)
155 const referenceDate = new Date("2024-06-30")
156 let daysToSubtract = 90
157 if (timeRange === "30d") {
158 daysToSubtract = 30
159 } else if (timeRange === "7d") {
160 daysToSubtract = 7
161 }
162 const startDate = new Date(referenceDate)
163 startDate.setDate(startDate.getDate() - daysToSubtract)
164 return date >= startDate
165 })
166
167 return (
168 <Card className="@container/card">
169 <CardHeader>
170 <CardTitle>Total Visitors</CardTitle>
171 <CardDescription>
172 <span className="hidden @[540px]/card:block">
173 Total for the last 3 months
174 </span>
175 <span className="@[540px]/card:hidden">Last 3 months</span>
176 </CardDescription>
177 <CardAction>
178 <ToggleGroup
179 type="single"
180 value={timeRange}
181 onValueChange={setTimeRange}
182 variant="outline"
183 className="hidden *:data-[slot=toggle-group-item]:!px-4 @[767px]/card:flex"
184 >
185 <ToggleGroupItem value="90d">Last 3 months</ToggleGroupItem>
186 <ToggleGroupItem value="30d">Last 30 days</ToggleGroupItem>
187 <ToggleGroupItem value="7d">Last 7 days</ToggleGroupItem>
188 </ToggleGroup>
189 <Select value={timeRange} onValueChange={setTimeRange}>
190 <SelectTrigger
191 className="flex w-40 **:data-[slot=select-value]:block **:data-[slot=select-value]:truncate @[767px]/card:hidden"
192 size="sm"
193 aria-label="Select a value"
194 >
195 <SelectValue placeholder="Last 3 months" />
196 </SelectTrigger>
197 <SelectContent className="rounded-xl">
198 <SelectItem value="90d" className="rounded-lg">
199 Last 3 months
200 </SelectItem>

Callers

nothing calls this directly

Calls 1

useIsMobileFunction · 0.90

Tested by

no test coverage detected