AI-native design editor. Open-source Figma alternative.
feat(layout): text auto-resize control in Layout section
Danila Poyarkov14d4a17a33a5
diff --git a/packages/vue/src/i18n/messages/panels.ts b/packages/vue/src/i18n/messages/panels.tsindex 234fa2c67..9a7dcae61 100644--- a/packages/vue/src/i18n/messages/panels.ts+++ b/packages/vue/src/i18n/messages/panels.ts@@ -246,6 +246,10 @@ export const panelMessageDefaults = {setToCurrentHeight: 'Set to current height',sizingFillFr: 'Fill (fr)',sizingFixedPx: 'Fixed (px)',+ resizing: 'Resizing',+ resizeAutoWidth: 'Auto width',+ resizeAutoHeight: 'Auto height',+ resizeFixed: 'Fixed size',searchFonts: 'Search fonts...'} as constdiff --git a/src/components/properties/LayoutSection/LayoutSection.vue b/src/components/properties/LayoutSection/LayoutSection.vueindex 9939fac2e..80b577097 100644--- a/src/components/properties/LayoutSection/LayoutSection.vue+++ b/src/components/properties/LayoutSection/LayoutSection.vue@@ -7,6 +7,7 @@ import FlexControls from '@/components/properties/LayoutSection/FlexControls.vueimport GridControls from '@/components/properties/LayoutSection/GridControls.vue'import PaddingControls from '@/components/properties/LayoutSection/PaddingControls.vue'import SizeControls from '@/components/properties/LayoutSection/size/SizeControls.vue'+import TextResizingControl from '@/components/properties/LayoutSection/TextResizingControl.vue'import SharedStyleField from '@/components/properties/shared-style/SharedStyleField.vue'import PanelSection from '@/components/ui/panel/PanelSection.vue'@@ -20,6 +21,7 @@ const CONTAINER_TYPES = ['FRAME', 'COMPONENT', 'COMPONENT_SET', 'INSTANCE']<template v-if="ctx.node"><PanelSection :label="panels.layout"><SharedStyleField kind="grid" :label="panels.gridStyle" />+ <TextResizingControl v-if="ctx.node.type === 'TEXT'" /><SizeControls /></PanelSection>diff --git a/src/components/properties/LayoutSection/TextResizingControl.vue b/src/components/properties/LayoutSection/TextResizingControl.vuenew file mode 100644index 000000000..207bcad47--- /dev/null+++ b/src/components/properties/LayoutSection/TextResizingControl.vue@@ -0,0 +1,59 @@+<script setup lang="ts">+import { computed } from 'vue'+import { useI18n, useLayoutControlsContext } from '@open-pencil/vue'++import SegmentedControl from '@/components/ui/SegmentedControl.vue'+import PanelFieldGroup from '@/components/ui/panel/PanelFieldGroup.vue'+import Tip from '@/components/ui/Tip.vue'++import type { SceneNode } from '@open-pencil/scene-graph'++type TextResizeMode = 'AUTO_WIDTH' | 'AUTO_HEIGHT' | 'FIXED'++const ctx = useLayoutControlsContext()+const { panels } = useI18n()++function modeFor(node: SceneNode | null): TextResizeMode {+ if (node?.textAutoResize === 'WIDTH_AND_HEIGHT') return 'AUTO_WIDTH'+ if (node?.textAutoResize === 'HEIGHT' || node?.textAutoResize === 'TRUNCATE') return 'AUTO_HEIGHT'+ return 'FIXED'+}++const mode = computed<TextResizeMode>(() => modeFor(ctx.node))++const options = computed(() => [+ { value: 'AUTO_WIDTH' as const, label: panels.value.resizeAutoWidth },+ { value: 'AUTO_HEIGHT' as const, label: panels.value.resizeAutoHeight },+ { value: 'FIXED' as const, label: panels.value.resizeFixed }+])++function setMode(value: TextResizeMode) {+ const node = ctx.node+ if (!node) return+ const byMode: Record<TextResizeMode, SceneNode['textAutoResize']> = {+ AUTO_WIDTH: 'WIDTH_AND_HEIGHT',+ AUTO_HEIGHT: 'HEIGHT',+ FIXED: 'NONE'+ }+ ctx.editor.updateNodeWithUndo(node.id, { textAutoResize: byMode[value] }, 'Set text resizing')+}+</script>++<template>+ <PanelFieldGroup :label="panels.resizing">+ <SegmentedControl+ :model-value="mode"+ :options="options"+ :label="panels.resizing"+ @change="setMode($event as TextResizeMode)"+ >+ <template #option="{ option }">+ <Tip :label="option.label" class="flex items-center justify-center">+ <icon-lucide-move-horizontal v-if="option.value === 'AUTO_WIDTH'" class="size-3.5" />+ <icon-lucide-wrap-text v-else-if="option.value === 'AUTO_HEIGHT'" class="size-3.5" />+ <icon-lucide-lock v-else class="size-3.5" />+ </Tip>+ </template>+ </SegmentedControl>+ </PanelFieldGroup>+</template>