From 3fc547db654b30d1feeae2261fda39f85d4a9817 Mon Sep 17 00:00:00 2001 From: FrancoisGe Date: Fri, 20 Dec 2024 11:22:13 +0100 Subject: [PATCH] add FontAwesomeOption + fix BuilderColorPicker --- .../builder_components/builder_colorpicker.js | 17 +++++++--- .../builder_colorpicker.xml | 2 +- .../builder/options/font_awesome_option.js | 16 ++++++++++ .../builder/options/font_awesome_option.xml | 32 +++++++++++++++++++ .../builder/options/progress_bar_option.xml | 2 +- .../options/section_background_option.xml | 2 +- .../builder_colorpicker.test.js | 19 +++++++++-- 7 files changed, 81 insertions(+), 9 deletions(-) create mode 100644 addons/html_builder/static/src/builder/options/font_awesome_option.js create mode 100644 addons/html_builder/static/src/builder/options/font_awesome_option.xml diff --git a/addons/html_builder/static/src/builder/builder_components/builder_colorpicker.js b/addons/html_builder/static/src/builder/builder_components/builder_colorpicker.js index 22b0b490c6467..176c78e378320 100644 --- a/addons/html_builder/static/src/builder/builder_components/builder_colorpicker.js +++ b/addons/html_builder/static/src/builder/builder_components/builder_colorpicker.js @@ -21,8 +21,8 @@ export class BuilderColorPicker extends Component { setup() { useBuilderComponent(); this.currentColors = useDomState((editingElement) => ({ - backgroundColor: editingElement - ? getComputedStyle(editingElement).backgroundColor + [this.props.styleAction]: editingElement + ? getComputedStyle(editingElement)[this.props.styleAction] : undefined, })); this.colorButton = useRef("colorButton"); @@ -30,20 +30,29 @@ export class BuilderColorPicker extends Component { this.applyColor = this.env.editor.shared.history.makePreviewableOperation( ({ color, mode }) => { for (const element of this.env.getEditingElements()) { - this.env.editor.shared.color.colorElement(element, color, "backgroundColor"); + this.env.editor.shared.color.colorElement( + element, + color, + this.props.styleAction + ); } this.updateColorButton(); } ); } + + get colorType() { + return this.props.styleAction === "color" ? "foreground" : "background"; + } + updateColorButton() { const editingElement = this.env.getEditingElement(); if (!this.colorButton.el || !editingElement) { return; } const color = - this.env.editor.shared.color.getElementColors(editingElement)["backgroundColor"]; + this.env.editor.shared.color.getElementColors(editingElement)[this.props.styleAction]; this.env.editor.shared.color.colorElement(this.colorButton.el, color, "backgroundColor"); } } diff --git a/addons/html_builder/static/src/builder/builder_components/builder_colorpicker.xml b/addons/html_builder/static/src/builder/builder_components/builder_colorpicker.xml index 39da51d592e28..3d0b81955a821 100644 --- a/addons/html_builder/static/src/builder/builder_components/builder_colorpicker.xml +++ b/addons/html_builder/static/src/builder/builder_components/builder_colorpicker.xml @@ -5,7 +5,7 @@
+ + + + + + + + + + + + + + 1x + 2x + 3x + 4x + 5x + + + + + + + + diff --git a/addons/html_builder/static/src/builder/options/progress_bar_option.xml b/addons/html_builder/static/src/builder/options/progress_bar_option.xml index 5b32058a9f129..d3ea93d5f1bb6 100644 --- a/addons/html_builder/static/src/builder/options/progress_bar_option.xml +++ b/addons/html_builder/static/src/builder/options/progress_bar_option.xml @@ -14,7 +14,7 @@ - + diff --git a/addons/html_builder/static/src/builder/options/section_background_option.xml b/addons/html_builder/static/src/builder/options/section_background_option.xml index 5242903d537d1..e462a6fa1a33c 100644 --- a/addons/html_builder/static/src/builder/options/section_background_option.xml +++ b/addons/html_builder/static/src/builder/options/section_background_option.xml @@ -3,7 +3,7 @@ - + diff --git a/addons/html_builder/static/tests/custom_tab/builder_components/builder_colorpicker.test.js b/addons/html_builder/static/tests/custom_tab/builder_components/builder_colorpicker.test.js index 91447b9d7b02a..7d28d9999ab06 100644 --- a/addons/html_builder/static/tests/custom_tab/builder_components/builder_colorpicker.test.js +++ b/addons/html_builder/static/tests/custom_tab/builder_components/builder_colorpicker.test.js @@ -6,10 +6,10 @@ import { addOption, defineWebsiteModels, setupWebsiteBuilder } from "../../helpe defineWebsiteModels(); -test("should apply color to the editing element", async () => { +test("should apply backgroundColor to the editing element", async () => { addOption({ selector: ".test-options-target", - template: xml``, + template: xml``, }); await setupWebsiteBuilder(`
b
`); await contains(":iframe .test-options-target").click(); @@ -19,6 +19,21 @@ test("should apply color to the editing element", async () => { await click(".o-overlay-item [data-color='o-color-1']"); expect(":iframe .test-options-target").toHaveClass("test-options-target bg-o-color-1"); }); + +test("should apply color to the editing element", async () => { + addOption({ + selector: ".test-options-target", + template: xml``, + }); + await setupWebsiteBuilder(`
b
`); + await contains(":iframe .test-options-target").click(); + expect(".options-container").toBeDisplayed(); + await click(".we-bg-options-container .dropdown"); + await animationFrame(); + await click(".o-overlay-item [data-color='o-color-1']"); + expect(":iframe .test-options-target").toHaveClass("test-options-target text-o-color-1"); +}); + test("hide/display base on applyTo", async () => { addOption({ selector: ".parent-target",