Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add RenderWhen component (#616)
- Loading branch information
Showing
8 changed files
with
46 additions
and
3 deletions.
There are no files selected for viewing
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,29 @@ | ||
<script setup lang="ts"> | ||
import { computed, inject } from 'vue' | ||
import type { RenderContext } from '@slidev/types' | ||
import { injectionSlideContext } from '../constants' | ||
type Context = 'main' | RenderContext | ||
const props = defineProps<{ | ||
context: Context | Context[] | ||
}>() | ||
const { context } = props | ||
const currentContext = inject(injectionSlideContext) | ||
const shouldRender = computed(() => context instanceof Array ? context.some(contextMatch) : contextMatch(context)) | ||
function contextMatch(context: Context) { | ||
if (context === currentContext) | ||
return true | ||
if (context === 'main' && (currentContext === 'slide' || currentContext === 'presenter')) | ||
return true | ||
return false | ||
} | ||
</script> | ||
|
||
<template> | ||
<slot v-if="shouldRender" /> | ||
</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
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
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