extended-41
originui-vue/extended-41FreeComponent
Originui Vue publishes no description for this item.
Install it
npx shadcn@latest add https://originui-vue.com/r/extended-41.jsonSource
1<script setup lang="ts">2import {3 ContributionGraph,4 ContributionGraphBlock,5 ContributionGraphGroup,6} from "@/registry/default/ui/contribution-graph";78const generateData = () => {9 const days = [];10 const startDate = new Date();11 startDate.setMonth(startDate.getMonth() - 12);1213 for (let i = 0; i < 364; i++) {14 const currentDate = new Date(startDate);15 currentDate.setDate(startDate.getDate() + i);1617 const count = Math.floor(Math.random() * 13);1819 days.push({20 date: currentDate.toISOString().split("T")[0],21 count: count,22 });23 }24 return days;25};2627const data = ref(generateData());2829const weeks = computed(() => {30 const result = [];31 for (let i = 0; i < data.value.length; i += 7) {32 result.push(data.value.slice(i, i + 7));33 }34 return result;35});3637const getLevel = (count: number) => {38 if (count === 0) return 0;39 if (count <= 2) return 1;40 if (count <= 4) return 2;41 if (count <= 6) return 3;42 if (count <= 8) return 4;43 if (count <= 10) return 5;44 return 6;45};4647const colors = [48 "bg-muted",49 "bg-sky-200 dark:bg-sky-900/30",50 "bg-sky-300 dark:bg-sky-900/50",51 "bg-sky-400 dark:bg-sky-800/60",52 "bg-sky-500 dark:bg-sky-600/70",53 "bg-sky-600 dark:bg-sky-500/80",54 "bg-sky-700 dark:bg-sky-400",55];5657const monthLabels = computed(() => {58 let lastMonth = -1;5960 return weeks.value.map((week) => {61 const firstDay = week[0];62 if (firstDay?.date) {63 const firstDayOfWeek = new Date(firstDay.date);64 const month = firstDayOfWeek.getMonth();6566 if (month !== lastMonth) {67 lastMonth = month;68 return firstDayOfWeek.toLocaleString("en-US", { month: "short" });69 }70 }71 return "";72 });73});7475const totalActivities = computed(() => {76 return data.value.reduce((sum, day) => sum + day.count, 0);77});78</script>7980<template>81 <div class="flex flex-col items-center justify-center">82 <div>83 <div class="mb-1 flex gap-1">84 <div85 v-for="(label, index) in monthLabels"86 :key="index"87 class="text-muted-foreground w-3 text-xs"88 >89 {{ label }}90 </div>91 </div>92 <ContributionGraph class="flex gap-1">93 <ContributionGraphGroup v-for="(week, weekIndex) in weeks" :key="weekIndex">94 <ContributionGraphBlock95 v-for="(day, dayIndex) in week"96 :key="dayIndex"97 :colors="colors"98 :level="getLevel(day.count)"99 :title="`${day.count} contributions on ${day.date}`"100// … truncated
Files it writes
More from Originui Vue
All 58 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| contribution-graphcontribution-graph | Originui Vue | Components | Free | no deps · 4 files | |
| emptyempty | Originui Vue | Components | Free | no deps · 7 files | |
| extended-01extended-01 | Originui Vue | Components | Free | no deps | |
| extended-02extended-02 | Originui Vue | Components | Free | no deps | |
| extended-03extended-03 | Originui Vue | Components | Free | no deps | |
| extended-04extended-04 | Originui Vue | Components | Free | no deps | |
| extended-05extended-05 | Originui Vue | Components | Free | no deps | |
| extended-06extended-06 | Originui Vue | Components | Free | no deps |
