Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions packages/core/src/runtime/root.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ if (import.meta.hot) {

const showGrid = ref(false)
const gridGap = ref(8)
const zoom = ref(1)

const colorMode = useColorMode()
const hooks = shallowRef<Hookable<CompodiumHooks>>()
Expand All @@ -70,6 +71,7 @@ onMounted(() => {
showGrid.value = payload.enabled
gridGap.value = payload.gap
})
hooks.value.hook('renderer:zoom', scale => zoom.value = scale)

hooks.value.hook('renderer:set-color', color => colorMode.value = color)
hooks.value.callHook('renderer:mounted')
Expand All @@ -90,22 +92,24 @@ onMounted(() => {
id="__compodium-root"
:style="{ position: 'relative', minWidth: '100vw', minHeight: '100vh' }"
>
<PreviewComponent>
<RendererWrapper :wrapper="wrapper">
<RendererCombo
:combo="combo"
:props
#="{ props: comboProps }"
>
<component
:is="component"
v-if="component"
v-bind="comboProps"
v-on="eventHandlers"
/>
</RendererCombo>
</RendererWrapper>
</PreviewComponent>
<div :style="{ transform: `scale(${zoom})`, transformOrigin: 'center' }">

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this extra div? I feel like these styles can be applied to the one above

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there's an overflow when zooming above 100%

Image

<PreviewComponent>
<RendererWrapper :wrapper="wrapper">
<RendererCombo
:combo="combo"
:props
#="{ props: comboProps }"
>
<component
:is="component"
v-if="component"
v-bind="comboProps"
v-on="eventHandlers"
/>
</RendererCombo>
</RendererWrapper>
</PreviewComponent>
</div>

<RendererGrid
v-if="showGrid"
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ export interface CompodiumHooks {

// Toggle the renderer grid
'renderer:grid': (payload: { enabled: boolean, gap: number }) => void

// Scale the rendered component without scaling the devtools UI
'renderer:zoom': (scale: number) => void
}

declare global {
Expand Down
29 changes: 29 additions & 0 deletions packages/devtools/app/pages/components.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ import { getEnumOptions } from '~/utils/enum'

const { hooks } = useCompodiumClient()
const rendererMounted = ref(false)
const zoom = ref(1)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This zoom factor should also apply to the grid gap

      <RendererGrid
        v-if="showGrid"
        v-model:gap="scaledGridGap" <-- gridGap * zoom / 100 
      />

const zoomMin = 0.25
const zoomMax = 4
const zoomStep = 0.25

function updateZoom(value: number) {
zoom.value = Math.min(zoomMax, Math.max(zoomMin, value))
hooks.callHook('renderer:zoom', zoom.value)
}

const events = ref<{ name: string, data?: any }[]>([])

Expand All @@ -32,6 +41,7 @@ hooks.hook('renderer:mounted', () => {
})

updateComponent()
updateZoom(zoom.value)
})

const { data: collections, refresh: refreshCollections } = useAsyncData(async () => {
Expand Down Expand Up @@ -224,6 +234,25 @@ const tabs = computed(() => {
</div>

<div class="flex gap-2 justify-end">
<UInputNumber

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this to the left side of the preview, the right side feels a bit too crowded with it

v-model="zoom"
:min="zoomMin"
:max="zoomMax"
:step="zoomStep"
:format-options="{ style: 'percent' }"
:disabled="!rendererMounted"
color="neutral"
variant="none"
size="sm"
aria-label="Component zoom"
class="w-28"
:ui="{
root: 'rounded-full border border-default bg-default',
base: 'rounded-full tabular-nums'
}"
@update:model-value="updateZoom"
/>

<UTooltip
text="Open docs"
:content="{ side: 'left' }"
Expand Down
Loading