Skip to content

Commit

Permalink
Add Tabs/Tab
Browse files Browse the repository at this point in the history
  • Loading branch information
baku89 committed Sep 29, 2023
1 parent b288644 commit 7d355c4
Show file tree
Hide file tree
Showing 7 changed files with 375 additions and 68 deletions.
122 changes: 54 additions & 68 deletions src/components/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import MonacoEditor, {ErrorInfo} from './MonacoEditor.vue'
import OverlayColorPicker from './OverlayColorPicker.vue'
import OverlayNumberSlider from './OverlayNumberSlider.vue'
import OverlayPointHandle from './OverlayPointHandle.vue'
import {Tab, Tabs} from './Tabs'
const {appStorage} = provideAppStorage('com.baku89.paperjs-editor')
Expand Down Expand Up @@ -332,47 +333,42 @@ window.addEventListener('drop', async e => {
/>
</div>
<FloatingPane name="inspector" icon="code">
<div class="inspector">
<div class="actions">
<Tabs class="inspector-tab" name="inspector.tab">
<template #before-tablist>
<button class="play" @click="autoRefresh = !autoRefresh">
<span class="material-symbols-outlined">{{
autoRefresh ? 'pause_circle' : 'play_circle'
}}</span>
{{ autoRefresh ? 'Pause' : 'Resume' }}
</button>
<div class="spacer" />
<button @click="copyCanvasAsSVG">
<span class="material-symbols-outlined">content_copy</span>
</button>
<button @click="pasteSVGToCanvas">
<span class="material-symbols-outlined">content_paste</span>
</button>
<button @click="saveProject">
<span class="material-symbols-outlined">download</span>
</button>
</div>
<div class="editor-wrapper">
<MonacoEditor
v-model="code"
v-model:cursorIndex="cursorIndex"
v-model:cursorPosition="cursorPosition"
class="editor"
:errors="errors"
/>
<OverlayColorPicker
v-model:code="code"
v-model:visible="colorPickerVisible"
:cursor-index="cursorIndex"
:cursor-position="cursorPosition"
/>
<OverlayNumberSlider
v-show="!colorPickerVisible"
v-model:code="code"
v-model:cursorIndex="cursorIndex"
:cursor-position="cursorPosition"
/>
</div>
</div>
</template>
<Tab name="Settings">
<div>Settings</div>
</Tab>
<Tab name="Code" class="inspector">
<div class="editor-wrapper">
<MonacoEditor
v-model="code"
v-model:cursorIndex="cursorIndex"
v-model:cursorPosition="cursorPosition"
class="editor"
:errors="errors"
/>
<OverlayColorPicker
v-model:code="code"
v-model:visible="colorPickerVisible"
:cursor-index="cursorIndex"
:cursor-position="cursorPosition"
/>
<OverlayNumberSlider
v-show="!colorPickerVisible"
v-model:code="code"
v-model:cursorIndex="cursorIndex"
:cursor-position="cursorPosition"
/>
</div>
</Tab>
</Tabs>
</FloatingPane>
</main>
</div>
Expand Down Expand Up @@ -448,47 +444,37 @@ window.addEventListener('drop', async e => {
background-image radial-gradient(circle at 0 0, var(--dot-color) 1px, transparent 0), linear-gradient(to bottom, var(--axis-color) 1px, transparent 0), linear-gradient(to right, var(--axis-color) 1px, transparent 0)
background-repeat repeat, repeat-x, repeat-y
.inspector-tab
height 100%
.play
display inline-flex
justify-content center
align-items center
background var(--ui-button)
color var(--ui-color)
width 32px
height 32px
border-radius 9999px
vertical-align middle
padding 0 6px
gap .4em
transition all ease .2s
width auto
padding 0 12px 0 6px
background var(--ui-color)
color var(--ui-bg)
&:hover
background var(--ui-accent)
color var(--ui-bg)
.inspector
position relative
height 100%
display flex
flex-direction column
gap 1rem
.actions
display flex
align-items center
gap 0.5rem
.spacer
flex-grow 1
button
display inline-flex
justify-content center
align-items center
background var(--ui-button)
color var(--ui-color)
width 32px
height 32px
border-radius 9999px
vertical-align middle
padding 0 6px
gap .4em
transition all ease .2s
&.play
width auto
padding 0 12px 0 6px
background var(--ui-color)
color var(--ui-bg)
&:hover
background var(--ui-accent)
color var(--ui-bg)
.editor-wrapper
position relative
flex-grow 1
Expand Down
81 changes: 81 additions & 0 deletions src/components/Tabs/Tab.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<script setup lang="ts">
import {
computed,
defineProps,
onBeforeMount,
onBeforeUnmount,
watch,
withDefaults,
} from 'vue'
import {AddTabKey, DeleteTabKey, TabsProviderKey, UpdateTabKey} from './symbols'
import {injectStrict} from './utils'
type Props = {
id?: string
name: string
isDisabled?: boolean
}
const props = withDefaults(defineProps<Props>(), {
id: undefined,
isDisabled: false,
})
const tabsProvider = injectStrict(TabsProviderKey)
const addTab = injectStrict(AddTabKey)
const updateTab = injectStrict(UpdateTabKey)
const deleteTab = injectStrict(DeleteTabKey)
const id = computed(() =>
props.id ? props.id : props.name.toLowerCase().replace(/ /g, '-')
)
const paneId = computed(() => id.value + '-pane')
const isActive = computed(() => id.value === tabsProvider.activeId)
watch(
() => Object.assign({}, props),
() => {
updateTab(id.value, {
name: props.name,
isDisabled: props.isDisabled,
id: id.value,
paneId: paneId.value,
})
}
)
onBeforeMount(() => {
addTab({
name: props.name,
isDisabled: props.isDisabled,
id: id.value,
paneId: paneId.value,
})
})
onBeforeUnmount(() => {
deleteTab(id.value)
})
</script>

<template>
<section
v-show="isActive"
:id="paneId"
ref="tab"
class="Tab"
:data-tab-id="id"
:aria-hidden="!isActive"
role="tabpanel"
tabindex="-1"
>
<slot />
</section>
</template>

<style lang="stylus" scoped>
.Tab
height 100%
</style>
Loading

0 comments on commit 7d355c4

Please sign in to comment.