|
| 1 | +<script setup lang="ts"> |
| 2 | +import { computed, ref } from 'vue' |
| 3 | +import { useLocalStorage } from '@vueuse/core' |
| 4 | +import { Pane, Splitpanes } from 'splitpanes' |
| 5 | +
|
| 6 | +import 'splitpanes/dist/splitpanes.css' |
| 7 | +
|
| 8 | +const props = withDefaults(defineProps<{ |
| 9 | + /** |
| 10 | + * The key to use for storing the pane sizes in localStorage. |
| 11 | + */ |
| 12 | + storageKey?: string |
| 13 | + stateKey?: string |
| 14 | + leftSize?: number |
| 15 | + minSize?: number |
| 16 | + horizontal?: boolean |
| 17 | +}>(), { |
| 18 | + stateKey: 'nuxt-devtools-panels-state', |
| 19 | +}) |
| 20 | +
|
| 21 | +const state = useLocalStorage<Record<string, number>>(props.stateKey, {} as any, { listenToStorageChanges: false }) |
| 22 | +
|
| 23 | +const DEFAULT = 30 |
| 24 | +
|
| 25 | +const key = props.storageKey |
| 26 | +const size = key |
| 27 | + ? computed({ |
| 28 | + get: () => state.value[key] || props.leftSize || DEFAULT, |
| 29 | + set: (v) => { state.value[key] = v }, |
| 30 | + }) |
| 31 | + : ref(props.leftSize || DEFAULT) |
| 32 | +</script> |
| 33 | + |
| 34 | +<template> |
| 35 | + <Splitpanes :horizontal="horizontal" h-full of-hidden @resize="size = $event[0].size"> |
| 36 | + <Pane h-full class="of-auto!" :size="size" :min-size="$slots.right ? (minSize || 10) : 100"> |
| 37 | + <slot name="left" /> |
| 38 | + </Pane> |
| 39 | + <Pane v-if="$slots.right" relative h-full class="of-auto!" :min-size="minSize || 10"> |
| 40 | + <slot name="right" /> |
| 41 | + </Pane> |
| 42 | + </Splitpanes> |
| 43 | +</template> |
| 44 | + |
| 45 | +<style> |
| 46 | +.splitpanes__splitter { |
| 47 | + position: relative; |
| 48 | +} |
| 49 | +.splitpanes__splitter:before { |
| 50 | + position: absolute; |
| 51 | + left: 0; |
| 52 | + top: 0; |
| 53 | + transition: .2s ease; |
| 54 | + content: ''; |
| 55 | + transition: opacity 0.4s; |
| 56 | + z-index: 1; |
| 57 | +} |
| 58 | +.splitpanes__splitter:hover:before { |
| 59 | + background: #8881; |
| 60 | + opacity: 1; |
| 61 | +} |
| 62 | +.splitpanes--vertical>.splitpanes__splitter { |
| 63 | + min-width: 0 !important; |
| 64 | + width: 0 !important; |
| 65 | + @apply border-r border-base |
| 66 | +} |
| 67 | +.splitpanes--horizontal>.splitpanes__splitter { |
| 68 | + min-height: 0 !important; |
| 69 | + height: 0 !important; |
| 70 | + @apply border-t border-base |
| 71 | +} |
| 72 | +.splitpanes--vertical>.splitpanes__splitter:before { |
| 73 | + left: -5px; |
| 74 | + right: -4px; |
| 75 | + height: 100%; |
| 76 | +} |
| 77 | +.splitpanes--horizontal>.splitpanes__splitter:before { |
| 78 | + top: -5px; |
| 79 | + bottom: -4px; |
| 80 | + width: 100%; |
| 81 | +} |
| 82 | +</style> |
0 commit comments