From 6856cb936cac89caa5cba61a5c2f6a4126c6281b Mon Sep 17 00:00:00 2001 From: MattiasSp Date: Mon, 22 Feb 2021 13:21:42 +0100 Subject: [PATCH 01/11] Expose print control header config options --- src/controls/print/index.js | 18 ++++++++-- src/controls/print/print-component.js | 18 +++++++--- src/controls/print/print-settings.js | 52 ++++++++++++++++++--------- src/controls/print/title-control.js | 36 ++++++++++--------- 4 files changed, 83 insertions(+), 41 deletions(-) diff --git a/src/controls/print/index.js b/src/controls/print/index.js index d820609e7..23e1af202 100644 --- a/src/controls/print/index.js +++ b/src/controls/print/index.js @@ -7,6 +7,10 @@ const Print = function Print(options = {}) { logo = {}, northArrow = {}, title = 'Skriv ut', + headerText = '', + headerPlaceholderText = 'Här kan du skriva en rubrik', + headerAlignment = 'center', + headerSizes = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'], leftFooterText = '', showCreated = false, createdPrefix = '', @@ -17,6 +21,8 @@ const Print = function Print(options = {}) { filename } = options; let { + headerSize = 'h4', + headerFormatIsVisible = false, showNorthArrow = true } = options; @@ -36,9 +42,16 @@ const Print = function Print(options = {}) { const printComponent = PrintComponent({ logo, northArrow, - target: viewer.getId(), + filename, map: viewer.getMap(), + target: viewer.getId(), viewer, + title: headerText, + titlePlaceholderText: headerPlaceholderText, + titleAlignment: headerAlignment, + titleSizes: headerSizes, + titleSize: headerSize, + titleFormatIsVisible: headerFormatIsVisible, leftFooterText, showCreated, createdPrefix, @@ -46,8 +59,7 @@ const Print = function Print(options = {}) { scales, showScale, classes, - defaultClass, - filename + defaultClass }); mapMenu = viewer.getControlByName('mapmenu'); menuItem = mapMenu.MenuItem({ diff --git a/src/controls/print/print-component.js b/src/controls/print/print-component.js index 6fd999ae4..91eabf152 100644 --- a/src/controls/print/print-component.js +++ b/src/controls/print/print-component.js @@ -19,6 +19,9 @@ const PrintComponent = function PrintComponent(options = {}) { map, target, viewer, + titlePlaceholderText, + titleAlignment, + titleSizes, leftFooterText, createdPrefix, scales, @@ -27,6 +30,9 @@ const PrintComponent = function PrintComponent(options = {}) { } = options; let { + title, + titleSize, + titleFormatIsVisible, size = 'a4', orientation = 'portrait', showCreated, @@ -40,9 +46,7 @@ const PrintComponent = function PrintComponent(options = {}) { let targetElement; const pageContainerId = cuid(); const pageId = cuid(); - let title = ''; - let titleSize = 'h4'; - let titleAlign = 'text-align-center'; + let titleAlign = `text-align-${titleAlignment}`; let description = ''; let descriptionSize = 'h4'; let descriptionAlign = 'text-align-center'; @@ -117,11 +121,17 @@ const PrintComponent = function PrintComponent(options = {}) { }; const printSettings = PrintSettings({ + map, + title, + titlePlaceholderText, + titleAlignment, + titleSizes, + titleSize, + titleFormatIsVisible, orientation, customSize: sizes.custom, initialSize: size, sizes: Object.keys(sizes), - map, showCreated, showNorthArrow, scales, diff --git a/src/controls/print/print-settings.js b/src/controls/print/print-settings.js index 272f9cabf..b4f4f094a 100644 --- a/src/controls/print/print-settings.js +++ b/src/controls/print/print-settings.js @@ -15,22 +15,33 @@ import SetScaleControl from './set-scale-control'; import ResolutionControl from './resolution-control'; import ShowScaleControl from './show-scale-control'; -const PrintSettings = function PrintSettings({ - closeIcon = '#ic_close_24px', - initialSize, - openIcon = '#ic_tune_24px', - orientation = 'portrait', - customSize, - sizes, - map, - showCreated, - showNorthArrow, - scales, - resolution = 150, - showScale, - classes, - defaultClass -} = {}) { +const PrintSettings = function PrintSettings(options = {}) { + const { + closeIcon = '#ic_close_24px', + openIcon = '#ic_tune_24px', + map, + title, + titlePlaceholderText, + titleAlignment, + titleSizes, + initialSize, + customSize, + sizes, + orientation = 'portrait', + showCreated, + showNorthArrow, + scales, + resolution = 150, + showScale, + classes, + defaultClass + } = options; + + let { + titleSize, + titleFormatIsVisible + } = options; + let headerComponent; let contentComponent; let openButton; @@ -96,7 +107,14 @@ const PrintSettings = function PrintSettings({ const orientationControl = OrientationControl({ orientation }); const sizeControl = SizeControl({ initialSize, sizes }); - const titleControl = TitleControl({ classes, size: defaultClass }); + const titleControl = TitleControl({ + title, + titlePlaceholderText, + titleAlignment, + titleSizes, + titleSize, + titleFormatIsVisible + }); const descriptionControl = DescriptionControl({ classes, size: defaultClass }); const marginControl = MarginControl({ checked: true }); const createdControl = CreatedControl({ checked: showCreated }); diff --git a/src/controls/print/title-control.js b/src/controls/print/title-control.js index f8aeac132..1fce3f833 100644 --- a/src/controls/print/title-control.js +++ b/src/controls/print/title-control.js @@ -2,19 +2,21 @@ import { Input, cuid, Component, Button, Dropdown, ToggleGroup } from '../../ui' export default function TitleControl(options = {}) { const { - title = '', - alignment = 'center', - classes = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] + title, + titlePlaceholderText, + titleAlignment, + titleSizes } = options; + let { - size = 'h4' + titleSize, + titleFormatIsVisible } = options; + const cls = 'placeholder-text-smaller smaller'; - const placeholderText = 'Här kan du skriva en rubrik'; const style = { height: '2rem', margin: 0, width: '16rem' }; const align = ['text-align-left', 'text-align-center', 'text-align-right']; const formatId = cuid(); - let isVisible = false; let formatEl; let inputTitle; let formatButton; @@ -30,7 +32,7 @@ export default function TitleControl(options = {}) { inputTitle = Input({ cls, style, - placeholderText, + placeholderText: titlePlaceholderText, value: title }); formatButton = Button({ @@ -42,19 +44,19 @@ export default function TitleControl(options = {}) { alignLeftComponent = Button({ cls: 'grow light text-smaller', text: 'Vänster', - state: alignment === 'left' ? 'active' : 'initial', + state: titleAlignment === 'left' ? 'active' : 'initial', style: { width: '34%' } }); alignCenterComponent = Button({ cls: 'grow light text-smaller', text: 'Mitten', - state: alignment === 'center' ? 'active' : 'initial', + state: titleAlignment === 'center' ? 'active' : 'initial', style: { width: '34%' } }); alignRightComponent = Button({ cls: 'grow light text-smaller', text: 'Höger', - state: alignment === 'right' ? 'active' : 'initial', + state: titleAlignment === 'right' ? 'active' : 'initial', style: { width: '33%' } }); alignButtons = [alignLeftComponent, alignCenterComponent, alignRightComponent]; @@ -87,25 +89,25 @@ export default function TitleControl(options = {}) { onChangeSize(evt) { this.dispatch('change:titleSize', { class: evt }); selectSize.setButtonText(evt); - size = evt; + titleSize = evt; }, onRender() { formatEl = document.getElementById(formatId); this.dispatch('render'); - selectSize.setButtonText(size); - selectSize.setItems(classes); - this.onChangeSize(size); + selectSize.setButtonText(titleSize); + selectSize.setItems(titleSizes); + this.onChangeSize(titleSize); document.getElementById(selectSize.getId()).addEventListener('dropdown:select', (evt) => { this.onChangeSize(evt.target.textContent); }); }, onChangeVisible() { - if (isVisible) { + if (titleFormatIsVisible) { formatEl.classList.add('hidden'); } else { formatEl.classList.remove('hidden'); } - isVisible = !isVisible; + titleFormatIsVisible = !titleFormatIsVisible; }, onChangeTitle(evt) { this.dispatch('change:title', evt); @@ -122,7 +124,7 @@ export default function TitleControl(options = {}) { ${formatButton.render()} -