Skip to content

Commit

Permalink
docd(playground): update panelSizes when titleHeightPercent changed (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nieyuyao committed Jun 19, 2022
1 parent 8426174 commit 1097c5b
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions playground/src/components/Editor.vue
Expand Up @@ -15,16 +15,25 @@ const TITLE_HEIGHT = 34
const { height: vh } = useElementSize(panel)
const titleHeightPercent = computed(() => TITLE_HEIGHT / vh.value * 100)
const getInitialPanelSizes = (percent: number): number[] => {
return [
100 - percent * 2,
percent,
percent,
]
}
if (!inputHTML.value)
inputHTML.value = defaultHTML
if (!customConfigRaw.value)
customConfigRaw.value = defaultConfigRaw
const panelSizes = useStorage<number[]>('unocss-panel-sizes', [
100 - titleHeightPercent.value * 2,
titleHeightPercent.value,
titleHeightPercent.value,
], localStorage, { listenToStorageChanges: false })
const panelSizes = useStorage<number[]>(
'unocss-panel-sizes',
getInitialPanelSizes(titleHeightPercent.value),
localStorage,
{ listenToStorageChanges: false },
)
function handleResize(event: ({ size: number })[]) {
panelSizes.value = event.map(({ size }) => size)
Expand Down Expand Up @@ -80,6 +89,13 @@ const formatted = computed(() => {
}
})
watch(
titleHeightPercent,
(value: number) => {
panelSizes.value = getInitialPanelSizes(value)
},
)
onMounted(() => {
// prevent init transition
setTimeout(() => {
Expand Down

0 comments on commit 1097c5b

Please sign in to comment.