Skip to content

Use only "color" tabs in countdown and item product color picker options #4712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master-mysterious-egg
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getCSSVariableValue } from "@html_builder/utils/utils_css";
import { ColorSelector } from "@html_editor/main/font/color_selector";
import { Component, useComponent, useRef } from "@odoo/owl";
import { useColorPicker } from "@web/core/color_picker/color_picker";
Expand Down Expand Up @@ -53,9 +54,11 @@ export function useColorPickerBuilderComponent() {
};
}
function getColor(colorValue) {
return colorValue.startsWith("color-prefix-")
? `var(${colorValue.replace("color-prefix-", "--")})`
: colorValue;
if (colorValue.startsWith("color-prefix-")) {
const cssVariableColor = getCSSVariableValue(colorValue.replace("color-prefix-", ""));
return cssVariableColor ? cssVariableColor : colorValue.replace("color-prefix-", "");
}
return colorValue;
}

function onApply(colorValue) {
Expand Down
16 changes: 13 additions & 3 deletions addons/html_builder/static/src/core/core_builder_action_plugin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { Plugin } from "@html_editor/plugin";
import { CSS_SHORTHANDS, applyNeededCss, areCssValuesEqual } from "@html_builder/utils/utils_css";
import {
CSS_SHORTHANDS,
applyNeededCss,
areCssValuesEqual,
normalizeColor,
} from "@html_builder/utils/utils_css";

export function withoutTransition(editingElement, callback) {
if (editingElement.classList.contains("o_we_force_no_transition")) {
Expand Down Expand Up @@ -263,8 +268,13 @@ const attributeAction = {
};

const dataAttributeAction = {
getValue: ({ editingElement, params: { mainParam: attributeName } = {} }) =>
editingElement.dataset[attributeName],
getValue: ({ editingElement, params: { mainParam: attributeName } = {} }) => {
if (!/(^color|Color)($|(?=[A-Z]))/.test(attributeName)) {
return editingElement.dataset[attributeName];
}
const color = normalizeColor(editingElement.dataset[attributeName]);
return color;
},
isApplied: ({ editingElement, params: { mainParam: attributeName } = {}, value }) => {
if (value) {
return editingElement.dataset[attributeName] === value;
Expand Down
10 changes: 10 additions & 0 deletions addons/web/static/src/core/utils/colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,16 @@ export function convertCSSColorToRgba(cssColor) {
}

// Otherwise, check if cssColor is an hexadecimal code color
// first check if it's in its compact form (e.g. #FFF)
if (/^#([0-9a-f]{3})$/i.test(cssColor)) {
return {
red: parseInt(cssColor[1] + cssColor[1], 16),
green: parseInt(cssColor[2] + cssColor[2], 16),
blue: parseInt(cssColor[3] + cssColor[3], 16),
opacity: 100,
};
}

if (/^#([0-9A-F]{6}|[0-9A-F]{8})$/i.test(cssColor)) {
return {
red: parseInt(cssColor.substr(1, 2), 16),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
</BuilderRow>

<BuilderRow label.translate="Text Color">
<BuilderColorPicker dataAttributeAction="'textColor'"/>
<BuilderColorPicker dataAttributeAction="'textColor'" enabledTabs="['solid', 'custom']"/>
</BuilderRow>

<BuilderRow label.translate="Layout">
Expand All @@ -62,7 +62,7 @@
</BuilderRow>
<BuilderRow label.translate="Layout Background Color"
t-if="!this.isActiveItem('no_background_layout_opt')">
<BuilderColorPicker dataAttributeAction="'layoutBackgroundColor'"/>
<BuilderColorPicker dataAttributeAction="'layoutBackgroundColor'" enabledTabs="['solid', 'custom']"/>
</BuilderRow>

<BuilderRow label.translate="Progress Bar Style">
Expand All @@ -82,7 +82,7 @@
</BuilderRow>
<BuilderRow label.translate="Progress Bar Color"
t-if="!this.isActiveItem('no_progressbar_style_opt')">
<BuilderColorPicker dataAttributeAction="'progressBarColor'"/>
<BuilderColorPicker dataAttributeAction="'progressBarColor'" enabledTabs="['solid', 'custom']"/>
</BuilderRow>
</t>
</t>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@
<BuilderTextInput actionParam="'name'" />
</BuilderRow>
<BuilderRow label.translate="Background" level="1">
<BuilderColorPicker actionParam="'bg_color'" />
<BuilderColorPicker actionParam="'bg_color'" enabledTabs="['solid', 'custom']"/>
</BuilderRow>
<BuilderRow label.translate="Text" level="1">
<BuilderColorPicker actionParam="'text_color'" />
<BuilderColorPicker actionParam="'text_color'" enabledTabs="['solid', 'custom']"/>
</BuilderRow>
<BuilderRow label.translate="Position" level="1">
<BuilderSelect actionParam="'position'">
Expand Down