Skip to content

Commit

Permalink
feat: a few new layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Apr 25, 2021
1 parent 427be4f commit e1c12d1
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 9 deletions.
26 changes: 26 additions & 0 deletions packages/client/layoutHelper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { CSSProperties } from 'vue'

export function handleBackground(background?: string, dim = false): CSSProperties {
const isColor = background && background[0] === '#' && background.startsWith('rgb')

return {
background: isColor
? background
: background
? undefined
: 'white',
color: (background && !isColor)
? 'white'
: undefined,
backgroundImage: isColor
? undefined
: background
? dim
? `linear-gradient(#0005, #0008), url(${background})`
: `url(${background})`
: undefined,
backgroundRepeat: 'no-repeat',
backgroundPosition: 'center',
backgroundSize: 'cover',
}
}
24 changes: 24 additions & 0 deletions packages/client/layouts/image-left.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<script setup lang="ts">
import { computed, defineProps } from 'vue'
import { handleBackground } from '../layoutHelper'
const props = defineProps({
image: {
type: String,
},
class: {
type: String,
},
})
const style = computed(() => handleBackground(props.image))
</script>

<template>
<main class="grid grid-cols-2 w-full h-full">
<div class="w-full w-full" :style="style"></div>
<div class="layout-master default" :class="props.class">
<slot />
</div>
</main>
</template>
24 changes: 24 additions & 0 deletions packages/client/layouts/image-right.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<script setup lang="ts">
import { computed, defineProps } from 'vue'
import { handleBackground } from '../layoutHelper'
const props = defineProps({
image: {
type: String,
},
class: {
type: String,
},
})
const style = computed(() => handleBackground(props.image))
</script>

<template>
<main class="grid grid-cols-2 w-full h-full">
<div class="layout-master default" :class="props.class">
<slot />
</div>
<div class="w-full w-full" :style="style"></div>
</main>
</template>
5 changes: 4 additions & 1 deletion packages/create-app/template/slides.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ Hover on the bottom-left corner to see the navigation's controls panel
/>
<p v-after class="absolute bottom-23 left-45 opacity-30 transform -rotate-10">Here!</p>

----
---
layout: image-right
image: 'https://source.unsplash.com/collection/94734566/1920x1080'
---

# Code

Expand Down
10 changes: 2 additions & 8 deletions packages/theme-seriph/layouts/cover.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script setup lang="ts">
import { handleBackground } from '@slidev/client/layoutHelper'
import { defineProps, computed } from 'vue'
const props = defineProps({
Expand All @@ -8,14 +9,7 @@ const props = defineProps({
},
})
const style = computed(() => ({
background: !props.background && 'white',
color: props.background && 'white',
backgroundImage: props.background && `linear-gradient(#0005, #0008), url(${props.background})`,
backgroundRepeat: 'no-repeat',
backgroundPosition: 'center',
backgroundSize: 'cover',
}) as any)
const style = computed(() => handleBackground(props.background, true))
</script>

<template>
Expand Down

0 comments on commit e1c12d1

Please sign in to comment.