From 3414b1b282b2cbd856353dc6a941313dcba166cb Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Fri, 29 Apr 2022 15:15:09 +0800 Subject: [PATCH] feat: add tabs component Signed-off-by: Ryan Wang --- src/components/base/tabs/TabItem.vue | 24 ++++++++- src/components/base/tabs/Tabbar.story.vue | 14 ++--- src/components/base/tabs/Tabbar.vue | 18 +++---- src/components/base/tabs/Tabs.story.vue | 49 ++++++++++++++++++ src/components/base/tabs/Tabs.vue | 62 ++++++++++++++++++++++- 5 files changed, 147 insertions(+), 20 deletions(-) create mode 100644 src/components/base/tabs/Tabs.story.vue diff --git a/src/components/base/tabs/TabItem.vue b/src/components/base/tabs/TabItem.vue index 4be8a44f..8041c248 100644 --- a/src/components/base/tabs/TabItem.vue +++ b/src/components/base/tabs/TabItem.vue @@ -1,5 +1,25 @@ - + diff --git a/src/components/base/tabs/Tabbar.story.vue b/src/components/base/tabs/Tabbar.story.vue index b033864f..e6faa8ab 100644 --- a/src/components/base/tabs/Tabbar.story.vue +++ b/src/components/base/tabs/Tabbar.story.vue @@ -3,11 +3,11 @@ import { VTabbar } from "./index"; function initState() { return { - active: "johnniang", + activeId: "johnniang", items: [ - { label: "Ryan Wang", value: "ryanwang" }, - { label: "JohnNiang", value: "johnniang" }, - { label: "guqing", value: "guqing" }, + { label: "Ryan Wang", id: "ryanwang" }, + { label: "JohnNiang", id: "johnniang" }, + { label: "guqing", id: "guqing" }, ], }; } @@ -16,20 +16,20 @@ function initState() { diff --git a/src/components/base/tabs/Tabbar.vue b/src/components/base/tabs/Tabbar.vue index d45b0754..0d28352c 100644 --- a/src/components/base/tabs/Tabbar.vue +++ b/src/components/base/tabs/Tabbar.vue @@ -4,7 +4,7 @@ import { computed } from "vue"; import type { Type } from "./interface"; const props = defineProps({ - active: { + activeId: { type: [Number, String], }, items: { @@ -14,9 +14,9 @@ const props = defineProps({ type: String as PropType, default: "default", }, - valueKey: { + idKey: { type: String, - default: "value", + default: "id", }, labelKey: { type: String, @@ -24,15 +24,15 @@ const props = defineProps({ }, }); -const emit = defineEmits(["update:active", "change"]); +const emit = defineEmits(["update:activeId", "change"]); const classes = computed(() => { return [`tabbar-${props.type}`]; }); -const handleChange = (value: number | string) => { - emit("update:active", value); - emit("change", value); +const handleChange = (id: number | string) => { + emit("update:activeId", id); + emit("change", id); };