Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
Allow input color without hex, also fx invalid (#1837)
Ivan Starkovade16e50053f
diff --git a/apps/builder/app/builder/features/style-panel/shared/color-picker.tsx b/apps/builder/app/builder/features/style-panel/shared/color-picker.tsxindex c348c4a20b..3ce1a77128 100644--- a/apps/builder/app/builder/features/style-panel/shared/color-picker.tsx+++ b/apps/builder/app/builder/features/style-panel/shared/color-picker.tsx@@ -152,7 +152,8 @@ const useFixDragOverCanvas = () => {export type CssColorPickerValueInput =| RgbValue| KeywordValue- | IntermediateStyleValue;+ | IntermediateStyleValue+ | InvalidValue;type ColorPickerProps = {onChange: (value: CssColorPickerValueInput | undefined) => void;@@ -318,6 +319,7 @@ export const ColorPicker = ({styleValue?.type === "rgb" ||styleValue?.type === "keyword" ||styleValue?.type === "intermediate" ||+ styleValue?.type === "invalid" ||styleValue === undefined) {onChange(styleValue);@@ -331,19 +333,14 @@ export const ColorPicker = ({}}onHighlight={onHighlight}onChangeComplete={({ value }) => {- if (- value.type === "rgb" ||- value.type === "keyword" ||- value.type === "invalid"- ) {+ if (value.type === "rgb" || value.type === "keyword") {onChangeComplete({ value });+ return;}-- onChangeComplete({- value: {- type: "invalid",- value: toValue(value),- },+ // In case value is parsed to something wrong+ onChange({+ type: "invalid",+ value: toValue(value),});}}onAbort={onAbort}diff --git a/apps/builder/app/builder/features/style-panel/shared/css-value-input/parse-intermediate-or-invalid-value.ts b/apps/builder/app/builder/features/style-panel/shared/css-value-input/parse-intermediate-or-invalid-value.tsindex 5150e4a99b..9a300e619a 100644--- a/apps/builder/app/builder/features/style-panel/shared/css-value-input/parse-intermediate-or-invalid-value.ts+++ b/apps/builder/app/builder/features/style-panel/shared/css-value-input/parse-intermediate-or-invalid-value.ts@@ -84,6 +84,13 @@ export const parseIntermediateOrInvalidValue = (}}+ // Last chance probably it's a color without #+ styleInput = parseCssValue(property, `#${value}`);++ if (styleInput.type !== "invalid") {+ return styleInput;+ }+// If we are here it means that value can be Valid but our parseCssValue can't handle it// or value is invalidreturn {diff --git a/apps/builder/app/builder/features/style-panel/shared/css-value-input/parse-intermediate-or-invalid-value.ts.test.ts b/apps/builder/app/builder/features/style-panel/shared/css-value-input/parse-intermediate-or-invalid-value.ts.test.tsindex 4c75168d2d..04fc6a8c12 100644--- a/apps/builder/app/builder/features/style-panel/shared/css-value-input/parse-intermediate-or-invalid-value.ts.test.ts+++ b/apps/builder/app/builder/features/style-panel/shared/css-value-input/parse-intermediate-or-invalid-value.ts.test.ts@@ -372,6 +372,66 @@ describe("Colors", () => {});});+ test("color with value hex", () => {+ const result = parseIntermediateOrInvalidValue("color", {+ type: "intermediate",+ value: "#f00",+ });++ expect(result).toEqual({+ type: "rgb",+ alpha: 1,+ r: 255,+ g: 0,+ b: 0,+ });+ });++ test("color with value with long hex", () => {+ const result = parseIntermediateOrInvalidValue("color", {+ type: "intermediate",+ value: "#f0ee0f",+ });++ expect(result).toEqual({+ type: "rgb",+ alpha: 1,+ r: 240,+ g: 238,+ b: 15,+ });+ });++ test("color with value hex without #", () => {+ const result = parseIntermediateOrInvalidValue("color", {+ type: "intermediate",+ value: "f00",+ });++ expect(result).toEqual({+ type: "rgb",+ alpha: 1,+ r: 255,+ g: 0,+ b: 0,+ });+ });++ test("color with value long hex without #", () => {+ const result = parseIntermediateOrInvalidValue("color", {+ type: "intermediate",+ value: "f0ee0f",+ });++ expect(result).toEqual({+ type: "rgb",+ alpha: 1,+ r: 240,+ g: 238,+ b: 15,+ });+ });+test("color with value rgba(0,0,0,0)", () => {const result = parseIntermediateOrInvalidValue("color", {type: "intermediate",