feat(frontend): fix text resize

This commit is contained in:
Faton Ramadani
2023-03-06 13:40:07 +01:00
parent 94e30052bf
commit 2060445d20
3 changed files with 24 additions and 25 deletions
@@ -27,6 +27,7 @@
let result: string | undefined = undefined
let style: 'Title' | 'Subtitle' | 'Body' | 'Caption' | 'Label' | undefined = undefined
let copyButton: boolean
let fitContent = false
function getComponent() {
switch (style) {
@@ -64,9 +65,10 @@
<InputValue {id} input={configuration.style} bind:value={style} />
<InputValue {id} input={configuration.copyButton} bind:value={copyButton} />
<InputValue {id} input={configuration.fitContent} bind:value={fitContent} />
<RunnableWrapper flexWrap {componentInput} {id} bind:initializing bind:result>
<ResizeWrapper {id}>
<ResizeWrapper {id} shouldWrap={fitContent}>
<AlignWrapper {horizontalAlignment} {verticalAlignment}>
{#if !result || result === ''}
<div class="text-gray-400 bg-gray-100 flex justify-center items-center h-full w-full">
@@ -2,38 +2,31 @@
import { getContext } from 'svelte'
import { findGridItem } from '../../editor/appUtils'
import type { AppEditorContext } from '../../types'
import gridHelp from '@windmill-labs/svelte-grid/src/utils/helper'
export let id: string
const { app } = getContext<AppEditorContext>('AppEditorContext')
export let shouldWrap: boolean = false
const { app, breakpoint } = getContext<AppEditorContext>('AppEditorContext')
$: gridItem = findGridItem($app, id)
let wrapper: HTMLElement
$: {
if (wrapper && gridItem) {
if (wrapper && gridItem && shouldWrap) {
const wrapperHeight = wrapper.getBoundingClientRect().height
const parentHeight = wrapper.parentElement?.getBoundingClientRect().height
console.log(wrapperHeight, parentHeight)
if (parentHeight && wrapperHeight > parentHeight) {
gridItem[12].h = Math.ceil(wrapperHeight / 36)
gridItem = gridItem
}
if (parentHeight && wrapperHeight < parentHeight) {
gridItem[12].h = Math.floor(parentHeight / 36)
gridItem = gridItem
}
const width = $breakpoint === 'sm' ? 3 : 12
gridItem[width].h = Math.ceil(wrapperHeight / 36)
gridItem = gridItem
}
}
$: console.log(shouldWrap)
</script>
<div bind:this={wrapper}>
{#if shouldWrap}
<div bind:this={wrapper}>
<slot />
</div>
{:else}
<slot />
</div>
{/if}
@@ -228,6 +228,12 @@ export const components: Record<AppComponent['type'], AppComponentConfig> = {
value: false,
fieldType: 'boolean',
onlyStatic: true
},
fitContent: {
type: 'static',
value: false,
fieldType: 'boolean',
onlyStatic: true
}
},
customCss: {
@@ -912,9 +918,7 @@ Hello \${ctx.username}
type: 'static',
fieldType: 'array',
subFieldType: 'text',
value: [
"Foo", "Bar"
]
value: ['Foo', 'Bar']
},
placeholder: {
type: 'static',