Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Change the selected color according to the value selected in a list

Hi! How is the way to set a color into "ColorSelect", selecting a value from a "Select" (All into index.jsx from settings). I had put onSelection on Select to set the color on the other component, but I don't know if set the string value or use json.stringify...

I need some help...

Best Answer
0 Votes
2 REPLIES 2

Finally I used this:

(background, backgroundGradient and foreground are color settings)

<Select
        label={'Color'}
        settingsKey="colorSelected"
        options={[
          {name: 'Background', value: 'background'},
          {name: 'Background Gradient', value: 'backgroundGradient'},
          {name: 'Foreground', value: 'foreground'}
        ]}
        onSelection={({values}) => {
            props.settingsStorage.setItem("selectedColor", props.settingsStorage.getItem(values[0].value));
          }
        }
      />

But I had to use the value without formatting to JSON to send to the watch:

function sendValue(key, val) {
  if (val) {
    sendSettingData({
      key: key,
      //value: JSON.parse(val)
      value: val
    });
  }
}

 

Best Answer
0 Votes

JSON.parse() doesn't convert a value TO JSON format; it does the opposite. Perhaps you were thinking of JSON.stringify()?

Peter McLennan
Gondwana Software
Best Answer