From 5b0f43248a8166fcbb5c1e69c174db03c772bfba Mon Sep 17 00:00:00 2001 From: zernonia Date: Tue, 5 Dec 2023 15:06:53 +0800 Subject: [PATCH] feat: improve generic props --- .../registry/default/ui/chart-area/AreaChart.vue | 7 +++++-- .../lib/registry/default/ui/chart-bar/BarChart.vue | 14 +++++++++----- .../registry/default/ui/chart-donut/DonutChart.vue | 8 ++++++-- .../registry/default/ui/chart-line/LineChart.vue | 7 +++++-- .../registry/new-york/ui/chart-area/AreaChart.vue | 7 +++++-- .../registry/new-york/ui/chart-bar/BarChart.vue | 7 +++++-- .../new-york/ui/chart-donut/DonutChart.vue | 8 ++++++-- .../registry/new-york/ui/chart-line/LineChart.vue | 7 +++++-- 8 files changed, 46 insertions(+), 19 deletions(-) diff --git a/apps/www/src/lib/registry/default/ui/chart-area/AreaChart.vue b/apps/www/src/lib/registry/default/ui/chart-area/AreaChart.vue index adad26a8..9b975ef9 100644 --- a/apps/www/src/lib/registry/default/ui/chart-area/AreaChart.vue +++ b/apps/www/src/lib/registry/default/ui/chart-area/AreaChart.vue @@ -15,11 +15,11 @@ const props = withDefaults(defineProps<{ /** * Select the categories from your data. Used to populate the legend and toolip. */ - categories: string[] + categories: KeyOfT[] /** * Sets the key to map the data to the axis. */ - index: string + index: KeyOfT /** * Change the default colors. */ @@ -77,7 +77,10 @@ const props = withDefaults(defineProps<{ showGradiant: true, }) +type KeyOfT = Extract type Data = typeof props.data[number] + +const index = computed(() => props.index as KeyOfT) const colors = computed(() => props.colors?.length ? props.colors : defaultColors(props.categories.length)) const legendItems = ref(props.categories.map((category, i) => ({ diff --git a/apps/www/src/lib/registry/default/ui/chart-bar/BarChart.vue b/apps/www/src/lib/registry/default/ui/chart-bar/BarChart.vue index eae765d4..2439cbcc 100644 --- a/apps/www/src/lib/registry/default/ui/chart-bar/BarChart.vue +++ b/apps/www/src/lib/registry/default/ui/chart-bar/BarChart.vue @@ -15,11 +15,11 @@ const props = withDefaults(defineProps<{ /** * Select the categories from your data. Used to populate the legend and toolip. */ - categories: string[] + categories: Array /** * Sets the key to map the data to the axis. */ - index: string + index: KeyOfT /** * Change the default colors. */ @@ -77,6 +77,10 @@ const props = withDefaults(defineProps<{ showGridLine: true, }) +type KeyOfT = Extract +type Data = typeof props.data[number] + +const index = computed(() => props.index as KeyOfT) const colors = computed(() => props.colors?.length ? props.colors : defaultColors(props.categories.length)) const legendItems = ref(props.categories.map((category, i) => ({ name: category, @@ -102,14 +106,14 @@ const selectorsBar = computed(() => props.type === 'grouped' ? GroupedBar.select