Issue #2496💬 AnsweredOpened January 7, 2020by prabha-9121 reactions

Convert rgb/rgba color value to hex code

快速解答by artf1

As the StyleManager can target Components and CssRules you have to find out first what was selected

Read full answer below ↓

Question

Hi Folks,

Steps I followed:

  1. Drag the text block.
  2. set the font color. (its in rgb/rgba format)

What I Expected: Style needs to be updated as like hexa code. (like, #f0f0f0)

I tried to get the particular color update using, editor.on('component:styleUpdate:color', function (model) { . But I could not get the solution. Guide me how to achieve the expected solution.

Thanks in advance, Prabha.

Answers (3)

artfJanuary 12, 2020

As the StyleManager can target Components and CssRules you have to find out first what was selected

editor.on('component:styleUpdate:color', component => {
	const sm = editor.StyleManager;
    const model = sm.getModelToStyle(component);
	// the model can be a Component or CssRule
    console.log(model.getStyle()['color'])
})
pouyamiralayiJanuary 7, 2020

@prabha-912

    editor.on('component:styleUpdate:color', function (model) {
            console.log(model.getStyle()['color'])
     })

cheers!

prabha-912January 8, 2020

It returns undefined for me while updating the color @pouyamiralayi

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.

Browse premium plugins →

Related tutorials

In-depth guides on the same topic.

All tutorials →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.