align number field

pull/220/head^2
Pete Matsyburka 2 years ago
parent f6691c110e
commit 95899336b8

@ -157,6 +157,7 @@
ref="textContainer" ref="textContainer"
dir="auto" dir="auto"
class="flex items-center px-0.5 w-full" class="flex items-center px-0.5 w-full"
:class="alignClasses[field.preferences?.align]"
> >
<span v-if="Array.isArray(modelValue)"> <span v-if="Array.isArray(modelValue)">
{{ modelValue.join(', ') }} {{ modelValue.join(', ') }}
@ -167,6 +168,7 @@
<span <span
v-else v-else
class="whitespace-pre-wrap" class="whitespace-pre-wrap"
:class="{ 'w-full': field.preferences?.align }"
>{{ modelValue }}</span> >{{ modelValue }}</span>
</div> </div>
</div> </div>
@ -253,6 +255,13 @@ export default {
phone: this.t('phone') phone: this.t('phone')
} }
}, },
alignClasses () {
return {
center: 'text-center',
left: 'text-left',
right: 'text-right'
}
},
option () { option () {
return this.field.options.find((o) => o.uuid === this.area.option_uuid) return this.field.options.find((o) => o.uuid === this.area.option_uuid)
}, },

@ -99,7 +99,7 @@
<div <div
class="flex items-center h-full w-full" class="flex items-center h-full w-full"
dir="auto" dir="auto"
:class="[bgColors[submitterIndex], field?.default_value ? '' : 'justify-center']" :class="[bgColors[submitterIndex], field?.default_value ? (alignClasses[field.preferences?.align] || '') : 'justify-center']"
> >
<span <span
v-if="field" v-if="field"
@ -211,6 +211,13 @@ export default {
defaultName () { defaultName () {
return this.buildDefaultName(this.field, this.template.fields) return this.buildDefaultName(this.field, this.template.fields)
}, },
alignClasses () {
return {
center: 'justify-center',
left: 'justify-start',
right: 'justify-end'
}
},
optionIndexText () { optionIndexText () {
if (this.area.option_uuid && this.field.options) { if (this.area.option_uuid && this.field.options) {
return `${this.field.options.findIndex((o) => o.uuid === this.area.option_uuid) + 1}.` return `${this.field.options.findIndex((o) => o.uuid === this.area.option_uuid) + 1}.`

@ -115,6 +115,32 @@
@dragstart.prevent.stop @dragstart.prevent.stop
@click="closeDropdown" @click="closeDropdown"
> >
<div
v-if="['number'].includes(field.type)"
class="py-1.5 px-1 relative"
@click.stop
>
<select
class="select select-bordered select-xs w-full max-w-xs h-7 !outline-0 font-normal"
@change="[field.preferences ||= {}, field.preferences.align = $event.target.value, save()]"
>
<option
v-for="value in ['left', 'right', 'center']"
:key="value"
:selected="field.preferences?.align ? value === field.preferences.align : value === 'left'"
:value="value"
>
{{ t(value) }}
</option>
</select>
<label
:style="{ backgroundColor: backgroundColor }"
class="absolute -top-1 left-2.5 px-1 h-4"
style="font-size: 8px"
>
{{ t('align') }}
</label>
</div>
<div <div
v-if="['text', 'number'].includes(field.type) && !defaultField" v-if="['text', 'number'].includes(field.type) && !defaultField"
class="py-1.5 px-1 relative" class="py-1.5 px-1 relative"

@ -1,4 +1,8 @@
const en = { const en = {
align: 'Align',
left: 'Left',
right: 'Right',
center: 'Center',
description: 'Description', description: 'Description',
display_title: 'Display title', display_title: 'Display title',
with_logo: 'With logo', with_logo: 'With logo',

@ -1,4 +1,5 @@
<field-value dir="auto" class="flex absolute text-[1.5vw] lg:text-base" style="width: <%= area['w'] * 100 %>%; height: <%= area['h'] * 100 %>%; left: <%= area['x'] * 100 %>%; top: <%= area['y'] * 100 %>%"> <% align = field.dig('preferences', 'align') %>
<field-value dir="auto" class="flex absolute text-[1.5vw] lg:text-base <%= align == 'right' ? 'justify-end' : (align == 'center' ? 'justify-center' : '') %>" style="width: <%= area['w'] * 100 %>%; height: <%= area['h'] * 100 %>%; left: <%= area['x'] * 100 %>%; top: <%= area['y'] * 100 %>%">
<% if field['type'].in?(['signature', 'image', 'initials', 'stamp']) %> <% if field['type'].in?(['signature', 'image', 'initials', 'stamp']) %>
<img class="object-contain mx-auto" src="<%= attachments_index[value].url %>" loading="lazy"> <img class="object-contain mx-auto" src="<%= attachments_index[value].url %>" loading="lazy">
<% elsif field['type'].in?(['file', 'payment']) %> <% elsif field['type'].in?(['file', 'payment']) %>

@ -75,8 +75,10 @@ module Submissions
value = submitter.values[field['uuid']] value = submitter.values[field['uuid']]
layouter = HexaPDF::Layout::TextLayouter.new(text_valign: :center, text_align = field.dig('preferences', 'align').to_s.to_sym.presence ||
text_align: value.to_s.match?(RTL_REGEXP) ? :right : :left, (value.to_s.match?(RTL_REGEXP) ? :right : :left)
layouter = HexaPDF::Layout::TextLayouter.new(text_valign: :center, text_align:,
font: pdf.fonts.add(FONT_NAME), font_size:) font: pdf.fonts.add(FONT_NAME), font_size:)
next if Array.wrap(value).compact_blank.blank? next if Array.wrap(value).compact_blank.blank?
@ -202,15 +204,23 @@ module Submissions
font: pdf.fonts.add(FONT_NAME), font: pdf.fonts.add(FONT_NAME),
font_size: (font_size / 1.4).to_i) font_size: (font_size / 1.4).to_i)
lines = layouter.fit([text], area['w'] * width, height).lines lines = layouter.fit([text], field['type'].in?(%w[date number]) ? width : area['w'] * width, height).lines
box_height = lines.sum(&:height) box_height = lines.sum(&:height)
end end
height_diff = [0, box_height - (area['h'] * height)].max height_diff = [0, box_height - (area['h'] * height)].max
layouter.fit([text], area['w'] * width, height_diff.positive? ? box_height : area['h'] * height) right_align_x_adjustment =
.draw(canvas, (area['x'] * width) + TEXT_LEFT_MARGIN, if field['type'].in?(%w[date number]) && text_align != :left
(width - (area['w'] * width)) / (text_align == :center ? 2.0 : 1)
else
0
end
layouter.fit([text], field['type'].in?(%w[date number]) ? width : area['w'] * width,
height_diff.positive? ? box_height : area['h'] * height)
.draw(canvas, (area['x'] * width) - right_align_x_adjustment + TEXT_LEFT_MARGIN,
height - (area['y'] * height) + height_diff - TEXT_TOP_MARGIN) height - (area['y'] * height) + height_diff - TEXT_TOP_MARGIN)
end end
end end

Loading…
Cancel
Save