add tabs to demos

This commit is contained in:
Philipp Kühn
2021-03-19 18:36:27 +01:00
parent 7a20640872
commit 40f14f904c
6 changed files with 126 additions and 33 deletions

View File

@@ -5,16 +5,18 @@
<template v-if="mainFile"> <template v-if="mainFile">
<demo-frame class="demo__preview" v-bind="props" /> <demo-frame class="demo__preview" v-bind="props" />
<div class="demo__source" v-if="showSource"> <div class="demo__source" v-if="showSource">
<div class="demo__tabs" v-if="showFileNames"> <div class="demo__scroller" v-if="showFileNames">
<button <div class="demo__tabs">
class="demo__tab" <button
:class="{ 'is-active': currentIndex === index}" class="demo__tab"
v-for="(file, index) in files" :class="{ 'is-active': currentIndex === index}"
:key="index" v-for="(file, index) in files"
@click="currentIndex = index" :key="index"
> @click="currentIndex = index"
{{ file.name }} >
</button> {{ file.name }}
</button>
</div>
</div> </div>
<div class="demo__code" v-if="activeFile" :key="activeFile.path"> <div class="demo__code" v-if="activeFile" :key="activeFile.path">
<!-- eslint-disable-next-line --> <!-- eslint-disable-next-line -->

View File

@@ -18,33 +18,42 @@
background-color: $colorBlack; background-color: $colorBlack;
} }
&__tabs { &__scroller {
padding: 0.5rem 1.25rem 0 1.25rem; display: flex;
background-color: rgba($colorBlack, 0.9);
white-space: nowrap;
overflow-x: auto; overflow-x: auto;
-webkit-overflow-scrolling: touch; -webkit-overflow-scrolling: touch;
} }
&__tabs {
display: flex;
flex: 1 1 auto;
padding: 0 1.25rem 0 1.25rem;
border-bottom: 2px solid rgba($colorWhite, 0.1);
}
&__tab { &__tab {
position: relative;
display: inline-flex; display: inline-flex;
position: relative; position: relative;
background-color: transparent; background-color: transparent;
color: rgba($colorWhite, 0.7); color: rgba($colorWhite, 0.7);
padding: 0.1rem 0.5rem; padding: 0.3rem 0 calc(0.3rem + 2px) 0;
border-radius: 5px; font: inherit;
font-weight: 500; font-family: "JetBrainsMono", monospace;
font-size: 0.85rem;
border: none; border: none;
margin-right: 0.5rem; margin-right: 1rem;
margin-bottom: -2px;
&:first-child { border-bottom: 2px solid transparent;
margin-left: -0.5rem;
}
&.is-active, &.is-active,
&:hover { &:hover {
color: $colorWhite; color: $colorWhite;
background-color: rgba($colorWhite, 0.1); }
&.is-active {
font-weight: 700;
border-bottom-color: $colorWhite
} }
} }

View File

@@ -0,0 +1,83 @@
<template>
<div class="demos" :class="{ 'is-first-active': selectedIndex === 0 }">
<button
class="demos__tab"
:class="{ 'is-active': selectedIndex === index }"
v-for="(item, index) in formattedItems"
:key="index"
@click="selectedIndex = index"
>
{{ item.title }}
</button>
<demo
:name="selectedItem.name"
:key="selectedItem.title"
/>
</div>
</template>
<script>
import Demo from '@/components/Demo'
export default {
components: {
Demo,
},
props: {
items: {
type: Object,
required: true,
},
},
data() {
return {
selectedIndex: 0,
}
},
computed: {
formattedItems() {
return Object
.entries(this.items)
.map(([title, name]) => {
return {
title,
name,
}
})
},
selectedItem() {
return this.formattedItems[this.selectedIndex]
},
},
}
</script>
<style lang="scss" scoped>
.demos {
&__tab {
border-radius: 0.4rem 0.4rem 0 0;
border: none;
background: none;
padding: 0.3rem 1.25rem;
font: inherit;
font-weight: 700;
font-size: 0.75rem;
text-transform: uppercase;
letter-spacing: 0.025rem;
&.is-active {
background-color: $colorBlack;
color: $colorWhite;
font-weight: 700;
}
}
&.is-first-active ::v-deep .demo {
border-top-left-radius: 0;
}
}
</style>

View File

@@ -1,7 +1,6 @@
# Suggestions # Suggestions
## Vue <demos :items="{
<demo name="Examples/Community/Vue" /> Vue: 'Examples/Community/Vue',
React: 'Examples/Community/React',
## React }" />
<demo name="Examples/Community/React" />

View File

@@ -1,8 +1,7 @@
# Default text editor # Default text editor
Did we mention that you have full control over the rendering of the editor? Here is barebones example without any styling, but packed with a whole set of common extensions. Did we mention that you have full control over the rendering of the editor? Here is barebones example without any styling, but packed with a whole set of common extensions.
## Vue <demos :items="{
<demo name="Examples/Default/Vue" /> Vue: 'Examples/Default/Vue',
React: 'Examples/Default/React',
## React }" />
<demo name="Examples/Default/React" />

View File

@@ -51,4 +51,5 @@ export default function (Vue) {
Vue.component('Layout', App) Vue.component('Layout', App)
Vue.component('Demo', () => import(/* webpackChunkName: "demo" */ '~/components/Demo')) Vue.component('Demo', () => import(/* webpackChunkName: "demo" */ '~/components/Demo'))
Vue.component('Demos', () => import(/* webpackChunkName: "demos" */ '~/components/Demos'))
} }