Skip to content

AI-native design editor. Open-source Figma alternative.

2.3 KB
Raw Blame
<script setup lang="ts">
import { computed } from 'vue'

import { useI18n } from '@open-pencil/vue/i18n'
import { useLayoutControlsContext } from '@open-pencil/vue/primitives/LayoutControls'

import SizeAxisField from '@/components/properties/layout/size/SizeAxisField.vue'
import SizeLimitField from '@/components/properties/layout/size/SizeLimitField.vue'
import type { SizeLimitItem } from '@/components/properties/layout/size/types'
import IconButton from '@/components/ui/button/IconButton.vue'
import PanelGrid from '@/components/ui/panel/PanelGrid.vue'

const ctx = useLayoutControlsContext()
const { panels } = useI18n()

const sizeLimits = computed<SizeLimitItem[]>(() => [
  {
    prop: 'minWidth',
    icon: panels.value.minWidthShort,
    label: panels.value.minWidthShort,
    setLabel: panels.value.setToCurrentWidth,
    removeLabel: panels.value.removeMinWidth
  },
  {
    prop: 'maxWidth',
    icon: panels.value.maxWidthShort,
    label: panels.value.maxWidthShort,
    setLabel: panels.value.setToCurrentWidth,
    removeLabel: panels.value.removeMaxWidth
  },
  {
    prop: 'minHeight',
    icon: panels.value.minHeightShort,
    label: panels.value.minHeightShort,
    setLabel: panels.value.setToCurrentHeight,
    removeLabel: panels.value.removeMinHeight
  },
  {
    prop: 'maxHeight',
    icon: panels.value.maxHeightShort,
    label: panels.value.maxHeightShort,
    setLabel: panels.value.setToCurrentHeight,
    removeLabel: panels.value.removeMaxHeight
  }
])

const visibleSizeLimits = computed(() =>
  sizeLimits.value.filter((item) => ctx.node[item.prop] != null)
)
</script>

<template>
  <PanelGrid :columns="1">
    <SizeAxisField axis="width" icon="W" :label="panels.width" />
    <SizeAxisField axis="height" icon="H" :label="panels.height" />
    <template v-if="ctx.aspectRatioLockable" #actions>
      <IconButton
        :label="panels.lockAspectRatio"
        size="xs"
        toggle
        :active="ctx.aspectRatioLocked"
        data-test-id="aspect-ratio-lock"
        @click="ctx.toggleAspectRatioLock"
      >
        <icon-lucide-proportions class="size-3" />
      </IconButton>
    </template>
  </PanelGrid>

  <PanelGrid v-if="visibleSizeLimits.length" :columns="2" class="mt-1.5">
    <SizeLimitField v-for="item in visibleSizeLimits" :key="item.prop" :item="item" />
  </PanelGrid>
</template>