-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jeroen Nijhuis
committed
Jan 2, 2024
1 parent
c8f8d21
commit b8e4ef4
Showing
10 changed files
with
177 additions
and
23 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { | ||
provide, | ||
reactive, | ||
InjectionKey, | ||
toRefs, | ||
ToRefs, | ||
shallowRef, | ||
} from "vue"; | ||
|
||
export const TabProviderStateKey: InjectionKey<ToRefs<TabProviderState>> = | ||
Symbol("TabProviderState"); | ||
export const TabProviderAddTabKey: InjectionKey< | ||
(id: string, title: string, component: any, props?: any) => void | ||
> = Symbol("TabProviderAddTab"); | ||
export const TabProviderCloseTabKey: InjectionKey<(id: string) => void> = | ||
Symbol("TabProviderCloseTab"); | ||
|
||
export interface Tab { | ||
id: string; | ||
title: string; | ||
component: any; | ||
props?: any; | ||
} | ||
|
||
export interface TabProviderState { | ||
tabs: Tab[]; | ||
activeTabId: string | null; | ||
} | ||
|
||
export default { | ||
setup() { | ||
const state: TabProviderState = reactive({ | ||
tabs: [], | ||
activeTabId: null, | ||
}); | ||
|
||
provide(TabProviderStateKey, toRefs(state)); | ||
|
||
const addTab = (id: string, title: string, component: any, props?: any) => { | ||
if (state.tabs.find((tab) => tab.id === id)) { | ||
state.activeTabId = id; | ||
return; | ||
} | ||
|
||
state.tabs.push({ | ||
id, | ||
title, | ||
component: shallowRef(component), | ||
props, | ||
}); | ||
|
||
state.activeTabId = id; | ||
}; | ||
|
||
const closeTab = (id: string) => { | ||
const tabIndex = state.tabs.findIndex((tab) => tab.id === id); | ||
|
||
if (tabIndex !== -1) { | ||
state.tabs.splice(tabIndex, 1); | ||
} | ||
}; | ||
|
||
provide(TabProviderAddTabKey, addTab); | ||
provide(TabProviderCloseTabKey, closeTab); | ||
}, | ||
render(): any { | ||
return this.$slots.default(); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<script setup lang="ts"> | ||
const props = defineProps<{ | ||
context: string; | ||
namespace: string; | ||
pod: string; | ||
}>(); | ||
</script> | ||
<template> | ||
<div>Logs for {{ props }}</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters